// ########################################  Funções úteis ################################################### 


  var w3c = (document.getElementById) ? 1:0
  var hasCookies = true;
  var postnuke="true";

  
  if(document.cookie == '') {
    document.cookie = 'hasCookies=yes';
    if (document.cookie.indexOf('hasCookies=yes') != -1) hasCookies = true;
  }
  else hasCookies = true;

  /*
	SE FOR DESCOMENTAR AVISE A TAKENAMI ANTES...........................

  function setCookie (name, value, hours, path) {
    if (hasCookies) {
  	  if(hours) {
  	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) var numHours = hours;
  	    else if (typeof(hours) == 'number') var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
  	  }
  	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'');
    }
  }
  
  
  function readCookie(name) {
    if (document.cookie == '') return '';
    else {
    	var firstChar, lastChar;
    	var theBigCookie = document.cookie;
    	firstChar = theBigCookie.indexOf(name);
    	if (firstChar != -1) {
    	    firstChar += name.length + 1;
    	    lastChar = theBigCookie.indexOf(';', firstChar);
    	    if (lastChar == -1) lastChar = theBigCookie.length;
    	    return unescape(theBigCookie.substring(firstChar, lastChar));
    	}
      else return '';
    }
  }
  */
  
   
	function showHideModule(divID,sta) {
		var state;
		if (sta!=null){
			state=sta;
		}else{
			state = toggleFoldyPersistState(divID);
		}
		var ok=false;
		if(w3c) {
			var divIDobj = MM_findObj(divID);
			var tlobj = MM_findObj(divID +"tl");
			var toggleobj = MM_findObj(divID +"Toggle");
			if(divIDobj != null && tlobj != null && toggleobj != null) {

				ok=true;
				if(state=="c") {
					if(postnuke=="true") {
						tlobj.src = "../../img/spacer.gif";
						toggleobj.src = "../../img/module_toggle_closed.gif";
					} else {
						tlobj.src = "../../img/spacer.gif";
						toggleobj.src = "../../img/module_toggle_closed.gif";
					}
					divIDobj.style.display = "none";
				} else {
					if(postnuke=="true") {
						tlobj.src = "../../img/spacer.gif";
						toggleobj.src = "../../img/module_toggle_open.gif";
					} else {
						tlobj.src = "../../img/spacer.gif";
						toggleobj.src = "../../img/module_toggle_open.gif";
					}
					divIDobj.style.display = "";
				}
			}
		}
		if(!ok){
			document.location = document.location;
		}
		
	}
	
	function toggleFoldyPersistState(divID) {
		//var theCookie = readCookie(divID);
		eval ("var theCookie = objTabf_" + divID);
		var state="e";
		if ((theCookie == "e") || (theCookie == "")) {
			state="c";
		}
		//setCookie(divID,state,'Wed 01 Jan 2020 00:00:00 GMT','/');
		eval("objTabf_" + divID + "='" + state + "';");
		return state;
	}
	
	function MM_findObj(n, d) { //v4.0
	  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 && document.getElementById) x=document.getElementById(n); return x;
	}



/* Funcao que abre uma Janela Pop_UP 
//------------PARAMETROS------------
//PAGINA-nome da pagina que vai ser aberta
//WIDTH-largura que a pagina vai ser aberta
//HEIGHT-altura que a pagina vai ser aberta
*/
function abreJanela(pagina,width,height) {
	var left = (screen.width)?(screen.width-width)/2:100;
	var top = (screen.height)?(screen.height-height)/2:100;
	opt = "top=" + top + ",left=" + left + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=" + width + ",height=" + height;
 	window.open(pagina,"AppJanela",opt);
}


/* Função para Maximizar a Janela atual */
function Maximizar(){
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	} else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

/*
ESSA FUNCAO MOSTRA UMA JANELA DE DIALOGO DE FORMA MODAL
------------------------PARAMETROS---------------------
URL-ENDERECO DA PAGINA QUE VAI SER ABERTA
MWIDTH-LARGURA QUE A PAGINA VAI SER ABERTA
MHEIGHT-ALTURA QUE A PAGINA VAI SER ABERTA
*/
function showDialog(url,mwidth,mheight){
	window.showModalDialog(url,window,"help:0;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px;status:0");
	//dialogArguments.form1.edit1.value = "teste";
	//A Variável dialogArguments pega os canpos da janela que o chamou
}

/*
ESSA FUNCAO MOSTRA COMO APLICAR UM ZOOM NA JANELA
-------------------PARAMETROS---------------
URL-ENDERECO DA PAGINA QUE VAI SER ABERTA
MWIDTH-LARGURA QUE A PAGINA VAI SER ABERTA
MHEIGHT-ALTURA QUE A PAGINA VAI SER ABERTA
*/

function showZoom(url,mwidth,mheight){
	var left = (screen.width)?(screen.width-mwidth)/2:100;
	var top = (screen.height)?(screen.height-mheight)/2:100;
	window.open("../zoom/" + url,"Zoom","top=" + top + ",left=" + left + ",toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=" + mwidth + ",height=" + mheight);
}

// funcao para direcionar a pagina ao topo
function topo(){
  window.scroll(0,0);  
}    

function abreRelatorio(pagina,width,height) {
	var left = (screen.width)?(screen.width-width)/2:100;
	var top = (screen.height)?(screen.height-height)/2:100;
	opt = "top=" + top + ",left=" + left + ",toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=" + width + ",height=" + height;
 	window.open(pagina,"AppJanela",opt);
}

/* Esta função recebe o objeto select e o atributo checked do check box. Caso seja true todas as opções serão marcadas, caso contrário desmarcadas.
*/
function selectAll(select, checked){
	for ( i = 0; i < select.length; i++){
		if (checked){
			select.options[i].selected = true;
		}
		else {
			select.options[i].selected = false;
		}
	}
	if(!checked){
		select.scrollTop = 0;
	}
}


	
