function ignore_esp(string) { 
	var temp = ""; 
	string = '' + string; 
	splitstring = string.split(" "); 
	for(i = 0; i < splitstring.length; i++) 
		temp += splitstring[i]; 
	return temp; 
} 
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 cadastrarCliente(){
	enviando(1);
	var form = document["frmCliente"]; 
	
	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.cpf.value;
	dados[6] =form.ramo.value;
	dados[7] =form.receberEmails.checked;
	//alert(dados);
	//window.open("./cadastro_clientes/processaCadastro.php?dados="+dados);
	http.open("GET", "./cadastro_clientes/processaCadastro.php?dados="+dados, true); 
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function handleHttpResponse(){ 
  if(http.readyState == 4) {  
       result = http.responseText;   
  	   
	   enviando(0);
	   
	   if(ignore_esp(result)=="TRUE"){
	  		alert("Cadastro efetuado com sucesso!");
			iniciaCadastro();
	   }
	   else if(ignore_esp(result)=="FALSE"){
	   		alert("Atenção: Problemas ao efetuar cadastro!");
	   }
	   else{
		   alert(result);
	   }
  }//fim do if
}//fecha função

function iniciaCadastro(){
	form =  document["frmCliente"];
	form.nome.value="";
	form.contato.value="";
	form.telefone.value="";
	form.email.value="";
	form.cidade.value="";
	form.cpf.value="";
	form.ramo.value="";
	form.receberEmails.checked=true;
}

