// JavaScript Document
var caminho_loading="./";
function FormataData(campo) 
	{ 
		var tam = campo.value.length; 
		if ( ( tam == 2 ) || ( tam == 5 ) ) 
		{ 
			campo.value = campo.value + "/"; 
		} 
	} 
	
	function Oculta_Linhas(tabela,inicio,fim,obj) 
	{
	 	var valor;
	 	for (i=inicio; i<=fim; i++)
		{
			valor=document.getElementById(tabela+"_linha_"+i).style.display;
			if (valor=="none")
				document.getElementById(tabela+"_linha_"+i).style.display="";
			else
				document.getElementById(tabela+"_linha_"+i).style.display="none";
		}
		
		if (obj.src!="")
		{
			if (stristr(obj.src,'menu_tab_close.gif',true))
				obj.src=obj.src.replace('menu_tab_close.gif','menu_tab_open.gif');
			else							
				obj.src=obj.src.replace('menu_tab_open.gif','menu_tab_close.gif');
		}		
	}
	
	function stristr( haystack, needle, bool ) {
		// http://kevin.vanzonneveld.net
		// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   bugfxied by: Onno Marsman
		// *     example 1: stristr('Kevin van Zonneveld', 'Van');
		// *     returns 1: 'van Zonneveld'
		// *     example 2: stristr('Kevin van Zonneveld', 'VAN', true);
		// *     returns 2: 'Kevin '
	 
		var pos = 0;
	 
		haystack += '';
		pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );
		if( pos == -1 ){
			return false;
		} else{
			if( bool ){
				return haystack.substr( 0, pos );
			} else{
				return haystack.slice( pos );
			}
		}
	}
	
	function MudaOrdem(campo) {
		var campo_ordem=document.getElementById('campo_ordem').value,ordem=document.getElementById('ordem').value ;
		if (campo_ordem!=campo) {
			document.getElementById('campo_ordem').value=campo;
			document.getElementById('ordem').value='asc';
	 	} else {
			if (ordem=='asc') {
				document.getElementById('ordem').value='desc';
			} else {
				document.getElementById('ordem').value='asc';
			}
		}
	}
	
	function imprimePesquisa() {
		document.getElementById("imprime_resultado_pesquisa").submit();
	}
	
	function mostraSubetapa(cod_subetapa,num_observacoes)
	{
		var stiloLink=document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display;
		var num=parseInt(num_observacoes);

		if (stiloLink=="none")
		{
			for (var i=1; i<=num; i++)
			{
				document.getElementById("tr_observacao_"+cod_subetapa+"_"+i).style.display="";
				try{
					if (document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML=="Nenhuma observação inserida")
					{
						document.getElementById("tr_observacao_"+cod_subetapa+"_"+i).style.display="";
						document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="";
						document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML="Nenhuma observação inserida ; ";
					} else {
						document.getElementById("tr_observacao_"+cod_subetapa+"_"+i).style.display="";
						document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="";
					}
				} catch(e)
				{
					document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="none";
				}
				
			}
		} else
		{	
			for (var i=1; i<=num; i++)
			{
				//alert(document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML);
				try{
					if (!document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML=="Nenhuma observação inserida ; ")
					{
						document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML="Nenhuma observação inserida";
						document.getElementById("tr_observacao_"+cod_subetapa+"_"+i).style.display="none";
						document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="none";
					} else if (!document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML=="Nenhuma observação inserida")
					{
						document.getElementById("tr_observacao_"+cod_subetapa+"_"+i).style.display="";
						document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="";
						document.getElementById("esconde_"+cod_subetapa+"_"+i).innerHTML="Nenhuma observação inserida ; ";
					} else
					{
						document.getElementById("tr_observacao_"+cod_subetapa+"_"+i).style.display="none";
						document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="none";
					}
				} catch(e)
				{
					document.getElementById("tr_link_subetapa_"+cod_subetapa).style.display="none";
				}
				
			}
		}
	}
	
	function mostraEtapa(cod_etapa,num_subetapas)
	{

		var stiloLink=document.getElementById("tr_subetapa_"+cod_etapa+"_1").style.display;
		var num=parseInt(num_subetapas)+1;

		if (stiloLink=="none")
		{
			for (var i=1; i<=num; i++)
			{
				try{
					var cod=document.getElementById("tr_subetapa_"+cod_etapa+"_"+i+"_cod").value;
					var obs=document.getElementById("tr_subetapa_"+cod_etapa+"_"+i+"_obs").value;
					document.getElementById("tr_subetapa_"+cod_etapa+"_"+i).style.display="";
					document.getElementById("tr_link_subetapa_"+cod).style.display="";
					for (var i2=1; i2<=obs; i2++)
					{
						try{
							if (document.getElementById("esconde_"+cod+"_"+i2).innerHTML=="Nenhuma observação inserida")
							{
								document.getElementById("tr_observacao_"+cod+"_"+i2).style.display="none";
								document.getElementById("tr_link_subetapa_"+cod).style.display="none";
							} else
								document.getElementById("tr_observacao_"+cod+"_"+i2).style.display="";
						} catch(e)
						{
							document.getElementById("tr_observacao_"+cod+"_"+i2).style.display="none";
						}
					}
				} catch(e)
				{
					
				}
			}
		} else
		{	
			for (var i=1; i<=num; i++)
			{
				try{
					var cod=document.getElementById("tr_subetapa_"+cod_etapa+"_"+i+"_cod").value;
					var obs=document.getElementById("tr_subetapa_"+cod_etapa+"_"+i+"_obs").value;
	
					document.getElementById("tr_subetapa_"+cod_etapa+"_"+i).style.display="none";
					document.getElementById("tr_link_subetapa_"+cod).style.display="none";
					for (var i2=1; i2<=obs; i2++)
						document.getElementById("tr_observacao_"+cod+"_"+i2).style.display="none";
				} catch(e)
				{
					
				}
			}
		}
	}
	
	function validaConclusao()
	{
		var status=document.getElementById("status").value;
		if (status=="")
		{
			alert("Preencha o campo Status");
			document.getElementById("status").focus();
			return false;
		}
		
		document.getElementById("formulario").submit();
	}
	
	function validaLink()
	{
		var linker=document.getElementById("link").value;
		var descricao=document.getElementById("descricao").value;
		if (descricao=="")
		{
			alert("Preencha o campo Descrição");
			document.getElementById("descricao").focus();
			return false;
		}
		
		if (linker=="")
		{
			alert("Preencha o campo Link");
			document.getElementById("link").focus();
			return false;
		}
		
		document.getElementById("formulario").submit();
	}
	
	function validaLinkAlterar()
	{
		var linker=document.getElementById("link").value;
		var descricao=document.getElementById("descricao").value;
		if (descricao=="")
		{
			alert("Preencha o campo Descrição");
			document.getElementById("descricao").focus();
			return false;
		}
		
		document.getElementById("formulario").submit();
	}
	
	function atualizar(caminho)
	{
		try {
			location.reload(caminho);
		} catch(e)
		{
			location.href(caminho);
		}
	}
	
	function VerCalendario(obj,id){
	
		document.getElementById("fram").style.visibility="visible";
			
		document.getElementById('fram').style.left  = getPosicaoElemento(id).left-150;
		document.getElementById('fram').style.top = getPosicaoElemento(id).top+25;
			
		cal1xx.select(obj,id,'dd/MM/yyyy');
		//document.rpi.prazo_oficial_de
		return false;
	
	
	}
	
	
	function getPosicaoElemento(elemID){
		var offsetTrail = document.getElementById(elemID);
		var offsetLeft = 0;
		var offsetTop = 0;
		while (offsetTrail) {
			offsetLeft += offsetTrail.offsetLeft;
			offsetTop += offsetTrail.offsetTop;
			offsetTrail = offsetTrail.offsetParent;
		}
		if (navigator.userAgent.indexOf("Mac") != -1 && 
			typeof document.body.leftMargin != "undefined") {
			offsetLeft += document.body.leftMargin;
			offsetTop += document.body.topMargin;
		}
		return {left:offsetLeft, top:offsetTop};
	}
	
	function confirmacaoUsuario(ancora,msg)
	{
		var resp=confirm(msg); 
		if(resp) { 
			location.href=ancora;
		}else{
			return false; 
		}

	}

// JavaScript Document
                    function mostraModalCaminho(width,height,caminho)
                    {
			//caminho=url_encode(caminho);
                        if (width=='' || width==undefined)
                            width="100%";
                        if (height=='' || height==undefined)
                            height="100%";
                            
                        var conta_largura=(100-width.replace("%","")-2)/2;
                        var conta_altura=(100-height.replace("%","")-50)/2;
                        conta_altura+="%";
                        conta_largura+="%";
                        try
                        {
                            visualizarJanelaCaminho(width,height,conta_largura,conta_altura,caminho);
                        } catch(e)
                        {
                            criaJanelaCaminho(width,height,conta_largura,conta_altura,caminho);
                        }
                    }
                    
                    function criaJanelaCaminho(width,height,conta_largura,conta_altura,caminho)
                    {
                        var theBody = document.getElementsByTagName('body')[0];
                        var div_fundo = document.createElement('div');
                        div_fundo.id="div_fundo";
                        theBody.appendChild(div_fundo);
                        var div_centro = document.createElement('div');
                        div_centro.id="div_centro";
                        div_centro.style.width="675px";
                        div_centro.style.height="450px";
                        div_centro.style.top=conta_altura;
                        div_centro.style.left=conta_largura;
                        if (navigator.appVersion.indexOf("MSIE") != -1){
                            div_centro.className='fixed';
                            gHideSelects = true;
                        } else {
                            div_centro.style.position='fixed';
                        }
                        theBody.appendChild(div_centro);
                        var cabecalho_div_centro = document.createElement('div');
                        cabecalho_div_centro.id="cabecalho_div_centro";
                        cabecalho_div_centro.innerHTML="<div align='right'><div align='center' class='fechar' onclick='Javascript:fecharJanelaCaminho()'>X</div></div>";
                        document.getElementById("div_centro").appendChild(cabecalho_div_centro);
                        var frame_div_centro = document.createElement('iframe');
                        frame_div_centro.id="frame_div_centro";
                        frame_div_centro.style.width="100%";
                        frame_div_centro.style.height="97%";
                        frame_div_centro.style.position="relative";
                        frame_div_centro.style.top="0px";
                        frame_div_centro.style.left="0px";
                        frame_div_centro.frameBorder="0";
                        frame_div_centro.src=caminho_loading+"loading.php?caminho="+caminho;
                        document.getElementById("div_centro").appendChild(frame_div_centro);
                        document.body.style.overflow="hidden";
                    }
                    
                    function visualizarJanelaCaminho(width,height,conta_largura,conta_altura,caminho)
                    {
                        document.getElementById('div_fundo').style.display="";
                        document.getElementById('div_centro').style.display="";
                        document.getElementById('div_centro').style.width=width;
                        document.getElementById('div_centro').style.height=height;
                        document.getElementById('div_centro').style.top=conta_altura;
                        document.getElementById('div_centro').style.left=conta_largura;
                        if (navigator.appVersion.indexOf("MSIE") != -1){
                            document.getElementById('div_centro').className='fixed';
                            gHideSelects = true;
                        } else {
                            document.getElementById('div_centro').style.position='fixed';
                        }
                        document.getElementById('cabecalho_div_centro').style.display="";
                        document.getElementById('frame_div_centro').style.display="";
                        document.getElementById('frame_div_centro').style.width="100%";
                        document.getElementById('frame_div_centro').style.height="97%";
                        document.getElementById('frame_div_centro').style.position="relative";
                        document.getElementById('frame_div_centro').style.top="0px";
                        document.getElementById('frame_div_centro').style.left="0px";
						caminho=url_encode(caminho);
                        document.getElementById('frame_div_centro').src=caminho_loading+"loading.php?caminho="+caminho;
                        document.body.style.overflow="hidden";
                    }
        
                    function mostraModal(id_div)
                    {
                        document.getElementById(id_div).style.display="";
                        var width=document.getElementById(id_div).style.width;
                        var height=document.getElementById(id_div).style.height;
                        var conta_largura=(100-width.replace("%",""))/2;
                        var conta_altura=(100-height.replace("%",""))/2;
                        conta_altura+="%";
                        conta_largura+="%";
                        var width=document.getElementById(id_div).style.top=conta_altura;
                        var width=document.getElementById(id_div).style.left=conta_largura;
                    }
        
                    
                    function hideSelectBoxes() {
                        for(var i = 0; i < document.forms.length; i++) {
                            for(var e = 0; e < document.forms[i].length; e++){
                                if(document.forms[i].elements[e].tagName == "SELECT") {
                                    document.forms[i].elements[e].style.visibility="hidden";
                                }
                            }
                        }
                    }
                    
                    function displaySelectBoxes() {
                        for(var i = 0; i < document.forms.length; i++) {
                            for(var e = 0; e < document.forms[i].length; e++){
                                if(document.forms[i].elements[e].tagName == "SELECT") {
                                document.forms[i].elements[e].style.visibility="visible";
                                }
                            }
                        }
                    }
                    
                    
                    function fecharJanelaCaminho(){
			document.body.style.overflow="";
                        document.getElementById('div_fundo').style.display="none";
                        document.getElementById('div_centro').style.display='none';
                        displaySelectBoxes();
                    }
                    
                    function fecharJanela(id){
                        document.getElementById(id).style.display="none";
                    }
                    
                    function url_encode(str) {
                        var hex_chars = "0123456789ABCDEF";
                        var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
                        var n, strCode, hex1, hex2, strEncode = "";
                    
                        for(n = 0; n < str.length; n++) {
                            if (noEncode.test(str.charAt(n))) {
                                strEncode += str.charAt(n);
                            } else {
                                strCode = str.charCodeAt(n);
                                hex1 = hex_chars.charAt(Math.floor(strCode / 16));
                                hex2 = hex_chars.charAt(strCode % 16);
                                strEncode += "%" + (hex1 + hex2);
                            }
                        }
                        return strEncode;
                    }


	