/*--------------------------------------------------------------------------------
Objetivo: Framework JS  
Criação: Leandro Elias
Data de Criação: 15/03/2005     Data da ultima modificação: 02/02/2007
--------------------------------------------------------------------------------*/
function LEBJSFrameWork( _strConteudoInicial ){
    /*----------------------------------------------------------------------------
    Declaração de Constantes;
    -----------------------------------------------------------------------------*/
    var cstTipoData = "Data";
    var cstTipoTexto = "Texto";
    var cstTipoMemorando = "Memorando";
    var cstTipoNumero = "Número"
    var cstTipoDocumento = "Documento";
    var cstTipoObjeto = "Objeto"
    var cstTipoMoeda = "Moeda"
    var cstTipoIndefinido = null;
    
    /*----------------------------------------------------------------------------
    Declaração de Propriedades;
    -----------------------------------------------------------------------------*/
    this.Value = (( _strConteudoInicial != null )? _strConteudoInicial : "" );
    
    /*----------------------------------------------------------------------------
    Declaração de Méthodos;
    -----------------------------------------------------------------------------*/
    //Retorna true se o conteudo for vazio ou nulo
    this.IsEmpty = function(){ 
        return this.pIsEmpty( this.Value );
    }
    this.pIsEmpty = function( _strConteudo ){ 
        var blnRetorno = false;
        try{
            blnRetorno = ( _strConteudo == null || _strConteudo == '' || this.pLength(_strConteudo) == 0 )? true : false; 
        }catch(e){
        }finally{
            return blnRetorno;
        }
    }
    
    //Retorna true se o contéudo for um CPF
    this.IsCPF = function(){
        return this.pIsCPF( this.Value );
    }
    this.pIsCPF = function( _strConteudo, _blnRemoverMascara ){
        var blnRetorno = false;
        //Preenchendo parametro opcional
        _blnRemoverMascara = ( _blnRemoverMascara != true ) ? false: true;
        
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            if( _blnRemoverMascara ){
                _strConteudo = this.pOnlyNumber(_strConteudo);
            }
            if( _strConteudo.length == 11 ){
                var strItemNegado = "";
                for( var i=1; i <= 9; i++ ){
                    strItemNegado = "";
                    for( var j=1; j <= 11; j++ ){                        
                        strItemNegado += i.toString(); 
                    } 
                    if( _strConteudo == strItemNegado ){
                        return blnRetorno;
                        break;
                    }
                }
                var strParte1 = _strConteudo.substring(0, 9);
                var strParte2 = _strConteudo.substring(9, 11);
                var dblSoma = 0;
                var dblDigito1 = 0;
                var dblDigito2 = 0;
                for( var i=0; i <= strParte1.length; i++ ){
                    dblSoma += strParte1.substring(i, i+1 ) * (11 - (i+1) );
                }
                dblSoma *= 10;
                dblDigito1 = ((dblSoma % 11)== 10)? 0: dblSoma % 11;
                strParte1 = strParte1 + parseInt(dblDigito1);
                
                dblSoma = 0;
                for( var i=0; i <= strParte1.length; i++ ){
                    dblSoma += strParte1.substring(i, i+1 ) * (12 - (i+1) );
                }
                
                dblSoma *= 10;
                dblDigito2 = ((dblSoma % 11)== 10)? 0: dblSoma % 11;
                if( strParte2.substring(0,1) == dblDigito1.toString() && strParte2.substring(1,2) == dblDigito2.toString() ){
                    blnRetorno = true;
                }
            }
            
        }catch(e){
        }finally{
            return blnRetorno;
        }
    }

    //Retorna true se o contéudo for um CNPJ
    this.IsCNPJ = function(){
        return this.pIsCNPJ( this.Value );
    }
    this.pIsCNPJ = function( _strConteudo ){
        var blnRetorno = false;
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = this.pOnlyNumber( _strConteudo );
            if( _strConteudo.length == 14 ){
                var strFluxo = "543298765432";
                var strParte1 = _strConteudo;
                var strParte2 = _strConteudo.substring(12, 14);
                var dblSoma = 0;
                var dblDigito1 = 0;
                var dblDigito2 = 0;
                
                for( var i=0; i <= strParte1.length; i++ ){
                    dblSoma += strParte1.substring(i, i+1 ) * strFluxo.substring(i, i+1 );
                }
                dblSoma *= 10;
                dblDigito1 = ((dblSoma % 11)== 10)? 0: dblSoma % 11;
                strParte1 = strParte1 + parseInt(dblDigito1);
                
                dblSoma = 0;
                strFluxo = "6543298765432";
                for( var i=0; i <= strParte1.length; i++ ){
                    dblSoma += strParte1.substring(i, i+1 ) * strFluxo.substring(i, i+1 );
                }
                
                dblSoma *= 10;
                dblDigito2 = ((dblSoma % 11)== 10)? 0: dblSoma % 11;
                if( strParte2.substring(0,1) == dblDigito1.toString() && strParte2.substring(1,2) == dblDigito2.toString() ){
                    blnRetorno = true;
                }
            }
        }catch(e){
        }finally{
            return blnRetorno;
        }
    
    }
    //Retorna true se for uma data
    this.IsDate = function(){
        return this.pIsDate( this.Value );
    }
    this.pIsDate = function( _strConteudo ) {
        var blnRetorno = false;
        try { 
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            if( _strConteudo.indexOf("/") != -1 ){
                var arrConteudoData = _strConteudo.split("/");
                
                var intDiaInformado = parseFloat(arrConteudoData[0]);
                var intMesInformado = parseFloat(arrConteudoData[1]);
                var intAnoInformado = parseFloat(arrConteudoData[2]);
                
                //Início - Verificação para ano bisexto
		        var intUltimoDiaFevereiro = 28;
		        if(intMesInformado == 2) {
			        if(intAnoInformado%400 == 0) {
				        intUltimoDiaFevereiro = 29;
			        }
			        else {
				        if(intAnoInformado%4 == 0 && intAnoInformado%100 != 0) {
                            intUltimoDiaFevereiro = 29;
	    		        }
			        }
		        }
		        //Fim - Verificação para ano bisexto
		        
		        var arrUltimoDia = new Array(11);
		        arrUltimoDia[0] = 31;
		        arrUltimoDia[1] = intUltimoDiaFevereiro;
		        arrUltimoDia[2] = 31;
		        arrUltimoDia[3] = 30;
		        arrUltimoDia[4] = 31;
		        arrUltimoDia[5] = 30;
		        arrUltimoDia[6] = 31;
		        arrUltimoDia[7] = 31;
		        arrUltimoDia[8] = 30;
		        arrUltimoDia[9] = 31;
		        arrUltimoDia[10] = 30;
		        arrUltimoDia[11] = 31;

                if( arrConteudoData.length > 2 ) {
                    if( intDiaInformado > 0 && intDiaInformado <= arrUltimoDia[parseFloat(intMesInformado - 1)] &&	
                        intMesInformado > 0 && intMesInformado <= 12 &&
                        intAnoInformado > 1800 ) {
                        var objData = new Date();
                        objData.setFullYear(intAnoInformado, parseFloat(intMesInformado - 1), intDiaInformado);
                        if( this.pIsNumeric(objData.getDate()) && this.pIsNumeric(objData.getMonth()) && this.pIsNumeric(objData.getFullYear()) ) {
                            blnRetorno = true;
                        }
                    }
                }
            }
        }catch(e){
        }finally{
            return blnRetorno;
        }
    }
    
    //Retorna true se o contéudo form um e-mail válido
    this.IsEmail = function(){
        return this.pIsEmail( this.Value );
    }
    this.pIsEmail = function( _strConteudo ){
        var blnRetorno = false;
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            blnRetorno = /^([\w\.\-])+\@(([\w\-])+\.)+([\w ]{2,4})$/.test( _strConteudo );
        }catch(e){
            this.Message(e);
        }finally{
            return blnRetorno;
        }
    }
    
    //Retorna true se o conteudo for numérico
    this.IsNumeric = function( ){
        return this.pIsNumeric( this.Value );
    }        
    this.pIsNumeric = function( _strConteudo ){
        var blnRetorno = false;
        try{
            if( typeof _strConteudo == "number" || ( ! isNaN( _strConteudo ) && ! this.pIsEmpty( _strConteudo ) ) ){
                blnRetorno = true;
            }
        }catch(e){
        }finally{
            return blnRetorno;
        }
    }
    
    //Retorna true se o conteudo for objeto
    this.IsObject = function(){
        return this.pIsObject( this.Value );
    }
    this.pIsObject = function( _strConteudo ){
        var blnRetorno = false;
        try{
            blnRetorno = (typeof _strConteudo == "object" );
        }catch(e){
        }finally{
            return blnRetorno;
        }
    }
    
    //Retorna true se o conteudo for uma função
    this.IsFunction = function(){
        return this.pIsFunction( this.Value );
    }
    this.pIsFunction = function( _strConteudo ){
        var blnRetorno = false;
        try{
            blnRetorno = (typeof _strConteudo == "function" );
        }catch(e){
        }finally{
            return blnRetorno;
        }
    }

    //Função para formatar o conteudo como data
    this.FormatDate = function(){
		this.Value = this.pFormatDate( this.Value );
		return this;
	}
    this.pFormatDate = function( _strConteudo ){
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            if( this.pIsDate( _strConteudo ) ){
                var strConteudoData = _strConteudo.split("/");
                strConteudoData[0] = new LEBFrameWork("0" + strConteudoData[0]).Right(2);
                strConteudoData[1] = new LEBFrameWork("0" + strConteudoData[1]).Right(2);
                _strConteudo = strConteudoData[0] + "/" + strConteudoData[1] + "/" + strConteudoData[2];
            }
        }catch(e){ 
            this.Message(e); 
        }finally{ 
            return _strConteudo; 
        }
    }
    
    //Retorna o tipo do conteudo
    this.GetType = function(){
        return this.pGetType( this.toString() );
    }
    this.pGetType = function( _strConteudo ){
        var strTipoRetorno = cstTipoIndefinido;
        try{
            if( this.pIsDate( _strConteudo ) ){
                strTipoRetorno = cstTipoData;
            }else if( this.pIsCPF( _strConteudo ) || this.pIsCNPJ( _strConteudo ) ){
                strTipoRetorno = cstTipoDocumento;
            }else if( this.pIsNumeric( _strConteudo ) ){
                strTipoRetorno = cstTipoNumero;
            }else if( this.pIsObject( _strConteudo ) ){
                strTipoRetorno = cstTipoObjeto;
            }else{
                strTipoRetorno = cstTipoTexto;
            }
        }catch(e){
            this.Message(e);
        }finally{
            return strTipoRetorno;
        }
    }


    //Retorna o contéudo decodificado do padrão HTML
    this.HTMLDecode = function(){
        this.Value = this.pHTMLDecode( this.toString() );
        return this;
    }
    this.pHTMLDecode = function( _strConteudo ){
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.replace(/&quot;/g, String.fromCharCode(34));
            _strConteudo = _strConteudo.replace(/&lt;/g  , String.fromCharCode(60));
            _strConteudo = _strConteudo.replace(/&gt;/g  , String.fromCharCode(62));
            _strConteudo = _strConteudo.replace(/&amp;/g , String.fromCharCode(38));
            _strConteudo = _strConteudo.replace(/&nbsp;/g, String.fromCharCode(32));
            for (var i=192; i <= 255; i++){
	            strRegExp = new RegExp("&#" + i + ";","g");
	            _strConteudo = _strConteudo.replace(strRegExp, String.fromCharCode(i));
            }
        }catch(e){
            this.Message(e);	        
        }finally{
            return _strConteudo;
        }
    }
    
    //Retorna o conteudo codificado no padrão HTML
    this.HTMLEncode = function(){
        this.Value = this.pHTMLEncode( this.toString() );
        return this;
    }
    this.pHTMLEncode = function( _strConteudo ){
        try{                
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            var strRegExp = "";

            strRegExp = new RegExp(String.fromCharCode(38), "g");
            _strConteudo = _strConteudo.replace(strRegExp, "&amp;" );

            strRegExp = new RegExp(String.fromCharCode(34), "g");
            _strConteudo = _strConteudo.replace(strRegExp, "&quot;" );

            strRegExp = new RegExp(String.fromCharCode(60), "g");
            _strConteudo = _strConteudo.replace(strRegExp, "&lt;" );

            strRegExp = new RegExp(String.fromCharCode(62), "g");
            _strConteudo = _strConteudo.replace(strRegExp, "&gt;" );

            strRegExp = new RegExp(String.fromCharCode(32), "g");
            _strConteudo = _strConteudo.replace(strRegExp, "&nbsp;" );

            for ( var i=192; i <= 255; i++ ){
                strRegExp = new RegExp(String.fromCharCode(i), "g");
                _strConteudo = _strConteudo.replace(strRegExp, "&#" + i + ";" );
            }
        }catch(e){
            this.Message(e);	        
        }finally{
            return _strConteudo;
        }
    }

    //Retorna uma quantidade x de caracteres a esquerda do conteudo;
    //_Quantidade --> Quantidade de carateres a ser capturado
    this.Left = function( _Quantidade ){ 
        this.Value = this.pLeft( this.toString(), _Quantidade );
        return this;
    }
    this.pLeft = function( _strConteudo, _Quantidade ){ 
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.substring(0,_Quantidade);
        }catch(e){
            this.Message(e);
        }finally{                
            return _strConteudo; 
        }
    }

    //Retorna o Tamanho do conteudo;
    this.Length = function( ){ 
        return this.pLength( this.toString() );
    }
    this.pLength = function( _strConteudo ){ 
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.toString();
            return _strConteudo.length;
        }catch(e){
            return 0;
        }                 
    }

    //Exibe uma Messagem como alert
    this.Message = function(_strMessagem){
        var strMessagem = "";
        if( _strMessagem ){
            alert( "Mensagem: " + _strMessagem.message );
        }else{
            alert(_strMessagem); 
        }
    }

    //Retorna o conteudo entre Inicio e Fim
    //_Inicio --> Define o ínicio do conteudo que será capturado
    //_Fim --> Define o Fim do conteudo que será capturado
    this.Mid = function( _Inicio, _Fim, _blnQuantiade ){
        this.Value = this.pMid( this.toString(), _Inicio, _Fim );
        return this;
    }
    this.pMid = function( _strConteudo, _Inicio, _Fim ){
        try{ 
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.substring(_Inicio, _Fim + 1 );
        }catch(e){
            this.Message(e);
        }finally{                
            return _strConteudo; 
        }
    }

    //Retorna apenas numeros do conteudo
    this.OnlyNumber = function(){
        this.Value = this.pOnlyNumber( this.Value );
        return this;
    }
    this.pOnlyNumber = function( _strConteudo ){
        var strConteudoAlterado = "";
        var strCaracter = "";
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            for(var i=0; i < this.pLength(_strConteudo); i++ ){
                strCaracter = _strConteudo.substring( i, i+1 );
                if( ! isNaN( strCaracter ) && strCaracter != " " && strCaracter != "" && strCaracter != null ){
                    strConteudoAlterado += strCaracter.toString();
                }
            }
        }catch(e){
            strCaracter = "";
        }finally{
            return strConteudoAlterado;
        }
    }
    
    //Retorna o valor informado caso o valor testado seja vazio
    this.ReplaceEmpty = function( _strTextoASubstituir ){
        this.Value = this.pReplaceEmpty( this.Value, _strTextoASubstituir );
        return this;
    }
    
    this.pReplaceEmpty = function( _strTextoATestar, _strTextoASubstituir ){
        try{
            return (! this.pIsEmpty(_strTextoATestar) ) ? _strTextoATestar : _strTextoASubstituir;
        }catch(e){
            this.Message(e);
        }
    } 
    
    
    //Retorna um conteudo com parte dele substituido por outro
    this.Replace = function( _strTextoASubstituir, _strTextoUtilizadoParaSubstituicao ){
        this.Value = this.pReplace( this.toString(), _strTextoASubstituir, _strTextoUtilizadoParaSubstituicao );
        return this;
    }
	this.pReplace = function( _strConteudo, _strTextoASubstituir, _strTextoUtilizadoParaSubstituicao ){
        try{
            //Convertendo conteudo para string
            _strConteudo = this.pToString( _strConteudo );                        
                        
            if(_strTextoASubstituir.indexOf(';') == -1 && _strTextoASubstituir.indexOf('/') == -1 && _strTextoASubstituir.indexOf('\\') == -1 && _strTextoASubstituir.indexOf('[') == -1 && _strTextoASubstituir.indexOf('(') == -1 && _strTextoASubstituir.indexOf('*') == -1 && _strTextoASubstituir.indexOf('$') == -1)
            {                            
                _strConteudo = _strConteudo.replace(eval('/' + _strTextoASubstituir + '/ig'), _strTextoUtilizadoParaSubstituicao);                           
            }
            else
            {
                var lngNumRepeticoes = _strConteudo.toUpperCase().split(_strTextoASubstituir.toUpperCase()).length;
                
                for(var x = 0; x < lngNumRepeticoes; x++){
                   _strConteudo = _strConteudo.replace(_strTextoASubstituir, _strTextoUtilizadoParaSubstituicao);               
                   _strConteudo = _strConteudo.replace(_strTextoASubstituir.toLowerCase(), _strTextoUtilizadoParaSubstituicao);               
                   _strConteudo = _strConteudo.replace(_strTextoASubstituir.toUpperCase(), _strTextoUtilizadoParaSubstituicao);               
                }
            }                
        }catch(e){
            this.Message(e);
        }finally{                
            return _strConteudo; 
        }
    }

    //Retorna uma quantidade x de caracteres a direita do conteudo;
    //_Quantidade --> Quantidade de carateres a ser capturado
    this.Right = function( _Quantidade ){
        this.Value = this.pRight( this.toString(), _Quantidade );
        return this;
    } 
    this.pRight = function( _strConteudo, _Quantidade ){ 
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.substring(_strConteudo.length - _Quantidade, _strConteudo.length );
        }catch(e){
            this.Message(e);
        }finally{                
            return _strConteudo; 
        }
    }
    
    //Retorna o conteudo de uma url acessada
    this.RPC = function( _strURL ){
        this.Value = this.pRPC( _strURL );
        return this;
    } 
    this.pRPC = function( _strURL, _Handle, _MethodPost, _Conteudo ){
        //Variáveis internas
        var strRetornoURL;
        var oXMLHTTP;
        var blnModoAssincrono = ( ! this.pIsEmpty( _Handle ) ? true : false );
        var Method = ( _MethodPost != true )? "GET" : "POST";
        
        try{
            //Criando instância de objeto xmlhttp
            try
            { oXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e1){   
                try
                { oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e2){   
                    try 
                    { oXMLHTTP = new XMLHttpRequest(); }catch(e3){ 
                        oXMLHTTP = null; 
                    }
                }
            }
            if ( this.pIsObject( oXMLHTTP ) ){
                //Executando a url informada
                oXMLHTTP.open( Method, _strURL, blnModoAssincrono );
                oXMLHTTP.setRequestHeader("Content-Type","text/HTML");
                
                //Verifica se o modo solicitado é o Assíncrono
                if(blnModoAssincrono) {
                    oXMLHTTP.onreadystatechange = function (){
                        if( oXMLHTTP.readyState == 4 || oXMLHTTP.readyState == 'complete' ){
					        if( oXMLHTTP.status == 200 ){
					            strRetornoURL = oXMLHTTP.responseText;
						        //Verificando necessidade de codificação dos dados
						        if( (typeof _Handle == "function") ){
							        eval( _Handle(strRetornoURL) );
						        }
	                        }
                        }
                    }
                    oXMLHTTP.send( _Conteudo );
                }else{
                    oXMLHTTP.send( _Conteudo );
                    if( oXMLHTTP.status == 200 ){
                        strRetornoURL = oXMLHTTP.responseText;
                    }
                }
            }
        }catch(e){
            this.Message(e);
        }finally{
            return strRetornoURL;
        }
    }

    //Retorna conteudo em maiusculo
    this.ToLower = function(){ 
        this.Value = this.pToLower( this.toString() );
        return this;
    }
    this.pToLower = function( _strConteudo ){ 
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.toLowerCase();
        }catch(e){
            this.Message(e);
        }finally{                
            return _strConteudo; 
        }
    }

    //Retorna o conteudo como string (este metódo deve ser chamada toString() com t em minusculo mesmo
    this.ToString = function(){
        return this.toString();
    }
    this.pToString = function ( _strConteudo ){
        return this.ptoString( _strConteudo );
    }
    //Início - Funções necessárias para serem executadas de forma implícita
    this.toString = function(){ 
        //return = this.ptoString( this.Value );
        return this.ptoString( this.Value );
    }
    this.ptoString = function( _strConteudo ){ 
        try{
            _strConteudo = _strConteudo.toString(); 
        }catch(e){
            _strConteudo = "";
        }finally{                
            return _strConteudo; 
        }
    }
    //Fim - Funções necessárias para serem executadas de forma implícita
    
    //Retorna conteudo em maiusculo
    this.ToUpper = function(){
        this.Value = this.pToUpper( this.toString() );
        return this;
    } 
    this.pToUpper = function( _strConteudo ){ 
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            _strConteudo = _strConteudo.toUpperCase();
        }catch(e){
            this.Message(e);
        }finally{                
            return _strConteudo; 
        }
    }

    //Retorna o conteudo sem espaços antes e depois
    this.Trim = function(){
        this.Value = this.pTrim( this.toString() );
        return this;
    }
    this.pTrim = function( _strConteudo ){
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

            if( _strConteudo.length > 0 ){
                while( _strConteudo.charAt(0) == " " || this.pURLEncode(_strConteudo.charAt(0)) == "%0A" || this.pURLEncode(_strConteudo.charAt(0)) == "%09" ){
                    _strConteudo = _strConteudo.substring(1, _strConteudo.length);
                }
                while( _strConteudo.charAt(_strConteudo.length-1) == " " || this.pURLEncode(_strConteudo.charAt(_strConteudo.length-1)) == "%0A" || this.pURLEncode(_strConteudo.charAt(_strConteudo.length-1)) == "%09" ){
                    _strConteudo = _strConteudo.substring(0, _strConteudo.length-1);
                }
            }
        }catch(e){ 
            this.Message(e) 
        }
        finally{ 
            return _strConteudo; 
        }
    }
    
    //Retorna o conteudo formatado no modelo URL
    this.URLEncode = function( _blnUTF8 ){
        this.Value = this.pURLEncode( this.toString(), _blnUTF8 );
        return this;
    }
    this.pURLEncode = function( _strConteudo, _blnUTF8 ){
		if( _blnUTF8 != true ){ _blnUTF8 = false }
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

			if( ! _blnUTF8 ){
				_strConteudo = escape( _strConteudo );
				_strConteudo = _strConteudo.replace( /\+/g, "%2B"); //Não pode mudar a ordem deste item
				_strConteudo = _strConteudo.replace( /%20/g, "+");
				_strConteudo = _strConteudo.replace( /\*/g, "%2A");
				_strConteudo = _strConteudo.replace( /-/g, "%2D");
				_strConteudo = _strConteudo.replace( /\./g, "%2E");
				_strConteudo = _strConteudo.replace( /\//g, "%2F");
				_strConteudo = _strConteudo.replace( /\@/g, "%40");
				_strConteudo = _strConteudo.replace( /_/g, "%5F");
            }else{
				_strConteudo = encodeURI(_strConteudo);
	        }
        }catch(e){
            this.Message(e);
        }finally{              
          return _strConteudo; 
        }
    }
    
    //Retorna o conteudo descodificado do padrão URL
    this.URLDecode = function( _blnUTF8){
        this.Value = this.pURLDecode( this.toString(), _blnUTF8 );
        return this;
    }           
    this.pURLDecode = function( _strConteudo, _blnUTF8 ){
		if( _blnUTF8 != true ){ _blnUTF8 = false }
        try{
			//Convertendo conteudo para string
			_strConteudo = this.pToString( _strConteudo );

			if( ! _blnUTF8 ){
				var strRegularExpression = /\+/g;
				_strConteudo = unescape(String(_strConteudo).replace(strRegularExpression, " ")); 
            }else{
				_strConteudo = decodeURI(_strConteudo);
            }
        }catch(e){
            this.Message(e);
        }finally{              
          return _strConteudo; 
        }
    }
    
    //Retorno o caracter separador das casas decimais
    this.CaracterDecimais = function() {
        this.Value = this.pCaracterDecimais( this.Value );
        return this;
    }
    this.pCaracterDecimais = function(){
        var strCarecterDecimais = ".";
        var cstPtBr = "PT-BR";
        var cstEnUs = "EN-US";
        var strIdioma = (document.all)?navigator.userLanguage:navigator.language;

        if( this.pIsEmpty( strIdioma ) ){
            strIdioma = cstPtBr;
        }
        
        switch ( this.pToUpper(strIdioma) ){
            case cstPtBr :
                strIdioma = cstPtBr;    
                strCarecterDecimais = ",";
                break;
            case cstEnUs :
                strIdioma = cstEnUs;
                strCarecterDecimais = ".";
                break;
            default :
                strIdioma : cstPtBr;
                strCarecterDecimais = ",";
                break;
        }
        return strCarecterDecimais;
    }
    
    //Formata valor informado no padrão numerico com x numeros de casas decimais,
    //Máscara de moeda e definição de caracter de centavos.
    this.FormatNumber = function( lngCasasDecimais, blnTipoMoeda, blnForcarDecimaisComPontos ) {
        this.Value = this.pFormatNumber( this.Value, lngCasasDecimais, blnTipoMoeda, blnForcarDecimaisComPontos, blnMascararSaida );
        return this;
    }
    this.pFormatNumber = function( vrtValorOrigem, lngCasasDecimais, blnTipoMoeda, blnForcarDecimaisComPontos, blnMascararSaida ) {
	    try{
	        var strCarecterSeparador = ".";
	        var strCarecterSeparadorErrado = ",";
	        var strCaracterDecimal = this.pCaracterDecimais();
            var strValorOrigem = vrtValorOrigem.toString();
	        var strValorDecimal = "";

	        if( strCaracterDecimal == "," ){
	            strCarecterSeparador = ",";
	            strCarecterSeparadorErrado = ".";
	        }
    	    
	        if( ! this.pIsNumeric( lngCasasDecimais ) ){
	            lngCasasDecimais = 2;
	        }

            if( blnTipoMoeda != true ){
                blnTipoMoeda = false;
            }
            
            if( blnForcarDecimaisComPontos != true ){
                blnForcarDecimaisComPontos = false;
            }
            
            if( blnMascararSaida != true ){
                blnMascararSaida = false;
            }            

	        //Formatando o conteudo inicialmente
	        if( strValorOrigem.indexOf(strCarecterSeparador) != -1 && strValorOrigem.indexOf(strCarecterSeparador) != -1 ){
		        if( strValorOrigem.indexOf(strCarecterSeparadorErrado) < strValorOrigem.indexOf(strCarecterSeparador) ){
		            strValorOrigem = strValorOrigem.replace(strCarecterSeparadorErrado,"");
		        }else{
		            strValorOrigem = strValorOrigem.replace(strCarecterSeparador,"");
		            strValorOrigem = strValorOrigem.replace(strCarecterSeparadorErrado, strCarecterSeparador);
		        }
	        }else if(strValorOrigem.indexOf(strCarecterSeparadorErrado) != -1){
		        strValorOrigem = strValorOrigem.replace(strCarecterSeparadorErrado, strCarecterSeparador);		
	        }
        	
	        if (strValorOrigem.indexOf(strCarecterSeparador) != -1){
		        strValorDecimal = strValorOrigem.split(strCarecterSeparador)[1];
		        strValorOrigem = strValorOrigem.split(strCarecterSeparador)[0];
	        }
	        if( this.pIsEmpty(strValorOrigem) ){
	            strValorOrigem = "0";
	        }
	        strValorOrigem = parseFloat(strValorOrigem);
	        
	        var lngTamanhoDecimal = this.pLength(strValorDecimal);
    	    var lngTamanhoInteiro = this.pLength(strValorOrigem);
    	    var strValorParteInteira = "";

            if( blnMascararSaida ){
    	        if( lngTamanhoInteiro > 3 ){
    	            for(var i=0; i < lngTamanhoInteiro; i++ ){
    	                strValorParteInteira = this.pMid(strValorOrigem, (lngTamanhoInteiro - i) - 1, (lngTamanhoInteiro - i) - 1) + strValorParteInteira;
        	            if( ( (i+1) % 3 == 0 ) && ( (i+1) != lngTamanhoInteiro ) ){
        	                strValorParteInteira = (blnForcarDecimaisComPontos ? "," : strCarecterSeparadorErrado) + strValorParteInteira;
        	            }
    	            }
    	            strValorOrigem = strValorParteInteira;
    	        }
    	    }
    	    
	        if(lngTamanhoDecimal > lngCasasDecimais){
		        var lngArredondamentoCasas = 0;
		        var lngDecimalAMais = parseFloat(strValorDecimal.substring(lngCasasDecimais, lngCasasDecimais+1));
		        var strBaseCalculoArredondamentoCasaAdicional = ".";
		        
		        if(  lngDecimalAMais >=5 ){
		            lngArredondamentoCasas = 1;
		        }
		        
		        if( lngCasasDecimais == 0 ){
					strValorOrigem = strValorOrigem + lngArredondamentoCasas;
					strValorDecimal = "";
		        }else{
					//Necessário a inclusão da concatenação do "1" para evitar calculo de dizima pelo javascript
					//Não deverá ser removido.
					strValorDecimal = parseFloat("." + strValorDecimal.substring(0, lngCasasDecimais) + "1");
					for( j=0; j < lngCasasDecimais-1; j++ ){
						strBaseCalculoArredondamentoCasaAdicional += "0";
					}
					strValorDecimal += parseFloat(strBaseCalculoArredondamentoCasaAdicional + lngArredondamentoCasas + "1");
					strValorDecimal = strValorDecimal.toString();
					strValorDecimal = strValorDecimal.substring(2, lngCasasDecimais + 2 );
		        }
		        lngTamanhoDecimal = this.pLength(strValorDecimal);
	        }
    	    
	        for(var i=0; i < parseInt(lngCasasDecimais)-lngTamanhoDecimal; i++){
		        strValorDecimal += "0";
	        }
    	    
            if( blnForcarDecimaisComPontos ){
	            strCarecterSeparador = ".";
	            strCarecterSeparadorErrado = ",";
            }

    	    if( lngCasasDecimais > 0 ){
				strValorOrigem += strCarecterSeparador + strValorDecimal;
	        }
    	    
	        if(blnTipoMoeda){
		        strValorOrigem = "R$ " + strValorOrigem;
	        }
        }catch(e){
            strValorOrigem = vrtValorOrigem;
        }finally{
	        return strValorOrigem;
	    }
    }
}