document.write("<meta http-equiv='Pragma' content='no-cache'>");
document.write("<meta http-equiv='Expires' content='Thu, 01 Jan 1970 00:00:00 GMT'>");
document.write("<meta http-equiv='Cache-Control' content='no-store'>");

function Tecla(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	
	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else
	{
		if (tecla != 8) // backspace
			event.keyCode = 0;
		else
			return true;
	}
}

function MascaraCep(e,cpoCep)
{
	Tecla(e);
	var  strCep=cpoCep.value;
	var  nBytes =strCep.length;
	if((nBytes==5))
	  cpoCep.value=strCep+"-";

	return true;
}	

function MascaraCNPJ(e,cpoCNPJ)
{
	Tecla(e);
	var  strCNPJ=cpoCNPJ.value;
	var  nBytes =strCNPJ.length;
	if((nBytes==2|| nBytes==6))
	  cpoCNPJ.value=strCNPJ+".";
	
	if(nBytes==10)
	  cpoCNPJ.value=strCNPJ+"/";
	 
	if(nBytes==15)
	  cpoCNPJ.value=strCNPJ+"-";
	
	return true;
}

function MascaraCPF(e,cpoCPF)
{
	Tecla(e);
	var  strCPF=cpoCPF.value;
	var  nBytes =strCPF.length;
	if((nBytes==3 || nBytes==7))
	  cpoCPF.value=strCPF+".";
	
	if(nBytes==11)
	  cpoCPF.value=strCPF+"-";
	 
	return true;
}

function MascaraFone(e,cpoFone)
{
	Tecla(e);
	var  strFone=cpoFone.value;
	var  nBytes =strFone.length;
	if((nBytes==4))
	  cpoFone.value=strFone+"-";
	
	return true;
}	

function Maiusculo(strCpo)
{
   strCpo.value=strCpo.value.toUpperCase();
   return true;
}

function Minusculo(strCpo)
{
   strCpo.value=strCpo.value.toLowerCase();
   return true;
}

function MascaraData(e,cpoData)
{
	Tecla(e);
	var  strData=cpoData.value;
	var  nBytes =strData.length;
	if((nBytes==2 || nBytes==5))
	  cpoData.value=strData+"/";
	
	return true;
}

function MascaraPlaca(cpoPlaca)
{
	var  strPlaca=cpoPlaca.value;
	var  nBytes =strPlaca.length;
	if(nBytes==3)
		cpoPlaca.value=strPlaca.toUpperCase()+"-";
	else if(nBytes==9)
		cpoPlaca.value=strPlaca.substr(0,8);
	
	return true;
}

function MascaraHora(cpoHora)
{
	Tecla(e);
	var  strHora=cpoHora.value;
	var  nBytes =strHora.length;
	
	if(nBytes==2)
	{
	   if(cpoHora.value<=24 && cpoHora.value>=0)
		  cpoHora.value=strHora+":";
	   else
	   {
		   alert('Hora inválida!');
		  cpoHora.value="";
		  cpoHora.focus();
	   }
	}
	else if(nBytes==5)
	{
	   vethora=strHora.split(":");
	   minutos=vethora[1];
	   if(parseInt(minutos)>60 || parseInt(minutos)<0)
	   {
		   alert('Hora inválida!');
		  cpoHora.value="";
		  cpoHora.focus();
	   }
	}
	else if(nBytes==6)
	{
	   strHora=strHora.substr(0,5);
	   cpoHora.value=strHora;
	}
	
	return true;
}

function formataReal(ValoraFormatar) {
	Tecla(e);
    var i ;
    var decimalPointDelimiter = ",";
    var posDecPoint = parseInt("");
    var hasDecPoint = false;
    var s = new String(ValoraFormatar);
    var sAux = new String("");

    for (i = 0; i < s.length; i++)
    {   
    	var c = s.charAt(i);
    	if ( c == '.' ) c = decimalPointDelimiter;
	    sAux += c;
      if (c == decimalPointDelimiter){ 
        	  hasDecPoint = true;
        	  posDecPoint = i;
        	  break;}
    }
    for (var j = i+1; j < s.length; j++) sAux += s.charAt(j);
    
    if (!hasDecPoint) //(isNaN(posDecPoint)) 
      {	ValoraFormatar = s + ",00";}
    else
      {	
      	s = sAux + '00';
        ValoraFormatar= s.charAt(0);
        for (i = 1; i <= (posDecPoint+2); i++){ 
            ValoraFormatar += s.charAt(i);}
        if (posDecPoint == 0) ValoraFormatar = '0'+ValoraFormatar;
      }
    s = ValoraFormatar;
    ValoraFormatar = "";
    i=0;

    for (var j=s.length-4; j>=0; j--)
	{
		i++;
		ValoraFormatar = s.charAt(j) + ValoraFormatar;
		if (i == 3 && j != 0)
		{
			ValoraFormatar = "." + ValoraFormatar;
			i = 0;
		}
	}	    	
	ValoraFormatar +=  s.substring(s.length-3,s.length);
	
    return ValoraFormatar;
}

//-----------------------------------------------------
//Funcao: MascaraMoeda
//Sinopse: Mascara de preenchimento de moeda
//Parametro:
//   objTextBox : Objeto (TextBox)
//   SeparadorMilesimo : Caracter separador de milésimos
//   SeparadorDecimal : Caracter separador de decimais
//   e : Evento
//Retorno: Booleano
//Autor: Gabriel Fróes
//Data Criação: 15/02/2005
//-----------------------------------------------------
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e)
{
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '-0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13 || whichCode == 8) 
		return true;
    
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) 
		return false; // Chave inválida

    len = objTextBox.value.length;

    for(i = 0; i < len; i++)
    {
	    if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
			break;
    }
	aux = '';
    
	for(; i < len; i++)
	{
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
			aux += objTextBox.value.charAt(i);
	}
    
	aux += key;
    len = aux.length;
    
	if (len == 0) 
		objTextBox.value = '';
    if (len == 1) 
		objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
		objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) 
	{
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) 
		{
            if (j == 3) 
			{
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function MascaraMoeda2(objTextBox, SeparadorMilesimo, SeparadorDecimal, e,tamanho)
{
	if (tamanho == objTextBox.value.length)
		return false;
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8) 
		return true;
    
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) 
		return false; // Chave inválida

    len = objTextBox.value.length;

    for(i = 0; i < len; i++)
    {
	    if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
			break;
    }
	
	aux = '';
    
	for(; i < len; i++)
	{
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
			aux += objTextBox.value.charAt(i);
	}
    
	aux += key;
    len = aux.length;
    
	if (len == 0) 
		objTextBox.value = '';
    if (len == 1) 
		objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
		objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) 
	{
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) 
		{
            if (j == 3) 
			{
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function mascaraValor(valor)
{
	var aux=0;
	var valorAux="";
	for(i=0;i<valor.length;i++)
	{
		if(valor.charAt(i) == ".")
		{
			aux = i;
			valorAux = valorAux + ",";
		}
		else
			valorAux = valorAux + valor.charAt(i);
	}
	diferenca = parseInt(valor.length) - parseInt(aux);
	if (diferenca == 2)
		valorAux = valorAux + "0";
	
	parteInteira = valorAux.substring(0,aux);
	parteInteiraAux = "";
	cont=0;
	
	if (parteInteira.length > 3)
	{
		
		for(i=parteInteira.length-1;i>=0;i--)
		{
			parteInteiraAux = parteInteiraAux + parteInteira.charAt(i);
			cont++;
			if(cont==3)
			{
				parteInteiraAux = parteInteiraAux + ".";
				cont=0;
			}
		}
		parteInteira = "";
		for(i=parteInteiraAux.length-1;i>=0;i--)
			parteInteira = parteInteira + parteInteiraAux.charAt(i);

		parteDecimal = valorAux.substring(aux,valorAux.length);
		valorAux = parteInteira + parteDecimal;
	}
	return valorAux;
}


function MascaraPorcentagem(objTextBox, SeparadorDecimal, e)
{
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8) 
		return true;
    
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) 
		return false; // Chave inválida

    len = objTextBox.value.length;
	
    for(i = 0; i < len; i++)
    {
	    if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
			break;
    }
	aux = '';
    
	for(; i < len; i++)
	{
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
			aux += objTextBox.value.charAt(i);
	}
    
	aux += key;
    len = aux.length;
    
	if (len == 0) 
		objTextBox.value = '';
    if (len == 1) 
		objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
		objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) 
	{
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) 
		{
            if (j == 3) 
			{
                return false;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

function MascaraPorcentagem2(objTextBox, SeparadorDecimal, e)
{
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13 || whichCode == 8) 
		return true;
    
	key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) 
		return false; // Chave inválida

    len = objTextBox.value.length;
	
    for(i = 0; i < len; i++)
    {
	    if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
			break;
    }
	aux = '';
    
	for(; i < len; i++)
	{
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
			aux += objTextBox.value.charAt(i);
	}
    
	aux += key;
    len = aux.length;
    
	if (len == 0) 
		objTextBox.value = '';
    if (len == 1) 
		objTextBox.value = '0'+ SeparadorDecimal + '000' + aux;
    if (len == 2) 
		objTextBox.value = '0'+ SeparadorDecimal + '00' + aux;

    if (len == 3) 
		objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;

    if (len == 4) 
		objTextBox.value = '0'+ SeparadorDecimal + aux;
	
    if (len > 4) 
	{
        aux2 = '';
        for (j = 0, i = len - 5; i >= 0; i--) 
		{
            if (j == 3) 
			{
                return false;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
		
		objTextBox.value += SeparadorDecimal + aux.substr(len - 4, len);
    }
    return false;
}

