function ignore_esp(string) { 
	var temp = ""; 
	string = '' + string; 
	splitstring = string.split(" "); 
	for(i = 0; i < splitstring.length; i++) 
		temp += splitstring[i]; 
	return temp; 
} 

function ValidaEmail()
{
  var obj = eval("document['frmContato'].email");
  var txt = obj.value;
  if ((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7)))
  {
    alert('Email incorreto, ou não reconhecido');
	obj.focus();
  }else{
  	return true;
  }
}

function enviando(num){
	if(num){
		document.getElementById("divEnviando").style.display = "";
	}else{
		document.getElementById("divEnviando").style.display = "none";
	}
}



function getHTTPObject(){
var xmlhttp;  /*@cc_on  @if (@_jscript_version >= 5)    try {      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");    } catch (e) {      try {        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");      } catch (e) {        xmlhttp = false;      }    }  @else  xmlhttp = false;  @end @*/  
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {    try {      xmlhttp = new XMLHttpRequest();    } catch (e) {      xmlhttp = false;    }  }  return xmlhttp;
}
var http = getHTTPObject();//função necessária para saber como a resposta deve vir, ela localiza o browser


function enviaEmail(){
	enviando(1);
	var form = document["frmContato"]; 
	
	dados = new Array();
	
	dados[0] =form.nome.value;
	dados[1] =form.contato.value;
	dados[2] =form.telefone.value;
	dados[3] =form.email.value;
	dados[4] =form.cidade.value;
	dados[5] =form.setor.value;
	dados[6] =form.mensagem.value;
	//alert(dados);
	
		http.open("GET", "contato/processaContato.php?dados="+dados, true); 
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	
}
function handleHttpResponse(){ 
  if(http.readyState == 4) {  
      result = http.responseText.split("|separa|");//separa os dados importantes   
  	   
	   enviando(0);
	   
	   if(ignore_esp(result[0])=="TRUE"){
	  		alert("E-mail enviado com Sucesso!");
			location.href = "contato.php";
	   }
	   else if(ignore_esp(result[0])=="FALSE"){
	   		alert("Problemas ao enviar e-mail!");
	   }
	   else{
		   alert(result[0]);
	   }
  }//fim do if
}//fecha função
