	function checkTab(iKeyCod) {
		if (iKeyCod != 9) {
			return false
		}
	}
	
	function ChangeImages(oldImage,newImage)
	{
		if (parseInt(navigator.appVersion) >= 3)
			document[oldImage].src = eval(newImage + ".src");
	}


	function abrePopup(pagina, strWidth, strHeight, popupname, resizable)
	{
		if (resizable=='true')
			var Wnd = window.open(pagina,popupname,"toolbar=no,status=yes,location=no,directories=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+strWidth+",height="+strHeight);
		else
			var Wnd = window.open(pagina,popupname,"toolbar=no,status=yes,location=no,directories=no,scrollbars=yes,resizable=no,copyhistory=no,width="+strWidth+",height="+strHeight);
		Wnd.moveTo(0,0);
		Wnd.focus();
		return false;
	}
	
	var cont;
	cont = new Date();
	
	//funções para validação de formulário
	function replace(t,f,r)
	{
	  if (f == ".")
	     var re = /\./g;
	  else
	     var re = new RegExp(f,"g");

	  return t.replace(re, r);
	}
	

	// ************ Validação de Data **********************
	function isDate(strData)
	{
		//verifica se a data foi digitada corretamente
		strData = retiraEspaco(strData);
		if (isEmpty(strData)) 
			return false;
		var strNum = "0123456789/";
		var Size = strData.length;
		//testa a validade dos caracteres que formam a data
		for (var i=0; i<Size; i++) {
			if (strNum.indexOf(strData.charAt(i)) < 0)
				return false;
		}
			
		var Pos1 = strData.indexOf("/");
		var Pos2 = strData.lastIndexOf("/");
		if (!(Pos1==2 && Pos2==5)) return false;
						
		a = strData.split("/");
		if (a.length == 3 && a[2].length==4 && a[2]>0) {
			if ((a[1]<1) || (a[1]>12)) 
				return false;
			else if ((a[0]<1) || (a[0]>numDias(a[1], a[2])))
					return false;
		} else return false;
			
		return true;
	}

	function retiraEspaco(theString) {
		//retira todos os espaços de uma string
		if (theString.indexOf(" ") >= 0) {
			var i = 0;
			while (theString.indexOf(" ") >= 0) {
				if (theString.charAt(i) == " ") 
					theString = theString.substring(0,i) + theString.substring(i+1,theString.length);
				else i++
			}
			newString = theString;
		} 
		else newString = theString;
		return newString;
	}

	function numDias(intMes,intAno)	{
		//retorna o número de dias de um mês em um ano qualquer
		var Dias;
		intMes = parseInt(intMes, 10);
		intAno = parseInt(intAno, 10);
			
		switch(intMes) {
			case 1: 
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12: Dias = 31; break;
			case 4:
			case 6:
			case 9:
			case 11: Dias = 30;	break;
			case 2:
				Dias = 28;
				if (((intAno%400)==0) || ((intAno%100)!=0 && (intAno%4)==0)) 
					Dias++; 
				break;
			default:
				Dias = 0;
				alert("DATA DESCONHECIDA");
		}
		return Dias;
	}
		

	function isEmpty(str) {
		//verifica se alguma coisa foi digitada num determinado campo
		if (str == null || str == "")
			return true;
		return false;
	}
		
	//Função que testa um número
	// t - Número a ser testado
	// d - Usar decimais ou nao	
	function isNumber(t,d) {
		var i, sepused;
		if (t == "")
			return false;
		sepused = false;
		
		for (i=0;i<t.length;i++) {
			if (trim(t.substr(i,1)) == "" || (isNaN(t.substr(i,1)) && ((t.substr(i,1) != ",") || !d || sepused || i==0 || i==t.length-1)))
			   return false;
			if (t.substr(i,1) == ",")
			   sepused = true;	
		}
	  return true;     
	}
	
	function formataHora(lStrHorario){
		//Coloca o 0 na frete do horario, caso nao tenha
		a = lStrHorario.split(":");
		if(a[0].length == 1)
			a[0] = "0" + a[0];
		
		lStrHorario = a[0] + ":" + a[1];
		
		return lStrHorario;
	}

	//Funcao que coloca os ':' no horario
	function formataHora(index,evento,form) {
		var tecla = evento.keyCode;
		vr = form[index].value;
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ":", "" );
		vr = vr.replace( ":", "" );
		tam = vr.length + 1;
		if (((tecla >= 48) && (tecla <= 57)) || ((tecla == 9) || (tecla == 8))){
			if ( tecla != 9 && tecla != 8 ){
				if ( tam == 3 )
					form[index].value = vr.substr( 0, tam - 1  ) + ':' + vr.substr( tam - 1, tam );
			}		
		}
		else{
			evento.returnValue = false;
		}
	}

	//Funcao que coloca as '/' na data
	function formataData(index,evento,form) {
		var tecla = evento.keyCode;
		vr = form[index].value;
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length + 1;
		if (((tecla >= 48) && (tecla <= 57)) || ((tecla == 9) || (tecla == 8))){
			if ( tecla != 9 && tecla != 8 ){
				if ( tam == 3 )
					form[index].value = vr.substr( 0, tam - 1  ) + '/' + vr.substr( tam - 1, tam );
				if ( tam > 3 && tam < 5 )
					form[index].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
				if ( tam >= 5 && tam <= 10 )
					form[index].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
			}		
		}
		else{
			evento.returnValue = false;
		}
	}

	function isEmail(str) {
		//verifica se o e-mail digitado é válido 
		var strAlfa = "ABCDEFGHIJKLMNOPQRSTUWVXYZ";
		var strNum = "0123456789";
		var strSpecial = "_.-@/";
		var strValid = strAlfa + strNum + strSpecial;
		var email = str.toUpperCase();
		//verifica se os caracteres do e-mail são válidos
		for (i=0; i<email.length; i++) {
			if (strValid.indexOf(email.charAt(i)) < 0) {
				return false;
			}
		}

		var strC = "@."; 
		//verifica se o e-mail contém @ e . (caracteres obrigatórios)
		for (i=0; i<strC.length; i++) {
			if (email.indexOf(strC.charAt(i)) < 0) 
				return false;
		}

		if (email.indexOf("@") != email.lastIndexOf("@"))
			return false;
		if (email.indexOf("@") > email.lastIndexOf("."))
		    return false;
		if (email.charAt(email.indexOf("@") + 1) == ".")
		    return false;
		if (!(email.indexOf("@") != 0 && email.lastIndexOf(".") != email.length-1))
			return false;
						
		return true;
	}
		
	function isMoney(strValue) 
	{
		//verifica se uma determinada string é um valor em dinheiro
		
		//verificando se os caracteres da string são válidos
		var strDin = "0123456789.,";
		for (i=0; i<strValue.length; i++) {
			if (strDin.indexOf(strValue.charAt(i)) < 0)
				return false;
		}
	
		//verifica se a vírgula está no lugar certo caso ela exista	
		var arrDin = strValue.split(",");
		if(arrDin.length != 1 && arrDin.length !=2)
			return false;
		else
			if(arrDin.length == 2 && arrDin[1].length != 2)
				return false;
		
		//verifica se entre os pontos presentes na string
		//existe um número mútiplo de três de algarismos
		//Ex: "1.000", "1000.000", "1000000", "1.000.000.000" (corretos)
		//Ex: "1.00000", "100.0000", "1.000.0000.00" (incorretos)
		if(arrDin[0].indexOf(".") > 0)
		{
			var arrInt = arrDin[0].split(".");
			var i;
			for(i=1; i<arrInt.length; i++)
				if( (arrInt[i].length % 3) != 0 )
					return false;
		}
			
			
		return true;
	}
		
	function inverteData(strData){
		var novadata, a;
		
		a = strData.split("/");
		novadata = a[2] + "/" +  a[1] + "/" + a[0] ;
		return novadata
	}

	function IsValidPeriod(strDataIni, strDataFim) {
		//retorna true se a data final for maior que a data inicial
		arrDataIni = strDataIni.split("/")
		arrDataFim = strDataFim.split("/")
		diaIni = parseInt(arrDataIni[0],10)
		mesIni = parseInt(arrDataIni[1],10)
		anoIni = parseInt(arrDataIni[2],10)
		diaFim = parseInt(arrDataFim[0],10)
		mesFim = parseInt(arrDataFim[1],10)
		anoFim = parseInt(arrDataFim[2],10)
		if (anoFim >= anoIni) {
			if (anoFim == anoIni) {
				if (mesFim >= mesIni) {
					if (mesFim == mesIni) {
						if (diaFim >= diaIni) { 
							return true;
						}
					} else {
						return true;
					}
				}
			} else {
				return true;
			}
		}
		return false;
	}

	// Função para retirar os espaços de uma string, equivalente ao TRIM do VB
	function trim(theString) {
		var aString = theString;
		var newString = "";
		var kBlank = " ";
		if (aString.indexOf(kBlank) >= 0)  {
			for (var i = 0; i < aString.length; i++)
				if (aString.charAt(i) != kBlank)
					break;
				
			for (var j =  aString.length-1; j >= 0; j--)
				if (aString.charAt(j) != kBlank)
					break;
				
			if (i == aString.length && j == -1)
				newString = "";
			else
				if (i != 0 || j != aString.length -1)
					newString = trim(aString.substring(i, j+1));
				else
					newString = aString.charAt(i) + trim(aString.substring(i+1, j+1)) + aString.charAt(j+1);
		}
		else
			newString = aString;
				
		return newString;
	}
	
	function trimOpcao(theString) {
		theString = Trim(theString)
		i = 0
		while (i < theString.length) {
			if (theString.charCodeAt(i) == 13 || theString.charCodeAt(i) == 10) 
				theString = theString.substring(0,i) + theString.substring(i+1,theString.length);
			else i++
		}
		return theString;
	}
	
	//Verifica se o CGC é valido
	function isCgc(strCGC) {
		//verifica se o CGC é válido
		var strvalid = "0123456789", i = 0;
		//retira os caracteres que não forem números para aplicar o algoritmo
		while (i < strCGC.length) {
			if (strvalid.indexOf(strCGC.charAt(i)) < 0) {
				strCGC = strCGC.substring(0,i) + strCGC.substring(i+1,strCGC.length)
			} else i++;	
		}
		if (strCGC.length != 14) return false;
		//teste do primeiro dígito
		strserie = "543298765432", c1=0;
		for (i=1; i < 13; i++) {
			c1 += strCGC.charAt(i-1) * strserie.charAt(i-1);
		}
		c1 %= 11;
		if (c1 < 2)
			c1 = 0
		else c1 = 11 - c1;
		if (c1 != strCGC.charAt(12))
			return false;
		//teste do segundo dígito
		strserie = "6543298765432", c1=0;
		for (i=1; i < 14; i++) {
			c1 += strCGC.charAt(i-1) * strserie.charAt(i-1);
		}
		c1 %= 11;
		if (c1 < 2)
			c1 = 0
		else c1 = 11 - c1;
		if (c1 != strCGC.charAt(13))
			return false;
		
		return true;		
	} //29.010.519/0001-32
	
	//Funcao que coloca os pontos, a barra e o traco no CGC
	//Recebe como entrada um CGC valido, jah testado
	function formataCGC(strCGC){
		var strvalid = "0123456789", i = 0, strFormatado = "";
		//retira os caracteres que não forem números para aplicar o algoritmo
		while (i < strCGC.length) {
			if (strvalid.indexOf(strCGC.charAt(i)) < 0) {
				strCGC = strCGC.substring(0,i) + strCGC.substring(i+1,strCGC.length)
			} else i++;	
		}
		
		for(i=0; i<2; i++)
			strFormatado += strCGC.charAt(i);
			
		strFormatado += ".";
			
		for(i=2; i<5; i++)
			strFormatado += strCGC.charAt(i);
		
		strFormatado += ".";
		
		for(i=5; i<8; i++)
			strFormatado += strCGC.charAt(i);
		
		strFormatado += "/";
		
		for(i=8; i<12; i++)
			strFormatado += strCGC.charAt(i);
		
		strFormatado += "-";
		
		for(i=12; i<14; i++)
			strFormatado += strCGC.charAt(i);
			
		return strFormatado;		
	}
	
	function isNumeric(strTexto)
	{
		//verifica se uma string é um número inteiro
		//Obs.: utiliza a função IsEmpty
		if (IsEmpty(strTexto)) 
			return false;
		var strNum = "0123456789";
		
		for (var i=0; i < strTexto.length; i++) {
			if (strNum.indexOf(strTexto.charAt(i)) < 0)
				return false;			
		}
		return true;
	}
	
	function isValidPassword(strTexto) {
		//retorna true se uma senha tiver 8 dígitos ou mais
		if (strTexto.length >= 6 && strTexto.length <= 15) 
			return true;
		else
			return false;
	}
	
	function isValidPeriod(strDataIni, strDataFim) {
		//retorna true se a data final for maior que a data inicial
		arrDataIni = strDataIni.split("/")
		arrDataFim = strDataFim.split("/")
		diaIni = parseInt(arrDataIni[0],10)
		mesIni = parseInt(arrDataIni[1],10)
		anoIni = parseInt(arrDataIni[2],10)
		diaFim = parseInt(arrDataFim[0],10)
		mesFim = parseInt(arrDataFim[1],10)
		anoFim = parseInt(arrDataFim[2],10)
		if (anoFim >= anoIni) {
			if (anoFim == anoIni) {
				if (mesFim >= mesIni) {
					if (mesFim == mesIni) {
						if (diaFim >= diaIni) { 
							return true;
						}
					} else {
						return true;
					}
				}
			} else {
				return true;
			}
		}
		return false;
	}
	
	function isCep(cep)
	{	
		//verifica se o CEP está corretamente digitado aceitando apenas números e "-"
		var i, strCEP = "0123456789";
		
		if(cep.length != 8 && cep.length != 9)
			return false;
		
		for (i=0; i<5; i++)
		{
			if ( strCEP.indexOf(cep.charAt(i)) < 0 )
				return false;
		}
		if ( (strCEP.indexOf(cep.charAt(i)) >= 0 && cep.length != 8) || (cep.charAt(i) == "-" && cep.length != 9) || (cep.charAt(i) != "-" && strCEP.indexOf(cep.charAt(i)) < 0) )
			return false;
				
		for (++i; i<cep.length; i++)
		{
			if ( strCEP.indexOf(cep.charAt(i)) < 0 )
				return false;
		}
		
		return true;
	}
	
	//Funcao que coloca o traco no CEP
	//Recebe como entrada um CEP valido, jah testado
	function formataCEP(strCEP)
	{
		var strvalid = "0123456789", i = 0, strFormatado = "";
		//retira os caracteres que não forem números para aplicar o algoritmo
		while (i < strCEP.length) {
			if (strvalid.indexOf(strCEP.charAt(i)) < 0) {
				strCEP = strCEP.substring(0,i) + strCEP.substring(i+1,strCEP.length)
			} else i++;	
		}
		
		for(i=0; i<5; i++)
			strFormatado += strCEP.charAt(i);
			
		strFormatado += "-";
		
		for(i=5; i<strCEP.length; i++)
			strFormatado += strCEP.charAt(i);
			
		return strFormatado;		
	}

//validação da busca
	function buscaValida(strBusca)
	{
		var strvalid = "0123456789 ABCDEFGHIJKLMNOPQRSTUVXYZ().-,;ÁÄÀÃÂÉËÈÊÍÏÌÎÓÖÒÕÔÚÜÙÛÇ", i = 0, strFormatado = "";
		strBusca = trim(strBusca);
		strBusca = strBusca.toUpperCase();
				
		//retira os caracteres que não forem números para aplicar o algoritmo
		while (i < strBusca.length)
		{
			if (strvalid.indexOf(strBusca.charAt(i)) < 0)
				return false;
			else
				i++;
		}
		
		return true;
	}
	
	function Navegacao(url,area){
				document.navegacao.area.value = "" + area + "";
				document.navegacao.action = "" + url + "";
				document.navegacao.submit();
	}
