/**
 * @fileoverview
 * Framework Web Petros - Mascaras<br/>
 * <b>Caminho:</b> /RotinasReutilizaveis/javascript/FWP/Mascaras.js
 * @author Fernando Henrique da S N de Souza - C001222
 * @version 06/03/2008 
 */

/**
 * Caminho dos arquivos do FWP
 * @private
 */
	var caminho = "/RotinasReutilizaveis/javascript/FWP/";

/**
 * Inclundo o Calendario
 * @private
 */
	var incCalendario = new String('<script language="javascript" src="'+caminho+'Calendario.js"></script>');
	document.write(incCalendario);

/**
 * Classe ancestral das rotinas Basicas de mascara de campo
 * @class Classe Pai das classes de mascaras 
 */
function MascaraBaseObject(){
  /**
   * Evento do campo 
   * @protected
   */	
  this.event   = null;
  /**
   * Objeto Campo de tratamento da mascara
   * @protected
   */	
  this.campo   = null;
  /**
   * Mascara que sera aplicada no campo
   * @protected
   */	
  this.mascara = null;
  /**
   * ???
   * @protected
   */	
  this.valido = true;
  /**
   * Pega o codigo da tecla acionada no event
   * @protected
   * @method 
   */	
  this.pegarKeyCode = function(){
   
    var keyCode = this.event.keyCode ? this.event.keyCode :
                              this.event.charCode ? this.event.charCode :
                                              this.event.which ? this.event.which : void 0;
    return keyCode;
  }
  /**
   * Colocando o evento de OnKeyPress no campo 
   * @protected
   * @method 
   */	
  this.teclasEspeciais = function(keyCode){
  	return (keyCode != 8) && (keyCode != 9) && (keyCode != 37) && (keyCode != 39) && (keyCode != 46);
  }
  
  /**
   * Colocando o evento de OnKeyPress no campo 
   * @protected
   * @method 
   */	
  this.setOnKeyPress = function(){ // Colocando o Evendo no objeto
    this.campo.oldKeyPress = this.campo.onkeypress;
    this.campo.onkeypress = function(e){
      this.mask.event = e ? e : window.event;
      this.mask.execOnKeyPress();
      if(this.oldKeyPress)
        this.oldKeyPress(e);
    }  
  }

  /**
   * Valida as teclas de entrada no campo
   * @protected
   * @method 
   */	
  this.validaKeyPress = function (keyCode, boolCancel){
    
    if (keyCode && window.event && !window.opera) {  // INTERNET EXPLORER
      // Cancelando o Evento keyPress
      if (boolCancel) {
        this.event.returnValue = false; 
        return false;
      }
    }else{ // MOZILLA
      if(this.event.keyCode==9 || (this.event.keyCode==37) || (this.event.keyCode==39) ||(this.event.keyCode==46) || this.event.keyCode==8){
        return true;
      }
      // Cancelando o Evento keyPress
      if (boolCancel){  
        if (this.event.preventDefault) {
          this.event.preventDefault();
        }
        return false;
      }else{
        return true;
      } 
    }
  }
  /**
   * Executando o tramento da Mascara no campo
   * @protected
   * @method 
   */	
  this.execOnKeyPress = function(){
    var keyCode = this.pegarKeyCode(this.event);
    var key = String.fromCharCode(keyCode);
    var boolCancel = this.mascara.indexOf(key) == -1;
    this.validaKeyPress(keyCode, boolCancel);
  }
  /**
   * Pega o objeto campo
   * @protected
   * @method 
   */	
  this.instaceCampo = function(IdCampo){
    if(typeof(IdCampo) == "string"){
      this.campo = document.getElementById(IdCampo);
      if(!this.campo){
        alert("Campo '"+IdCampo+"' não encontrado.");
        return false;
      }
    }else{
      this.campo = IdCampo;
    }
  }  
  
}

  
/**
 * Classe para mascara de data
 * @class Classe para adicionar mascara de Data em um campo
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraData&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraData.byId('meu_campo');
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo');  
 *        MascaraData.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraData.byId('meu_campo');
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */
function MascaraData(IdCampo){
  /**
   * Mascara do campo 
   * @private
   */	
  this.mascara = "0123456789";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;
  /** @private */
  this.btn = document.createElement("input");
  /** @private */
  this.calenario = new Calendario();
  this.btn.calenario = this.calenario;
  this.btn.campo = this.campo;
  
  with (this.btn) {
  	type  = "image";
  	src   = caminho + "calendar.png";
  	value = "Calendário";
	style.position = "absolute";
	var x = 0 , y = 0;
	
	if( this.campo.parentNode.tagName.toLowerCase() == "td"){
		var node = this.campo.parentNode;
		while(node.tagName.toLowerCase() != "body"){
			if(node.tagName.toLowerCase() == "table" || 
			   node.tagName.toLowerCase() == "td" || 
			   node.tagName.toLowerCase() == "div" || 
			   node.tagName.toLowerCase() == "span"){
				x += node.offsetLeft;
				y += node.offsetTop;
			}
			node = node.parentNode;
		}
		x = (((this.campo.clientWidth + this.campo.offsetLeft) - 14) + x) + "px";
		y = (y + this.campo.offsetTop + 2 ) + "px";
	}else{
		x = ((this.campo.clientWidth - 16) + this.campo.offsetLeft) + "px";
		y = (this.campo.offsetTop + 2) + "px";
	}
	style.left = x;
	style.top  = y;
  	style.border = "0px solid black";
  }
  /** @private */
  this.btn.onclick = function(){
  	if(this.campo.readOnly) return false;
	
	this.calenario.setPosition(this.offsetLeft + "px",this.offsetTop + "px");
	this.calenario.setData(this.campo.value);
	this.calenario.campo = this.campo;
	this.calenario.onClickData = function(){
		this.campo.value = this.pegaData();
		this.esconder();
	}
	this.calenario.show();
  }
  this.campo.parentNode.appendChild(this.btn) ;
  /**
   * Informa que terar calendario ou não 
   * @public
   */	
  this.setCalendario = function(bol){
  	if(bol){
		this.btn.style.display = "inline";
	}else{
		this.btn.style.display = "none";
		
	}
  }
  this.setCalendario(false);
  /**
   * Informando o evento OnBlur para o campo tratado 
   * @method 
   * @return {void}
   */	
  this.campo.onblur = function(){
  	if(this.value == "") return false;
	var dia = Number(this.value.substr(0,2)); 
	var mes = Number(this.value.substr(3,2)) - 1; // O mês começa como 0 (zero)
	var ano = Number(this.value.substr(6,4));
	var xdata = new Date(ano, mes, dia); 
	
	if(dia != xdata.getDate() || mes != xdata.getMonth() || ano != xdata.getFullYear()){
		alert('data invalida');
		this.focus();
	}
  }
  /**
   * Informando a quantidade de caracteres a ser digitado no campo
   * @method 
   * @private
   */
  this.campo.maxLength = 10;
  /**
   * Colocando o Evendo no objeto
   * @method 
   * @private
   */
  this.setOnKeyPress(); 
  /**
   * Executando o tramento da Mascara no campo
   * @protected
   * @method 
   */
  this.execOnKeyPress = function(){
    var keyCode = this.pegarKeyCode(this.event);
    var key = String.fromCharCode(keyCode);
    var boolCancel = this.mascara.indexOf(key) == -1;
    if(this.teclasEspeciais(keyCode) && (this.campo.value.length == 2 || this.campo.value.length == 5)){
        this.campo.value += "/";
    }
    this.validaKeyPress(keyCode, boolCancel);
  }
}
  MascaraData.prototype = new MascaraBaseObject(); 

  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraData}
   */
  MascaraData.byId = function(id){
    var result = new MascaraData(id);
    return result;
  }

  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraData}
   */
  MascaraData.byObject = function(obj){
    var result = new MascaraData(obj);
    return result;
  }
  
/**
 * Classe para mascara de Numero
 * @class Classe para adicionar mascara de número em um campo
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraNumerico&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraNumerico.byId('meu_campo');
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo');  
 *        MascaraNumerico.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraNumerico.byId('meu_campo');
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */
function MascaraNumerico(IdCampo){
  /**
   * Mascara do campo 
   * @private
   */	
  this.mascara = "0123456789";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  this.campo.mask = this;
  this.campo.style.textAlign = "right";
  this.setOnKeyPress(); // Colocando o Evendo no objeto
}
  MascaraNumerico.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject 
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraNumerico}
   */
  MascaraNumerico.byId = function(id){
    var result = new MascaraNumerico(id);
    return result;
  }
  
  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraNumerico}
   */
  MascaraNumerico.byObject = function(obj){
    var result = new MascaraNumerico(obj);
    return result;
  }

/**
 * Classe para mascara valor
 * @class Classe para adicionar mascara de moeda em um campo
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraValor&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraValor.byId('meu_campo');
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo');  
 *        MascaraValor.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraValor.byId('meu_campo');
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */
function MascaraValor(IdCampo){
  /**
   * Informa o caracter separador de decimal   
   * @public
   */
   
   
  
  this.separadorDecimal = ",";
  /**
   * informando o caracter separador de Milesimo
   * @public
   */	
  this.separadorMilesimo = ".";	
  /**
   * informando a mascara de valor 
   * @private
   */	
  this.mascara = "0123456789";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;

  this.campo.style.textAlign = "right";
  this.setOnKeyPress(); // Colocando o Evendo no objeto
  /**
   * Funcionalidade para retirar o ponto de milesimo do campo 
   * @public
   * @method retirarSeparadorMilesimo
   * @return {void} 
   */	
  this.retirarSeparadorMilesimo = function() {
	while (this.campo.value.indexOf(this.separadorMilesimo)>-1)
		this.campo.value = this.campo.value.toString().replace(this.separadorMilesimo,'');
  }
  /**
   * Retorna o valor do campo sem formatação e a separação da casa decimal em ponto "."
   * @return {Number}
   */
  this.getValue = function(){
  	var valor = this.campo.value;
	while (valor.indexOf(this.separadorMilesimo)>-1)
		valor = valor.replace(this.separadorMilesimo,'');
	if(this.separadorDecimal == ","){
		valor = valor.replace(this.separadorDecimal,'.');
	}
	return parseFloat(valor);
  }
  /**
   * Informa o valor para o campo e visualiza o valor formatado. 
   * @example
   * mask.setValue(2000.50);
   * @param {Number} vlr Novo Valor
   */
  this.setValue = function(vlr){
  	this.campo.value = vlr;
	var decimal;
	var numero;
	if(this.campo.value.indexOf(".") == -1){
		decimal = "00";
		numero = new String(this.campo.value); 	
	}else{
		decimal = new String(this.campo.value.substr(this.campo.value.length - 2, 2));
		numero  = new String(this.campo.value.substr(0,(this.campo.value.length - 3))); 
	}
	var position = 0;
	var aux = "";
 	for(var i = numero.length - 1; i > -1; i--){
		if (position == 3) {
		position = 1;
		aux = numero.substr(i,1) + this.separadorMilesimo + aux;
		}else{
			position += 1;
			aux = numero.substr(i,1) + aux;
		}
	}
	this.campo.value = aux + this.separadorDecimal + decimal;
  }
  /**
   * Executando o tramento da Mascara no campo
   * @public
   * @method retirarPontos
   */	
  this.execOnKeyPress = function(){
    if(this.campo.readOnly) return false;
    if(this.separadorDecimal == this.separadorMilesimo){
		alert("A configuração dos separadores esta igual.");
		return false;
	}
	var i = j = 0;
    var len = len2 = 0;
    var aux = aux2 = '';
	var keyCode = this.pegarKeyCode(this.event);
	var key = String.fromCharCode(keyCode);
	var boolCancel = this.mascara.indexOf(key) == -1;
	this.validaKeyPress(keyCode, boolCancel);
	if (boolCancel) 
		return false; // chave invalida de acordo com a mascara
	var boolCancel = true;
	this.validaKeyPress(keyCode, boolCancel);
    len = this.campo.value.length;
    for(i = 0; i < len; i++)
        if ((this.campo.value.charAt(i) != '0') && (this.campo.value.charAt(i) != this.separadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (this.mascara.indexOf(this.campo.value.charAt(i))!=-1) aux += this.campo.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) this.campo.value = '';
    if (len == 1) this.campo.value = '0'+ this.separadorDecimal + '0' + aux;
    if (len == 2) this.campo.value = '0'+ this.separadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += this.separadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        this.campo.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        this.campo.value += aux2.charAt(i);
        this.campo.value += this.separadorDecimal + aux.substr(len - 2, len);
    }
    return false;
  }
}
  MascaraValor.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject 
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraValor}
   */
  MascaraValor.byId = function(id){
    var result = new MascaraValor(id);
    return result;
  }

  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraValor}
   */
  MascaraValor.byObject = function(obj){
    var result = new MascaraValor(obj);
    return result;
  }

/**
 * Classe para mascara de somente texto
 * @class Classe para adicionar mascara de somente Texto  em um campo
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraTexto&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraTexto.byId('meu_campo'); // como padrão, caracteres sem acento
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo'); 
 *        MascaraTexto.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraTexto.byId('meu_campo');
 *      ObjetoMascara.acentos = true; // Informa se vai ter acento 
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */
/*---inicio--20-04-2011--anderson--*/

function converte(item){


var nova="";
for (i=0; i<item.length; i++){
if (item.substr(i,1)!="."){
if(item.substr(i,1)==","){
nova+=".";
}else{
nova+=item.substr(i,1);
}
}
}

nova = parseFloat(nova);

return nova;
}

function converteString(item){


var nova="";
for (i=0; i<item.length; i++){
if (item.substr(i,1)!="."){
if(item.substr(i,1)==","){
nova+=",";
}else{
nova+=item.substr(i,1);
}
}
}

//nova = parseFloat(nova);

return nova;
}

function MascaraValorValidacao(IdCampo){
  /**
   * Informa o caracter separador de decimal   
   * @public
   */	

  this.separadorDecimal = ".";
  /**
   * informando o caracter separador de Milesimo
   * @public
   */	
  this.separadorMilesimo = "";	
  /**
   * informando a mascara de valor 
   * @private
   */	
  this.mascara = "0123456789";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;

  this.campo.style.textAlign = "right";
  this.setOnKeyPress(); // Colocando o Evendo no objeto
  /**
   * Funcionalidade para retirar o ponto de milesimo do campo 
   * @public
   * @method retirarSeparadorMilesimo
   * @return {void} 
   */	
  this.retirarSeparadorMilesimo = function() {
	while (this.campo.value.indexOf(this.separadorMilesimo)>-1)
		this.campo.value = this.campo.value.toString().replace(this.separadorMilesimo,'');
  }
  /**
   * Retorna o valor do campo sem formatação e a separação da casa decimal em ponto "."
   * @return {Number}
   */
  this.getValue = function(){
  	var valor = this.campo.value;
	while (valor.indexOf(this.separadorMilesimo)>-1)
		valor = valor.replace(this.separadorMilesimo,'');
	if(this.separadorDecimal == ","){
		valor = valor.replace(this.separadorDecimal,'.');
	}
	return parseFloat(valor);
  }
  /**
   * Informa o valor para o campo e visualiza o valor formatado. 
   * @example
   * mask.setValue(2000.50);
   * @param {Number} vlr Novo Valor
   */
  this.setValue = function(vlr){
  	this.campo.value = vlr;
	var decimal;
	var numero;
	if(this.campo.value.indexOf(".") == -1){
		decimal = "00";
		numero = new String(this.campo.value); 	
	}else{
		decimal = new String(this.campo.value.substr(this.campo.value.length - 2, 2));
		numero  = new String(this.campo.value.substr(0,(this.campo.value.length - 3))); 
	}
	var position = 0;
	var aux = "";
 	for(var i = numero.length - 1; i > -1; i--){
		if (position == 3) {
		position = 1;
		aux = numero.substr(i,1) + this.separadorMilesimo + aux;
		}else{
			position += 1;
			aux = numero.substr(i,1) + aux;
		}
	}
	this.campo.value = aux + this.separadorDecimal + decimal;
  }
  /**
   * Executando o tramento da Mascara no campo
   * @public
   * @method retirarPontos
   */	
  this.execOnKeyPress = function(){
    if(this.campo.readOnly) return false;
    if(this.separadorDecimal == this.separadorMilesimo){
		alert("A configuração dos separadores esta igual.");
		return false;
	}
	var i = j = 0;
    var len = len2 = 0;
    var aux = aux2 = '';
	var keyCode = this.pegarKeyCode(this.event);
	var key = String.fromCharCode(keyCode);
	var boolCancel = this.mascara.indexOf(key) == -1;
	this.validaKeyPress(keyCode, boolCancel);
	if (boolCancel) 
		return false; // chave invalida de acordo com a mascara
	var boolCancel = true;
	this.validaKeyPress(keyCode, boolCancel);
    len = this.campo.value.length;
    for(i = 0; i < len; i++)
        if ((this.campo.value.charAt(i) != '0') && (this.campo.value.charAt(i) != this.separadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (this.mascara.indexOf(this.campo.value.charAt(i))!=-1) aux += this.campo.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) this.campo.value = '';
    if (len == 1) this.campo.value = '0'+ this.separadorDecimal + '0' + aux;
    if (len == 2) this.campo.value = '0'+ this.separadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += this.separadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        this.campo.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        this.campo.value += aux2.charAt(i);
        this.campo.value += this.separadorDecimal + aux.substr(len - 2, len);
    }
    return false;
  }
}
  MascaraValorValidacao.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject 
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraValorValidacao}
   */
  MascaraValorValidacao.byId = function(id){
    var result = new MascaraValorValidacao(id);
    return result;
  }

  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraValorValidacao}
   */
  MascaraValorValidacao.byObject = function(obj){
    var result = new MascaraValorValidacao(obj);
    return result;
  }

/**
 * Classe para mascara de somente texto
 * @class Classe para adicionar mascara de somente Texto  em um campo
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraTexto&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraTexto.byId('meu_campo'); // como padrão, caracteres sem acento
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo'); 
 *        MascaraTexto.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraTexto.byId('meu_campo');
 *      ObjetoMascara.acentos = true; // Informa se vai ter acento 
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */





/*----fim----*/
function MascaraTexto(IdCampo){
  /**
   * Propriedade para informar o campo se tera texto com acento. Por padrão é False. 
   * @public
   */	
  this.acentos = false;
  /**
   * Mascara dos caracteres natureais 
   * @private
   */	
  this.mascaraN  = "qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM";
  /**
   * Mascara dos caracteres com acento 
   * @private
   */	
  this.mascaraA  = "áàâãÁÀÂÃéêÉÊíÍóôõÓÔÕúÚçÇ";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;
  /**
   * Executando o tramento da Mascara no campo
   * @protected
   * @method 
   */	
  this.execOnKeyPress = function(){
	var keyCode = this.pegarKeyCode(this.event);
	var key = String.fromCharCode(keyCode);
	if(this.acentos){
		this.mascara = this.mascaraN + this.mascaraA;
	}else{
		this.mascara = this.mascaraN;
	}
	var boolCancel = this.mascara.indexOf(key) == -1;
    this.validaKeyPress(keyCode, boolCancel);
  }
  this.setOnKeyPress(); // Colocando o Evendo no objeto
}
  MascaraTexto.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject  
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraTexto}
   */
  MascaraTexto.byId = function(id){
    var obj = new MascaraTexto(id);
    return obj;
  }

   /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraTexto}
   */
 MascaraTexto.byObject = function(obj){
    var result = new MascaraTexto(obj);
    return result;
  }


/**
 * Classe para mascara de CPF
 * @class Classe para adicionar mascara e validar o CPF
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraCPF&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraCPF.byId('meu_campo');
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo');  
 *        MascaraCPF.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraCPF.byId('meu_campo');
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */
function MascaraCPF(IdCampo){
  this.mascara  = "1234567890";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;
  this.campo.maxLength = 12;
  this.setOnKeyPress(); // Colocando o Evendo no objeto
  /**
   * Executando o tramento da Mascara no campo
   * @protected
   * @method 
   */	
  this.execOnKeyPress = function(){
    var keyCode = this.pegarKeyCode(this.event);
    var key = String.fromCharCode(keyCode);
    var boolCancel = this.mascara.indexOf(key) == -1;
    if(this.campo.value.length == 9){
      if(this.teclasEspeciais(keyCode))
        this.campo.value += "-";
    }
    this.validaKeyPress(keyCode, boolCancel);
  }
}
  MascaraCPF.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraCPF}
   */
  MascaraCPF.byId = function(id){
    var result = new MascaraCPF(id);
    return result;
  }

  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraCPF}
   */
  MascaraCPF.byObject = function(obj){
    var result = new MascaraCPF(obj);
    return result;
  }

/**
 * Classe para mascara de CEP
 * @class Classe para adicionar mascara e validar o CEP
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraCEP&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraCEP.byId('meu_campo');
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo');  
 *        MascaraCEP.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraCEP.byId('meu_campo');
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */

function MascaraCEP(IdCampo){
  this.mascara  = "1234567890";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;
  this.campo.maxLength = 9;
  this.setOnKeyPress(); // Colocando o Evendo no objeto

  /**
   * Executando o tramento da Mascara no campo
   * @protected
   * @method 
   */	
  this.execOnKeyPress = function(){
    var keyCode = this.pegarKeyCode(this.event);
    var key = String.fromCharCode(keyCode);
    var boolCancel = this.mascara.indexOf(key) == -1;
    if(this.campo.value.length == 5){
      if(this.teclasEspeciais(keyCode))
        this.campo.value += "-";
    }
    this.validaKeyPress(keyCode, boolCancel);
  }
}
  MascaraCEP.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraCEP}
   */
  MascaraCEP.byId = function(id){
    var result = new MascaraCEP(id);
    return result;
  }

  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraCEP}
   */
 MascaraCEP.byObject = function(obj){
    var result = new MascaraCEP(obj);
    return result;
  }
  
/**
 * Classe para mascara de Email
 * @class  Classe para validar o E-mail 
 * @extends MascaraBaseObject
 * @example
 * Exemplo de como utilizar:
 *&lt;html&gt;
 *  &lt;head&gt;
 *    &lt;title&gt;Exemplo de MascaraEmail&lt;/title&gt;
 *    &lt;script language=&quot;javascript&quot; src=&quot;/RotinasReutilizaveis/javascript/FWP/Mascaras.js&quot;&gt;&lt;/script&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        MascaraEmail.byId('meu_campo');
 *      }  
 *     &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *        var campo = document.getElementById('meu_campo');  
 *        MascaraEmail.byObject(campo);
 *      }  
 *    &lt;/script&gt;
 *     &lt;!-- OU --&gt;
 *    &lt;script language=&quot;javascript&quot;&gt;
 *      window.onload = function(){
 *      // Pegando o objeto Mascara 
 *      var ObjetoMascara = MascaraEmail.byId('meu_campo');
 *      }  
 *    &lt;/script&gt;
 *  &lt;/head&gt;
 *  &lt;body&gt;
 *    &lt;input type=&quot;text&quot; name=&quot;meu_campo&quot; id=&quot;meu_campo&quot;/&gt;
 *  &lt;/body&gt;
 *&lt;/html&gt;
 * 
 */

function MascaraEmail(IdCampo){
  /**
   * informando a mascara do campo 
   * @private
   */	
  this.mascara  = "1234567890";
  this.mascara += "qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM";
  this.mascara += "@.";
  /**
   * informando o campo a ser tratado 
   * @private
   */	
  this.instaceCampo(IdCampo);
  /**
   * Repassando a propria classe para o campo tratado 
   * @private
   */	
  this.campo.mask = this;
  this.campo.maxLength = 200;
  this.setOnKeyPress(); // Colocando o Evendo no objeto
  /**
   * Validando a informação do campo ao sair 
   * @private
   * @method
   * @return {void}
   */
  this.campo.onblur = function(){
  	if(this.value == "") return false;
	if(this.value.indexOf("@") > -1){
		return true;
	}else{
		alert('Email inválido!');
		this.focus();
		return false;
	}
  }
}
  MascaraEmail.prototype = new MascaraBaseObject(); // Herdando da class MascaraBaseObject
  /**
   * Gera a mascara de acordo com o ID do campo 
   * @public
   * @method 
   * @static 
   * @param {String} id
   * @return {MascaraEmail}
   */
  MascaraEmail.byId = function(id){
    var result = new MascaraEmail(id);
    return result;
  }

  /**
   * Gera a mascara de acordo com o Objeto do campo 
   * @public
   * @method
   * @static 
   * @param {Object} Obj
   * @return {MascaraEmail}
   */
 MascaraEmail.byObject = function(obj){
    var result = new MascaraEmail(obj);
    return result;
  }
