﻿    var form;
    var CodCidade = 0;
    
    function gE(id){return document.getElementById(id)}

	function EnviarCasaClaudia() {
        form = new Form();
        form.Form = gE("FormCasaClaudia");
	    form.PostUrl = "CasaClaudia/Services/CasaClaudia.aspx";
	    form.callback = callback;
                   
	    if (form.DoPost())
	        gE("btEnviarCasaClaudia").disabled = true;
        else if (gE("Nascimento").value == "")
            gE("Nascimento").value = "(dd/mm/aaaa)";
    }

	// Resultado do envio do form
function callback() {
	if (http.readyState == 4) {
		var xml = http.responseXML;
		if (xml.getElementsByTagName("Erro").length > 0) {
            alert("Atenção. "+ xml.getElementsByTagName("Erro")[0].childNodes[0].nodeValue);
		} else if (xml.getElementsByTagName("ErroSistema").length > 0) {
		    alert("Ocorreu um erro no sistema, contate o administrador e forneça a seguinte mensagem: \""+ xml.getElementsByTagName("ErroSistema")[0].childNodes[0].nodeValue +"\"");
		} else {
		    gE("FormCasaClaudia").style.display = "none";
		    gE("divRespostaCasaClaudia").style.display = "block";		
		    gE("SpanRespostaCasaClaudia").innerHTML = xml.getElementsByTagName("Sucesso")[0].childNodes[0].nodeValue;
		    gE("divTopCasaClaudia").style.display = "none";
		    limparCampos();
		}
		gE("btEnviarCasaClaudia").disabled = false;
	}
}
    
    function limparCampos(){
        if (gE("Nome") != null) 
            gE("Nome").value = "";
        if (gE("Sobrenome") != null)
            gE("Sobrenome").value = "";
        if (gE("Email") != null)
            gE("Email").value = "";
        if(document.forms["FormCasaClaudia"].Sexo[0] != null)
            document.forms["FormCasaClaudia"].Sexo[0].checked = false;
        if(document.forms["FormCasaClaudia"].Sexo[1] != null)
            document.forms["FormCasaClaudia"].Sexo[1].checked = false;
        if (gE("Nascimento") != null)
            gE("Nascimento").value = "dd/mm/aaaa";
        if (gE("Rg") != null)
            gE("Rg").value = "";
        if (gE("Cpf") != null)
	        gE("Cpf").value = "00000000000";        
        if (gE("Endereco") != null)
            gE("Endereco").value = "";
        if (gE("Numero") != null)
            gE("Numero").value = "";
        if (gE("Complemento") != null)
            gE("Complemento").value = "";
        if (gE("CodEstado") != null)
            gE("CodEstado").selectedIndex = 0;
        if (gE("CodCidade") != null)
            gE("CodCidade").selectedIndex = 0;
        if (gE("DddTelefone") != null)
            gE("DddTelefone").value = "";
        if (gE("Telefone") != null)
            gE("Telefone").value = "";
        if (gE("DddCelular") != null)
            gE("DddCelular").value = "";
        if (gE("Celular") != null)
            gE("Celular").value = "";
        if (gE("Perfil") != null)
            gE("Perfil").selectedIndex = 0;
        if (gE("OptInInternet") != null)
            gE("OptInInternet").checked = true;
        if (gE("OptInCelular") != null)
            gE("OptInCelular").checked = true;
        if (gE("OptInCorreio") != null)
            gE("OptInCorreio").checked = true;
    }

    function voltar() {
        gE("FormCasaClaudia").style.display = "block";
	    gE("divRespostaCasaClaudia").style.display = "none";
	    gE("SpanRespostaCasaClaudia").innerHTML = "";
    }

    function PopularCidade(ComboEstado) {
        var formCidade = new Form();
        formCidade.Form = gE("FormCasaClaudia");
	    formCidade.PostUrl = "CasaClaudia/Services/Cidades.aspx?CodEstado="+ ComboEstado.options[ComboEstado.selectedIndex].value;
    	
	    formCidade.callback = callbackCidade;
	    formCidade.DoPost();
    }

    function callbackCidade() {
        if (http.readyState == 4) {
            var combo = gE("CodCidade");
            for(var i=combo.options.length-1;i>=0;i--)
                combo.options[i] = null;
            var cidades = http.responseXML.getElementsByTagName("Cidade");        
            combo.options[0] = new Option("Selecione","");
            for(var i=0;i<cidades.length;i++) {
                var opt = new Option(cidades[i].childNodes[0].nodeValue,cidades[i].attributes[0].value);
                
                if (opt.value == CodCidade)
                    opt.selected = true;
                combo.options[combo.options.length] = opt;
            }
        }
    }
   
    function mascaraNumero(obj,evento) {
        ascii = (evento.keyCode) ? evento.keyCode : evento.which;
        if(ascii == 8 || ascii == 9 || ascii == 13 || ascii == 116 || ascii == 37 || ascii == 39 || ascii == 36 || ascii == 35 || ascii == 46)
            return true;
        if (/\D/.test(String.fromCharCode(ascii)))
            return false;
        return true;
    }

    function escolheProfissao() {
        if(document.getElementById("Perfil").value == 0 || document.getElementById("Perfil").value == 5 || document.getElementById("Perfil").value == 2) {
            document.getElementById("lbCrea").style.display = "";
            document.getElementById("Crea").style.display = "";
        }
        else {
            document.getElementById("lbCrea").style.display = "none";
            document.getElementById("Crea").style.display = "none";
        }
    }
    
    
 
    function soCaracter(campo){
        var regexTexto = /^[a-z' 'A-ZãÃáÁàÀêÊéÉèÈíÍìÌôÔõÕóÓòÒúÚùÙûÛçÇ.;:,ºª]+$/;
        
        if ( regexTexto.test(campo.value)) {
            return true;
        }
        else{
            campo.value = '';
            campo.focus();
            return false;
        }
    }