//======================================================================
// Purpose: Opens a 640x480 PopUp
// Inputs:  --
// Returns: Window-Reference
// Remarks: Use together with <a href="..." target="winLukbPopup"
//======================================================================
function jsfOpenPopup()
{
	return jsfOpenSizedPopup(720, 740);
}

//======================================================================
// Purpose: Opens a PopUp
// Inputs:  iWidth, iHeight
// Returns: Window-Reference
// Remarks: Use together with <a href="..." target="winLukbPopup"
//======================================================================
function jsfOpenSizedPopup(iWidth, iHeight)
{
	return jsfOpenSpecificPopup(iWidth, iHeight, 'resizable=yes,toolbar=no,addressbar=no,menubar=no,scrollbars=yes,');
}

//======================================================================
// Purpose: Opens a PopUp
// Inputs:  iWidth, iHeight, sProps
// Returns: Window-Reference
// Remarks: Use together with <a href="..." target="winLukbPopup"
//======================================================================
function jsfOpenSpecificPopup(iWidth, iHeight, sProps)
{
	var winPopup = window.open('', 'winMcDoPopup', 'width=' + iWidth + ',height=' + iHeight + ',' + sProps);
	winPopup.focus();
	return winPopup;
}

//======================================================================
// Purpose: Table-Row alternater
// Inputs:  --
// Returns: --
//======================================================================
function ChangeRowColors()
{
	if(document.getElementsByTagName)
	{
		var tables = document.getElementsByTagName("table");
		for(var i=0; i<tables.length; i++)
		{
			var currTable = tables[i];
			if(currTable.className=='alternatingTable')
			{	
				var rows=currTable.getElementsByTagName("TR");
				for(var j=1; j<rows.length; j+=2)
				{
					rows[j].bgColor = '#ebebea' ;
					if((j+1)<rows.length)
					{
						rows[j+1].bgColor = '#999999';
					}
				}
			}
		}
	}
}

//======================================================================
// Purpose: Add current page to favorites.
// Inputs:  --
// Returns: --
//======================================================================
function jsfAddToFavorites()
{
	if(window.sidebar)
	{
		//--- Moz ---
		window.sidebar.addPanel(document.title, location.href, "");
	}
	else if(document.all)
	{
		//--- IE ---
		window.external.AddFavorite(location.href, document.title);
	}
}

//======================================================================
// Purpose: Open PrintView using PostBack.
// Inputs:  --
// Returns: --
//======================================================================
function jsfOpenPrintViewWindow()
{
	var oForm = document.forms["Form1"];
	
	if(oForm)
	{
		//--- Keep Form-action and -target ---
		var sOldAction = oForm.action;
		var sOldTarget = oForm.target;
		//--- Add Print-Param ---
		oForm.action += (oForm.action.indexOf('?')>-1 ? '&' : '?') + "print=true";
		//--- Set Target ---
		oForm.target = 'winMcDoPopup';
		//--- Open Win ---
		jsfOpenSpecificPopup(604, 640, 'resizable=yes,toolbar=no,addressbar=no,menubar=yes,scrollbars=yes,status=yes,')
		//--- Popup-Postback ---
		__doPostBack('', '');
		//--- Reset Postback-Form ---
		oForm.action = sOldAction;
		oForm.target = sOldTarget;
	}
}

//======================================================================
// Purpose: Print current window.
// Inputs:  --
// Returns: --
//======================================================================
function jsfPrint()
{
	window.print();
}

//======================================================================
// Purpose: Used for .Net unicode-style escaping.
// Inputs:  rohtext : string to encode
// Returns: encoded string...
// Remarks: Developed by SelfHTML, added by dirty-vinz:
//          http://aktuell.de.selfhtml.org/artikel/javascript/utf8b64/utf8.htm
//======================================================================
function encode_utf8(rohtext) {
	// dient der Normalisierung des Zeilenumbruchs
	rohtext = rohtext.replace(/\r\n/g,"\n");
	var utftext = "";
	for(var n=0; n<rohtext.length; n++) {
		// ermitteln des Unicodes des  aktuellen Zeichens
		var c=rohtext.charCodeAt(n);
		// alle Zeichen von 0-127 => 1byte
		if (c<128)
			utftext += String.fromCharCode(c);
		// alle Zeichen von 127 bis 2047 => 2byte
		else if((c>127) && (c<2048)) {
			utftext += String.fromCharCode((c>>6)|192);
			utftext += String.fromCharCode((c&63)|128);
		}
		// alle Zeichen von 2048 bis 66536 => 3byte
		else {
			utftext += String.fromCharCode((c>>12)|224);
			utftext += String.fromCharCode(((c>>6)&63)|128);
			utftext += String.fromCharCode((c&63)|128);
		}
	}
	return utftext;
}

//======================================================================
// Purpose: Used to get the Numeric Value of a Textboc
// Inputs:  The Id of the Textbox
// Returns: The Value
// Remarks: Used for the MortgageCalculator
//======================================================================
function jsfGetTextBoxAmount(fieldid)
{
	var objAmount = document.getElementById(fieldid);
	if( objAmount !=null)
	{
		var sValue = objAmount.value;
		if(!isNaN(parseInt(sValue)))
		{	
			return parseInt(sValue);
		}
	}
	return 0;
}

//======================================================================
// Purpose: Used to get the Numeric Value of a Textboc
// Inputs:  The Id of the Textbox
// Returns: The Value
// Remarks: Used for the MortgageCalculator
//======================================================================
function jsfValidateTextBoxAmount(fieldid,errorfieldid)
{
	var objAmount = document.getElementById(fieldid);
	if( objAmount !=null)
	{
		var sValue = objAmount.value;
		if(!isNaN(parseInt(sValue)))
		{	
			document.getElementById(errorfieldid).style.display='none';
			return parseInt(sValue);
		}
		else
		{
			if(sValue=='')
			{
				return 0;
				document.getElementById(errorfieldid).style.display='none';
			}
			else
			{
			document.getElementById(errorfieldid).style.display='block';
			return 0;
			}
		}
	}
	else
	{
		document.getElementById(errorfieldid).style.display='block';
		return 0;
	}
}