
/*
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789.").indexOf(keychar) > -1))
   return true;

// decimal point jump
else
   return false;
}
*/

function ceponly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else
   return false;
}




function validacnpj(Campo){
var i;
var Valida=true;
var s = Campo;
var c = s.substr(0,12);
var dv = s.substr(12,2);
var d1 = 0;
for (i = 0; i < 12; i++){d1 += c.charAt(11-i)*(2+(i % 8));}
if (d1 == 0) Valida=false;
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(0) != d1){Valida=false;}
d1 *= 2;
for (i = 0; i < 12; i++){d1 += c.charAt(11-i)*(2+((i+1) % 8));}
d1 = 11 - (d1 % 11);
if (d1 > 9) d1 = 0;
if (dv.charAt(1) != d1){Valida=false;}
return Valida; 
}


function validacpf(cpf){  
// ******* Verifico se os números digitados são iguais ********
// sem está verificação, se os números forem iguais aparecerá que o CPF é válido
  iguais = true;
  for(i=0; i<=9; i++) {
    if(cpf.charAt(i) != cpf.charAt(i+1)) {
      iguais = false;
      break;
    }
  }
// ************************************************************
  subtot1 = 0
  subtot2 = 0
 	 for(n=0; n <= 8; n++) {
	    n1 = parseInt(cpf.charAt(n)) * (n + 1);
	    subtot1 = subtot1 + n1; // mesma coisa que sbtot1 += n1
	    n2 = parseInt(cpf.charAt(n+1)) * (n+1);
	    subtot2 = subtot2 + n2;
 	}
	 resto1 = subtot1 % 11;// pegando o resto da divisão
	 resto2 = subtot2 % 11;
	 if(resto1 == 10) resto1 = 0;
	 if(resto2 == 10) resto2 = 0;
	 resto1 = resto1.toString();
	 resto2 = resto2.toString();
	 if(resto1 == cpf.charAt(9) && resto2 == cpf.charAt(10) && iguais == false) {
	 	Valida=true;
	 }
	 else {
	 	Valida=false;
	 }
 return Valida;  
}




function validadata(pStr)
{
reDate = /^\d{2}\/\d{2}\/\d{4}$/;
	if (reDate.test(pStr) && pStr.length>0) {
		if(parseInt(pStr.substring(0,2))<=31 && parseInt(pStr.substring(3,5))<=12 && parseInt(pStr.substring(6,10))<=2050 && parseInt(pStr.substring(6,10))>=1900 )
		{return true;}else{return false;}
	} else{return false;}
} 





function validaemail(pStr)
{
reEmail = /^[\w!#$%&*+\/=?^`{|}~-]+(\.[\w!#$%&*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
if (reEmail.test(pStr) && pStr.length>0) {return true;} else{return false;}
}

function Val(field,tipo)
{
if (tipo=="txt")pat=/[0-9]/;
if (tipo=="num")pat=/[^0-9]/;
if (tipo=="tel")pat=/[^0-9\-]/;
if (tipo=="dt")pat=/[^0-9\/]/;
if (tipo=="dec")pat=/[^0-9\,]/;
idx = field.value.search( pat );
while ( idx > -1 ) {field.value = field.value.replace( pat, '' ); idx = field.value.search( pat );}
}


/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=0 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

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.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
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 the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
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
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
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"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

