// ==========================================================================================
// HISTORY
// Version	Date		Who	What
// 3.5		30.10.03	ul	methode lock added (ul)
// 3.4		11.09.03	ul	defaultValue added
// 3.3		21.08.03	ul	pagetimer added
// 3.21		30.06.03 	ul	ts2date extended (takes now parameter n,N,h,H,s,S)
// 3.2		08.05.03	ul	getRadioValue added, checkboxChecker changed. Now it can alsow handle multiple select
// 3.11		07.03.03	ul	autoExtend (lets show and hide parts of page)
// 3.0		03.03.03	ul	resizeTextarea (new method to provide possibilite to resize Textareas dynamically)
// 2.9		26.02.03	ul	checkRadios takes third parameter (which button shall be selected if no value given)
// 2.8		07.01.02	nst	updated adjustDate: small bugfixes
// 2.7		07.11.01	ul	selectSelecter now accepts defaut values and clears all items that are not in the parameter (trigger od defaultvalue)
// 2.6		02.11.01	ul	checkRadios now accepts default values
//						nst	fixed formclearer: opera compatibility, scrolltop-fix, only text/textarea/pw-fields get focused
// 2.5		01.11.01	sh	added disableField("formname","fieldname",delete) (if delete=true then values will be deleted)
// 2.4		23.10.01	ul	checkboxChecker extended
// 2.3		22.10.01	ul	getIndex() added
// 2.2		13.09.01	sh	formClearer only deletes value if first and last! chars are %
// 2.1		16.08.01 	sh  	changed chekboxChecker to handle values different from 0 and 1
// 2.0		08.08.01 	lp  	function checkLogout
// 1.1		23.07.01 	ul	selectSelecter return selectedIndex and formClearer jumps to the top
// 1.0		13.07.01
// ==========================================================================================

var STANDARD_TIME_PATTERN = "%D.%M.%Y";

// ==========================================================================================

/**
 * indexOf is a recent addition to the ECMA-262 standard; as such it may not be present in all browsers.
 * See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/IndexOf
 */
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
        "use strict";
        if (this == null) {
            throw new TypeError();
        }
        var t = Object(this);
        var len = t.length >>> 0;
        if (len === 0) {
            return -1;
        }
        var n = 0;
        if (arguments.length > 0) {
            n = Number(arguments[1]);
            if (n != n) { // shortcut for verifying if it's NaN
                n = 0;
            } else if (n != 0 && n != Infinity && n != -Infinity) {
                n = (n > 0 || -1) * Math.floor(Math.abs(n));
            }
        }
        if (n >= len) {
            return -1;
        }
        var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
        for (; k < len; k++) {
            if (k in t && t[k] === searchElement) {
                return k;
            }
        }
        return -1;
    }
}

// call wherever you like on your page
// radio	: radio-button object
// purpose	: gets the value of the current selected radio
function getRadioValue(radio)
{
	for (var i=0;i<radio.length;i++)
	{
		if(radio[i].checked==true) return radio[i].value;
	}
}

// call wherever you like on your page
// id		: id of html-element that should be hidden / shown (e.g. table)
// showhtml	: html that should be shown when element is hidden
// showtitle: title-tag for html
// hidehtml	: see above
// start	: show | hidden (shown is default)
// example for call: <span id="myid">Hier kommt die gewünscht Erweiterung</span><script>autoExtend("myid","anzeigen","Erweiterung anzeigen","verstecken","Erweiterung verstecken")
var hiddenIds = new Array();
function autoExtend(id,showhtml,showtitle,hidehtml,hidetitle,start)
{
 if(typeof(icms_lib_ar)=="undefined")
 {
 	icms_lib_ar = new Array();
 }
 if(showtitle=="") showtitle=icms_lib_ar[0]
 if(hidetitle=="") hidetitle=icms_lib_ar[1]
 if(start=="hidden")
 {
	hiddenIds[hiddenIds.length] = id;
 	first = "";
 	second = "display:none;";
 }
 else
 {
 	second = "";
 	first = "display:none;";
 }
// Zeile 51: "erweiterte Ansicht einblenden";
// Zeile 52: "erweiterte Ansicht ausblenden";

 var html = "<span style=\""+first+"cursor:hand\" id=\""+id+"_showhtml\" title=\""+showtitle+"\" onclick=\"this.style.display='none';var myobj=document.getElementById('"+id+"_hidehtml');myobj.style.display='inline';myobj=document.getElementById('"+id+"');myobj.style.display='inline';\">"+showhtml+"</span>";
 document.write(html);
 html = "<span style=\""+second+"cursor:hand\" id=\""+id+"_hidehtml\" title=\""+hidetitle+"\" onclick=\"this.style.display='none';var myobj=document.getElementById('"+id+"_showhtml');myobj.style.display='inline';myobj=document.getElementById('"+id+"');myobj.style.display='none';\">"+hidehtml+"</span>";
 document.write(html);
}

// call after every textarea that needs resized dynamically
// rows		: number of rows in second view (first will be taken from html)
// cols		: number of cols in second view
// first	: html-code to be rendered in first view
// firstinfo: Text in title and status
// second	: html-code to be rendered in second view
// secondinfo: Text in title and status
// first will be rendered on startup
// example for call: <textarea>blabla</textarea><script>resizeTextares(20,50,"-","+")
function resizeTextarea(rows,cols,first,firstinfo,second,secondinfo)
{
	var myForm = document.forms.length-1;
	var myIndex = document.forms[myForm].elements.length-1;
	var myTextarea = document.forms[myForm].elements[myIndex];
	myTextarea.view = "first";
	myTextarea.rowArray = new Array(myTextarea.rows,rows);
	myTextarea.colArray = new Array(myTextarea.cols,cols);
	// generate output
	html1 = "<span style=\"cursor:hand\" title=\""+firstinfo+"\" onmouseover=\"status='"+firstinfo+"';return true\" onmouseout=\"status='';\" onclick=\"toggleTextareaView("+myForm+","+myIndex+","+1+")\">"+first+"</span>";
	html2 = "<span style=\"cursor:hand\" title=\""+secondinfo+"\" onmouseover=\"status='"+secondinfo+"';return true\" onmouseout=\"status='';\" onclick=\"toggleTextareaView("+myForm+","+myIndex+","+0+")\">"+second+"</span>";
	myTextarea.view = new Array(html1,html2);
	document.write("<span id=\""+myForm+"_"+myIndex+"\">"+myTextarea.view[0]+"</span>");

}
function toggleTextareaView(myForm,myIndex,newView)
{
	myElement = document.forms[myForm].elements[myIndex];

	// set new properties
	myElement.rows = myElement.rowArray[newView];
	myElement.cols = myElement.colArray[newView];

	// set new switch
	myObj = document.getElementById(myForm+"_"+myIndex);
	myObj.innerHTML=myElement.view[newView];
}



// call after every checkbox that needs to be checked or not according to the state of trigger
// trigger must match to value of checkbox to select checkbox
// example for call: <input type=checkbox ....><script>checkboxChecker("%module.criteria%")</script>
// v2 [8.5.03]: trigger can also be a comma-separated string of values. If there are several checkboxes with the same name, all of them will be selected which value matches one of the values in the string
function checkboxChecker(trigger,def)
{
	myForm = document.forms[document.forms.length-1];
	myElement = myForm.elements[myForm.elements.length-1];
	if(myForm.elements[myElement.name].length>1)
	{
		// split values into array
		if(trigger.substr(0,1)=='%')
			if(def) var myValues = def.toString().split(",");
			else return;
		else
			var myValues = trigger.split(",");
		var trueVals = new Array();
		for( var i = 0;i<myValues.length;i++)
			trueVals[myValues[i]] = true;

		for( var i = 0;i<myForm.elements[myElement.name].length;i++)
		{
			if(myForm.elements[myElement.name][i].type=="checkbox")
			{
				myForm.elements[myElement.name][i].checked = trueVals[myForm.elements[myElement.name][i].value];
			}
		}
	}
	else
	{
		if(trigger.substr(0,1)=='%')
		{
			if(def) myElement.checked=true;
		 	return;
		}
		myElement.checked=(myElement.value==trigger);
	}
}

function iCheckboxChecker(checkboxName, values, defaultValues)
{
	if(values.substr(0,1) == '%')
	{
		if(defaultValues) values = defaultValues;
		else return 0;
	}
	
	checkboxes = document.getElementsByName(checkboxName);
	items = values.split(",");
	for(j=0; j<checkboxes.length; j++)
	{
		checkboxes[j].checked=false;
	}
	for(i=0;i<items.length;i++)
	{
		for(j=0;j<checkboxes.length;j++)
		{
			if(checkboxes[j].value==items[i])
			{
				checkboxes[j].checked=true;
			}
		}	
	} 
}

// returns the index of the form-elements that this function is places behind.
function getIndex()
{
	return document.forms[document.forms.length-1].elements.length-1;
}

// sets a startvalue of any input-type if current value starts with %
function defaultValue(startvalue,setOnEmptyField)
{
	myEl = document.forms[document.forms.length-1].elements[getIndex()];
	if ((typeof setOnEmptyField != 'undefined') && (setOnEmptyField == true) && (myEl.value == ''))
	{
		myEl.value = startvalue;
	}
	else if (myEl.value.substr(0,1) == "%")
	{
		myEl.value = startvalue;
	}
}

// call after every selectbox whitch items need to be selected according to the state of trigger
// trigger can be one or more values (comma-separated). Every item with the same value as on of the triggers will be selected
// example for call: <select ....><script>selectSelecter("%module.criteria%")</script>


function selectSelecter(trigger, defaultvalue)
{
	var lastForm, lastInput, values, i;

	if(trigger.substr(0, 1) == '%') {
		if(defaultvalue) {
			trigger = defaultvalue;
		} else {
			return 0;
		}
	}

	if (document.forms.length == 0) {
		return 0;
	}

	// find the last select element, otherwise return 0
	lastForm = document.forms[document.forms.length - 1];
	lastInput = lastForm.elements[lastForm.length - 1];

	if ( ! lastInput || ! lastInput.options) {
		return 0;
	}

	// unselect all options
	for(i = 0; i < lastInput.options.length; i++) {
		lastInput.options[i].selected = false;
	}

	values = trigger.split(",");

	for(i = 0; i < lastInput.options.length; i++) {
		if (values.indexOf(lastInput.options[i].value) != -1) {
			lastInput.options[i].selected = true;
		}
	}

	return Math.max(lastInput.selectedIndex, 0);
}

function iSelectSelecter(selectID, values, defaultValues)
{
	if(values.substr(0,1) == '%')
	{
		if(defaultValues) values = defaultValues;
		else return 0;
	}
	var selectBox = document.getElementById(selectID);
	items = values.split(",");
	for(j=0; j<selectBox.options.length; j++)
	{
		selectBox.options[j].selected=false;
	}
	for(i=0;i<items.length;i++)
	{
		for(j=0;j<selectBox.options.length;j++)
		{
			if(selectBox.options[j].value==items[i])
			{
				selectBox.options[j].selected = true;
			}
		}	
	}
	if(selectBox.selectedIndex >= 0)
	{
		return selectBox.selectedIndex;
	}
	else
	{
		return 0;
	}
}

// call after every inputfield whitch property needs to be updates
// example for call: <input ....><script>setProperty("name","gugus")</script>
function setProperty(prop,value)
{
	myfield=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	eval("myfield."+prop+"="+value+";");
}

// call after every inputfield that shouldnt be touched by the formClearer
// example for call: <input ....><script>lock()</script>
function lock()
{
	setProperty("locked",true);
}


// call after the last radiobutten whitch items need to be selected according to the state of trigger
// trigger must be one of the values of the radio-buttons.
// defaultvalue can be null or nothing or value which corresponding button will be selected
// defaultselected can be number from 0 - ...; if defaultvalue or trigger not found, button number 'defaulselected' will be set
// example for call: <input type="radio" value="pic_ico_graph.gif" name="content.data[type]><script>checkRadios("%module.criteria%")</script>

function checkRadios(trigger,defaultvalue,defaultselected)
{
	myselect=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	myradio = document.forms[document.forms.length-1].elements[myselect.name];

	if(trigger.substr(0,1)=='%')
	{
		 if(typeof(defaultvalue)!="undefined") trigger=defaultvalue;
		 else
		 if(typeof(defaultselected)=="undefined")
			return;
	}

	for(i=0;i<myradio.length;i++)
	{
		if(myradio[i].value==trigger)
		{
			myradio[i].checked=true;
			return;
		}

	}
	if(typeof(defaultselected)!="undefined")
	{
		if(typeof(myradio[defaultselected])!="undefined") myradio[defaultselected].checked=true;
	}

}

function iCheckRadios(radioName, value)
{
	var radio = document.getElementsByName(radioName);	
	for(var i = 0; i < radio.length; i++)
	{
		if(radio[i].value == value)
		{
			radio[i].checked = true;
			return;
		}	
	}
}


//-----------------------------------------------------------------------------
// formClearer()
//=============================================================================
// Descr: 	Scans all fields of all forms of the current document and clears
// 			them if value starts AND ends with '%'.
//
// Insert the following code into your html-file AFTER the </body>-tag:
//	<script>
//	<!--
//	formClearer();
//	if( -1 != navigator.appName.toLowerCase().indexOf("opera") )
//	{	setTimeout( "formClearer();", 500 );	}	// Opera needs this!
//	// -->
//	</script>
//-----------------------------------------------------------------------------
function formClearer()
{
	var i = 0;
	var j = 0;
	for(i=document.forms.length-1;i>=0;i--)
	{
		if(document.forms[i].elements.length > 0)
		{
			for(j=document.forms[i].elements.length-1;j>=0;j--)
			{
				if( typeof(document.forms[i].elements[j].locked)=="undefined")
				{
					if(	document.forms[i].elements[j].value )
					{
						//getAttribute returns untrimmed value for inputs with limited length, but will return null
						//for textareas and selects, as they do not have such an attribute
						val = document.forms[i].elements[j].getAttribute('value');
						//if getAttribute returned smth empty - lets use the value property instead
						if(!val)		
						{
							val = document.forms[i].elements[j].value;
						}
						if(val.search(/^\%([^ ,:;]*)\%$/)>-1)
						{
							document.forms[i].elements[j].value="";
							if ( (
									document.forms[i].elements[j].type=="text"
									|| document.forms[i].elements[j].type=="textarea"
									|| document.forms[i].elements[j].type=="password"
								 )
								&& !document.forms[i].elements[j].disabled)
							{
								try {
									// alert("fs - start: " + document.forms[i].elements[j].name);
									document.forms[i].elements[j].focus();
									document.forms[i].elements[j].blur();
									// alert("fs - end: " + document.forms[i].elements[j].name);
								}
								catch(e)
								{
									// IE doesn't allow focus to hidden element, we have to catch & destroy this exception
								}
							}
						}
					}
				}
			}
		}
	}
	i = 0;
	j = 0;
	while( document.forms[j].elements.length == 0 )
	{	j++;	}
	while( document.forms[j].elements[i]
			&& ( document.forms[j].elements[i].type != "textarea"
				&& document.forms[j].elements[i].type != "text"
				&& document.forms[j].elements[i].type != "password" ) )
	{	i++;	}
	if( document.forms[j].elements[i]
		&& ( document.forms[j].elements[i].type == "textarea"
				|| document.forms[j].elements[i].type == "text"
				|| document.forms[j].elements[i].type == "password" )
		)
	{
		try
		{
			document.forms[j].elements[i].focus();
		}
		catch(e)
		{
			// IE doesn't allow focus to hidden element, we have to catch & destroy this exception
		}

	}

	// hide all Elements that need to
	hideNeededElements();
	setTimeout("scrollTo(0,0);", 100);	// scroll to the top of the page
}
// ----------------------------------------------------------------------------


function hideNeededElements()
{
	for(i=0;i<hiddenIds.length;i++)
	{
		myId = document.getElementById(hiddenIds[i]);
		myId.style.display="none";
	}

}





// call after the form element which focus needs to be set
// example for call: <input type=checkbox ....><script>setFocus()</script>
var focusobject=null;

function setFocus()
{
	if(focusobject)
		focusobject.focus();
	else
	{
		if(!document.forms.length) return;
		focusobject=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
		focusobject.focus();

	}
}


function setInputName(name)
{
	if(!document.forms.length) return;
	myobject=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	myobject.name=name;
}

function setInputValue(value)
{
	if(!document.forms.length) return;
	myobject=document.forms[document.forms.length-1].elements[document.forms[document.forms.length-1].elements.length-1];
	myobject.value=value;
}


// color fields in forms
// used styles: "formactive", "formfull", and "formempty"

function colorIt(myform)
{
	if (document.all)
	myform.className = "formactive";
}

function noColor(myform)
{
	if (document.all)
	myform.className = "formfull";
}

function checkField(field)
{
	if (document.all)
	{
		if (field.value.length>1)
			field.className = "formfull";
		else
			field.className = "formempty";
	}
}

function switchClasses(myform, className)
{
	myform.className = className;
}


function checkReqField(field,className1,className2)
{
	if (field.value.length>1)
		field.className = className1;
	else
		field.className = className2;

}

// stuff for the menu-bar navigation
// used vars
mOff	= "_off";
mMs	= "_ms";
navExt	= ".gif";
navPath	= "images/";
navName	= "nav_";
itemName = "nav";

function hiLight(number,button,status)
{
	if (window.document.images)
	{
		eval("window.document.nav"+number+".src = navPathCorr+navPath+navName+button+mMs+navExt;");
		window.status = status;
	}
}

function nohiLight(number,button)
{
	if (window.document.images)
	{
		eval("window.document.nav"+number+".src = navPathCorr+navPath+navName+button+mOff+navExt;");
		window.status = "";
	}
}

// confirmation to log out
function checkLogout(msg,dummy)  //some old templates use 2 params
{
	check = confirm(msg);
	if(check != false)
	{
		if(typeof(absCorrect) == 'undefined')
		{
			document.location.href = navPathCorr+"icms/logout.html";
		}
		else
		{
			document.location.href = absCorrect+"icms/logout.html";
		}
	}
}

// confirmatioon to delete records
function delRecord(msg)
{
	check = confirm(msg);
	if(check != false)
	{
		alert("okay, delete record");
	}
}

function disableField(formname,inputname,delcont)
{
	myElement=document.forms[formname].elements[inputname];
	if(document.layers)
		myElement.onfocus = doBlurField;
	else
		myElement.disabled = true;
	if (delcont)
		myElement.value = "";
}

function enableField(formname,inputname)
{
	myElement=document.forms[formname].elements[inputname];
	if(document.layers)
		myElement.onfocus = "";
	else
		myElement.disabled = false;
}

function doBlurField()
{
	this.blur();
}

// ------------------------------------------------------------------------------------------
// Time and date function to use with icms and forms
// ------------------------------------------------------------------------------------------

// ==========================================================================================
// INPUT: mysqlTimestamp yyyymmddhhmmss
// pattern : string with the following parameter
// capital letter means with additional 0 before values lower than 10
// %d / %D - day of the month
// %m / %M - month (1 - 12)
// %y / %Y - year format 01 / 2001
// OUTPUT:  string according to pattern
// ------------------------------------------------------------------------------------------
function ts2date(mysqlTs_,pattern_)
{
	if( mysqlTs_.length != 14 )
	{
		alert("Invalid mysqlTimestamp length! (should be 14)");
		return("");
	}
	if( !pattern_ )
	{
		pattern_= STANDARD_TIME_PATTERN;
	}
	output = "";

	nYear 		= mysqlTs_.slice(0, 4);
	nMonth		= mysqlTs_.slice(4, 6);
	nDay		= mysqlTs_.slice(6, 8);
	nHours		= mysqlTs_.slice(8, 10);
	nMinutes	= mysqlTs_.slice(10, 12);
	nSeconds	= mysqlTs_.slice(12, 14);

	nCurrentIndex = pattern_.indexOf("%", 0);
	while( nCurrentIndex != -1)
	{
		param = pattern_.charAt( nCurrentIndex+1 );

		// handle the parameter
		switch( param )
		{
		case 'd':
			output += nDay*1;
			break;
		case 'D':
			output += nDay;
			break;
		case 'm':
			output += nMonth*1;
			break;
		case 'M':
			output += nMonth;
			break;
		case 'y':
			output += nYear.substring(2, 4);
			break;
		case 'Y':
			output += nYear;
			break;
		case 's':
			output += nSeconds*1;
			break;
		case 'S':
			output += nSeconds;
			break;
		case 'h':
			output += nHours*1;
			break;
		case 'H':
			output += nHours;
			break;
		case 'n':
			output += nMinutes*1;
			break;
		case 'N':
			output += nMinutes;
			break;
		default:
			alert("Wrong parameter supplied to the ts2date function: %" + param);
		}

		// check for next occurence of "%"
		nLastIndex = nCurrentIndex+2;
		nCurrentIndex = pattern_.indexOf("%", nCurrentIndex+1);

		// fill stuff between parameters
		if( nCurrentIndex != -1 )
		{
			output += pattern_.substring( nLastIndex, nCurrentIndex );
		}
	}

	return(output);
}
// ------------------------------------------------------------------------------------------

// ==========================================================================================
// INPUT:
// date  -> format: [d]d.[m]m.[yy]yy
// time  -> format: true - sets time of the moment (clients time)
//			     [h]h.[m]m.[s]s
// OUTPUT: mysqlTimestamp yyyymmddhhmmss
// ------------------------------------------------------------------------------------------
function date2ts(date_, time_)
{
	output = "";
	// validate the date_ parameter
	date_ = adjustDate(date_, true);

	nYear 		= date_.substr(6, 4);
	nMonth		= date_.substr(3, 2);
	nDay		= date_.substr(0, 2);
	nHours		= 0;
	nMinutes	= 0;
	nSeconds	= 0;

	if( time_ == true )
	{
		// use the current time
		today 		= new Date();
		time_		= adjustTime( today.getHours() + "."
									+ today.getMinutes() + "."
									+ today.getSeconds() );
	}
	else
	{
		// use suplied time (string)
		time_		= adjustTime( time_ );
	}

	nHours 		= time_.substr( 0, 2 );
	nMinutes	= time_.substr( 3, 2 );
	nSeconds	= time_.substr( 6, 2 );

	output = nYear + nMonth + nDay + nHours + nMinutes + nSeconds;

	return(output);
}
// ------------------------------------------------------------------------------------------

// ==========================================================================================
//INPUT: date: format [d]d.[m]m.[yy]yy
//
//OUTPUT: correct date in format d.m.y or dd.mm.yy according to full
// ------------------------------------------------------------------------------------------
function adjustDate(dateString, full, bShowErrMsg_, nAdjustByDays_)
{
	if( !full )
	{
		full = false;
	}
	if( typeof bShowErrMsg_ == 'undefined' )
	{
		bShowErrMsg_ = true;
	}
	if( typeof nAdjustByDays_ == 'undefined' )
	{
		nAdjustByDays_ = 0;
	}
	splitedDate = dateString.match(/(\d+\.)|(\d+$)/g);
	flag=true;
	if(splitedDate)
	{
		if(splitedDate.length==2)
		{
			var today = new Date();
			splitedDate[2] = today.getYear();
		}
		if(splitedDate.length!=3)
		{
			flag=false;
		}
		else
		{
			for(i=0;i<splitedDate.length;i++)
			{
				splitedDate[i]=splitedDate[i]*1;
			}
		}
	}
	else
	{
		flag= false;
	}
	if(!flag)
	{
		if( bShowErrMsg_ )
		{
			alert("Feld für Datum: Falsches Format.\nBitte das folgende Format verwenden:\nTT.MM.JJJJ");
		}
		today= new Date();
		year = today.getYear();
		if(year < 1000) year+= 1900;

		if( full == true )
		{
			var nDay = today.getDate()+1+nAdjustByDays_;
			var nMonth = today.getMonth()+1;
			if( nDay < 10 )
			{
				nDay = "0" + nDay;
			}
			if( nMonth < 10 )
			{
				nMonth = "0" + nMonth;
			}
			myDate = nDay + "." + nMonth + "." + year;
		}
		else
		{
			myDate = (today.getDate()+1+nAdjustByDays_)+"."+(today.getMonth()+1)+"."+year;
		}
	}
	else
	{
		if(splitedDate[2]<70) splitedDate[2]+=2000;
		myDate = new Date(splitedDate[2],splitedDate[1]-1,splitedDate[0]);
		year =myDate.getYear();

		if( (year + "").length == 3 || (year + "").length > 4 || (year + "").length == 0 )
		{
			today = new Date();
			year = today.getYear();
		}

		if(year < 1000) year+= 1900;

		if( full == true )
		{
			var nDay = myDate.getDate() + nAdjustByDays_;
			var nMonth = myDate.getMonth()+1;
			if( nDay < 10 )
			{
				nDay = "0" + nDay;
			}
			if( nMonth < 10 )
			{
				nMonth = "0" + nMonth;
			}
			myDate = nDay + "." + nMonth + "." + year;
		}
		else
		{
			var x = myDate.getDate()+nAdjustByDays_;
			myDate = x+"."+(myDate.getMonth()+1)+"."+year;
		}
	}

	return myDate;
}
// ------------------------------------------------------------------------------------------


// ==========================================================================================
//INPUT: time: format [h]h.[m]m.[s]s
//
//OUTPUT: success: 	correct time in format hh.mm.ss
// 		  fail: 	return 00.00.00
// ------------------------------------------------------------------------------------------
function adjustTime(timeString_)
{
	output = "";
	if( !timeString_ )
	{
		return( "00.00.00" );
	}

	nLastIndex 		= 0;
	nCurrentIndex 	= timeString_.indexOf(".", 0);
	// hours:
	Value = timeString_.substring(nLastIndex, nCurrentIndex);
	Value %= 24;
	if( (Value * 1) < 10 )
	{
		Value = "0" + Value;
	}
	output += Value + ".";

	nLastIndex 		= nCurrentIndex;
	nCurrentIndex 	= timeString_.indexOf(".", nLastIndex + 1);
	// minutes:
	Value = timeString_.substring(nLastIndex + 1, nCurrentIndex) + ".";
	Value %= 60;
	if( (Value * 1) < 10 )
	{
		Value = "0" + Value;
	}
	output += Value + ".";

	// seconds:
	Value = timeString_.substring(nCurrentIndex + 1, timeString_.length);
	Value %= 60;
	if( (Value * 1) < 10 )
	{
		Value = "0" + Value;
	}
	output += Value;

	return(output);
}
// ------------------------------------------------------------------------------------------


// ==========================================================================================
//INPUT: datestring (dd.mm.yyyy)
//
//OUTPUT: success: 	string {"Montag", "Dienstag, ... ,"Sonntag"}
// 		  fail: 	return "getWeekDay::ERROR!"
// ------------------------------------------------------------------------------------------
function getWeekDay(dateString)
{
	splitedDate = dateString.match(/(\d+\.)|(\d+$)/g);
	convertedDate = 0;
	result = 0;
	flag=true;
	if(splitedDate)
	{
		if(splitedDate.length!=3)
		{
			flag=false;
		}
		else
		{
			for(i=0;i<splitedDate.length;i++)
			{
				splitedDate[i]=splitedDate[i]*1;
			}
		}
	}
	else
	{
		flag= false;
	}
	if(!flag)
	{
		today= new Date();
		year = today.getYear();
		if(year < 1000) year+= 1900;
		myDate = new Date( year, today.getMonth(), today.getDate(), 12, 00, 00 );
	}
	else
	{
		if(splitedDate[2]<70) splitedDate[2]+=2000;
		myDate = new Date(splitedDate[2],splitedDate[1]-1,splitedDate[0]);
		year =myDate.getYear();
		if(year < 1000) year+= 1900;
		myDate = new Date( year, myDate.getMonth(), myDate.getDate(), 12, 00, 00 );
	}
	switch ( myDate.getDay() )
	{
	case 0:
		return "Sonntag";
	case 1:
		return "Montag";
	case 2:
		return "Dienstag";
	case 3:
		return "Mittwoch";
	case 4:
		return "Donnerstag";
	case 5:
		return "Freitag";
	case 6:
		return "Samstag";
	default:
		alert("getWeekDay::ERROR!");
		return "getWeekDay::ERROR!";
		break;
	}
}
// ------------------------------------------------------------------------------------------

// ==========================================================================================
// Class to time a html page
//
// Step 1: initialisation
//	<script>myTimer = new pagetimer()</script>
// Step 2: add timelines
//	<script>myTimer.timeline("name1")</script>
// Step 3: plot output
//	<script>myTimer.output()</script>
// ------------------------------------------------------------------------------------------
function pagetimer()
{
	// properties
	this.starttime = new Date().getTime();
	this.timelines = new Array();

	// methods
	this.timeline 	= pagetimer_timeline;
	this.output 	= pagetimer_output;
}

function pagetimer_timeline(name)
{
	this.timelines[name] = new Date().getTime();
}

function pagetimer_output()
{
	// print timeline
	text = "";
	previous = this.starttime;
	for (var key in this.timelines)
	{
		text +=key+":"+(this.timelines[key]-this.starttime)+" ("+(this.timelines[key]-previous)+")\n";
		previous = this.timelines[key];
	}
	alert(text);
}

// functions for iframe expander in all various browsers [START]

function getIFrameDoc( name ) {
  var IFrameDoc;
  var Height;
  var IFrameObj = document.getElementsByName(''+name)[0];

  if (typeof(document.frames) != 'undefined') {
    IFrameObj = document.frames[name];
  }

  if (typeof(IFrameObj) == 'undefined') {
    return false;
  }

  if (typeof(IFrameObj.contentDocument) != 'undefined') {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument;
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return false;
  }

  if(typeof(IFrameDoc.body) != 'undefined')
  {
    return IFrameDoc.body;
  }
  else
  {
    return IFrameDoc.documentElement;
  }
}

/*
* gets the height of an iframe document
*/
function getIFrameDocHeight( name )
{
var IFrameDoc = getIFrameDoc( name );
  if(typeof IFrameDoc == 'undefined')
    return false;
  	return IFrameDoc.scrollHeight;
}

/*
* gets the width of an iframe document
*/
function getIFrameDocWidth( name )
{
var IFrameDoc = getIFrameDoc( name );
  if(typeof IFrameDoc == 'undefined')
    return false;
  return IFrameDoc.scrollWidth;
}
function iframeExpander(iframe,iframediv)
{
	setTimeout('iframeExpander()', 500);
	var iH = getIFrameDocHeight( iframe );
	document.getElementById( iframe ).height = "" + iH;
	document.getElementById(iframediv).style.height = getIFrameDocHeight(iframe);
	if(iH > 0)
	{
		superLoader = 'true';
	}
}

// functions for iframe expander in all various browsers [END]



//Helplayerstuff
function docjslib_getRealLeft(imgElem) {
	xPos = imgElem.offsetLeft;
	tempEl = imgElem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function docjslib_getRealTop(imgElem) {
	yPos = imgElem.offsetTop;
	tempEl = imgElem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function getImageXfromLeft(imgID,mydoc) {
	if(!mydoc) mydoc = document;
	myImage = mydoc.getElementById(imgID);
	if(!myImage)
	{
		//  	alert("Achtung!\nDas Bild "+imgID+", welches zur relativen Positionierung gebraucht wird, scheint nicht vorhanden zu sein.");
		return false;
	}
	return docjslib_getRealLeft(myImage);
}

function getImageYfromTop(imgID,mydoc) {
	if(!mydoc) mydoc = document;
	myImage = mydoc.getElementById(imgID);
	if(!myImage)
	{
		//  	alert("Achtung!\nDas Bild "+imgID+", welches zur relativen Positionierung gebraucht wird, scheint nicht vorhanden zu sein.");
		return false;
	}
	return docjslib_getRealTop(myImage);
}

function showModelLayer(id)
{
	var div = document.getElementById('layer_' + id);
	div.style.left = getImageXfromLeft('image_' + id, document) + 4 + 'px';
	div.style.top = getImageYfromTop('image_' + id, document) + 10 + 'px';
	div.style.display = '';
}

function hideModelLayer(id)
{
	var div = document.getElementById('layer_' + id);
	div.style.display = 'none';
}


// Popup-Funktion
function openPicWin(pFileName,pWinName,pWidth,pHeight) {
	var isNS = (document.layers) ? true : false;

	if (isNS) pHeight = pHeight + 19;
		eval("allSettings = 'width="+pWidth+",height="+pHeight+",menubar=yes,scrollbars=yes,status=yes,resizable=yes'");
		w=window.open(pFileName,pWinName,allSettings);
		w.window.focus();
}

