﻿   	PopularEstado();

    function PopularEstado() {
        var formEstado = new Form();
		formEstado.PostUrl = "FengShui/Services/Estados.aspx";
		formEstado.Form = document.getElementById("FormExperiencia");
		formEstado.callback = callbackEstado;
		formEstado.DoPost();
    }
    
    function callbackEstado() {
        if (http.readyState == 4) {
            var combo = document.getElementById("CodEstado");
            for(var i=combo.options.length-1;i>=0;i--)
                combo.options[i] = null;
            
            var estados = http.responseXML.getElementsByTagName("Estado");
            
            
            combo.options[0] = new Option("Selecione","");
            for(var i=0;i<estados.length;i++) {
                var opt = new Option(estados[i].childNodes[0].nodeValue,estados[i].attributes[0].value);
                
                combo.options[combo.options.length] = opt;
            }
        }
    }
    
    function PopularCidade(ComboEstado) {
        var formCidade = new Form();
		formCidade.PostUrl = "FengShui/Services/Cidades.aspx?CodEstado="+ ComboEstado.options[ComboEstado.selectedIndex].value;
		formCidade.Form = document.getElementById("FormExperiencia");
		formCidade.callback = callbackCidade;
		formCidade.DoPost();
    }
    
    function callbackCidade() {
        if (http.readyState == 4) {
            var combo = document.getElementById("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);
                
                combo.options[combo.options.length] = opt;
            }
        }
    }

    var form = new Form();
	form.Form = document.getElementById("FormExperiencia");

	form.NoRegistro = "Experiencia";
	form.NoErro = Array("Erro","ErroSistema");
	
	function enviarExperiencia() {
		form.PostUrl = "FengShui/Services/Experiencia.aspx";
		form.callback = callbackExperiencia;
		form.AdicionarValidacao("Nome","Preencha o campo \"Nome\".","vazio");
		form.AdicionarValidacao("Email","Preencha o campo \"E-mail\" com um endereço válido.","email");
		//form.AdicionarValidacao("Endereco","Preencha o campo \"Endereço\".","vazio");
		//form.AdicionarValidacao("Numero","Preencha o campo \"Número\".","vazio");
		//form.AdicionarValidacao("CEP","Preencha o campo \"CEP\".","vazio");
        form.AdicionarValidacao("CodEstado","Preencha o campo \"Estado\".","vazio");
		form.AdicionarValidacao("CodCidade","Preencha o campo \"Cidade\".","vazio");
		form.AdicionarValidacao("Mensagem","Preencha o campo \"Mensagem\".","vazio");

        //FAZER FUNÇÃO PARA VERIFICAR SE O CEP É VÁLIDO, NO FORM.JS

        if (document.getElementById("Concordo").checked == false)
        {
            alert ("Assinale o campo Concordo em ter a minha experiência e meus dados publicados no site Suvinil");
            return false;
        }

		if (form.DoPost())
		    document.getElementById("btEnviarExperiencia").disabled = true;
	}
	
	function callbackExperiencia() {
		if (http.readyState == 4) {
		    var msg = "";
		    if (http.responseXML.getElementsByTagName("Sucesso").length > 0)
		        msg = http.responseXML.getElementsByTagName("Sucesso")[0].childNodes[0].nodeValue;
		    else if (http.responseXML.getElementsByTagName("Erro").length > 0)
		        msg = http.responseXML.getElementsByTagName("Erro")[0].childNodes[0].nodeValue;
		        else if (http.responseXML.getElementsByTagName("ErroSistema").length > 0)
		        msg = http.responseXML.getElementsByTagName("ErroSistema")[0].childNodes[0].nodeValue;
            document.getElementById("FormExperiencia").style.display = "none";
            document.getElementById("divRespostaExperiencia").style.display = "block";
            document.getElementById("SpanRespostaExperiencia").innerHTML = msg;
            document.getElementById("btEnviarExperiencia").disabled = false;
		}
    }
    
    function voltar() {
        document.getElementById("FormExperiencia").style.display = "block";
		document.getElementById("divRespostaExperiencia").style.display = "none";
		document.getElementById("Nome").value = "";
		document.getElementById("Email").value = "";
		document.getElementById("Mensagem").value = "";
        //document.getElementById("Endereco").value = "";
        //document.getElementById("Numero").value = "";
        //document.getElementById("Complemento").value = "";
        //document.getElementById("CEP").value = "";
        document.getElementById("CodEstado").selectedIndex = 0;
        document.getElementById("CodCidade").selectedIndex = 0;
    }