// JavaScript Document
function CookieClass()
{

this.GetCookie = function(sName)
{
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {
        // a name alue pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
        {
            return aCrumb[1];
        }
    }
    // a cookie with the requested name does not exist
    return null;
}

this.SetCookie = function(sName,sValue,sDate)
{
	var expires = new Date();
	expires.setTime(expires.getTime()+sDate*24*60*60*1000);
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + expires.toGMTString;
}

this.decode64 = function(input)
{
    var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;
    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
    flag = 0; // flag of Bytes follows.
    ucs2_code = 0;
    do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));
        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
        if ( chr1 <= 0x80) {
            // 单字节ASCII，直接输出
        ucs2_code = chr1;
        } else if (chr1 <= 0xC0) {
            // 非独立字节 --flag;
                if (flag ==1)
                {
                    ucs2_code += ( chr1-0x80 ) << 6;
                }else {
                    ucs2_code += chr1-0x80;
                }
        } else if (chr1 <= 0xE0)
         {
                 // 双字节utf-8编码
        flag = 1;
                ucs2_code = ( chr1-0xC0 ) << 6;
        } else if (chr1 <=0xF0)
        {
             // 三字节utf-8编码
        flag = 2;
                ucs2_code = ( chr1-0xE0 ) << 12;
        }
        if (flag == 0)
        {
            output = output + String.fromCharCode(ucs2_code);
        }
      if (enc3 != 64) {
        if ( chr2 <= 0x80) {
            ucs2_code = chr2;
        } else if (chr2 <= 0xC0)
        {
            --flag;
             if (flag == 1)
            {
                ucs2_code += ( chr2-0x80 ) << 6;
            }else {
                ucs2_code += chr2-0x80;
            }
        } else if (chr2 <= 0xE0)
         {
            flag = 1;
            ucs2_code = ( chr2-0xC0 ) << 6;
        } else if (chr2 <=0xF0)
         {
            flag = 2;
            ucs2_code = ( chr2-0xE0 ) << 12;
        }
        if (flag == 0)
         {
            output = output + String.fromCharCode(ucs2_code);
        }
    }
    if (enc4 != 64) {
        if ( chr3 <= 0x80) {
            ucs2_code = chr3;
        } else if (chr3 <= 0xC0)
        {
            --flag;
            if (flag==1)
            {
                ucs2_code += ( chr3-0x80 ) << 6;
            }else {
            ucs2_code += chr3-0x80;
             }
        } else if (chr3 <= 0xE0)
        {
            flag = 1;
            ucs2_code = ( chr3-0xC0 ) << 6;
        } else if (chr3 <=0xF0)
        {
            flag = 2;
            ucs2_code = ( chr3-0xE0 ) << 12;
        }
        if (flag == 0)
        {
            output = output + String.fromCharCode(ucs2_code);
        }
    }
} while (i < input.length);
    return output;
}

}

