urlTemp = "";
div = "";
divCarregando = "status";
corAntiga = "";
var cache = new Array();

function ajax(destino,url){	
	document.getElementById(divCarregando).innerHTML = "Requisitando...";
	if(cache[url]==undefined){
      urlTemp = url;	
		div = destino;
		xmlHttp = getObjXmlHttp();
		xmlHttp.onreadystatechange=pronto; 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else{
	   document.getElementById(destino).innerHTML = cache[url];		
		document.getElementById(divCarregando).innerHTML = "";		
	}
}

function ajaxFlu(destino,url){
	document.getElementById(divCarregando).innerHTML = "Requisitando...";
	if(cache[url]===undefined){
	   urlTemp = url;
		div = destino;
		xmlHttp = getObjXmlHttp();
		xmlHttp.onreadystatechange=pronto2; 
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else{	   
	   document.getElementById(destino).style.display = "block";		
	   document.getElementById(destino).innerHTML = cache[url];
		document.getElementById(divCarregando).innerHTML = "";
	}
}

function ajaxNoCache(destino,url){
   div = destino;
	xmlHttp = getObjXmlHttp();
	xmlHttp.onreadystatechange=pronto3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function ajaxFluNoCache(destino,url){
	div = destino;
	xmlHttp = getObjXmlHttp();
	xmlHttp.onreadystatechange=pronto4; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function pronto() 
{  carrTexto(xmlHttp.readyState);
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {	if ( xmlHttp.status == 200) { // resposta do servidor OK	     
	     cache[urlTemp] = unescape(xmlHttp.responseText.replace(/\+/g," "));
		  document.getElementById(div).innerHTML = cache[urlTemp];
      } else { 
         alert("Ocorreu um erro ao acessar esta área do site, por favor informe ao administrador do site. Desculpe o inconveniente."); 
	   }
	   document.getElementById(divCarregando).innerHTML = "";
   }else if(xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3){
	   document.getElementById(divCarregando).innerHTML = "Carregando...";		
		if(window.ActiveXObject){
		   window.scrollTo(0,0);
		}
	}
} 

function pronto2() 
{  carrTexto(xmlHttp.readyState);
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {	if ( xmlHttp.status == 200) { // resposta do servidor OK
	     document.getElementById(div).style.display = "block";
		  cache[urlTemp] = unescape(xmlHttp.responseText.replace(/\+/g," "));
		  document.getElementById(div).innerHTML = cache[urlTemp];
      } else { 
         alert("Ocorreu um erro ao acessar esta área do site, por favor informe ao administrador do site. Desculpe o inconveniente."); 
	   }
	   document.getElementById(divCarregando).innerHTML = "";
   }else if(xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3){
	   //document.getElementById(divCarregando).innerHTML = "Carregando...";
		if(window.ActiveXObject){
		   window.scrollTo(0,0);
		}
	}
} 

function pronto3() 
{  carrTexto(xmlHttp.readyState);
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {	if ( xmlHttp.status == 200) { // resposta do servidor OK
		  document.getElementById(div).innerHTML = unescape(xmlHttp.responseText.replace(/\+/g," "));
      } else { 
         alert("Ocorreu um erro ao acessar esta área do site, por favor informe ao administrador do site. Desculpe o inconveniente."); 
	   }
	   document.getElementById(divCarregando).innerHTML = "";
   }else if(xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3){
	   //document.getElementById(divCarregando).innerHTML = "Carregando...";
		if(window.ActiveXObject){
		   window.scrollTo(0,0);
		}
	}
} 

function pronto4() 
{  carrTexto(xmlHttp.readyState);
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {	if ( xmlHttp.status == 200) { // resposta do servidor OK
	     document.getElementById(div).style.display = "block";
		  document.getElementById(div).innerHTML = unescape(xmlHttp.responseText.replace(/\+/g," "));
      } else { 
         alert("Ocorreu um erro ao acessar esta área do site, por favor informe ao administrador do site. Desculpe o inconveniente."); 
	   }
	   document.getElementById(divCarregando).innerHTML = "";
   }else if(xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3){
	   //document.getElementById(divCarregando).innerHTML = "Carregando...";
		if(window.ActiveXObject){
		   window.scrollTo(0,0);
		}
	}
} 


function getObjXmlHttp()
{	var objXMLHttp=null;
   if (window.XMLHttpRequest)
   {	objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{   objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
	   alert("Seu navegador não consegue mostrar essa página corretamente.");
	}
	return objXMLHttp;
}

function parametros(vet){ //no formato new Array("var1=valor1","var2=valor2","var3=valor3");   
	return "?"+vet.join("&");	
}

function escondeFlutuante(str){
   document.getElementById(str).innerHTML = '';
	document.getElementById(str).style.display='none';
}

function testeAbas(link, classe, cor){
   //muda link
   document.getElementById("link0").className = "aba";
   document.getElementById("link1").className = "aba";
   document.getElementById("link2").className = "aba";
   document.getElementById("link3").className = "aba";
   document.getElementById(link).className = "";
   //muda aba
   document.getElementById("abasImg").className = classe;
}

function isset(vet,key){
   for(pos in vet){	   
		if(pos==key)
		   return true;
	}
	return false;
}

function alimentadoraMulti(){
    if(objetoXmlHttp.readyState == "4" || objetoXmlHttp.readyState == "complete"){
        document.getElementById(id).innerHTML = unescape(objetoXmlHttp.responseText.replace(/\+/g," "));
        document.getElementById("status").style.display = 'none';
        eval(fMulti);
    }
    document.getElementById("status").style.display = 'none';
}

function ajaxMulti(idLocal,url,func){
   document.getElementById("status").style.display = 'block';
   fMulti = func;
   id = idLocal;
   objetoXmlHttp = pegaObjetoXmlHttp(alimentadoraMulti);
   objetoXmlHttp.open("GET",url,true);
   objetoXmlHttp.send(null);
   return true;
}

function abrirJanela(url, largura, altura,  nome){
  if(nome=="ABRIR"){
		window.open(url);
	}else{
		if(document.getElementById("link0").className != "aba"){
			window.open(url+'&estilo=Azul',''+nome+'','dependent=yes,width='+largura+',height='+altura+',scrollbars=yes,resizable=no');
		}
		if(document.getElementById("link1").className != "aba"){
			window.open(url+'&estilo=Azul',''+nome+'','dependent=yes,width='+largura+',height='+altura+',scrollbars=yes,resizable=no');
		}
		if(document.getElementById("link2").className != "aba"){
			window.open(url+'&estilo=Verde',''+nome+'','dependent=yes,width='+largura+',height='+altura+',scrollbars=yes,resizable=no');
		}
		if(document.getElementById("link3").className != "aba"){
			window.open(url+'&estilo=Laranja',''+nome+'','dependent=yes,width='+largura+',height='+altura+',scrollbars=yes,resizable=no');
		}
	}
}

function carregaCSS(cor){
  var css = "./css/estilo";

		if(cor!=""){
			css += cor;
		}
	css += ".css";

	document.getElementById("enquete").value = cor; 

	document.getElementById("status").style.display = 'block';
  objetoXmlHttp2 = pegaObjetoXmlHttp(alimentadoraCSS);
  objetoXmlHttp2.open("GET","pegaConteudo.php?arquivo1="+css,true);
  objetoXmlHttp2.send(null);
}

function pegaObjetoXmlHttp(fncAlimentadora){
  isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')>0);
	isKonqueror = (navigator.userAgent.toLowerCase().indexOf('konqueror')>0);
	isIE = ((!isOpera)&&(navigator.userAgent.toLowerCase().indexOf('msie')>0));
	isMozilla = ((!isOpera)&&(!isKonqueror)&&(!isIE));
	if (isIE)
		{
			strName = "Microsoft.XMLHTTP"
			try {
				objetoXmlHttp = new ActiveXObject(strName);
				objetoXmlHttp.onreadystatechange = fncAlimentadora;
				return objetoXmlHttp;
				}
			catch(e) {
				alert("Erro");
			return
			}

		}
	else
		{objetoXmlHttp = new XMLHttpRequest();
		 objetoXmlHttp.readystatechange = fncAlimentadora;
		 objetoXmlHttp.onload = fncAlimentadora;
		 return objetoXmlHttp;}
}

function alimentadoraCSS(){
      if(objetoXmlHttp2.readyState == "4" || objetoXmlHttp2.readyState == "complete"){
         var css = document.createElement("style");
         css.type = "text/css";
         css.innerHTML = objetoXmlHttp2.responseText;         
		     document.getElementsByTagName('head').item(0).appendChild(css);
         document.getElementById("status").style.display = 'none';
      }
}

function imprimeChaves(vet){
   alert("atencao para a impressao de chaves");
	for(pos in vet)
	   alert(pos);
}

function criaCache(div){
  cache = new Array();
  cache["index.php?ajax=1"] = document.getElementById(div).innerHTML;
}

function carregado(){
   document.getElementById('status').innerHTML='';
   document.getElementById('esquerda').style.display ='block';
   document.getElementById('direita').style.display ='block';
   document.getElementById('abasImg').style.display ='block';
   document.getElementById('meio').style.display ='block';
}

function toggleBlock(id, forceHidden) {

forceHidden = (forceHidden==undefined) ? false : forceHidden;
var toggleObj;
var nohPai;
var linkObj;

linkObj = id.getElementsByTagName('div')[0];
twistyObj = linkObj.getElementsByTagName('div')[0];
	if (twistyObj) {
		toggleObj = id.getElementsByTagName('div')[2];
	} else {
		toggleObj = id.getElementsByTagName('div')[1];
	}

	if (toggleObj) {
		styleObj = toggleObj.style;
		if (styleObj.display != "none" || forceHidden==true) {
			styleObj.display = "none";
			if (linkObj) {
				if (twistyObj) {
					twistyObj.style.backgroundPosition = "0px 0px";
					nohPai = twistyObj.parentNode;
					nohPai.parentNode.className = "box";
				}
			}
		} else {
			styleObj.display = "block";
			if (linkObj) {
				if (twistyObj) {
					twistyObj.style.backgroundPosition = "-10px 0px";
          nohPai = twistyObj.parentNode;
					nohPai.parentNode.className = "box-selected";
				}
			}
		}
	}
}

