/**
 * This script decode all base64 encoded strings like "[".base64_encode("b64tag:".$string)."]"
 * directly after loading the whole DOM.
 *
 * you have to insert prototype into your html header before this script.
 *
 * @requirements prototype 1.6
 * @requirements base64 0.beta
 *
 * @author Helmut Wandl <helmut@wandls.net>
 * @version 0.beta.2.3
 *
 * @copy STERNWERK 2008
 *
 */
document.observe('dom:loaded', function()
{
	var reg=/\[([A-Za-z0-9+\/=]+)\]/g;
	var e;

	var obj=document.body;
	while(obj)
	{
		if (obj.nodeName == 'A' && obj.getAttribute('href'))
		{
			var href=decode_str(obj.getAttribute('href'));
			if (Prototype.Browser.IE) href=href.replace(/^.+?(?=mailto\:)/, '');
			if (obj.getAttribute('href') != href) obj.setAttribute('href', href);
		}

		if (obj.nodeName == 'IMG' && obj.getAttribute('alt'))
			obj.setAttribute('alt', decode_str(obj.getAttribute('alt')));

		if (obj.getAttribute && obj.getAttribute('title'))
			obj.setAttribute('title', decode_str(obj.getAttribute('title')));

		if ((obj.nodeName == 'TEXTAREA' || obj.nodeName == 'INPUT') && obj.value)
			obj.value=decode_str(obj.value);

		if (obj.nodeName == '#text' && obj.nodeValue)
			obj.nodeValue=decode_str(obj.nodeValue);

		obj=nextSiblingX(obj);
	}

	function nextSiblingX(obj)
	{
		if (obj.firstChild) return obj.firstChild;
		while (!obj.nextSibling && obj.parentNode) obj = obj.parentNode;
		if (obj.nextSibling && obj.nextSibling.nodeName != 'BODY') return obj.nextSibling;
		return false;
	}

	function decode_str(str)
	{
		return str.replace(reg, function(a,b,c){
			if ((e=base64.decode(b)) && e.substr(0,7) == 'b64tag:')
				return e.substr(7);
			return a;
		});
	}
});



