function RollOver(Imagem)
{
	Imagem.src = Imagem.MouseOverImg;
}

function RollOut(Imagem)
{
	if(Imagem.AreaAtiva != "1") 
	{
		Imagem.src = Imagem.MouseOutImg;
	}
}

function AtivaMenuArea(Imagem)
{
	Imagem.AreaAtiva = "1" 
	Imagem.src = Imagem.MouseOverImg;
}

function MascaraCPF(Obj,Opcao)
{var KeyCod = window.event.keyCode;
 //PARA EVENTO ONBLUR / ONKEYUP
 if(Opcao == 0 && ((!(KeyCod == 16 || KeyCod == 8 || (KeyCod > 34 && KeyCod < 41)) && ((KeyCod > 47 && KeyCod < 58) || (KeyCod > 95 && KeyCod < 106))) || (KeyCod == 0)) || (RetornaNumeros(Obj.value).length == 11 && (!(KeyCod == 16 || KeyCod == 8 || (KeyCod > 34 && KeyCod < 41)))))
	{
	var NovoTexto = '';
	 var TextoAntigo = RetornaNumeros(Obj.value)
	 if(TextoAntigo.length > 11)
		{TextoAntigo = TextoAntigo.substr(0,11)}
	 for(Pos=0; Pos<TextoAntigo.length; Pos++)
		{NovoTexto+= TextoAntigo.substr(Pos,1)
		 if(NovoTexto.length == 3 || NovoTexto.length == 7)
			{NovoTexto+= '.'}
		 if(NovoTexto.length == 11) 
			{NovoTexto+= '-'}
		}
	 Obj.value = NovoTexto
	}
}

function MascaraCEP(Obj,Opcao)
{var KeyCod = window.event.keyCode;
 //PARA EVENTO ONBLUR / ONKEYUP	
 if(Opcao == 0 && ((!(KeyCod == 16 || KeyCod == 8 || (KeyCod > 34 && KeyCod < 41)) && ((KeyCod > 47 && KeyCod < 58) || (KeyCod > 95 && KeyCod < 106))) || (KeyCod == 0)) || (RetornaNumeros(Obj.value).length == 8 && (!(KeyCod == 16 || KeyCod == 8 || (KeyCod > 34 && KeyCod < 41)))))
	{var NovoTexto = '';
	 var TextoAntigo = RetornaNumeros(Obj.value)
	 if(TextoAntigo.length > 8)
		{TextoAntigo = TextoAntigo.substr(0,8)}
	 for(Pos=0; Pos<TextoAntigo.length; Pos++)
		{NovoTexto+= TextoAntigo.substr(Pos,1)
		 if(NovoTexto.length == 5)
			{NovoTexto+= '-'}
		}
	 Obj.value = NovoTexto
	}
}

function MascaraData(Obj,Opcao)
{var KeyCod = window.event.keyCode;
 //PARA EVENTO ONBLUR / ONKEYUP
 if(Opcao == 0 && ((!(KeyCod == 16 || KeyCod == 8 || (KeyCod > 34 && KeyCod < 41)) && ((KeyCod > 47 && KeyCod < 58) || (KeyCod > 95 && KeyCod < 106))) || (KeyCod == 0)) || (RetornaNumeros(Obj.value).length == 8 && (!(KeyCod == 16 || KeyCod == 8 || (KeyCod > 34 && KeyCod < 41)))))
	{var NovoTexto = '';
	 var TextoAntigo = RetornaNumeros(Obj.value)
	 if(TextoAntigo.length > 8)
		{TextoAntigo = TextoAntigo.substr(0,8)}
	 for(Pos=0; Pos<TextoAntigo.length; Pos++)
		{NovoTexto+= TextoAntigo.substr(Pos,1)
		 if(NovoTexto.length == 2 || NovoTexto.length == 5)
			{NovoTexto+= '/'}
		}
	 Obj.value = NovoTexto
	}
}


function SomenteNumeros() // PARA EVENTO OnKeyDown
{var Tecla = window.event.keyCode;
if (!(	(Tecla > 95 && Tecla < 106) || 
	(Tecla > 44 && Tecla < 58)  || 
	(Tecla > 32 && Tecla < 41)  ||
	(	Tecla == 17 ||
		Tecla == 16 ||
		Tecla == 8  || 
		Tecla == 9  || 
		Tecla == 13 ||
		Tecla == 144  )))
{window.event.returnValue = false;}

}

function ApagarCaracterSomente()  // PARA EVENTO OnKeyDown
{var Tecla = window.event.keyCode;
 if (!(	(Tecla > 33 && Tecla < 40) ||
 	(Tecla > 16 && Tecla < 18) ||
 	(Tecla == 8) ||
 	(Tecla == 46)))
	{window.event.returnValue = false;}
	
}

function RemoveTexto(Obj)
{CharPego = new RegExp("[^0-9]","gi")
 Obj.value= Obj.value.replace(CharPego,'')
}

function RetornaNumeros(Texto)
{var CharPego = new RegExp("[^0-9]","gi")
 var NovoTexto= Texto.replace(CharPego,'')
 return NovoTexto
}

function RetornaReverse(Texto)
{var str = '';
 for(indx=Texto.length; indx > 0 ;indx--)
	{str+=Texto.substr(indx - 1,1);
	}
return str;
}

function RetornaDecimal(Valor)// PARA VALORES MONETÁRIOS, PORCENTAGENS, ETC.
{Valor = Valor.replace(/[^0-9^\.^\-^\,]/g,'')
 if(Valor.replace(/[^0-9]/g,'') == ''){Valor = '0';}
 var indxVirg = RetornaReverse(Valor.replace(/,/g,'.')).indexOf('.'); // encontra a posição do separador decimal ('.')
 var FormatVal = ''
 FormatVal = RetornaNumeros(Valor.substr(0,Valor.length - indxVirg)) + '.' + RetornaNumeros(Valor.substr((Valor.length - indxVirg),indxVirg))
 return parseFloat(FormatVal);
}

function isDecimal(Valor)
{var indxVirg = RetornaReverse(Valor.replace(/,/g,'.')).indexOf('.'); // encontra a posição do separador decimal ('.')
 var SimulaValor = '';
 SimulaValor = ((Valor.substr(0,Valor.length - indxVirg)).replace(/,/g,'').replace(/\./g,'') + '.' + (Valor.substr((Valor.length - indxVirg),indxVirg)).replace(/,/g,'').replace(/\./g,'')).replace(/ /g,'')
 return !isNaN(SimulaValor)
}


function RetornaMoney(Valor)
{
var decValor = "" + RetornaDecimal(Valor)
var PontoPos = decValor.search(/\./i)
if (PontoPos >= 0)
	{casaDec = "" + decValor.substr(PontoPos+1,decValor.length) + "00000000000000000"
	 Incremento = Math.round("0." + casaDec.substr(2,15))
	 VetorDec = casaDec.substr(0,2).split("");
	 indx = 1;
	 
	 while(Incremento == 1 && indx >= 0)
	 	{VetorDec[indx] = parseInt(VetorDec[indx]) + 1;
	 	 if(VetorDec[indx] > 9)
	 	 	{VetorDec[indx] = 0;}
	 	 else
	 	 	{Incremento = 0;}
	 	 indx-- ;
	 	}
	
	 casaDec = VetorDec.join("")
	 decValor = "" + (parseFloat(decValor) + Incremento);
	 
	 //casaDec = "" + casaDec.substr(0,1) + (parseInt(casaDec.substr(1,1)) + Math.round(parseInt(Arrendonda) / 10000))
	 ValTemp = decValor.substring(decValor.substr(0,PontoPos).length - parseInt(decValor.substr(0,PontoPos).length / 3) * 3,PontoPos)
	 
	 Val = ""
	 for(indx=0; indx < ValTemp.length; indx++)
	 	{Val+= (indx % 3 == 0) ? "." + ValTemp.substr(indx,1) : ValTemp.substr(indx,1);
	 	}
	 
	 valMonetario = decValor.substr(0,PontoPos - ValTemp.length) + Val + "," + casaDec;
	 
	 if ((decValor.substr(0,PontoPos).length) % 3 == 0){valMonetario = valMonetario.substring(1,valMonetario.length)}
	}
else
	{if (decValor.length > 0 && Valor.replace(/ /g,'') != '')
		{ValTemp = decValor.substring(decValor.length - parseInt(decValor.length / 3) * 3,decValor.length)
		 Val = ""
		 for(indx=0; indx < ValTemp.length; indx++)
		 	{Val+= (indx % 3 == 0) ? "." + ValTemp.substr(indx,1) : ValTemp.substr(indx,1);
		 	}
		 valMonetario = decValor.substr(0,decValor.length - ValTemp.length) + Val + ",00";
		 
		 if ((decValor.length) % 3 == 0){valMonetario = valMonetario.substring(1,valMonetario.length)}
		}
	 else
	 	{valMonetario = "0,00";}
		
	}
return valMonetario;
}


function ArredondaDec(Numero, NumCasaDec)
{	var NumDec = "" + RetornaDecimal(Numero);
	var PontoPos = NumDec.search(/\./i);
	var decValor = NumDec.substr(PontoPos+1,NumDec.length) + "00000000000000" ;
	var Arredonda = "";
	var valFinal = "";

	var Incremento = Math.round("0." + decValor.substr(NumCasaDec,decValor.length))
	var VetorDec = decValor.substr(0,NumCasaDec).split("");
	var indx = parseInt(NumCasaDec) - 1;
	
	while(Incremento == 1 && indx >= 0)
	{VetorDec[indx] = parseInt(VetorDec[indx]) + 1;
	 if(VetorDec[indx] > 9)
	 	{VetorDec[indx] = 0;}
	 else
	 	{Incremento = 0;}
	 indx-- ;
	}
	
	decValor = VetorDec.join("")
	NumDec = "" + (parseFloat(NumDec) + Incremento);
	
	
	if(parseInt(NumCasaDec) > 0)
		{Arredonda = "." + decValor.substr(0,NumCasaDec-1) + (parseInt(decValor.substr(NumCasaDec-1,1)) + parseInt(Math.round("0."+decValor.substr(NumCasaDec,decValor.length))));
		 valFinal = NumDec.substr(0,PontoPos) + Arredonda;
		}
	else
		{valFinal = parseInt(NumDec.substr(0,PontoPos)) + parseInt(Math.round("0." + decValor))
		}
	
	return valFinal;
}