// JavaScript Document

function GetCtrlKeyCode(secKey, cmd2execute)
{	var isCtrl = false;
	document.onkeyup=function(e) 
	{
		if(e.which == 17) isCtrl=false;	
	}
	document.onkeydown=function(e)
	{
	if(e.which == 17) isCtrl=true;
		if(e.which == secKey && isCtrl == true) 
		{
		alert('Ctrl Key found');
//		return false;
		}
	}
}

// ** Setzt den Focus() auf ElementID **********************************************************************************
function setFocusOnID(ElementID)
{	var e = document.getElementById(ElementID);
	document.getElementById(ElementID).focus(); 
}
//***********************************************************************************************************************

// ** Überprüft angegebenen ID auf Textlänge und Enabled BtnID **********************************************************
function checkLengthANDEnableBtn(ElementID, myLength, btnID)
{	var e = document.getElementById(ElementID).value
	var l = e.length
	if (l>myLength)
		enableBtn(btnID); 
}
//***********************************************************************************************************************

// ** Fügt angegebene URL zu den Favoriten hinzu (NUR FF und IE) ********************************************************
function AddFavorite(title,url)
{	if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){
		var e = document.createElement('a');
		e.setAttribute('href',url);
		e.setAttribute('title',title);
		e.setAttribute('rel','sidebar');
		e.click();
} 	else if(document.all)
		window.external.AddFavorite(url, title); 
}
//***********************************************************************************************************************


// ** Macht ein Reload des aktuellen Fensters ***************************************************************************
function RefreshWin(withURL) 
{	focus();
	location.href = withURL; 
}
//***********************************************************************************************************************


function RefreshParentWin(withURL) 
{	opener.focus();
	opener.location.href = withURL;
	self.focus(); 
}
//***********************************************************************************************************************


// ** Ändert die Größe des aktuellen Fensters**************************** ***********************************************
function wResize(w,h) 
{	window.resizeBy(w, h); 
}
//***********************************************************************************************************************


// ** Toggle Element-ID CSS:Hidden/visible - je nach Starteigenschaft *************************************************
function toggleVisibilityID(ElementID)
{	var e = document.getElementById(ElementID);
	if(e.style.visibility == 'visible')
		e.style.visibility = 'hidden';
	else if(e.style.visibility == 'hidden')
		e.style.visibility = 'visible';
}
//***********************************************************************************************************************
// ** macht Element-ID CSS:Hidden **************************************************************************************
function hideID(ElementID)
{	var e = document.getElementById(ElementID);
	e.style.visibility = 'hidden'; 
}
//***********************************************************************************************************************
// ** macht Element-ID CSS:Visible *************************************************************************************
function showID(ElementID)
{	var e = document.getElementById(ElementID);
	e.style.visibility = 'visible'; 
}
//***********************************************************************************************************************


// ** Überprüft angegebenen ID auf Textlänge und toggled readonly Attribut ***********************************************
function checkLengthANDdisableReadOnlyStatus(ElementID, myLength, btnID)
{	var e = document.getElementById(ElementID).value
	var b = document.getElementById(btnID)
	var l = e.length
	if (l>myLength)
		if(b.getAttribute("readonly"))
			b.removeAttribute("readonly"); 
}


// ** Toggle Attribut READONLY von ElementID - je nach Starteigenschaft  ****************************************************
function toggleReadOnlyStatus(ElementID)
{	var e = document.getElementById(ElementID);
	if(e.getAttribute("readonly"))
		e.removeAttribute("readonly"); 
	else
		e.setAttribute("readonly", "readonly");
}


// ** Toggle Attribut DISABLED von BtnID - je nach Starteigenschaft  ****************************************************
function toggleBtnStatus(btnID)
{	var btn = document.getElementById(btnID);
	if(btn.getAttribute("disabled"))
		enableBtn(btnID);
	else
		disableBtn(btnID);
}
//***********************************************************************************************************************
// ** Entfernt Attribut DISABLED von BtnID ******************************************************************************
function enableBtn(btnID)
{	var btn = document.getElementById(btnID)
	btn.removeAttribute("disabled"); 
}
//***********************************************************************************************************************
// ** Setzt Attribut DISABLED von BtnID ******************************************************************************
function disableBtn(btnID)
{	var btn = document.getElementById(btnID)
	btn.setAttribute("disabled", "disabled");
}
//***********************************************************************************************************************


// ** hängt Text ans Ende der Parent Element-ID an *********************************************************************
function appendText2ParentID(myText, ElementID)
{	window.opener.document.getElementById(ElementID).value = window.opener.document.getElementById(ElementID).value+myText
	window.opener.document.getElementById(ElementID).focus; 
}
//***********************************************************************************************************************


// ** fügt Text ans Ende der Element-ID an *********************************************************************
function toggleText4ID(myText, ElementID)
{	if(document.getElementById(ElementID).value != myText)
		document.getElementById(ElementID).value = document.getElementById(ElementID).value+myText;
	else
		document.getElementById(ElementID).value = '';
}
//***********************************************************************************************************************


// ** fügt Text an Cursorposition in Parent Element-ID ein **************************************************************
function insertText2ParentID(myText, ElementID)
{	if (window.opener.document.getElementById(ElementID).createTextRange)
		{ 	window.opener.document.getElementById(ElementID).focus();
			window.opener.document.selection.createRange().duplicate().text = myText;
		}
	else if (window.opener.document.getElementById && !document.all) // Mozilla
		{ 	var tarea = window.opener.document.getElementById(ElementID);	
			var selEnd = tarea.selectionEnd;
			var txtLen = tarea.value.length;
			var txtbefore = tarea.value.substring(0,selEnd);
			var txtafter =  tarea.value.substring(selEnd, txtLen);
			tarea.value = txtbefore + myText + txtafter;
		}
	else
	{
	window.opener.document.entryform.text.value += myText; 
	}
}


// ** erstellt ein HTML Alert Fenster ************************************************************************************
function showAlertWin(WindowTitle, myMSG, w, h)
{	var width=w, height=h;
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var msgWindow = window.open("","msgWindow", styleStr);
	var head = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>'+WindowTitle+'</title><link href="/ALL.css" rel="stylesheet" type="text/css"></head>';
	var body = '<body style="margin:5px; padding:5px; text-align:center;">'+myMSG+''
	var footer = '<br><br><form><input type="button" value="OK" onClick="self.close();"></form></body></html>';
	msgWindow.document.write(head + body + footer); 
}
//*************************************************************************************************************************


// ** erstellt ein HTML Fenster in dem Images angezeigt werden **************************************************************
function showImg(WindowTitle, myMSG, w, h)
{	var width=w, height=h;
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var msgWindow = window.open("about:blank","imgWindow", styleStr);
	var head = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n<head>\n<title>'+WindowTitle+'</title>\n<link href="/ALL.css" rel="stylesheet" type="text/css">\n</head>';
	var body = '\n<body style="margin:5px; padding:5px; text-align:center;" onkeydown="if (event.keyCode == 27) {self.close();}">\n'+myMSG+'\n'
	var footer = '<br>\n<br>\n<form>\n<input type="button" value="OK / ESC" class="content_save_btn" onClick="self.close();">\n</form>\n</body>\n</html>';
	msgWindow.document.write(head + body + footer); 
}
//*************************************************************************************************************************


// ** erstellt ein neues Fenster ******************************************************************************************
function OpenNewWindow(newURL, WindowTitle, w, h)
{	var width=w, height=h;
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var msgWindow = window.open(newURL, WindowTitle, styleStr); 
}
//******************************************************************************************************************************


// ** Aktualisiert den Seitentitel *******************************************************************************
function RefreshTitle(pagetitle)
{	document.title = pagetitle + " / bpi-solutions";
	return null; 
}
//*****************************************************************************************************************


// ** erstellt ein xmlHTTP Object *********************************************************************************
function createXHR() 
{	try {return new XMLHttpRequest();} 
		catch(e) {}
	try {return new ActiveXObject("Msxml2.XMLHTTP");} 
		catch (e) {}
	alert("Ihr Browser unterstützt leider kein AJAX");
   return null; 
}
//*****************************************************************************************************************


// ** Aktualisiert angegebene DIV-ID mit Inhalt aus myURL und setzt (optional) Title*******************************
function RefreshDiv(Div2Refresh, myURL, PageTitle)
{	var Browser = navigator.appName;

	xhr = createXHR();
	xhr.onreadystatechange=function() {
		if(xhr.readyState==4) {
		  	document.getElementById(Div2Refresh).innerHTML=xhr.responseText;
			if(PageTitle) {
				document.title = PageTitle;
			}
		}
	}
	if(Browser == "Microsoft Internet Explorer") {
		xhr.open("GET", myURL, false);
	}
	else {
		xhr.open("GET", myURL, true);
	}
	xhr.send(null);
	return null; 
}
//*****************************************************************************************************************


// ** Aktualisiert automatisch angegebene DIV-ID mit Inhalt aus myURL in RefreshInterval MiliSec*******************
function AutoRefreshDiv(Div2Refresh, myURL, RefreshInterval)
{	var xhr = createXHR();
	var Browser = navigator.appName;
	
	xhr.onreadystatechange=function() {
		if(xhr.readyState==4) {
			document.getElementById(Div2Refresh).innerHTML=xhr.responseText;
		}
	}
	if(Browser == "Microsoft Internet Explorer") {
		xhr.open("GET", myURL, false);
	}
	else {
		xhr.open("GET", myURL, true);
	}
	xhr.send(null);
	setTimeout("AutoRefreshDiv('"+ Div2Refresh +"', '"+ myURL +"', '"+ RefreshInterval +"')", RefreshInterval);
	return null; 
}
//*****************************************************************************************************************


// ** Erstellt eine Uhr in angegebener clockDiv. Sofern RefreshIntervall angegeben werden Sekunden angezeigt 
// ** und alle Refreshintervall MilliSekunden aktualiert. Ohne Angabe RefreshIntervall werden nur Minuten angezeigt
// ** und automatisch alle 60 Sekunden aktualisiert ******************************************************************
function clock(clockDiv, RefreshInterval)
{	thedate = new Date();
	h = thedate.getHours();
	m = thedate.getMinutes();
	s = thedate.getSeconds();	

	var myAktTime='';
	myAktTime+=Math.round((h+5)/10-1);
	myAktTime+=h - Math.round((h+5)/10-1)*10;

	myAktTime+=':';
	
	myAktTime+=Math.round((m+5)/10-1);
	myAktTime+=m - Math.round((m+5)/10-1)*10;

	if(RefreshInterval) {
		myAktTime+=':';
		myAktTime+=Math.round((s+5)/10-1);
		myAktTime+=s - Math.round((s+5)/10-1)*10;
	}
	else {
	}
		
	document.getElementById(clockDiv).innerHTML=myAktTime;

	if(RefreshInterval) {
	}
	else {
		RefreshInterval = 60000;
	}
		
	window.setTimeout("clock('"+ clockDiv +"', '"+ RefreshInterval +"');", RefreshInterval); 
}
//*****************************************************************************************************************
