// JavaScript Document

function $(id){
	return document.getElementById(id);	
}
function RetiraPX(str){
	var n = String(str).length - 2;
	//window.alert(n);
	return String(str).substring(0,n);
	//Left(str,n);
}

function RetiraEXT(str){
	n = String(str).length - 4;
	//window.alert(n);
	return String(str).substring(0,n);
	//Left(str,n);
}

function AbrirPag(url){
	var w = window.screen.availWidth
	var h = window.screen.availHeight
	widthF = w
	heightF = h
	//window.innerWidth || self.innerWidth || document.body.clientWidth;
	//var h = window.innerHeight || self.innerHeight || document.body.clientHeight;
	//(window.screen.width)
	//(window.screen.height)
	window.open(url, RetiraEXT(url),'status=no,menubar=no,scrollbars=yes,toolbar=no,location=no,resizable=no,width=' + widthF + ',height=' + heightF + ',top=0,left=0');
}

function CentralizarDiv(div){
	var w = window.innerWidth || self.innerWidth || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || document.body.clientHeight;
	var w_div = RetiraPX(document.getElementById(div).style.width);
	var h_div = RetiraPX(document.getElementById(div).style.height);
	//window.alert(h_div);
	//window.alert(w_div);
	
	var topf
	var leftf
	
	topf = (h - h_div)/2;
	leftf = (w - w_div)/2;
	
	if (topf < 0){
		topf = 0;
	}
	
	if (leftf < 0){
		leftf = 0;
	}
	//window.alert(topf);
	//window.alert(leftf);
	document.getElementById(div).style.top = topf;
	document.getElementById(div).style.left = leftf;
	//window.alert('passou1');
	document.getElementById(div).style.visibility = 'visible';
	//window.alert('passou2');
};


function CentralizarDivHorizontal(div){
	var w = window.innerWidth || self.innerWidth || document.body.clientWidth;

	var w_div = RetiraPX(document.getElementById(div).style.width);
	//window.alert(w_div);
	var leftf
	leftf = (w - w_div)/2;
	
	if (leftf < 0){
		leftf = 0;
	}
	//window.alert(topf);
	//window.alert(leftf);
	document.getElementById(div).style.left = leftf;
	//window.alert('passou1');
	document.getElementById(div).style.visibility = 'visible';
	//window.alert('passou2');
};



function DivInferior(div){
	var h = window.innerHeight || self.innerHeight || document.body.clientHeight;
	h = (h);
	var hDiv 
	hDiv= $(div).style.height;
	hDiv = RetiraPX(hDiv);
	var topDiv
	topDiv= h - hDiv + document.body.scrollTop;
	//alert( topDiv);
	$(div).style.top = topDiv;
	//$(div).style.bottom = 0;
	$(div).style.visibility = "visible";
	//var dsoctop=document.body.scrollTop

	
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  $(obj).style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  $(obj).style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  $(obj).style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  $(obj).style.opacity = opacity/100;
  $(obj).style.visibility = "visible";
}

function fadeIn(objId,opacity,opacityF,increase,time) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity < opacityF) {
			setOpacity(obj, opacity);
			obj.style.visibility = "visible";
			obj.style.display = "";
			opacity += increase;
			window.setTimeout("fadeIn('" +objId+ "'," +opacity+ "," +opacityF+ "," +increase+"," +time+ ")", time);
		}
	}
	
}

function fadeOut(objId,opacity) {
  opc = opacity
  if (document.getElementById) {
	obj = document.getElementById(objId);
    if (opacity > 0) {
      setOpacity(obj, opacity);
      opacity -= 5;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 1);
    }
	else{
		document.getElementById(objId).style.visibility = "hidden";
		document.getElementById(objId).style.display = "none"
	};
  
  }	
}

function SombraDiv(Principal,Sombra,cor){
	document.write("<div id='" + Sombra + "' style='position:absolute;width:0;height:0;left:0;top:0;'></div>" )
	var divPrinc = $(Principal).style;
	var divSombra = $(Sombra).style;
	var largura = RetiraPX(divPrinc.width);
	var altura = RetiraPX(divPrinc.height);
	var top = RetiraPX(divPrinc.top);
	var left = RetiraPX(divPrinc.left);
	//alert(largura)
	//alert(altura)
	//alert(top)
	//alert(left)
	divSombra.width = Math.abs(largura);
	//alert(divSombra.width); 
	divSombra.height = Math.abs(altura);
	//alert(divSombra.height)
	divSombra.left = Math.abs(left) + 5;
	//alert(divSombra.left)
	divSombra.top = Math.abs(top) + 5;
	//alert(divSombra.top)
	divSombra.background=cor;
	//alert(divSombra.background)
	divSombra.zIndex = Math.abs(divPrinc.zIndex) - 1;
	//alert(divSombra.zIndex);
	setOpacity($(Sombra),80);

}

function SombraDivText(DivPrincipal,DivSombra,cor,Opacidade,distancia){
	var Princ = $(DivPrincipal).style;
	//var Sombra = $(DivSombra).style;
	var largura = RetiraPX(Princ.width);
	var altura = RetiraPX(Princ.height);
	var zIndex = Math.abs(Princ.zIndex) - 1;
	var top = Math.abs(RetiraPX(Princ.top)) + distancia;
	var left = Math.abs(RetiraPX(Princ.left)) + distancia;
	var textTransform = Princ.textTransform;
	var color = cor;
	var fontSize = Princ.fontSize;
	var fontWeight = Princ.fontWeight;
	var fontFamily = Princ.fontFamily;
	var conteudo = $(DivPrincipal).innerHTML;
	
	document.write("<div id='" + DivSombra + "' style='position:absolute;width:" +largura + ";height:" + altura + ";left:" + left + ";top:" + top + ";z-index:"+zIndex + ";font-family:"+fontFamily + ";font-weight:"+fontWeight + ";color:"+color + ";text-transform:"+textTransform + ";font-size:"+fontSize + ";'>"+ conteudo +"</div>" )
	
	setOpacity($(DivSombra),Opacidade);
	//z-index:2;
	//font-family:Tahoma, Geneva, sans-serif;
	//font-size:40px;
	//font-weight:bolder;
	//color:#000000;
	//text-transform:uppercase;
}

function getPosicaoElemento(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }

    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

function ShowElement(element){
		$(element).style.visibility = "visible";
}

function HideElement(element){
		$(element).style.visibility = "hidden";
}


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = PerseguirMouse;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function PerseguirMouse(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  $('apDiv8').style.left = tempX;
  $('apDiv8').style.top = tempY;
  return true
}
