// *** Variablen und Events fuer Hilfefenster
var MausTyp, X, Y, WinHelpID;
var isDOM 	= (document.getElementById) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isIE 		= (document.all) ? true : false;
var isNS 		= (document.layers && !isDOM && !isIE) ? true : false;
document.onmousedown = Move;
document.onmousemove = Move;
document.onmouseup = Move;

// *********************************
function ChColor(BGFarbe, objSource)
{
	objSource.style.background = BGFarbe;
}

// *** Zweidimmensionales Array

function MakeArray2Dim(spalten,zeilen)
{
	this.dim = new Array(spalten,zeilen)
	for (var i=0; i < spalten; i++)
	{
		this[i] = new Array(zeilen)
	}
}
// *** Bildschirminfos (Hoehe,Breite)

function BSInfo()
{
	this.Height	= screen.availHeight;
	this.Width	= screen.availWidth;
}

// *** Editor oeffnen ab IE 5.5

function Edit (Url, Name, Breite, Hoehe, UrlEncode, Menbar, Status, i)
{
	var Version, A, E;
	A= navigator.userAgent.indexOf("MSIE");
	E= navigator.userAgent.indexOf(";",A);
	Version = navigator.userAgent.substring(A + 5,E);

	if((isIE && Version == 5.5) || (isIE && Version.substr(0,1) > 5))
	{
		WinAuf(Url, Name, Breite, Hoehe, UrlEncode, Menbar, Status);
	}
	else
	{
		document.all["T"+i].innerHTML = "<textarea style=\"width: 95%;\" rows=\"5\" name=\"Text2"+i+"\" id=\"T"+i+"\">" + document.all["T"+i].innerHTML + "</textarea>";
	}
}

// *** Ueberschrift in Layout anzeigen

function Headline (i)
{
	var Headline = document.all['Headline'+i].value;
	document.all["HL"+i].innerHTML = "<input type=\"text\" name=\"Headline"+i+"\" size=\"80\" maxlength=\"100\" value=\"\">";
	document.all['Headline'+i].value = Headline;
}

// *** Zusatzfenster oeffnen (z.B. fuer Bilder)
function WinHelp(strUrl, strBreite, strHoehe, strMenbar, strStatus) 
{
	WinAuf(strUrl, 'Hilfe', strBreite, strHoehe, strMenbar, strStatus);
}

function WinAuf(strUrl, strWName, strBreite, strHoehe, strMenbar, strStatus) 
{
	if(!strMenbar) strMenbar = "1";
	if(!strStatus) strStatus = "1";
	var strBS;
	strBS =  new BSInfo();
	if (!strBreite) strBreite = 400;
	var strLeft = (strBS.Width - strBreite) / 2;
	if (!strHoehe) strHoehe = 430;

	var win =  window.open(strUrl, strWName,
 "alwaysRaised=yes,dependent=yes,left="+strLeft+",top=70,width="+strBreite+",height="+strHoehe+",scrollbars=yes,resizable=yes,menubar="+strMenbar+",status="+strStatus+"");
	win.focus();
}

function WinPrint(strUrl, strWName, strBreite, strHoehe, strMenbar, strStatus) 
{
	if(!strMenbar) strMenbar = "1";
	if(!strStatus) strStatus = "1";
	var strBS;
	strBS =  new BSInfo();
	if (!strBreite) strBreite = 400;
	var strLeft = (strBS.Width - strBreite) / 2;
	if (!strHoehe) strHoehe = 430;

	var win =  window.open(strUrl, strWName,
 "alwaysRaised=yes,dependent=yes,left="+strLeft+",top=70,width="+strBreite+",height="+strHoehe+",scrollbars=yes,resizable=yes,menubar="+strMenbar+",status="+strStatus+"");
	win.title = strWName;
	win.focus();
	//win.print();     <- FF hat kein Bock auf X-Scripting, deshalb window.print auf den Druckansichten im onLoad HS20061123
}

//*** Hilfefenster ***************************************
// *** Mauszeiger wechseln
function ChangeCursor(Cursor)
{
	if(isIE)
	{
		event.srcElement.style.cursor = Cursor;
	}
	else
	{
		document.cursor = Cursor;
	}
}
// *** Hilfelayer sichtbar machen

function OpenHelp(ID)
{
	var strBS, strTop, strLeft;
	strBS =  new BSInfo();
	if(isIE)
	{
		if(WinHelpID)
		{
			document.all("Help"+WinHelpID).style.visibility = "hidden";
		}
		strTop = (strBS.Height - (document.all("TDHelp"+ID).offsetHeight * 2)) / 2;
		if(strTop < 0 || parent.name == "Keywords") strTop = 0;
		strLeft = (strBS.Width - document.all("TDHelp"+ID).width) / 2;
		if(strLeft < 0 || parent.name == "Keywords") strLeft = 0;
		document.all("Help"+ID).style.top = strTop;
		document.all("Help"+ID).style.left = strLeft;
		document.all("Help"+ID).style.visibility = "";
	}
	else
	{
		if(WinHelpID)
		{
			document.layers["Help"+WinHelpID].visibility = "hidden";
		}
		strTop = (strBS.Height - (document.layers["Help"+ID].clip.height * 2)) / 2;
		if(strTop < 0 || parent.name == "Keywords") strTop = 0;
		strLeft = (strBS.Width - document.layers["Help"+ID].clip.width) / 2;
		if(strLeft < 0 || parent.name == "Keywords") strLeft = 0;
		document.layers["Help"+ID].pageY = strTop;
		document.layers["Help"+ID].pageX = strLeft;
		document.layers["Help"+ID].visibility = "show";
	}
	WinHelpID = ID;
}
// *** Hilfelayer unsichtbar machen

function CloseHelp(ID)
{
	if(isIE)
	{
		document.all("Help"+ID).style.visibility = "hidden";
	}
	else
	{
		document.layers["Help"+ID].visibility = "hidden";
	}
	WinHelpID = "";
}

// *** Eingabeformulare validieren

function FormValidate(oField, reReplace, reSweep, reTest, sErrorText) 
{

	var value = oField.value;
	var re;
	
	if (reReplace != '') {
		re = new RegExp(reReplace, 'gi');
		value = value.replace(re, ' ');	
	}

	if (reSweep != '') {
		re = new RegExp(reSweep, 'gi');
		value = value.replace(re, '');	
	}
	oField.value = value;

	if (reTest != '') {
		re = new RegExp(reTest, 'i');
		if (!re.test(value)) {
			oField.select();
			if (sErrorText == '') sErrorText = 'Ungültige Eingabe.';
			alert(sErrorText);
			return(false);
		}
	}
	
	return(true);
}

// *** Hilfefenster verschieben

function Move()
{
	if(WinHelpID)
	{
		strBS =  new BSInfo();
		if(window.event.type == "mousedown")
		{
			if(window.event.x >= document.all("Help"+WinHelpID).offsetLeft && window.event.x <= (document.all("Help"+WinHelpID).offsetLeft + document.all("TDHelp"+WinHelpID).width) && window.event.y >=    document.all("Help"+WinHelpID).offsetTop && window.event.y <= (document.all("Help"+WinHelpID).offsetTop + document.all("TDHelp"+WinHelpID).offsetHeight))
			{
				MausTyp = window.event.type;
				
				X = window.event.x;
				Y = window.event.y;
			}
		}
	
		if(MausTyp == "mousedown" && window.event.type == "mousemove")	
		{
			X = document.all("Help"+WinHelpID).offsetLeft + (window.event.x - X);
			Y = document.all("Help"+WinHelpID).offsetTop + (window.event.y - Y);
			if(X < 0)
			{
				X = 0;
			}
			if(Y < 0)
			{
				Y = 0;
			}
	   	document.all("Help"+WinHelpID).style.left = X;
			document.all("Help"+WinHelpID).style.top = Y;
			
			X = window.event.x;
			Y = window.event.y;
		}
		
		if(window.event.type == "mouseup") 
		{			
			MausTyp = "";
		}
	}
}

// *** Hilfelayer erzeugen

function HelpBox(Text,ID,Head,Breite)
{
	var strHead;
		if(Head)
	{
		strHead = Head;	
	}
	else
	{
		strHead = "Hilfe";
	}
	if(!Breite) Breite = 450;
	if(isIE)
	{
		document.write("<span ID=\"Help"+ID+"\" style=\"top: 0; left: 0; visibility: hidden; ");
		document.write("position: absolute; z-index: 99; border-style: outset; ");
		document.writeln("background-color: #000000;\">");
	}
	else
	{
		document.write("<div ID=\"Help"+ID+"\" style=\"visibility:hidden; position:absolute; ");
		document.writeln("z-index:8;\">");
		document.write("<table ID=\"TDHelp"+ID+"\" width=\""+(Breite + 10)+"\" ");
		document.writeln("cellspacing=\"0\">");
		document.writeln("  <tr>");
		document.writeln("    <td>");
	}
	document.write("    <table ID=\"TDHelp"+ID+"\" class=\"Help\" width=\""+Breite+"\" ");
	document.writeln("cellspacing=\"0\" cellpadding=\"5\">");
	document.writeln("      <tr>");
	document.writeln("        <td class=\"bgcolor\">"+strHead+"</td>");
	document.write("        <th class=\"bgcolor\" align=\"right\">");
	document.write("<a ID=\"IMG\" href=\"javascript:CloseHelp('"+ID+"');\" ");
	document.write("onClick=\"CloseHelp('"+ID+"')\" onMouseOver=\"ChangeCursor('Hand')\" ");
	document.write("onMouseOut=\"ChangeCursor('default')\">");
	document.write("<img src=\"../../images/Kreuz.gif\" border=\"0\" alt=\"Schliessen\" ");
	document.writeln("align=\"middle\"></a></th>");
	document.writeln("      </tr>");
	document.writeln("      <tr>");
	document.writeln("        <td colspan=\"2\">"+Text+"</td>");
	document.writeln("		  </tr>");
	document.writeln("      <tr>");
	document.write("        <td colspan=\"2\" align=\"right\">");
	document.write("<input class=\"button\" type=\"button\" value=\"Schliessen\" " +
								 "onClick=\"CloseHelp('"+ID+"')\" onMouseOver=\"ChangeCursor('Hand')\" " +
								 "onMouseOut=\"ChangeCursor('default')\">");
	document.writeln("        </td>");
	document.writeln("		  </tr>");
	document.writeln("		</table>");
	if(isIE)
	{
		document.write("</span>");
	}
	else
	{
		document.writeln("		</td>");
		document.writeln("	</tr>");
		document.writeln("</table>");
		document.writeln("</div>");
	}
}
//****************************************************

var expCookiesDays = 7; // number of days the cookie should last
var expCookies = new Date(); 
expCookies.setTime(expCookies.getTime() + (expCookiesDays*24*60*60*1000));

function ShowHide(ID, DefaultValue) {
	// value berechnen 
	var Value = GetCookie(ID);
	if (Value == null) Value = DefaultValue;
	if (DefaultValue == null) Value = (Value == 1) ? 0 : 1;
		
	// bilder setzten
	var oMenue = document.getElementById(ID);
	var oImg = document.getElementById(ID + 'Img');
	with ( document.location ) {
		var sImgPath = protocol + '//' + host + '/images/';
	}
	if (Value == 1) {
		oMenue.style.display = '';
		oImg.src = sImgPath + 'minus.gif';
		SetCookie(ID, 1, expCookies, '/');
	}
	else {
		oMenue.style.display = 'none';
		oImg.src = sImgPath + 'plus.gif';
		SetCookie(ID, 0, expCookies, '/')
	}
}

// ************************************

function CheckSelStart() 
{
	var oEvent = event.srcElement;

	return (oEvent.tagName == 'INPUT' || oEvent.xallowsel != null);
}

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;
}

function getCookieVal(offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

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" : "");
}

function DeleteCookie (name) 
{  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

