function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;  
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}


function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}

}



return result;



}







//Formata número tipo moeda usando o evento onKeyDown







function Formata(campo,tammax,teclapres,decimal) {



var tecla = teclapres.keyCode;



vr = Limpar(campo.value,"0123456789");



tam = vr.length;



dec=decimal







if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }







if (tecla == 8 )



{ tam = tam - 1 ; }







if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )



{







if ( tam <= dec )



{ campo.value = vr ; }







if ( (tam > dec) && (tam <= 5) ){



campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }



if ( (tam >= 6) && (tam <= 8) ){



campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 


}



if ( (tam >= 9) && (tam <= 11) ){



campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }



if ( (tam >= 12) && (tam <= 14) ){



campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }



if ( (tam >= 15) && (tam <= 17) ){



campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}



} 







}



function formatarMoeda(fld, milSep, decSep, e) {    

var sep = 0;    

var key = '';    

var i = j = 0;    

var len = len2 = 0;    

var strCheck = '0123456789';    

var aux = aux2 = '';    

var whichCode = (window.Event) ? e.which : e.keyCode;    

if (whichCode == 13) return true;  // Enter    

key = String.fromCharCode(whichCode);  // recebe o valor da chave vinda da chave do código   

  

if (strCheck.indexOf(key) == -1) return false;  // Chave não válida   

len = fld.value.length;    

for(i = 0; i < len; i++)    

if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;    

aux = '';    

for(; i < len; i++)    

if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);    

aux += key;    

len = aux.length;    

if (len == 0) fld.value = '';    

if (len == 1) fld.value = '0'+ decSep + '0' + aux;    

if (len == 2) fld.value = '0'+ decSep + aux;    

if (len > 2) {    

aux2 = '';    

for (j = 0, i = len - 3; i >= 0; i--) {    

if (j == 3) {    

aux2 += milSep;    

j = 0;    

}    

aux2 += aux.charAt(i);    

j++;    

}    

fld.value = '';    

len2 = aux2.length;    

for (i = len2 - 1; i >= 0; i--)    

fld.value += aux2.charAt(i);    

fld.value += decSep + aux.substr(len - 2, len);    

}    

return false;    

}    





// 	DRIVE TIPS

var offsetxpoint=-60 

var offsetypoint=20 

var ie=document.all 

var ns6=document.getElementById && !document.all 

var enabletip=false 

if (ie||ns6) 

var tipobj=document.all? document.all["ajudarapida"] : document.getElementById? document.getElementById("ajudarapida") : "" 



function ietruebody(){ 

return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body 

} 



function ddrivetip(thetext, thecolor, thewidth){ 

	if (ns6||ie){ 

		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px" 

		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor 

		tipobj.innerHTML=thetext 

		enabletip=true 

		return false 

	} 

} 



function positiontip(e){ 

	if (enabletip){ 

		var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft; 

		var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop; 

		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20 

		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20 

		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000 

	

		if (rightedge<tipobj.offsetWidth) 

			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px" 

		else if (curX<leftedge) 

			tipobj.style.left="5px" 

		else 

			tipobj.style.left=curX+offsetxpoint+"px" 

		if (bottomedge<tipobj.offsetHeight) 

			tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px" 

		else 

			tipobj.style.top=curY+offsetypoint+"px" 

		tipobj.style.visibility="visible" 

	} 

} 



function hideddrivetip(){ 

	if (ns6||ie){ 

		enabletip=false 

		tipobj.style.visibility="hidden" 

		tipobj.style.left="-1000px" 

	} 

} 





function showdiv(id) {

	//safe function to show an element with a specified id

	document.getElementById(id).style.top=Math.round(screen.height/2) -200;

	document.getElementById(id).style.left=Math.round(screen.width/2) - 300;	

	if (document.getElementById) { // DOM3 = IE5, NS6

		document.getElementById(id).style.display = 'block';

	}

	else {

		if (document.layers) { // Netscape 4

			document.id.display = 'block';

		}

		else { // IE 4

			document.all.id.style.display = 'block';

		}

	}

	document.getElementById('nome').focus();

}

function hidediv(id) {

	//safe function to hide an element with a specified id

	if (document.getElementById) { // DOM3 = IE5, NS6

		document.getElementById(id).style.display = 'none';

	}

	else {

		if (document.layers) { // Netscape 4

			document.id.display = 'none';

		}

		else { // IE 4

			document.all.id.style.display = 'none';

		}

	}

}




