var opcSaida = "";

function campoVazio(ObjSel,Campo) {
 if (ObjSel.value == '') {
   alert("Favor preencha o campo '"+ Campo +"' para continuar.");
   ObjSel.focus();
   return false;}
}

//Limpa campos do formulário de orçamento
function limpaorcamento()
{
	document.orcamento.Nome.value = '';
	document.orcamento.Email.value = '';
	document.orcamento.CidadeUF.value = '';
	document.orcamento.CEP.value = '';
	document.orcamento.CNPJCPF.value = '';
	document.orcamento.IERG.value = '';
	document.orcamento.FoneFax.value = '';
	document.orcamento.Contato.value = '';
}

//Valida formulário de orçamento
function validaorcamento()
{
	if (document.orcamento.Nome.value == ''){
	  alert('Preencha o nome!');
	  document.orcamento.Nome.focus();
	  return false;
	}
	if (document.orcamento.Email.value == ''){
	  alert('Preencha o Email!');
	  document.orcamento.Email.focus();
	  return false;
	}
	if (document.orcamento.CidadeUF.value == ''){
	  alert('Preencha a cidade/uf!');
	  document.orcamento.CidadeUF.focus();
	  return false;
	}
	if (document.orcamento.FoneFax.value == ''){
	  alert('Preencha o fone/fax!');
	  document.orcamento.FoneFax.focus();
	  return false;
	}
	if (document.orcamento.Contato.value == ''){
	  alert('Preencha o Contato!');
	  document.orcamento.Contato.focus();
	  return false;
	}
	listaSCat('orcamento');
	//Aguarde(1);
	//setTimeout ( 'Aguarde(0)', 5000);
	Modalbox.show('orcamento_finaliza.asp', {title: 'Orcamento...', width: 600});
    window.scrollTo(0, 0);
}

//Função de impressão
 function f_imprimir()
 {
    if (!window.print){ 
      alert("Use o Netscape  ou Internet Explorer \n nas versőes 4.0 ou superior!") 
      return
    } 
      window.print()
 }

//Exibe foto do detalhe do produto
function mostraFoto(cod)
{
  var det = document.frmProduto.fotoDetalhe.value;
  if (det!='') {
	Modalbox.show('fotoproduto.asp?Produto='+cod+'&det='+det, {title: 'Foto do produto...', width: 600});  
  }else{
    Modalbox.show('fotoproduto.asp?Produto='+cod, {title: 'Foto do produto...', width: 600});
  }
}

//Envia a requisição ao servidor, de acordo com a ação do usuário
function Loja(secao, parametro) {
	window.scrollTo(0, 0);
	Aviso(1); //exibe aviso "Aguarde..."
    var url="detalhaproduto.asp?"+secao+"="+encodeURIComponent(parametro);
    requisicaoHTTP("GET",url,true);
}

function Exibir(pag, onde) {
	opcSaida = onde;
	Aviso(1); //exibe aviso "Aguarde..."
    requisicaoHTTP("GET",pag,true);
}


function Assi(secao, parametro) {
	window.scrollTo(0, 0);
	Aviso(1); //exibe aviso "Aguarde..."
    var url="listaAssistenciaTecnicaDet.asp?"+secao+"="+encodeURIComponent(parametro);
    requisicaoHTTP("GET",url,true);
}

//Exibe ou oculta a mensagem de espera
function Aviso(exibir) {
	var saida = document.getElementById("avisos");
	if(exibir){
		//saida.className = "aviso";
		//saida.innerHTML = "Aguarde... Processando!";
		//Exibe globo
		var imagem = document.createElement("img");
		imagem.setAttribute("src", "carregando.gif");
		imagem.setAttribute("alt", "Carregando...");
		imagem.style.cssText = 'display:block; width:50px; height:50px; margin:60px auto;'; 
		saida.appendChild(imagem);
	} else {
	  saida.className = "";
	  saida.innerHTML = "";
	}
}

function Aguarde(exibir) {
	var saida = document.getElementById("aguarde");
	if(exibir){
		saida.className = "aviso";
		saida.innerHTML = "Aguarde... Processando!";
	} else {
	  saida.className = "";
	  saida.innerHTML = "";
	}
}

function temporizador(onde)
{
  	setTimeout ( 'msgAguarde(0, "'+onde+'")', 5000);
}

function msgAguarde(exibir, onde) {
    var saida = document.getElementById(onde);
	if(exibir){
		saida.className = "aviso";
		saida.innerHTML = "Aguarde... Processando!";
	} else {
	  saida.className = "";
	  saida.innerHTML = "";
	}
	temporizador(onde);
}

//Exibe a resposta do servidor
function trataDados(){
  var info = ajax.responseText;
  if (opcSaida==""){
    var saida = document.getElementById("principal");
  }else{
	var saida = document.getElementById(opcSaida);
  }
  saida.innerHTML = info;
  v_salvaEstado(); //salva o novo conteúdo na cache*********NOVO****************
  Aviso(0);
}


//JAVASCRIPT DAS FUNÇÕES AJAX DOS MENUS DO SITE ***************************************************
//<![CDATA[
var tempo; 
function iniciaAjax() {
	var objetoAjax = false;
		if (window.XMLHttpRequest) {
			objetoAjax = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {		
		objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
			objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");			
		} catch(ex) {	
		objetoAjax = false;
       }
		}
	}
	return objetoAjax;
}
 
// Captura o link clicado
function linkClicado() {
	var listaLinks = document.getElementById("menu");
	var links = listaLinks.getElementsByTagName("a");
    for (var i=0; i<links.length; i++) {
		links[i].onclick = function() {
		var query = this.getAttribute("href").split("?")[1];
        var arquivo = "produtos2.asp?"+(query);
		var conteudo = document.getElementById("principal"); //* TESTE
		return !requisitar(arquivo);
		};
	}

    //TRATAMENTO PARA MENU SUPERIOR ****************************
	var listaLinksSup = document.getElementById("menuSub");
	var linksSup = listaLinksSup.getElementsByTagName("a");
    for (var i=0; i<linksSup.length; i++) {
		linksSup[i].onclick = function() {
		var nomeArquivo = this.getAttribute("href").split("?ajax=")[1];
		//alert(nomeArquivo);
		var conteudo = document.getElementById("principal"); //* TESTE
		return !requisitar(nomeArquivo);
		};
	}
}

function carregando(container) {
	while (container.hasChildNodes()) {
	container.removeChild(container.lastChild);
	}
	
	var imagem = document.createElement("img");
	imagem.setAttribute("src", "carregando.gif");
	imagem.setAttribute("alt", "Carregando...");
	imagem.style.cssText = 'display:block; width:50px; height:50px; margin:130px auto;'; 
	container.appendChild(imagem);
}

function requisitar(arquivo) {
			var requisicaoAjax = iniciaAjax(); 
				if(requisicaoAjax) {
					carregando(document.getElementById("principal"));     
					requisicaoAjax.onreadystatechange = function () {	
					trataResposta(requisicaoAjax);	
					};
  requisicaoAjax.open("GET", arquivo, true);  
  tempo = setTimeout(tempoEsgotado, 50000); //Se em 50 segundos a página nao responder, retorna erro
  requisicaoAjax.send(null);    
    return true;
  } else {
    return false;
  }
}

function trataResposta(requisicaoAjax) {                 
  if(requisicaoAjax.readyState == 4) {
	clearTimeout(tempo);
	if(requisicaoAjax.status == 200 || requisicaoAjax.status == 304) {         
	document.getElementById("principal").innerHTML = requisicaoAjax.responseText;
	v_salvaEstado(); //salva o novo conteúdo na cache*********NOVO****************
} 
}
}
function tempoEsgotado() {
	var requisicaoAjax = iniciaAjax(); 
	requisicaoAjax.abort();
	alert("Ocorreu um problema na conexao. Tente mais tarde");
	}
window.onload = linkClicado;
// ]]>
