// sub menu
		
		Menu = {timer : null, current : null};
		Menu.getStyle = function(name){
			if(document.getElementById) return document.getElementById(name).style;
			else if(document.all) return document.all[name].style;
			else if(document.layers) return document.layers[name];
		}
		Menu.show = function(name){
			if(this.timer) clearTimeout(this.timer);
			this.getStyle(name).visibility = "visible";
			this.current = name;
		}
		Menu.hide = function(){
			this.timer = setTimeout("Menu.doHide()",300);
		}
		Menu.doHide = function(){
			if(this.current){
				this.getStyle(this.current).visibility = "hidden";
				this.current = null;
			}
		}
		
// fim sub menu

var faq_antigo;
var titulo_antigo;
function mostraItem(id, titulo, acao)	{			

				var faq = document.getElementById(id);

				if (faq_antigo && titulo_antigo) {
						faq_antigo.style.display          = "none";
						titulo_antigo.style.fontSize     = "11px";
						titulo_antigo.style.fontWeight = "normal";
						titulo_antigo.style.color         = "#666666";
				}
						
						faq.style.display = acao;
						titulo.style.fontSize     = "12px";
						titulo.style.fontWeight = "bold";
						titulo.style.color         = "#003366";					  

						titulo_antigo = titulo;
  			    faq_antigo    = faq;

		}
		
function cadastraNews() {
	if (document.frmNews.nome.value == "") 	{
	   alert("Por favor, informe seu nome.");
		 document.frmNews.nome.focus();
		 return false;
		}

	if (document.frmNews.email.value == "") 	{
	   alert("Por favor, informe seu email.");
		 document.frmNews.email.focus();
		 return false;
		}
	
	if (!valida_mail(document.frmNews.email.value))	{
		 alert("O email fornecido não parece ser válido.");
		 document.frmNews.email.focus();
		 return false;
	}

	if (document.frmNews.acao[0].checked == false && document.frmNews.acao[1].checked == false) 	{
	   alert("Por favor, escolha uma opção");
		 document.frmNews.acao[0].focus();
		 return false;
		}

	acao = document.frmNews.acao[0].checked ? "cadastrar" : "sair";
  nome = document.frmNews.nome.value;
	email = document.frmNews.email.value;
	url = "cadastra_news.php?nome="+nome+"&email="+email+"&acao=" + acao;
	window.open(url, 'News', 'width=300, height=100');
}

function validaContato(obj) {
  display  = Array("o Nome", "o Email", "o Assunto"," a Mensagem");
  campos = Array("nome", "email", "assunto","msg");
	num_campos = obj.elements.length - 1;
	for (i=0;i<num_campos;i++ ) {
	     if (obj.elements[campos[i]].value == "") {
				  alert("Por favor informe "+display[i]+".");
					obj.elements[campos[i]].focus();
					return false;
	       }
			}
	if (!valida_mail(obj.email.value))	{
		  alert("E-mail não parece ser válido. Por favor, informe outro.");
		  obj.email.focus();
		  return false;
	  }
	return true;
}


function valida_mail(valor) {
	prim = valor.indexOf("@")
	if(prim < 1) return false;
	if(valor.indexOf("@",prim + 1) != -1) return false
	if(valor.indexOf(".") < 1) return false;
	if(valor.indexOf("zipmeil.com") > 0) return false;
	if(valor.indexOf("hotmeil.com") > 0) return false;
	if(valor.indexOf(".@") > 0) return false;
	if(valor.indexOf("@.") > 0) return false;
	if(valor.indexOf(".com.br.") > 0) return false;
	if(valor.indexOf("/") > 0) return false;
	if(valor.indexOf("[") > 0) return false;
	if(valor.indexOf("]") > 0) return false;
	if(valor.indexOf("(") > 0) return false;
	if(valor.indexOf(")") > 0) return false;
	if(valor.indexOf("..") > 0) return false;
	if(valor.indexOf(",") > 0) return false;
	return true;

}

function openFoto(foto, w, h) {
  window.open("../produtos/pop_fotos.php?img="+foto, '', 'width='+w+', height='+h);
}

function setaSub(valor) {
	 if (valor != "") {
				 location.href = "index_suporte.php?cod_cat=" + valor;
  	 }
}

function listaFaqs(valor, cat) {
	 if (valor != "") {
			 location.href = "index_suporte.php?cod_sub=" + valor + "&cod_cat=" + cat;
  	 }
}

function validaVazio(obj, msgErro) {
	if (obj.value == '')	{
	   alert(msgErro);
		 return false;
		}
	
	return true;
}

function validaDados(form) {

	if (!validaVazio(form.user, 'Por favor, preencha o campo USUÁRIO.'))	 return false;
	if (!validaVazio(form.empresa, 'Por favor, preencha o campo EMPRESA.'))	 return false;
	if (!validaVazio(form.login, 'Por favor, preencha o campo E-MAIL.'))	 return false;
	if (!validaVazio(form.senha, 'Por favor, preencha o campo SENHA.'))	 return false;

	if (form.novaSenha.value != form.confirmaSenha.value)	{
      alert('As senhas estão diferentes.');
			return false;
	  }
	
	return true;

}



//================================== AJAX =========================================
// global flag
var isIE = false;

// global request and XML document objects
var req;

var tipo;

function loadXMLDoc(url) {
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChange() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			 switch (tipo) {
			   case "mudaPagina": mudaPagina(); break;
			   case "listaProdutos": listaProdutos(); break;
			   case "listaTiposDownload": listaTiposDownload(); break;
			   case "mudaPaginaProd": mudaPaginaProd(); break;
			 }
		} else {
			alert("There was a problem retrieving the XML data:\n" +		req.statusText);
		}
	}
}
//===========================================================================

//===========================================================================
// paginação da notícia
//===========================================================================

pag = 1;
function mudaPagina() {
		 var exibeNoticias = document.getElementById("noticia");
		 exibeNoticias.innerHTML = "";
		 var items   = !isIE ? req.responseXML : req.responseXML.documentElement;
		 if (items) {
				 var dsc     =  items.getElementsByTagName("descricao");
				 var codigo =  items.getElementsByTagName("codigo");
				 var nome   =  items.getElementsByTagName("nome");

				 var prox = items.getElementsByTagName("proxima");
				 var ant = items.getElementsByTagName("anterior");
				 var total = items.getElementsByTagName("total");

				 for (i=0;i<codigo.length;i++) {
					 		exibeNoticias.innerHTML += "<h2><a href=\"../noticias/index_noticias.php?codigo=" + codigo[i].firstChild.data + "\">" + nome[i].firstChild.data + "</a></h2>";
		          exibeNoticias.innerHTML += "<h3><a href=\"../noticias/index_noticias.php?codigo=" + codigo[i].firstChild.data + "\">" + dsc[i].firstChild.data +  "</a></h3>";
				 }
				
				pgs = total[0].firstChild.data

				if (pgs > 1)	{				
						numeros = "";
						for (i=1; i<=pgs; i++) {
								 if (i == pag)  {
										numeros += "<b>" + i + "</b> | ";
								 }	else
											 numeros += "<a href=\"#\" onClick=\"pag="+i+"; validaNoticia("+cod+")\">" + i + "</a> | ";
						}


						numeros = numeros.substr(0, numeros.length-2);

						document.getElementById("paginas").innerHTML = numeros;


						if (prox.length > 0)	
							 document.getElementById("btNext").innerHTML = "<a href=\"javaScript:paginacao('proxima')\"><img src=\"../img/bt_proximo.gif\" width=\"10\" height=\"9\" border=\"0\"></a>";
							 else
								 document.getElementById("btNext").innerHTML = "&nbsp;";


						if (ant.length > 0)	
							 document.getElementById("btPrev").innerHTML = "<a href=\"javaScript:paginacao('anterior')\"><img src=\"../img/bt_anterior.gif\" width=\"10\" height=\"9\" border=\"0\"></a>";
							 else
									document.getElementById("btPrev").innerHTML = "&nbsp;";
				}
    }
}


cod = 0;
function validaNoticia(codigo) {
  	   url = "listagem.php?pg=" + pag + "&codigo=" + codigo;
			 cod = codigo;
			 tipo = "mudaPagina";
			 loadXMLDoc(url);
}

function paginacao(acao) {
	 pag += acao == "anterior" ? -1 : 1;
	 validaNoticia(cod);
}

//===========================================================================




//===========================================================================
// LISTAGEM DE PRODUTOS
//===========================================================================
function validaProdutos(cod_tipo) {
	 
	 if (cod_tipo != "")	 {
			 url = "listaProdutos.php?tipo=" + cod_tipo;
			 tipo = "listaProdutos";
			 loadXMLDoc(url);
	 }

}

function listaProdutos() {
		 var exibeProdutos = document.getElementById("subcategoria");
		 exibeProdutos.length = 0;
		 exibeProdutos.options[0] = new Option("Selecione o produto:", "");
		 
		 var items   = !isIE ? req.responseXML : req.responseXML.documentElement;
		 if (items)		 {
				 document.getElementById("divSubCat").style.display = "block";
			   var prod = items.getElementsByTagName("prod");
				 var codigo = items.getElementsByTagName("codigo");
				 var nome = items.getElementsByTagName("nome");
				 for (i=0;i<prod.length;i++)	 {
							exibeProdutos.options[i+1] = new Option(nome[i].firstChild.data, codigo[i].firstChild.data);
				 }
		 }
}

function mostraProduto(codigo) {
		if (codigo != "")	{
				location.href = 'produto.php?codigo=' + codigo;
		}
}
//===========================================================================


//===========================================================================
// DOWNLOADS
//===========================================================================
	function validaDownload(cod_prod) {
					if (cod_prod != "")	{
						 url   = "../produtos/listaTiposDownload.php?produto=" + cod_prod;
						 tipo = "listaTiposDownload";
						 loadXMLDoc(url);	
					}
	}

	function listaTiposDownload() {
				 var exibeTipos= document.getElementById("tipodownload");
				 exibeTipos.length = 0;
				 exibeTipos.options[0] = new Option("Tipo de download:", "");
				 
				 var items   = !isIE ? req.responseXML : req.responseXML.documentElement;

				 if (items)		 {
						 document.getElementById("divDownload").style.display = "block"
						 var tipo    = items.getElementsByTagName("tipo");
						 var cod = items.getElementsByTagName("cod");
						 var desc   = items.getElementsByTagName("desc");
						 for (i=0;i<tipo.length;i++)
									exibeTipos.options[i+1] = new Option(desc[i].firstChild.data, cod[i].firstChild.data);
				 }		
	}

	function mudaTipo(tipo) {
		 produtoDown = document.getElementById("produto").value;
		 if (tipo != "" && produtoDown !="") {
				 location.href = "downloads.php?tipo=" + tipo + "&produto=" + produtoDown;
		 }
	}
//===========================================================================

//===========================================================================
// paginação da produtos
//===========================================================================

pagProd = 1;
function mudaPaginaProd() {
		 var exibeProdutos = document.getElementById("menuProd");
		 exibeProdutos.innerHTML = "";
		 var items   = !isIE ? req.responseXML : req.responseXML.documentElement;
		 if (items) {
				 var Prods =  items.getElementsByTagName("prod");
				 var codigoProd =  items.getElementsByTagName("codigo");
				 var nomeProd  =  items.getElementsByTagName("nome");
				 var tipoProd   =  items.getElementsByTagName("tipo");

				 var prox = items.getElementsByTagName("proxima");
				 var ant = items.getElementsByTagName("anterior");
				 var total = items.getElementsByTagName("total");

				 for (i=0;i<Prods.length;i++) {
					   // alert("<li id=\"mnArena\"><a href=\"produto.php?codigo=" + codigoProd[i].firstChild.data +"\"><span>"+nomeProd[i].firstChild.data+" - "+tipoProd[i].firstChild.data+"</span></a></li>");
					 		exibeProdutos.innerHTML += "<li id=\"mnArena\"><a href=\"produto.php?codigo=" + codigoProd[i].firstChild.data +"\"><span>"+nomeProd[i].firstChild.data+" - "+tipoProd[i].firstChild.data+"</span></a></li>";
				 }
				pgs = total[0].firstChild.data;


			 if (pgs > 1) {
						numeros = "";
						for (i=1; i<=pgs; i++) {
								 if (i == pagProd)  {
										numeros += "<b>" + i + "</b> | ";
								 }	else
											 numeros += "<a href=\"#\" onClick=\"pagProd="+i+"; validaProdutoPaginacao("+cod_prod+")\">" + i + "</a> | ";
						}


						numeros = numeros.substr(0, numeros.length-2);

						document.getElementById("paginas").innerHTML = numeros;

						if (prox.length > 0)	
							 document.getElementById("btNext").innerHTML = "<a href=\"javaScript:paginacaoProduto('proxima')\"><img src=\"../img/bt_proximo.gif\" width=\"10\" height=\"9\" border=\"0\"></a>";
							 else
								 document.getElementById("btNext").innerHTML = "&nbsp;";


						if (ant.length > 0)	
							 document.getElementById("btPrev").innerHTML = "<a href=\"javaScript:paginacaoProduto('anterior')\"><img src=\"../img/bt_anterior.gif\" width=\"10\" height=\"9\" border=\"0\"></a>";
							 else
									document.getElementById("btPrev").innerHTML = "&nbsp;";
				}
    }
}


cod_prod = 0;
function validaProdutoPaginacao(codigo) {
  	   url = "listagem.php?pg=" + pagProd + "&codigo=" + codigo;
			 cod_prod = codigo;
			 tipo				= "mudaPaginaProd";
			 loadXMLDoc(url);
}

function paginacaoProduto(acao) {
	 pagProd += acao == "anterior" ? -1 : 1;
	 validaProdutoPaginacao(cod_prod);
}

