// Version : 1.003
// Original File Name : EinsBase64Lib.js
// Last Modified : 2008/11/20
// Copyright(c) 2007 NewType Inortech. All Rights Reserved. http://www.newtype.com.tw
// Originally published and documented at http://www.einstand.idv.tw
//
EinsBase64Lib=function()
{
this.m02="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
this.m01=new Array(
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,
-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);
}
EinsBase64Lib.prototype.Base64Encode=function(str)
{
var a01=str.length;
var i=0;
var a02="";
while(i<a01)
{
var c1=str.charCodeAt(i++)&0xff;
if(i==a01)
{
a02+=this.m02.charAt(c1>>2);
a02+=this.m02.charAt((c1&0x3)<<4);
a02+="==";
break;
}
var c2=str.charCodeAt(i++);
if(i==a01)
{
a02+=this.m02.charAt(c1>>2);
a02+=this.m02.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));
a02+=this.m02.charAt((c2&0xF)<<2);
a02+="=";
break;
}
var c3=str.charCodeAt(i++);
a02+=this.m02.charAt(c1>>2);
a02+=this.m02.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));
a02+=this.m02.charAt(((c2&0xF)<<2)|((c3&0xC0)>>6));
a02+=this.m02.charAt(c3&0x3F);
}
return a02;
}
EinsBase64Lib.prototype.Base64Decode=function(str)
{
var c1,c2,c3,c4;
var i,a01,a02;
a01=str.length;
i=0;
a02="";
while(i<a01)
{
do
{
c1=this.m01[str.charCodeAt(i++)&0xff];
}while(i<a01&&c1==-1);
if(c1==-1)break;
do
{
c2=this.m01[str.charCodeAt(i++)&0xff];
}while(i<a01&&c2==-1);
if(c2==-1)break;
a02+=String.fromCharCode((c1<<2)|((c2&0x30)>>4));
do
{
c3=str.charCodeAt(i++)&0xff;
if(c3==61)return a02;
c3=this.m01[c3];
}while(i<a01&&c3==-1);
if(c3==-1)break;
a02+=String.fromCharCode(((c2&0XF)<<4)|((c3&0x3C)>>2));
do
{
c4=str.charCodeAt(i++)&0xff;
if(c4==61)return a02;
c4=this.m01[c4];
}while(i<a01&&c4==-1);
if(c4==-1)break;
a02+=String.fromCharCode(((c3&0x03)<<6)|c4);
}
return a02;
}
EinsBase64Lib.prototype.f04=function(str)
{
var re = /\*/g;
var s=str.replace(re,"+");
return s;
}
EinsBase64Lib.prototype.f02=function(str)
{
var re = /\+/g;
var s=str.replace(re,"*");
return s;
}
EinsBase64Lib.prototype.f01=function(str)
{
var re = /-/g;
var s=str.replace(re,"/");
return s;
}
EinsBase64Lib.prototype.f03=function(str)
{
var re = /\//g;
var s=str.replace(re,"-");
return s;
}
EinsBase64Lib.prototype.URLBase64Decode=function(str)
{
var s1=this.f04(str);
var s2=this.f01(s1);
return this.Base64Decode(s2);
}
EinsBase64Lib.prototype.URLBase64Encode=function(str)
{
var s1=this.Base64Encode(str);
var s2=this.f02(s1);
var s3=this.f03(s2);
if(s3.length>0)
{
var i=s3.length-1;
while((i>=0)&&(s3.charAt(i)=='='))i--;
s3=s3.substring(0,i+1);
}
return s3;
}

