// JavaScript Document
function AjustarCEP(input){
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 13)){
		event.returnValue = false;
	} else {
		if (input.value.length==5){
			input.value=input.value + "-" ;
		}
	}
}
function AjustarTelefone(input, ddd){
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 13)){
		event.returnValue = false;
	} else {
		if ((input.value.length==2) && (ddd==1)) {
			input.value=input.value + "-" ;
		} else if ((input.value.length==4) && (ddd==0)) {
			input.value=input.value + "-" ;
		} else if ((input.value.length==7) && (ddd==1)) {
			input.value=input.value + "-" ;
		}			
	}
}

function AjustarMoeda(input){
	if (((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 44) || (event.keyCode == 13)) {
		event.returnValue = true;
	} else {
	    event.returnValue = false; 		
	} 
}

function AjustarInteiro(campo) { 
 	if (((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 13)){
  		event.returnValue = true;
 	} else {
  		event.returnValue = false;
 	}
}

//Verifica se a data inicial é maior que a data final  
function ComparaData(DtHrInicio, DtHrTermino){  
	 var AgeDtHrIniciodt   		= document.getElementById(DtHrInicio).value;
     var AgeDtHrTerminodt   	= document.getElementById(DtHrTermino).value;
     var DiaInicial        		= AgeDtHrIniciodt.substring(0,2);
     var DiaFinal        		= AgeDtHrTerminodt.substring(0,2);
     var MesInicial      		= AgeDtHrIniciodt.substring(3,5);
     var MesFinal       	    = AgeDtHrTerminodt.substring(3,5);
     var AnoInicial      		= AgeDtHrIniciodt.substring(6,10);
     var AnoFinal        		= AgeDtHrTerminodt.substring(6,10);  

	if(AnoFinal != ""){
		if(AnoInicial > AnoFinal) {  
			 alert("A data Inicial deve ser menor que a data final.");   
			 document.getElementById(DtHrTermino).focus();
			 return false;  
		}else{  
			if(AnoInicial == AnoFinal){  
				if(MesInicial >  MesFinal){  
					alert("A data inicial deve ser menor que a data final.");  
					document.getElementById(DtHrTermino).focus();  
					return false;  
				}else{  
					if(MesInicial == MesFinal){  
						if(DiaInicial > DiaFinal){  
							alert("A data inicial deve ser menor que a data final.");  
							document.getElementById(DtHrTermino).focus();  
							return false;  
						 }  
					 }  
				 }  
			 }  
		 }  
	}
	 return true;
 }
 
function ajustarInt(campo, e) { 
	if (!e) e = window.event;

	if (e.keyCode) key = e.keyCode; // IE
	else if (e.which) key = e.which; // Netscape 4.?
	else if (e.charCode) key = e.charCode; // Mozilla

	if (((key >= 48) && (key <= 57)) || (key == 46) || (key == 13) || (key == 9) || (key == 8) || ((key >= 96) && (key <= 105)) || ((key >= 35) && (key <= 40))){
		return true;
	} else {
		return false;
	}
}

function AjustarData(input){
	
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 13)){
		event.returnValue = false;
	} else {
		if ((input.value.length==2) || (input.value.length==5)){
			input.value=input.value + "/" ;
		}
	}
}

function AjustarHora(input){
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 13)){
		event.returnValue = false;
	}else {
		if (input.value.length==2){
			input.value=input.value + ":" ;
		}
	}
}

function AjustarCPF(input){
	if (((event.keyCode<48)||(event.keyCode>57)) && (event.keyCode != 13)){
		event.returnValue = false;
	} else {
    	if((input.value.length==3)||(input.value.length==7)){
			input.value=input.value + "." ;
		} else {
    		if(input.value.length==11)
			input.value=input.value + "-" ;
		}
	}
}

function AjustarIE(input){
	if (((event.keyCode<48)||(event.keyCode>57)) && (event.keyCode != 13)){
		event.returnValue = false;
	}else {
    	if((input.value.length==3)||(input.value.length==7)||(input.value.length==12)) {
			input.value=input.value + "." ;
		}
	}
}


function AjustarCNPJ(input){
	if (input.value.lenght > 18){
		return false;	
	}
	if (((event.keyCode<48)||(event.keyCode>57)) && (event.keyCode != 13)){
		event.returnValue = false;
	} else {
    	if((input.value.length==2) || (input.value.length==6)) {
			input.value=input.value + "." ;
		} else {
			if(input.value.length==10) {
				input.value=input.value + "/" ;
			} else {
				if (input.value.length==15) {
					input.value=input.value + "-" ;					
				}
			}
		}
	} 
}

function CPF_CNPJonKeyPress(objeto){
	if (document.frmCampos.EntTipoPessoa[0].checked) {
		AjustarCPF(objeto);
	} else {
		AjustarCNPJ(objeto);
	}
}

function validarHora(valor) {
	if (valor.length < 5) {
		return false;
	}
	if (valor.indexOf(":") == 2 ){
		var hh = valor.slice(0,valor.indexOf(":"));
		var mm = valor.slice(valor.indexOf(":")+1,5);
		if (hh >= 0 && hh < 24) {
			if (mm >= 0 && mm < 60) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}

//Retorna Zero quando o Valor for Vazio - Zero When Empty
function ZWE(valor){
	if (valor != ""){
		return valor;	
	} else {
		return 0.0;	
	}
}

function validarData(valor){
	if (valor.length < 10) {
		return false;
	}
	if (valor.indexOf("/") == 2 && valor.lastIndexOf("/") == 5) {
		var DD = valor.slice(0,valor.indexOf("/"));
		var MM = valor.slice(valor.indexOf("/")+1,valor.lastIndexOf("/"));
		var YY = valor.slice(valor.lastIndexOf("/")+1,10);
		if (YY != 0){
			if (YY % 4 !=0){
				var DiaFinal = Array(31,28,31,30,31,30,31,31,30,31,30,31);
			} else {
				var DiaFinal = Array(31,29,31,30,31,30,31,31,30,31,30,31);		
			}
			if (MM > 0 && MM <= 12){
				if (DD > 0 && DD <= DiaFinal[MM-1]) {
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}


function validarEmail(email){
	if (email.length != 0) {
		if (email.indexOf(".") != -1 || email.indexOf("@") != -1) {
			if (email.lastIndexOf(".") > email.indexOf("@")) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function validarIntervalo(pValor, pObjeto){
	if (pValor == "Intervalo") {
		pObjeto.disabled = false;	
	} else {
		pObjeto.disabled = true;
	}
}

function aT(campo){
	if (event.keyCode == 13){
		event.returnValue = false;
		campo.blur();
	}
}

function validaTecla(campo) { 
	if (((event.keyCode<48) || (event.keyCode>57)) && (event.keyCode != 13)){
		event.returnValue = false;
	} else {
		campo.value=campo.value;
	}
} 

function validarCheckBox(vObCheck){
	var vSel = false;
	
	if (vObCheck.length == undefined) {
		vSel = (vObCheck.checked);
	} else {
		for (var j=0; j < vObCheck.length; j++) {
			vSel = vSel || (vObCheck[j].checked);
		}
	}
	return vSel;
}

function validarCheckBoxUnico(vObCheck, vIdSel, vTam){
	var vSel = false;
	
	for (var j=0; j < parseInt(vTam); j++) {
		document.getElementById(vObCheck + j).checked = (j==parseInt(vIdSel)? true: false);
	}
}

function FormataCNPJ(el) { 
	vr = el.value; 
	tam = vr.length; 

    if ( vr.indexOf(".") == -1 ) { 
		if ( tam <= 2 ) 
			  el.value = vr; 
		if ( (tam > 2) && (tam <= 6) ) 
			  el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
		if ( (tam >= 7) && (tam <= 10) ) 
			  el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/'; 
		if ( (tam >= 11) && (tam <= 18) ) 
			 el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ); 
    } 
    return true; 
}

function FormataStringCNPJ(el) { 
	vr = el; 
	tam = vr.length; 
	var retorno = "";

	if ( vr.indexOf(".") == -1 ) { 
		if ( tam <= 2 ) 
			  retorno = vr; 
		if ( (tam > 2) && (tam <= 6) ) 
			  retorno = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
		if ( (tam >= 7) && (tam <= 10) ) 
			  retorno = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/'; 
		if ( (tam >= 11) && (tam <= 18) ) 
			 retorno = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ); 
	} 
	return retorno; 
}

function FormataCPF( el ) { 
	vr = el.value; 
	tam = vr.length; 

    if ( vr.indexOf(".") == -1 ) { 
		if ( tam <= 3 ) 
			el.value = vr; 
		if ( (tam > 3) && (tam <= 7) ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 4, tam ); 
		if ( (tam >= 8) && (tam <= 11) ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 5, 3 ) + '-'; 
		if ( (tam >= 11) && (tam <= 18) ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ); 
    } 

    return true; 
}

function FormataStringCPF( el ) { 
	vr = el; 
	tam = vr.length; 
	var retorno = ""
    if ( vr.indexOf(".") == -1 ) { 
		if ( tam <= 3 ) 
			 retorno = vr; 
		if ( (tam > 3) && (tam <= 7) ) 
			retorno = vr.substr( 0, 3 ) + '.' + vr.substr( 4, tam ); 
		if ( (tam >= 8) && (tam <= 11) ) 
			retorno = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 5, 3 ) + '-'; 
		if ( (tam >= 11) && (tam <= 18) ) 
			retorno = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ); 
    } 

    return retorno; 
}

function validarCPF (CPF) {
	
	CPF = LimpaFormatoStr(CPF);
	
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
		return false;
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
		return false;
	return true;
}

/*
function validarCPF_old(strcpf) {
	
	if (strcpf.length < 14){
		return false;
	}

	var wSomaDosProdutos=0;
	var wResto=0;
	var wDigitChk=0;
	var wDigitChk2=0;
	var wStatus=0;
	var wI=0;

	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = strcpf.substring(0,3);
		x += strcpf.substring(4,7);
		x += strcpf.substring(8,11);
		x += strcpf.substring(12,14);
		strcpf = x; 
	} else {
		strcpf = strcpf.replace(".","");
		strcpf = strcpf.replace(".","");
		strcpf = strcpf.replace("-","");
	}

	if (parseInt(strcpf) == 0){
		return false;	
	}

	for (wI = 0;wI<9;wI++) {
		wSomaDosProdutos += parseInt( strcpf.substring(wI, wI+1) ) * (11 - (wI+1) );
	}

	wResto = wSomaDosProdutos - parseInt( wSomaDosProdutos / 11 ) * 11;

	if ( wResto == 0 || wResto == 1 ){
		wDigitChk1 = 0;
	}else{
		wDigitChk1 = 11 - wResto;
	}

	wSomaDosProdutos = 0;
	
	for (wI = 0;wI<9;wI++) {
		wSomaDosProdutos += parseInt( strcpf.substring(wI,wI+ 1) ) * (12 - (wI+1) );
	}

	wSomaDosProdutos += 2 * wDigitChk1;
	wResto = wSomaDosProdutos - parseInt(wSomaDosProdutos / 11) * 11;

	if ( wResto == 0 || wResto == 1) {
		wDigitChk2 = 0;
	}else{
		wDigitChk2 = 11-wResto ;
	}

	var ch1 = strcpf.charAt(9);
	var ch2 = strcpf.charAt(10);

	if ( strcpf == "" || ( parseInt( ch1 ) == wDigitChk1 && parseInt( ch2 ) == wDigitChk2 )) {
		return (true);
	}else{
		return (false);
	}
}
*/
function validarCNPJ(CNPJ) {
//	CNPJ = obCNPJ.value;
//	CNPJ = document.validacao.CNPJID.value;
	erro = new String;
	
	if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
	
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
	}
	//substituir os caracteres que nao sao numeros
	if(document.layers && parseInt(navigator.appVersion) == 4){
		x = CNPJ.substring(0,2);
		x += CNPJ.substring(3,6);
		x += CNPJ.substring(7,10);
		x += CNPJ.substring(11,15);
		x += CNPJ.substring(16,18);
		CNPJ = x; 
	} else {
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace(".","");
		CNPJ = CNPJ.replace("-","");
		CNPJ = CNPJ.replace("/","");
	}
	
	var nonNumbers = /\D/;
	
	if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n"; 
	
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];

	for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]); 
	}
	
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
		erro +="Digito verificador com problema!";
	}
	
	if (erro.length > 0){
//		alert(erro);
		return false;
	} else {
//		alert("CNPJ valido!");
		return true;
	}
return true;
}


function AbreJanela(arq, nomejanela, width, height, scroll) {
	var URL = arq
	var NM = nomejanela
	var W = width
	var H = height
	var S = scroll
	var Wpopupsize = (W/2);
	var Hpopupsize = (H/2);
	var CenterPopUpX = (screen.width / 2) - (Wpopupsize);
	var CenterPopUpY = (screen.height / 2) - (Hpopupsize);
	var pos = "left=" + CenterPopUpX + ",top=" + CenterPopUpY;
	var janela = window.open("" + URL + "", "" + NM + "", "width=" + W + ",height=" + H + ",scrollbars=" + S + "," + pos);
	janela.focus();
}

function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.bgColor = clrOver;
	}
}

function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.bgColor = clrIn;
	}
}

function mOvrs(src,styleOver) {
	if (!src.contains(event.fromElement)) {
		src.className = styleOver;
	}
}

function mOuts(src,styleIn) {
	if (!src.contains(event.toElement)) {
		src.className = styleIn;
	}
}

function mascara_data(data){ 
	var mydata = ''; 
	mydata = mydata + data; 
	if (mydata.length == 2){ 
	  mydata = mydata + '/'; 
	  document.forms[0].data.value = mydata; 
	} 
	if (mydata.length == 5){ 
	  mydata = mydata + '/'; 
	  document.forms[0].data.value = mydata; 
	} 
	if (mydata.length == 10){ 
	  verifica_data(); 
	} 
} 
           
function verifica_data () { 

	dia = (document.forms[0].data.value.substring(0,2)); 
	mes = (document.forms[0].data.value.substring(3,5)); 
	ano = (document.forms[0].data.value.substring(6,10)); 
	
	situacao = ""; 
	// verifica o dia valido para cada mes 
	if ((dia < 01) || ((dia > 30) && ((mes == 04) || (mes == 06) || (mes == 09) || (mes == 11))) || (dia > 31)) { 
		situacao = "falsa"; 
	} 

	// verifica se o mes e valido 
	if (mes < 01 || mes > 12 ) { 
		situacao = "falsa"; 
	} 

	// verifica se e ano bissexto 
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
		situacao = "falsa"; 
	} 

	if (document.forms[0].data.value == "") { 
		situacao = "falsa"; 
	} 

	if (situacao == "falsa") { 
		alert("Data inválida!"); 
		document.forms[0].data.focus(); 
	} 
} 

function mascara_hora(hora){ 
	var myhora = ''; 
	myhora = myhora + hora; 
	if (myhora.length == 2){ 
	  myhora = myhora + ':'; 
	  document.forms[0].hora.value = myhora; 
	} 
	if (myhora.length == 5){ 
	  verifica_hora(); 
	} 
} 
           
function verifica_hora(){ 
	hrs = (document.forms[0].hora.value.substring(0,2)); 
	min = (document.forms[0].hora.value.substring(3,5)); 
	
	alert('hrs '+ hrs); 
	alert('min '+ min); 
	
	situacao = ""; 
	// verifica data e hora 
	if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59)){ 
		situacao = "falsa"; 
	} 
	
	if (document.forms[0].hora.value == "") { 
		situacao = "falsa"; 
	} 
	
	if (situacao == "falsa") { 
		alert("Hora inválida!"); 
		document.forms[0].hora.focus(); 
	} 
}

function LimpaFormato(objeto){
	objeto.value = 	objeto.value.replace(",","");
	objeto.value = 	objeto.value.replace("/","");
	objeto.value = 	objeto.value.replace("-","");
	objeto.value =  objeto.value.replace(".","");
	objeto.value =  objeto.value.replace(".","");	
}

function LimpaFormatoStr(strnoformat){
	strnoformat = strnoformat.replace(",","");
	strnoformat = strnoformat.replace("/","");
	strnoformat = strnoformat.replace("-","");
	strnoformat = strnoformat.replace(".","");
	strnoformat = strnoformat.replace(".","");
	return strnoformat;
}

function trim(sString) {

	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}

	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}

	sString.replace('\n', null);
	sString.replace('\r', null);

	alert('ola' + sString + 'ola');
	return sString;
}


function retiraFormato(vlrDesformatar) {
	while (vlrDesformatar.indexOf('.') != -1) {
		vlrDesformatar = vlrDesformatar.replace('.','');
	}
	vlrDesformatar = vlrDesformatar.replace(',','.');
	return vlrDesformatar;
}

function MudaTamMaximo(objeto, tamanho){
	objeto.maxLength = tamanho;
}

function LimitaTamanho(objeto, tamanho){
	if (objeto.value.length >= tamanho){
		objeto.value = objeto.value.substring(0,tamanho);
	}
}


function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function validarNews(){
	if (! validarEmail(document.frmCadastro.NCEmail.value)) {
		alert("Por favor, preencha o E-mail!");
		document.frmCadastro.NCEmail.focus();
		return false;
	}
	AbreJanela('','janNews','250','200','no');		
	return true;
}

function validarCPF(strCPF) {
	cpf = LimpaFormatoStr(strCPF);
	valor = true;
	erro = new String;
	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		  erro += "Numero de CPF invalido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		//alert(erro);
		return false;
	}
	return true;
}

function validarIgual(strTabela, strFiltro) {
	var strRetorno = verificaRegistro("Verifica_Existencia.asp?tabela=" + strTabela + "&filtro=" + strFiltro);
	var _ret;

	if (parseInt(strRetorno) == 0) {
		_ret = true;
	} else {
		_ret = false;		 
	}
	return _ret;
}

var obHttp = getHTTPObject(); // We create the HTTP Object

function getDataHora() {
	var currentTime = new Date();	
	var vRetorno = currentTime.getDate() + '-' + currentTime.getMonth() + '-' + currentTime.getFullYear() + '-' + currentTime.getHours() + '-' + currentTime.getMinutes() + '-' + currentTime.getSeconds() + '-' + currentTime.getMilliseconds();
	return vRetorno;
}

function verificaRegistro(Url){
	var url = Url;
	obHttp.open("GET", url + '&hashdh=' + getDataHora(), false);
	obHttp.send(null);
	return obHttp.responseText;
}

function executaURL(vURL) {
	var url = vURL;
	//alert(url);
	obHttp.open("GET", url + '&hashdh=' + getDataHora(), false);
	obHttp.send(null);
	return obHttp.responseText;
}

function executaURLSemHash(vURL){
	var url = vURL;
	//alert(url);
	obHttp.open("GET", url, false);
	obHttp.send(null);
	return obHttp.responseText;	
}

function getHTTPObject() {
  var xmlhttp;

  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
	  xmlhttp = new XMLHttpRequest();
	} catch (e) {
	  xmlhttp = false;
	}
  }
  return xmlhttp;
}


function verificaStatus(pFrm, pBtn){
	var status = executaURLSemHash('/asp/VerificaStatus.asp');
	if(status != ''){
		AbreJanela('/asp/login_per.asp?erro=5&e=1&frm=' + pFrm + '&btn=' + pBtn + '&per=' + escape(location.href), 'janLogin', 300, 250, 'no');
		return false;
	}else{
		return true;	
	}
}


function selecionaCombo(combo, codigo){
	for (x=1; x<= combo.length - 1;x++){
		if (parseInt(combo.options[x].value) == parseInt(codigo)){
			combo.selectedIndex = x;
		}
	}
}

function txtBoxFormat(Field, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla, mskLength;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	sValue = Field.value;
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	expressao = /[\.\/\-\(\)\,\;\: ]/gi;
	sValue = sValue.toString().replace(expressao, '');
	fldLen = sValue.length;
	mskLen = sMask.length;
	mskLength = mskLen
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;

	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ",") || (sMask.charAt(i) == ";") || (sMask.charAt(i) == ":"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++; 
		} else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}

		i++;
	}

	Field.value = sCod;

	if (nTecla != 8 && nTecla != 13) { // backspace enter
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58)); 
		} else { 
			if (sMask.charAt(i-1) == "x") { // apenas letras... Sem espaco
				return ((nTecla > 64) && (nTecla < 123)); 
			} else { // qualquer caracter...
				if (mskLen < mskLength){
					return true;
				}else{
					return false;
				}
			} 
		} 
	} else {
		return true;
	}
}

function existeOpcao (obCombo, vlrVerifica) {
	var temOpcao = false;
	var j = 0;
	for (j=0; j < obCombo.options.length; j++) {
		if (obCombo.options[j].text == vlrVerifica) {
			temOpcao = true;
			break;
		}
	}
	return temOpcao;
}

function retornaIndice (obCombo, vlrVerifica) {
	var _retorno = 0;
	var j = 0;
	for (j=0; j < obCombo.options.length; j++) {
		if (obCombo.options[j].text == vlrVerifica) {
			_retorno = j;
			break;
		}
	}
	return _retorno;
}

function aplicarAcentuacao(str){
	
	if (str.length > 0) {
		var acentos = Array('á','é','í','ó','ú','À','È','Ì','Ò','Ù','Á','É','Í','Ó','Ú','Ç','ç','ã','õ','Õ','Ã','ô','Ô','Â','â','î','Î','Û','û','ê','Ê', 'ü', 'Ü', '&', 'º','ª');
		var cod_acentos = Array("&#225;","&#233;","&#237;","&#243;","&#250;","&#192;","&#200;","&#204;","&#210;","&#217;","&#193;","&#201;","&#205;","&#211;","&#218;","&#199;","&#231;","&#227;","&#245;","&#213;","&#195;", "&#244;", "&#212;","&#194;","&#226;","&#238;","&#206;","&#219;","&#251;","&#234;","&#202;", "&#252;", "&#220;", "&amp;","&#186;","&#170;");
	
		for (i = 0; i < acentos.length; i++) {
			while (str.lastIndexOf(cod_acentos[i]) != -1) {
				str = str.replace(cod_acentos[i],acentos[i]);
			}
		}
	}
	return str;
}

function BuscaCEP(pCEP, obLogradouro, obBairro, obLocalidade, obUF, obNumero) {

	var CEP = LimpaFormatoStr(pCEP);
		
	if (CEP.length == 8) {
	
		var retCEP = executaURL("retornaendereco.asp?CEP=" + escape(CEP));

		if (retCEP != "") {
			retCEP = aplicarAcentuacao(retCEP);
	
			var arCEP = retCEP.split("\r\n");
			
			if (obLogradouro) {
				obLogradouro.value = arCEP[0];
			}

			if (obBairro) {
				obBairro.value = arCEP[1];
			}

			if (obLocalidade) {
				obLocalidade.value = arCEP[2];
			}

			if (obUF) {
				obUF.value = arCEP[3];
			}

			if (obNumero) {
				obNumero.focus();
			}
		}
	}
}
function PesquisaCEP(strNomeCampoCEP) {
	AbreJanela("RetornaEnderecoPesquisa.asp?Origem=Pop&Campo=" + strNomeCampoCEP, "janPesquisaCEP", 700, 450, 'yes')
}

function ignoraEnter(obCampo) {
	if ((event.keyCode == 13) || (event.keyCode == 10)){
		event.returnValue = false;
	}
}

function booleanToInt(vBool){
	if (vBool) {
		return 1;	
	} else {
		return 0;
	}
}

function Iif(pCondicao, pValorVerdadeiro, pValorFalso){
	if (pCondicao) {return pValorVerdadeiro;} else {return pValorFalso;}
}

function verificaPreenchido(obCampo, pMensagem, pBloco){
	vlrRetorno = true;
	if (obCampo.type == "text"){
		if (obCampo.value == "") {
			alert(pMensagem);
			if (pBloco != ""){ exibeAba(pBloco); }
			try {obCampo.focus();} catch (e) { }
			vlrRetorno = false;
		}
		return vlrRetorno;
	} else if (obCampo.type == "hidden"){
		if (obCampo.value == "") {
			alert(pMensagem);
			if (pBloco != ""){ exibeAba(pBloco); }
			vlrRetorno = false;
		}
		return vlrRetorno;			
	} else if (obCampo.type == "select-one") {
		if (obCampo.selectedIndex == 0) {
			alert(pMensagem);
			if (pBloco != ""){ exibeAba(pBloco); }
			try {obCampo.focus();} catch (e) { }
			vlrRetorno = false;
		}
		return vlrRetorno;			
	}
}

function removerElement(obPai, obRemover){
	try {
		var obRemover = document.getElementById(obRemover);
		document.getElementById(obPai).removeChild(obRemover);
	} catch (e) { }		
}

function buscaPlanoContas(pNivelBloqueado, pCampoChave, pCampoNome){
	AbreJanela('/produtos/PlanoContas_Listar.asp?Acao=4&Origem=Pop&PCCodBloqueado=' + pNivelBloqueado + '&CampoChave=' + pCampoChave + '&CampoNome=' + pCampoNome, 'janBuscarPlanoContas', 450, 450, 'yes');	
}

function buscaCentroCusto(pNivelBloqueado, pCampoChave, pCampoNome){
	AbreJanela('/produtos/CentroCusto_Listar.asp?Acao=4&Origem=Pop&CCustoCodBloqueado=' + pNivelBloqueado + '&CampoChave=' + pCampoChave + '&CampoNome=' + pCampoNome, 'janBuscarCentroCusto', 450, 450, 'yes');	
}

function buscaProdutosClassificacao(pNivelBloqueado, pCampoChave, pCampoNome){
	AbreJanela('/produtos/ProdutosClassificacao_Listar.asp?Acao=4&Origem=Pop&PClassCodBloqueado=' + pNivelBloqueado + '&CampoChave=' + pCampoChave + '&CampoNome=' + pCampoNome, 'janBuscarProdutosClassificacao', 450, 450, 'yes');	
}

function buscaEntidades(pCampoChave,pCampoTexto,pTitulo){
	if (pTitulo == undefined){ pTitulo=""; }
	if (pCampoChave==undefined) {pCampoChave="EntCod";}
	if (pCampoTexto==undefined) {pCampoTexto="EntNome";}
	AbreJanela('/produtos/Entidades_Listar.asp?Acao=4&Origem=PopCampo&NomeCampoChave='+pCampoChave+'&NomeCampoTexto='+pCampoTexto+'&Titulo=' + pTitulo, 'janEntidadesBuscar', 770, 520, 'yes');	
}

function buscaProdutos(pCampoChave,pCampoTexto,pFilCod,pPTPCod,pNumItem,pSimples,pTemBarras,pTitulo){
	if (pTitulo == undefined){ pTitulo=""; }
	if (pCampoChave==undefined) {pCampoChave="ProdCod";}
	if (pCampoTexto==undefined) {pCampoTexto="ProdNome";}
	if (pTemBarras==undefined) {pTemBarras="1";}
	if (pNumItem==undefined) {pNumItem="";}	
	if (pSimples==undefined) {pSimples="";}
	AbreJanela('/produtos/Produtos_Listar.asp?TemBarras='+pTemBarras+'&Acao=4&Origem=Pop&NumItem='+pNumItem+'&Simples='+pSimples+'&FilCod=' + pFilCod + '&PTPCod=' + pPTPCod + '&NomeCampoChave='+pCampoChave+'&NomeCampoTexto='+pCampoTexto, 'janProdutosBuscar', 770, 520, 'yes');
}

function AdicionaEndereco(pCampo, pNomeForm, pEntNome, pEntCod){
	if (pEntNome.value.length > 0){
		AbreJanela('/produtos/EntidadesEnderecos_Incluir.asp?Origem=Pop&NomeForm='+pNomeForm+'&EntCod='+pEntCod.value+'&CampoEndCodChave='+pCampo, 'janEndereco', 720, 250, 'yes');
	}
}	

function rastrear(strMensagem){
	alert("Desconsiderar esta mensagem!\n Rastreamento de teste sendo realizado pela equipe de Desenvolvimento FitWeb!\n\n" + strMensagem);			
}


function validarPesquisa(pForm){
	var vPreenchido = false;
	for (var i = 0; i < pForm.elements.length; i++) {
		if ((pForm.elements[i].type == "text") || ((pForm.elements[i].type == "select-one") && !(pForm.elements[i].name.indexOf("cb") == 0) )) {
			vPreenchido = vPreenchido || validarPreenchido(pForm.elements[i]);
		}
	}
	if (!vPreenchido) {
		alert("Para realizar esta pesquisa utilize ao menos um Filtro!");
	}
	return vPreenchido;
}

function validarPreenchido(obCampo){
	vlrRetorno = true;
	if (obCampo.type == "text"){
		if (obCampo.value == "") {
			vlrRetorno = false;
		}
	} else if (obCampo.type == "hidden"){
		if (obCampo.value == "") {
			vlrRetorno = false;
		}
	} else if (obCampo.type == "select-one") {
		if (obCampo.selectedIndex == 0) {
			vlrRetorno = false;
		}
	}
	return vlrRetorno;
}

function preencheCombo(pCombo,pCampos,pOrigem,pChave,pValorChave,pFiltro,pSelecionado) {
	
	vCampoOrdem = "2";
	var vURL = "../produtos/RetornaCampo.asp?Campo=" + pCampos
			 + "&Tabela=" + pOrigem
			 + "&Chave=" + escape(pChave)
			 + "&FiltroAdicional=" + pFiltro
			 + "&Limite=Nao"
			 + "&Filtro=" + escape(pValorChave)
			 + "&Ordem=" + vCampoOrdem;


	var strRetorno = executaURL(vURL);	
	
	if ((strRetorno.indexOf("Error") != -1) || (strRetorno.indexOf("OLE DB Provider") != -1)) {
		alert(strRetorno);
	}
	
	pCombo.options.length = 1;
	
	if (strRetorno != "" ) {
		strRetorno = aplicarAcentuacao(strRetorno);
		var arLista = strRetorno.split("\n");
		var indSel = 0;
		for (var j=0; j<arLista.length; j++){
			var arValores = arLista[j].split("#$#");
			pCombo.options[j+1] = new Option(arValores[1], arValores[0]);
			if (pSelecionado == arValores[0]) {
				indSel = j+1;
			}
		}
	}
	pCombo.selectedIndex = indSel;
}

function parametrosFilial(sFilCod,pCampos){
	var strRetorno = executaURL("../produtos/RetornaCampo.asp?Campo="+pCampos+"&Tabela=Parametros&Chave=FilCod&Limite=Nao&Filtro="+sFilCod);
	return strRetorno;
}

function retornaCampo(pCampos,pTabela,pChave,pFiltro,pSinalFiltro,pFiltroAdicional,pLimite){
	if (pSinalFiltro==undefined) {pSinalFiltro="";}
	if (pFiltroAdicional==undefined) { pFiltroAdicional = ""; }
	if (pLimite==undefined) { pLimite=""; } 	
	var strRetorno = executaURL("../produtos/RetornaCampo.asp?Campo="+pCampos+"&Tabela="+pTabela+"&Chave="+pChave+"&Limite="+pLimite+"&Filtro="+pFiltro+"&Sinal="+pSinalFiltro+"&FiltroAdicional="+pFiltroAdicional);
	return strRetorno;	
}