
function gravaCamposOrcamento(orcamentos_id, nome_campo, valor_campo)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if (xmlhttp.responseText != "") {
			v = xmlhttp.responseText; 
			v = parseFloat(v);
			v = v.toFixed(2);
			v=v.replace(/\D/g,"") // permite digitar apenas numero 
			v=v.replace(/(\d{1})(\d{14})$/,"$1.$2") // coloca ponto antes dos ultimos digitos 
			v=v.replace(/(\d{1})(\d{11})$/,"$1.$2") // coloca ponto antes dos ultimos 11 digitos 
			v=v.replace(/(\d{1})(\d{8})$/,"$1.$2") // coloca ponto antes dos ultimos 8 digitos 
			v=v.replace(/(\d{1})(\d{5})$/,"$1.$2") // coloca ponto antes dos ultimos 5 digitos 
			v=v.replace(/(\d{1})(\d{1,2})$/,"$1,$2") // coloca virgula antes dos ultimos 2 digitos 
			element_tot = "tot_" + orcamentos_id;
			document.getElementById(element_tot).value=v;
		}
    }
  }


xmlhttp.open("GET","painel_orcamentos_grava_campos.php?orcamentos_id="+orcamentos_id+"&nome_campo="+nome_campo+"&valor_campo="+valor_campo,true);
xmlhttp.send();

}




function gravaItem(itens_id, element_vu, element_st, element_tot)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		v = xmlhttp.responseText; 
		v = parseFloat(v);
		v = v.toFixed(2);
		v=v.replace(/\D/g,"") // permite digitar apenas numero 
		v=v.replace(/(\d{1})(\d{14})$/,"$1.$2") // coloca ponto antes dos ultimos digitos 
		v=v.replace(/(\d{1})(\d{11})$/,"$1.$2") // coloca ponto antes dos ultimos 11 digitos 
		v=v.replace(/(\d{1})(\d{8})$/,"$1.$2") // coloca ponto antes dos ultimos 8 digitos 
		v=v.replace(/(\d{1})(\d{5})$/,"$1.$2") // coloca ponto antes dos ultimos 5 digitos 
		v=v.replace(/(\d{1})(\d{1,2})$/,"$1,$2") // coloca virgula antes dos ultimos 2 digitos 
		document.getElementById(element_tot).value=v;
    }
  }

document.getElementById(element_tot).value="";

valor_unitario = document.getElementById(element_vu).value.replace('.','');
valor_unitario = valor_unitario.replace(',','.');

subtotal = document.getElementById(element_st).value.replace('.','');
subtotal = subtotal.replace(',','.');

xmlhttp.open("GET","painel_orcamentos_grava_item.php?itens_id="+itens_id+"&valor_unitario="+valor_unitario+"&subtotal="+subtotal,true);
xmlhttp.send();

}




function ExcluiOrcamento(orcamentos_id, status)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		parent.document.getElementById('orcs').src = 'painel_orcamentos_lista.php?status='+status;
    }
  }
xmlhttp.open("GET","painel_orcamentos_exclui.php?orcamentos_id="+orcamentos_id,true);
xmlhttp.send();

return false;
}




function ChecaLogon(thisform)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  	if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if (xmlhttp.responseText == 0) {
			document.getElementById('falha_login').style.display='block';
			document.getElementById('email').focus();
		}
		else {
			document.getElementById('falha_login').style.display='none';
			document.frmLogon.submit(); 
		}
    }
  }
xmlhttp.open("GET","checa_logon.php?email="+thisform.email.value+"&senha="+thisform.senha.value,true);
xmlhttp.send();

return false;
}





function EnviarSenhaEmail(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		document.getElementById('email_inv').style.display='none';
		document.getElementById('email_envia').style.display='block';
    }
  }
xmlhttp.open("GET","envia_senha.php?email="+str,true);
xmlhttp.send();
}






function enviaLinkOrcamento(orcamentos_id)
{
//alert(orcamentos_id);
obj = "status_" + orcamentos_id;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		//alert(xmlhttp.responseText);
		document.getElementById(obj).style.visibility = 'visible';
		setTimeout("document.getElementById(obj).style.visibility = 'hidden'",2500);
    }
  }
xmlhttp.ontimeout=function(){
 alert("Request has timed out. Please try again.")
}
 xmlhttp.open("GET","painel_orcamentos_envia_link.php?orcamentos_id="+orcamentos_id,false);
xmlhttp.send(null);
}



function ValidarEmail(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		if (xmlhttp.responseText == 1) {
			document.getElementById('email_envia').style.display='none';
			document.getElementById('email_inv').style.display='block';
			//alert('Este e-mal já está cadastrado');
			document.getElementById('email').focus();
			
		}
		else {
			document.getElementById('email_inv').style.display='none';
			document.getElementById('email_envia').style.display='none';
		}
    }
  }
xmlhttp.open("GET","checa_email.php?email="+str,true);
xmlhttp.send();
}



function ValidarCliente(thisform){
	   if (thisform.email.value==""){
		   alert("Por favor, preencha o campo 'E-mail'.")
		   thisform.email.focus()
			return (false)
		}
		  var cont=1
		  var conf1=0 //Checa a presença do caractere @
		  var conf2=0 //Checa a presença do caractere .
		  for (var i=1;i<((thisform.email.value.length)-1);i++){
			 temp=thisform.email.value.substring(i,i+1)
			 if (temp=="@"){
				conf1=1
				if ((thisform.email.value.substring(i-1,i)==".") || (thisform.email.value.substring(i+1,i+2)==".")){
				   alert("Por favor, preencha corretamente o campo 'E-mail'.")
					 thisform.email.focus()
					 return (false)
				  }
			  }
			   if ((conf1==1) && (temp==".")){
				  conf2=1
			   }
		  }


		if ((conf1==0) || (conf2==0)){
	      alert("Por favor, preencha corretamente o campo 'E-mail'.")
		   thisform.email.focus()
		   return (false)
	   }
	   
	    if (thisform.senha.value==""){
		   alert("Por favor, preencha o campo 'Senha'.")
		   thisform.senha.focus()
			return (false)
		}

	    if (thisform.senha_conf.value==""){
		   alert("Por favor, confirme sua Senha.")
		   thisform.senha_conf.focus()
			return (false)
		}

	    if (thisform.senha.value != thisform.senha_conf.value){
		   alert("As senhas não conferem.")
		   thisform.senha_conf.focus()
			return (false)
		}

	    if (thisform.nome.value==""){
		   alert("Por favor, preencha o campo 'Nome'.")
		   thisform.nome.focus()
			return (false)
		}

	    if (thisform.cep.value==""){
		   alert("Por favor, preencha o campo 'Cep'.")
		   thisform.cep.focus()
			return (false)
		}

	    if (thisform.endereco.value==""){
		   alert("Por favor, preencha o campo 'Endereço'.")
		   thisform.endereco.focus()
			return (false)
		}

	    if (thisform.numero.value==""){
		   alert("Por favor, preencha o campo 'Número'.")
		   thisform.numero.focus()
			return (false)
		}

	    if (thisform.bairro.value==""){
		   alert("Por favor, preencha o campo 'Bairro'.")
		   thisform.bairro.focus()
			return (false)
		}

	    if (thisform.cidade.value==""){
		   alert("Por favor, preencha o campo 'Cidade'.")
		   thisform.cidade.focus()
			return (false)
		}

	    if (thisform.estado.value==""){
		   alert("Por favor, preencha o campo 'Estado'.")
		   thisform.estado.focus()
			return (false)
		}

		 if (thisform.telefone.value==""){
		   alert("Por favor, preencha o campo 'Telefone com o DDD'.")
		   thisform.telefone.focus()
			return (false)
		}
		

		return (true)
	}


function ValidarEndEntrega(thisform){
	    if (thisform.cep.value==""){
		   alert("Por favor, preencha o campo 'Cep'.")
		   thisform.cep.focus()
			return (false)
		}

	    if (thisform.endereco.value==""){
		   alert("Por favor, preencha o campo 'Endereço'.")
		   thisform.endereco.focus()
			return (false)
		}

	    if (thisform.numero.value==""){
		   alert("Por favor, preencha o campo 'Número'.")
		   thisform.numero.focus()
			return (false)
		}

	    if (thisform.bairro.value==""){
		   alert("Por favor, preencha o campo 'Bairro'.")
		   thisform.bairro.focus()
			return (false)
		}

	    if (thisform.cidade.value==""){
		   alert("Por favor, preencha o campo 'Cidade'.")
		   thisform.cidade.focus()
			return (false)
		}

	    if (thisform.estado.value==""){
		   alert("Por favor, preencha o campo 'Estado'.")
		   thisform.estado.focus()
			return (false)
		}

		 if (thisform.ddd.value==""){
		   alert("Por favor, preencha o campo 'DDD'.")
		   thisform.ddd.focus()
			return (false)
		}
		
		 if (thisform.telefone.value==""){
		   alert("Por favor, preencha o campo 'Telefone'.")
		   thisform.telefone.focus()
			return (false)
		}
		

		return (true)
	}




function LimparEndEntrega(thisform){
	    thisform.cep.value="";
		thisform.endereco.value="";
		thisform.numero.value="";
		thisform.complemento.value="";
		thisform.bairro.value="";
		thisform.cidade.value="";
		thisform.estado.value="";
		thisform.ddd.value="";
		thisform.telefone.value="";

	   thisform.cep.focus()
}




function valida_contato() {
	var nome=document.formulario.nome.value;
	var ddd=document.formulario.ddd.value;
	var telefone=document.formulario.telefone.value;
	var email=document.formulario.email.value;
	var como_conheceu=document.formulario.como_conheceu.value;
	var conteudo=document.formulario.conteudo.value;
	var assunto=document.formulario.assunto.value;
	
	if (nome=="") {
	alert("Por favor, digite o seu nome completo.");
	document.formulario.nome.focus();
	return false;
	} 
	
	if (ddd=="" || telefone=="") {
	alert("Por favor, digite o seu telefone.");
	document.formulario.ddd.focus();
	return false;
	} 
	
	if (email=="") {
	alert("Por favor, digite o seu email.");
	document.formulario.email.focus();
	return false;
	} 
	
	if (assunto=="") {
	alert("Por favor, informe o assunto de sua mensagem.");
	document.formulario.assunto.focus();
	return false;
	} 
	
	if (conteudo=="") {
	alert("Por favor, digite o conteúdo de sua mensagem.");
	document.formulario.conteudo.focus();
	return false;
	} 
	
	return true;
}


function mostra_cpo_email() {
	document.getElementById('bt_continuar').style.display = "none";
	document.getElementById('bt_finalizar').style.display = "none";
	document.getElementById('cpoEmail').style.display = "block";
	document.getElementById('email').select();
}

function mostra_form_end() {
	document.getElementById('frmEnd').style.display = "block";
	document.getElementById('end').select();
}

function mostra_form_nome() {
	if (document.getElementById('email').value == "") {
		alert("Você deve fornecer seu E-mail !");
		document.getElementById('email').select();
		return false;
	}
	  
	var cont=1
    var conf1=0 //Checa a presença do caractere @
    var conf2=0 //Checa a presença do caractere .
    for (var i=1;i<((document.getElementById('email').value.length)-1);i++){

		temp=document.getElementById('email').value.substring(i,i+1)
		if (temp=="@"){
			conf1=1
			if ((document.getElementById('email').value.substring(i-1,i)==".") || (document.getElementById('email').value.substring(i+1,i+2)==".")){
				alert("Por favor, preencha corretamente 1 o campo 'E-mail'.");
				document.getElementById('email').select();
				return false;
			}
		}
		
		if ((conf1==1) && (temp==".")){
			conf2=1
		}
	}
	if ((conf1==0) || (conf2==0)){
		alert("Por favor, preencha corretamente 2 o campo 'E-mail'.");
		document.getElementById('email').select();
		return false;
	}
	document.getElementById('frmNome').style.display = "block";
	document.getElementById('btEnviar').style.display = "block";
	//document.getElementById('nome').select();
	return true;
}



function Detona_Event(Campo,strtext){ 
	event.returnValue = false 
	if (strtext != "") { 
		Campo.value = strtext 
	} 
} 

function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){ 
	if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
		separador = arrpos 
		masktext = strtext + separador 
		Campo.value = masktext 
	} 
} 
function FormataCampo(Campo,teclapres,mascara){ 
	strtext = Campo.value 
	tamtext = strtext.length 
	tammask = mascara.length 
	arrmask = new Array(tammask) 
	for (var i = 0 ; i < tammask; i++){ 
		arrmask[i] = mascara.slice(i,i+1) 
	} 

	if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){ 
		if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){ 
			Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext) 
		} else { 
			Detona_Event(Campo,strtext) 
		} 
	} else {
		if ((arrmask[tamtext] == "A")) { 
			charupper = event.valueOf() 
			Detona_Event(Campo,strtext) 
			masktext = strtext + charupper 
			Campo.value = masktext 
		} 
	} 
} 


function autotab(elemento){ 
	if (elemento.value.length < elemento.getAttribute("maxlength")) return; 
	var formulario = elemento.form; var els = formulario.elements; 
	var x, autotab; 
	for (var i = 0, len = els.length; i < len; i++) {  
		x = els[i];  
		if (elemento == x && (autotab = els[i+1]))  {   
			if (autotab.focus) autotab.focus();  
		} 
	}
}
