

/******************************************
 * Inhalt aus Popup in Feld übertragen    *
 ******************************************/

	function fillfield(vval, fldno)
	{
		len = document.form1.elements.length;
		for(var a=0; a<document.form1.elements.length;a++){
				if(document.form1.elements[a].name == "pcField_"+fldno )
				{
					document.form1.elements[a].value = vval;
				}
			}
	}


/**************************
 * Info-Fenster öffnen    *
 **************************/

function openinfowindow (furl, fname, fwidth, fheight)
{
	var features ='scrollbars=yes,resizable=yes';
	features = features+',width='+fwidth+',height='+fheight;
	win = window.open(furl, fname, features);
	win.focus();
}	


/**************************
 * Menü-Fenster öffnen    *
 **************************/

function OpenMenuWindow (furl, fname, fwidth, fheight, fleft, ftop)
{
	var features ='scrollbars=no,resizable=yes';
	features = features+',width='+fwidth+',height='+fheight+',left='+fleft+',top='+ftop;
	win = window.open(furl, fname , features)
	win.focus();
}	



/********************************************
 * Markieren einer oder mehrerer Checkboxen *
 ********************************************/
			
function Check_Checkbox(cb)
{
	if (cb.checked) {
		for (var i = 1; i < arguments.length; i++) {
			var c = cb.form[arguments[i]]
			if (c.type == "checkbox") {
				c.checked = true;
			} 
		}
	}
}
		


/**********************************************
 * Demarkieren einer oder mehrerer Checkboxen *
 **********************************************/

function Uncheck_Checkbox(cb)
{
	if (!cb.checked) {
		for (var i = 1; i < arguments.length; i++) {
			var c = cb.form[arguments[i]]
			if (c.type == "checkbox") {
				c.checked = false;
			} else if (c.type="text") {
				c.value = "0"
			}
		}
	}
}



var gNoPointerWait = false;
		
function setPointerWait()
{
	var strCursor;
			
	if (!gNoPointerWait)
	{
		strCursor = 'wait';
	} else {
		strCursor = 'default';
	}
	try
	{
		if (document.all)
		{
			for (var i=0;i < document.all.length; i++)
			{
				document.all(i).style.cursor = strCursor;
			}
		}
	}
	catch(e)
	{}
} //setPointerWait



function onPostBackEvent(eventSource, eventAttribute, ConfirmText)
{
	if (ConfirmText!="")
	{
		if (confirm(ConfirmText)) 
		{
			document.forms[0]._EventSource.value = eventSource;
			document.forms[0]._EventAttribute.value = eventAttribute;
			document.forms[0].submit();					
		} 
	}
	else
	{
		document.forms[0]._EventSource.value = eventSource;
		document.forms[0]._EventAttribute.value = eventAttribute;				
		document.forms[0].submit();					
	}
}


/*
	Update server time controls
*/

var lngServerTimeTimer;
var intServerHour;
var intServerMinute;

lngServerTimeTimer = 0;
			
function UpdateServerTimeHTML()
{
	var strHour;
	var strMinute;

				
	strHour = intServerHour < 10 ? '0' + intServerHour : intServerHour;
	strMinute = intServerMinute < 10 ? '0' + intServerMinute : intServerMinute;

				
	var elem;
	elem = document.getElementById("ServerTimeField");
	elem.innerHTML = strHour + ':' + strMinute;

}


function OnServerTimeTimer()
{
	SetServerTimeTimer();

	intServerMinute++;

	if ( intServerMinute == 60 )
	{
		intServerMinute = 0;
		intServerHour++;

		if ( intServerHour == 24 )
		{
			intServerHour = 0;
		}
	}

	UpdateServerTimeHTML();
}


function SetServerTimeTimer()
{
	lngServerTimeTimer = setTimeout ( "OnServerTimeTimer()", 60000 );
}

			

	function SetPopupListValues(Name, Value, Label)
	{
		return SetPopupListValuesEx(Name, Value, Label, "");
	}
	
	function SetPopupListValuesEx(Name, Value, Label, index)
	{
		var valueName, labelName, labelInputName, linkName;
		var suffix;
		
		suffix = "";
		
		if(index != "")
		{
			suffix = "_" + index;
		}

		valueName = Name + suffix;
		labelInputName = Name + "_Label" + suffix;
		labelName = "Div_" + Name + "_Label" + suffix;
		linkName = "Div_Link_" + Name + suffix;

		if (document.getElementsByName(valueName).length > 0)
		{
			document.getElementsByName(valueName)[0].value = Value;
		}
		
		if (document.getElementsByName(labelInputName).length > 0)
		{
			document.getElementsByName(labelInputName)[0].value = Label;
		}
		
		if (document.getElementById(labelName) != null)
		{
			document.getElementById(labelName).innerHTML = Label;		
		}
		
		if (document.getElementById(linkName) != null)
		{
			document.getElementById(linkName).innerHTML = Label;
		}
		
		return true;
	}



	function SetSearchBoxValues(Name, Value, Label, index)
	{
		var valueName, labelInputName;
		var suffix;
		
		suffix = "";
		
		if(index != "")
		{
			suffix = "_" + index;
		}

		valueName = Name + suffix;
		labelInputName = Name + "_Search" + suffix;

		if (document.getElementsByName(valueName).length > 0)
		{
			var elem = document.getElementsByName(valueName)[0];
			if(elem.type == "select-one")
			{
				var found = false;
				for(var i=0;i<elem.options.length;i++)
				{
					if(elem.options[i].value == Value)
					{
						found = true;
						break;
					}
				}
				
				if(!found)
				{
					var option = new Option();
					option.value = Value;
					option.text = Label;
					elem.options[elem.options.length] = option;
				}
			}
			elem.value = Value;
		}
		
		if (document.getElementsByName(labelInputName).length > 0)
		{
			document.getElementsByName(labelInputName)[0].value = Label;
		}
		
		return true;
	}



//----------------------------------------------------------------------
//Speedometer
//----------------------------------------------------------------------

var CHECK_INTERVAL = 10000;
var CHECK_FILE = "../images/Check.gif";
var CHECK_SIZE = 1269;
var SPEED_LIMITS = [9, 4.5, 3, 1.8, 1];//the last is actually not used...
var CHECK_NOCONNECTION = 60000;
var speedRequestTime = 0;
var timeoutID;
var noConnectionID;

function CheckSpeedStart()
{
	var theimage;
	speedRequestTime = (new Date()).getTime();
	//alert("Start");
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) 
	{
		theimage = document.images["SpeedBenchMark"];
	}
	else 
	{
		theimage = document.images.SpeedBenchMark;
	}
	noConnectionID = window.setTimeout(NoConnection, CHECK_NOCONNECTION);
	
	theimage.src = 
		CHECK_FILE + "?reload="
		+ speedRequestTime;
}
function NoConnection()
{
	CheckSpeedOnLoad();
}
function CheckSpeedOnLoad()
{
	if(speedRequestTime == 0) {
		timeoutID = window.setTimeout(CheckSpeedDelayed, CHECK_INTERVAL);
		return;
	}
	window.clearTimeout(noConnectionID);
	miliSec = (new Date()).getTime() - speedRequestTime;
	speed = CHECK_SIZE / miliSec;
	if(speed >= SPEED_LIMITS[0])
	{//very good
		col1 = '#00FF00';
		col2 = '#00FF00';
		col3 = '#00FF00';
		col4 = '#00FF00';
		col5 = '#00FF00';
		tooltip = 'Verbindung: Sehr gut';
	}
	else if(speed >= SPEED_LIMITS[1])
	{//good
		col1 = '#00FF00';
		col2 = '#00FF00';
		col3 = '#00FF00';
		col4 = '#00FF00';
		col5 = '#FF0000';
		tooltip = 'Verbindung: Gut';
	}
	else if(speed >= SPEED_LIMITS[2])
	{//middle
		col1 = '#00FF00';
		col2 = '#00FF00';
		col3 = '#00FF00';
		col4 = '#FF0000';
		col5 = '#FF0000';
		tooltip = 'Verbindung: Durchschnittlich';
	}
	else if(speed >= SPEED_LIMITS[3])
	{//bad
		col1 = '#00FF00';
		col2 = '#00FF00';
		col3 = '#FF0000';
		col4 = '#FF0000';
		col5 = '#FF0000';
		tooltip = 'Verbindung: Schlecht';
	}
	else if(speed > CHECK_SIZE / CHECK_NOCONNECTION)
	{//very bad
		//alert("Speed: " + speed + ". nc speed: " + (CHECK_SIZE / CHECK_NOCONNECTION));
		col1 = '#00FF00';
		col2 = '#FF0000';
		col3 = '#FF0000';
		col4 = '#FF0000';
		col5 = '#FF0000';
		tooltip = 'Verbindung: Sehr schlecht';
	}
	else
	{//No connection
		col1 = '#FF0000';
		col2 = '#FF0000';
		col3 = '#FF0000';
		col4 = '#FF0000';
		col5 = '#FF0000';
		tooltip = 'Verbindung: Keine';
	}
	
	document.getElementById('Bar1').style.backgroundColor = col1;
	document.getElementById('Bar2').style.backgroundColor = col2;
	document.getElementById('Bar3').style.backgroundColor = col3;
	document.getElementById('Bar4').style.backgroundColor = col4;
	document.getElementById('Bar5').style.backgroundColor = col5;

	document.images["Img1"].alt = tooltip;
	document.images["Img2"].alt = tooltip;
	document.images["Img3"].alt = tooltip;
	document.images["Img4"].alt = tooltip;
	document.images["Img5"].alt = tooltip;
	
	document.images["Img1"].title = tooltip;
	document.images["Img2"].title = tooltip;
	document.images["Img3"].title = tooltip;
	document.images["Img4"].title = tooltip;
	document.images["Img5"].title = tooltip;
	
	timeoutID = window.setTimeout(CheckSpeedDelayed, CHECK_INTERVAL);
}
function CheckSpeedDelayed()
{
	window.clearTimeout(timeoutID);
	CheckSpeedStart();
}
function ShowSpeedInfo()
{
	window.open ('SpeedInfo.asp', '_blank', 'resizable=no, width=530, height=550, left=0, top=0');
}
