//Function to process an XMLHttpRequest.
function processajax (serverPage, obj, getOrPost, str){
	//Get an XMLHttpRequest object for use.
	xmlhttp = getxmlhttp ();
	if (getOrPost == "get"){
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(null);
	} else {
	xmlhttp.open("POST", serverPage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
			}
		}
	xmlhttp.send(str);
	}
}

function getxmlhttp(){

	//Create a boolean variable to check for a valid Microsoft active x instance.
	var xmlhttp = false;

	//Check if we are using internet explorer.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using internet explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-internet explorer browser.
			xmlhttp = false;
		}
	}
	// If not using IE, create a
	// JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		}
	return xmlhttp;
	}

try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
       try{
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }catch(E){
          xmlhttp = false;
       }
    }
}
	



try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
       try{
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }catch(E){
          xmlhttp = false;
       }
    }
}


// GERENCIANDO PARTE DE BUSCA

function updatebusca()
{
	document.getElementById('divbusca').innerHTML = "<br><br><span class=textoDEFAULT> <img src='puzzle/ajax-loader2.gif'> <br> Carregando ...  </span>";
}

///// TROCANDO CAMPO BUSCA

function changebusca(busca){
    //Abre a conexão
    xmlhttp.open("GET","inc_form_busca.php?busca="+busca);
    xmlhttp.onreadystatechange=mostrabusca
	updatebusca();
    //Executa
    xmlhttp.send(null)
}

function mostrabusca() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('divbusca').innerHTML=xmlhttp.responseText
   }
}

/// INTERAÇÃO COM A EMPRESA

function updateinterage()
{
	document.getElementById('lrempresa').innerHTML = "<br><br><span class=textoDEFAULT> <img src='puzzle/ajax-loader2.gif'> <br> Carregando ...  </span>";
}

///// TROCANDO CAMPO BUSCA

function interage(cod){
    //Abre a conexão
    xmlhttp.open("GET",cod);
    xmlhttp.onreadystatechange=mostrainterage
	updateinterage();
    //Executa
    xmlhttp.send(null)
}

function mostrainterage() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('lrempresa').innerHTML=xmlhttp.responseText
   }
}





/// FORMULÁRIO DE CONTATO

//Function to validate the addtask form.
function validatetask1 (thevalue, thename){
	var nowcont = true;
	if (thename == "cnome"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Informe seu nome</span>";
		nowcont = false;
		}
	}
	if (thename == "ctelefone"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Informe seu telefone</span>";
		nowcont = false;
		}
	}
	if (thename == "cemail"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Informe seu e-mail</span>";
		nowcont = false;
		}
	}
	if (thename == "ccidade"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Informe sua cidade</span>";
		nowcont = false;
		}
	}
	if (thename == "cmensagem"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Digite sua mensagem</span>";
		nowcont = false;
		}
	}

	if (nowcont == true){
	}
return nowcont;
var aok;
}


// FUNÇÃO PARA POSTAR O FORMULÁRIO
function getformvalues(fobj, valfunc){
	var str = "";
	aok = true;
	var val;

	//Run through a list of all objects contained within the form.
	for(var i = 0; i < fobj.elements.length; i++){
		if(valfunc) {
			if (aok == true){
				val = 

validatetask1(fobj.elements[i].value,fobj.elements[i].name);
				if (val == false){
					aok = false;
				}
			}
		}
	str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
	}
//Then return the string values.
return str;
}


function submitform(theform, serverPage, objID, valfunc){
	var file = serverPage;
	var str = getformvalues(theform,valfunc);
	//If the validation is ok.
	if (aok == true){
		obj = document.getElementById(objID);
		processajax(serverPage, obj, "post", str);
	}
}


function trim (inputString) {
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces them with one space. If something besides
	// a string is passed in (null, custom object, etc.), then return the input.
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
while (retValue.indexOf(" ") != -1) {
		// Note there are two spaces in the string
		// Therefore look for multiple spaces in the string
		retValue = retValue.substring(0, retValue.indexOf(" ")) + 

retValue.substring(retValue.indexOf(" ")+1, retValue.length); 
		// Again, there are two spaces in each of the strings
	}
return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function verifica() { 
document.all.divnome.innerHTML = '&nbsp;'; 
document.all.divtelefone.innerHTML = '&nbsp;'; 
document.all.divemail.innerHTML = '&nbsp;'; 
document.all.divcidade.innerHTML = '&nbsp;'; 
document.all.divmensagem.innerHTML = '&nbsp;'; 

document.all.statusnome.innerHTML = '&nbsp;'; 
document.all.statustelefone.innerHTML = '&nbsp;'; 
document.all.statusemail.innerHTML = '&nbsp;'; 
document.all.statuscidade.innerHTML = '&nbsp;'; 
document.all.statuscidade.innerHTML = '&nbsp;'; 

document.frmcontato.cnome.className = 'frmDEFAULT'; 
document.frmcontato.ctelefone.className = 'frmDEFAULT'; 
document.frmcontato.cemail.className = 'frmDEFAULT'; 
document.frmcontato.ccidade.className = 'frmDEFAULT'; 
document.frmcontato.cmensagem.className = 'frmDEFAULT'; 


var valido = false;

if ((document.frmcontato.cnome.value == "") || (document.frmcontato.cnome.value== null)) { 
	document.all.divnome.innerHTML = '<b>Preencha seu nome</b>'; 
	document.frmcontato.cnome.focus(); 
	document.frmcontato.cnome.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cnome.className = 'frmDEFAULT'; 
	document.all.divnome.innerHTML = '&nbsp;'; 
	document.all.statusnome.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

if ((document.frmcontato.ctelefone.value == "") || (document.frmcontato.ctelefone.value== null)) { 
	document.all.divtelefone.innerHTML = '<b>Preencha seu telefone</b>'; 
	document.frmcontato.ctelefone.focus(); 
	document.frmcontato.ctelefone.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.ctelefone.className = 'frmDEFAULT'; 
	document.all.divtelefone.innerHTML = '&nbsp;'; 
	document.all.statustelefone.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}
 
if ((document.frmcontato.cemail.value == "") || (document.frmcontato.cemail.value== null)) { 
	document.all.divemail.innerHTML = '<b>Preencha seu email</b>'; 
	document.frmcontato.cemail.focus(); 
	document.frmcontato.cemail.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cemail.className = 'frmDEFAULT'; 
	document.all.divemail.innerHTML = '&nbsp;'; 
	document.all.statusemail.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

if ((document.frmcontato.ccidade.value == "") || (document.frmcontato.ccidade.value== null)) { 
	document.all.divcidade.innerHTML = '<b>Preencha com o nome de sua cidade</b>'; 
	document.frmcontato.ccidade.focus(); 
	document.frmcontato.ccidade.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.ccidade.className = 'frmDEFAULT'; 
	document.all.divcidade.innerHTML = '&nbsp;'; 
	document.all.statuscidade.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}
	
if ((document.frmcontato.cmensagem.value == "") || (document.frmcontato.cmensagem.value== null)) { 
	document.all.divmensagem.innerHTML = '<b>Preencha seu mensagem</b>'; 
	document.frmcontato.cmensagem.focus(); 
	document.frmcontato.cmensagem.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cmensagem.className = 'frmDEFAULT'; 
	document.all.divmensagem.innerHTML = '&nbsp;'; 
	document.all.statusmensagem.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

	if (valido == true){
	
	return true; 
	
	}
}



//// VALIDA E-MAIL PARA NEWSLETTER

///// NEWSLETTER > VERIFICA

function verificanews() { 
document.all.divemail.innerHTML = '&nbsp;';
document.all.statusemail.innerHTML = '&nbsp;'; 
document.frmnewsletter.cemail.className = 'frmok'; 

var valido = false;

if ((document.frmnewsletter.cemail.value == "") || (document.frmnewsletter.cemail.value== null)) { 
	document.all.divemail.innerHTML = '<b>Preencha seu e-mail</b>'; 
	document.frmnewsletter.cemail.focus(); 
	document.frmnewsletter.cemail.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmnewsletter.cemail.className = 'frmok'; 
	document.all.divemail.innerHTML = '&nbsp;'; 
	document.all.statusemail.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

	if (valido == true){
	
	return true; 
	
	}
}


function submitform2(theform, serverPage, objID, valfunc){
	var file = serverPage;
	var str = getformvalues(theform,valfunc);
	//If the validation is ok.
	if (aok == true){
		obj = document.getElementById(objID);
		processajax(serverPage, obj, "post", str);
	}
}


//Function to validate the addtask form.
function validatetask2(thevalue, thename){
	var nowcont = true;
	if (thename == "cemail"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Informe seu e-mail</span>";
		nowcont = false;
		}
	}
	if (nowcont == true){
	}
return nowcont;
var aok;
}



/// FUNÇÃO VERIFICA INDICAÇÃO



function verificaindica() { 
document.all.divnomerem.innerHTML = '&nbsp;'; 
document.all.divemailrem.innerHTML = '&nbsp;'; 
document.all.divnomedest.innerHTML = '&nbsp;'; 
document.all.divemaildest.innerHTML = '&nbsp;'; 
document.all.divmensagem.innerHTML = '&nbsp;'; 

document.all.statusnomerem.innerHTML = '&nbsp;'; 
document.all.statusemailrem.innerHTML = '&nbsp;'; 
document.all.statusnomedest.innerHTML = '&nbsp;'; 
document.all.statusemaildest.innerHTML = '&nbsp;'; 
document.all.statusmensagem.innerHTML = '&nbsp;'; 

document.frmcontato.cnome_rem.className = 'frmDEFAULT'; 
document.frmcontato.cemail_rem.className = 'frmDEFAULT'; 
document.frmcontato.cnome_dest.className = 'frmDEFAULT'; 
document.frmcontato.cemail_dest.className = 'frmDEFAULT'; 
document.frmcontato.cmensagem.className = 'frmDEFAULT'; 


var valido = false;

if ((document.frmcontato.cnome_rem.value == "") || (document.frmcontato.cnome_rem.value== null)) { 
	document.all.divnomerem.innerHTML = '<b>Preencha seu nome</b>'; 
	document.frmcontato.cnome_rem.focus(); 
	document.frmcontato.cnome_rem.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cnome_rem.className = 'frmDEFAULT'; 
	document.all.divnomerem.innerHTML = '&nbsp;'; 
	document.all.statusnomerem.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

if ((document.frmcontato.cemail_rem.value == "") || (document.frmcontato.cemail_rem.value== null)) { 
	document.all.divemailrem.innerHTML = '<b>Preencha seu e-mail</b>'; 
	document.frmcontato.cemail_rem.focus(); 
	document.frmcontato.cemail_rem.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cemail_rem.className = 'frmDEFAULT'; 
	document.all.divemailrem.innerHTML = '&nbsp;'; 
	document.all.statusemailrem.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}
 
if ((document.frmcontato.cnome_dest.value == "") || (document.frmcontato.cnome_dest.value== null)) { 
	document.all.divnomedest.innerHTML = '<b>Preencha o nome do destinatário</b>'; 
	document.frmcontato.cnome_dest.focus(); 
	document.frmcontato.cnome_dest.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cnome_dest.className = 'frmDEFAULT'; 
	document.all.divnomedest.innerHTML = '&nbsp;'; 
	document.all.statusnomedest.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

if ((document.frmcontato.cemail_dest.value == "") || (document.frmcontato.cemail_dest.value== null)) { 
	document.all.divemaildest.innerHTML = '<b>Preencha o e-mail do destinatário</b>'; 
	document.frmcontato.cemail_dest.focus(); 
	document.frmcontato.cemail_dest.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cemail_dest.className = 'frmDEFAULT'; 
	document.all.divemaildest.innerHTML = '&nbsp;'; 
	document.all.statusemaildest.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}
	
if ((document.frmcontato.cmensagem.value == "") || (document.frmcontato.cmensagem.value== null)) { 
	document.all.divmensagem.innerHTML = '<b>Preencha seu mensagem</b>'; 
	document.frmcontato.cmensagem.focus(); 
	document.frmcontato.cmensagem.className = 'frmerro'; 
	var valido = false;
	return false; 
	} 
	else 
	{
	document.frmcontato.cmensagem.className = 'frmDEFAULT'; 
	document.all.divmensagem.innerHTML = '&nbsp;'; 
	document.all.statusmensagem.innerHTML = '<img src=puzzle/bto_OK.gif>'; 
	var valido = true;
	}

	if (valido == true){
	
	return true; 
	
	}
}


function submitform3(theform, serverPage, objID, valfunc){
	var file = serverPage;
	var str = getformvalues(theform,valfunc);
	//If the validation is ok.
	if (aok == true){
		obj = document.getElementById(objID);
		processajax(serverPage, obj, "post", str);
	}
}


//Function to validate the addtask form.
function validatetask3(thevalue, thename){
	var nowcont = true;
	if (thename == "cemail"){
		if (trim (thevalue) == ""){
		document.getElementById("themessage").innerHTML = "<span class=aviso>Informe seu e-mail</span>";
		nowcont = false;
		}
	}
	if (nowcont == true){
	}
return nowcont;
var aok;
}

// INSERIR NO MÍNIMO 3 CARACTERES PARA BUSCA

function validar(cmpbusca){   
  if(buscaprincipal.cmpbusca.value.length < 3){   
    alert("Por favor, preencha pelo menos 3 caracteres");   
    return false;   
  }   
  return true;   
}  



//// EXIBIR FOTOS

function updateStatus()
{
	document.getElementById('verfoto').innerHTML = "<span class=fundocinza> <img src='puzzle/ajax-loader.gif'> <br> Carregando ...  </span>";
}


// function to create a form
function createphoto(e, foto){
	theObject = document.getElementById("verfoto");
	theObject.style.visibility = "visible";
	theObject.style.height = "420px";
	theObject.style.width = "400px";
	var posx = 0;
	var posy = 0;
	posx = e.clientX + document.body.scrollLeft - 200;
	posy = e.clientY + document.body.scrollTop - 250;
	theObject.style.left = posx + "px";
	theObject.style.top = posy + "px";

	//The location we are loading the page into.
	var objID = "verfoto";
//	var serverPage = "theform.php";
	var obj = document.getElementById(objID);
	
	updateStatus('verfoto'); 
	
//	xmlhttp.open("GET", serverPage);
    xmlhttp.open("GET","ver_foto.php?foto="+foto);

	
//    xmlhttp.onreadystatechange=mostrafoto

	
	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		obj.innerHTML = xmlhttp.responseText;
	}
	} // close function
xmlhttp.send(null);
}





///// TROCANDO CAMPO BUSCA

function conteudofoto(url){
    //Abre a conexão
    xmlhttp.open("GET",url);
    xmlhttp.onreadystatechange=mostrafoto
	updateStatus();
    //Executa
    xmlhttp.send(null)
}

function mostrafoto() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('verfoto').innerHTML=xmlhttp.responseText
   }
}


/// INTERAÇÃO COM A EMPRESA

function updatemenu()
{
	document.getElementById('lrmenucat').innerHTML = "<br><br><span class=menuload> <img src='puzzle/ajax-loader3.gif'> <br> Carregando ...  </span>";
}

///// ATUALIZA MENU

function atualizamenu(sessao){
    //Abre a conexão
    xmlhttp.open("GET","inc_lat_esquerda_menu.php?sessao="+sessao);
    xmlhttp.onreadystatechange=showmenu
	updatemenu();
    //Executa
    xmlhttp.send(null)
}

function showmenu() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('lrmenucat').innerHTML=xmlhttp.responseText
   }
}


function atualizamenucat(cat){
    //Abre a conexão
    xmlhttp.open("GET","inc_lat_esquerda_menu.php?cat="+cat);
    xmlhttp.onreadystatechange=showmenucat
	updatemenu();
    //Executa
    xmlhttp.send(null)
}

function showmenucat() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('lrmenucat').innerHTML=xmlhttp.responseText
   }
}


/// INTERAÇÃO VER FOTO

function updatefoto()
{
	document.getElementById('fotoproduto').innerHTML = "<br><br><span class=menuload> <img src='../site/puzzle/ajax-loader3.gif'> <br> Carregando ...  </span>";
}

///// ATUALIZA FOTO

function atualizafoto(sessao){
    //Abre a conexão
    xmlhttp.open("GET",sessao);
    xmlhttp.onreadystatechange=showfoto
	updatefoto();
    //Executa
    xmlhttp.send(null)
}

function showfoto() {
if (xmlhttp.readyState==4){
   //Mostra o HTML recebido
   document.getElementById('fotoproduto').innerHTML=xmlhttp.responseText
   }
}



