function cadastro()
{
	
	ajaxFuncao("http://localhost/laudotec/enviaremail", "email=" + form.email.value, "divCadastro", "divCadastro", "<span class='texto'>Enviando...</span>");
}

function ajaxFuncao(url, parametros, div, divCarrega, msgCarrega)
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml12.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");			
			}
			catch(e)
			{
				alert("Seu navegador não suporta AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange = function()
	{		
		if(xmlHttp.readyState==4)
		{
			document.getElementById(divCarrega).innerHTML = "";
			document.getElementById(div).innerHTML = xmlHttp.responseText;
		}
		
	}	
	document.getElementById(divCarrega).innerHTML = msgCarrega;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", parametros.length);

	xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(parametros);
}

function Cadastro()
{
    var nome = prepraraCampo(document.formcadastro.nome.value);
    var email = prepraraCampo(document.formcadastro.email.value);
    
    if(nome == "" || email == "")
       alert("Nome ou e-mail não preenchido, corrija e envie novamente!");
    else
    {
        if(!checkMail(email))
           alert("E-mail inválido corrija e envie novamente!");
        else
        {
            ajaxFuncao("/visita/enviarcadastro/0/0", "nome=" + nome + "&email=" + email, "divCadastro", "divCadastro", "<Center><img src='/imagens/site/carregando.gif'><br/><br/></center>");
        }
    }   
}

function Contato()
{
    var nome = prepraraCampo(document.formcontato.nome.value);
    var email = prepraraCampo(document.formcontato.email.value);
    var telefone = prepraraCampo(document.formcontato.telefone.value);
    var mensagem = prepraraCampo(document.formcontato.mensagem.value);
    var destino = prepraraCampo(document.formcontato.destino.value);
    var cadastro = "";
    
    if(document.formcontato.cadastro.checked)
        cadastro = "&cadastro=true";        
    
    if(nome == "" || (email == "" && telefone == "") || mensagem == "")
        alert("É necessário preencher os campos nome, email/telefone e mensagem!");
    else
    {
        if(email != "" && checkMail(email) == false)
            alert("E-mail inválido, corrija e envie novamente!");
        else
        {           
           ajaxFuncao("/visita/enviarcontato/0/0", "nome=" + nome + "&email=" + email + "&telefone=" + telefone + "&mensagem=" + mensagem + "&destino=" + destino + cadastro, "divContato", "divContato", "&nbsp;&nbsp;&nbsp;&nbsp;<img src='/imagens/site/carregando.gif'><br/><br/>");   
        }   
    }
    
    
}

function checkMail(mail)
{ 
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); 
    
    if(er.test(mail))
        return true; 
    else
        return false;    
}

function prepraraCampo(valor)
{
    return valor.replace("&","&amp;")    
}
