  /**
   *  fScript JS Library - Base64 en/decoding  Module
	*  -----------------------------------------------------------------
	*  @copyright Copyright (c) 2006-2008 fCMS Development Team
	*	@author Arne Blankerts <theseer@fcms.de>
	*
	*  var b64=fBase64.encode(string);
	*  var str=fBase64.decode(b64);
	* 
	*/


 var fBase64 = {

	keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	encode: function (input) {
	   
	   if (typeof btoa == 'function') {
	      return btoa(input);
	   }
	   
		var output = "";
		var c1, c2, c3;
		var code1, code2, code3, enc4;
		var i = 0;

		do {
			c1 = input.charCodeAt(i++);
			c2 = input.charCodeAt(i++);
			c3 = input.charCodeAt(i++);

			code1 = c1 >> 2;
			code2 = ((c1 & 3) << 4) | (c2 >> 4);
			code3 = ((c2 & 15) << 2) | (c3 >> 6);
			enc4 = c3 & 63;

			if (isNaN(c2)) {
				code3 = enc4 = 64;
			} else if (isNaN(c3)) {
				enc4 = 64;
			}

			output = output + this.keyStr.charAt(code1) + this.keyStr.charAt(code2) +
			this.keyStr.charAt(code3) + this.keyStr.charAt(enc4);
		} while (i < input.length);

		return output;
	},

	decode: function (input) {
	   
	   if (typeof atob =='function') {
	      return atob(input);
	   }
	   
		var output = "";
		var c1, c2, c3;
		var code1, code2, code3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		do {
			code1 = this.keyStr.indexOf(input.charAt(i++));
			code2 = this.keyStr.indexOf(input.charAt(i++));
			code3 = this.keyStr.indexOf(input.charAt(i++));
			enc4 = this.keyStr.indexOf(input.charAt(i++));

			c1 = (code1 << 2) | (code2 >> 4);
			c2 = ((code2 & 15) << 4) | (code3 >> 2);
			c3 = ((code3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(c1);

			if (code3 != 64) {
				output = output + String.fromCharCode(c2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(c3);
			}
		} while (i < input.length);

      	return output;
	}
		
};
