
var xmlhttp = ajax();


function ajax(){

	oHtml = false;

	try { oHtml=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { 

			try { oHtml=new ActiveXObject("Msxml2.XMLHTTP");} catch(ee){ 

			try { oHtml=new XMLHttpRequest(); } catch(eee) { oHtml=false;} 

		}
	}
	
	return oHtml;
}

var prefix = parent.location.protocol + '//'; // http ou https   
var UrlBase = prefix+location.host+"/";
var bufferScreen = "";

//var UrlBaseS = UrlBase;
var UrlBaseS = "https://"+location.host+"/";


var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;


// Handle all the the FSCommand messages in a Flash movie
function menu_DoFSCommand(command, args) {
	var menuObj = InternetExplorer ? menu : document.menu;
	CarregarItem(command);
}


// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
	navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub menu_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call menu_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}




function homePage() {
	window.location = UrlBase;
}	

function AC_Flash() {
		theObjects = document.getElementsByTagName("object");
			for (var i = 0; i < theObjects.length; i++) {
				theObjects[i].outerHTML = theObjects[i].outerHTML;
			}
}









function SavaCarID(id) {
	
	document.getElementById("menssagem").innerHTML = "<img border='0' src='images/load.gif'> Aguarde...";

	theQtd = document.getElementById("edQTD"+id);
	url = UrlBase+"controller.php" ;
	urlvar = "ac=a&id="+id+ "&qtd="+ extractNumero(theQtd.value) ;
	
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("menssagem").innerHTML = "";
				} else { alert("Erro de comunicacao com o Servidor"); }
			}	
			}
	xmlhttp.send(urlvar);
}


function CalculaCar(id) 
{
	theQtd = document.getElementById("edQTD"+id);

	if  (theQtd.value > 99) {
		theQtd.value = 99;
	}

	if  (theQtd.value < 0) {
		theQtd.value = 0;
	}
	
	
	thePreco = document.getElementById("edPRECO"+id);
	theSubTotal = document.getElementById("edSUBTOTAL"+id);		
	theTotal = document.getElementById("edTOTAL");		
	
	theSubTotal.value = formatCurrencyPTBR((extractNumero(theQtd.value) * extractNumero(thePreco.value)));
	theFrete = document.getElementById("edFrete");		
	

	  theObjects = document.getElementsByTagName("input");
		ntotal = 0; ;
		for (var i = 0; i < theObjects.length; i++) {
			if (theObjects[i].name.substring(0,10) === 'edSUBTOTAL')
			
			if (extractNumero(theObjects[i].value) > 0)				
			ntotal =  parseFloat(ntotal) + parseFloat(extractNumero(theObjects[i].value));
			
		}
		
		// Calculando um Frete
		ntotal = parseFloat(ntotal) + parseFloat(extractNumero(theFrete.value));
		
		// Valor total Formatado
		theTotal.value = formatCurrencyPTBR(ntotal) ;    
	return true;	
}     





function formatarCepFRETE(oCampo) {

	document.getElementById("edUF").value = "";	
	document.getElementById("edTempo").value = "";	
	
	if (oCampo.value.length > 9) {
		oCampo.value = oCampo.value.substring(0,9);
	   return false;
	}

	/* Somente um ponto - */
	if (event.keyCode == 45) {
		return ( (oCampo.value.toString().match(/\-/g) == null) );
	}
	
	/* Permite somente numeros  ou pontos*/ 
	if (!(event.keyCode >= 48 && event.keyCode <= 57))
	{
		return false;
	}

	if (oCampo.value.length == 5) {
	   oCampo.value += '-';
	}
	return true;
}









function calculaFrete() {

theCep = document.getElementById("edCEP");
theTipoFrete = document.getElementById("edTipoFrete");
theValorFrete = document.getElementById("edFRETE");
thebtFrete = document.getElementById("btCalculaFrete");
chave = theTipoFrete.options[theTipoFrete.selectedIndex].value;

	
if ((theCep.value.length != 9) && (theTipoFrete.value != "Retirar") )  {
	alert("CEP: "+theCep.value+" Invalido !");
	return false;
}
  document.getElementById("menssagem").innerHTML = "<img border='0' src='images/load.gif'> Aguarde...";
  
	var r = Math.random();
	url = UrlBase+"controller.php";
	urlvar = "ac=cfrete&cep="+theCep.value+"&tipofrete="+theTipoFrete.value+"&r="+r;
	
	 xmlhttp.open("POST",url,true);  
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	 xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	 xmlhttp.setRequestHeader("Connection", "close");
	
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var xmlForm = xmlhttp.responseXML;
						
						if ( (theTipoFrete.value != "Retirar") )  {						
					
							if ( (xmlForm.getElementsByTagName("cepValidado").length > 0) &&
								(xmlForm.getElementsByTagName("cepValidado")[0].childNodes.length > 0) ) {
					
								var cepValido = xmlForm.getElementsByTagName("cepValidado")[0].childNodes[0].nodeValue;
								
								if ( cepValido.indexOf("Sim") != -1 ) {
								
										var cepDisponivel = xmlForm.getElementsByTagName("freteDisponivel")[0].childNodes[0].nodeValue;
									
										if ( cepDisponivel.indexOf("Sim") != -1 ) {
											document.getElementById("edTOTAL").value = formatCurrencyPTBR(xmlForm.getElementsByTagName("valorTotalPedido")[0].childNodes[0].nodeValue);
											document.getElementById("edFRETE").value = formatCurrencyPTBR(xmlForm.getElementsByTagName("valorFrete")[0].childNodes[0].nodeValue);
											document.getElementById("edUF").value = xmlForm.getElementsByTagName("entregaUF")[0].childNodes[0].nodeValue;
											document.getElementById("edTempo").value = xmlForm.getElementsByTagName("tempo")[0].childNodes[0].nodeValue;
											//document.getElementById("edCidade").value = xmlForm.getElementsByTagName("entregaCidade")[0].childNodes[0].nodeValue;
											document.getElementById("menssagem").innerHTML = "";
											changeFormaPagamento();
										} else {
											document.getElementById("edUF").value = "";
											document.getElementById("edTempo").value = "";
											document.getElementById("menssagem").innerHTML = "Desculpe-nos mas não possuimos transporte para essa região";
											alert("Desculpe-nos mas não possuimos transporte para essa região");
										}
										
								} else {
									document.getElementById("edUF").value = "";
									document.getElementById("edTempo").value = "";
									document.getElementById("menssagem").innerHTML = "CEP INVALIDO !!!";
									alert("Nao foi possivel identificar o CEP digitado verifique se o mesmo esta correto");
								}
							} else { 
								alert("Esse serviço não esta disponivel no momento");	
								document.getElementById("menssagem").innerHTML = "Esse serviço não esta disponivel no momento";
							}
							
						} else {
								document.getElementById("menssagem").innerHTML = "";
								document.getElementById("edTempo").value = xmlForm.getElementsByTagName("tempo")[0].childNodes[0].nodeValue;
								document.getElementById("edUF").value = "";
								document.getElementById("edFRETE").value = formatCurrencyPTBR(0);
								document.getElementById("edTOTAL").value = formatCurrencyPTBR(xmlForm.getElementsByTagName("valorTotalPedido")[0].childNodes[0].nodeValue);
								changeFormaPagamento();
						}						
								
						
						
				} else 	{ alert("serviço indisponivel no momento") }; 	
				
			}	
			}
	xmlhttp.send(urlvar);
	
}	


function numerico()    {
		if( !(event.keyCode >= 48 && event.keyCode <= 57 ) ) 
		 {
		 return false;
		 }
		 
		return true; 
}

function getValueFromRadioorCheck(ob) {
	re = "";
	for (var y=0;y < ob.length;y++) {
		if (ob[y].checked) { re = ob[y].value }
	}
	return re;
}

function changeFormaPagamento() {
	rb = document.getElementsByName("tipoPagamento");
	rbv = getValueFromRadioorCheck(rb);
	var r = Math.random();
	
	document.getElementById("menssagem").innerHTML = "<img border='0' src='images/load.gif'> Aguarde...";
	
	url = UrlBase+"controller.php";
	urlvar = "ac=capagto&tipopagamento="+rbv+"&r="+r;
	
	
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
    xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	

	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var xmlForm = xmlhttp.responseText;
					
					//document.getElementById("formaPagamentoShow").innerHTML = xmlForm.getElementsByTagName("formPgto")[0].childNodes[0].nodeValue;
					document.getElementById("formaPagamentoShow").innerHTML = xmlForm;
					document.getElementById("formaPagamento").value = "";
					document.getElementById("menssagem").innerHTML = "";
					
				} else 	{ alert("serviço indisponivel no momento") }; 	
				
			}	
			}
	xmlhttp.send(urlvar);
	
}	

function escolheParcela() {
	rb = document.getElementsByName("pagto");
	rbv = getValueFromRadioorCheck(rb);
	var r = Math.random();
	
	url = UrlBase+"controller.php";
	urlvar = "ac=chpagto&parcela="+rbv+"&r="+r;
	
	document.getElementById("menssagem").innerHTML = "<img border='0' src='images/load.gif'> Aguarde...";
	
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
    xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var xmlForm = xmlhttp.responseText;
					document.getElementById("formaPagamento").value = xmlForm;
					document.getElementById("menssagem").innerHTML = "";
				} else 	{ alert("serviço indisponivel no momento") }; 	
				
			}	
			}
	xmlhttp.send(urlvar);
}	


function formatarCampoMoedaEntradaAymore(Campo) {
	Campo.value = formatCurrencyPTBR(Campo.value);
	
	url = UrlBase+"controller.php";
	urlvar = "ac=ay&ent="+Campo.value;
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
			}	
	}	
	xmlhttp.send(urlvar);
	
	
	
	
}

function formatarCampoMoeda(Campo) {
	Campo.value = formatCurrencyPTBR(Campo.value);
}
				 
function formatCurrencyPTBR(num) {				 

		num = num.toString().replace(/\./g,'');
		num = num.toString().replace(/\,/g,'.');
		num = formatCurrency(num);
		
		num = num.toString().replace(/\,/g,'A');
		num = num.toString().replace(/\./g,',');
		num = num.toString().replace(/\A/g,'.');			
		
		return num;
}

function extractNumero(num) {
	num = num.toString().replace(/\./g,'');
	num = num.toString().replace(/\,/g,'.');
	if(isNaN(num))	num = "0";
	
	return num;
}

function formatCurrency(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
			num = "0";
		
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		
		if(cents<10)
			cents = "0" + cents;

		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '' + num + '.' + cents);
	
}	



function incCarrinho(id) {
	url = UrlBase+"controller.php";
	urlvar = "ac=i&id="+id;
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				var link = UrlBaseS+"?pg=carrinho";
				document.getElementById(id).innerHTML = "<font size='2'> <a title='Click Aqui para ver o seu carrinho \n\n fique a vontade para ver outros produto quando quizer continuar a compra ou a cotação clique em meu carrinho ! ' href='"+link+"'>Adicionado !! Click Aqui para ver o seu carrinho</a></font>"
				
			}	
			
	}	
	xmlhttp.send(urlvar);
	
}

function incCarrinhoAndGo(id) {
	url = UrlBase+"controller.php";
	urlvar = "ac=i&id="+id;
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				var link = UrlBaseS+"?pg=carrinho";
				document.getElementById(id).innerHTML = "<font size='2'> <a title='Click Aqui para ver o seu carrinho \n\n fique a vontade para ver outros produto quando quizer continuar a compra ou a cotação clique em meu carrinho ! ' href='"+link+"'>Adicionado !! Click Aqui para ver o seu carrinho</a></font>"
				
			}	
			
	}	
	xmlhttp.send(urlvar);
	
}


function excCarrinho(id) {
	url = UrlBase+"controller.php";
	urlvar = "ac=e&id="+id;
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				CarregarItem('carrinho');
			}	
			
	}	
	xmlhttp.send(urlvar);
 }



function ChangePesquisa(novaPesquisa) {
	CarregarItem(novaPesquisa);
}




function ChangeCategoria(novaCategoria) {
  Messagem('Aguarde Carregando......'+novaCategoria);
  var r = Math.random();
  CarregarCorpo(UrlBase+"body.php?pg=produtos"+"&n="+r+"&ct="+novaCategoria);
}


function exibirProduto( titulo , foto, id ) {
	var r = Math.random();
	url = UrlBase+"controller.php?ac=ra&id="+id+"&n="+r;
	windowReference = window.open(url,'_blank',"height=450,width=650,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,address=no");	  	     		
	
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
	
}

function exibirBoleto(id,sid) {

	if (document.getElementsByName('btProximo').length > 0) {
		document.getElementsByName('btProximo')[0].disabled = false;
	}

	var r = Math.random();
	url = UrlBase+"gerarboleto.php?id="+id+"&n="+r+"&sid="+sid;
	windowReference = window.open(url,'_blank',"height=650,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,address=no");	  	     		
	windowReference.print();
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
	
}






function exibirCaluladora() {
	var r = Math.random();
	url = UrlBase+"controller.php?ac=calc&n="+r;
	windowReference = window.open(url,'_blank',"height=250,width=350,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,address=no");	  	     		
	
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
	
}



function PesquisaProduto(pesquisa) {

  pesquisa = pesquisa.toLowerCase();

  Messagem('Pesquisando por: '+pesquisa);
  
  var r = Math.random();
  CarregarCorpo(UrlBase+"body.php?pg=produtos"+"&n="+r+"&ps="+pesquisa);
}


function Messagem(Mess) {

bufferScreen = document.getElementById("textBody").innerHTML;
var messagem = "";
messagem += '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family:Verdana; color:#454867; font-size:10 pt; font-weight:bold" bordercolor="#111111" width="100%" height="217">';
messagem += '<TR><TD align="center">';
messagem += '<img src="images/load.gif">' ;
messagem += '<p align="center">&nbsp;' + Mess + '</p>' ;
messagem += '</TD></TR>';
messagem += '</table>';
document.getElementById("textBody").innerHTML = messagem;
}


function backfromMessage() {
	document.getElementById("textBody").innerHTML =	bufferScreen;
}





function CarregarItem(item)
{
	   
   Messagem('Aguarde Carregando...'+item);
   
	item = item.toLowerCase();

	var r = Math.random();
	var bCarregarCorpo = true;
	
		if (item == 'localizacao') 
		{
			urla = UrlBase+"body.php?pg=localizacao&n="+r ;
		} 
		else if (item == 'babynames') 
		{
			urla = UrlBase+"body.php?pg=babynames&n="+r ;
		} 
		
		else if ( (item == 'orcamento') )
		{
			urla = UrlBase+"body.php?pg=orcamento&n="+r ;
		} 
		
		else if ( (item == 'pedido') )
		{
			urla = UrlBase+"body.php?pg=pedido&n="+r ;
		} 
		
		
		else if ( (item == 'meucadastro') )
		{
			urla = UrlBase+"?pg=meucadastro&n="+r ;
			bCarregarCorpo = false;
			window.location = urla;
		} 
		
		else if ( (item == 'carrinho') )
		{
			carregarCarrinho();
			bCarregarCorpo = false;
		} 
		else if ( (item == 'inscricao') )
		{
			carregarInscricao();
			bCarregarCorpo = false;
			
		} 
		else if ( (item == 'confirmacao') )
		{
			carregarConfirmacao();
			bCarregarCorpo = false;
		} 
		else if ( (item == 'pagamento') )
		{
			carregarInscricao();
			bCarregarCorpo = false;
		} 

		else if (item == 'contatos') 
		{
			urla = UrlBase+"body.php?pg=contato&n="+r ;
		} 
		else if (item == 'catalogo') 
		{
			urla = UrlBase+"body.php?pg=catalogos&n="+r ;
		} 
		else if (item == 'WebMail') 
		{
			urla = UrlBase+"body.php?pg=webmail&n="+r ;
		} 
	else 
		{
			urla = UrlBase+"body.php?pg=produtos&ct="+item+"&n="+r ;
		}
	
	if (bCarregarCorpo) { CarregarCorpo(urla); }
   
}

function CarregarCorpo(url)
{
	   // Envia a Requisicao
		xmlhttp.open("GET", url, true);
	
			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
				 document.getElementById("textBody").innerHTML = xmlhttp.responseText;
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(null);
}

function visible(ddi) {
	if (document.getElementById(ddi).style.visibility=="hidden")  {
		document.getElementById(ddi).style.visibility="visible" ;
		document.getElementById(ddi).style.display="block" ;
	}    
	else 
	{ 
		document.getElementById(ddi).style.visibility="hidden" ;
		document.getElementById(ddi).style.display="none";
	}
}

function visible2(ddi,ddc) {
	if (document.getElementById(ddi).style.visibility=="hidden")  {
		document.getElementById(ddi).style.visibility="visible" ;
		document.getElementById(ddi).style.display="block" ;
		
		document.getElementById(ddc).innerHTML = "[-]" ;
		
	}    
	else 
	{ 
		document.getElementById(ddi).style.visibility="hidden" ;
		document.getElementById(ddi).style.display="none";
		document.getElementById(ddc).innerHTML = "[+]" ;
	}
}


//***************************************************************************************************************
function validaCarrinho(orcOUped) {  // Passo 01

parcela = document.getElementById('formaPagamento');
theUF = document.getElementById('edUF');
theTOTAL = document.getElementById('edTOTAL');

theCep = document.getElementById("edCEP");
theTipoFrete = document.getElementById("edTipoFrete");
chave = theTipoFrete.options[theTipoFrete.selectedIndex].value;

  bTotalGeral = (extractNumero(theTOTAL.value) > 0);
  bFrete = ((chave == "Retirar") || ((theUF.value.length >= 2) && (theCep.value.length == 9))); 
  bPagamento = (parcela.value.length > 0);

  if (bTotalGeral && bFrete && bPagamento) {
	  carregarInscricao(orcOUped);
  }	else {
	var prob = "";
	
	if (!bTotalGeral) { prob += " Valor Total nao pode ser 0 \n" }
	if (!bFrete) { prob += " Preencha e calcule o frete corretamente \n" }
	if (!bPagamento) { prob += " Selecione uma opção de pagamento \n" }
	alert(prob);
  }
	
	
return (true);
}


function validaInscricao(orcOUped,sid) {  // Passo 02

	if (orcOUped == "orc") { 
		savaOrcamentoCarregaConfirmacao();
	} else if (orcOUped == "ped") { 
		if (validarCadastroEAlarmaCliente()) {
			salvarMeuCadastro(sid,"carregaConfirmacao");
		}	
	}	
		
return (true);
}

function validaConfirmacao(orcOUped) {   // Passo 03

	if (orcOUped == "orc") { 
		finalizaConfirmacao(); 
	} else {
	
			document.getElementById("btProximo").value = "Aguarde !!";    
			document.getElementById("btProximo").disabled = true;
			
			Messagem('Aguarde Confirmando Pedido');
			var r = Math.random();
			url = UrlBase+"controller.php";
			urlvar = "ac=sped&n="+r ;
			// Envia a Requisicao
			xmlhttp.open("POST", url, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
			xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
			xmlhttp.setRequestHeader("Connection", "close");
		
				xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4) {
					if (xmlhttp.status == 200) {
						texto = xmlhttp.responseText;
						document.getElementById("textBody").innerHTML = texto;
						
						if (texto.indexOf("O Pedido foi confirmado com Sucesso !") >= 0) {
							carregarPagamento(); 
						}	
						
					} else { alert(xmlhttp.status); } 
				}	
				}							
			xmlhttp.send(urlvar);
	}
 
return (true);
}

function validaPagamento(orcOUped) {   // Passo 04

	finalizaPagamento();
return (true);
}
//****************************************************************************************************

function carregarCarrinho() {
		var r = Math.random();
		url = UrlBase+"body.php" ;
		urlvar = "pg=carrinho&n="+r ;
		// Envia a Requisicao
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	    xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	    xmlhttp.setRequestHeader("Connection", "close");
	
			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
					
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(urlvar);
}



function carregarInscricao(orcOUped) {
		var r = Math.random();
		url = UrlBase+"body.php";
		urlvar = "pg=inscricao&n="+r ;
		
		// Envia a Requisicao
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	    xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	    xmlhttp.setRequestHeader("Connection", "close");
		
	
			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
					if (orcOUped == "orc") {
						validaCadastroOrcamento();
					} else if (orcOUped == "ped") {
						validarCadastroCliente();
					}
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(urlvar);
}

function carregarConfirmacao() {
		var r = Math.random();
		url = UrlBase+"body.php" ;
		urlvar = "pg=confirmacao&n="+r ;
		
		// Envia a Requisicao
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	    xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	    xmlhttp.setRequestHeader("Connection", "close");
	
			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(urlvar);
}



function finalizaConfirmacao() {
        document.getElementById("btProximo").value = "Aguarde !!";    
		document.getElementById("btProximo").disabled = true;
		Messagem('Aguarde Finalizando...');
		var r = Math.random();
		
		url = UrlBase+"controller.php";
		urlvar = "ac=svorc&n="+r ;
		// Envia a Requisicao
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
		xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
		xmlhttp.setRequestHeader("Connection", "close");
	
			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(urlvar);
}


function consultarPedido() {
		var r = Math.random();
		url = UrlBase+"?pg=pedido&ped="+document.getElementById("edPedido").value;
		window.location = url;
}

function carregarPagamento() {
		var r = Math.random();
		url = UrlBase+"body.php";
		urlvar = "pg=pagamento&n="+r ;
		window.location = UrlBase+"?"+urlvar;
		
		
		// Envia a Requisicao
		/*
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
		xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
		xmlhttp.setRequestHeader("Connection", "close");

			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(urlvar);
		*/
}

function finalizaPagamento() {
		Messagem("Finalizando...");
		var r = Math.random();
		url = UrlBase+"body.php" ;
		urlvar = "pg=fpagamento&n="+r;
		
		// Envia a Requisicao
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
		xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
		xmlhttp.setRequestHeader("Connection", "close");
	
	
			xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
				} else { alert(xmlhttp.status); } 
			}	
			}							
		xmlhttp.send(urlvar);
}



// Funcoes para o Orcamento *****************************************************************************

function orcamento() {
	CarregarItem('CARRINHO');
}

function LimparOrc() {
	url = UrlBase+"controller.php";
	urlvar = "ac=c";
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				CarregarItem('orcamento');
			}	
			
	}	
	xmlhttp.send(urlvar);
}



function CalularTOrc() {
	habOrc();
}

function savaOrcamentoCarregaConfirmacao() {
	var oNome = document.getElementById("edNome");
	var oFone = document.getElementById("edFone");
	var oEmail = document.getElementById("edEmail");   
	var oObs = document.getElementById("edObsPedido");   
	
    document.getElementById("menssagem").innerHTML = 'Salvando...';
	url = UrlBase+"controller.php";
	urlvar = "ac=an&nome="+oNome.value + "&fone="+oFone.value +  "&mail="+oEmail.value + "&obs="+oObs.value;
	xmlhttp.open("POST",url,true); 
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
				document.getElementById("menssagem").innerHTML = xmlhttp.responseText;
				if ( xmlhttp.responseText.indexOf("Salvo com sucesso") != -1) {
					CarregarItem('confirmacao');
				}	
			}
	   	}
	}	
	xmlhttp.send(urlvar);
}


//Validação Local 
function validaCadastroOrcamento() {

	var oNome = document.getElementById("edNome");
	var oFone = document.getElementById("edFone");
	var oEmail = document.getElementById("edEmail");   
	var oBtProximo = document.getElementById("btProximo");
	
	var bnomeValido = (oNome.value.length >= 3) ;
	oNome.className =  (bnomeValido ? '':'error');

	var bfoneValido = (oFone.value.length >= 1) ;
	oFone.className =  (bfoneValido ? '':'error');

	var bemailValido = emailValido(oEmail);
	oEmail.className = (bemailValido ? '':'error');
			
	oBtProximo.disabled = (! ( bnomeValido && bfoneValido && bemailValido) );

}

function formatarCPF(oCampo) {
	if (oCampo.value.length >= 14) {
		oCampo.value = oCampo.value.substring(0,14);
	   return false;
	}
	/* Permite somente numeros  ou pontos*/ 
	if (!(event.keyCode >= 48 && event.keyCode <= 57))
	{
		return false;
	}
	if (oCampo.value.length == 3) {
	   oCampo.value += '.';
	}
	if (oCampo.value.length == 7) {
	   oCampo.value += '.';
	}
	if (oCampo.value.length == 11) {
	   oCampo.value += '.';
	}
	return true;
}

function formatarRG(oCampo) {
	if (oCampo.value.length >= 13) {
		oCampo.value = oCampo.value.substring(0,13);
	   return false;
	}
	/* Permite somente numeros  ou pontos*/ 
	if (!(event.keyCode >= 48 && event.keyCode <= 57) )
	{
		return false;
	}
	if (oCampo.value.length == 2) {
	   oCampo.value += '.';
	}
	if (oCampo.value.length == 6) {
	   oCampo.value += '.';
	}
	if (oCampo.value.length == 10) {
	   oCampo.value += '-';
	}
	
	return true;
}




function formatarData(oCampo) {
	if (oCampo.value.length >= 10) {
		oCampo.value = oCampo.value.substring(0,10);
	   return false;
	}
	/* Permite somente numeros  ou pontos*/ 
	if (!(event.keyCode >= 48 && event.keyCode <= 57) )
	{
		return false;
	}
	if (oCampo.value.length == 2) {
	   oCampo.value += '/';
	}
	if (oCampo.value.length == 5) {
	   oCampo.value += '/';
	}
	if (oCampo.value.length == 11) {
	   oCampo.value += '.';
	}
	return true;
}

function formatarCep(oCampo) {
	
	if (oCampo.value.length >= 9) {
		oCampo.value = oCampo.value.substring(0,9);
	   return false;
	}

	/* Somente um ponto - */
	if (event.keyCode == 45) {
		return ( (oCampo.value.toString().match(/\-/g) == null) );
	}
	
	/* Permite somente numeros  ou pontos*/ 
	if (!(event.keyCode >= 48 && event.keyCode <= 57))
	{
		return false;
	}

	if (oCampo.value.length == 5) {
	   oCampo.value += '-';
	}
	
}


function formatarFone(oCampo,evitarCelular) {
	if (oCampo.value.length >= 40) {
		oCampo.value = oCampo.value.substring(0,40);
	   return false;
	}
	
	if ( (event.keyCode >= 55 && event.keyCode <= 57) && (oCampo.value.length <= 1) ) { // Area errada
		alert("Não existe area de DDD com esse numero Formato Correto é (99)9999-9999 ");
		return(false);
	}
	
	if ( (evitarCelular == 1) && (event.keyCode >= 55 && event.keyCode <= 57) && (oCampo.value.length == 2) ) { // Celular Sendo Digitado
		alert("Esse campo não pode ser Celular");
		return(false);
	}
	
	
	/* Permite somente numeros  ou pontos*/ 
	if (!(event.keyCode >= 48 && event.keyCode <= 57) )
	{
		return false;
	}
	if (oCampo.value.length == 2) {
	   oCampo.value += '-';
	}
	
	if (oCampo.value.length == 7) {
	   oCampo.value += '-';
	}
	
	
	return true;
}



function validarEmail(campo) {
	campo.className = ((emailValido(campo)) ? '':'error');
	return true;
}


function salvarMeuCadastro(ssid,proximaFase) {

	ssr = "";
	ssr += getValorCampo('rg')+"&"
	ssr += getValorCampo('nome')+"&"
	ssr += getValorCampo('email')+"&"
	ssr += getValorCampo('fone_casa')+"&"
	ssr += getValorCampo('fone_comercial')+"&"
	ssr += getValorCampo('celular')+"&"
	ssr += getValorCampo('melhor_horario')+"&"
	ssr += getValorCampo('aniversario')+"&"
	ssr += getValorCampo('endereco_cep')+"&"
	ssr += getValorCampo('endereco_logradouro')+"&"
	ssr += getValorCampo('endereco_numero')+"&"
	ssr += getValorCampo('endereco_complemento')+"&"
	ssr += getValorCampo('endereco_bairro')+"&"
	ssr += getValorCampo('endereco_cidade')+"&"
	ssr += getValorCampo('endereco_uf')+"&"
	ssr += getValorCampo('endereco_referencia')+"&"
	ssr += getValorCampo('entrega_cep')+"&"
	ssr += getValorCampo('entrega_logradouro')+"&"
	ssr += getValorCampo('entrega_numero')+"&"
	ssr += getValorCampo('entrega_complemento')+"&"
	ssr += getValorCampo('entrega_bairro')+"&"
	ssr += getValorCampo('entrega_cidade')+"&"
	ssr += getValorCampo('entrega_uf')+"&"
	ssr += getValorCampo('senha')+"&"
	ssr += getValorCampo('entrega_referencia');
	
	
	
	url = UrlBase+"controller.php";
	urlvar = "ac=svcl&"+ssr+"&sid="+ssid;
	xmlhttp.open("POST",url,true); 
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
				document.getElementById("menssagem").innerHTML = xmlhttp.responseText;
				//if ( xmlhttp.responseText.indexOf("Salvo com sucesso") != -1) {
					if (proximaFase == "carregaConfirmacao") {
						
						carregarConfirmacao();
						
				//}
				}	
			}
	   	}
	}	
	xmlhttp.send(urlvar);
}





function getValorCampo(campo) {
	return (campo+'='+document.getElementsByName(campo)[0].value);
}


function validarCadastroCliente() {
	
	if ( document.getElementsByName('rg').length > 0 ) { 
	

	bRG = validaMinimoCampo('rg',10);
	bNome =	validaMinimoCampo('nome',10);
	bEMail = validarEmail(document.getElementsByName('email')[0]);
	bFoneCasa =	validaMinimoCampo('fone_casa',12);
	bFoneComercial =	validaMinimoCampo('fone_comercial',12);
	
	
	bsenha = (document.getElementsByName('senha')[0].value.length == 0);
	if (!bsenha) {	
		bsenha =	validaMinimoCampo('senha',4);
	}	
	bconfirma =	document.getElementsByName('senha')[0].value == document.getElementsByName('confirma')[0].value;
	document.getElementsByName('confirma')[0].className = (bconfirma ? '':'error');
		
	bCEP =	validaMinimoCampo('endereco_cep',8);
	bEndereco =	validaMinimoCampo('endereco_logradouro',4);
	bNumero =	validaMinimoCampo('endereco_numero',1);
	bCidade =	validaMinimoCampo('endereco_cidade',2);
	buf =	validaMinimoCampo('endereco_uf',2);
	
	bCEP_Entrega =	validaMinimoCampo('entrega_cep',8);
	bEndereco_Entrega =	validaMinimoCampo('entrega_logradouro',4);
	bNumero_Entrega =	validaMinimoCampo('entrega_numero',1);
	bCidade_Entrega =	validaMinimoCampo('entrega_cidade',2);
	buf_Entrega =	validaMinimoCampo('entrega_uf',2);
	
	re = (bRG && bNome && bEMail && bFoneCasa && bsenha && bconfirma && bFoneComercial && bCEP && bEndereco && bNumero && bCidade && buf && bCEP_Entrega && bEndereco_Entrega && bNumero_Entrega && buf_Entrega && bCidade_Entrega && buf_Entrega)
	
	
	
	if (document.getElementById('btProximo') != null) {
		btSalvar = document.getElementById('btProximo');
		btSalvar.disabled = (!re);
	}	
	
	return(re);
	
	} else { return(false); }

}

function validarCadastroEAlarmaCliente() {
	rrr = validarCadastroCliente();
	if (!rrr) {
		alert("Campos com a borda vermelha são obrigatorios, por favor preencha todos para continuar ");
	}
	return rrr;
}	


function validaMinimoCampo(campoNome,minimo) {
  oOb = document.getElementsByName(campoNome)[0];
  oOb.className = ((bRG = ( (oRG = document.getElementsByName(campoNome)[0]).value.length >= minimo)) ? '':'error');
  return(bRG);
}


function lembrarSenhaCliente(myid) {

	theCPF = document.getElementById('edCPF');
	var bCPF = isCpf(theCPF.value);
	
	if (!bCPF) {
		alert(theCPF.value +" não é um CPF valido");
	}	
	theCPF.className =  (bCPF ? '':'error');
	
	if ( (bCPF) ) {
			Messagem("Aguarde Enviando.....");
			
			var r = Math.random();
			
			url = UrlBase+"controller.php";
			urlvar = "ac=atccli33000&udoc="+theCPF.value+"&sid="+myid;
			xmlhttp.open("POST",url,true); 
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
			xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
			xmlhttp.setRequestHeader("Connection", "close");
			
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4) {
					if(xmlhttp.status == 200) {
						document.getElementById("textBody").innerHTML = xmlhttp.responseText;
					}
			   	}
			}	
			xmlhttp.send(urlvar);
	
	}
	
	
	

}


function autenticarCliente(myid,item) {
	theCPF = document.getElementById('edCPF');
	theSenha = document.getElementById('edSenha');
	

	var bCPF = isCpf(theCPF.value);
	
	var bSenha = (theSenha.value.length >= 4);
	
	if (!bCPF) {
		alert(theCPF.value +" não é um CPF valido");
		theCPF.focus();
	}	
	
	if (!bSenha) {
		alert("A Senha deve ter mais que 4 digitos");
		theCPF.focus();
	}	
	
	theCPF.className =  (bCPF ? '':'error');
	theSenha.className =  (bSenha ? '':'error');
	
	
	if ( (bCPF) && (bSenha) ) {
			//Messagem("Autenticando.....");
			
			var r = Math.random();
			
			url = UrlBase+"controller.php";
			urlvar = "ac=atccli32000&udoc="+theCPF.value+"&pass="+r+"&man="+theSenha.value+"&sid="+myid;
			xmlhttp.open("POST",url,true); 
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
			xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
			xmlhttp.setRequestHeader("Connection", "close");
			
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4) {
					if(xmlhttp.status == 200) {
					
							var xmlForm = xmlhttp.responseXML;
							//alert(xmlhttp.responseText);
							var credencialValida = xmlForm.getElementsByTagName("Autenticado")[0].childNodes[0].nodeValue;
							if ( credencialValida.indexOf("Sim") != -1 ) {
							
								var usuarioAtivo = xmlForm.getElementsByTagName("Ativo")[0].childNodes[0].nodeValue;
								var ms = xmlForm.getElementsByTagName("Mensagem")[0].childNodes[0].nodeValue;
								
									if ( usuarioAtivo.indexOf("Sim") != -1 ) {
										CarregarItem(item);
									} else { alert(ms);	}									
										
										
							} else {
								alert("Informações não conferem !");
								theCPF.focus();
							}
							
							
					}
			   	}
			}	
			xmlhttp.send(urlvar);
	
	}
	
}


function novoCliente(myid,item) {
	theCPF = document.getElementById('edCPFNovo');
	
	theNome = document.getElementById('edNome');
	theEmail = document.getElementById('edEmail');
	
	theSenha = document.getElementById('edNovaSenha');
	theSenhaConfirma = document.getElementById('edConfirmaSenha');
	

	var bCPF = isCpf(theCPF.value);
	var bEmail = emailValido(theEmail);
	var bNome = (theNome.value.length >= 3);
	var bSenha = (theSenha.value.length >= 4);
	var bSenhaConfirma = (theSenha.value == theSenhaConfirma.value);
	
	if (!bCPF) {
		alert(theCPF.value +" não é um CPF valido");
		theCPF.focus();
	}	
	
	if (!bSenha) {
		alert("A Senha deve ter mais que 4 digitos");
		theCPF.focus();
	}	
	
	if (!bSenhaConfirma) {
		alert("Senha e confirmação deve ser exatamente igual");
		theCPF.focus();
	}	
	
	if (!bNome) {
		alert("Nome deve ter no minimo 3 letras");
		theCPF.focus();
	}	
	
	if (!bEmail) {
		alert("o e-mail é invalido");
		theCPF.focus();
	}	

	theCPF.className =  (bCPF ? '':'error');
	theSenha.className =  (bSenha ? '':'error');
	theSenhaConfirma.className =  (bSenhaConfirma ? '':'error');
	
	theEmail.className =  (bEmail ? '':'error');
	theNome.className =  (bNome ? '':'error');
	
	
	if ( (bCPF) && (bSenha) && (bSenhaConfirma) ) {
			Messagem("Incluindo novo cliente...Aguarde");
			
			var r = Math.random();
			
			url = UrlBase+"controller.php";
			urlvar = "ac=atccli35000&udoc="+theCPF.value+"&pass="+r+"&man="+theSenha.value+"&sid="+myid+"&nome="+theNome.value+"&mail="+theEmail.value;
			xmlhttp.open("POST",url,true); 
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
			xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
			xmlhttp.setRequestHeader("Connection", "close");
			
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4) {
					if(xmlhttp.status == 200) {
							var xmlForm = xmlhttp.responseXML;
							var credencialValida = xmlForm.getElementsByTagName("Cadastrado")[0].childNodes[0].nodeValue;
							if ( credencialValida.indexOf("Sim") != -1 ) {
								CarregarItem(item);
							} else {
								backfromMessage();
								alert("O CPF "+theCPF.value+" já está cadastrado !");
								theCPF.focus();
							}
							
					}
			   	}
			}	
			xmlhttp.send(urlvar);
	
	}
	
}

function pesquisarCepEndereco() {
		cs = document.getElementsByName('endereco_cep')[0].value;
		if (cs.length >= 8) {
				url = UrlBase+"adminController.php?ac=pescep&cep="+cs;
				// Envia a Requisicao
					xmlhttp.open("GET", url, true);
					xmlhttp.setRequestHeader("Content-Type","text/xml; charset=iso-8859-1;");
					
					xmlhttp.onreadystatechange = function() {
							if(xmlhttp.readyState == 4) {
								if (xmlhttp.status == 200) {
										xmlForm = xmlhttp.responseXML;
										document.getElementsByName("endereco_logradouro")[0].value = xmlForm.getElementsByTagName("logradouro")[0].childNodes[0].nodeValue; 
										document.getElementsByName("endereco_cidade")[0].value = xmlForm.getElementsByTagName("cidade")[0].childNodes[0].nodeValue ;
										document.getElementsByName("endereco_bairro")[0].value = xmlForm.getElementsByTagName("bairro")[0].childNodes[0].nodeValue ;
										document.getElementsByName("endereco_uf")[0].value = xmlForm.getElementsByTagName("uf")[0].childNodes[0].nodeValue ;
										validarCadastroCliente();
								} else { alert( xmlhttp.status ); }
							}	
					}							
					xmlhttp.send(null);
		}
}


function pesquisarCepEntrega() {
		cs = document.getElementsByName('entrega_cep')[0].value;
		if (cs.length >= 8) {
				url = UrlBase+"adminController.php?ac=pescep&cep="+cs;
				// Envia a Requisicao
					xmlhttp.open("GET", url, true);
					xmlhttp.setRequestHeader("Content-Type","text/xml; charset=iso-8859-1;");
					
					xmlhttp.onreadystatechange = function() {
							if(xmlhttp.readyState == 4) {
								if (xmlhttp.status == 200) {
										xmlForm = xmlhttp.responseXML;
										document.getElementsByName("entrega_logradouro")[0].value = xmlForm.getElementsByTagName("logradouro")[0].childNodes[0].nodeValue; 
										document.getElementsByName("entrega_cidade")[0].value = xmlForm.getElementsByTagName("cidade")[0].childNodes[0].nodeValue ;
										document.getElementsByName("entrega_bairro")[0].value = xmlForm.getElementsByTagName("bairro")[0].childNodes[0].nodeValue ;
										document.getElementsByName("entrega_uf")[0].value = xmlForm.getElementsByTagName("uf")[0].childNodes[0].nodeValue ;
										validarCadastroCliente();
								} else { alert( xmlhttp.status ); }
							}	
					}							
					xmlhttp.send(null);
		}
}


function copiaEnderecoParaEntrega() {
		document.getElementsByName('entrega_cep')[0].value = document.getElementsByName('endereco_cep')[0].value;
		document.getElementsByName("entrega_logradouro")[0].value = document.getElementsByName("endereco_logradouro")[0].value;
		document.getElementsByName("entrega_cidade")[0].value = document.getElementsByName("endereco_cidade")[0].value;
		document.getElementsByName("entrega_bairro")[0].value = document.getElementsByName("endereco_bairro")[0].value;
		document.getElementsByName("entrega_uf")[0].value = document.getElementsByName("endereco_uf")[0].value;
		document.getElementsByName("entrega_numero")[0].value = document.getElementsByName("endereco_numero")[0].value;
		document.getElementsByName("entrega_complemento")[0].value = document.getElementsByName("endereco_complemento")[0].value;
		document.getElementsByName("entrega_referencia")[0].value = document.getElementsByName("endereco_referencia")[0].value;
		validarCadastroCliente();
		
		
}

function efetuarPagamentoVisa() {
	if (document.getElementsByName('btProximo').length > 0) {
		document.getElementsByName('btProximo')[0].disabled = false;
	}
}	

function fabrewin() {
		var retorno;
		var mpg_popup;
		window.name = "loja";

		if(navigator.appName.indexOf("Netscape") != -1) {
			mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
		} else {
			mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
		}	
		return true;
}

function abreRedeCard() {
		var retorno;
		var mpg_popup;
		window.name = "loja";

		if(navigator.appName.indexOf("Netscape") != -1) {
			mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=780,height=470");
		} else {
			mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=780,height=470");
		}	
		return true;
}

function abreRedeCardCupon() {
		var retorno;
		var mpg_popup;
		window.name = "loja";

		if(navigator.appName.indexOf("Netscape") != -1) {
			mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=280,height=440");
		} else {
			mpg_popup = window.open("", "mpg_popup","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=280,height=440");
		}	
		return true;
}



function exibirBoleto(id,sid) {

	if (document.getElementsByName('btProximo').length > 0) {
		document.getElementsByName('btProximo')[0].disabled = false;
	}

	var r = Math.random();
	url = UrlBase+"gerarboleto.php?id="+id+"&n="+r+"&sid="+sid;
	windowReference = window.open(url,'_blank',"height=650,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,address=no");	  	     		
	windowReference.print();
	if (!windowReference.opener) {
		windowReference.opener = self;
	}
	
}


function windowAymore() {
	var r = Math.random();
	var retorno;
	var pAymore;
	window.name = "loja";
	
		if(navigator.appName.indexOf("Netscape") != -1) {
			pAymore = window.open("", "pAymore","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
		} else {
			pAymore = window.open("", "pAymore","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=765,height=440");
		}	
	return true;
}


function windowChat() {
	var r = Math.random();
	var retorno;
	var pAymore;
	window.name = "loja";
	
		if(navigator.appName.indexOf("Netscape") != -1) {
			pChat = window.open("", "pChat","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,screenX=0,screenY=0,left=0,top=0,width=500,height=300");
		} else {
			pChat = window.open("", "pChat","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,screenX=0,screenY=0,left=0,top=0,width=500,height=300");
		}	
	return true;
}

function iniciarPagina() {
	//setTimeout('AC_Flash()', 2000);
	var r = Math.random();
	url = UrlBase+"controller.php";
	urlvar = "ac=iss&r="+r;
	xmlhttp.open("POST",url,false); 
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(urlvar);
	
	
}


function finalizarPagina() {
	var r = Math.random();
	url = UrlBase+"controller.php";
	urlvar = "ac=ess&r="+r;
	xmlhttp.open("POST",url,false); 
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(urlvar);
}



function enviarPesquisar() {
		
	o = document.getElementById("atendimento");
	pAtendimento = o.options[o.selectedIndex].value;
	
	o = document.getElementById("entrega");
	pEntrega = o.options[o.selectedIndex].value;
	
	o = document.getElementById("preco");
	pPreco = o.options[o.selectedIndex].value;
	
	pDepoimento = document.getElementById("depoimento").value;
	pEmail = document.getElementById("email").value;
	pNome = document.getElementById("nome").value;
	
	
	url = UrlBase+"controller.php" ;
	urlvar = "ac=pssa001007&e="+pEmail+ "&n="+ pNome+ "&depoimento="+ pDepoimento+ "&atendimento="+ pAtendimento+ "&entrega="+ pEntrega+ "&preco="+ pPreco;
	
	xmlhttp.open("POST",url,true);  
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1;");
	xmlhttp.setRequestHeader("Content-length", urlvar.length);			 
	xmlhttp.setRequestHeader("Connection", "close");
	
	xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					document.getElementById("textBody").innerHTML = xmlhttp.responseText;
				} else { alert("Erro de comunicacao com o Servidor"); }
			}	
			}

	document.getElementById("textBody").innerHTML = "<img border='0' src='images/load.gif'> Aguarde...";
	xmlhttp.send(urlvar);
}

	
	





		


	
	









