var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var browser;
if (isNS4) browser="NS4";
if (isIE4) browser="IE4";
if (isIE5) browser="DOM";
if (isNS6) browser="DOM";




var estadomenu=1;
var pos_atual_menu_x=-2;
var pos_destino_menu_x=-2;


var pos_atual_conteudo_x=85;
var pos_destino_conteudo_x=85;
var velocidade=10;

function setaelemento(x){
	if (browser=="DOM") {
	elemento=document.getElementById(x);
	}
	else {
	elemento=document.all[x];
	}
}

function mudaestado(){
if (estadomenu==1) {
pos_destino_menu_x=-196;
estadomenu=0;
}
else {
pos_destino_menu_x=-2;
estadomenu=1;
}
}

function movemenu(){
	if (pos_atual_menu_x!=pos_destino_menu_x) {
		if (pos_destino_menu_x < pos_atual_menu_x) {
	pos_atual_menu_x=pos_atual_menu_x-Math.ceil((pos_atual_menu_x-pos_destino_menu_x)/velocidade);
		}
		else {
	pos_atual_menu_x=pos_atual_menu_x-Math.floor((pos_atual_menu_x-pos_destino_menu_x)/velocidade);
		}
	setaelemento("menuportal");
	elemento.style.left=pos_atual_menu_x;
	}
}

function destacaitem (x,y,z,e) {
	switch (e) {
	case 0:
	coritem='#FFE700';
	larguraitem='190';
	corfonte='#000000';
	break;

	case 1:
	coritem='#FFF7C0';
	larguraitem='190';
	corfonte='#000000';	
	break;

	case 2:
	coritem='#D3D3D3';
	larguraitem='190';
	corfonte='#000000';	
	break;
	}

	if (x!=-1) {
	setaelemento("itemmenu"+x);
	elemento.style.backgroundColor=coritem;
	elemento.style.color=corfonte;
	}

	if (y!=-1) {
	setaelemento("itemsubmenu"+y);	
	elemento.style.backgroundColor=coritem;
	elemento.style.color=corfonte;	
	}
	
	if (z!=-1) {
	setaelemento("itemsubsubmenu"+z);	
	elemento.style.backgroundColor=coritem;
	elemento.style.color=corfonte;	
	}
}


function mostraitens(x,y,e) {
	if(e==1) {
	visivel='visible';
	}	
	else {
	visivel='hidden';
	}
	
  	if(x!=-1) {
	setaelemento("submenu"+x);	
	elemento.style.visibility=visivel;
	}
	
	if(y!=-1) {
	setaelemento("subsubmenu"+y);	
	elemento.style.visibility=visivel;
	}
}

timer=window.setInterval('movemenu()',50);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

tms=new Array();

function Over(n,q){
	if (n!=0){
		document.getElementById("s"+n).style.display="block";
		document.getElementById("s"+n).style.visibility="visible";
		document.getElementById("d"+n).style.color = "#ffffff";
		for (i=1; i<q+1; i++){
			if (i!=n){document.getElementById("s"+i).style.display="none";}
		}
	}
	else {
		for (i=1; i<q+1; i++){
			document.getElementById("s"+i).style.display="none";
		}
	}
}


// test variables 
var myHeight = 480; 
var myWidth = 640; 
var isResizable = true; 

function createTarget(form) { 
_target = form.target; 
_colon = _target.indexOf(":"); 
if(_colon != -1) { 
form.target = _target.substring(0,_colon); 
form.args = _target.substring(_colon+1); 
} else if(typeof(form.args)=="undefined") { 
form.args = ""; 
} 
if(form.args.indexOf("{")!=-1) { 
_args = form.args.split("{"); 
form.args = _args[0]; 
for(var i = 1; i < _args.length;i++) { 
_args[i] = _args[i].split("}"); 
form.args += eval(_args[i][0]) + _args[i][1]; 
   } 
} 
form.args = form.args.replace(/ /g,""); 
_win = window.open('',form.target,form.args); 
_win.document.focus(); 
return true; 
} 

function DoPrinting(){
if (!window.print){
alert("Use o Netscape  ou Internet Explorer \n nas versões 4.0 ou superior!")
return
}
window.print()
}

function exit(){
close();
}

function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()

//Hides the div

/*
function hideIt(div){
	if(bw.bw){
		div="divLoadCont"
		obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?document[div]:0; 
		obj.visibility='hidden'
	}
}
onload=hideIt;
*/

function SombreaMenu(x){
document.getElementById("m"+x).style.background = "#888888";
document.getElementById("d"+x).style.color = "#ffffff";
}

function LimpaMenu(x){
document.getElementById("m"+x).style.background = "";
document.getElementById("d"+x).style.color = "#003366";
}

function Atualiza_Arq(VMeio,VNome,VInclude){
document.location = "default.cfm?VMeio="+VMeio+"&VNome="+VNome+"&VInclude="+VInclude;
}

function Atualiza_Perf(VMeio,VNome){
document.location = "default.cfm?VMeio="+VMeio+"&VNome="+VNome;
}

function Atualiza_Variavel(VMeio,VNome,VInclude,VCod,VObj){
document.location = "default.cfm?VMeio="+VMeio+"&VNome="+VNome+"&VInclude="+VInclude+"&VCod="+VCod+"&VObj="+VObj;
}

var estilo="display:''";
var objeto='';

function expandit(recObj){
	objeto = recObj.style;
	if (objeto.display=="none")
		objeto.display="";
	else
		objeto.display="none";	
}

function abrelink(endereco,largura,altura) {
	if (largura==null) {
	largura='464';
	}
	if (altura==null) {
	altura='342';
	}
	window.open(endereco,'','width='+largura+',height='+altura+',scrollbars=1,status=0,toolbars=0,resizable=1');
}
	
function abreendereco(endereco,largura,altura) {
	if (largura==null) {
	largura='400';
	}
	if (altura==null) {
	altura='300';
	}
	window.open('http://portal.saude.gov.br/portal/'+endereco,'','width='+largura+',height='+altura+',scrollbars=1,status=0,toolbars=0,resizable=1');
}	

function abrejanela(endereco) {
	window.open(endereco,'','width=620,height=400,scrollbars=1,status=0,toolbar=1,resizable=1');
}

function redirect(x){
	if (x == 1) {document.acao.nome.selectedIndex=document.acao.cod.selectedIndex;}
	else if (x == 2) {document.acao.cod.selectedIndex=document.acao.nome.selectedIndex;}
	else if (x == 3) {document.acao.comp.selectedIndex=0;}
	else if (x == 4) {document.acao.AnoComp.selectedIndex=0;}
	else if (x == 5) {
		opcoes = document.acao.nome1.options;
		opcoesCod = document.acao.cod1.options;
		for(i = 0; i < opcoes.length; ++i) {
			opcoes(i).selected = opcoesCod(i).selected;
		}
	//document.acao.nome1.selectedIndex=document.acao.cod1.selectedIndex;
	}
	else if (x == 6) {
		opcoes = document.acao.cod1.options;
		opcoesNome = document.acao.nome1.options;
		for(i = 0; i < opcoes.length; ++i) {
			opcoes(i).selected = opcoesNome(i).selected;
	}
	//document.acao.cod1.selectedIndex=document.acao.nome1.selectedIndex;
}
}

/* 
	Data de Criação: 14.09.05
	Descrição: Função que valida se algum objeto de formulário do tipo Radio ou Checkbox foi selecionado.
			   Retorna uma lista contendo os valores dos objetos selecionados.
	Argumentos:
			[Obrigatório] noForm = nome do formulário que utiliza a função 
			[Obrigatório] noObj  = nome do objeto do formulário (radio ou checkbox)  
	Exemplo de uso:	
			<input type="button" name="btn_exemplo" value="Exemplo" onClick="javascript:fValidaCheckBoxRadio(this.form,'nomeDoObjetoInput');" />

*/

function fValidaCheckBoxRadio(noForm,noObj){
	var selecionado = "";
	var campo = eval("noForm."+noObj); // Objeto do formulário
	var tam = campo.length;
	
	if(tam>0){
		for(var i=0;i<tam;i++){
			if(campo[i].checked == true){ //objeto foi selecionado
				selecionado = selecionado+","+campo[i].value;
			}
		}
	}else{
		if(campo.checked == true){ //objeto foi selecionado
				selecionado = campo.value;
			}
	}
	
	return selecionado;
}

/*
	Data de criação: 20.10.05
	Descrição: Função que marca/desmarca todos objetos checkbox de um formulário.
	Argumentos:
			[Obrigatório] noForm 	  = "document." +nome do formulário que utiliza a função 
			[Obrigatório] noObj  	  = nome do objeto do formulário (radio ou checkbox)  
			[Obrigatório] tpOperacao  = tipo de operação a ser executada: marcar ou desmarcar.
	Exemplo de uso:	
			<input type="button" name="btn_exemplo" value="Exemplo" onClick="javascript:fMarcaDesmarca(document.formExemplo,'nomeDoObjetoInput');" />
*/	

function fMarcaDesmarca(noForm,noObj,tpOperacao){
	var campo = eval("noForm."+noObj); // Objeto do formulário
	var tam = campo.length;
	var op = tpOperacao;
	
	if(op == 1){
		for(var i=0;i<tam;i++){
			campo[i].checked = true; // marca todos os checkboxes
		}
	}
	
	if(op == 0){
		for(var i=0;i<tam;i++){
			campo[i].checked = false; // desmarca todos os checkboxes
		}
	}
}	
	
function fRetornaSelecionado(noForm,noObj){
	var selecionado = "";
	var campo = eval("noForm."+noObj); // Objeto do formulário
	var tam = campo.length;
	
	if(tam>0){
		for(var i=0;i<tam;i++){
			if(campo[i].checked == true){ //objeto foi selecionado
				selecionado = campo[i].value;
			}
		}
	}else{
		if(campo.checked == true){ //objeto foi selecionado
				selecionado = campo.value;
			}
	}
	
	return selecionado;
}


function result(cod){
	window.open('http://portal.saude.gov.br/portal/aplicacoes/enquete/gravavotos.cfm?enquete='+cod,'resultado','width=400px; height=600px', 'scrollbars=1,status=0,toolbars=0,resizable=1');
    return true;
}
 
function grava(){
	document.lista.action = "http://portal.saude.gov.br/portal/aplicacoes/enquete/gravavotos.cfm";         
}
/*
	Função para validação de e-mail
	fValidaEmail()
*/
function fValidaEmail(campo){
	var emailValido = true;
	
	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo)) {
		emailValido = false;
	}
	return emailValido;
}


/* 
	fMostra() e fEsconde() utilizam as imagens abaixo 
*/

var imgMais = new Image(30,30);
var imgMenos = new Image(30,30);

imgMais.src = "<cfoutput>#portal#</cfoutput>/aplicacoes/imagens/max.gif";
imgMenos.src = "<cfoutput>#portal#</cfoutput>/aplicacoes/imagens/min.gif";

/*
	Função: 	fMostra(id)
	Descrição: 	Função que altera a propriedade (style.display) de um bloco de html 
				gerenciando qual bloco de html pode abrir um novo bloco e qual pode ser excluído (ocultado).
				Utiliza duas imagens: max.gif e min.gif.
					
	Atributos: 	'id' 	  - id do objeto html.

	Exemplo: 	<div id="7" style="display:none;">
					<input type="text" name="CAMPO" size="50" maxlength="255"> 
					<span id="-7">
						<a href="#" onClick="fEsconde(7);"><img border="0" width="15" height="15" src="<cfoutput>#portal#</cfoutput>/aplicacoes/imagens/min.gif"></a>
					</span>
					<span id="+7">
						 <a href="#" onClick="fMostra(8);"><img border="0" width="15" height="15" src="<cfoutput>#portal#</cfoutput>/aplicacoes/imagens/max.gif"></a>
					</span>
				</div>
	Obs:		A aplicação de enquete utiliza a fMostra e a fEsconde.						
*/

function fMostra(id){
	
	var idAnterior = id-1;
	
	// imagem de [+] do campo 'id-1'
	imagem = document.getElementById('+'+idAnterior);
	imagem.style.display = "none";
	
	// proximo campo
	campo = document.getElementById(id);
	campo.style.display = "";	
	campo = document.getElementById('-'+idAnterior);
	
	// habilita o [-] para todos os campos anteriores
	while(campo.style.display == "none"){
		campo.style.display = "";
		idAnterior--;

		if(idAnterior == 0){break;}
		campo = document.getElementById('-'+idAnterior);
	}
}

/*
	Função: 	fEsconde(id)
	Descrição:	Função que altera a propriedade (style.display) de um bloco de html 
				gerenciando qual bloco de html pode ser excluído do formulário (ocultado).
				Utiliza duas imagens: max.gif e min.gif.
				
	Atributos: 	'id' 	  - id do objeto html.
				'noForm'  - nome do formulário.
				'noCampo' - nome do campo txt que se encontra dentro de um bloco de hmtl a ser ocultado
	Exemplo: 	<div id="1">
					<input type="text" name="CAMPO" size="50" maxlength="255"> 
					<span id="-1" style="display:none;">
						<a href="#" onClick="fEsconde(1);"><img border="0" width="15" height="15" name="imgMenos1" src="<cfoutput>#portal#</cfoutput>/aplicacoes/imagens/min.gif"></a>
					</span>
				</div>			
*/

function fEsconde(id,noForm,noCampo){
	var maxObj = 10;
	
	if(id != maxObj){
		var proxId = id+1;
		campo = document.getElementById(proxId);
		
		while(campo.style.display == ""){
			eval("document."+noForm+"."+noCampo+id+".value = document."+noForm+"."+noCampo+proxId+".value");
			proxId++;
			id++;
			
			if(proxId == maxObj) {break;}
			campo = document.getElementById(proxId);
		}
			
		var idAtual = id-1; // para mostrar o [+] do ultimo campo visivel
		
		campo = document.getElementById(id);
		campo.style.display = "none"; // oculta o ultimo campo
		eval("document."+noForm+"."+noCampo+id+".value=''"); // zera o valor do ultimo campo
		
		imagem = document.getElementById('+'+idAtual);
		imagem.style.display = "";
		
		campo = document.getElementById('-'+idAtual);
		
		// Caso existam apenas 2 campos, desabilita o [-]
		if(idAtual == 2){
			while(campo.style.display == ""){			
				campo.style.display = "none";
				idAtual--;
				
				if(idAtual==0){break;}
				campo = document.getElementById('-'+idAtual);
			}
		}
	}else{ // ultimo campo ativo
		var idAtual = id-1;
		campo = document.getElementById(idAtual);
		campo.style.display = "none"; // oculta o ultimo campo
		eval("document."+noForm+"."+noCampo+idAtual+".value=''"); // zera o valor do ultimo campo
		
		//para habilitar o [+] do ultimo campo ativo
		idAtual--;
		imagem = document.getElementById('+'+idAtual);
		imagem.style.display = "";
	}
}

/*
	AJAX
*/
var req; 
function loadXMLDoc(url,dv){
	par = dv;
	req = null; 
	// Procura por um objeto nativo (Mozilla/Safari) 
	if (window.XMLHttpRequest) { 
		req = new XMLHttpRequest(); 
		req.onreadystatechange = processReqChange; 
		req.open("GET", url, true); 
		req.send(null); 
	// Procura por uma versão ActiveX (IE) 
	}else if (window.ActiveXObject) { 
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
		if (req) { 
			req.onreadystatechange = processReqChange; 
			req.open("GET", url, true); 
			req.send(); 
		} 
	} 
} 

function processReqChange() { 
	// apenas quando o estado for "completado" 
	if (req.readyState == 4) { 
		// apenas se o servidor retornar "OK" 
		if (req.status == 200) { 
			// procura pela div id="news" e insere o conteudo 
			// retornado nela, como texto HTML 
			document.getElementById(par).innerHTML = req.responseText; 
		} else { 
			alert("Houve um problema ao obter os dados:\n" + req.statusText); 
		}
	} document.getElementById('dvStatus').style.display='none';
} 

function carregaCombo(obj, pg, dv){
	loadXMLDoc(pg+"&co_sitio="+obj.value, dv);
    document.getElementById('dvStatus').style.display='';
}
function pesquisarParam(pg,param,dv){
	loadXMLDoc(pg+"&"+param, dv);
    document.getElementById('dvStatus').style.display='';
}
function montaCombo(pg,param,dv){
	loadXMLDoc(pg+param, dv);
	document.getElementById('dvStatus').style.display='';
}
function pesquisar(pg,dv){
	loadXMLDoc(pg, dv);
    document.getElementById('dvStatus').style.display='';
}

function pesquisarSemStatus(pg,dv){
	loadXMLDoc(pg, dv);
}

// Recarrega a cada 60000 milissegundo (60 segundos) 
//setInterval("buscarNoticias()", 600); 


/*
	Função: DateFormat
	Descrição: Valida um campo data. Elimina valores não numéricos.
*/
// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
// If you are using any Java validation on the back side you will want to use the / because
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if(navigator.appName == "Netscape") {
if (navigator.appVersion < "5") {
isNav4 = true;
isNav5 = false;
}
else
if (navigator.appVersion > "4") {
isNav4 = false;
isNav5 = true;
   }
}
else {
isIE4 = true;
}
function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
vDateType = dateType;
// vDateName = object name
// vDateValue = value in the field being checked
// e = event
// dateCheck
// True  = Verify that the vDateValue is a valid date
// False = Format values being entered into vDateValue only
// vDateType
// 1 = mm/dd/yyyy
// 2 = yyyy/mm/dd
// 3 = dd/mm/yyyy
//Enter a tilde sign for the first number and you can check the variable information.
if (vDateValue == "~") {
alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
vDateName.value = "";
vDateName.focus();
return true;
}
var whichCode = (window.Event) ? e.which : e.keyCode;
// Check to see if a seperator is already present.
// bypass the date if a seperator is present and the length greater than 8
if (vDateValue.length > 8 && isNav4) {
if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
return true;
}
//Eliminate all the ASCII codes that are not valid
var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
if (alphaCheck.indexOf(vDateValue) >= 1) {
if (isNav4) {
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
else {
vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
return false;
   }
}
if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
return false;
else {
//Create numeric string values for 0123456789/
//The codes provided include both keyboard and keypad values
var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
if (strCheck.indexOf(whichCode) != -1) {
if (isNav4) {
if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
if (vDateValue.length == 6 && dateCheck) {
var mDay = vDateName.value.substr(2,2);
var mMonth = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
//Turn a two digit year into a 4 digit year
if (mYear.length == 2 && vYearType == 4) {
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30;
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
}
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (!dateValid(vDateValueCheck)) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
return true;
}
else {
// Reformat the date for validation and set date type to a 1
if (vDateValue.length >= 8  && dateCheck) {
if (vDateType == 1) // mmddyyyy
{
var mDay = vDateName.value.substr(2,2);
var mMonth = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
}
if (vDateType == 2) // yyyymmdd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(4,2);
var mDay = vDateName.value.substr(6,2);
vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
}
if (vDateType == 3) // ddmmyyyy
{
var mMonth = vDateName.value.substr(2,2);
var mDay = vDateName.value.substr(0,2);
var mYear = vDateName.value.substr(4,4)
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
}
//Create a temporary variable for storing the DateType and change
//the DateType to a 1 for validation.
var vDateTypeTemp = vDateType;
vDateType = 1;
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (!dateValid(vDateValueCheck)) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateType = vDateTypeTemp;
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
         }
      }
   }
}
else {
// Non isNav Check
if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateName.value = "";
vDateName.focus();
return true;
}
// Reformat date to format that can be validated. mm/dd/yyyy
if (vDateValue.length >= 8 && dateCheck) {
// Additional date formats can be entered here and parsed out to
// a valid date format that the validation routine will recognize.
if (vDateType == 1) // mm/dd/yyyy
{
var mMonth = vDateName.value.substr(0,2);
var mDay = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vDateType == 2) // yyyy/mm/dd
{
var mYear = vDateName.value.substr(0,4)
var mMonth = vDateName.value.substr(5,2);
var mDay = vDateName.value.substr(8,2);
}
if (vDateType == 3) // dd/mm/yyyy
{
var mDay = vDateName.value.substr(0,2);
var mMonth = vDateName.value.substr(3,2);
var mYear = vDateName.value.substr(6,4)
}
if (vYearLength == 4) {
if (mYear.length < 4) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateName.value = "";
vDateName.focus();
return true;
   }
}
// Create temp. variable for storing the current vDateType
var vDateTypeTemp = vDateType;
// Change vDateType to a 1 for standard date format for validation
// Type will be changed back when validation is completed.
vDateType = 1;
// Store reformatted date to new variable for validation.
var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
if (mYear.length == 2 && vYearType == 4 && dateCheck) {
//Turn a two digit year into a 4 digit year
var mToday = new Date();
//If the year is greater than 30 years from now use 19, otherwise use 20
var checkYear = mToday.getFullYear() + 30;
var mCheckYear = '20' + mYear;
if (mCheckYear >= checkYear)
mYear = '19' + mYear;
else
mYear = '20' + mYear;
vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
// Store the new value back to the field.  This function will
// not work with date type of 2 since the year is entered first.
if (vDateTypeTemp == 1) // mm/dd/yyyy
vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
if (vDateTypeTemp == 3) // dd/mm/yyyy
vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
}
if (!dateValid(vDateValueCheck)) {
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateType = vDateTypeTemp;
vDateName.value = "";
vDateName.focus();
return true;
}
vDateType = vDateTypeTemp;
return true;
}
else {
if (vDateType == 1) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
if (vDateType == 2) {
if (vDateValue.length == 4) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 7) {
vDateName.value = vDateValue+strSeperator;
   }
}
if (vDateType == 3) {
if (vDateValue.length == 2) {
vDateName.value = vDateValue+strSeperator;
}
if (vDateValue.length == 5) {
vDateName.value = vDateValue+strSeperator;
   }
}
return true;
   }
}
if (vDateValue.length == 10&& dateCheck) {
if (!dateValid(vDateName)) {
// Un-comment the next line of code for debugging the dateValid() function error messages
//alert(err);
alert("Data Inválida.\nPor favor, digite a data de novo.");
vDateName.focus();
vDateName.select();
   }
}
return false;
}
else {
// If the value is not in the string return the string minus the last
// key entered.
if (isNav4) {
vDateName.value = "";
vDateName.focus();
vDateName.select();
return false;
}
else
{
vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
return false;
         }
      }
   }
}
function dateValid(objName) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
// var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = objName;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
//Adjustment for short years entered
if (strYear.length == 2) {
strYear = '20' + strYear;
}
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
   }
}
else {
if (intday > 28) {
err = 10;
return false;
      }
   }
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

/*
	Função: fMostraEsconde
	Descrição: Oculta/Exibe um bloco de html.
	Atributo:  id [requerido] = atributo 'id' do objeto html a ser ocultado/exibido.
*/
function fMostraEsconde(id){
	obj = document.getElementById(id);
	if(obj.style.display == "none"){
		obj.style.display = "";
	}else{
		obj.style.display = "none"
	}
}

/*
	**********************************************************************
		Descrição: Conjunto de funcoes para rotacionar uma imagem
	**********************************************************************

This notice must be untouched at all times.

wz_rotateimg.js    v. 0.5
The latest version is available at
http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Copyright (c) 2003 Walter Zorn. All rights reserved.
Created 9. 10. 2003 by Walter Zorn (Web: http://www.walterzorn.com )
Last modified: 9. 10. 2003

Can rotate images on a webpage by arbitrary angles.


This program is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License
at http://www.gnu.org/copyleft/gpl.html for more details.
*/


// PATH TO THE TRANSPARENT 1*1 PX IMAGE (required by NS 4 as spacer)
var spacer = 'transparentpixel.gif';




//window.onerror = new Function('return true;');


function rr_getPageXY(r_o)
{
	if (rr_n4)
	{
		r_o.x = r_o.img.x || 0;
		r_o.y = r_o.img.y || 0;
	}
	else
	{
		var r_p = r_o.img;
		r_o.x = r_o.y = 0;
		while (r_p)
		{
			r_o.x += parseInt(r_p.offsetLeft);
			r_o.y += parseInt(r_p.offsetTop);
			r_p = r_p.offsetParent || null;
		}
	}
};


function rr_getDiv(r_x)
{
	return (
		document.all? document.all[r_x]
		: rr_n4? document.layers[r_x]
		: document.getElementById? document.getElementById(r_x)
		: null
	);
}


function RRObj(r_o, r_ang)
{
	this.name = r_o;
	this.img = document.images[r_o];
	rr_getPageXY(this);
	this.w = this.img.width;
	this.h = this.img.height;
	this.angle = r_ang;
	this.htm = '';
	for (var r_i = this.h; r_i--;)
	{
		for (var r_j = this.w; r_j--;)
		{
			this.htm += '<div id="' + r_o + 'row' + r_i + 'col' + r_j + '"'+
				' style="position:absolute;'+
				'left:' + (this.x+r_j) + 'px;'+
				'top:' + (this.y+r_i) + 'px;'+
				'width:1px;height:1px;'+
				(rr_n4? 'clip:rect(0, 1px 1px 0);">' : 'overflow:hidden;">')+
				'<div style="position:absolute;'+
				'left:' + (-r_j) + 'px;'+
				'top:' + (-r_i) + 'px;">'+
				'<img src="../' + this.img.src+ '" '+
				'width="' + this.w + '" height="' + this.h + '">'+
				'<\/div><\/div>';
		}
	}
}


RRObj.prototype.rotateTo = function(r_ang)
{
	this.angle = r_ang;
	var r_sin = Math.sin(r_ang = r_ang*Math.PI/180),
	r_cos = Math.cos(r_ang),
	r_cx = this.w>>1,
	r_cy = this.h>>1,
	r_o,
	r_z = 0;
	for (var r_i = this.h; r_i--;)
	{
		for (var r_j = this.w; r_j--;)
		{
			r_o = this.pxs[r_z++] || null;
			var r_x = r_j-r_cx,
			r_y = r_i-r_cy,
			r_xrot = Math.round(r_x*r_cos-r_y*r_sin+r_cx),
			r_yrot = Math.round(r_x*r_sin+r_y*r_cos+r_cy);
			if (rr_n4) r_o.moveTo(this.x+r_xrot, this.y+r_yrot);
			else if (r_o)
			{
				r_o.style.left = (this.x+r_xrot)+rr_px;
				r_o.style.top = (this.y+r_yrot)+rr_px;
			}
		}
	}
}


RRObj.prototype.swapImage = function(r_x)
{
	//this.nimg.src = r_x;
};


function SET_ROTATABLE()
{
	var r_a = SET_ROTATABLE.arguments, r_htm = '', r_o; 
	window.rr_n4 = !!document.layers;
	window.rr_px = (rr_n4 || !!(window.opera && !(r_o = document.documentElement || document.body) && !r_o.innerHTML))? '' : 'px';
	window.rots = new Array();
	for (var r_i = r_a.length-1; r_i > 0; r_i -= 2)
	{
		r_o = rots[rots.length] = rots[r_a[r_i-1]] = new RRObj(r_a[r_i-1], r_a[r_i]);
		r_htm += r_o.htm;
	    if (rr_n4) r_o.img.src = spacer;
	    else r_o.img.style.visibility = 'hidden';
	}
	document.write((rr_n4? '<div style="position:absolute;"><\/div>\n' : '') + r_htm);
	for (r_i = rots.length; r_i--;)
	{
		(r_o = rots[r_i]).pxs = new Array(r_o.w*r_o.h);
		for (var r_z = 0, r_j = r_o.h; r_j--;)
		{
			for (var r_k = r_o.w; r_k--; r_z++)
				r_o.pxs[r_z] = rr_getDiv(r_o.name + 'row' + r_j + 'col' + r_k);
		}
		r_o.rotateTo(r_o.angle);
	}
}
/* fim do conjunto de funções para rotacionar uma imagem */

/* 
	Função: previewImagem
	Descrição: Pre-visualiza uma imagem no documento ou em um pop-up antes de realizar upload 
	Argumentos:
		fileInfo 		: valor do objeto 'file'
		noForm 		 	: nome do formulário que utiliza a função
		noCampo  		: nome do objeto 'file'
		noImg	 		: nome do objeto 'img' 
		tpVisualizacao	: tipo de visualizacao da imagem. Pode ser na 'pagina' ou 'popup' 
	
	Observação: Funciona apenas no IE.
	Exemplo de utilização:

		<form action="" enctype="multipart/form-data" name="formFotos" method="post">
			Imagem: <input type="file" name="IM_ARQUIVO1" onblur="previewImagem(this.value,'formFotos','IM_ARQUIVO1','img1');" onchange="previewImagem(this.value,'formFotos','IM_ARQUIVO1','img1');"  onclick="previewImagem(this.value,'formFotos','IM_ARQUIVO1','img1');" onkeypress="previewImagem(this.value,'formFotos','IM_ARQUIVO1','img1');">
			<br><img style="display:none;" name="img1">
		</form>
*/

function previewImagem(fileInfo,noForm,noCampo,noImg,tpVisualizacao) {
	var filename = "";
	
	if (fileInfo == null) {
		if (this != "") {
			filename = eval("document."+noForm+"."+noCampo+".value");
			alert(filename);
		}
	}else {	filename = fileInfo; }
	
	if (!filename == "") {
		var fileExtension = filename.substring(filename.lastIndexOf(".")+1);
		var filename = filename.substring(filename.lastIndexOf(":\\\\")+1);
		
		if (fileExtension == "jpg" || fileExtension == "jpeg" || fileExtension == "gif" || fileExtension == "png"){
			if(tpVisualizacao == 'pagina'){
				var campoImg = eval("document."+noForm+"."+noImg);
				campoImg.src="file:///"+filename;
				campoImg.style.display = '';
			}else if(tpVisualizacao == 'popup'){
				popup = window.open('', 'imagePreview', 'width=600,height=450,left=100,top=75,screenX=100,screenY=75,scrollbars,location,menubar,status,toolbar,resizable=1');
				popup.document.writeln("<html lang='pt-br'><body>");
				popup.document.writeln("<img src='file:///" + filename + "'>");
				popup.document.writeln("</body></html>");
				popup.document.close();
				popup.focus();
			}	
		}
	}
}
/* fim da função: previewImagem */

function previewLegenda(fileInfo,Legenda,Fotografo,noForm,noCampo,noImg,tpVisualizacao) {
	var filename = "";
		
	if (fileInfo == null) {
		if (this != "") {
			filename = eval("document."+noForm+"."+noCampo+".value");
			alert(filename);
		}
	}else {	filename = fileInfo; }
	
	if (!filename == "") {
		var fileExtension = filename.substring(filename.lastIndexOf(".")+1);
		var filename = filename.substring(filename.lastIndexOf(":\\\\")+1);
		
		if (fileExtension == "jpg" || fileExtension == "jpeg" || fileExtension == "gif" || fileExtension == "png"){
			if(tpVisualizacao == 'pagina'){
				var campoImg = eval("document."+noForm+"."+noImg);
				campoImg.src="file:///"+filename;
				campoImg.style.display = '';
			}else if(tpVisualizacao == 'popup'){
				popup = window.open('', 'imagePreview', 'width=600,height=450,left=100,top=75,screenX=100,screenY=75,scrollbars,location,menubar,status,toolbar,resizable=1');
				popup.document.writeln("<html lang='pt-br'><body>");
				popup.document.writeln("<img src='file:///" + filename + "'>");
				popup.document.writeln("<br>Legenda: " + Legenda);
				popup.document.writeln("<br>Foto: " + Fotografo);
				popup.document.writeln("</body></html>");
				popup.document.close();
				popup.focus();
			}	
		}
	}
}

/*--------------------------------------------------|
| INÍCIO DO CONJUNTO DE FUNÇÕES DO dTree 2.05       |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landrö               |
|--------------------------------------------------*/

// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
	this.id = id;
	this.pid = pid;
	this.name = name;
	this.url = url;
	this.title = title;
	this.target = target;
	this.icon = icon;
	this.iconOpen = iconOpen;
	this._io = open || false;
	this._is = false;
	this._ls = false;
	this._hc = false;
	this._ai = 0;
	this._p;
};

// Tree object
function dTree(objName) {
	this.config = {
		target					: null,
		folderLinks			: true,
		useSelection		: true,
		useCookies			: true,
		useLines				: true,
		useIcons				: true,
		useStatusText		: false,
		closeSameLevel	: false,
		inOrder					: false
	}
	this.icon = {
		root				: '/portal/imagens/root.gif',
		folder			: '/portal/imagens/folder.gif',
		folderOpen	: '/portal/imagens/folderopen.gif',
		node				: '/portal/imagens/page.gif',
		empty				: '/portal/imagens/empty.gif',
		line				: '/portal/imagens/line.gif',
		join				: '/portal/imagens/join.gif',
		joinBottom	: '/portal/imagens/joinbottom.gif',
		plus				: '/portal/imagens/plus.gif',
		plusBottom	: '/portal/imagens/plusbottom.gif',
		minus				: '/portal/imagens/minus.gif',
		minusBottom	: '/portal/imagens/minusbottom.gif',
		nlPlus			: '/portal/imagens/nolines_plus.gif',
		nlMinus			: '/portal/imagens/nolines_minus.gif'
	};
	this.obj = objName;
	this.aNodes = [];
	this.aIndent = [];
	this.root = new Node(-1);
	this.selectedNode = null;
	this.selectedFound = false;
	this.completed = false;
};

// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
	this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
};

// Open/close all nodes
dTree.prototype.openAll = function() {
	this.oAll(true);
};
dTree.prototype.closeAll = function() {
	this.oAll(false);
};

// Outputs the tree to the page
dTree.prototype.toString = function() {
	var str = '<div class="dtree">\n';
	if (document.getElementById) {
		if (this.config.useCookies) this.selectedNode = this.getSelected();
		str += this.addNode(this.root);
	} else str += 'Browser not supported.';
	str += '</div>';
	if (!this.selectedFound) this.selectedNode = null;
	this.completed = true;
	return str;
};

// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
	var str = '';
	var n=0;
	if (this.config.inOrder) n = pNode._ai;
	for (n; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == pNode.id) {
			var cn = this.aNodes[n];
			cn._p = pNode;
			cn._ai = n;
			this.setCS(cn);
			if (!cn.target && this.config.target) cn.target = this.config.target;
			if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
			if (!this.config.folderLinks && cn._hc) cn.url = null;
			if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
					cn._is = true;
					this.selectedNode = n;
					this.selectedFound = true;
			}
			str += this.node(cn, n);
			if (cn._ls) break;
		}
	}
	return str;
};

// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
	var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
	if (this.config.useIcons) {
		if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
		if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
		if (this.root.id == node.pid) {
			node.icon = this.icon.root;
			node.iconOpen = this.icon.root;
		}
		str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
	}
	if (node.url) {
		str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
		if (node.title) str += ' title="' + node.title + '"';
		if (node.target) str += ' target="' + node.target + '"';
		if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
		if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
			str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
		str += '>';
	}
	else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
		str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
	str += node.name;
	if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
	str += '</div>';
	if (node._hc) {
		str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
		str += this.addNode(node);
		str += '</div>';
	}
	this.aIndent.pop();
	return str;
};

// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
	var str = '';
	if (this.root.id != node.pid) {
		for (var n=0; n<this.aIndent.length; n++)
			str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';
		(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
		if (node._hc) {
			str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
			if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
			else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );
			str += '" alt="" /></a>';
		} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';
	}
	return str;
};

// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
	var lastId;
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == node.id) node._hc = true;
		if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
	}
	if (lastId==node.id) node._ls = true;
};

// Returns the selected node
dTree.prototype.getSelected = function() {
	var sn = this.getCookie('cs' + this.obj);
	return (sn) ? sn : null;
};

// Highlights the selected node
dTree.prototype.s = function(id) {
	if (!this.config.useSelection) return;
	var cn = this.aNodes[id];
	if (cn._hc && !this.config.folderLinks) return;
	if (this.selectedNode != id) {
		if (this.selectedNode || this.selectedNode==0) {
			eOld = document.getElementById("s" + this.obj + this.selectedNode);
			eOld.className = "node";
		}
		eNew = document.getElementById("s" + this.obj + id);
		eNew.className = "nodeSel";
		this.selectedNode = id;
		if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
	}
};

// Toggle Open or close
dTree.prototype.o = function(id) {
	var cn = this.aNodes[id];
	this.nodeStatus(!cn._io, id, cn._ls);
	cn._io = !cn._io;
	if (this.config.closeSameLevel) this.closeLevel(cn);
	if (this.config.useCookies) this.updateCookie();
};

// Open or close all nodes
dTree.prototype.oAll = function(status) {
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
			this.nodeStatus(status, n, this.aNodes[n]._ls)
			this.aNodes[n]._io = status;
		}
	}
	if (this.config.useCookies) this.updateCookie();
};

// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
	if (!bFirst) {
		for (var n=0; n<this.aNodes.length; n++) {
			if (this.aNodes[n].id == nId) {
				nId=n;
				break;
			}
		}
	}
	var cn=this.aNodes[nId];
	if (cn.pid==this.root.id || !cn._p) return;
	cn._io = true;
	cn._is = bSelect;
	if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
	if (this.completed && bSelect) this.s(cn._ai);
	else if (bSelect) this._sn=cn._ai;
	this.openTo(cn._p._ai, false, true);
};

// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
			this.nodeStatus(false, n, this.aNodes[n]._ls);
			this.aNodes[n]._io = false;
			this.closeAllChildren(this.aNodes[n]);
		}
	}
}

// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
			if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
			this.aNodes[n]._io = false;
			this.closeAllChildren(this.aNodes[n]);		
		}
	}
}

// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
	eDiv	= document.getElementById('d' + this.obj + id);
	eJoin	= document.getElementById('j' + this.obj + id);
	if (this.config.useIcons) {
		eIcon	= document.getElementById('i' + this.obj + id);
		eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
	}
	eJoin.src = (this.config.useLines)?
	((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
	((status)?this.icon.nlMinus:this.icon.nlPlus);
	eDiv.style.display = (status) ? 'block': 'none';
};


// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	this.setCookie('co'+this.obj, 'cookieValue', yesterday);
	this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
};

// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
};

// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
};

// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
	var str = '';
	for (var n=0; n<this.aNodes.length; n++) {
		if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
			if (str) str += '.';
			str += this.aNodes[n].id;
		}
	}
	this.setCookie('co' + this.obj, str);
};

// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
	var aOpen = this.getCookie('co' + this.obj).split('.');
	for (var n=0; n<aOpen.length; n++)
		if (aOpen[n] == id) return true;
	return false;
};

// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
	Array.prototype.push = function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
};
if (!Array.prototype.pop) {
	Array.prototype.pop = function array_pop() {
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
};

/*--------------------------------------------------|
| FINAL DO CONJUNTO DE FUNÇÕES DO dTree 2.05        |
|--------------------------------------------------*/

function visibilidade(objeto){
	if (objeto.style.display == ''){
		objeto.style.display = 'none';
	}else{
		objeto.style.display = '';
	}
	return true;
}
/* Função para a Custom Tag - cf_sisPaginacao */
function paginaClick(QtRegAtual,dsUrl){
   document.frm.action = dsUrl;
    document.frm.STARTROW.value = QtRegAtual;
    document.frm.submit();
}

function abrirRadioweb(URL){
var width = 400;
var height = 240;
var left = 99;
var top = 99;
window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no'); 
}
function carregar(arquivo,div){	
	var resultado=$(div);
	resultado.update('<img src="images/loading.gif" align="absmiddle"><span style="font-family:Trebuchet MS; font-size:10px; color:#b46b60">Carregando...</span><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>');
	new Ajax.Request(arquivo, {	      
	  onSuccess: function(transport) {   		
   		resultado.update(transport.responseText);  	
      }
    });
}

