function busca(valor,teclapres){
   var tecla = 0;
   if(document.all){
        tecla = teclapres.keyCode;
    }
    else{
      tecla = teclapres.which;
      if(tecla==1){tecla=0}
    }
    if (tecla == 13 || tecla == 0){
       if(document.formBusca.txtcriterio.value==''){
			alert('Informe um critério de busca!');
			document.formBusca.txtcriterio.focus();
		}
		else{
			document.formBusca.action='?ac=busca';
			document.formBusca.submit();
		}
   } 
}
function acessarSistema(){
	if(document.form.txtCPF.value==''||document.form.txtSenha.value==''){
		alert('Informe seu CPF e Senha!');
	}else{
		document.form.action='acesso?ac=verificar_acesso';
		document.form.submit();
	}
}
function escondeDiv(div){
	document.getElementById(div).innerHTML="";
	document.getElementById(div).style.visibility="hidden";
}

function CheckNums(campo,teclapres) {
	var tecla = 0;
	
	if(document.all){
        tecla = teclapres.keyCode;
    }
    else{
      tecla = teclapres.which;
      if(tecla==1){tecla=0}
    }
	
	if ((tecla < 48) || (tecla > 57)) {
		return false;
	}
}

function validaData(pValor,nome){
	if(document.form.elements[nome].value!='' && validarDataYYYY(pValor)=='F'){
		alert('Data incorreta!');
		document.form.elements[nome].value='';
		document.form.elements[nome].focus();
	}
}

function validaEmail(Email){
	var filter = /^(([a-zA-Z0-9_-])+(([\.\])+([a-zA-Z0-9_-]{0,1})))+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
	var arrayEmail = Email.split(";"); //Separa os email 
	for (var i=0;i < arrayEmail.length; i++){ //varre a lista de emails 
		if ( !filter.test(arrayEmail[i]) ){ 
			return false; //se tiver erro sai com false 
		}
		else{ 
			return true; // se nao achou erro retorrna verdadeiro 
		}
	}
} 
function CaixaBaixa(fsValor, foForm, foNome) { 
	if (window.event.keyCode >= 65 && window.event.keyCode <= 90){
		x = new String(document.forms[foForm].elements[foNome].value);
		document.forms[foForm].elements[foNome].value = x.toLowerCase();
	}
} 
function enviarEmail(){
	if(document.form.txtNome.value==''){
		alert('Informe um nome!');
		document.form.txtNome.focus();
	}
	else if(document.form.txtEmail.value==''){
		alert('Informe um e-mail!');
		document.form.txtEmail.focus();
	}
	else if(validaEmail(document.form.txtEmail.value)==false){
		alert('E-mail inválido');
		document.form.txtEmail.value = '';
	}
	else if(document.form.txtAssunto.value==''){
		alert('Informe um assunto!');
		document.form.txtAssunto.focus();
	}
	else if(document.form.txtMsg.value==''){
		alert('Digite uma mensagem!');
		document.form.txtMsg.focus();
	}
	else{
		document.form.action='?ac=contato';
		document.form.submit();
	}
}

function consulta(){
	if(document.form.txtNome.value==''){
		alert('Informe um nome!');
		document.form.txtNome.focus();
	}
	else if(document.form.txtDataNascimento.value==''){
		alert('Informe sua data de nascimento!');
		document.form.txtDataNascimento.focus();
	}
	else if(document.form.txtEmail.value==''){
		alert('Informe um e-mail!');
		document.form.txtEmail.focus();
	}
	else if(validaEmail(document.form.txtEmail.value)==false){
		alert('E-mail inválido');
		document.form.txtEmail.value = '';
	}
	else if(document.form.txtDataPreferencia.value==''){
		alert('Informe uma data para a consulta!');
		document.form.txtDataPreferencia.focus();
	}
	else if(document.form.cboHorasInicio.value==0||document.form.cboHorasFim.value==0){
		alert('Selecione um horário!');
	}
	else{
		document.form.action='?ac=agendar';
		document.form.submit();
	}
}

function validarDataYYYY(vValor){ 
    var checkStr = ''; 
	checkStr = vValor; 
	var err=0; 
    var psj=0; 
	var dia = 0; 
	var mes = 0; 
	var ano = 0; 
	var barra1 = ''; 
	var barra2 = ''; 
       	dia = checkStr.substring(0, 2); 
       	barra1 = checkStr.substring(2, 3); 
       	mes = checkStr.substring(3, 5); 
       	barra2 = checkStr.substring(5, 6); 
	    ano = checkStr.substring(6, 10); 
    	    //verifica??es b?sicas 
    	    if (checkStr.length != 10) 
				err = 1; 
    	    if (mes<1 || mes>12) 
				err = 1; 
    	    if (barra1 != '/') 
				err = 1; 
    	    if (dia<1 || dia>31) 
				err = 1; 
    	    if (barra2 != '/') 
				err = 1; 
    	    if (ano<1900 || ano>2900) 
				err = 1; 
    	    //verifica??es avan?adas 
    	    // m?s com 30 dias 
    	    if (mes==4 || mes==6 || mes==9 || mes==11){ 
    		   if (dia==31) 
			   		err=1; 
    	    } 
    	    // fevereiro e ano bissexto 
    	    if (mes==2){ 
    		    var g = parseInt(ano/4); 
    		    if (isNaN(g)) { 
    			    err=1; 
    		    } 
    		    if (dia>29) 
					err=1; 
    		    if (dia==29 && ((ano/4)!=parseInt(ano/4))) 
					err=1; 
    	    } 
    if (err==1) 
       return 'F'; 
	else 
	   return 'T'; 
}

function validarCPF(CPF){ 
	if (CPF != ''){ 
		if (!verificarCPF(CPF)){ 
			alert('CPF Inválido!'); 
			document.form.txtCPF.value=''; 
			document.form.txtCPF.focus(); 
		} 
	} 
}  

function verificarCPF(c){ 
	c = c.replace('.','');	
	c = c.replace('.','');	
	c = c.replace('-','');	
	var i;  
	s = c; 
	var c = s.substr(0,9);  
	var dv = s.substr(9,2);  
	var d1 = 0;  
	var v = false; 
	for (i = 0; i < 9; i++)  
	{  
		d1 += c.charAt(i)*(10-i);  
	}  
	if (d1 == 0){  
	v = true;  
	return false;  
	}  
	d1 = 11 - (d1 % 11);  
		if (d1 > 9) d1 = 0;  
			if (dv.charAt(0) != d1)  
			{  
		v = true; 
		return false;  
	}  
	d1 *= 2;  
	for (i = 0; i < 9; i++) {  
		d1 += c.charAt(i)*(11-i);  
	}  
	d1 = 11 - (d1 % 11);  
	if (d1 > 9) d1 = 0;  
		if (dv.charAt(1) != d1)  
	{  
	v = true; 
	return false;  
	}  
	if (!v) { 
	return true; 
	} 

	
}

function formatarCPF (campo,teclapres) { 
	var tecla = teclapres.keyCode;  
	if ((tecla < 48) || (tecla > 57)) {
		return false;
	} 
	vr = campo.value;  
	vr = vr.replace( '-', '' );  
	vr = vr.replace( '.', '' );  
	vr = vr.replace( '.', '' );  
	tam = vr.length; 
	 
	if (tam < 11 && 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 <= 2 ){  
	 		campo.value = vr ; }  
	 	if ( (tam > 2) && (tam <= 5) ){  
	 		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }  
	 	if ( (tam >= 6) && (tam <= 8) ){  
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, 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 - 2, tam ) ; }  
	}
}

function formatarDataYYYY(campo, teclapres) { 
	var tecla = teclapres.keyCode;  
	vr = campo.value;  
	vr = vr.replace( '/', '' );  
	vr = vr.replace( '/', '' );  
	tam = vr.length + 1;  
	if ( tecla != 9 && tecla != 8 ) {  
	   if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {  
		   if ( tam <= 2 ) campo.value = vr ;  
		   if ( tam > 2 && tam < 5 ) campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, tam );  
		   if ( tam >= 5 && tam <= 10 ) campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, tam );   
      }  
   }  
}  
