﻿var SrgGlobal =
{
	/*********************************
	 * Get X-position of any object. *
	 * Can be used with a root-id.   *
	 *********************************/
	GetObjectX: function(oGetX, sRootId)
	{
		var iX = 0;
		var obj = oGetX;
		//--- Loop to top or defined root ---
		while(obj.offsetParent!=null && obj.offsetParent.id!=sRootId)
		{
			//--- Add ---
			iX += obj.offsetLeft;
			//--- Level up ---
			obj = obj.offsetParent
		}
		//--- Add last ---
		iX += obj.offsetLeft;
		return iX;
	},

	/*********************************
	 * Get Y-position of any object. *
	 * Can be used with a root-id.   *
	 *********************************/
	GetObjectY: function(oGetY, sRootId)
	{
		var iY = 0;
		var obj = oGetY;
		//--- Loop to top or defined root ---
		while(obj.offsetParent!=null && obj.offsetParent.id!=sRootId)
		{
			//--- Add ---
			iY += obj.offsetTop;
			//--- Level up ---
			obj = obj.offsetParent
		}
		//--- Add last ---
		iY += obj.offsetTop;
		return iY;
	},
	
	/*********************************************
	 * Set the opacity of an object, in percent! *
	 *********************************************/
	SetOpacity: function(oSet, iOpacity)
	{
		if(typeof(oSet.filters)=='object')
		{
			//---> IE
			if(typeof(oSet.filters.alpha)=='object')
			{
				oSet.filters.alpha.opacity = iOpacity;
			}
			else
			{
				oSet.style.filter = 'Alpha(Opacity=' + iOpacity + ')';
			}
		}
		else
		{
			oSet.style.opacity = iOpacity/100;
		}
	},

	/**********************************************************************
	 * Used for .Net unicode-style escaping.                              *
	 * Developed by SelfHTML, added by vinz:                              *
	 * http://aktuell.de.selfhtml.org/artikel/javascript/utf8b64/utf8.htm *
	 **********************************************************************/
	EncodeUTF8: function(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;
	},
	
	/*********************************************
	 * Display skiplink info for the passed link *
	 *********************************************/
	ShowSkipLinkInfo: function(skipLink)
	{
		var oDivSkipLinkInfo = document.getElementById('skipLinkInfo');
		if(typeof(oDivSkipLinkInfo)=='object')
		{
			oDivSkipLinkInfo.innerHTML = skipLink.innerHTML + " (Alt+" + skipLink.accessKey + ")";
			oDivSkipLinkInfo.style.display = 'block';
		}
	},
	
	/**********************
	 * Hide skiplink info *
	 **********************/
	HideSkipLinkInfo: function()
	{
		var oDivSkipLinkInfo = document.getElementById('skipLinkInfo');
		if(typeof(oDivSkipLinkInfo)=='object')
		{
			oDivSkipLinkInfo.style.display = 'none';
		}
	},
	
	/******************************************************************************************
	 * Open a link in a new window. Used as XHTML compatible replacement for target="_blank". *
	 ******************************************************************************************/
	OpenInNewWindow: function(oAnchor, oEvent)
	{
		var bOpen = false;
		//--- Check if event was passed (from onkeypress) ---
		if(typeof(oEvent)=='object')
		{
			var iKeyCode = -1;
			if(window.event) // IE
			{
				iKeyCode = oEvent.keyCode;
			}
			else if(oEvent.which) // Netscape/Firefox/Opera
			{
				iKeyCode = oEvent.which;
			}
			//--- Show window only if enter was pressed... ---
			if(iKeyCode==13)
			{
				bOpen = true;
			}
		}
		else
		{
			//--- Onclick always shows the popup ---
			bOpen = true;
		}
		//--- Show popup if ok ---
		if(bOpen)
		{
			window.open(oAnchor);
		}
		//--- Return false if popup was opened to avoid opening the link twice... ---
		return !bOpen;
	},
	
	/************************************************************************
	 * Used by text-boxes containing their label as value. Called on focus. *
	 ************************************************************************/
	EndoLabelFocus: function(inputField, endoLabelValue)
	{
		//--- Clear the field if it contains the label ---
		if(inputField.value.toLowerCase()==endoLabelValue.toLowerCase())
		{
			inputField.value = '';
		}
	},
	
	/***********************************************************************
	 * Used by text-boxes containing their label as value. Called on blur. *
	 ***********************************************************************/
	EndoLabelBlur: function(inputField, endoLabelValue)
	{
		//--- Put the label back if nothing was entered... ---
		if(inputField.value=='')
		{
			inputField.value = endoLabelValue;
		}
	}
}