var x, y, relx, rely;
var TreeNode = new Array();
var lastMark = "";
var lastClass = "Verdana11Black";
var fontMarkColor = "#000000";
var lastFontMarkColor = "";

var sBgColor = "#FCFCFC";
var sColSelected = "#0F9596";

var ie = document.all ? 1 : 0;
var tempX = 0;
var tempY = 0;
//if (!ie) document.captureEvents(Event.MOUSEMOVE);
//document.onmousemove = getXY;

var aktivExtMenu = "";
var timer = null;
var breakBool = false;

window.onload = init;

function init() {
	//if (window.Event) {
	if(!ie){
		if (document) {
			document.captureEvents(Event.MOUSEMOVE);
		}
	}
	if (document) {
		document.onmousemove = getXY;
	}
}

var DynToolTipp_mposx = 0;
var DynToolTipp_mposy = 0;
var DynToolTipp_id = '';

function getXY(e) {
	var ie = document.all ? 1 : 0;
	if (ie) {
		tempX = event.clientX + document.body.scrollLeft + 10;
		tempY = event.clientY + document.body.scrollTop + 8;
	} else {
		tempX = e.pageX + 10;
		tempY = e.pageY + 10;
	}
//	x = (window.Event) ? e.pageX : event.screenX;
//	y = (window.Event) ? e.pageY : event.screenY;
	x = (!ie) ? e.pageX : event.screenX;
	y = (!ie) ? e.pageY : event.screenY;
	/*if (window.Event) {
		posx =	e.screenX;
		posy = e.screenY;
		relx = e.pageX;
		rely = e.pageY;
	}
	else {
		x = window.event.screenX;
				y = window.event.screenY;
				relx = window.event.clientX;
		rely = window.event.clientY;
	}
	var e = e || window.event;
		//Tool Tipp Stuff
		DynToolTipp_mposx = e.x;
		DynToolTipp_mposy = e.y;

		//Netscape
		if (! DynToolTipp_mposx) {
				DynToolTipp_mposx = e.pageX;
				DynToolTipp_mposy = e.pageY;

				//hier Scrollabstände nicht beim Tool Tipp verwenden
				if (DynToolTipp_addscroll == 1) {
						DynToolTipp_addscroll = 0;
				}
		}
		*/
	if (DynToolTipp_shown) {
			//var scrollleft = 0;
			//var scrolltop = 0;
			//if (DynToolTipp_addscroll == 1) {
			//    scrollleft = document.body.scrollLeft;
			//    scrolltop = document.body.scrollTop;
			//}
		ToolTip = document.getElementById(DynToolTipp_id);
		if(ToolTip){
			ToolTip.style.position = "absolute";
			ToolTip.style.left = tempX;
			ToolTip.style.top = tempY;
		}

	//	ToolTipText = document.getElementById(DynToolTipp_id+'Text');
	//	if(ToolTipText)
	//		ToolTipText.innerHTML = ToolTipText.innerHTML;
	}
}


var DynToolTipp_shown = 0;
var DynToolTipp_addscroll = 1;
var right = 0;

function DynToolTipp_Show (text, offset, elem_id, yoffset) {
	if (offset > 0)
		right = offset;
 /* var scrollleft = 0;
	var scrolltop = 0;
	if (DynToolTipp_addscroll == 1) {
			scrollleft = document.body.scrollLeft;
			scrolltop = document.body.scrollTop;
	}
 */
	DynToolTipp_id = 'DynToolTipp';
	var idtext = 'DynToolTippText';
	if(elem_id && elem_id.length){
		DynToolTipp_id = elem_id;
		idtext = elem_id+'Text';
	}
	ToolTipText = document.getElementById(idtext);
	if(ToolTipText)
		ToolTipText.innerHTML = text;
	ToolTip = document.getElementById(DynToolTipp_id);
	var showit = false;
	if(ToolTip){
		if(DynToolTipp_shown == 0)
			showit = true;
		DynToolTipp_shown = 1;
//		alert("showit: " + showit);
		if(showit){
			if (!yoffset)
				yoffset = 0;
			ToolTip.style.position = "absolute";
			ToolTip.style.left = tempX;
			ToolTip.style.top = tempY + yoffset;
			ToolTip.style.visibility = 'visible';
			ToolTip.style.display = '';
		}
	}
}

function DynToolTipp_Hide(elem_id) {
	if(elem_id && elem_id.length)
		DynToolTipp_id = elem_id;
	ToolTip = document.getElementById(DynToolTipp_id);
	if(ToolTip){
		ToolTip.style.visibility = 'hidden';
		ToolTip.style.display = 'none';
	}
	DynToolTipp_shown = 0;
	right = 0;
}

function DynToolTipp_HideEX(elem_id) {
	DynToolTipp_shown = 0;
}

function showPleaseWait(offsetX, offsetY) {
	var element = document.getElementById('std_please_wait');
	if(element){
		if(offsetX && offsetX > 0)
			element.style.top=offsetX+100;
		else
			element.style.top=document.body.scrollTop+100;

		if(offsetY && offsetY > 0)
				element.style.left=offsetY+120;
		else
			element.style.left=document.body.scrollLeft+120;

		element.style.display='';
	}

}

function hidePleaseWait() {
	var element = document.getElementById('std_please_wait');
	if(element)
		element.style.display='none';
}


function frmChange(daten) {
	var aFrames = daten.split("|");
	for (i=0; i<aFrames.length; i++) {
		sDaten = aFrames[i];
		iLinks = sDaten.indexOf("{");
		iRechts = sDaten.indexOf("}");
		//alert(sDaten+" "+iLinks+"/"+iRechts);
		sFrameName = sDaten.substr(0, iLinks);
		sFrameURL = sDaten.substr(iLinks+1, (iRechts-iLinks-1));
		 //alert("Frame: "+sFrameName);
		 //alert("URL: "+sFrameURL);

		top.frames[sFrameName].location.href=sFrameURL;
	}
	return false;
}

/*
 *
 */
function frmChangeDispatcherView(aargs, cPATH, PHPSESSID) {

	frm = parent.frames["frmDocumentsAssign"];
	url = cPATH+"/dispatcher_documents_assign.php";
	args = "?PHPSESSID="+PHPSESSID;

	action = frm.document.forms["assignForm"].action.value;
	if (frm.document.forms["assignForm"] != null) {
		args += "&action=" + action;
	}
	args += aargs;

	if (action == "assignproc")
		url = cPATH+"/dispatcher_documents_assign_proc.php";
	else if (action == "assigncomp")
		url = cPATH+"/dispatcher_documents_assign_comp.php";
	else if (action == "assignerl")
		url = cPATH+"/dispatcher_documents_assign_erl.php";
	//alert(url + args);
	frm.location.href = url + args;

	return false;
}


function mOver(src, clOver){
	src.style.cursor = 'pointer';
	src.bgColor = clOver;
}
function mOut(src, clOut){
	src.style.cursor = 'default';
	src.bgColor = clOut;
}
function mClick(src){
	if(event.srcElement.tagName == 'TD'){
		src.children.tags('A')[0].click();
	}
}

function ValidDate(TestDate) {
	if (!TestDate) return false;
	TestDate=TestDate.toString();

	DatePart = TestDate.split(".");
	if (DatePart.length!=3) return false;

	DatePart[0]=parseInt(DatePart[0],10);
	DatePart[1]=parseInt(DatePart[1],10)-1;

	if (DatePart[2].length==2) return false;

	var ControlDate = new Date(DatePart[2],DatePart[1],DatePart[0]);

	if (ControlDate.getDate() == DatePart[0] && ControlDate.getMonth() == DatePart[1] && ControlDate.getFullYear() == DatePart[2])
		return true;
	else
		return false;
}

/**
 * JavaScript-Funktion. Prüft, ob die Teile eines Datums innerhalb ihrer Wertebereiche sind.
 * @param int year Jahr
 * @param int month Monat
 * @param int day Tag
 * @param int hour Stunden
 * @param int minute Minute
 * @param int second Sekunde
 * @param string msg Fehlertext, der weiter gefüllt und dann zurückgegeben wird
 * @param array aDateFieldNames Array mit den Namen der Datumsfelder
 * @return Fehlermeldung
 */
function validateDate(year, month, day, hour, minute, second, msecond, msg, aDateFieldNames){
	sReturn = '';
	if(aDateFieldNames) {
		sReturn = msg;
		last_day_of_month = new Date(year, month+1, 0, 0, 0, 0).getDate();
		errCode = 0;
		if(hour < 0 || hour > 23) errCode = -1;
		else if(minute < 0 || minute > 59) errCode = -2;
		else if(second < 0 || second > 59) errCode = -3;
		else if(day < 1 || day > last_day_of_month) errCode = -4;
		else if(month < 0 || month > 11) errCode = -5; // month beginnt bei 0
		else if(year < 1970 || year > 2030) errCode = -6;
		else if(msecond < 0 || msecond > 999) errCode = -7;

		switch(errCode) {
			case -1 : // falsche Stunden
				sReturn = sReturn.replace(/###/,"0-23");
				sReturn = sReturn.replace(/:::/,aDateFieldNames["hour"]);
				break;
			case -2 : // falsche Minuten
				sReturn = sReturn.replace(/###/,"0-59");
				sReturn = sReturn.replace(/:::/,aDateFieldNames["minute"]);
				break;
			case -3 : // falsche Sekunden
				sReturn = sReturn.replace(/###/,"0-59");
				sReturn = sReturn.replace(/:::/,aDateFieldNames["second"]);
				break;
			case -4 : // falsche Tageszahl
				sReturn = sReturn.replace(/###/,"1-"+last_day_of_month);
				sReturn = sReturn.replace(/:::/,aDateFieldNames["day"]);
				break;
			case -5 : // falsche Monatszahl
				sReturn = sReturn.replace(/###/,"1-12");
				sReturn = sReturn.replace(/:::/,aDateFieldNames["month"]);
				break;
			case -6 : // falsche Jahreszahl
				sReturn = sReturn.replace(/###/,"1970-2030");
				sReturn = sReturn.replace(/:::/,aDateFieldNames["year"]);
				break;
			case -7 : // falsche Millisekunden
				sReturn = sReturn.replace(/###/,"0-999");
				sReturn = sReturn.replace(/:::/,aDateFieldNames["msecond"]);
				break;
			default :
				sReturn = '';
				break;
		}
	}
	return sReturn;
}

function NewCalendar(Path,Session,DayField,MonthField,YearField,FormObj,FormStr,Datum1,Datum2,AnzMode) {

	if ((FormObj.elements[DayField].value != "") && (FormObj.elements[MonthField].value != "") && (FormObj.elements[YearField].value != "")) {
		if (ValidDate(FormObj.elements[DayField].value + '.' + FormObj.elements[MonthField].value + '.' + FormObj.elements[YearField].value)) {
			Datum1 = FormObj.elements[DayField].value + '.' + FormObj.elements[MonthField].value + '.' + FormObj.elements[YearField].value;
		} else {
			FormObj.elements[DayField].value = "";
			FormObj.elements[MonthField].value = "";
			FormObj.elements[YearField].value = "";
		}
	}

	iWidth = 200;
	iHeight = 128;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	if (AnzMode == "1") {
		var NewWindow = window.open(Path + '/calendar.php?PHPSESSID=' + Session + '&firstdate=' + Datum1 + '&lastdate=' + Datum2 + '&mode=' + AnzMode + '&dayfield=' + DayField + '&monthfield=' + MonthField + '&yearfield=' + YearField + '&formstr=' + FormStr, 'Zweitfenster', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY + ',noscrollbars');
		NewWindow.focus();
	}
	if (AnzMode == "2") {
		var NewWindow = window.open(Path + '/calendar.php?PHPSESSID=' + Session + '&firstdate=' + Datum1 + '&lastdate=' + Datum2 + '&mode=' + AnzMode, 'Zweitfenster', 'width=600,height=520,scrollbars');
		NewWindow.focus();
	}
}

function NewCalendarEx(Path,Session,DayField,MonthField,YearField,FormObj,FormStr) {

	if ((FormObj.elements[DayField].value != "") && (FormObj.elements[MonthField].value != "") && (FormObj.elements[YearField].value != "")) {
		if (ValidDate(FormObj.elements[DayField].value + '.' + FormObj.elements[MonthField].value + '.' + FormObj.elements[YearField].value)) {
			Datum1 = FormObj.elements[DayField].value + '.' + FormObj.elements[MonthField].value + '.' + FormObj.elements[YearField].value;
		} else {
			FormObj.elements[DayField].value = "";
			FormObj.elements[MonthField].value = "";
			FormObj.elements[YearField].value = "";
		}
	}

	iWidth = 200;
	iHeight = 128;

	posX = x;
	posY = y - 128;

	var NewWindow = window.open(Path + '/calendar.php?PHPSESSID=' + Session + '&mode=1&dayfield=' + DayField + '&monthfield=' + MonthField + '&yearfield=' + YearField + '&formstr=' + FormStr + '&bsubmit=1', 'CalendarEx', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY + ',noscrollbars');
	NewWindow.focus();

	return NewWindow;
}

function NewPeriodCalendar(Path,Session,FirstDayField,FirstMonthField,FirstYearField,SecondDayField,SecondMonthField,SecondYearField,FormObj,FormStr,Datum1,Datum2,AnzMode,Direction) {
	//alert(FirstDayField);
	if ((FormObj.elements[FirstDayField].value != "") && (FormObj.elements[FirstMonthField].value != "") && (FormObj.elements[FirstYearField].value != "")) {
		if (ValidDate(FormObj.elements[FirstDayField].value + '.' + FormObj.elements[FirstMonthField].value + '.' + FormObj.elements[FirstYearField].value)) {
			Datum1 = FormObj.elements[FirstDayField].value + '.' + FormObj.elements[FirstMonthField].value + '.' + FormObj.elements[FirstYearField].value;
		} else {
			FormObj.elements[FirstDayField].value = "";
			FormObj.elements[FirstMonthField].value = "";
			FormObj.elements[FirstYearField].value = "";
		}
	}

	iWidth = 200;
	iHeight = 128;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	if (AnzMode == "1") {
		var NewWindow = window.open(Path + '/calendar.php?PHPSESSID=' + Session + '&firstdate=' + Datum1 + '&lastdate=' + Datum2 + '&mode=' + AnzMode + '&dayfield=' + FirstDayField + '&monthfield=' + FirstMonthField + '&yearfield=' + FirstYearField  + '&seconddayfield=' + SecondDayField + '&secondmonthfield=' + SecondMonthField + '&secondyearfield=' + SecondYearField +'&formstr=' + FormStr + '&direction=' + Direction, 'Zweitfenster', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY + ',noscrollbars');
		NewWindow.focus();
	}
	if (AnzMode == "2") {
		var NewWindow = window.open(Path + '/calendar.php?PHPSESSID=' + Session + '&firstdate=' + Datum1 + '&lastdate=' + Datum2 + '&mode=' + AnzMode, 'Zweitfenster', 'width=600,height=520,scrollbars');
		NewWindow.focus();
	}
}


function NewColorPicker(Path,Session,InputField,PreviewField,FormObj,FormStr) {
	iWidth = 90;
	iHeight = 165;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/util_colorpicker.php?PHPSESSID=' + Session + '&inputfield=' + InputField + '&previewfield=' + PreviewField + '&formstr=' + FormStr, 'ColorPicker', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',noscrollbars');
	NewWindow.focus();

}

function NewTask(Path,Session,args) {
	iWidth = 430;
	iHeight = 470;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/scheduler_edit.php?PHPSESSID=' + Session + args + '&mode=new', 'Terminfenster', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars=yes,resizable=yes');
	NewWindow.focus();
}

function NewTaskView(Path,Session,args) {
	iWidth = 430;
	iHeight = 470;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/scheduler_view.php?PHPSESSID=' + Session + args, 'Terminfenster', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars=yes,resizable=yes');
	NewWindow.focus();
}

function updateLocationHRef(refurl){
	if(refurl && refurl.length)
		document.location.href = refurl;
	else {
		if(document.location.href.indexOf('php') > -1)
			document.location.href = document.location.href;
	}
}

function NewErlView(Path,Session,args) {
	url = Path+"/pu_logbuch_book_index.php?PHPSESSID="+Session+"&"+args;
	iWidth  = 800;
	iHeight = 600;
	posX    = Math.round((screen.availWidth-iWidth)/2);
	posY    = Math.round((screen.availHeight-iHeight)/2);
	frmLogbuch_Book = window.open(url,"logbuch_book","width="+iWidth+",height="+iHeight+",left="+posX+",top="+posY+",scrollbars=no");
	frmLogbuch_Book.focus();
}

function NewAdressBook(Path,Session,InputField,FormStr,closeatselection) {
	iWidth = 600;
	iHeight = 400;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/adressbook.php?PHPSESSID=' + Session + '&inputfield=' + InputField  + '&formstr=' + FormStr + '&closeatselection=' + closeatselection, 'Adressbuch', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars');
	NewWindow.focus();

}

function NewTasksOverview(Path,Session) {
	iWidth = 327;
	iHeight = 300;

	posX = x;
	posY = y - iHeight - 20;

	var NewWindow = window.open(Path + '/tasks_overview.php?PHPSESSID=' + Session, 'Tasks', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars');
	NewWindow.focus();

}

function NewErrAssign(Path,Session,args) {
	iWidth = 730;
	iHeight = 620;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/admin_err_assign2.php?PHPSESSID=' + Session + args, 'ErrAssign', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars');
	NewWindow.focus();
}

function NewDclChoice(Path,Session,args) {
	iWidth = 330;
	iHeight = 300;

	posX = x - iWidth;
	posY = y - iHeight - 20;

	var NewWindow = window.open(Path + '/park_updatestate.php?PHPSESSID=' + Session + args, 'DCLChoice', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars');
	NewWindow.focus();
}

function NewDialInParameterSettings(Path,Session,args) {
	iWidth = 820;
	iHeight = 570;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/park_onlinedialin.php?PHPSESSID=' + Session + args, 'DCLChoice', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars');
	NewWindow.focus();
}

function newDocumentView(Path,Session,args) {
	iWidth = 820;
	iHeight = 600;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/document_index.php?PHPSESSID=' + Session + args, 'Documents', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',noscrollbars,resizable=yes');
	NewWindow.focus();
}

function newAdressbook(Path,Session,args) {
	iWidth = 800;
	iHeight = 600;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/adressbook_index.php?PHPSESSID=' + Session + args, 'Documents', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',noscrollbars');
	NewWindow.focus();
}


function newDispatcher(Path,Session,args) {
	iWidth = 1000;
	iHeight = 700;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	link = Path + '/dispatcher_index.php?PHPSESSID=' + Session + args;
	var NewWindow = window.open(link, 'Dispatcher', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',scrollbars=no, resizable=yes');
	NewWindow.focus();
}

function isType(Transmitter,Value,Type) {

	// Variablen festlegen
	var isOK = true;
	var isNumber = false;
	var Length1 = '';
	var Length2 = '';

	// Suche nach Längenangaben im Typ
	if ((Type.indexOf("(") != '-1') && (Type.indexOf(",") == '-1')) {
		Length1 = Type.substr(Type.indexOf("(")+1,Type.indexOf(")") - (Type.indexOf("(")) - 1);
		Length2 = '';
	}

	if ((Type.indexOf("(") != '-1') && (Type.indexOf(",") != '-1')) {
		Length2 = Type.substr(Type.indexOf(",")+1,Type.indexOf(")") - (Type.indexOf(",")) - 1);
		Length1 = Type.substr(Type.indexOf("(")+1,Type.indexOf(",") - (Type.indexOf("(")) - 1);
	}

	// den Typ extrahieren
	if (Type.indexOf("(") != -1)
		Type = Type.substr(0,Type.indexOf("("));

	// Zuweisen der entsprechenden Regulären Ausdrücke
	if (Type == 'int') {
		var RegExpr = /[^0-9]/;
		ErrorMessage = ErrorMessages['Zeichen_erlaubt']+'0-9';
	}

	if ((Type == 'dec') || (Type == 'float')) {
		var RegExpr = /[^\.\,0-9]/;
		ErrorMessage = ErrorMessages['Zeichen_erlaubt']+'\. 0-9'
	}

	if (Type == 'text') {
		var RegExpr = /\'|\"/;
		ErrorMessage = ErrorMessages['Zeichen_nicht_erlaubt']+'\' \"'
	}

	if (Type == 'varchar') {
		var RegExpr = /[^a-zA-Z0-9_ ()\-öäüÖÄÜß\+,\/;:\.\&]/; // ein "." ist nicht erlaubt
		ErrorMessage = ErrorMessages['Zeichen_erlaubt']+'a-z A-Z 0-9_ ()\-öäüÖÄÜß\+.,\/;:';
	}

	if (Type == 'xml_konform') {
		var RegExpr = /[^a-zA-Z0-9_ ()\-öäüÖÄÜß\+,\/;:\.\&\[\]\{\}]/;
		ErrorMessage = ErrorMessages['Zeichen_erlaubt']+'a-z A-Z 0-9_ ()\-öäüÖÄÜß\+.,\/;:[]{}';
	}

	if (Type == 'telnummer') {
		var RegExpr = /[^0-9\-\+]/;
		ErrorMessage = ErrorMessages['Zeichen_erlaubt']+'0-9 \- \+';
	}

	// eventuellen Zahlenwert berichtigen
	if ((Type == "int") && ((Value.indexOf(',') != '-1') || (Value.indexOf('.') != '-1'))) {
		var counter = 0;
		for (var i = 0;i < Value.length; i++)
			if ((Value.charAt(i) == '.') || (Value.charAt(i) == ','))
				 counter++;
		if (counter > 1) isOK = false
	}

	if (isOK && ((Type == "dec") || (Type == 'float'))&& (Value.indexOf(',') != '-1')) Value = Value.replace(/,?/,'.');

	// Überprüfen des übergebenen Wertes auf richtige Zeichen
	Result = RegExpr.exec(Value);

	// Maximale Längen setzen, wenn keine Längenangaben vorhanden
	if ((Length1 == '') && (Type == 'varchar')) Length1 = 255;
	if ((Result != null) && (Result != '')) isOK = false;
	if (Length1 != '') {
		if (Value.length > Length1) isOK = false;
	}

	// Überprüfen auf richtige Telefonnummer wenn vorhanden
	if (isOK && (Type == "telnummer") && (Value != "")) {
		if (Value.indexOf('+') == 0){
			Nummer = Value.substr(1,Value.length-1);
			Nummern = Nummer.split("-");
			if (Nummern.length == 3) {
				Land = Nummern[0];
				Vorwahl = Nummern[1];
				Nummer = Nummern[2];

				var RegExpr = /[^0-9]/;
				Result = RegExpr.exec(Land);
				if ((Result != null) && (Result != '')) {isOK = false;}

				Result = RegExpr.exec(Vorwahl);
				if ((Result != null) && (Result != '')) {isOK = false;}

				Result = RegExpr.exec(Nummer);
				if ((Result != null) && (Result != '')) {isOK = false;}

				ErrorMessage = ErrorMessages['richtige_Telefonnummer'];
			}	else {
				isOK = false;
				ErrorMessage = ErrorMessages['richtige_Telefonnummer'];
			}
	} else {
			if (isOK) {
				isOK = false;
				ErrorMessage = ErrorMessages['richtige_Telefonnummer'];
			}
		}
	}

	// alert(isOK + ' ' + Result);

	if (!isOK) {
		alert(ErrorMessages['Fehler']+'! ' + ErrorMessage);
		if(Transmitter.indexOf('[]') == -1){
			window.setTimeout(Transmitter + ".focus();" + Transmitter + ".select();",10);
		}
	}
	return isOK;
}

function doNothing() {
	// nix tun
}

//Cookie lesen:
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
	}
	return null;
}

// Cookie setzen:
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
var exp = new Date();
exp.setTime(exp.getTime() + (100000*24*60*60*1000));

// Cookie-Wert auslesen:
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function showElement(id) {
	elem = document.getElementById(id);
	if(elem)
		elem.style.display = '';
}

function visibleElement(id) {
	elem = document.getElementById(id);
	if(elem)
		elem.style.visibility = 'visible';
}

function hideElement(id) {
	elem = document.getElementById(id);
	if(elem)
		elem.style.display = 'none';
}

function invisibleElement(id) {
	element = document.getElementById(id);
	if(element)
		element.style.visibility = 'hidden';
}

function closeElements(sID,sIdent,sKind) {
	for (iZL = 0; iZL < document.getElementsByTagName(sKind).length; iZL++) {
		oElement = document.getElementsByTagName(sKind)[iZL];

		if ((oElement.id.indexOf(sIdent) > -1) && (oElement.id != sID)){
			oElement.style.display = 'none';
		}
	}
}

function changeElement(sID,sIdent,sKind) {

	if ((sIdent != '') && (sKind != '')) {
		closeElements(sID,sIdent,sKind);
	}

	if (document.getElementById(sID)) {
		if (document.getElementById(sID).style.display == 'none') {
			document.getElementById(sID).style.display = '';
		} else {
			document.getElementById(sID).style.display = 'none';
		}
	}
}

function changeState(id,ItemID,img,blastitem,bsubmenu,cIMGPATH) {
	element = document.getElementById(id);
	if(element){
		if (element.style.display == 'none'){
			openTree(id,ItemID,img,blastitem,bsubmenu, cIMGPATH);
		} else if (element.style.display == ''){
			closeTree(id,ItemID,img,blastitem,bsubmenu, cIMGPATH);
		}
	}
}

function getTreeIcon(blastitem,bsubmenu,expanded, cIMGPATH){
	var img;
	var img_path = cIMGPATH+'/';

	img = img_path + "menu_empty.gif";
	if (!bsubmenu) { // wenn es keine tieferen Ebenen hinter diesem Punkt gibt
			if (blastitem) // ist es das letzte Element?
				img = img_path + "menu_con_2.gif";
			else
				img = img_path + "menu_con_3.gif";
		 } else {
				if (blastitem) {// ist es das letzte Element?
					if(expanded)
						img = img_path + "menu_plus_2.gif";
					else
						img = img_path + "menu_minus_2.gif";
				}
				else{
					if(expanded)
							img = img_path + "menu_plus_1.gif";
						else
							img = img_path + "menu_minus_1.gif";
				}
		}
		return img;
}

function openTree(id,ItemID,img,blastitem,bsubmenu, cIMGPATH) {
	if(bsubmenu){
		element = document.getElementById(id);
		if(element){
			if (document.getElementById(id).style.display == 'none'){
				showElement(id);
				imglink = getTreeIcon(blastitem,bsubmenu,false, cIMGPATH);
				document[img].src = imglink;
			}
		}
	}
}

function closeTree(id,ItemID,img,blastitem,bsubmenu, cIMGPATH) {
	if(bsubmenu){
		element = document.getElementById(id);
		if(element){
			if (element.style.display == ''){
				hideElement(id);
				imglink = getTreeIcon(blastitem,bsubmenu,true, cIMGPATH);
				document[img].src = imglink;
			}
		}
	}
}

function replaceImage(img, filename) {
	if(img){
		if(document[img]){
			document[img].src = filename;
		}
	}
}

function markMenuPos(id,currclass,nojump, sBgCol, sColSel) {
	if(!sBgCol)
		sBgCol = sBgColor;
	if(!sColSel)
		sColSel = sColSelected;
	if(lastMark && lastMark.length != 0){
		element =  document.getElementById(lastMark);
		if(element){
			document.getElementById(lastMark).className = lastClass;
			document.getElementById(lastMark).style.color = lastFontMarkColor;
		}
	}
	element = document.getElementById(id);
	if(element){
		element.className = currclass;
		lastFontMarkColor = element.style.color;
		element.style.color = fontMarkColor;
	}
	lastMark = id;
	lastClass = currclass;

	if(!nojump){
		href = self.location.href;
		var pos = href.lastIndexOf("#");
		if(pos != -1)
			var href = href.slice(0,pos);
		href = href + '#anchor_'+id;
		self.location.href=href;
	}
}

function openPart(id, currclass) {
	if(!currclass){
		currclass="Verdana11Black";
	}
	var img = document.getElementById('img_'+id);
	if(img){
		var src = img.src;
		if(src.search(/menu_con.+/) == -1 ){
			src = src.replace(/menu_plus_2.gif/,"menu_minus_2.gif");
			src = src.replace(/menu_plus_1.gif/,"menu_minus_1.gif");
			img.src = src;
		}
	}
	showElement('sub_'+id);
	markMenuPos(id, currclass, sBgColor, sColSelected);
}

function bw_check() {
	is_major      = parseInt(navigator.appVersion);
	this.nver     = is_major;
	this.ver      = navigator.appVersion;
	this.agent    = navigator.userAgent;
	this.dom      = document.getElementById ? 1 : 0;
	this.opera    = window.opera ? 1 : 0;

	this.ie5      = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera) ? 1 : 0;
	this.ie6      = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera) ? 1 : 0;
	this.ie7      = (this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera) ? 1 : 0;
	this.ie4      = (document.all && !this.dom && !this.opera) ? 1 : 0;
	this.ie       = this.ie4 || this.ie5 || this.ie6 || this.ie7;
	this.mac      = this.agent.indexOf("Mac")>-1;
	this.ns6      = (this.dom && parseInt(this.ver)>=5) ? 1 : 0;
	this.ie3      = (this.ver.indexOf("MSIE") && (is_major<4));
	this.hotjava  = (this.agent.toLowerCase().indexOf('hotjava')!=-1) ? 1 : 0;
	this.ns4      = (document.layers && !this.dom && !this.hotjava) ? 1 : 0;
	this.bw       = (this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera);
	this.ver3     = (this.hotjava || this.ie3);
	this.opera7   = ((this.agent.toLowerCase().indexOf('opera 7')>-1) || (this.agent.toLowerCase().indexOf('opera/7')>-1));
	this.operaOld = this.opera && !this.opera7;

	if (this.ie3 || this.ie4 || this.ie5 || this.ie6 || this.ie7) {
		return 'ie';
	}
	if (this.mac) {
		return 'mac';
	}
	if (this.ns4 || ns6) {
		return 'ns';
	}
}

function NewWindow(sParamUrl, sParamWindowName, iParamWidth, iParamHeight, sParamPosition, sParamScrollbars) {

	var sResizable="no";

	if (sParamPosition == "center") {
		posX    = Math.round((screen.availWidth-iParamWidth)/2);
		posY    = Math.round((screen.availHeight-iParamHeight)/2);
	} else  if (sParamPosition == "HELP") {
		var bw = bw_check();
		sResizable="yes";
		if (bw == "ie") {
			//alert("ie Screen Width:" + screen.Width + " Screen Height:" + screen.Height);
			top.window.resizeTo(screen.Width - 226, screen.Height);
			iParamHeight = screen.availHeight;
		}
		if ((bw == "ns") || (bw == "mac")) {
			//alert("ns Screen Width:" + window.outerWidth + " Screen Height:" + window.outerHeight);
			window.resizeTo(window.outerWidth - 244, window.outerHeight);
			iParamHeight = window.outerHeight;
		}
		posX    = Math.round(screen.availWidth-iParamWidth) - 5;
		posY    = 0;
	} else {
		posX = 10;
		posY = 10;
	}

	wnd = window.open(sParamUrl, sParamWindowName, "width="+iParamWidth+",height="+iParamHeight+",left="+posX+",top="+posY+",scrollbars="+sParamScrollbars+",resizable="+sResizable);
	if(wnd)
		wnd.focus();
	return wnd;
}

function ImagePoolWindow(sParamUrl, sParamWindowName, iParamWidth, iParamHeight, sParamScrollbars, sParamFormStr, sParamIDTarget, sParamNameTarget) {

	var sResizable="no";

	posX    = Math.round((screen.availWidth-iParamWidth)/2);
	posY    = Math.round((screen.availHeight-iParamHeight)/2);

	wnd = window.open(sParamUrl + '&form_str=' + sParamFormStr + '&id_target=' + sParamIDTarget + '&name_target=' + sParamNameTarget, sParamWindowName, "width="+iParamWidth+",height="+iParamHeight+",left="+posX+",top="+posY+",scrollbars=no,resizable="+sResizable);
	if(wnd)
		wnd.focus();
	return wnd;
}

function DownloadPoolWindow(sParamUrl, sParamWindowName, iParamWidth, iParamHeight, sParamScrollbars, sParamFormStr, sParamIDTarget, sParamNameTarget) {

	var sResizable="no";

	posX    = Math.round((screen.availWidth-iParamWidth)/2);
	posY    = Math.round((screen.availHeight-iParamHeight)/2);

	wnd = window.open(sParamUrl + '&form_str=' + sParamFormStr + '&id_target=' + sParamIDTarget + '&name_target=' + sParamNameTarget, sParamWindowName, "width="+iParamWidth+",height="+iParamHeight+",left="+posX+",top="+posY+",scrollbars=no,resizable="+sResizable);
	if(wnd)
		wnd.focus();
	return wnd;
}

function NewComponentTree(Path, Session, NameField, CompIDField, FormName, obj_id, DefNameField, CompDefIDField, preCompName, preCompId, mode, importMode) {

	iWidth = 578;
	iHeight = 600;
	posX    = Math.round((screen.availWidth-iWidth)/2);
	posY    = Math.round((screen.availHeight-iHeight)/2);

	p_id = '';
	pu_id = '';
	generalmode = '';

	if(mode == 'park'){
		p_id = obj_id;
	}
	else if (mode == 'general'){
		//weder pu noch p
		generalmode = '1';
	}
	else{
		pu_id = obj_id;
	}

	newWindow = window.open(Path + '/comp_index.php?PHPSESSID=' + Session + '&showselection=1&preCompName=' + preCompName + '&preCompId=' + preCompId + '&NameField=' + NameField + '&CompIDField=' + CompIDField + '&FormName=' + FormName + '&p_id='+p_id+'&pu_id=' + pu_id + '&DefNameField=' + DefNameField + '&CompDefIDField=' + CompDefIDField + '&generalmode=' + generalmode + '&importMode=' + importMode, 'CompTree', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY + ',resizable=no,scrollbars=no');
	newWindow.focus();

	return newWindow;
}

function NewRawDataImport(Path,Session,args) {
	iWidth = 800;
	iHeight = 600;

	posX    = Math.round((screen.availWidth-iWidth)/2);
	posY    = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/rep_rawdata_import.php?PHPSESSID=' + Session + args, 'RawImport', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY + ',resizable=yes,scrollbars=yes');
	NewWindow.focus();

	return NewWindow;
}

function highlightrow(id, bgColor) {
	elem = document.getElementById(id);
	if(elem)
		elem.style.backgroundColor=bgColor;
}

function dehighlightrow(id, bgColor, oldColor) {
	elem = document.getElementById(id);
	if(elem) {
		if(oldColor != null && oldColor != '')
			bgColor = oldColor;
		elem.style.backgroundColor = bgColor;
	}
}

/**
 * Fügt zum jeweiligen Browser ein Bookmark bzw. Favoriten hinzu
 */
function addToFavorite(url, title){
	var bw = bw_check();
	if (bw == "ie")
		window.external.AddFavorite(url,title);
	if (bw == "ns")
		window.sidebar.addPanel(title,url,'');
}

/**
 * öffnet ein kleines Fenster mit mehreren zum Ereignis gehörenden Vorgängen
 */
function AssignedProcesses(erl_id, pu, cPATH, PHPSESSID) {
	url = cPATH+"/pu_logbuch_erlproc.php?PHPSESSID="+PHPSESSID+"&erl_id="+erl_id+"&pu_id="+pu+"&mode=overview";
	iWidth  = 500;
	iHeight = 300;
	posX    = Math.round((screen.availWidth-iWidth)/2);
	posY    = Math.round((screen.availHeight-iHeight)/2);
	frmLogbuch_Book = window.open(url,"logbuch_ErlProc","width="+iWidth+",height="+iHeight+",left="+posX+",top="+posY+",scrollbars=no");
	frmLogbuch_Book.focus();
}

/**
 * öffnet das Vorgangsfenster
 */
function openProcInfo(proc_id, cPATH, PHPSESSID) {
	uri=cPATH+"/proc_index.php?PHPSESSID="+PHPSESSID+"&proc_id="+proc_id;
	//alert(uri);
	oeffneFenster(uri,'procindex',800,600,'CENTER','no');
}

/**
 * öffnet das Dokumenteneigenschaften
 */
function openDocumentProperties(doc_id, cPATH, PHPSESSID) {
	uri=cPATH+"/document_properties.php?PHPSESSID="+PHPSESSID+"&doc_id="+doc_id;
	oeffneFenster(uri,'doc_properties',400,470,'CENTER','yes');
}

/**
 * de- bzw. selektiert die checkbox mit der angegebenen ID
 */
function setRowCheckbox(id) {
	checkbox = document.getElementById(id);
	checkbox.checked = !checkbox.checked;
}

/**
 * öffnet das Komponenten-Adminfenster
 */
function CompAdmin(Path,Session,args) {
	iWidth = 575;
	iHeight = 600;

	posX = Math.round((screen.availWidth-iWidth)/2);
	posY = Math.round((screen.availHeight-iHeight)/2);

	var NewWindow = window.open(Path + '/comp_index.php?PHPSESSID=' + Session + args, 'AdminComp', 'width=' + iWidth + ',height=' + iHeight + ',left=' + posX + ',top=' + posY +',noscrollbars');
	NewWindow.focus();
}


function disableElement(element_name) {
	element = document.getElementById(element_name);
	if(element)
		element.disabled=true;
}

function enableElement(element_name) {
	element = document.getElementById(element_name);
	if(element)
		element.disabled=false;
}

/**
 * Füllt die Datumsfelder in den Auswertungs-, Rohdaten- und Betriebsführungsbericht-Menüs
 */
function fillDateInput(startDay, startMonth, startYear, startHour, startMin, endDay, endMonth, endYear, endHour, endMin ){
	frm = document.form1;

	if(startDay.length 	 == 1) startDay 	= '0' + startDay;
	if(endDay.length 		 == 1) endDay 		= '0' + endDay;
	if(startMonth.length == 1) startMonth = '0' + startMonth;
	if(endMonth.length 	 == 1) endMonth 	= '0' + endMonth;

	elem = frm.startMin;
	if(elem) elem.value = startMin;
	elem = frm.startHour;
	if(elem) elem.value = startHour;
	elem = frm.startDay;
	if(elem) elem.value = startDay;
	elem = frm.startMonth;
	if(elem) elem.value = startMonth;
	elem = frm.startYear;
	if(elem) elem.value = startYear;

	elem = frm.endMin;
	if(elem) elem.value = endMin;
	elem = frm.endHour;
	if(elem) elem.value = endHour;
	elem = frm.endDay;
	if(elem) elem.value = endDay;
	elem = frm.endMonth;
	if(elem) elem.value = endMonth;
	elem = frm.endYear;
	if(elem) elem.value = endYear;
}

/**
 * formatiert Zahlen
 *
 * zahl = Zahl (Komma wird durch Punkt ersetzt)
 * k    = Nachkommastellen
 * fix  = Nachkommastelle mit Nullen auffüllen?
 */
function number_format(zahl, k, fix)
{
		// zahl = Zahl :-)
		// k = Nachkommastellen
		// fix = Nachkommastelle mit Nullen auffüllen?

    if(!k) k = 0;
    var neu = '';
    zahl = zahl+"";
    zahl = zahl.replace(",", ".");

    // Nachkommastellen
    var f = Math.pow(10, k);
    zahl = ''+parseInt(zahl*f+.5)/f;
    var idx = zahl.indexOf('.');
    if(idx == -1) {
    	idx = zahl.length;
    	if (k>0)
    		neu = ',' + zahl.substring(idx + 1);
    } else {
    	neu = ',' + zahl.substring(idx + 1);
    }

    // fehlende Nullen einfügen
    if(fix) {
    	for(var i=neu.length-1; i<k; i++) {
    		neu = neu + '0';
    	}
    }
    while(idx > 0) {
        if(idx - 3 > 0)
        	neu = '.' + zahl.substring( idx - 3, idx) + neu;
        else
        	neu = zahl.substring(0, idx) + neu;
        idx -= 3;
    }
    return neu;
}

function $(id)
{
	return document.getElementById(id);
}

function showExtMenu(id)
{
	closeElements('', 'menudiv_', 'div');
	$(id).style.display = 'block';
	aktivExtMenu = id;
}


function hideExtMenu()
{
	breakBool = false;
	timer = window.setTimeout("doHideExtMenu()", 10);
}

function doHideExtMenu()
{
	if(aktivExtMenu != "" && breakBool == false)
	{
		closeElements('', 'menudiv_', 'div');
		//$(aktivExtMenu).style.display = 'none';
		aktivExtMenu = "";
	}
}

function extMenuStopTimer()
{
	breakBool = true;
	window.clearTimeout(timer);
	showExtMenu(aktivExtMenu);
}
