/*--------------Indice de Funções-------------------------------------------------
FormatDate(i, delKey,direction)
CheckDate(dtaDate)
FormatCGC(i, delKey,direction)
FormatCEP(i, delKey,direction)
FormatIE(i, delKey,direction)
CheckNum()
IsNumeric(strNumber)
IsDate(strDate)
LTrim(String)
RTrim(String)
Trim(String)
Len(String)
Left(str, n)
Right(str, n)
Mid(str, start, len)
InStr(strSearch, charSearchFor)
FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,UseParensForNegativeNumbers, GroupDigits)
FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,UseParensForNegativeNumbers, GroupDigits)
*/

/*------------------------------------------------------------------------------------------
Função: FormatDate(i, delKey,direction) 
		CheckDate(dtaDate)
Objetivo: Faz a formatação da data numa caixa de texto
		  Esta função deve ser utilizada em conjunto com a função CheckDate
Exemplo: onchange="CheckDate(this)" onkeydown="FormatDate(this, window.event.keyCode,'down')" onkeyup="FormatDate(this, window.event.keyCode,'up')"
Retorno: Data formatada e mensagem de erro.
------------------------------------------------------------------------------------------*/

	function FormatDate(i, delKey,direction)
	{
		if (i.value.length < 10) 
		{
			if (delKey!=9)
			{ // se for tab
				if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41))
				{ //teclas delete, backspace, shift, nao disparam o evento
					var fieldLen = i.value.length
					if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) 
					{
						if (fieldLen == 2 || fieldLen == 5)
						{
							i.value = i.value + "/";
						}
					}
					else
					{
						if (direction == "up")
						{
							if (i.value.length == 0)
							{
								i.value = "";
							} 
							else 
							{
								i.value = i.value.substring(0,i.value.length-1);
							}
						}
					}
					i.focus();
				}
			}
			else
			{
				if (direction == "down")
				{
					CheckDate(i);
				}
			}
		}
	}
	//---------------------------------
	function CheckDate(dtaDate)
	{
		if (dtaDate.value == "" ) //verifica se a data foi digitada
		{
		return false;
		}
		var err=0;
		dtaValue=dtaDate.value;
		if (dtaValue.length != 8 && dtaValue.length != 10 ) err=1
		mm = dtaValue.substring(3, 5);
		dd = dtaValue.substring(0, 2);
		yy = dtaValue.substring(6, 10);
		if (mm<1 || mm>12) err = 1
		if (dd<1 || dd>31) err = 1
		if (yy.length == 4){
			if (yy<1900) err = 1
		}
		else {
			//se ano for inferior a 30 se entende 20??
			//se for maior que 29 se entende 19??
			yy=parseInt(yy,10)
			yy += yy<30?2000:1900
		}
		if (mm==4 || mm==6 || mm==9 || mm==11)
		{
			if (dd==31) err=1
		}
		if (mm==2)
		{
			var dtaYear=parseInt(yy/4);
			if (isNaN(dtaYear)) 
			{
				err=1;
			}
			if (dd>29) err=1
			if (dd==29 && ((yy/4)!=parseInt(yy/4))) err=1
		}
		dtaDate.value = dd + '/' + mm + '/' + yy

		if (err==1) 
		{
			if (dtaValue.length < 8) //verifica se a data digitada está completa
			{
			dtaDate.value = ""
			}
			else
			{
			alert(dtaDate.value + ' e uma data invalida!');
			dtaDate.value = ""
			dtaDate.focus();
			return false;
			}
		}
		return true;
	}
/*-------------------------------------------------------------------------------------------------
Função: FormatCGC(i, delKey,direction)
Objetivo: Cria máscara para digitação de CGC
Exemplo: onkeydown="FormatCGC(this, window.event.keyCode,'down')" onkeyup="FormatCGC(this, window.event.keyCode,'up')"
Retorno: Retorna o CGC Formatado
-------------------------------------------------------------------------------------------------*/

	function FormatCGC(i, delKey,direction)
	{
		if (i.value.length < 18) 
		{
			if (delKey!=9) 
			{ // se for tab
				if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41))
				{ //teclas delete, backspace, shift, nao disparam o evento
					var fieldLen = i.value.length
					if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) 
					{
						if ((fieldLen == 2) || (fieldLen == 6)) 
						{
							i.value = i.value + ".";
						}
						if (fieldLen == 10) 
						{
							i.value = i.value + "/";
						}
						if (fieldLen == 15) 
						{
							i.value = i.value + "-";
						}
					} 
					else 
					{
						if (direction == "up") 
						{
							if (i.value.length == 0) 
							{
								i.value = "";
							} 
							else 
							{
								i.value = i.value.substring(0,i.value.length-1);
							}
						}
					}
					i.focus();
				}
			} 
		}
	}

/*-------------------------------------------------------------------------------------------------
Função: FormatCEP(i, delKey,direction)
Objetivo: Cria máscara para digitação de CEP
Exemplo: onkeydown="FormatCEP(this, window.event.keyCode,'down')" onkeyup="FormatCEP(this, window.event.keyCode,'up')"
Retorno: Retorna o CEP Formatado
-------------------------------------------------------------------------------------------------*/

	function FormatCep(i, delKey,direction)
	{
		if (i.value.length < 8) 
		{
			if (delKey!=9) 
			{ // se for tab
				if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41))
				{ //teclas delete, backspace, shift, nao disparam o evento
					var fieldLen = i.value.length
					if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) 
					{
						if (fieldLen == 5) 
						{
							i.value = i.value + "-";
						}
					} 
					else 
					{
						if (direction == "up") 
						{
							if (i.value.length == 0) 
							{
								i.value = "";
							} 
							else 
							{
								i.value = i.value.substring(0,i.value.length-1);
							}
						}
					}
					i.focus();
				}
			} 
		}
	}

/*-------------------------------------------------------------------------------------------------
Função: FormatIE(i, delKey,direction)
Objetivo: Cria máscara para digitação de Inscrição Estadual
Exemplo: onkeydown="FormatIE(this, window.event.keyCode,'down')" onkeyup="FormatIE(this, window.event.keyCode,'up')"
Retorno: Retorna a IE Formatada
-------------------------------------------------------------------------------------------------*/

	function FormatIE(i, delKey,direction) 
	{
		if (i.value.length < 11) 
		{
			if (delKey!=9) 
			{ // se for tab
				if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41))
				{ //teclas delete, backspace, shift, nao disparam o evento
					var fieldLen = i.value.length
					if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) 
					{
						if ((fieldLen == 3) || (fieldLen == 7)) 
						{
							i.value = i.value + ".";
						}
					} 
					else 
					{
						if (direction == "up") 
						{
							if (i.value.length == 0) 
							{
								i.value = "";
							} 
							else 
							{
								i.value = i.value.substring(0,i.value.length-1);
							}
						}
					}
					i.focus();
				}
			} 
		}
	}

/*-------------------------------------------------------------------------------------------------
Função: FormatCPF(i, delKey,direction)
Objetivo: Cria máscara para digitação de CPF
Exemplo: onkeydown="FormatCPF(this, window.event.keyCode,'down')" onkeyup="FormatCPF(this, window.event.keyCode,'up')"
Retorno: Retorna o CPF Formatada
-------------------------------------------------------------------------------------------------*/
	function FormatCPF(i, delKey,direction)
	{
		if (i.value.length < 18) 
		{
			if (delKey!=9) 
			{ // se for tab
				if(delKey!=8 && delKey!=46 && delKey!=16 && !(delKey>36 && delKey<41) && delKey!=17 && delKey!=86)
				{ //teclas delete, backspace, shift, nao disparam o evento
					var fieldLen = i.value.length
					if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) 
					{
						if ((fieldLen == 3) || (fieldLen == 7)) 
						{
							i.value = i.value + ".";
						}
						if (fieldLen == 11) 
						{
							i.value = i.value + "-";
						}
					} 
					else 
					{
						if (direction == "up") 
						{
							if (i.value.length == 0) 
							{
								i.value = "";
							} 
							else 
							{
								i.value = i.value.substring(0,i.value.length-1);
							}
						}
					}
					i.focus();
				}
			} 
		}
	}

/*-------------------------------------------------------------------------------------------------
Função: CheckNum()
Objetivo: Faz a validação para permitir apenas ser digitado números numa caixa de texto.
OBS: Esta função permite digitar vírgulas
Exemplo: onKeyPress = "return CheckNum()"
Retorno: A função barra a digitação
-------------------------------------------------------------------------------------------------*/

	function CheckNum()
	{
		if ((event.keyCode < 48) || (event.keyCode > 57))
			if (event.keyCode != 44)
			{
				return false;
			}
		return true;
	}
/*-------------------------------------------------------------------------------------------------
Função: CheckWSpace()
Objetivo: Faz a validação para não permitir ser digitado espaços em branco.
Exemplo: onKeyPress = "return CheckWSpace()"
Retorno: A função barra a digitação
-------------------------------------------------------------------------------------------------*/
	function CheckWSpace()
	{
		if (event.keyCode == 32)
			{
				return false;
			}
		return true;
	}
/*-------------------------------------------------------------------------------------------------
Função: CheckIntNum()
Objetivo: Faz a validação para permitir apenas ser digitado números numa caixa de texto.
OBS: Esta função não permite digitar vírgulas
Exemplo: onKeyPress = "return CheckIntNum()"
Retorno: A função barra a digitação
-------------------------------------------------------------------------------------------------*/

	function CheckIntNum()
	{
		if ((event.keyCode < 48) || (event.keyCode > 57))
		return false;
	}

/*-------------------------------------------------------------------------------------------------
Função: IsNumeric(strNumber)
Objetivo: Verifica se a informação de entrada da função é numérico
		  Esta função é usada na função IsDate, mas pode ser utilizada separadamente.
Retorno: True ou False
-------------------------------------------------------------------------------------------------*/

	function IsNumeric(strNumber)
	{
		strTemp = "";
		if (strNumber == "")
		{
			return false;
		}
		
		for( i = 0; i < (strNumber.length); i++)
		{
			strChar = strNumber.charAt(i);
			if ( !( strChar >= "0" && strChar <= "9" || strChar == "," || strChar == "." ) )
			{
				if ( !(i == 0 && strChar == "-") )
				{
					strTemp += strChar;
				}
			}
		}
		return (strTemp == "");
	}

/*-------------------------------------------------------------------------------------------------
Função: IsDate(strDate)
Objetivo: Verifica se a informação de entrada é uma data.
Exemplo: onKeyPress = "return CheckNum()"
Retorno: True ou False
-------------------------------------------------------------------------------------------------*/

	function IsDate(strDate)
	{
		if (!IsNumeric(strDate.charAt(1)) )
		{
			strDate = "0" + strDate;
		}
		
		if (!IsNumeric(strDate.charAt(4)) )
		{
			strDate = strDate.substring(0,3) + "0" + strDate.substring(3,strDate.length);
		}

		if ( !(strDate.length == 8 || strDate.length == 10) )
		{
			return (false);
		}
		
		strDay = strDate.charAt(0) + strDate.charAt(1);
		strMonth = strDate.charAt(3) + strDate.charAt(4);
		strYear = strDate.charAt(6) + strDate.charAt(7);

		if (strDate.length == 10)
		{
			strYear += strDate.charAt(8) + strDate.charAt(9);
		}

		numDay = 0;
		numMonth = 0;
		numYear = 0;
		
		if (IsNumeric(strDay))
		{
			numDay = parseInt(strDay,10);
		}
		else
		{
			return (false);
		}

		if (IsNumeric(strMonth))
		{
			numMonth = parseInt(strMonth,10);
		}
		else
		{
			return (false);
		}

		if (IsNumeric(strYear))
		{
			numYear = parseInt(strYear,10);
			if (numYear < 100 )
			{
				numYear += numYear<30?2000:1900;
			}
		}
		else
		{
			return false;
		}

		blnBissexto = ((numYear % 4) == 0);

		if (numMonth == 0 || numMonth > 12)
		{
			return (false);
		}

		if (numMonth == 2)
		{
			if (blnBissexto)
			{
				if (numDay > 29)
				{
					return (false);
				}
			}
			else
			{
				if (numDay > 28)
				{
					return (false);
				}
			}
		}
		else if (numMonth == 4 || numMonth == 6 || numMonth == 9 || numMonth == 11)
		{
			if (numDay > 30)
			{
				return (false);
			}
		}
		else
		{
			if (numDay > 31)
			{
				return (false);
			}
		}
		return (true);
	}

/*---------------------------------------------------------------------------------------------
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
PURPOSE: Remove	leading	blanks from	our	string.
IN:	str	- the string we	want to	LTrim

RETVAL:	An LTrimmed	string!
---------------------------------------------------------------------------------------------*/
	function LTrim(str)
	{
		var	whitespace = new String(" \t\n\r");

		var	s =	new	String(str);

		if (whitespace.indexOf(s.charAt(0))	!= -1) {
			// We have a string	with leading blank(s)...

			var	j=0, i = s.length;

			// Iterate from	the	far	left of	string until we
			// don't have any more whitespace...
			while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
				j++;

			// Get the substring from the first	non-whitespace
			// character to	the	end	of the string...
			s =	s.substring(j, i);
		}

		return s;
	}

/*---------------------------------------------------------------------------------------------
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
PURPOSE: Remove	trailing blanks	from our string.
IN:	str	- the string we	want to	RTrim

RETVAL:	An RTrimmed	string!
---------------------------------------------------------------------------------------------*/
	function RTrim(str)
	{
		// We don't	want to	trip JUST spaces, but also tabs,
		// line	feeds, etc.	 Add anything else you want	to
		// "trim" here in Whitespace
		var	whitespace = new String(" \t\n\r");

		var	s =	new	String(str);

		if (whitespace.indexOf(s.charAt(s.length-1)) !=	-1)	{
			// We have a string	with trailing blank(s)...

			var	i =	s.length - 1;		// Get length of string

			// Iterate from	the	far	right of string	until we
			// don't have any more whitespace...
			while (i >= 0 &&	whitespace.indexOf(s.charAt(i))	!= -1)
				i--;

			// Get the substring from the front	of the string to
			// where the last non-whitespace character is...
			s =	s.substring(0, i+1);
		}

		return s;
	}

/*---------------------------------------------------------------------------------------------
Trim(string) : Returns a copy of a string without leading or
			   trailing spaces
=============================================================
PURPOSE: Remove	trailing and leading blanks	from our string.
IN:	str	- the string we	want to	Trim

RETVAL:	A Trimmed string!
---------------------------------------------------------------------------------------------*/
	function Trim(str)
	{
			return RTrim(LTrim(str));
	}

/*---------------------------------------------------------------------------------------------
Len(String) : Returns the number of characters in a string
===========================================================
IN: str - the string whose length we are interested in

RETVAL: The number of characters in the string
---------------------------------------------------------------------------------------------*/

	function Len(str)
	{  return String(str).length;  }

/*---------------------------------------------------------------------------------------------
Left(string, length): Returns a	specified number of	characters from	the
					  left side	of a string
========================================================================
IN:	str	- the string we	are	LEFTing
	n -	the	number of characters we	want to	return

RETVAL:	n characters from the left side	of the string
---------------------------------------------------------------------------------------------*/

	function Left(str, n)
	{
		if (n <= 0)	   // Invalid bound, return	blank string
				return "";
		else if	(n > String(str).length)	  // Invalid bound,	return
				return str;				   // entire string
		else //	Valid bound, return	appropriate	substring
				return String(str).substring(0,n);
	}

/*---------------------------------------------------------------------------------------------
Right(string, length): Returns a specified number of characters from the
					   right side of a string
========================================================================
IN:	str	- the string we	are	RIGHTing
	n -	the	number of characters we	want to	return

RETVAL:	n characters from the right	side of	the	string
---------------------------------------------------------------------------------------------*/

	function Right(str, n)
	{
		if (n <=	0)		// Invalid bound, return	blank string
			return "";
		else if	(n >	String(str).length)	  // Invalid bound,	return
			return str;					   // entire string
		else { // Valid	bound, return appropriate substring
			var iLen	= String(str).length;
			return String(str).substring(iLen, iLen - n);
		}
	}

/*---------------------------------------------------------------------------------------------
Mid(string,	start, length):	Returns	a specified	number of characters from a
							string
============================================================================
IN:	str	- the string we	are	LEFTing
	start -	our	string's starting position (0 based!!)
	len	- how many characters from start we	want to	get

RETVAL:	The	substring from start to	start+len

---------------------------------------------------------------------------------------------*/
	function Mid(str, start, len)
	/***
	***/
	{
		// Make	sure start and len are within proper bounds
		if (start < 0 || len < 0) return "";

		var	iEnd, iLen = String(str).length;
		if (start +	len > iLen)
			iEnd = iLen;
		else
			iEnd = start + len;

		return String(str).substring(start,iEnd);
	}

/*------------------------------------------------------------------------------------------------------
InStr(str, SearchForStr) : Returns the location	a character	(charSearchFor)
						   was found in	the	string str
========================================================================
InStr(strSearch, charSearchFor)	: Returns the first	location a substring (SearchForStr)
						   was found in	the	string str.	 (If the character is <B>not</B>
						   found, -1 is	returned.)
------------------------------------------------------------------------------------------------------*/
	function InStr(strSearch, charSearchFor)
	{
		for (i=0; i < Len(strSearch); i++)
		{
			if (charSearchFor == Mid(strSearch, i, 1))
			{
				return i;
			}
		}
		return -1;
	}

/*------------------------------------------------------------------------------------------------------
FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,
             UseParensForNegativeNumbers, GroupDigits)
======================================================================
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 ------------------------------------------------------------------------------------------------------*/

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
{ 
	if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign

	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

/*------------------------------------------------------------------------------------------------------
FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit,
               UseParensForNegativeNumbers, GroupDigits)
/**********************************************************************
IN:
	NUM - the number to format
	decimalNum - the number of decimal places to format the number to
	bolLeadingZero - true / false - display a leading zero for
									numbers between -1 and 1
	bolParens - true / false - use parenthesis around negative numbers
	bolCommas - put commas as number separators.
 
RETVAL:
	The formatted number!
------------------------------------------------------------------------------------------------------*/
	function FormatCurrency(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
	{
		var tmpStr = new String(FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas));

		if (tmpStr.indexOf("(") != -1 || tmpStr.indexOf("-") != -1) {
			// We know we have a negative number, so place '$' inside of '(' / after '-'
			if (tmpStr.charAt(0) == "(")
				tmpStr = "($"  + tmpStr.substring(1,tmpStr.length);
			else if (tmpStr.charAt(0) == "-")
				tmpStr = "-$" + tmpStr.substring(1,tmpStr.length);
				
			return tmpStr;
		}
		else
			return "$" + tmpStr;		//Return formatted string!
	}
	
//------------------------------------------------------------------------------------------------------
	function FormatCEP(field)
	{
		if (field.value.length == 5)
		{
			field.value = field.value + "-"
		}
	}
//------------------------------------------------------------------------------------------------------
	function LeftZeroes(string,lenght)
	{
		string = Right('00000000' + String(string),lenght)

		return string
	}
//------------------------------------------------------------------------------------------------------
	function FormatHour(i, delKey,direction)
	{
		if (i.value.length < 9)
		{
			if (delKey!=9) 
			{ // se for tab
				if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41))
				{ //teclas delete, backspace, shift, nao disparam o evento
					var fieldLen = i.value.length
					if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) 
					{
						if (fieldLen == 2 || fieldLen == 5)
						{
							i.value = i.value + ":";
						}
					} 
					else 
					{
						if (direction == "up") 
						{
							if (i.value.length == 0) 
							{
								i.value = "";
							} 
							else 
							{
								i.value = i.value.substring(0,i.value.length-1);
							}
						}
					}
					i.focus();
				}
			} 
		}
	}
	//---------------------------------
	function CheckHour(item)
	{
		var strValue = item.value
		var varHora = 0,varMinutos = 0,varSegundos = 0
		if (strValue != "")
		{
			varHora = Left(strValue,2)
			varMinutos = Mid(strValue,3,2)
			varSegundos = Mid(strValue,6,2)

			if (varHora > 23 || varMinutos > 59 || varSegundos > 59)
			{
				alert(strValue + ' nao e um horario valido!')
				item.value = '';
				item.focus();
			}
			else
			{
				if (isNaN(varSegundos))
				{
					varSegundos = '00'
				}
				if (isNaN(varMinutos))
				{
					varMinutos = '00'
				}
				strValue = LeftZeroes(varHora,2) + ':' + LeftZeroes(varMinutos,2) + ':' + LeftZeroes(varSegundos,2)
				item.value = strValue
			}
		}
	}
	//---------------------------------
	function MM_swapImgRestore() 
	{ 
		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() 
	{
	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) 
	{
		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;
	}
	//---------------------------------
	function MM_swapImage() 
	{
		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 fctTimer(tempo)
	{
		var Timer = setTimeout("window.open('/SessionExpired/frmSessionExpired.asp','PassWindow','width=300, height=250, top=150, left=210,alwaysRaised=yes,hotkeys=no,directories=no,z-lock=yes')",tempo)
	}
//------------------------------------------------------------------------------------------------------

//******************************************************************************************
// Funções utilizadas para validar valor digitado.
//******************************************************************************************

// Verificando qual o navegador utilizado
	var isNav4, isNav, isIE;
	if (parseInt(navigator.appVersion.charAt(0)) >= 4)
	{
		isNav = (navigator.appName=="Netscape") ? true : false;
		isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
	}
	if (navigator.appName=="Netscape") {
		isNav4 = (parseInt(navigator.appVersion.charAt(0))==4);
	}

function formataval(item)
{
	var valor = item;
	var str="";
	var j=0;
	if(valor.value!=""){
	if(range(valor)){
		alert("Por Favor digite um valor válido.");
		item.focus();
		item.select();
		return;
	}
	str = valor.value + ",";
	arredonda(valor);
	}
}

function checkDecimal(campo) {
	if (campo.value.length == 2)
		campo.value = '0,' + campo.value;
	if (campo.value.length == 1)
		campo.value = '0,' + campo.value + '0';
}

function onlynum(){
	if((event.keyCode<48)||(event.keyCode>57)){
		event.keyCode=0;
	}
}

function arredonda(valor) {
	var j=0, str="";
	for(var i=0; (i<=valor.value.length-1)&&(valor.value.charAt(i)!=',');i++) {
	str=str+valor.value.charAt(i);
	j++
	}
	if(valor.value.charAt(0)==',')
	str=str+"0"
	str=str + ",";
		j++
	if(valor.value.charAt(j)=='')
		str=str+0
	else
		str=str+valor.value.charAt(j)
	if(valor.value.charAt(j+1)=='')
		str=str+0
	else
		str=str+valor.value.charAt(j+1)
		valor.value=str;
		str=""
		str=str+valor.value;
		valor.value=str
}

function formatarOnKeyDown(obj)
{
	var decimal,inteiro;
	var i,count;
	str = new String(obj.value);

	inteiro='';
	(isIE)
	{
		if (obj.maxLength > str.length)
		{
		str = tirarZerosEsquerda(str); //ESTA FUNCAO TIRA TAMBEM PONTO E VIRGULA

		if (((event.keyCode > 47) && (event.keyCode < 59)) || ((event.keyCode > 95) && (event.keyCode < 106)))
		{
			if (str.length == 0)
			{
				inteiro  = '0';
				decimal =	'0' + str;
			}
			else 
			{
				if (str.length == 1)
				{
					inteiro	 = '0';
					decimal	= str;
				}
				else
				{
					decimal	= str.substring(str.length-1,str.length);
					i=2;
					count=0;
					while (i<=str.length)
					{
						if (count==3)
						{
							inteiro = '.' + inteiro;
							count = 0;
						}
						inteiro = str.charAt(str.length-i) + inteiro;
						count++;
						i++;
					}
				}
			}
		}
		else
		{
			if (event.keyCode == 8)
			{
				if (str.length == 0)
				{
					inteiro  = '0';
					decimal = '000';
				}
				else {
					if (str.length == 1)
					{
						inteiro  = '0';
						decimal = '00' + str;
					}
					else
					{
						if (str.length == 2)
						{
							inteiro  = '0';
							decimal = '0' + str;
						}
						else
						{
		 					decimal = str.substring(str.length-3,str.length);
							i=4;
							count=0;
							
							while (i<=str.length)
							{
								if (count==3)
								{
									inteiro = '.' + inteiro;
									count = 0;
								}
								inteiro = str.charAt(str.length-i) + inteiro;
								count++;
								i++;
							}
						}
					}
				}
			}
			else
			{
				if (str.length == 1)
				{
					inteiro  = '0';
					decimal = '0' + str;
				}
				else
				{
					if (str.length == 2)
					{
						inteiro	= '0';
						decimal	= str;
					}
					else
					{
						decimal = str.substring(str.length-2,str.length);
						i=3;
						count=0;

						while (i<=str.length)
						{
							if (count==3)
							{
								inteiro = '.' + inteiro;
								count = 0;
							}
							inteiro = str.charAt(str.length-i) + inteiro;
							count++;
							i++;
						}
					}
				}
			}
		}
		if (inteiro == '')
		{
			inteiro = '0';
		}
		if (decimal == '')
		{
			decimal = '00';
		}
			obj.value = inteiro+','+decimal;
		}
	}
}

function formatarOnKeyUp(obj)
{
	var decimal,inteiro;
	var i,count;
	str = new String(obj.value);
	str = tirarZerosEsquerda(str);
	inteiro='';
	
	if (isIE)
	{
		if (str.length == 1)
		{
			inteiro  = '0';
			decimal = '0' + str;
		}
		else
		{
			if (str.length == 2)
			{
				inteiro  = '0';
				decimal = str;
			}
			else
			{
				decimal = str.substring(str.length-2,str.length);
				i=3;
				count=0;
				while (i<=str.length)
				{
					if (count==3)
					{
						inteiro = '.' + inteiro;
						count = 0;
					}
					inteiro = str.charAt(str.length-i) + inteiro;
					count++;
					i++;
				}
			}
		}
		if (inteiro == '')
		{
			inteiro = '0';
		}
		if (decimal == '')
		{
			decimal = '00';
		}
		obj.value = inteiro+','+decimal;
	}
}
function range(campo)
{
	for(var	i=0; i<=(eval(campo.value.length)-1); i++)
		if(campo.value.charAt(i)!='0' && campo.value.charAt(i)!='1'	&& campo.value.charAt(i)!='2'
			&& campo.value.charAt(i)!='3' &&	campo.value.charAt(i)!='4' && campo.value.charAt(i)!='5'
			&& campo.value.charAt(i)!='6' &&	campo.value.charAt(i)!='7' && campo.value.charAt(i)!='8'
			&& campo.value.charAt(i)!='9' &&	campo.value.charAt(i)!=',' && campo.value.charAt(i)!='.')
		{
			alert("Valor inválido. Favor redigitar.");
			campo.value=0
			campo.focus()
		}
}

function tirarZerosEsquerda(str)
{
	var sAux='';
	var i=0;
	str=new String(str);

	while (i < str.length )
	{
		if ((str.charAt(i)!='.') && (str.charAt(i)!=','))
		{
			sAux += str.charAt(i);
		}
		i++
	}
	str = new String(sAux);
	sAux = '';
	i=0;

	while (i < str.length)
	{
		if (str.charAt(i) != '0')
		{
			sAux	= str.substring(i,str.length)
			i		= str.length;
		}
		i++;
	}
	return  sAux;
}

function fncData()
{
	Todays = new Date();
	TheDate = Todays.getDate() + "" + (Todays.getMonth() + 1) + "" +
	Todays.getYear() + "" + Todays.getHours() + "" + Todays.getMinutes() + "" + Todays.getSeconds();
	return TheDate;
}


//Trecho que contém a validação para não permitir o clique com o botão direito na página
if (window.Event) document.captureEvents(Event.MOUSEUP); 

function nocontextmenu() 
{ 
	event.cancelBubble = true 
	event.returnValue = false; 

	return false; 
} 

function norightclick(e) 
{ 
	if (window.Event) 
	{ 
		if (e.which == 2 || e.which == 3) 
		return false; 
	} 
	else if (event.button == 2 || event.button == 3) 
	{ 
		event.cancelBubble = true 
		event.returnValue = false; 
		return false; 
	} 
} 
if (document.layers) 
{ 
	document.captureEvents(Event.MOUSEDOWN); 
} 
//document.oncontextmenu = nocontextmenu; 
//document.onmousedown = norightclick; 
//document.onmouseup = norightclick; 
//--------------------------------------------------------------------------------------------
