// *******************************************************************************************************************************************
//  global vars
// *******************************************************************************************************************************************

	var arrMenuMainItems = Array();
	// http request object 
	var oHttpRequest = null;
	
	/**
	 * Input element used for debug purposes
	 * @type {HTMLInputElement}
	 */
	var oDebugField;
	/**
	 * Anchor element used for debug purposes
	 * @type {HTMLAnchorElement}
	 */
	var oDebugGoToLink;
	
// *******************************************************************************************************************************************
//  Show hide global functions
// *******************************************************************************************************************************************

	// Block-Elements
	function HideBlockElement(pId) {
		
		try{
			var _oElement = document.getElementById(pId);
		   	_oElement.style.display = 'none'; 
		} catch(e){alert(e);}
	}
	
	function ShowBlockElement(pId) {
		
		try{
			 var _oElement = document.getElementById(pId);
		   	_oElement.style.display = 'block';  
		} catch(e){alert(e + ' -- ' + pId);}
	}

	function ShowTableElement(pId) {
		try{
			 var _oElement = document.getElementById(pId);
		   	_oElement.style.display = 'table';  
		} catch(e){alert(e + ' -- ' + pId);}
	}
	
	function IsBlockElementHidden (pId){
		var _oElement = document.getElementById(pId);
		if(_oElement.style.display == 'none'){
			return true;
		} else {
			return false;
		}
	}
	
	function IsBlockElementVisible (pId){
		if(IsBlockElementHidden(pId)){
			return false;
		} else {
			return true;
		}
	}
	
	function ShowHideBlockElement(pId){
		if(IsBlockElementVisible(pId)){
			HideBlockElement(pId);
		} else {
			ShowBlockElement(pId);
		}
	}

	
	// Inline-Elements
	function HideInlineElement(pId) {
		
		try{
			var _oElement = document.getElementById(pId);
		   	_oElement.style.visibility = 'hidden'; 
		} catch(e){alert(e);}
	}
	
	function ShowInlineElement(pId) {
		
		try{
			 var _oElement = document.getElementById(pId);
		   	_oElement.style.visibility = "visible";  
		} catch(e){alert(e);}
	}

	function ShowHideInlineElement (pId) {
		
		if(IsInlineElementVisible(pId)){
			HideInlineElement(pId);
		} else {
			ShowInlineElement(pId);
		}
	}
	
	function IsInlineElementHidden (pId){
		var _oElement = document.getElementById(pId);
		if(_oElement.style.visibility == 'hidden'){
			return true;
		} else {
			return false;
		}
	}
	
	function IsInlineElementVisible(pId) {
		if(IsInlineElementHidden(pId)){
			return false;
		} else {
			return true;
		}
	}
	
	function ResizeMainFrame() {
		try {
			var elm = document.getElementById('main');
			elm.style.height = 'auto';
			var x = elm.offsetHeight;
			
			if (x < 400) {
				x = 400;
			} 
			elm.style.height = x + "px";
		} catch(e) { }
		try {
			var tmpx = x - 240;
			document.getElementById('main_fotogalerie').style.height = tmpx + "px";
		} catch(e) { }
		try {
			var tmpfx = tmpx-142;
			document.getElementById('fotogalerie').style.top = tmpfx + "px";
		} catch(e) { }

	}

	function initScrollLayer() {
  		// arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  		// if horizontal scrolling, id of element containing scrolling content (table?)
  		var wndo = new dw_scrollObj('wn', 'lyr1', 't1');
  
  		// pass id('s) of scroll area(s) if inside table(s)
 		dw_scrollObj.GeckoTableBugFix('wn'); 
	}
	

	
	
	//------------------------------------------------------------------------
	//------------------------------------------------------------------------
	
	// The following functions are deprecated. Replaced by HideBlockElement, ShowInlineElement,.... 
	
	
	// Hides an div element by giving the div id as parameter
	function HideDiv(pDiv) {
		
		try{
			var _divTag = document.getElementById(pDiv);
		   	_divTag.style.display = 'none'; 
		} catch(e){alert(e);}
	}
	
	
	// Displays an div element by giving the div id as parameter
	function ShowDiv(pDivId) {
		
		try{
			 var _divTag = document.getElementById(pDivId);
		   	_divTag.style.display = 'block';  
		} catch(e){alert(e + ' -- ' + pDivId);}
	}

	function IsDivHidden (pDivId){
		var _divTag = document.getElementById(pDivId);
		if(_divTag.style.display == 'none'){
			return true;
		} else {
			return false;
		}
	}
	
	function IsDivVisible (pDivId){
		if(IsDivHidden(pDivId)){
			return false;
		} else {
			return true;
		}
	}
	
	function ShowHideDiv(pDivId){
		if(IsDivVisible(pDivId)){
			HideDiv(pDivId);
		} else {
			ShowDiv(pDivId);
		}
	}
	
	
	//------------------------------------------------------------------------
	//------------------------------------------------------------------------
	
	
	// The following functions are deprecated. Replaced by HideElement, ShowElement,.... 
	 
	function HideSpan(pSpanId) {
		
		try{
			var _spanTag = document.getElementById(pSpanId);
		   	_spanTag.style.visibility = 'hidden'; 
		} catch(e){alert(e);}
	}
	
	
	// Displays an div element by giving the div id as parameter
	function ShowSpan(pSpanId) {
		
		try{
			 var _spanTag = document.getElementById(pSpanId);
		   	_spanTag.style.visibility = "visible";  
		} catch(e){alert(e);}
	}

	
	function ShowHideSpan (pSpanId) {
		if(IsSpanVisible(pSpanId)){
			HideSpan(pSpanId);
		} else {
			ShowSpan(pSpanId);
		}
	}
	
	function IsSpanHidden (pSpanId){
		var _spanTag = document.getElementById(pSpanId);
		if(_spanTag.style.visibility == 'hidden'){
			return true;
		} else {
			return false;
		}
	}
	
	function IsSpanVisible(pSpanId) {
		if(IsSpanHidden(pSpanId)){
			return false;
		} else {
			return true;
		}
	}

	
// *******************************************************************************************************************************************
//  Show hide special functions
// *******************************************************************************************************************************************
	function ShowHideSidebar(pDiv, pTd, pClassName){
		
		var _tdTag = document.getElementById(pTd);
		if(IsDivVisible(pDiv)){
			HideDiv(pDiv);
			_tdTag.className = pClassName + " collapsed";
		} else {
			ShowDiv(pDiv);
			_tdTag.className = pClassName + " exanded";
		}
	}
	
// *******************************************************************************************************************************************
//  Misc
// *******************************************************************************************************************************************

	function DoNothing () {}
	
	function GoTo (pUrl) {
		window.location = pUrl;
	}
	
	function MM_openBrWindow(theURL,winName,features) { //v2.0
  		window.open(theURL,winName,features);
	}
	
	
	// A function that returns a substring between two substrings
	function GiveMeTextBetween(pString, pStartTag, pEndTag) {

		var _iStartIndex;
		var _iEndIndex;
		_iStartIndex = pString.indexOf(pStartTag);         // Find the index of the beginning tag
		if (_iStartIndex == -1) return "";              // If we don't find anything, return an empty String
		_iStartIndex += pStartTag.length;              // Move to the end of the beginning tag
		_iEndIndex = pString.indexOf(pEndTag, _iStartIndex); // Find the index of the end tag
		if (_iEndIndex == -1) return "";                // If we don't find the end tag, return a empty String
		return pString.substring(_iStartIndex,_iEndIndex);      // Return the text in between
	}
	
	/** 
	 * 
	 * first argument has to be the id of the html container tag of the template that schould be formated
	 * second argument has to be an 2 dimension array that has to be formated as follows
	 * Array ( Array ('tag', 'replacement_value'),  Array ('tag', 'replacement_value'))
	 *
	 **/
	function StringReplace (pString, pArrayTagValueCouples) {
	
		for (var i = 0; i < pArrayTagValueCouples.length; i++) {
			var _regExp = RegExp(pArrayTagValueCouples[i][0], 'g');
			pString = pString.replace(_regExp, pArrayTagValueCouples[i][1]);
		}
		return pString;
	}
	
	function CheckDate(pDate) {
	     //(Schritt 1) Fehlerbehandlung
		 if (!pDate) return false;
		 pDate=pDate.toString();
		
		 //(Schritt 2) Aufspaltung des Datums
		 var sDelimiter = "";
		 if (pDate.search(/\./) != -1){
		 	sDelimiter = ".";
		 }
		 if (pDate.search(/\-/) != -1){
		 	sDelimiter = "-";
		 }
		 if (pDate.search(/\//) != -1){
		 	sDelimiter = "/";
		 }
		 pDate=pDate.split(sDelimiter);
		 if (pDate.length!=3) return false;
		
		 //(Schritt 3) Entfernung der fuehrenden Nullen und Anpassung des Monats
		 pDate[0]=parseInt(pDate[0],10);
		 pDate[1]=parseInt(pDate[1],10)-1;
		
		 //(Schritt 4) Behandlung Jahr nur zweistellig
		 if (pDate[2].length==2) pDate[2]="20"+pDate[2];
		
		 //(Schritt 5) Erzeugung eines neuen Dateobjektes
		 var oTmpDate=new Date(pDate[2],pDate[1],pDate[0]);
		
		 //(Schritt 6) Vergleich, ob das eingegebene Datum gleich dem JS-Datum ist
		 if (oTmpDate.getDate()==pDate[0] && oTmpDate.getMonth()==pDate[1] && oTmpDate.getFullYear()==pDate[2])
		     return true; else return false;
		
	}
/*
	function SetLayoutStyle(pLinkID) {
		var _arrSiteLinks = Array(  'HomeLink',
									'ProductsLink',
									'KnowHowLink',
									'B2BLink',
									'ImpressumLink',
									'SitemapLink',
									'ContactLink');
		var _oField = '';
		for (var i = 0; i < _arrSiteLinks.length; i++)
	  	{
			if (pLinkID == _arrSiteLinks[i])
			{
				//this is the selected link
				//set the style class to the div
				_oField = document.getElementById('div' + _arrSiteLinks[i]);
				_oField.className = _oField.className.replace('floatleft bgbuttonnotactive', 'floatleft bgbuttonactive');
				
				//set the style class to the a href text
				_oField = document.getElementById('ah' + _arrSiteLinks[i]);
				_oField.className = _oField.className.replace('a_navbartop_notactive', 'a_navbartop_active');
				
			} else {
				//set the style class to the div
				_oField = document.getElementById('div' + _arrSiteLinks[i]);
				_oField.className = _oField.className.replace('floatleft bgbuttonactive', 'floatleft bgbuttonnotactive');
				
				//set the style class to the a href text
				_oField = document.getElementById('ah' + _arrSiteLinks[i]);
				_oField.className = _oField.className.replace('a_navbartop_active', 'a_navbartop_notactive');
			}
		}
	}
*/
	
	
// *******************************************************************************************************************************************
//  Http request object 
// *******************************************************************************************************************************************

	// This function cretaes the XML Http Request according to the used browser
	function CreateXMLHttpRequest() {
		
		oHttpRequest = null;
		
		try{
			// Try to create request object. XMLHttpRequest is the request object used by 
			// Mozilla, Safari, Firefox, Opera and most non microsoft browsers
			oHttpRequest = new XMLHttpRequest();
			if (oHttpRequest.overrideMimeType) {
				oHttpRequest.overrideMimeType('text/xml');
			}
		} catch (e) {
			
			try {
				// Try to create request object supported by most microsoft browsers
				oHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				
				try {
					// However if the previous microsoft request object creation failed try this one
					oHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					oHttpRequest = null;
				}
			}
		}
		
		if (oHttpRequest == null) {
			alert('The XMLHTTP object can not be created !');
			return false;
		} else {
			return true;
		}
	}
	
	// This function creates an XML Http Request according to the used browser
	// and throws it
	function GetXMLHttpRequestObject() {
		
		var _oHttpRequest = null;
		
		try{
			// Try to create request object. XMLHttpRequest is the request object used by 
			// Mozilla, Safari, Firefox, Opera and most non microsoft browsers
			_oHttpRequest = new XMLHttpRequest();
			if (_oHttpRequest.overrideMimeType) {
				_oHttpRequest.overrideMimeType('text/xml');
			}
			
		} catch (e) {
			
			try {
				// Try to create request object supported by most microsoft browsers
				_oHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				
				try {
					// However if the previous microsoft request object creation failed try this one
					_oHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					_oHttpRequest = null;
				}
			}
		}
		
		if (_oHttpRequest == null) {
			alert('The XMLHTTP object can not be created !');
		}
		return _oHttpRequest;
	}
	
// *******************************************************************************************************************************************
//  Image functions
// *******************************************************************************************************************************************


	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
		
	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
// *******************************************************************************************************************************************
// Listbox (<select />) functions 
// *******************************************************************************************************************************************


function AddOneToListbox(pListbox, pValue, pTxt) {	
	var _oItem = null;
	// check whether the user uses IE or Firefox to do the appropriate operations
	if(navigator.appName == 'Netscape') {
		_oItem = document.createElement('option');
    	_oItem.value = pValue;
    	_oItem.text = pTxt;
	} else {
		_oItem = document.createElement('<option value="' + pValue + '"></option>');
        _oItem.innerHTML = pTxt;
	}
	pListbox.appendChild(_oItem);
}

function AddToListbox (pItems, pListbox) {
	for(var i = 0 ; i < pItems.length; i++) {
        AddOneToListbox(pListbox, pItems[i].value, pItems[i].text);
   	}
}

function AddFromToListbox (pScrBox, pTargetBox, pRemoveFromSrc) {
	
	_arrSelectedItems = GetSelectedItemsFromListbox(pScrBox);
	AddToListbox(_arrSelectedItems, pTargetBox);
   	
	// finally delete them from the source listbox if the parameter was set
	if(pRemoveFromSrc){
		RemoveFromListboxByItem(_arrSelectedItems, pScrBox);
	}
}


function GetSelectedItemsFromListbox(pListbox) {
	
	// init requiered variables 
	var _arrSelectedItems = pListbox.options;
	var _arrAddedItems = new Array();
	var _iIndex = 0

	for(var i = 0 ; i < _arrSelectedItems.length; i++) {
    	if(_arrSelectedItems[i].selected == true) {
        	_arrAddedItems[_iIndex] = _arrSelectedItems[i];
        	_iIndex++;
        }
	}
	return _arrAddedItems;
}

function GetSelectedIndexFromListbox(pListbox) {
	
	// init requiered variables 
	var _arrSelectedItems = pListbox.options;
	var _iIndex = 0;
	
	for(var i = 0 ; i < _arrSelectedItems.length; i++) {
    	if(_arrSelectedItems[i].selected == true) {
        	return i;
        }
	}
	return -1;
}

function GetListValuesAsPostParam(pListbox, pSeparator) {

	var _arrItems = pListbox.options;
	var _sPostParam = '';

	for (var i = 0; i < _arrItems.length; i++){
		_sPostParam += _arrItems[i].value + '' + pSeparator;
	}
	_sPostParam = _sPostParam.substr(0, _sPostParam.length -1);
	return _sPostParam;
}

function GetItemTextFromListbox(pListbox, pValue) {
	
	// init requiered variables 
	var _arrItems = pListbox.options;
	var _iIndex = 0

	for(var i = 0 ; i < _arrItems.length; i++) {
    	if(_arrItems[i].value == pValue) {
        	return _arrItems[i].text;
        }
	}
	return null;
}


function RemoveFromListboxByValue (pListbox, pValue) {

	var _arrItems = pListbox.options;
   	for (var i = _arrItems.length -1; i >= 0; i--){
   		if(_arrItems[i].value == pValue){
   			pListbox.removeChild(_arrItems[i]);
   			i=-1;
		}
	}
}

function RemoveFromListboxByItem (pItems, pListbox) {

   	for (var i = pItems.length -1; i >= 0; i--){
   		try{
   			pListbox.removeChild(pItems[i]);
   		}catch(e){alert(e.message);}
	}
}

function RemoveFromListboxByComparaison (pItems, pListbox) {
	
	var _arrItems = pListbox.options;
	var _arrDeleteItemsValues = new Array();
	var _iIndex = 0;
	
	for (var i = 0; i <  pItems.length; i++){
		_arrDeleteItemsValues[_iIndex] = pItems[i].value;
		_iIndex++;
	}
	
	var _arrItemsFound = new Array();
	_iIndex = 0;
	
   	for (var i = 0; i < _arrItems.length; i++){
   		for (var j = 0; j < _arrDeleteItemsValues.length; j++){
   			if(_arrItems[i].value == _arrDeleteItemsValues[j]){
   				_arrItemsFound[_iIndex] = _arrItems[i];
   				_iIndex++;
   			}
   		}
	}
	RemoveFromListboxByItem(_arrItemsFound ,pListbox);
}


function EmptyListbox (pListbox) {

	var _arrItems = pListbox.options;
   	for (var i = _arrItems.length -1; i >= 0; i--){
   		pListbox.removeChild(_arrItems[i]);
	}
}


function ListboxValueExists (pListbox, pValue) {
	
	_arrItems = pListbox.options;
	for (var i = 0; i < _arrItems.length; i++){
		if(_arrItems[i].value == pValue){
			return true;
		}
	}
	return false;
}


function SelectAllItemsInListBox (pListbox) {
	
	_arrItems = pListbox.options;
	for (var i = 0; i < _arrItems.length; i++){
		try{
			_arrItems[i].selected = true;
		} catch(e) {
			alert(e.message);
		}
	}
}

function SelectItemInListBox (pListbox, pValueToSelect) {
	
	_arrItems = pListbox.options;
	for (var i = 0; i < _arrItems.length; i++){
		if(_arrItems[i].value == pValueToSelect){
			try{
				_arrItems[i].selected = true;
			} catch(e) {
				alert(pListbox.id + "-" + _arrItems[i].text);
			}
		}
	}
}

function SelectItemInListBoxByText (pListbox, pTextToSelect) {
	
	_arrItems = pListbox.options;
	for (var i = 0; i < _arrItems.length; i++){
		if(_arrItems[i].text == pTextToSelect){
			try{
				_arrItems[i].selected = true;
			} catch(e) {
				alert(pListbox.id + "-" + _arrItems[i].text);
			}
		}
	}
}

function UnselectItemInListBox (pListbox, pValueToDeselect) {
	
	_arrItems = pListbox.options;
	for (var i = 0; i < _arrItems.length; i++){
		if(_arrItems[i].value == pValueToSelect){
			_arrItems[i].selected = false;
		}
	}
}

function UpdateListBoxItemText (pListbox, pValue, pText) {
	_arrItems = pListbox.options;
	for (var i = 0; i < _arrItems.length; i++){
		if(_arrItems[i].value == pValue){
			_arrItems[i].text = pText;
		}
	}
}

// *******************************************************************************************************************************************
// Ajax Debug function
// *******************************************************************************************************************************************


function InitAjaxDebugDataElements() {
	oDebugField = document.getElementById('fAjaxDebugField');
	oDebugGoToLink = document.getElementById("AjaxDebugGoToLink");
}

function SetAjaxDebugData (pUrl){
	/*
	var _sParams = '';
	var _arrSplitItems_1 = pUrl.split('?');
	var _arrSplitItems_2 = _arrSplitItems_1[1].split('&');
	
	_sParams += _arrSplitItems_1[0] + '&#13;&#10;';
	for (var j = 0; j < _arrSplitItems_2.length; j++){
		_sParams += _arrSplitItems_2[j] + '&#13;&#10;';
	}
	alert(_sParams);*/
	try{
		oDebugField.value = pUrl;
		oDebugGoToLink.href = pUrl;	
	} catch (e){e.message}
}


// *******************************************************************************************************************************************
// Newsletter
// *******************************************************************************************************************************************

function NewsletterSubscription(pAction){
	document.getElementById('hfNewsletterSubscriptionAction').value = pAction;
	document.getElementById('frmNewsletterSubscription').submit();
}