var preparedForms = new Array;
function prepareForm(pTarget)
{
	nodeForm = defineNode(pTarget);
	if ( !in_array(nodeForm.get('id'),preparedForms) )
	{
		array_push(preparedForms,nodeForm.get('id'));
		nodeForm.setAttribute('method','post');
		nodeForm.all('input, textarea').each(function(el)
		{
			if ( el.getAttribute('type') == 'text' || el.get('tagName') == 'TEXTAREA' )
			{
				if ( el.get('value') != '' )
				{
					el.setAttribute('valueDefault',el.get('value'));
					el.setAttribute('title',el.get('value'));
					el.on('focus',function()
					{
						if ( this.hasClass('error') )
						{
							this.removeClass('error');
						}
						if ( this.get('value') == this.getAttribute('valueDefault') && !this.hasClass('noclear') )
						{
							this.set('value','');
						}
					});
					el.on('blur',function()
					{
						if ( this.get('value') == '' && !this.hasClass('noclear') )
						{
							this.set('value',this.getAttribute('valueDefault'));
						}
						if ( this.get('value') == this.getAttribute('valueDefault') && this.hasClass('checked') )
						{
							this.addClass('error');
						}
						else
						{
							if ( !empty(this.getAttribute('prufen')) )
							{
								if ( !prufen(this.get('value'),this.getAttribute('prufen')) )
								{
									this.addClass('error');
									if ( !empty(this.getAttribute('prufenAlert')) )
									{
										alert(this.getAttribute('prufenAlert'));
									}
								}
							}
						}
					});
				}
			}
		});
	}
}
function confirmForm(pTarget)
{
	nodeForm = defineNode(pTarget);
	if ( !in_array(nodeForm.get('id'),preparedForms)  )
	{
		prepareForm(nodeForm);
	}
	erlaubt = true;
	nodeForm.all('input, textarea').each(function(el)
	{
		if ( el.getAttribute('type') == 'text' || el.get('tagName') == 'TEXTAREA' )
		{
			if ( el.hasClass('checked') )
			{
				if ( el.get('value') == '' || ( el.get('value') == el.getAttribute('valueDefault') && !this.hasClass('noclear') ) )
				{
					erlaubt = false;
					el.addClass('error');
				}
				else
				{
					if ( !empty(this.getAttribute('prufen')) )
					{
						if ( !prufen(this.get('value'),this.getAttribute('prufen')) )
						{
							erlaubt = false;
							this.addClass('error');
							if ( !empty(this.getAttribute('prufenAlert')) )
							{
								alert(this.getAttribute('prufenAlert'));
							}
						}
					}
				}
			}
		}
	});
	if ( erlaubt )
	{
		nodeForm.all('input, textarea').each(function(el)
		{
			if ( el.getAttribute('type') == 'text' || el.get('tagName') == 'TEXTAREA' )
			{
				if ( el.getAttribute('valueDefault') != '' && el.get('value') == el.getAttribute('valueDefault') && !this.hasClass('noclear') )
				{
					el.set('value','');
				}
			}
		});
	}
	return erlaubt;
}
function togglePropImg(imgId,propValue1,propValue2)
{
	nodeIMG = Y.one('#'+imgId);
	src = nodeIMG.getAttribute('src');
	var reg1 = new RegExp(propValue1+"$","g");
	var reg2 = new RegExp(propValue2+"$","g");
	if ( reg1.test(src) )
	{
		src = src.replace(reg1,"") + propValue2;
		nodeIMG.setAttribute('src',src);
	}
	else if ( reg2.test(src) )
	{
		src = src.replace(reg2,"") + propValue1;
		nodeIMG.setAttribute('src',src);
	}
	else
	{
		alert('togglePropImg error: not found propValue im src img ('+imgId+')');
	}
}
function prufen(str,prufenTyp)
{
	switch ( prufenTyp )
	{
		case 'email':
			var reg= /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
			if ( reg.test(str) )
			{
				return true;
			}
		break;
		case 'telefon':
			var reg= /^[0-9]+$/;
			if ( reg.test(str) )
			{
				return true;
			}
		break;
	}
	return false;
}
function ajaxForm(pTarget,fnComplete)
{
	nodeFORM = defineNode(pTarget);
	formObj = Y.DOM.byId(nodeFORM.get('id'));
	uri = nodeFORM.get('action');
	var cfg = {
		method: 'POST',
		form: {
			id: formObj,
			useDisabled: true
		}
	};
	// Define a function to handle the response data.
	function complete(id, o, args) {
		var id = id; // Transaction ID.
		data = o.responseText; // Response data.
		if ( !empty(o.responseText) )
		{
			responseText = o.responseText;
		}
		else
		{
			responseText = null;
		}
		if ( !empty(fnComplete) )
		{
			fnComplete();
		}
	};
 
	// Subscribe to event "io:complete", and pass an array
	// as an argument to the event handler "complete".
	Y.on('io:complete', complete, this);
 
	// Start the transaction.
	var request = Y.io(uri, cfg);
}
function ajaxGetInhalt(mappe,inhalt,params,pTarget,fnComplete)
{
	node = defineNode(pTarget);
	pattern = /^[0-9]+$/;
	if ( pattern.test(params) )
	{
		params = 'id='+params;
	}
	YUI().use('node', 'io-base', function(Y) {
		var uri = systemUrl + '?Xkern=1&bearbeiter=' + 'getInhalt';
		var cfg = {
			method: 'POST',
			data: 'mappe=' + mappe + '&' +'inhalt=' + dateiInhalt + '&' + params
		}
		function complete(id, o, args) {
			node.setContent(o.responseText);
			node.show();
			if ( !empty(fnComplete) )
			{
				fnComplete();
			}
			removeAjaxLoader();
		};
		Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
		var request = Y.io(uri,cfg);
	});
}

function ajaxGetFrameInhalt(frameInhalt,params,pTarget,fnComplete)
{
	node = defineNode(pTarget);
	pattern = /^[0-9]+$/;
	if ( pattern.test(params) )
	{
		params = 'id='+params;
	}
	YUI().use('node', 'io-base', function(Y) {
		var uri = systemUrl + '?Xkern=1&bearbeiter=' + 'getFrameInhalt';
		var cfg = {
			method: 'POST',
			data: 'mappe=nomappe&&frameInhalt=' + frameInhalt + '&' + params
		}
		function complete(id, o, args) {
			node.setContent(o.responseText);
			node.show();
			if ( !empty(fnComplete) )
			{
				fnComplete();
			}
			removeAjaxLoader();
		};
		Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
		var request = Y.io(uri,cfg);
	});
}
var ajaxLoaderId;
var nodeBeforeAjaxLoaderId;
var ajaxLoaderImg = new Image();
ajaxLoaderImg.src = mediaUrl+'darstellungen/ajax-loader.gif';
function insertAjaxLoader(pTarget,containerHtml)
{
	node = defineNode(pTarget);
	if ( !empty(ajaxLoaderId) )
	{
		Y.one('#'+ajaxLoaderId).remove();
	}
	if ( empty(containerHtml) )
	{
		containerHtml = '<div style="position:relative;float:right;"></div>';
	}
	nodeAjaxLoader = Y.one('body').create(containerHtml);
	ajaxLoaderId = nodeAjaxLoader.generateID();
	nodeAjaxLoader.setContent('<img src="'+ajaxLoaderImg.src+'" style="position:absolute;margin-left:-45px;margin-top:25px;">');
	node.insert(nodeAjaxLoader,'append');
}
function removeAjaxLoader()
{
	if ( !empty(ajaxLoaderId) )
	{
		nodeAjaxLoader = Y.one('#'+ajaxLoaderId);
		if ( nodeAjaxLoader != null )
		{
			nodeAjaxLoader.setContent('<div style="color:#00CC00;position:absolute;margin-left:-35px;margin-top:18px;">OK</span>');
			window.setTimeout(function()
			{
				nodeAjaxLoader.hide(true);
				window.setTimeout(function()
				{
					nodeAjaxLoader.remove();
				},500);
			},500);
		}
		ajaxLoaderId = '';	
	}
}

function ajaxResponse(mappe,bearbeiter,params,fnComplete)
{
	pattern = /^[0-9]+$/;
	if ( pattern.test(params) )
	{
		params = 'id='+params;
	}
	YUI().use('node', 'io-base', function(Y) {
		var uri = systemUrl + '?bearbeiter=' + bearbeiter;
		var cfg = {
			method: 'POST',
			data: 'mappe=' + mappe +'&' + params
		}
		
		function complete(id, o, args) {
			if ( !empty(o.responseText) )
			{
				responseText = o.responseText;
			}
			if ( !empty(fnComplete) )
			{
				fnComplete();
			}
		};
		Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
		
		var request = Y.io(uri,cfg);
	});
}
function changeProp(mappe,bearbeiter,id,propName,propValueNull,propValueSet,fnComplete)
{
	params = 'id='+id;
	params += '&propName='+propName;
	params += '&propValueNull='+propValueNull;
	params += '&propValueSet='+propValueSet;
	ajax(mappe,bearbeiter,params,fnComplete);
}
function ajaxURL(url,fnComplete)
{
	YUI().use('node', 'io-base', function(Y) {
		var uri = url;
		var cfg = {
			method: 'POST'
		}
		
		function complete(id, o, args) {
			if ( !empty(o.responseText) )
			{
				alert(o.responseText);
			}
			if ( !empty(fnComplete) )
			{
				fnComplete();
			}
		};
		Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
		
		var request = Y.io(uri,cfg);
	});
}
function ajax(mappe,bearbeiter,params,fnComplete)
{
	pattern = /^[0-9]+$/;
	if ( pattern.test(params) )
	{
		params = 'id='+params;
	}
	YUI().use('node', 'io-base', function(Y) {
		var uri = systemUrl + '?bearbeiter=' + bearbeiter;
		var cfg = {
			method: 'POST',
			data: 'mappe=' + mappe +'&' + params
		}
		
		function complete(id, o, args) {
			if ( !empty(o.responseText) )
			{
				alert(o.responseText);
			}
			if ( !empty(fnComplete) )
			{
				fnComplete();
			}
		};
		Y.on('io:complete', complete, Y, ['lorem', 'ipsum']);
		
		var request = Y.io(uri,cfg);
	});
}

var nodeShadow;
function showShadow(fnClick)
{
	nodeShadow = Y.one('#shadow');
	if ( !Y.Lang.isObject(nodeShadow) )
	{
		nodeShadow = Y.Node.create('<div id="shadow"/>');
		nodeShadow.setStyle('backgroundColor','#999');
		nodeShadow.setStyle('position','fixed');
		nodeShadow.setStyle('width','100%');
		nodeShadow.setStyle('height','100%');
		nodeShadow.setStyle('top','0');
		nodeShadow.setStyle('left','0');
		nodeShadow.setStyle('display','none');
		nodeShadow.setStyle('zIndex','40000');
		Y.one('body').prepend(nodeShadow);
	}
	nodeShadow.setStyle('opacity',0.7);
	nodeShadow.show();
	nodeShadow.on('click',fnClick);
}
function hideShadow(bool)
{
	nodeShadow.hide(bool);
	//window.setTimeout(function(){nodeShadow.remove();},500);
}
function centerLayer(pTarget)
{
	node = defineNode(pTarget);
	node.setStyle('visibility','hidden');
	node.show();
	width = node.get('scrollWidth') - 30;
	height = node.get('clientHeight');
	node.hide();
	node.setStyle('visibility','visible');
	halbWidth = Math.ceil(width/2);
	halbHeight = Math.ceil(height/2);
	node.setStyle('position','fixed');
	node.setStyle('width',width);
	node.setStyle('height',height);
	node.setStyle('left','50%');
	node.setStyle('top','50%');
	node.setStyle('marginLeft',-halbWidth);
	node.setStyle('marginTop',-halbHeight);
	node.setStyle('zIndex','40001');
}
layersShadowActivated = new Array();
var imgClose = new Image();
imgClose.src = '/image/dialog-close.png';
function layerShadow(pTarget,fnStart,fnEnd,grosseK)
{
	node = defineNode(pTarget);
	if ( 1 )
	{
		fnClose = function()
		{
			node = defineNode(layersShadowActivated[layersShadowActivated.length-1]);
			node.hide();
			//nodeClose.remove();
			hideShadow(true);
			if ( !empty(fnEnd) )
			{
				fnEnd();
			}
		}
		if ( !in_array(node.get('id'),layersShadowActivated) )
		{
			centerLayer(pTarget);
			array_push(layersShadowActivated,node.get('id'));
			//nodeClose = Y.Node.create('<a href="javascript:void(0);" class="close"><span>&nbsp;</span></a>');
			//nodeClose.setStyle('position','absolute');
			//nodeClose.setStyle('top','0px');
			//nodeClose.setStyle('right','0px');
			//nodeClose.setStyle('width','32px');
			//nodeClose.setStyle('cursor','pointer');
			//nodeClose.on('click',fnClose);
			//node.append(nodeClose);
		}
		showShadow(fnClose);
		
		if ( Y.all('.close') )
		{
		    Y.all('.close').on('click',fnClose);
		}
		node.show(true);
		if ( !empty(fnStart) )
		{
			fnStart();
		}
	}
}
var nodePreloader;
var imgPreloader = new Image();
imgPreloader.src = '/media/darstellungen/109.png';
function showPreloader()
{
	nodePreloader = Y.one('#transaction');
	if ( !Y.Lang.isObject(nodePreloader) )
	{
		nodePreloader = Y.Node.create('<div id="transaction" style="display:none;text-align:center;"><img src="'+imgPreloader.src+'"></div>');
		Y.one('body').prepend(nodePreloader);
	}
	showShadow(null);
	centerLayer(nodePreloader);
	nodePreloader.show();
}
function hidePreloader()
{
	nodePreloader = Y.one('#transaction');
	nodePreloader.hide();
	hideShadow();
}
function toggleLayer(id)
{
	node = Y.one('#'+id);
	if ( document.getElementById(id).style.visibility == 'hidden' )
	{
		node.setStyle('visibility','visible');
	}
	else if ( document.getElementById(id).style.visibility == 'visible' )
	{
		node.setStyle('visibility','hidden');
	}
	else
	{
		if ( node.getStyle('display') != 'block' && node.getStyle('display') != 'inline' )
		{
		    showLayer(id);
			
			
		}
		else
		{
			hideLayer(id);
		}
	}
}
function defineNode(pTarget)
{
	switch(typeof(pTarget))
	{
		case 'string':
			id = (pTarget.indexOf('#') === 0) ? pTarget : '#' + pTarget;
		break;
		case 'object':
			if(!Y.Lang.isUndefined(pTarget._node))
			{
				id = (pTarget.get('id') === '') ? Y.guid(): pTarget.get('id');
				pTarget.set('id', id);
				id = (id.indexOf('#') === 0) ? id : '#' + id;
			}
			else if(!Y.Lang.isUndefined(pTarget.nodeName))
			{
				id = (pTarget.id === '') ? Y.guid(): pTarget.id;
				Y.one(pTarget).set('id',id);
				id = (id.indexOf('#') === 0) ? id : '#' + id;
			}
		break;
		default:
			return false;
		break;
	}
	node = Y.one(id);
	return node;
}
function showLayer(pTarget)
{
	node = defineNode(pTarget);
	node.setStyle('opacity','0');
	node.show(true);
	if ( node.getStyle('position') == 'absolute' || node.getStyle('position') == 'fixed' )
	{
		if ( Y.one('window').get('winHeight') - Y.one('window').get('scrollY') > node.getY() )
		{
			Y.one('window').set('scrollTop',Y.one('window').get('winHeight') - Y.one('window').get('scrollY')+20);
		}
	}
}
function hideLayer(pTarget)
{
	node = defineNode(pTarget);
	node.hide(true);
}
function toggleCheckbox(id)
{
	if ( document.getElementById(id).checked == true && document.getElementById(id).type != 'radio' )
	{
		Y.one('#'+id).set('checked',false);
	}
	else
	{
		Y.one('#'+id).set('checked','checked');
	}
}
function checkboxToggle(id)
{
	return toggleCheckbox(id);
}

function getObjectProps(obj, objName)
{
    var result = "";
    for (var i in obj) result += objName + "." + i + " = " + obj[i] + "<BR>\n";
    return result;
}
function addHandler(object, event, handler)
{
	if ( typeof object.addEventListener != 'undefined' )
	{
		object.addEventListener(event, handler, false);
	}
	else if ( typeof object.attachEvent != 'undefined' )
	{
		object.attachEvent('on' + event, handler);
	}
	else
	{
		throw "Incompatible browser";
	}
}
function domReady(f)
{
	if ( domReady.done )
	{
		return f();
	}
	if ( domReady.timer )
	{
		domReady.ready.push(f);
	}
	else
	{
		if ( window.addEventListener )
		{
			window.addEventListener('load',isDOMReady,false);
		}
		else if (window.attachEvent)
		{
			window.attachEvent('onload',isDOMReady);
		}
		domReady.ready=[f];
		domReady.timer=setInterval(isDOMReady,13);
	}
}
function isDOMReady()
{
	if ( domReady.done )
	{
		return false;
	}
	if ( document && document.getElementsByTagName && document.getElementById && document.body )
	{
		clearInterval(domReady.timer);
		domReady.timer=null;
		for (i=0;i<domReady.ready.length;i++) domReady.ready[i]();
		domReady.ready=null;
		domReady.done=true;
	}
}

// Tiny MCE functions
var tinyMCEmode = true;
function toggleEditorMode(forceActiviert,tinyMCEIndex) {
	if ( thisTinyMCEId != '' )
	{
		if ( tinyMCEIndex > 0 )
		{
			tinyMCEIdSelected = tinyMCEId[tinyMCEIndex];
		}
		else
		{
			tinyMCEIdSelected = tinyMCEId[0];	
		}
		try {
			if(tinyMCEmode&&!forceActiviert) {
			tinyMCE.execCommand('mceRemoveControl', false, tinyMCEIdSelected);
			tinyMCEmode = false;
			} else {
			initMCE(tinyMCEIdSelected);
			tinyMCEmode = true;
			}
		} catch(e) {
			//error handling
		}
	}
	else
	{
		tinyMCEmode = false;	
	}
	return tinyMCEmode;
}

var thisTinyMCEId = '';
tinyMCEId = new Array();
var tineMCE = '';
function initMCE(elementId,buttonSet,nichtAktiviert)
{
	domReady(function(){
		var msh = document.createElement('div');
		thisTinyMCEId = elementId;
		tinyMCEId.push(thisTinyMCEId);
		msh.className = "mceStatusHidden";
		if ( nichtAktiviert == 1 )
		{
			window.setTimeout(function(){tinyMCE.activeEditor.focus();toggleEditorMode('',tinyMCEId[tinyMCEId.length - 1]);},500);	
		}
		else
		{
		if ( buttonSet == 'light' )
		{
			var buttons = {
			theme_advanced_buttons1 : "save,|,bold,italic,underline,strikethrough,attribs,link,|,formatselect",
				theme_advanced_buttons2 : "justifyleft,justifycenter,justifyright,justifyfull,|,image,images,|,code",
				theme_advanced_buttons3 : "",
				theme_advanced_buttons4 : ""
				};
		}
		else
		{
			var buttons = {
			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
				theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,images,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
				theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
				theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage"
				};
		}
		var general = {
			// General options
				mode : "exact",
				elements : elementId,
				theme : "advanced",
				plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,images"
		};
		var theme = {
			// Theme options
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : true,
				theme_advanced_resize_horizontal : false,
				file_browser_callback: "imgLibManager.open",
				relative_urls : true
		};
		var skin = {
			// Skin options
				skin : "o2k7",
				skin_variant : "silver"
		};
		var links = {
			relative_urls : false,
			// Example content CSS (should be your site CSS)
				content_css : "/styleMCE.css,/media/tinyMCE.css",
				// Drop lists for link/image/media/template dialogs
				template_external_list_url : "js/template_list.js",
				external_link_list_url : "js/link_list.js",
				external_image_list_url : "js/image_list.js",
				media_external_list_url : "js/media_list.js"
		};
		var templateValues = {
			// Replace values for the template plugin
				template_replace_values : {
					username : "Some User",
					staffid : "991234"
				}
		};
		config = Y.merge(buttons, general, theme, skin, links, templateValues)
			tinyMCE.init(config);
			imgLibManager.init({url: mediaUrl+'script/imglib/index.html'});
			/*
			tinyMCE.init
			({
				mode : "exact",
				elements : elementId,
				theme : "advanced",
				skin : "default",
				content_css : systemUrl + "css.css",
				theme_advanced_resizing : true,
				theme_advanced_resize_horizontal : false,
				theme_advanced_resizing_min_height : 150,
				theme_advanced_toolbar_location : "top",
				theme_advanced_statusbar_location : "bottom",
				relative_urls : false,
				document_base_url : systemUrl,
				plugins: "table,xhtmlxtras,images",
				theme_advanced_buttons1 : "bold,italic,underline,strikethrough,attribs,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist",
				theme_advanced_buttons2 : "undo,redo,|,image,images,|,link,|,formatselect,hr,|,sub,sup,|,charmap,|,code,removeformat",
				theme_advanced_buttons3 : "tablecontrols",
				language : "ru"
			});
			*/
			window.setTimeout(function(){if(0){tinyMCE.activeEditor.focus();}},500);
			
		}
	});
}


// similar PHP functions
function trim (str, charlist)
{
	var whitespace, l = 0, i = 0;
	str += '';
	if (!charlist)
	{
		whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
	}
	else
	{
		charlist += '';
		whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
	}
	l = str.length;
	for (i = 0; i < l; i++)
	{
		if ( whitespace.indexOf(str.charAt(i) ) === -1)
		{
			str = str.substring(i);
			break;
		}
	}
	l = str.length;
	for (i = l - 1; i >= 0; i--)
	{
		if ( whitespace.indexOf(str.charAt(i) ) === -1 )
		{
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
function strtolower(str)
{
	return (str+'').toLowerCase();
}
function empty (mixed_var) {
    // !No description available for empty. @php.js developers: Please update the function summary text file.
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/empty
    // +   original by: Philippe Baumann
    // +      input by: Onno Marsman
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: LH
    // +   improved by: Onno Marsman
    // +   improved by: Francesco
    // +   improved by: Marc Jansen
    // +   input by: Stoyan Kyosev (http://www.svest.org/)
    // *     example 1: empty(null);
    // *     returns 1: true
    // *     example 2: empty(undefined);
    // *     returns 2: true
    // *     example 3: empty([]);
    // *     returns 3: true
    // *     example 4: empty({});
    // *     returns 4: true
    // *     example 5: empty({'aFunc' : function () { alert('humpty'); } });
    // *     returns 5: false
    var key;
 
    if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || typeof mixed_var === 'undefined') {
        return true;
    }
 
    if (typeof mixed_var == 'object') {
        for (key in mixed_var) {
            return false;
        }
        return true;
    }
 
    return false;
}
function is_array(arr)
{
        return typeof arr === 'object' && typeof arr.length === 'number' && !(arr.propertyIsEnumerable('length')) && typeof arr.splice === 'function';
};
function ohneLeere(daten)
{
	datenOhneLeere = new Array();
	if ( is_array(daten) )
	{
		for ( i = 0; i < daten.length; i++ )
		{
			if ( !is_array(daten[i]) && trim(daten[i]) == '' ) continue;
			array_push(datenOhneLeere,daten[i]);
		}
	}
	return datenOhneLeere;
}
function array_push ( array ) {
    // Pushes elements onto the end of the array  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/array_push
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_push(['kevin','van'], 'zonneveld');
    // *     returns 1: 3
    var i, argv = arguments, argc = argv.length;

    for (i=1; i < argc; i++){
        array[array.length++] = argv[i];
    }

    return array.length;
}
function explode( delimiter, string, limit )
{
	var emptyArray = { 0: '' };
	if ( arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined' )
	{
		return null;
	}
	if ( delimiter === '' || delimiter === false || delimiter === null )
	{
		return false;
	}
	if ( typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object' )
	{
		return emptyArray;
	}
	if ( delimiter === true )
	{
		delimiter = '1';
	}
	if (!limit)
	{
		return string.toString().split(delimiter.toString());
	}
	else
	{
		var splitted = string.toString().split(delimiter.toString());
		var partA = splitted.splice(0, limit - 1);
		var partB = splitted.join(delimiter.toString());
		partA.push(partB);
		return partA;
	}
}
function in_array(needle, haystack, argStrict)
{
	var found = false, key, strict = !!argStrict;
	for (key in haystack)
	{
		if ( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) )
		{
			found = true;
			break;
		}
	}
	return found;
}
function array_keys (input, search_value, argStrict) {
    // Return just the keys from the input array, optionally only for the specified search_value  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/array_keys
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: jd
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: array_keys( {firstname: 'Kevin', surname: 'van Zonneveld'} );
    // *     returns 1: {0: 'firstname', 1: 'surname'}
    var search = typeof search_value !== 'undefined',
        tmp_arr = [],
        strict = !!argStrict,
        include = true,
        key = '';
 
    for (key in input) {
        if (input.hasOwnProperty(key)) {
            include = true;
            if (search) {
                if (strict && input[key] !== search_value) {
                    include = false;
                }
                else if (input[key] != search_value) {
                    include = false;
                }
            }
 
            if (include) {
                tmp_arr[tmp_arr.length] = key;
            }
        }
    }
 
    return tmp_arr;
}
function array_splice (arr, offst, lgth, replacement)
{
	var checkToUpIndices = function (arr, ct, key)
	{
		if (arr[ct] !== undefined)
		{
			var tmp = ct;
			ct += 1;
			if (ct === key)
			{
				ct += 1;
			}
			ct = checkToUpIndices(arr, ct, key);
			arr[ct] = arr[tmp];
			delete arr[tmp];
		}
		return ct;
	}
	if ( replacement && !(typeof replacement === 'object') )
	{
		replacement = [replacement];
	}
	if ( lgth === undefined )
	{
		lgth = offst >= 0 ? arr.length - offst : -offst;
	}
	else if ( lgth < 0 )
	{
		lgth = (offst >= 0 ? arr.length - offst : -offst)  + lgth;
	}
	if ( !(arr instanceof Array) )
	{
		var lgt = 0, ct = -1, rmvd = [], rmvdObj = {}, repl_ct=-1, int_ct=-1;
		var returnArr = true, rmvd_ct = 0, rmvd_lgth = 0, key = '';
		for (key in arr)
		{
			lgt += 1;
		}
		offst = (offst >= 0) ? offst : lgt + offst;
		for (key in arr)
		{
			ct += 1;
			if ( ct < offst )
			{
				if ( is_int(key) )
				{
					int_ct += 1;
					if (parseInt(key, 10) === int_ct)
					{
						continue;
					}
					checkToUpIndices(arr, int_ct, key);
					arr[int_ct] = arr[key];
					delete arr[key];
				}
				continue;
			}
			if ( returnArr && is_int(key) )
			{
				rmvd.push(arr[key]);
				rmvdObj[rmvd_ct++] = arr[key];
			}
			else
			{
				rmvdObj[key] = arr[key];
				returnArr    = false;
			}
			rmvd_lgth += 1;
			if ( replacement && replacement[++repl_ct] )
			{
				arr[key] = replacement[repl_ct]
			}
			else
			{
				delete arr[key];
			}
		}
		return returnArr ? rmvd : rmvdObj;
	}
	if (replacement)
	{
		replacement.unshift(offst, lgth);
		return Array.prototype.splice.apply(arr, replacement);
	}
	return arr.splice(offst, lgth);
}
function array_slice(arr, offst, lgth, preserve_keys)
{
	var key = '';
	if ( !(arr instanceof Array) || (preserve_keys && offst != 0))
	{
		var lgt =0, newAssoc = {};
		for (key in arr)
		{
			lgt += 1;
			newAssoc[key] = arr[key];
		}
		arr = newAssoc;
		offst = (offst < 0) ? lgt + offst : offst;
		lgth  = lgth == undefined ? lgt : (lgth < 0) ? lgt + lgth - offst : lgth;
		var assoc = {};
		var start = false, it=-1, arrlgth=0, no_pk_idx=0;
		for (key in arr)
		{
			++it;
			if ( arrlgth >= lgth )
			{
				break;
			}
			if ( it == offst )
			{
				start = true;
			}
			if ( !start )
			{
				continue;
			}
			++arrlgth;
			if ( is_int(key) && !preserve_keys )
			{
				assoc[no_pk_idx++] = arr[key];
			}
			else
			{
				assoc[key] = arr[key];
			}
		}
	return assoc;
	}
	if ( lgth === undefined )
	{
		return arr.slice(offst);    
	}
	else if ( lgth >= 0 )
	{
		return arr.slice(offst, offst + lgth);
	}
	else
	{
		return arr.slice(offst, lgth);
	}
}
function implode( glue, pieces )
{
    return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}
function array_search( needle, haystack, argStrict )
{
	var strict = !!argStrict;
	var key = '';
	for (key in haystack)
	{
		if ( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) )
		{
			return key;
		}
	}
	return false;
}
function str_replace(search, replace, subject)
{
    var s = subject;
    var ra = r instanceof Array, sa = s instanceof Array;
    var f = [].concat(search);
    var r = [].concat(replace);
    var i = (s = [].concat(s)).length;
    var j = 0;
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    }
    return sa ? s : s[0];
}
function ceil(value) {
    // Returns the next highest integer value of the number  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/ceil
    // +   original by: Onno Marsman
    // *     example 1: ceil(8723321.4);
    // *     returns 1: 8723322
    return Math.ceil(value);
}

/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;   /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = "";  /* base-64 pad character. "=" for strict RFC compliance   */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */

function hex_md5(s)    { return rstr2hex(rstr_md5(str2rstr_utf8(s))); }
function b64_md5(s)    { return rstr2b64(rstr_md5(str2rstr_utf8(s))); }
function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); }
function hex_hmac_md5(k, d)
  { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
function b64_hmac_md5(k, d)
  { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); }
function any_hmac_md5(k, d, e)
  { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
  


/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test()
{
  return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
}

/*
 * Calculate the MD5 of a raw string
 */
function rstr_md5(s)
{
  return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
}

/*
 * Calculate the HMAC-MD5, of a key and some data (raw strings)
 */
function rstr_hmac_md5(key, data)
{
  var bkey = rstr2binl(key);
  if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
  return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
}

/*
 * Convert a raw string to a hex string
 */
function rstr2hex(input)
{
  try { hexcase } catch(e) { hexcase=0; }
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var output = "";
  var x;
  for(var i = 0; i < input.length; i++)
  {
    x = input.charCodeAt(i);
    output += hex_tab.charAt((x >>> 4) & 0x0F)
           +  hex_tab.charAt( x        & 0x0F);
  }
  return output;
}

/*
 * Convert a raw string to a base-64 string
 */
function rstr2b64(input)
{
  try { b64pad } catch(e) { b64pad=''; }
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var output = "";
  var len = input.length;
  for(var i = 0; i < len; i += 3)
  {
    var triplet = (input.charCodeAt(i) << 16)
                | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
                | (i + 2 < len ? input.charCodeAt(i+2)      : 0);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > input.length * 8) output += b64pad;
      else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
    }
  }
  return output;
}

/*
 * Convert a raw string to an arbitrary string encoding
 */
function rstr2any(input, encoding)
{
  var divisor = encoding.length;
  var i, j, q, x, quotient;

  /* Convert to an array of 16-bit big-endian values, forming the dividend */
  var dividend = Array(Math.ceil(input.length / 2));
  for(i = 0; i < dividend.length; i++)
  {
    dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
  }

  /*
   * Repeatedly perform a long division. The binary array forms the dividend,
   * the length of the encoding is the divisor. Once computed, the quotient
   * forms the dividend for the next step. All remainders are stored for later
   * use.
   */
  var full_length = Math.ceil(input.length * 8 /
                                    (Math.log(encoding.length) / Math.log(2)));
  var remainders = Array(full_length);
  for(j = 0; j < full_length; j++)
  {
    quotient = Array();
    x = 0;
    for(i = 0; i < dividend.length; i++)
    {
      x = (x << 16) + dividend[i];
      q = Math.floor(x / divisor);
      x -= q * divisor;
      if(quotient.length > 0 || q > 0)
        quotient[quotient.length] = q;
    }
    remainders[j] = x;
    dividend = quotient;
  }

  /* Convert the remainders to the output string */
  var output = "";
  for(i = remainders.length - 1; i >= 0; i--)
    output += encoding.charAt(remainders[i]);

  return output;
}

/*
 * Encode a string as utf-8.
 * For efficiency, this assumes the input is valid utf-16.
 */
function str2rstr_utf8(input)
{
  var output = "";
  var i = -1;
  var x, y;

  while(++i < input.length)
  {
    /* Decode utf-16 surrogate pairs */
    x = input.charCodeAt(i);
    y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
    if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
    {
      x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
      i++;
    }

    /* Encode output as utf-8 */
    if(x <= 0x7F)
      output += String.fromCharCode(x);
    else if(x <= 0x7FF)
      output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
                                    0x80 | ( x         & 0x3F));
    else if(x <= 0xFFFF)
      output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
                                    0x80 | ((x >>> 6 ) & 0x3F),
                                    0x80 | ( x         & 0x3F));
    else if(x <= 0x1FFFFF)
      output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
                                    0x80 | ((x >>> 12) & 0x3F),
                                    0x80 | ((x >>> 6 ) & 0x3F),
                                    0x80 | ( x         & 0x3F));
  }
  return output;
}

/*
 * Encode a string as utf-16
 */
function str2rstr_utf16le(input)
{
  var output = "";
  for(var i = 0; i < input.length; i++)
    output += String.fromCharCode( input.charCodeAt(i)        & 0xFF,
                                  (input.charCodeAt(i) >>> 8) & 0xFF);
  return output;
}

function str2rstr_utf16be(input)
{
  var output = "";
  for(var i = 0; i < input.length; i++)
    output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
                                   input.charCodeAt(i)        & 0xFF);
  return output;
}

function is_object (mixed_var) {
    // Returns true if variable is an object  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/is_object
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   improved by: Michael White (http://getsprink.com)
    // *     example 1: is_object('23');
    // *     returns 1: false
    // *     example 2: is_object({foo: 'bar'});
    // *     returns 2: true
    // *     example 3: is_object(null);
    // *     returns 3: false
    if (mixed_var instanceof Array) {
        return false;
    } else {
        return (mixed_var !== null) && (typeof(mixed_var) == 'object');
    }
}

/*
 * Convert a raw string to an array of little-endian words
 * Characters >255 have their high-byte silently ignored.
 */
function rstr2binl(input)
{
  var output = Array(input.length >> 2);
  for(var i = 0; i < output.length; i++)
    output[i] = 0;
  for(var i = 0; i < input.length * 8; i += 8)
    output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
  return output;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2rstr(input)
{
  var output = "";
  for(var i = 0; i < input.length * 32; i += 8)
    output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
  return output;
}

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length.
 */
function binl_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);
}

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}
/*****************************************************************************************************/

if (typeof(HTMLElement) != "undefined")
{
	 var _emptyTags = {
		"IMG": true,
		"BR": true,
		"INPUT": true,
		"META": true,
		"LINK": true,
		"PARAM": true,
		"HR": true
	 };
 
	 HTMLElement.prototype.__defineGetter__("outerHTML", function () {
		var attrs = this.attributes;
		var str = "<" + this.tagName;
		for (var i = 0; i < attrs.length; i++)
		   str += " " + attrs[ i ].name + "=\"" + attrs[ i ].value + "\"";
	 
		if (_emptyTags[this.tagName])
		   return str + ">";
	 
		return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	 });
 
	 HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var df = r.createContextualFragment(sHTML);
		this.parentNode.replaceChild(df, this);
	 });
}
