var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) { 
    var boleanoMascara; 

    var Digitato = evento.keyCode;
    exp = /\-|\.|\/|\(|\)| /g
    campoSoNumeros = campo.value.toString().replace( exp, "" ); 
   
    var posicaoCampo = 0;     
    var NovoValorCampo="";
    var TamanhoMascara = campoSoNumeros.length;; 

    if (Digitato != 8) { // backspace 
        for(i=0; i<= TamanhoMascara; i++) { 
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
                                || (Mascara.charAt(i) == "/")) 
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") 
                                || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " ")) 
            if (boleanoMascara) { 
                NovoValorCampo += Mascara.charAt(i); 
                  TamanhoMascara++;
            }else { 
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
                posicaoCampo++; 
              }            
          }     
        campo.value = NovoValorCampo;
          return true; 
    }else { 
        return true; 
    }
}

//adiciona mascara de data
function MascaraData(data){
    if(mascaraInteiro(data)==false){
        event.returnValue = false;
    }    
    return formataCampo(data, '00/00/0000', event);
}
function mascaraInteiro(){
    if (event.keyCode < 48 || event.keyCode > 57){
        event.returnValue = false;
        return false;
    }
    return true;
}

function MascaraCep(cep){
        if(mascaraInteiro(cep)==false){
        event.returnValue = false;
    }    
    return formataCampo(cep, '00.000-000', event);
}


function foco(){
	document.cadSite.nome.focus();
}

function checkformcadSite() {
	nome						= document.getElementById('nome').value;
	id_categoria_profissional	= document.getElementById('id_categoria_profissional').value;
	endereco					= document.getElementById('endereco').value;
	bairro						= document.getElementById('bairro').value;
	cidade						= document.getElementById('cidade').value;
	estado						= document.getElementById('estado').value;
	email						= document.getElementById('email').value;
	senha						= document.getElementById('senha').value;
	c_senha						= document.getElementById('c_senha').value;	
	
	if (nome == "") {
		alert("O nome é obrigatorio!");
		document.getElementById('nome').focus();
		return false;
	}

	if (id_categoria_profissional == "") {
		alert("É obrigatorio selecionar uma categoria profissional!");
		document.getElementById('categoria_profissional').focus();
		return false;
	}
	
	if (endereco == "") {
		alert("O endereço é obrigatorio!");
		document.getElementById('endereco').focus();
		return false;
	}

	if (bairro == "") {
		alert("O bairro é obrigatorio!");
		document.getElementById('bairro').focus();
		return false;
	}

	if (cidade == "") {
		alert("A cidade é obrigatorio!");
		document.getElementById('cidade').focus();
		return false;
	}

	if (estado == "") {
		alert("A uf é obrigatorio!");
		document.getElementById('estado').focus();
		return false;
	}
	
	if (!(er.test(email))) { 
		alert("O campo e-mail deve ser conter um endereço eletronico valido!");
		document.getElementById('email').focus();
		return false;
	}
	
	if (senha == "") {
		alert("A senha é obrigatorio!");
		document.getElementById('senha').focus();
		return false;
	}
	
	if (senha != c_senha) {
		alert("A confirmação da senha é inválida!");
		document.getElementById('senha').focus();
		return false;
	}

	return true;
}

function focoRecuperar(){
	document.formRecuperar.emailRecuperar.focus();
}

function checkformRecuperar() {
	email						= formRecuperar.emailRecuperar.value;
	
	if (!(er.test(email))) { 
		alert("O campo e-mail deve ser conter um endereço eletronico valido!");
		formRecuperar.emailRecuperar.focus();
		return false;
	}
	
	return true;
}

function validaLogin() {
	email						= formLogin.emailLogin.value;
	senha						= formLogin.senhaLogin.value;
	
	if (!(er.test(email))) { 
		alert("O campo e-mail deve ser conter um endereço eletronico valido!");
		formLogin.emailLogin.focus();
		return false;
	}

	if (!senha) { 
		alert("O campo senha deve ser preenchido!");
		formLogin.senhaLogin.focus();
		return false;
	}

	return true;
}

function checkformcadSitea() {
	nome						= document.getElementById('nome').value;
	id_categoria_profissional	= document.getElementById('id_categoria_profissional').value;
	endereco					= document.getElementById('endereco').value;
	bairro						= document.getElementById('bairro').value;
	cidade						= document.getElementById('cidade').value;
	estado						= document.getElementById('estado').value;
	
	if (nome == "") {
		alert("O nome é obrigatorio!");
		document.getElementById('nome').focus();
		return false;
	}

	if (id_categoria_profissional == "") {
		alert("É obrigatorio selecionar uma categoria profissional!");
		document.getElementById('categoria_profissional').focus();
		return false;
	}
	
	if (endereco == "") {
		alert("O endereço é obrigatorio!");
		document.getElementById('endereco').focus();
		return false;
	}

	if (bairro == "") {
		alert("O bairro é obrigatorio!");
		document.getElementById('bairro').focus();
		return false;
	}

	if (cidade == "") {
		alert("A cidade é obrigatorio!");
		document.getElementById('cidade').focus();
		return false;
	}

	if (estado == "") {
		alert("A uf é obrigatorio!");
		document.getElementById('estado').focus();
		return false;
	}
	
	return true;
}


function checkformalteraSenha() {
	senha_atual					= document.getElementById('senha_atual').value;
	nova_senha					= document.getElementById('nova_senha').value;
	c_senha						= document.getElementById('c_senha').value;	
	
	if (senha_atual == "") {
		alert("A senha atual não pode ser em branco!");
		document.getElementById('senha_atual').focus();
		return false;
	}


	if (nova_senha == "") {
		alert("A nova senha é obrigatorio!");
		document.getElementById('nova_senha').focus();
		return false;
	}
	
	if (nova_senha != c_senha) {
		alert("A confirmação da senha é inválida!");
		document.getElementById('nova_senha').focus();
		return false;
	}

	return true;
}

function focoAlterarSenha(){
	document.altSenha.senha_atual.focus();
}

function checkformAcesso() {
	emailAcesso					= document.getElementById('emailAcesso').value;
	senhaAcesso					= document.getElementById('senhaAcesso').value;
	
	if (!(er.test(emailAcesso))) { 
		alert("O campo e-mail deve ser conter um endereço eletronico valido!");
		document.getElementById('emailAcesso').focus();
		return false;
	}

	if (senhaAcesso == "") {
		alert("A senha é obrigatorio!");
		document.getElementById('senhaAcesso').focus();
		return false;
	}

	return true;
}

function focoAcesso(){
	document.Acesso.emailAcesso.focus();
}
