//New decoder
function decode(mystring) 
{
	b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	pad="000000";
	pads = mystring.match(/=+/) ? mystring.match(/=+/)[0].length : 0;
	mystring=mystring.replace(/=/g,"A");
	out="";
	for (var i = 0; i<mystring.length; i+=4) 
	{
		temp=((b64.indexOf(mystring.charAt(i))<<18) + (b64.indexOf(mystring.charAt(i+1))<<12) + (b64.indexOf(mystring.charAt(i+2))<<6) + (b64.indexOf(mystring.charAt(i+3)))).toString(16);
		out+=(pad.substring(0,6-temp.length)+temp).replace(/../g,"%$&");
	}
	out=unescape(out.substring(0,out.length-pads*3).replace(/%00/g,""));
	return out
} 




//Old decoder
var base64 = [ 
       'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',   //  0 to  7 
       'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',   //  8 to 15 
       'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',   // 16 to 23 
       'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',   // 24 to 31 
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',   // 32 to 39 
       'o', 'p', 'q', 'r', 's', 't', 'u', 'v',   // 40 to 47 
       'w', 'x', 'y', 'z', '0', '1', '2', '3',   // 48 to 55 
       '4', '5', '6', '7', '8', '9', '+', '/' ]; // 56 to 63 

function charFromCharCode (charCode) { 
    return unescape('%' + charCode.toString(16)); 
} 

function reverseBase64 () { 
  var r = new Object(); 
  for (var i = 0; i < 64; i++) { 
    r[base64[i]] = i; 
  } 
  return r; 
} 

var reversedBase64 = reverseBase64(); 

function unicodelessDecode (encStr) { 
    var charCodes = new Array(); 
    var decStr = ""; 

    /* charCodes contains the index values into the base64 array 
       for each character in the encoded string */ 
    for (var i = 0; i < encStr.length; i++) 
        charCodes[i] = reversedBase64[encStr.charAt(i)]; 

    for (var i = 0; i < encStr.length; i += 4) { 
        /* bits24 is 4 groups of 6-bit character indexes */ 
        var bits24  = ( charCodes [i]     & 0xFF  ) <<  18; 
            bits24 |= ( charCodes [i + 1] & 0xFF  ) <<  12; 
            bits24 |= ( charCodes [i + 2] & 0xFF  ) <<   6; 
            bits24 |= ( charCodes [i + 3] & 0xFF  ) <<   0; 

        /* grab the character for the first 8 bits by masking off the 
           last 16 bits and then shifting right */ 
        decStr     += charFromCharCode((bits24 & 0xFF0000) >> 16); 

        /* if the next characer is a pad character, there won't be a charCode 
           for it; so charCodes[] will return false and the character won't 
           be decoded. */ 

        /* grab the character for the second 8 bits by masking off the 
           last 8 bits and then shifting right */ 
        if (charCodes[i + 2])  // check for padding character = 
            decStr += charFromCharCode((bits24 &   0xFF00) >>  8); 


        /* grab the character for the last 8 bits */ 
        if (charCodes[i + 3])  // check for padding character = 
            decStr += charFromCharCode((bits24 &     0xFF) >>  0); 
   } 
   return decStr; 
} 
