function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function enviarEmail(){
 if (verificadados()){
    document.getElementById("aguarde").innerHTML = '<img class="no-border" src="images/ajax_preloader.gif"><font color="#FF0000">Aguarde enviando email...</font><br/><br/>';
	nome=document.form1.txtNome.value;
	email=document.form1.txtEmail.value;
	assunto=document.form1.txtAssunto.value;
	msg = document.form1.txtMsg.value;
	num = document.form1.txtNumber.value;
		
	//instanciando o objetoAjax
	ajax=objetoAjax();
	//uso del medotod POST
	//archivo que realizará la operacion
	//registro.php
	ajax.open("POST", "envia-email.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			//document.getElementById("aguarde").innerHTML="<center>Registro Incluído (" + dt + "/" + hora +")</center>";
			document.getElementById("aguarde").innerHTML = ajax.responseText;
			//llamar a funcion para limpiar los inputs
			LimparCampos();
		}
	}
	dados_a_enviar = "txtNome="+nome+"&txtEmail="+email+"&txtAssunto="+assunto+"&txtMsg="+msg+"&txtNumber="+num;
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", dados_a_enviar.length);
	ajax.send(dados_a_enviar);
 }
}

function LimparCampos(){
  document.form1.txtNome.value="";
  document.form1.txtEmail.value="";
  document.form1.txtAssunto.value="";
  document.form1.txtMsg.value="";
}
// teste 
function verificadados() {
	if (document.form1.txtNome.value.length == 0) 
	{
		alert("ATENÇÃO. Informe seu nome");
		document.form1.txtNome.focus();
		return false;
	}		
	if (document.form1.txtEmail.value.length == 0) 
	{
		alert("ATENÇÃO. Informe seu email");
		document.form1.txtEmail.focus();
		return false;
	}
	if (document.form1.txtAssunto.value.length == 0) 
	{
		alert("ATENÇÃO. Informe o assunto do email");
		document.form1.txtAssunto.focus();
		return false;
	}
	if (document.form1.txtMsg.value.length == 0) 
	{
		alert("ATENÇÃO. Escreva a mensagem a ser enviada");
		document.form1.txtMsg.focus();
		return false;
	}
 return true;
}
