function inicializarCadastroDeAgencias()
{
	var oFrm = document.getElementById("frmCadastroAgencia");	//formulário de cadastro de agências
	var oEnviar = document.getElementById("btnEnviar");	
	addEvent(oEnviar,"click",validarFormulario);
	
	function validarFormulario()
	{		
		var regExpEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;		
		var sTxtCnpj = oFrm.txtCnpj.value.trim();
		var sTxtEmail = oFrm.txtEmail.value.trim();
		var sTxtCep = oFrm.txtCep.value.trim();
		var sTxt = oFrm.txtMensagem.value.trim();
		var sTxtTelefone = oFrm.txtTelefone.value.trim();
		var sTxtFax = oFrm.txtFax.value.trim();
		var sTxtMensagem = oFrm.txtMensagem.value.trim();

		if (sTxtEmail == "") {
		    alert("Por favor, preencha um email.");
		    return false;
		}

		if (!regExpEmail.test(sTxtEmail)) {
		    alert("Por favor, digite um email válido.");
		    return false;
		}

		if (sTxtMensagem.length > 500) {
		    alert("O campo Mensagem só permite 500 caracteres.");
		    return false;
		}
        		
		enviarEmail();
	}
	
	function enviarEmail()
	{		
		//verifica se tem contato cadastrado no SiteUP
		if (window.document.getElementById("txtHidRemetente"))
		{ 		
			/*
            var sParametros = "";			
			sParametros += "acao=CA";			
			sParametros += "&txtHidRemetente=" + escape(window.document.getElementById("txtHidRemetente").value);
			sParametros += "&txtHidDestinatarios=" + escape(window.document.getElementById("txtHidDestinatarios").value);			
			sParametros += "&txtHidCopia=" + escape(window.document.getElementById("txtHidCopia").value);			
			sParametros += "&txtHidAssunto=" + escape(window.document.getElementById("txtHidAssunto").value);			
			sParametros += "&txtRazaoSocial=" + escape(window.document.getElementById("txtRazaoSocial").value);
			sParametros += "&txtNomeFantasia=" + escape(window.document.getElementById("txtNomeFantasia").value);
			sParametros += "&txtCnpj=" + escape(window.document.getElementById("txtCnpj").value);
			sParametros += "&txtEmbratur=" + escape(window.document.getElementById("txtEmbratur").value);
			sParametros += "&txtIata=" + escape(window.document.getElementById("txtIata").value);
			sParametros += "&txtAgente=" + escape(window.document.getElementById("txtAgente").value);
			sParametros += "&txtEmail=" + escape(window.document.getElementById("txtEmail").value);
			sParametros += "&txtEndereco=" + escape(window.document.getElementById("txtEndereco").value);
			sParametros += "&txtBairro=" + escape(window.document.getElementById("txtBairro").value);
			sParametros += "&txtCep=" + escape(window.document.getElementById("txtCep").value);
			sParametros += "&txtCidade=" + escape(window.document.getElementById("txtCidade").value);
			sParametros += "&cmbEstado=" + escape(window.document.getElementById("cmbEstado").options[window.document.getElementById("cmbEstado").selectedIndex].value);
			sParametros += "&txtTelefone=" + escape(window.document.getElementById("txtTelefone").value);
			sParametros += "&txtFax=" + escape(window.document.getElementById("txtFax").value);
			sParametros += "&txtPaginaWeb=" + escape(window.document.getElementById("txtPaginaWeb").value);
			sParametros += "&txtMensagem=" + escape(window.document.getElementById("txtMensagem").value);
			sParametros += "&cmbPromocaoEmail=" + escape(window.document.getElementById("cmbPromocaoEmail").options[window.document.getElementById("cmbPromocaoEmail").selectedIndex].value);
			sParametros += "&cmbProgramacaoImpressa=" + escape(window.document.getElementById("cmbProgramacaoImpressa").options[window.document.getElementById("cmbProgramacaoImpressa").selectedIndex].value);
			
			if(window.ActiveXObject)
			{
				var oHttpRequest = new ActiveXObject("Microsoft.xmlHttp");
			}
			else if (window.XMLHttpRequest) // Mozilla, Safari, ...
			{
				var oHttpRequest = new XMLHttpRequest();
				oHttpRequest.overrideMimeType('text/xml');
			}

            */

            document.frmCadastroAgencia.target = "ifrmEnvio";
            document.frmCadastroAgencia.action = "a_envioDeEmail.asp";
            document.frmCadastroAgencia.submit();
			
            /*
			var sUrl = "a_envioDeEmail.asp?" + sParametros;			
			oHttpRequest.open("GET",sUrl,true);			
			oHttpRequest.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			oHttpRequest.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			oHttpRequest.setRequestHeader("Pragma", "no-cache");
			oHttpRequest.onreadystatechange = exibirMensagemDeEnvio;		
			oHttpRequest.send(null);
            */
		}
		else
		{
			alert("Não foi possível enviar este formulário. Favor entrar em contato pelo e-mail info@fuiviagens.com.br");
		}
		
		function exibirMensagemDeEnvio()
		{
			if(oHttpRequest.readyState == 4 && oHttpRequest.status == 200)
			{
				alert(oHttpRequest.responseText);
				var sCodHome = document.getElementById("codHome").value;
				window.location.href = "PaginaDinamica.asp?Grupo=" + sCodHome;
			}
		}
	}
}

var oTxtCnpj=document.getElementById("txtCnpj");
if (oTxtCnpj)
{
	oTxtCnpj.onkeypress=function(){mascara(oTxtCnpj,mskCNPJ)};
}

var oTxtCep=document.getElementById("txtCep");
if (oTxtCep)
{
	oTxtCep.onkeypress=function(){ mascara(oTxtCep,mskCEP) };
}

var oTxtCidade=document.getElementById("txtCidade");
if (oTxtCidade)
{
	oTxtCidade.onkeypress=function(){ mascara(oTxtCidade,MaskTexto) };
}

var oTxtTelefone=document.getElementById("txtTelefone");
if (oTxtTelefone)
{
	oTxtTelefone.onkeypress=function(){ mascara(oTxtTelefone,mskTEL_FAX) };
}

var oTxtFax=document.getElementById("txtFax");
if (oTxtFax)
{
	oTxtFax.onkeypress=function(){ mascara(oTxtFax,mskTEL_FAX) };
}

addEvent(window,"load",inicializarCadastroDeAgencias);
