//speichert die scrollposition des �ffnenden fensters
var xpos = 0;
var ypos = 0;

//�ffnet ein neues fenster mit den angegebenen optionen
function openWindow(windowurl, windowname, width, height, scrollbars) {
	/*
	window.alert('appCodeName: ' + navigator.appCodeName + '\n' +
		'appName: ' + navigator.appName + '\n' +
		'appVersion: ' + navigator.appVersion + '\n' +
		'platform: ' + navigator.platform + '\n' +
		'userAgent: ' + navigator.userAgent + '\n');
	window.alert('screenLeft: ' + window.screenLeft + '\nscreenTop: ' + window.screenTop +
		'\nscreenX: ' + window.screenX + '\nscreenY: ' + window.screenY);
	*/
	var nleft = 0;
	var ntop = 0;
	if (navigator.userAgent.indexOf('MSIE') > -1) {
		nleft = window.screenLeft + 200;
		ntop = window.screenTop + 80;
		if (document.documentElement && document.documentElement.scrollTop) {
			ypos = document.documentElement.scrollTop;
			xpos = document.documentElement.scrollLeft;
		}
		else {
			ypos = document.body.scrollTop;
			xpos = document.body.scrollLeft;
		}
	}
	else {
		nleft = window.screenX + 200;
		ntop = window.screenY + 180;
		ypos = window.pageYOffset;
		xpos = window.pageXOffset;
	}
	var options = 'top=' + ntop + ',left=' + nleft + ',height=' + height + ',width=' + width + ',scrollbars=' + ((scrollbars)?'yes':'no') + ',status=no,location=no,menubar=no,resizable=no,toolbar=no';
	//window.alert(options);
	window.open(windowurl, windowname, options);
	window.scrollTo(0,0);
}
//scrollt das fenster zur �rspr�nglichen position
function scrollToPrevPos() {
	if (ypos || xpos) {
		window.scrollTo(xpos, ypos);
		ypos = 0;
		xpos = 0;
	}
}

function openBillWindow(width, height){
	var nleft = 0;
	var ntop = 0;
	var nwidth = 0;
	if (navigator.userAgent.indexOf('MSIE') > -1) {
		nleft = window.screenLeft;
		ntop = window.screenTop;
	}
	else {
		nleft = window.screenX;
		ntop = window.screenY;
	}
	left = nleft + ((parent.iWidth / 2) - 315);
	var options = 'top=' + ntop + ',left=' + left + ',height=' + height + ',width=' + width + ',scrollbars=yes,status=no,location=no,menubar=no,resizable=yes,toolbar=no';
	newwin = window.open('', 'bill', options);
	newwin.resizeTo(width, height);
	newwin.focus();
}

// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
  var output = "";
  var chr1, chr2, chr3;
  var enc1, enc2, enc3, enc4;
  var i = 0;

  do {
     chr1 = input.charCodeAt(i++);
     chr2 = input.charCodeAt(i++);
     chr3 = input.charCodeAt(i++);

     enc1 = chr1 >> 2;
     enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
     enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
     enc4 = chr3 & 63;

     if (isNaN(chr2)) {
        enc3 = enc4 = 64;
     } else if (isNaN(chr3)) {
        enc4 = 64;
     }

     output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
        keyStr.charAt(enc3) + keyStr.charAt(enc4);
  } while (i < input.length);
    return output;
}

function decode64(input) {
  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, "");

  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;

     output = output + String.fromCharCode(chr1);

     if (enc3 != 64) {
        output = output + String.fromCharCode(chr2);
     }
     if (enc4 != 64) {
        output = output + String.fromCharCode(chr3);
     }
  } while (i < input.length);

  return output;
}


// Checkt, ob das Prototype Framework eingebunden wurde
function checkForPrototype() {
	if (typeof Prototype == 'undefined') {
		throw("Function/method requires the Prototype Javascript Framework");
	}
}

// Konvertiert HTML Entities in einem String derart, dass sie korrekt in einem
// alert() oder confirm() dargestellt werden koennen.
// - Benoetigt das Prototype Javascript Framework
function convertHTMLEntities(text) {
	try {
		checkForPrototype();
		text = text.gsub("&auml;", "%E4");
		text = text.gsub("&ouml;", "%F6");
		text = text.gsub("&uuml;", "%FC");
		text = text.gsub("&Auml;", "%C4");
		text = text.gsub("&Ouml;", "%D6");
		text = text.gsub("&Uuml;", "%DC");
		text = text.gsub("&szlig;", "%DF");
	} catch(e) {
		// Exception Handling..?
	}
	
	return text;
}