/*
 * 
 * Arquivo Padrao 
 * Cuidado em altera-lo  
 * Mantenha este comentario e modifique a 
 * data de atualizao 
 * 
 * Atualizao 18/08/2006
 * 
 */
 
mostrarTempoExecucao = false;

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));

formIsUpload = false;
formUpload = null;
intervalUpLoad = null;
intervalTempoExec = null;
tempoExecIni = null;
loginStatus = false;
loginOk     = undefined;
cacheAjax = "";
divCarregado = "";
carrPorcentagemX = 1;
carrPorcentagemY = 23;
acao_lista = "L";
corAntiga = "";


intervalPopUp        = new Array();
janelasPopUp         = new Array();
janelasPopUpRetornar = new Array();
janelasPopUpFoco     = new Array();
janelasPopUpzIndex = 500;
contPOP         = 0;
arrastaX = -20;
arrastaY = -20;
alturaArrasta = null;
posIniX  = -20;
posIniY  = -20;
objArrasta = null;

function carrTexto(param){
	if(document.getElementById('carregando')==undefined){
		var novo = document.createElement("div");
		novo.id = "carregando";
		document.body.appendChild(novo);
		novo.style.position = "fixed";
		novo.className = 'carregando'
		novo.innerHTML = 'Carregando...'; 
		document.getElementById('carregando').style.top = 1;
		document.getElementById('carregando').style.left = 1;
	}
	if(document.getElementById('carregando').style.display == "none")
		document.getElementById('carregando').style.display = "inline"; 
	if(param==4)
			document.getElementById('carregando').style.display = "none"; 
}

function logon(execLogado){
    if(execLogado!=undefined) loginOk = execLogado;
    if(document.getElementById('loginAjax')==undefined){
	    
	    var divLogin = document.createElement("div");
	    divLogin.id = "loginAjax";
	    divLogin.className = "divLogin";
	    
			document.getElementById('esquerdo_baixo').appendChild(divLogin);
    	
	    ajaxCarr('../site/login.php','loginAjax','acao=tela');
    }
    if(document.getElementById('loginAjax').style.display == "none"){
     	document.getElementById('loginAjax').style.display = "inline";
     	document.getElementById('errorLoginAjax').innerHTML = "";
        atvLogin();
        document.formLoginAjax.login.focus();
 	}	
}

function logoff(){
    if(document.getElementById('loginAjax')==undefined){
	    var divLogin = document.createElement("div");
	    divLogin.id = "loginAjax";
	    document.body.appendChild(divLogin);
	    divLogin.style.position = "fixed";
	    if(isIE) novo.style._left = 0;
	    divLogin.style.top = calcTamAbs(100);
	    divLogin.style.left = calcTamAbs(250);
	    divLogin.style.border = "solid";
	    divLogin.style.background = "white";
	    ajaxCarr('../padrao/login.php','loginAjax','acao=tela');
    }
    document.getElementById('loginAjax').style.display = "none";
    ajaxCarr('../padrao/login.php',"loginAjax",'acao=logoff');
}

function logar(){
    ajaxFormCarr('../site/login.php','errorLoginAjax',document.formLoginAjax);
}

function atvLogin(){
    document.getElementById('verificadorLoginAjax').innerHTML = "";
	document.formLoginAjax.codigo.value = "";
    document.formLoginAjax.senha.value = "";
    ajaxCarr('../site/login.php','verificadorLoginAjax','acao=verificador');
}

function sumirLogin(){
    if(document.getElementById('loginAjax')!=undefined)
		document.getElementById('loginAjax').style.display = "none";
}

function alterarSenha(){
	sumirLogin();
	if(document.getElementById('alteraSenhaAjax')==undefined){
	    
	    var divLogin = document.createElement("div");
	    divLogin.id = "alteraSenhaAjax";
	    divLogin.className = "divLogin";
	    if(isIE) 
		    divLogin.style.position = "absolute";
	    else
	    	divLogin.style.position = "fixed";
	    	
    	divLogin.style.top = calcTamAbs(100);
	    divLogin.style.left = calcTamAbs(260);
	    
    	document.body.appendChild(divLogin);
    	ajaxCarr('../site/login.php','alteraSenhaAjax','acao=telaAlterarSenha');
    }
    if(document.getElementById('alteraSenhaAjax').style.display == "none"){
     	document.getElementById('alteraSenhaAjax').style.display = "inline";
     	document.getElementById('errorAlteraSenhaAjax').innerHTML = "";
     	document.alterarSenhaAjax.senha.value = '';
       document.alterarSenhaAjax.senhaVerif.value = '';
     	if(document.alterarSenhaAjax.senhaAtual.value == "")
	     	document.alterarSenhaAjax.senhaAtual.focus();
     	else
	        document.alterarSenhaAjax.senha.focus();
    }
}

function execAltSenha(){
    ajaxFormCarr('../site/login.php','errorAlteraSenhaAjax',document.alterarSenhaAjax);
}

function insereCompromisso(){
	ajaxFormCarr('../site/inserirCompromisso.php','errorInsereCompromissoAjax',document.insereCompromissoAjax);
}

function sumirAlterarSenha(){
    if(document.getElementById('alteraSenhaAjax')!=undefined)
		document.getElementById('alteraSenhaAjax').style.display = "none";
}

function recarregar(arq,acao){
	ajaxStringObj(arq, document.body, (acao=="")?'':'acao='+acao, carrTexto, false);
}

function fechar(phpSelf){
	ajaxString('../site/fechar.php',"cadastro",'phpSelf='+phpSelf, function(p){},false);
}

function seleciona(indice,valor,janela){
    if(parent==window){
        retorna(indice,valor,window.opener.document);
    	window.close();
    }
    else{
        retorna(indice,valor,parent.window.janelasPopUpRetornar[window.name].document); 
        fecharPopUp(window.name);
        parent.window.janelasPopUpFoco[window.name].focus();
	}
}

function arrastaDown(obj,evento){
    arrastaX = evento.clientX;
	arrastaY = evento.clientY;
	objArrasta = obj;
	eventoArrasta = evento;
	posIniX  = parseInt(obj.style.left);
	posIniY  = parseInt(obj.style.top);
	obj.style.zIndex = ++janelasPopUpzIndex;
}

function arrastaUp(){
	if(parent == window){
		arrastaX = -20;
		arrastaY = -20;
	}
	else{
		parent.window.arrastaX = -20;
		parent.window.arrastaY = -20;
	}
}

function arrastaObj(event){
    if(parent == window){
        if(arrastaX!=-20){
		    objArrasta.style.left = posIniX + event.clientX - arrastaX;
			objArrasta.style.top  = posIniY + event.clientY - arrastaY;
			alturaArrasta = event.clientY-parseInt(objArrasta.style.top);
	 	}
	}
	else {
	    if(parent.window.arrastaX!=-20){
	        if(parent.window.objArrasta.id == window.name){
		        var cantoFrameX = parseInt(parent.window.objArrasta.style.left) + 2;
		        var cantoFrameY = parseInt(parent.window.objArrasta.style.top) + parent.window.alturaArrasta + 4;
				parent.window.objArrasta.style.left = cantoFrameX - parent.window.arrastaX + parent.window.posIniX + event.clientX;
				parent.window.objArrasta.style.top  = cantoFrameY - parent.window.arrastaY + parent.window.posIniY + event.clientY;
			}
		}
	}   
}

function cria_popUp(nome,src,obj){
    
    var janelaPrincipal = (parent == window)?this:parent.window;
    if(janelaPrincipal.janelasPopUp[nome]==undefined){
		
		janelaPrincipal.contPOP++;
	    if(janelaPrincipal.contPOP>30) janelaPrincipal.contPOP = 0;
	    janelaPrincipal.janelasPopUpRetornar[nome] = window;
	    janelaPrincipal.janelasPopUpFoco[nome] = obj;
	    janelaPrincipal.janelasPopUp[nome] = document.createElement("div");
	    janelaPrincipal.janelasPopUp[nome].id = nome;
	    janelaPrincipal.janelasPopUp[nome].style.background = "white";
	    var iframe = document.createElement("iFrame");
	    iframe.name = nome;
	    iframe.width = 595;
	    iframe.height = calcTamAbs(400);
	    iframe.src = src;
	    iframe.className = "janelaIFrame";
	    
	    if(isIE) 
		    janelaPrincipal.janelasPopUp[nome].style.position = "absolute";
	    else
	    	janelaPrincipal.janelasPopUp[nome].style.position = "fixed";
	    	
    	janelaPrincipal.janelasPopUp[nome].style.top = calcTamAbs(20+(janelaPrincipal.contPOP*15));
	    janelaPrincipal.janelasPopUp[nome].style.left = calcTamAbs(20+(janelaPrincipal.contPOP*15));
	    janelaPrincipal.janelasPopUp[nome].innerHTML = '<table onmousemove="arrastaObj(event);" onmousedown="arrastaDown(janelasPopUp[\''+nome+'\'],event);" width="599px;" class="janelaPopUp"><tr><td id="tituloJanela'+nome+'" width="'+calcTamAbs(470)+'"> &nbsp; &nbsp;Aguardando ...</td><td style="text-align: right;"></td><img src="../padrao/img/padrao/bt_atualizar.gif" onclick="atualizarPopUp(\''+nome+'\');" style="cursor:pointer; position:relative; top:2; left:-5;"><img src="../padrao/img/padrao/bt_minimizar.gif" onclick="minimizaPopUp(\''+nome+'\');" style="cursor:pointer; position:relative; top:2; left:-3;"><img src="../padrao/img/padrao/bt_fechar.gif" onclick="fecharPopUp(\''+nome+'\');" style="cursor:pointer; position:relative; top:2; left:-2;"></td></tr></table>';
		janelaPrincipal.janelasPopUp[nome].appendChild(iframe);
		janelaPrincipal.document.body.appendChild(janelaPrincipal.janelasPopUp[nome]);
	    
	    if(janelaPrincipal.document.getElementById('minimizarTarefas')==undefined){
	    	var divBarraDeTarefas = document.createElement("table");
	        divBarraDeTarefas.className = "barraPopUp";
	        if(isIE) 
		    	divBarraDeTarefas.style.position = "absolute";
	    	else
	    		divBarraDeTarefas.style.position = "fixed";
	    	divBarraDeTarefas.style.top = 0;  
	    	divBarraDeTarefas.style.left = 0;
	    	divBarraDeTarefas.style.background = "white";
	    	divBarraDeTarefas.style.width = "100%";
	    	
	    	var trDivTarefas = document.createElement("tr");
	    	trDivTarefas.id = "minimizarTarefas";
	    	
	    	divBarraDeTarefas.appendChild(trDivTarefas);
	    	janelaPrincipal.document.body.appendChild(divBarraDeTarefas);
	    	
	    }
	    
	}
    else 
    	janelaPrincipal.janelasPopUp[nome].style.visibility = 'visible';
    
    janelaPrincipal.janelasPopUp[nome].style.zIndex = ++janelaPrincipal.janelasPopUpzIndex;
    if(janelaPrincipal.document.getElementById(nome+"Min")==undefined)	
    	janelaPrincipal.document.getElementById('minimizarTarefas').innerHTML += '<td class="itemBarraPopUp" id="'+nome+'Min" onclick="restauraPopUp(\''+nome+'\')"> &nbsp;Aguardando ...</td>';
	janelaPrincipal.intervalPopUp[nome] = setInterval("colocaTituloPopUp('"+nome+"');",2500);
}

function atualizarPopUp(nome){
    window.frames[nome].location.reload();	
}

function colocaTituloPopUp(nome){
    var janelaPrincipal = (parent == window)?this:parent.window;
    if(janelaPrincipal.document.getElementById(nome+"Min").innerHTML == ' &nbsp;Aguardando &nbsp;&nbsp;&nbsp;'){
		janelaPrincipal.document.getElementById(nome+"Min").innerHTML = ' &nbsp;Aguardando ...';
		janelaPrincipal.document.getElementById('tituloJanela'+nome).innerHTML = ' &nbsp; &nbsp;Aguardando ...';
	}
	else{
		janelaPrincipal.document.getElementById(nome+"Min").innerHTML = ' &nbsp;Aguardando &nbsp;&nbsp;&nbsp;';
		janelaPrincipal.document.getElementById('tituloJanela'+nome).innerHTML = ' &nbsp; &nbsp;Aguardando';
	}
	if(janelaPrincipal.frames[nome].document.body.innerHTML!=""){
	    if((janelaPrincipal.frames[nome].document.getElementById('titulo_lov')==undefined)||(janelaPrincipal.frames[nome].document.getElementById('titulo_lov').innerHTML.trim()=="")){
	        janelaPrincipal.document.getElementById(nome+"Min").innerHTML = ' &nbsp;Sem Ttulo';
			janelaPrincipal.document.getElementById('tituloJanela'+nome).innerHTML = ' &nbsp; &nbsp;Sem Ttulo';
		}
	    else{
		    janelaPrincipal.document.getElementById(nome+"Min").innerHTML = ' &nbsp;'+janelaPrincipal.frames[nome].document.getElementById('titulo_lov').innerHTML;
			janelaPrincipal.document.getElementById('tituloJanela'+nome).innerHTML = ' &nbsp; &nbsp;'+janelaPrincipal.frames[nome].document.getElementById('titulo_lov').innerHTML;
		}
		clearInterval(janelaPrincipal.intervalPopUp[nome]);
	}
}

function fecharPopUp(nome){
    if(parent==window){
	    janelasPopUp[nome].style.visibility = 'hidden';
		document.getElementById('minimizarTarefas').removeChild(document.getElementById(nome+"Min"));
		janelasPopUp[nome].style.zIndex = -500;
	}
	else{
		parent.window.janelasPopUp[nome].style.visibility = 'hidden';
		parent.window.document.getElementById('minimizarTarefas').removeChild(parent.window.document.getElementById(nome+"Min"));
		parent.window.janelasPopUp[nome].style.zIndex = -500;
	}
}

function minimizaPopUp(nome){
	janelasPopUp[nome].style.visibility = 'hidden';
	janelasPopUp[nome].style.zIndex = -500;
}

function restauraPopUp(nome){
    if(janelasPopUp[nome].style.visibility == 'hidden'){
		janelasPopUp[nome].style.visibility = 'visible';
		janelasPopUp[nome].style.zIndex = ++janelasPopUpzIndex;
	}
	else
		janelasPopUp[nome].style.visibility = 'hidden';
}

function destroi_sessao(){
	if(document.getElementById('conteudo')==undefined){
	    var divCont = document.createElement("div");
	    divCont.id = "conteudo";
	    document.body.appendChild(divCont);
    	}
        ajaxCarr('../padrao/destroi_sessao.php','conteudo','');
}

function calcTamAbs(tam){
 return (Math.round((tam*screen.availHeight)/600));
}

function code(evento){
   if(isMozilla)
      return parseInt(evento.which);
   else
      return parseInt(evento.keyCode);
}

function retorna(indice,valor,doc)
{ if (doc == undefined) doc = document;
    
   for(var j=0;j<doc.forms.length;j++)
  {
      for(var i=0;i<valor.length;i++)
      {   
        if (doc.forms[j][indice[i]] != undefined)
          doc.forms[j][indice[i]].value = valor[i]; 
      }
  }  
}


function trocaDiv(id1,id2){
   if(id2[0].length>1){
      for(var i=0;i<id2.length;i++){
         if (document.getElementById(id2[i]) != null)
             document.getElementById(id2[i]).style.display='inline'; 
      }
   }
   else{
      if (document.getElementById(id2) != null)
          document.getElementById(id2).style.display='inline'; 
   }
 
   if(id1[0].length>1){
      for(var i=0;i<id1.length;i++){
        if (document.getElementById(id1[i]) != null)
            document.getElementById(id1[i]).style.display='none'; 
       }
   }
   else{
    if (document.getElementById(id1) != null)
        document.getElementById(id1).style.display='none'; 
   }
}

function colocaJs(str){
     var novo = document.createElement("script");
  novo.text = str;
  document.body.appendChild(novo);
}

function colocaJsSrc(str){
	var novo = document.createElement("script");
	novo.src = str;
	document.body.appendChild(novo);
}

function colocaStilo(str){
	if(!isIE){
		var novo = document.createElement("style");
		novo.type = 'text/css';
		novo.innerHTML = str;
		document.getElementsByTagName("head").item(0).appendChild(novo);
	}
	else{
		var aux = str.split("}");
		for(var i=0;i<aux.length;i++){
			var aux1 = aux[i].split("{");
			if((aux1[1]!=undefined)&&(aux1[1]!="")&&(document.getElementById(replaceAll(aux1[0].replace("#","")," ",""))!=null)){
				var valores = aux1[1].split(";")  
						for(var j=0;j<valores.length;j++){
							var propriedade = valores[j].split(":");
							if(propriedade.length>1)
								document.getElementById(replaceAll(aux1[0].replace("#","")," ","")).style[replaceAll(propriedade[0]," ","")] = replaceAll(propriedade[1]," ","");
				    } 
			}
		}
        
	}
}

function tamAbs(){
 for (var i=0; i<document.all.length; i++){
  if(document.all[i].style.width!='')
   document.all[i].style.width = calcTamAbs(parseInt(document.all[i].style.width));
 }
 if(!isOpera){
   for (var i=0; i<document.styleSheets.length; i++){
      for (var j=0; j< document.styleSheets[i][((isMozilla)?'cssRules':'rules')].length; j++)
         document.styleSheets[i][((isMozilla)?'cssRules':'rules')][j].style.width = calcTamAbs(parseInt(document.styleSheets[i][((isMozilla)?'cssRules':'rules')][j].style.width));
   }
 }
}

function sumirAparecer(m,n,imagens){
    if(document.getElementById((m*n)).style.display=="none"){
       if(imagens!='none')
     document.images['imgMenu'+m].src=imagens+"menos.png";
       document.getElementById((m*n)).style.display="inline";
    }
    else{
       if(imagens!='none')
     document.images['imgMenu'+m].src=imagens+"mais.png";
    document.getElementById((m*n)).style.display="none";
    }
}

function pintaCampo(campo,css){
   campo.className = css;
}

function calcExp(num,div){
   var i=0;
   for(;num>1;i++)
      num = num/div;
   return i;
}

function geraMenuArvore(vetor,p,imagens){
   var aux='';
   var str='<div  ID="'+p+'" style="border-style: none; cursor: pointer; '+((p!=1)?'display:none;':'')+'"><table cellpadding="0" cellspacing="0" style="border-style: none;">';
   for(var i=0;i<vetor.length;i++){
      if((vetor[i][3]==undefined)||(vetor[i][3].length==0))
         str+='<tr onmouseover="this.className='+"'trArvoreNivel"+calcExp(p*100,100)+"Over';"+'" onmouseout="this.className='+"'trArvoreNivel"+calcExp(p*100,100)+"';"+'" class="trArvoreNivel'+calcExp(p*100,100)+'" '+((vetor[i][1]==undefined)?'':'onclick="'+vetor[i][1]+'"')+'><td '+((p==1)?'':'class="menuArvoreTab"')+'>'+(((vetor[i][2]==undefined)||(vetor[i][2]==''))?'&nbsp;':'<img src="'+vetor[i][2]+'">')+'</td><td nowrap class="tdArvoreNivel'+calcExp(p*100,100)+'" onmouseover="this.className='+"'tdArvoreNivel"+calcExp(p*100,100)+"Over';"+'" onmouseout="this.className='+"'tdArvoreNivel"+calcExp(p*100,100)+"';"+'">'+vetor[i][0]+'</td></tr>' ;
      else{
        str+='<tr onmouseover="this.className='+"'trArvoreNivel"+calcExp(p*100,100)+"Over';"+'" onmouseout="this.className='+"'trArvoreNivel"+calcExp(p*100,100)+"';"+'" class="trArvoreNivel'+calcExp(p*100,100)+'" onclick="sumirAparecer('+(i+p)+',100,'+"'"+imagens+"'"+'); '+((vetor[i][1]==undefined)?'':vetor[i][1])+'"><td '+((p==1)?'':'class="menuArvoreTab"')+'>'+((imagens=='none')?'&nbsp;':'<img src="'+imagens+'mais.png" name="imgMenu'+((i+1)*p)+'">')+'</td><td><table style="border-style: none;" cellpadding="0" cellspacing="0"><tr><td>'+(((vetor[i][2]==undefined)||(vetor[i][2]==''))?'':'<img src="'+vetor[i][2]+'">')+'</td><td nowrap class="tdArvoreNivel'+calcExp(p*100,100)+'" onmouseover="this.className='+"'tdArvoreNivel"+calcExp(p*100,100)+"Over';"+'" onmouseout="this.className='+"'tdArvoreNivel"+calcExp(p*100,100)+"';"+'">'+vetor[i][0]+'</td></tr></table></tr><tr><td></td><td>'+geraMenuArvore(vetor[i][3],(i+p)*100,imagens)+'</td></tr>';
      }
   }
   str+='</table></div>';
   return str;
}

function colocaMenuArvore(vetor,id,imagens){
 id.innerHTML = geraMenuArvore(vetor,1,imagens);
}

// function ajax (url,id,colocaMsg){
//     ajaxString(url,id,"",colocaMsg,false);
// }

function ajaxDados(url,id,dados, colocaMsg){
    ajaxString(url,id,montaDados(dados), colocaMsg,false);
}

function ajaxForm(url,id,form, colocaMsg){
    ajaxString(url,id,montaDadosForm(form), colocaMsg,false);
}

function ajaxFormCarr(url,id,form){
	//alert(url);
	ajaxString(url,id,montaDadosForm(form), carrTexto,false);
}

function ajaxDivCarr(url,id,dados){
	ajaxString(url,id,dados, carrTexto,true);
}

function ajaxCarr(url,id,dados){
	ajaxString(url,id,dados, carrTexto,false);
}

function carrPorcentagemXY(x, y){
	carrPorcentagemX = x;
	carrPorcentagemY = y;
}

function mostraTempo(){
   //alert(10);
   if(document.getElementById('tempoExec')==undefined){
	  var novo = document.createElement("div");
	  novo.id = "tempoExec";
	  document.body.appendChild(novo);
	  if(isIE) 
	  	 novo.style.position = "absolute";
	  else
	  	 novo.style.position = "fixed";
	  novo.innerHTML = '0 mms'; 
  	}
  	document.getElementById('tempoExec').style.top = carrPorcentagemY+40;
    document.getElementById('tempoExec').style.left = carrPorcentagemX;
    var aux = new Date();
  	document.getElementById('tempoExec').innerHTML = (aux.getTime()-tempoExecIni.getTime())+" mms";
 }

function carrPorcentagem(param){
  if(document.getElementById('carregando')==undefined){
	  var novo = document.createElement("div");
	  novo.id = "carregando";
	  document.body.appendChild(novo);
	  novo.style.position = "fixed";
	  if(isIE) {
	      novo.style._left = 0;
	      novo.style._top = 0;
	  }
  	  novo.innerHTML = '<table class="tabelaCarregando" cellpading="0" cellspacing="0"><tr><td colspan="4">Carregando...</td></tr><tr class="bordaCarregando"><td id="carregando1" class="carregando">&nbsp;</td><td id="carregando2" class="carregando" style="text-align:right;">0</td><td id="carregando3" class="carregando"> %</td><td id="carregando4" class="carregando">&nbsp;</td></tr></table>'; 
 }
 if(document.getElementById('carregando').style.display == "none"){
     document.getElementById('carregando1').className = "carregando";
     document.getElementById('carregando2').className = "carregando";
     document.getElementById('carregando3').className = "carregando";
     document.getElementById('carregando4').className = "carregando";
     document.getElementById('carregando2').innerHTML = "0";
     document.getElementById('carregando3').innerHTML = " %";
     document.getElementById('carregando').style.display = "inline"; 
 }
 document.getElementById('carregando').style.top = carrPorcentagemY;
 document.getElementById('carregando').style.left = carrPorcentagemX;
 switch(param){
  case -1:
  	document.getElementById('carregando').style.display = "none"; 
  	alert("Erro ao carregar");
  break;
  case -2:
  	document.getElementById('carregando').style.display = "none"; 
  	alert("Div "+divCarregado+" no existe");
  break;
  case 0:
   if(mostrarTempoExecucao){
	   tempoExecIni = new Date();
	   if(intervalTempoExec!=null)
	   	  clearInterval(intervalTempoExec);
	   intervalTempoExec = setInterval("mostraTempo();",1);	
   }
  break;
  case 1: 
   document.getElementById('carregando1').className = "carregado";
   document.getElementById('carregando2').innerHTML = "25";
   document.getElementById('carregando3').innerHTML = " %";
  break;
  case 2: 
   document.getElementById('carregando2').className = "carregado";
   document.getElementById('carregando2').innerHTML = "50";
   document.getElementById('carregando3').innerHTML = " %";
  break;
  case 3:
   document.getElementById('carregando3').className = "carregado";
   document.getElementById('carregando2').innerHTML = "75";
   document.getElementById('carregando3').innerHTML = " %"; 
   document.getElementById('carregando4').className = "carregado";
  break;
  case 4:
   document.getElementById('carregando4').className = "carregado";
   document.getElementById('carregando2').innerHTML = "100";
   document.getElementById('carregando3').innerHTML = " %";
   document.getElementById('carregando').style.display = "none"; 
   if(mostrarTempoExecucao)
   	  clearInterval(intervalTempoExec);
  break;
 }
}

function exec (url){
    ajaxString(url,"","", function(p){},false);
}

function execDados (url, dados){
    ajaxString(url,"",montaDados(dados), function(p){},false);
}

function execForm (usrl, form){
 ajaxString(url,"",montaDadosForm(form), function(p){},false);
}

function limparId (id) {
    if(document.getElementById(id)!=undefined)
    	document.getElementById(id).innerHTML = "";
}

function montaDados(dados){
    var link = "";
    for (chave in dados) {
       link += chave + "=" + dados[chave] + "&";
    }
    return link;
}

function montaDadosForm(form){
   formUpload = form;
   if((form==undefined)||(form.elements.length == 0))
      return "";
   else{
      var retorno = "";
      for(var i = 0; i + 1 < form.elements.length; i++){
         formIsUpload = ((form.elements[i].type == "file")||(formIsUpload));
         if(((form.elements[i].type != "checkbox")&&(form.elements[i].type != "radio"))||(form.elements[i].checked))
	            retorno += form.elements[i].name + "=" + form.elements[i].value + "&";
      }	 
      formIsUpload = ((form.elements[i].type == "file")||(formIsUpload));
      return (retorno + form.elements[i].name + "=" + form.elements[i].value);
   }        
}

function replaceAll(str,part,subst){
    str = str.replace(/part/g,subst); 
    return str;
}

function ajaxFormArqs(url, id, form, colocaMsg, substitui){
	colocaMsg(0);
	if(document.getElementById("iFrameUpload")==undefined){
		var iFrameUpload = document.createElement("iframe");
		iFrameUpload.id = "iFrameUpload";
		iFrameUpload.name = "iFrameUpload";
        iFrameUpload.style.border = "1px none white";
        iFrameUpload.style.width = 1;
        iFrameUpload.style.height = 1;
		document.body.appendChild(iFrameUpload);
	}
	colocaMsg(1);
	if(document.getElementById("iFrameUpload").style.display == "none"){
		document.getElementById("iFrameUpload").style.display = "inline";
	}
	form.target = "iFrameUpload";
	form.enctype = "multipart/form-data";
	form.method = "POST";
	form.submit();
	colocaMsg(2);
	intervalUpLoad = setInterval("trocaIFrameDiv('"+id+"',"+colocaMsg+","+substitui+")",1000);
	formIsUpload = false;
}

function trocaIFrameDiv(id,colocaMsg,substitui){
    colocaMsg(3);
    if(window.frames["iFrameUpload"].document.body.innerHTML!=""){
		if(substitui)
			document.getElementById(id).innerHTML += replaceAll(replaceAll(window.frames["iFrameUpload"].document.body.innerHTML,"window.open","//"),"alert","");
		else
			document.getElementById(id).innerHTML = replaceAll(replaceAll(window.frames["iFrameUpload"].document.body.innerHTML,"window.open","//"),"alert","");
		document.getElementById("iFrameUpload").style.display = "none";
		window.frames["iFrameUpload"].document.body.innerHTML = "";
		colocaMsg(4);
        clearInterval(intervalUpLoad);
	} 
}

function ajaxString(url, id, parametros, colocaMsg, substitui) {
    divCarregado = id;
    if(formIsUpload)
    	ajaxFormArqs(url, id, formUpload, colocaMsg, substitui);
    else
		ajaxStringObj(url, (id=="")?undefined:document.getElementById(id), parametros, colocaMsg, substitui);
}

function ajaxStringObj(url, obj, parametros, colocaMsg, substitui) {
    var httpRequest = false;
    colocaMsg(0);
    try {
        httpRequest=new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e) {
        try {
            httpRequest=new ActiveXObject("Microsoft.XMLHTTP")
        } 
        catch (e) {
            try {
                httpRequest = new XMLHttpRequest();
            } 
            catch (e) {
                alert ('Seu Navegador no suporta XMLHttpRequest');
                return null;
            }
        }
    }
    httpRequest.onreadystatechange = function(){
        colocaMsg(httpRequest.readyState); 
        if(httpRequest.readyState==4){
           if(httpRequest.status == 200){
           	   colocaMsg(4);
               cacheAjax = httpRequest.responseText; 
	           if(obj==undefined){
	               colocaMsg(-2);
	           }
	           else{
		          if(substitui)
		             obj.innerHTML += cacheAjax;
		          else
		             obj.innerHTML = cacheAjax;
	           }
           }
           else { 
              colocaMsg(-1);
           }
        }
    }
    if(url == "") url = "./";
    httpRequest.open("POST", url, true);
    httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpRequest.send(acertaAcento(parametros));

}

function acertaAcento(param){
	var retorno = '';

	if (param != '') {
			var arr = param.split('&');
			var arrU;
			for(var i=0;i<arr.length;i++){
					arrU = arr[i].split('=');
					if(arrU.length>2){
							for(var j=2;j++<arrU.length;j++){
								arrU[1] += "="+arrU[i];
							}  
					}
					if ((arrU[0]=="acao")&& ((arrU[1]=="L") || (arrU[1]=="LOV"))) acao_lista = arrU[1];
					if(i==0)
					retorno += encodeURIComponent(verificaChar(arrU[0]))+"="+encodeURIComponent(verificaChar(arrU[1]));
					else
						retorno += "&"+encodeURIComponent(verificaChar(arrU[0]))+"="+encodeURIComponent(verificaChar(arrU[1]));
			}
			if(acao_lista=="LOV") carrPorcentagemXY(460, 1);
			else                  carrPorcentagemXY(1, 23); 
			retorno += "&acao_lista="+acao_lista;
	}
 return retorno;
}

function verificaChar(str){
	str = replaceAll(str,">","");
	str = replaceAll(str,"<","");
	str = replaceAll(str,"=","");
	str = replaceAll(str,"","");
	str = replaceAll(str,"%","");

	return str;
}

function alteraSenhaLogado(){
   document.getElementById('alteraSenhaAjax').innerHTML='';
   document.getElementById('alteraSenhaAjax').style.display='block';
   ajaxCarr('../site/login.php','alteraSenhaAjax','acao=telaAlterarSenha');
}

