//*** Permite apenas números inteiros
function IntValido(ch) 
{ 
	if (ch == 0)
		tecla = event.keyCode
	else
		tecla =  ch;

	if ((tecla >= 48 && tecla <= 57)) // numeros de 0 a 9 
		return true
	else if ((tecla == 8) || (tecla == 13))
		return true
	else 
		return false; 
} 

//*** Permite apenas números reais
function NumValido(ch) 
{ 
	if (ch == 0)
		tecla = event.keyCode
	else
		tecla =  ch;

	if ((tecla >= 48 && tecla <= 57) || (tecla == 44)) // numeros de "0" a "9" e ","
		return true
	else if ((tecla == 8) || (tecla == 13))
		return true
	else 
		return false; 
} 

//*** Permite números inteiros e a barra (/)
function DataValida(ch) 
{ 
	if (ch == 0)
		tecla = event.keyCode
	else
		tecla =  ch;

	if ((tecla >= 48 && tecla <= 57) || (tecla == 47)) // numeros de "0" a "9" e "/"
		return true
	else if ((tecla == 8) || (tecla == 13))
		return true
	else 
		return false; 
} 

//*** Permite números inteiros e a dois pontos (:)
function HoraValida(ch) 
{ 
	if (ch == 0)
		tecla = event.keyCode
	else
		tecla =  ch;

	if ((tecla >= 48 && tecla <= 57) || (tecla == 58)) // numeros de "0" a "9" e ":"
		return true
	else if ((tecla == 8) || (tecla == 13))
		return true
	else 
		return false; 
} 

function ValidoEMail(Texto)
{
	tValido = true;
	for (i = 0; i < String(Texto).length; i++)
	{
		ch = String(Texto).charCodeAt(i);
		if (!ValidaCharEMail(ch)) tValido = false;
	}
	
	if (tValido)
	{
		PosPA = Texto.indexOf ('@',1);
		if (PosPA == -1)
			tValido = false
		else
		{
		 	if (Texto.indexOf ('@',(PosPA+1)) != -1)
				tValido = false
			else
			{
				if (Texto.indexOf ('.',(PosPA+2)) == -1)
					tValido = false
				else
					tValido = true;
			}
		}
	}
	
	return tValido;
}

function ValidaCharEMail(ch) 
{ 
	if (ch == 0)
		tecla = event.keyCode
	else
		tecla =  ch;

	if ((tecla >= 65) && (tecla <= 90)) // LETRAS MAIUSCULAS 
		return true
	else if ((tecla >= 97) && (tecla <= 122)) // LETRAS MINUSCULAS 
		return true
	else if ((tecla >= 48 && tecla <= 57)) // numeros de 0 a 9 
		return true
	else if ((tecla == 8) || (tecla == 13) || (tecla == 45) || (tecla == 46) || (tecla == 64) || (tecla == 95)) // (8) backspace  / (46) . / (95) _ / (45) - / (64) @
		return true
	else 
		return false; 
} 

//*** Formata moeda
function formatCurrency(num, moeda) {
	if (moeda == 'r') {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+'.'+
		num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + 'R$ ' + num + ',' + cents);
	}
	else {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + 'US$ ' + num + '.' + cents);
	}
}

function LTrim(s){
    var i=0;
    var j=0;
    
    for(i=0; i<=s.length-1; i++)
        if(s.substring(i,i+1) != ' '){
            j=i;
            break;
        }
    return s.substring(j, s.length);
}

function RTrim(s){
    var j=0;

    for(var i=s.length-1; i>-1; i--)
        if(s.substring(i,i+1) != ' '){
            j=i;
            break;
        }
    return s.substring(0, j+1);
}

function Trim(s){
    return LTrim(RTrim(s));
}

//*** Controle de layers
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
if ((obj=MM_findObj(objName))!=null) with (obj)
	if (document.layers) {document.write(unescape(newText)); document.close();}
	else innerHTML = unescape(newText);
}
