


function checaMask(src, evento, objeto){

	if (evento.keyCode) tecla = evento.keyCode;       
	else if (evento.which) tecla = evento.which; // Netscape 4.?   
	else if (evento.charCode) tecla = evento.charCode; // Mozilla  

	if (tecla == 8){
		if (objeto == 1){
			if (src.value.length == 3 || src.value.length == 7 || src.value.length == 11 || src.value.length == 16){
				src = src.value.substring(0,src.value.length-1);
			}
			else if (objeto == 2){
				if (src.value.length == 6){
					src = src.value.substring(0,src.value.length-1);
				}
			}
		else if (objeto == 3){
			if (src.value.length == 3 || src.value.length == 8)
				src = src.value.substring(0,src.value.length-1);
			}
		}
	}
	else{
		if (objeto == 1){
			if (src.value.length == 2 || src.value.length == 6){
				src.value += '.';
			}
			else if (src.value.length == 10) {
				src.value += '/';
			}
			else if (src.value.length == 15){
				src.value +=  '-';
			}
		}
		else if (objeto == 2){
			if (src.value.length == 5){
				src.value += '-';
			}				
		}
		else if (objeto == 3){
			if (src.value.length == 2){
				src.value += ' ';
			}				
			if (src.value.length == 7){
				src.value += '-';
			}				
		}			
		if (objeto == 4){
			if (src.value.length == 3 || src.value.length == 7){
				src.value += '.';
			}
			else if (src.value.length == 11){
				src.value +=  '-';
			}
		}
		if (objeto == 5){
			if (src.value.length == 2 || src.value.length == 5 ){
				src.value += "/";
			}
		}
	}
}
		
 //Permite digitar apenas números
	function jNumero(evento){
		if (evento.keyCode) tecla = evento.keyCode;       
		else if (evento.which) tecla = evento.which; // Netscape 4.?   
		else if (evento.charCode) tecla = evento.charCode; // Mozilla  
			if((tecla > 47 && tecla < 58)) return true;
			else{
			if (tecla != 8) return false;
			else return true;
		}
			
	}
	
	function buscaEndereco(){
		if(document.cadastro.cep.value.length!=9)
		{
			alert("Preencha o campo CEP corretamente.");
			document.cadastro.cep.focus();
		}
		else
		{
			document.cadastro.btnbuscarendereco.disabled="disabled";
			document.cadastro.btnbuscarendereco.value="aguarde...";
			window.frames["iframebuscacep"].location =  "busca_endereco.php?cep="+document.cadastro.cep.value;
		}
	}
	
	function VerificaCPF(){
		if (vercpf(document.frmcpf.cpf.value)){
			document.frmcpf.submit();
		}
		else{
			errors="1";
			if (errors) alert('CPF NÃO VÁLIDO');
				document.retorno = (errors == '');
		}
	}
	
	function validaCPF(ncpf){
		/*
		if ((cpf.charAt(3) != ".") || (cpf.charAt(8) != ".") || (cpf.charAt(12) != "-")){
			if (erro.length == 0) erro += "É necessário preencher corretamente o número do CPF! \n\n";
		}
		*/
		
		cpf = ncpf.substring(0,3) + ncpf.substring(4,7) + ncpf.substring(8,11) + ncpf.substring(12);
		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;
		add = 0;
		for (i=0; i < 9; i ++)
			add += parseInt(cpf.charAt(i)) * (10 - i);
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
			rev = 0;
		if (rev != parseInt(cpf.charAt(9)))
			return false;
		add = 0;
		for (i = 0; i < 10; i ++)
			add += parseInt(cpf.charAt(i)) * (11 - i);
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
			rev = 0;
		if (rev != parseInt(cpf.charAt(10)))
			return false;
		return true;
	}
	
	
	function validaCNPJ(CNPJ) {
		//CNPJ = document.validacao.CNPJID.value;
		erro = new String;
		if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n";
		if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
			if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
		}
		//substituir os caracteres que n&atilde;o s&atilde;o números
               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 verifica&ccedilão de CNPJ suporta apenas números! \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 +="Dígito verificador com problema!";
               }
               if (erro.length > 0){
                       //alert(erro);
                       return false;
               } else {
                       //alert("CNPJ valido!");
					   return true;
               }
               return true;
       }
	   
	function validaEMAIL(email)
	{
		if ((email.indexOf("@") == -1) && (email.indexOf(".") == -1))
		{
			return false;
		}
		else
		{
			return true;
		}
		
	}

	function validaCampos(){	
	//alert("validando campos");
	if (window.document.getElementById("razaosocial").value == "")
		{
			alert("O campo RAZÃO SOCIAL é de preenchimento obrigatório.");
			window.document.getElementById("razaosocial").focus();
			return false;
		}
		
		if (window.document.getElementById("cnpj").value == "")
		{
			alert("O campo CNPJ é de preenchimento obrigatório.");
			window.document.getElementById("cnpj").focus();
			return false;
		}
		else
		{
			if (validaCNPJ(window.document.getElementById("cnpj").value) == false)
			{
				alert("Insira um CNPJ válido.");
				return false;
			}
			
		}
		
		if (window.document.getElementById("responsavel").value == "")
		{
			alert("O campo Responsável / Contato é de preenchimento obrigatório.");
			window.document.getElementById("responsavel").focus();
			return false;
		}
	
	if (window.document.getElementById("endereco").value == "")
	{
		alert("O campo ENDERE&Ccedil;O é de preenchimento obrigatório.");
		window.document.getElementById("endereco").focus();
		return false;
	}
	
	if (window.document.getElementById("numero").value == "")
	{
		alert("O campo NÚMERO é de preenchimento obrigatório.");
		window.document.getElementById("numero").focus();
		return false;
	}
	
		
	if (window.document.getElementById("bairro").value == "")
	{
		alert("O campo BAIRRO é de preenchimento obrigatório.");
		window.document.getElementById("bairro").focus();
		return false;
	}
	
	if (window.document.getElementById("cidade").value == "")
	{
		alert("O campo CIDADE é de preenchimento obrigatório.");
		window.document.getElementById("cidade").focus();
		return false;
	}
	
	if (window.document.getElementById("estado").value == "")
	{
		alert("Selecione um ESTADO.");
		window.document.getElementById("estado").focus();
		return false;
	}
	
	if (window.document.getElementById("cep").value == "")
	{
		alert("O campo CEP é de preenchimento obrigatório.");
		window.document.getElementById("cep").focus();
		return false;
	}
	
	if (window.document.getElementById("email").value == "")
	{
		alert("O campo EMAIL é de preenchimento obrigatório.");
		window.document.getElementById("email").focus();
		return false;
	}
	
	Email = window.document.getElementById("email").value;
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;
	
	if(((Email.search(exclude) != -1)||(Email.search(check)) == -1)||(Email.search(checkend) == -1))
	{
       	alert("Digite um EMAIL válido.");
		window.document.getElementById("email").focus();
		return false;
	}
		
	if (window.document.getElementById("telefone2").value == "")
	{
		alert("O campo TELEFONE é de preenchimento obrigatório.");
		window.document.getElementById("telefone2").focus();
		return false;
	}
	/*
	if (window.document.getElementById("senha").value == "")
	{
		alert("O campo SENHA é de preenchimento obrigatório.");
		window.document.getElementById("senha").focus();
		return false;
	}
	
	if (window.document.getElementById("senha").value.length < 6 || window.document.getElementById("senha").value.length > 10)
	{
		alert("O tamanho da SENHA deve ser entre 6 e 10 caracteres.");
		window.document.getElementById("senha").focus();
		return false;
	}
	
	
	else
	{
		if (window.document.getElementById("senha").value != window.document.getElementById("senhaconfirma3").value)
		{
			alert("A Senha n&atilde;o confere com a confirma&ccedilão.");
			window.document.getElementById("senha").focus();
			return false;
		}
	}
	*/
	
	window.document.cadastro.submit();
	return true;
}

	function validaCred(){	
	// alert("validando campos");
	if (window.document.getElementById("profissional").value == "")
		{
			alert("O campo NOME DO PROFISSIONAL é de preenchimento obrigatório.");
			window.document.getElementById("profissional").focus();
			return false;
		}
		
		if (window.document.getElementById("CPF").value == "")
		{
			alert("O campo CPF é de preenchimento obrigatório.");
			window.document.getElementById("CPF").focus();
			return false;
		}
		else
		{
			if (validaCPF(window.document.getElementById("CPF").value) == false)
			{
				alert("Insira um CPF válido.");
				return false;
			}
			
		}
		
	if (window.document.getElementById("CRO").value == ""){
		alert("O campo CRO é de preenchimento obrigatório.");
		window.document.getElementById("CRO").focus();
		return false;
	}

		
	if (window.document.getElementById("endereco").value == "")
	{
		alert("O campo ENDEREÇO é de preenchimento obrigatório.");
		window.document.getElementById("endereco").focus();
		return false;
	}
	
	if (window.document.getElementById("numero").value == "")
	{
		alert("O campo NÚMERO é de preenchimento obrigatório.");
		window.document.getElementById("numero").focus();
		return false;
	}
	
		
	if (window.document.getElementById("bairro").value == "")
	{
		alert("O campo BAIRRO é de preenchimento obrigatório.");
		window.document.getElementById("bairro").focus();
		return false;
	}
	
	if (window.document.getElementById("cidade").value == "")
	{
		alert("O campo CIDADE é de preenchimento obrigatório.");
		window.document.getElementById("cidade").focus();
		return false;
	}
	
	if (window.document.getElementById("estado").value == "")
	{
		alert("Selecione um ESTADO.");
		window.document.getElementById("estado").focus();
		return false;
	}
	
	if (window.document.getElementById("cep").value == "")
	{
		alert("O campo CEP é de preenchimento obrigatório.");
		window.document.getElementById("cep").focus();
		return false;
	}
	
	if (window.document.getElementById("email").value == "")
	{
		alert("O campo EMAIL é de preenchimento obrigatório.");
		window.document.getElementById("email").focus();
		return false;
	}
	
	Email = window.document.getElementById("email").value;
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;
	
	if(((Email.search(exclude) != -1)||(Email.search(check)) == -1)||(Email.search(checkend) == -1))
	{
       	alert("Digite um EMAIL válido.");
		window.document.getElementById("email").focus();
		return false;
	}
		
	if (window.document.getElementById("telefone2").value == "")
	{
		alert("O campo TELEFONE é de preenchimento obrigatório.");
		window.document.getElementById("telefone2").focus();
		return false;
	}

	if (window.document.getElementById("faculdade").value == "")
	{
		alert("O campo FACULDADE é de preenchimento obrigatório.");
		window.document.getElementById("faculdade").focus();
		return false;
	}

	
	if (window.document.getElementById("especial").value == "")
	{
		alert("O campo ESPECIALIDADE é de preenchimento obrigatório.");
		window.document.getElementById("especial").focus();
		return false;
	}

	if (window.document.getElementById("atuacao").value == "")
	{
		alert("O campo ATUAÇÃO é de preenchimento obrigatório.");
		window.document.getElementById("atuacao").focus();
		return false;
	}

	window.document.cadastro.submit();
	return true;
}


/*formulário de troca de senha e gravação de email*/
function validaconfirma(antiga, inicial, formulario){

	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;

	if (document.getElementById("senha1").value == ""){
		alert('Informe a senha antiga.');
		document.getElementById("senha1").focus();
		return false;
	}

    if (document.getElementById("senha1").value != antiga) {
		alert('Senha atual incorreta.');
		document.getElementById("senha1").focus();
		return false;
    }

    if (document.getElementById("senha2").value == inicial) {
		alert('Nova senha não pode ser igual a senha inicial.');
		document.getElementById("senha2").focus();
		return false;
    }

	if (document.getElementById("senha2").value == ""){
		alert('Informe a nova senha.');
		document.getElementById("senha2").focus();
		return false;
	}
	
	if (document.getElementById("senha3").value == ""){
		alert('Confirme a nova senha.');
		document.getElementById("senha3").focus();
		return false;
	}	

	if (document.getElementById("email1").value == ""){
		alert('Informe seu e-mail.');
		document.getElementById("email1").focus();
		return false;
	}	

	Email = window.document.getElementById("email1").value;
	
	if(((Email.search(exclude) != -1)||(Email.search(check)) == -1)||(Email.search(checkend) == -1))
	{
       	alert("Digite um EMAIL válido.");
		window.document.getElementById("email1").focus();
		return false;
	}	

	if (document.getElementById("senha2").value.length  < 6 || document.getElementById("senha2").value.length  > 12){
		alert('Tamanho incorreto da nova senha.')
		document.getElementById("senha3").value = "";
		document.getElementById("senha2").focus();
		return false;
	}
		
	if (document.getElementById("senha2").value != document.getElementById("senha3").value){
		alert('Verificar nova senha.');
		document.getElementById("senha3").value = "";
		document.getElementById("senha2").focus();
		return false;
	}
	
	if (formulario == 1)
		window.document.cadsenha.submit();
	else
		window.document.altsenha.submit();
		
	return true;
		
}

