//########### 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 ----------------------------------------------------
// 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);
	}
}


// 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;
    }
  }
// Funcao que só permiti digitar numero em um campo txt ------------------
function txtlimita(event){
    if (navigator.appName == 'Netscape') {
      var codigo = event.which;
    }else{
      var codigo=event.keyCode;
    }
	//alert(codigo);
    if ((codigo >= 48 && codigo <= 57) || codigo == 8){
        event.returnValue = true;
        event.cancelBubble = false;
    }else{
		return false;
        event.returnValue = false;
        event.cancelBubble = true;
    }
}
// Gera o Logoff da pagina -----------------------------------------------
  function logoff(vget){
	  
		var url = window.location;
		var file = url.href;
		//if(vget != null && vget != ''){var param = '?des=' + vget;}else{var param = ''};
		while (file.indexOf("/") != -1) var file = file.slice(file.indexOf("/") + 1);				
		vurl = url.href.substr(0, parseInt(url.href.length - file.length));

        url.replace(vurl /*+ param*/);
  }	
 
// 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('Aguarde, em breve este link estará disponível.\n');
		return false;
	 }else{
		 numero = new String(Math.random());
		 numero = numero.substr(3, 4);
		if(vLink.indexOf("target") != -1 && vLink.indexOf("=popup_areaexclusiva") != -1){
			vLink = vLink.replace('target=popup_areaexclusiva', '');
			WinOpen('null', vLink, '', 'popup_areaexclusiva' + numero, 800, 450, 'resizable=yes');
		}else if(vLink.indexOf("http://") != -1 || vLink.indexOf("www.") != -1 || (vLink.indexOf("target") != -1 && vLink.indexOf("=blank") != -1)){
			if(vLink.indexOf("target") != -1 && vLink.indexOf("=blank") != -1){
				vLink = vLink.replace('target=blank', '');
			}
			window.open(vLink, 'externo' + numero);
		}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.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;
	}
}
// Gera mascara de valor
function mask(str, textbox, loc, delim, loc2, delim2){
	var locs = loc.split(',');
	for(var i=0; i <= locs.length; i++){
		for(var k=0; k <= str.length; k++){
			if(k == locs[i]){
				if(str.substring(k,k+1) != delim){
					str = str.substring(0,k)+delim+str.substring(k,str.length);
				}
			}else if(k == loc2){
				if(str.substring(k,k+1) != delim2){
					str=str.substring(0,k)+delim2+str.substring(k,str.length);
				}
			}
		}
	}
	textbox.value = str;
}

// Pagina verifica email
	function check_envia_email(var_form, var_matri, var_rg, var_email, var_remail){
		var form = window.document.getElementById(var_form);
		var matri = window.document.getElementById(var_matri);
		var rg = window.document.getElementById(var_rg);
		var email = window.document.getElementById(var_email);
		var remail = window.document.getElementById(var_remail);

		if(matri.value == 'null' || matri.value == 'undefined' || matri.value ==  ''){
			alert('Erro!\nPreencha corretamente o campo MATRÍCULA.');
			matri.select();matri.focus();return false;
		}else if(matri.value.length != matri.size){
			alert('Erro!\nMATRÍCULA inválida, por favor tente novamente.');
			matri.select();matri.focus();return false;
		}else if(rg.value == 'null' || rg.value == 'undefined' || rg.value ==  ''){
			alert('Erro!\nPreencha corretamente o campo RG.');
			rg.select();rg.focus();return false;
		}else if(email.value == 'null' || email.value == 'undefined' || email.value ==  ''){
			alert('Erro!\nPreencha corretamente o campo EMAIL.');
			email.select();email.focus();return false;
		}else if(email.value.indexOf("@") == -1 || email.value.indexOf(".") == -1 || email.value.indexOf("com") == -1){
			alert('Erro!\nE-MAIL inválido.\nPor favor digite corretamente o seu e-mail válido.');
			email.select();email.focus();return false;
		}else if(remail.value != email.value){
			alert('Erro!\nRe-digitação de email inválida.\nPor favor digite corretamente o seu e-mail.');
			remail.select();remail.focus();return false;
		}else{
			form.submit();
		}
	}
	// Conta o total de numeros ou letras de um caracter ********************************
	function verifica_letras(valor, valreturn){
		var cont_valor = valor.length;
		
		var list_letras = "ABCÇDEFGHIJKLMNOPQRSTUVWXYZ";
		var tot_letras = 0;
		
		var list_number = "1234567890";
		var tot_number = 0;

		for(i=0; i <= cont_valor; i++){
			var valchar = valor.charAt(i - 1);
			if(list_letras.indexOf(valchar.toUpperCase()) != -1){
				tot_letras++;
			}else if(list_number.indexOf(valchar) != -1){				
				tot_number++;
			}
		}
		if(valreturn == 'text'){
			return(tot_letras);
		}else if(valreturn == 'number'){
			return(tot_number);
		}
	}
	// Valida CPF *************************************************************************
	function valida_CPF(cpf){
		var numeros, digitos, soma, i, resultado, digitos_iguais;
		digitos_iguais = 1;
		if (cpf.length < 11)
			return false;
		for (i = 0; i < cpf.length - 1; i++)
			if (cpf.charAt(i) != cpf.charAt(i + 1))
			{
				digitos_iguais = 0;
				break;
			}
		if (!digitos_iguais)
		{
			numeros = cpf.substring(0,9);
			digitos = cpf.substring(9);
			soma = 0;
			for (i = 10; i > 1; i--)
				soma += numeros.charAt(10 - i) * i;
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(0))
				return false;
			numeros = cpf.substring(0,10);
			soma = 0;
			for (i = 11; i > 1; i--)
				soma += numeros.charAt(11 - i) * i;
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(1))
				return false;
			return true;
		}else{
			return false;
		}
	}
	
	// Funcao limita somente digitaçao de numeros
function limita_number(text){
	
	var obj_value = text;
	var new_value = text;

	for(var i=0; i<obj_value.length; i++){
		var value_letra = obj_value.charAt(i);
		var code_letra = obj_value.charCodeAt(i);		
		
		if (code_letra < 48 || code_letra > 57){
			
			new_value = new_value.replace(value_letra, '');
		}
	}
	return(new_value);	
}