/* #############################################################################
UTF-8 Decoder and Encoder
base64 Encoder and Decoder
written by Tobias Kieslich, justdreams
Contact: tobias@justdreams.de				http://www.justdreams.de/
############################################################################# */

// included in <body onload="b64arrays"> it creates two arrays which makes base64
// en- and decoding faster
// this speed is noticeable especially when coding larger texts (>5k or so)
	function b64arrays() {
	var b64s='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
		b64 = new Array();f64 =new Array();
		for (var i=0; i<b64s.length ;i++) {
			b64[i] = b64s.charAt(i);
			f64[b64s.charAt(i)] = i;
		}
	}	

// returns plaintext from an array of bytesrepresenting dezimal numbers, which
// represent an UTF-8 encoded text; browser which does not understand unicode
// like NN401 will show "?"-signs instead
// expects an array of byterepresenting decimals; returns a string
	function utf8d2t(d)
		{
		var r=new Array; var i=0;
		while(i<d.length)
			{
			if (d[i]<128) {
				r[r.length]= String.fromCharCode(d[i]); i++;}
			else if((d[i]>191) && (d[i]<224)) {
				r[r.length]= String.fromCharCode(((d[i]&31)<<6) | (d[i+1]&63)); i+=2;}
			else {
				r[r.length]= String.fromCharCode(((d[i]&15)<<12) | ((d[i+1]&63)<<6) | (d[i+2]&63)); i+=3;}
			}
		return r.join("");
		}

// returns array of byterepresenting numbers created of an base64 encoded text
// it is still the slowest function in this modul; I hope I can make it faster
// expects string; returns an array
	function b64t2d(t) {
		var d=new Array; var i=0;
		// here we fix this CRLF sequenz created by MS-OS; arrrgh!!!
		t=t.replace(/\n|\r/g,""); t=t.replace(/=/g,"");
		while (i<t.length)
			{
			d[d.length] = (f64[t.charAt(i)]<<2) | (f64[t.charAt(i+1)]>>4);
			d[d.length] = (((f64[t.charAt(i+1)]&15)<<4) | (f64[t.charAt(i+2)]>>2));
		  	d[d.length] = (((f64[t.charAt(i+2)]&3)<<6) | (f64[t.charAt(i+3)]));
		  	i+=4;
			}
		if (t.length%4 == 2)
			d = d.slice(0, d.length-2);
		if (t.length%4 == 3)
			d = d.slice(0, d.length-1);
		return d;
		}
		
b64arrays();
		
		
function prepareEmailLayer(email_addy,mailnr)
{
maketip("email"+mailnr,'<table border="0" cellspacing="0" cellpadding="1" style="border:solid 2px #223F6E"><tr><td bgcolor="#396ABA"><span class="font2-bb" style="color:#FFFFFF;">E-Mail: </span><span class="font2-nb" style="color:#FFFFFF;">'+utf8d2t(b64t2d(email_addy))+'</span></td></tr></table>',300,150);
}


