// Função para mudar o StyleSheet ... CSS
function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}
//Função única para abrir janelas
function openwindow(arquivo,width,height){
	window.open(arquivo,'jav','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+width+',height='+height+',fullscreen=no');
}
//Função de Busca
function pegapalavra2(palavra)
{
if (palavra != ""){
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} 
catch(e) {
     try {
     ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
	             ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  if(ajax) {
	  ajax.open("POST", "busca_cadastro.php", true);
	  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 ajax.onreadystatechange = function() {
         if(ajax.readyState == 1) {
		 document.getElementById("dica").innerHTML = "<img src='images/icon_wait.gif' /><br />Carregando Sugest&otilde;es";  
	     }
         if(ajax.readyState == 2) {
		 document.getElementById("dica").innerHTML = "<img src='images/icon_wait.gif' /><br />Dificuldades em encontrar alguma sugest&atilde;o - Tente clicar no bot&atilde;o <b>PESQUISAR</b></div>";   
	     }		 
		 if(ajax.readyState == 4 ) {
			  if(ajax.responseXML) {
			    processXML2(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   document.getElementById("dica").innerHTML = "";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "cadastro="+palavra;
         ajax.send(params);
      }
}
}
function processXML2(obj){
var dataArray   = obj.getElementsByTagName("cadastro");
  if(dataArray.length > 0) {
       for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			var numero = item.getElementsByTagName("numero")[0].firstChild.nodeValue;
			var Resultado = "";
			if (numero > 0){
			Resultado = "<strong>Palavras :</strong><br>";
			for (var i = 0; i < numero; i++){
			if(i < (numero-1)){
			Resultado = Resultado + item.getElementsByTagName("titulo")[i].firstChild.nodeValue+" - ";
			}
			else{
			Resultado = Resultado + item.getElementsByTagName("titulo")[i].firstChild.nodeValue+"  ";	
			}
			}
			Resultado = Resultado + "<br /><br />";
			}
			var numeroo = item.getElementsByTagName("numeroo")[0].firstChild.nodeValue;
			var Resultado2 = "";
			Resultado2 = "";
			if (numeroo > 0){
			Resultado2 = "<strong>Empresas :</strong><br>";
			for (var i = 0; i < numeroo; i++){
			if(i < (numeroo-1)){
			Resultado2 = Resultado2 + item.getElementsByTagName("empresa")[i].firstChild.nodeValue+" - ";
			}
			else{
			Resultado2 = Resultado2 + item.getElementsByTagName("empresa")[i].firstChild.nodeValue+"  ";	
			}
			}
			}
			document.getElementById("dica").innerHTML = Resultado + Resultado2;
		 }
	  }
	  else {
		document.getElementById("dica").innerHTML = "";
	  }	  
}
//Submit Form Único
function submitform(){document.form_guia.submit();} function submitform_g(){document.form_google.submit();}

