
    var tblEncodeString1= new Array
                            (
                                108,112,88,117,99,85,68,69,121,113,
                                81,51,106,111,70,80,77,74,86,104,
                                67,115,72,71,48,73,65,103,107,102,
                                49,110,114,83,98,82,50,100,54,75,
                                66,105,97,87,120,76,56,55,84,116,
                                79,109,52,78,118,89,57,53,119,101
                            );

      var tblEncodeString2= new Array
                            (
                                51,70,117,68,101,97,82,72,113,87,
                                76,88,108,104,99,71,106,115,121,56,
                                100,52,110,84,54,89,75,102,86,111,
                                109,67,85,66,116,53,78,120,119,118,
                                77,69,83,49,65,50,55,80,107,74,
                                112,79,98,105,57,114,73,48,103,81
                            );


    function ExistsInBytes(b, s)
    {

	    for (var i=0; i<s.length; i++)
	    {
	      if(s[i]==parseInt(b,10))
	        return i;
	    }
	    return -1;
    }
    
    function AdjustStringLen(s,len)
    {
        if(s.length>=len)
            return s;
        var rc=new String;
        rc=s;
        while(rc.length<len)
        {
            rc = "0"+rc;
        }
        return rc;
    }

    function EncodeString(s)
    {
        var rc="";
        
        if (s.length == 0)
            return rc;

        var i=0;
        var sb= new String;
        for (i = 0; i < s.length; i++)
        {
            var v=parseInt(s.charCodeAt(i).toString(16),16);
            if (v < 0x0FF)
            {          
                if (v == 90||v ==122)
                {
                    sb+=String.fromCharCode(v);
                    sb+="x";
                    continue;
                }
                
                var nPos =ExistsInBytes(v, tblEncodeString1);
                if (nPos!=-1)
                {
                    sb += String.fromCharCode(tblEncodeString2[nPos]);
                    continue;
                }
                
                sb+="z"+AdjustStringLen(s.charCodeAt(i).toString(16),2);
            }
            else
            {
                sb+="Z" +AdjustStringLen(s.charCodeAt(i).toString(16).toUpperCase(),4) ;
            }
            
        }
        return sb;
    }

    function DecodeString(s)
    {
        var rc=""
        if (s.length == 0)
            return rc;
        var sb = new String;
        var pos=0;
        while (pos < s.length)
        {
            var v=parseInt(s.charCodeAt(pos).toString(16),16);
            if (v != 90&&v!=122)
            {
                var nPos = ExistsInBytes(v, tblEncodeString2);
                if (nPos == -1)
                    return "";
                sb+=String.fromCharCode(tblEncodeString1[nPos]);
                pos++;
            }
            else
            {
                if (s.charCodeAt(pos + 1) <=121  && s.charCodeAt(pos + 1) >= 103)  //'z' 'y'
                {
                    sb+=String.fromCharCode(v);
                    pos += 2;
                    continue;
                }

                if (v == 122)//'z'
                {
                    if (pos + 3 > s.Length)
                    {
                        return "";
                    }
                    var v=parseInt(s.charAt(pos + 1),16)*16+parseInt(s.charAt(pos + 2),16);
                    sb+=String.fromCharCode(v);
                    pos += 3;
                }
                else
                {
                    if (pos + 5 > s.Length)
                    {
                        return "";
                    }
                    var value=parseInt(s.charAt(pos + 1),16) * 16 * 16 * 16 + parseInt(s.charAt(pos + 2),16) * 256 + parseInt(s.charAt(pos + 3),16) * 16 + parseInt(s.charAt(pos + 4),16);
                    sb+=String.fromCharCode(value);
                    pos += 5;
                }
                
            }
        }
        return sb;
    }


