//########### Funções Globais #####################//
	var ie4
	var ie5
	var ie6
	var ns4
	var ns6
	
	ie4 = (document.all) ? true : false;
	ie5 = (navigator.userAgent.indexOf("MSIE 5.")>-1) ? true : false;
	ie6 = (navigator.userAgent.indexOf("MSIE 6.")>-1) ? true : false;
	ns4 = (document.layers) ? true : false;
	ns6 = (document.getElementById && !document.all) ? true : false;
	
// Redimensiona a Janela--------------------------
function maximizeWin() {
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
	//alert(ie5);
  }
}

// Abre Janela ----------------------------------------------------
function WinOpen(td, url, param, name, width, height, maximiza){
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	str +=",scrollbars=yes, status=no";
	str +="," + maximiza;
	if (window.screen) {
		if(name == 'banner'){
			str += ",left=5, screenX=5, screenLeft=5";
			str += ",top=20, screenY=20, screenTop=20";
		}else{
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		}
	}
	
	if(td != 'null'){
		len_td = window.document.getElementById(td).childNodes.length;
		val_td = window.document.getElementById(td).childNodes[0].nodeName;
		if(len_td > 1 || val_td.toLowerCase() == 'table'){	
			window.open(url+param, name, str,scrollbars='yes');
		}else{		
			alert("Para iniciar a impressão é necessário obter algum, resultado no formulário de busca.");
			return false;
		}
	}else{
		window.open(url+param, name, str,scrollbars='yes');
	}
}

// Gera a data atual ----------------------------------------------    
	arrSemana = new Array("Domingo","Segunda","Terça","Quarta","Quinta","Sexta","Sábado");
	arrMes = new Array("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
	
	function data() {
			 hoje = new Date();
			 dia = hoje.getDate(); if (dia==1) dia+="&ordm";
			 diaSem = arrSemana[hoje.getDay()];
			 mes = arrMes[hoje.getMonth()];
			 ano = hoje.getYear();
	
			 if (ano<1900) ano+=1900;
				hora = hoje.getHours(); if (hora.toString().length<2) hora = "0"+hora;
				mins = hoje.getMinutes(); if (mins.toString().length<2) mins = "0"+mins;
				document.write(diaSem +", "+ dia +" de "+ mes +" de "+ ano +" - "+ hora +"h"+ mins+"min.&nbsp;");
	}
	
// Funçoes que Muda o Stylo do Botao ------------------------------------------
	function muda(id){
		var obj = document.getElementById(id);
		obj.setAttribute("className","botaover");
		obj.setAttribute("class","botaover");
	}

	function volta(id){
		var obj = document.getElementById(id);
		obj.setAttribute("className","botaout");
		obj.setAttribute("class","botaout");
	}
	
// Desabilita o Teclado ------------------------------------------------
  function desabilita(event){
    if (navigator.appName == 'Netscape') {
      var codigo = event.which;
      if(codigo == 13){
        form_valida();
      }
    }else{
      var codigo=event.keyCode;
      if(codigo == 13){
        form_valida();
      }
    }
    if ((codigo >= 112 && codigo <= 123) || (codigo >= 16 && codigo <= 19) || (codigo >= 37 && codigo <= 40) || (codigo >= 91 && codigo <= 93) || codigo == 27){
      if (navigator.appName == 'Netscape') {
        //event.which = 0;
        return false;
      }else{
        event.keyCode = 0;
      }
      event.returnValue = false;
      event.cancelBubble = true;
    }
  }
 
// Cria o menu e a sua animação -----------------------------------------
  function geraMenu(vEvent, vClass, vLink, vObj, vTipMnu, namIframe){
	  if (navigator.appName == 'Netscape') {
		// element.parentNode = É igual a parentElement usado no IE e Mostra por Nestscape uma casa abaixo do elemento especificado
		// element.childNodes.length = Guarda em um vetor os elementos existes dentro dele
		// element.nodeName = nodeName e igual a tagName usado no IE
		var vNum = vObj.parentNode.id.substring(3, 6);
  		var vMnu = 'mnu' + vNum;
		var vSub = 'sub' + vNum;
		var element = vEvent.target;
		while(element.nodeName.toLowerCase() != 'td'){
			element = element.parentNode;
		}		
		var aParentNod = element.parentNode.parentNode;
		
	}else{
		var vNum = vObj.parentElement.id.substring(3, 6);
  		var vMnu = 'mnu' + vNum;
		var vSub = 'sub' + vNum;
		var element = vEvent.srcElement;
		while(element.tagName.toLowerCase() != 'td'){
			element = element.parentElement;
		}			
		var aParentNod = element.parentElement.parentElement;
	}
	// Se foi clicado faça ------------------------------------------------------	
	if(vEvent.type.toLowerCase() == 'click'){
	 // Carrega Link ------------------------------------------------------
	 if(vClass == 'mnuNull' || vClass == 'subNull'){
		alert('Você não tem permissão para acessar este link.\nEstá é uma área reservada.');
		return false;
	 }else{

		if(vLink.indexOf("http://") != -1 || vLink.indexOf("www.") != -1){
			window.open(vLink, 'externo');
		}else if(vLink.indexOf(".") != -1 || vLink.indexOf(".php") != -1 || vLink.indexOf(".html") != -1){
				/*var cont = 0;
				var namIframe = '';
				while(namIframe.toLowerCase() != 'ifrload'){
					var vIframe = window.self.frames[cont];
					namIframe = vIframe.name;
					cont++;
				}*/
				var vIframe = window.parent.document.getElementById(namIframe);
				vIframe.src = vLink;
		}
		
	  // Mostra Menu ------------------------------------------------------		
		var aParentLst = aParentNod.childNodes.length;
		var child;

		for(var i=0; i < aParentLst; i++){
			var Tag = aParentNod.childNodes[i];
			
			if(Tag.nodeName.toLowerCase() == 'tr'){
				var TagId = Tag.id;
				var vTag = TagId.substr(0, 6);
			  
				var aChildLst = Tag.childNodes.length;
				var cssId = vTag.substr(0, 3);

				if(cssId == vMnu.substr(0,3)){
					for(var j=0; j < aChildLst; j++){
						var child = Tag.childNodes[j];
						var img = child.childNodes[0];
						child.className = cssId + 'Off';
						// Se o menu for do tipo 1 faça
						if(vTipMnu == 'mnu1'){
							img.src = 'images/mnu_icoMenos.gif';							
						}else if(child.className != cssId + 'Null' && vTag.substr(0, 5) != vMnu.substr(0, 5)){
							
							img.src = 'images/mnu_icoMais.gif';						
						}	
					}
				}else if(cssId == vSub.substr(0,3)){									
					for(var j=0; j < aChildLst; j++){
						var child = Tag.childNodes[j];
						var img = child.childNodes[0];
						if(vTag.substr(0, 5) == vSub.substr(0, 5)){
							Tag.className = 'subSome';
							if(child.className != cssId + 'Null'){							
								child.className = cssId + 'Off';
							}else if(child.className == cssId + 'Null'){
								img.src = 'images/sub_icoSetaNull.gif';
							}
						}else{
							if(vTipMnu == 'mnu1'){
								child.className = 'subOff';
							}else{
								// Se menu for igual a 2 verifique se o nome do campo da tabela
								// existe o traço se existir o ZERO oculte a tabela se nao mostre
								// o '0' ZERO especificamente significa simbolicamente que o sub campo
								// do menu nao faz parte de um menu principal dessa forma ela nao oculta o conteudo
								if(vTag.indexOf("0") == -1){
									child.className = 'subNone';
								}else{
									child.className = 'subOff';
								}
							}
						}								
					}
				}
			}
		}
	  }
	}

	var nClass = element.className;	
	if(nClass != 'mnuOn' && nClass != 'subOn'){
		element.className = vClass;
		if(element.className == 'mnuOn'){
			var childElem = element.childNodes;
			for(i=0; i<childElem.length; i++){
				var child = childElem[i];
				if(child.nodeName.toLowerCase() == 'img'){
					child.src = 'images/mnu_icoMenos.gif';
				}
			}
		}
	}
  }

// Gera o aumento do iframe na pagina principal ----------------------
	function valIframe(iframe, table){
	  var vIframe = window.parent.document.getElementById(iframe);
	  var vTable = window.document.getElementById(table);
	  
	  if(vTable != 'null' && vIframe != 'null'){		
		
		var celTD = vIframe;
		while(celTD.nodeName.toLowerCase() != 'td'){
			if (navigator.appName == 'Netscape') {
				celTD = celTD.parentNode;
			}else{
				celTD = celTD.parentElement;
			}
		}
		vIframe.height = 0;
		vIframe.height = vTable.offsetHeight;
		vIframe.width = celTD.offsetWidth;
		
		vTable.width = celTD.offsetWidth;
	}
}
