// *******************************************************************************************************************************************
//  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);
	}
	
	function HtmlEntitiesEncode (pString) {
		
	  var _arrChars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
		                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
		                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
		                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
		                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
		                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','"','ß','<',
		                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
		                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
		                         '·','¸','¹','º','»','¼','½','¾');

	  var _arrEntities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
		                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
		                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
		                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
		                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
		                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
		                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
		                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
		                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','quot','szlig',
		                            'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
		                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
		                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
		                            'ordm','raquo','frac14','frac12','frac34');

	  var _sNewString = pString;
	  
	  for (var i = 0; i < _arrChars.length; i++)
	  {
	    _regExp = new RegExp();
	    _regExp.compile(_arrChars[i],'g');
	    _sNewString = _sNewString.replace (_regExp, '&' + _arrEntities[i] + ';');
	    
	  }
	  return _sNewString;
		
	}
	
	function HtmlEntitiesDecode (pString) {
		
	  var _arrChars = new Array ('&','à','á','â','ã','ä','å','æ','ç','è','é',
		                         'ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô',
		                         'õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ','À',
		                         'Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë',
		                         'Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö',
		                         'Ø','Ù','Ú','Û','Ü','Ý','Þ','€','\"','"','ß','<',
		                         '>','¢','£','¤','¥','¦','§','¨','©','ª','«',
		                         '¬','­','®','¯','°','±','²','³','´','µ','¶',
		                         '·','¸','¹','º','»','¼','½','¾');

	  var _arrEntities = new Array ('amp','agrave','aacute','acirc','atilde','auml','aring',
		                            'aelig','ccedil','egrave','eacute','ecirc','euml','igrave',
		                            'iacute','icirc','iuml','eth','ntilde','ograve','oacute',
		                            'ocirc','otilde','ouml','oslash','ugrave','uacute','ucirc',
		                            'uuml','yacute','thorn','yuml','Agrave','Aacute','Acirc',
		                            'Atilde','Auml','Aring','AElig','Ccedil','Egrave','Eacute',
		                            'Ecirc','Euml','Igrave','Iacute','Icirc','Iuml','ETH','Ntilde',
		                            'Ograve','Oacute','Ocirc','Otilde','Ouml','Oslash','Ugrave',
		                            'Uacute','Ucirc','Uuml','Yacute','THORN','euro','quot','quot','szlig',
		                            'lt','gt','cent','pound','curren','yen','brvbar','sect','uml',
		                            'copy','ordf','laquo','not','shy','reg','macr','deg','plusmn',
		                            'sup2','sup3','acute','micro','para','middot','cedil','sup1',
		                            'ordm','raquo','frac14','frac12','frac34');

	  var _sNewString = pString;
	  
	  for (var i = 0; i < _arrEntities.length; i++)
	  {
	    _regExp = new RegExp();
	    _regExp.compile('&' + _arrEntities[i] + ';','g');
	    _sNewString = _sNewString.replace (_regExp, _arrChars[i]);
	  }
	  return _sNewString;	
	}
	
	
	// 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 to calculate the difference in days between two days
	 * 
	 * pStartDate = String (Acceptet Delimiters [./-])
	 * pEndDate   = String (Acceptet Delimiters [./-])
	 * 
	 * returns a Number
	 */
	function DateDiff(pStartDate, pEndDate){
		//Error Handling
		if (!pStartDate || !pEndDate) return 0;
		
		pStartDate = pStartDate.toString();
		pEndDate   = pEndDate.toString();
		
		//(Step 2) Split the dates
		pStartDate = SplitDate(pStartDate);
		pEndDate   = SplitDate(pEndDate);
		 
		
		if ((pStartDate.length!=3) || (pEndDate.length!=3)) return 0;
		
		//(Schritt 3) Entfernung der fuehrenden Nullen und Anpassung des Monats
		pStartDate[0]=parseInt(pStartDate[0],10);
		pStartDate[1]=parseInt(pStartDate[1],10)-1;
		 
		pEndDate[0]=parseInt(pEndDate[0],10);
		pEndDate[1]=parseInt(pEndDate[1],10)-1;
		
		//(Schritt 4) Behandlung Jahr nur zweistellig
		if (pStartDate[2].length==2) pStartDate[2]="20"+pStartDate[2];
		if (pEndDate[2].length==2) pEndDate[2]="20"+pEndDate[2];
		
		//(Schritt 5) Erzeugung eines neuen Dateobjektes
		var oStartDate=new Date(pStartDate[2],pStartDate[1],pStartDate[0]);
		var oEndDate=new Date(pEndDate[2],pEndDate[1],pEndDate[0]);
		 
		var _idiff = oEndDate.getTime() - oStartDate.getTime();
		return Math.floor(_idiff / (1000 * 60 * 60 * 24));
		
	}
	/*
	 * Function to split a date
	 * 
	 * pDate = String (Acceptet Delimiters [./-])
	 * 
	 * returns array(day, month, year)
	 * 
	 */
	function SplitDate(pDate){
		if (!pDate) return new Array();
		
		 //Split the date
		 var sDelimiter = "";
		 if (pDate.search(/\./) != -1){
		 	sDelimiter = ".";
		 }
		 if (pDate.search(/\-/) != -1){
		 	sDelimiter = "-";
		 }
		 if (pDate.search(/\//) != -1){
		 	sDelimiter = "/";
		 }
		 
		 return pDate.split(sDelimiter);
	}

// *******************************************************************************************************************************************
//  Main menu functions
// *******************************************************************************************************************************************

	function ShowHideMainMenuItem (pDiv){
		
		if(IsDivHidden) {
			var _iItemsCount = arrMenuMainItems.length;
			// Let's collapse first all the menu main items
			for (var _i = 0; _i < _iItemsCount; _i++){
				HideDiv(arrMenuMainItems[_i]);
			}
			ShowDiv(pDiv);
		}
	}
	
	
// *******************************************************************************************************************************************
//  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;
	}
	
	
// *******************************************************************************************************************************************
// Checkbox
// *******************************************************************************************************************************************
/*
	function MakeCheckboxReadOnly (pCheckBoxId) {
		var _oCheckBox = document.getElementById(pCheckBoxId);
		if(_oCheckBox.checked == true){
			_oCheckBox.checked = true;
		} else {
			_oCheckBox.checked = false;
		}
	}
	*/
// *******************************************************************************************************************************************
// 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 SelectListBoxItem (pListboxID, pValueToSelect) {
	var _oSelectBox = document.getElementById(pListboxID);
	_arrItems = _oSelectBox.options;
	for (var i = 0; i < _arrItems.length; i++){
		if(_arrItems[i].value == pValueToSelect){
			try{
				_arrItems[i].selected = true;
			} catch(e) {
				alert(_oSelectBox.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}
}

// *******************************************************************************************************************************************
// Travel Search function
// *******************************************************************************************************************************************

function TravelSearch(pRootUrl){
	var _sType = document.getElementById('TravelSearchType').value;
	var _sDestination = document.getElementById('TravelSearchDestination').value;
	var _sThemeType = '';
	//document.getElementById('frmTravelSearch').submit();
	switch (_sType) {
		case "allseasons":	
							_sThemeType = "default";
							break;
		case "summer":		_sThemeType = "default";
							break;
		case "winter":		_sThemeType = "winter";
							break;
		default:			_sThemeType = "default";
							break;
	}
	window.location = pRootUrl + 'index.php?module=travel&page=list&Type=' + _sType + '&Destination=' + _sDestination + '&Action=1&theme=' + _sThemeType;
}

var _sSelectedCountry = '';
var _oHttpRequestCountries = '';
function GetCountries(pRootUrl, pSeason, pSelected){
	if (pSeason == ''){
		pSeason = 'allseasons';
	}
	_sSelectedCountry = pSelected;
	//first clear the list box
	_oSelectBox = document.getElementById('TravelSearchDestination');
	EmptyListbox(_oSelectBox);
	//add the default item
	var _oOption = document.createElement("OPTION");
	_oOption.text = "**Reiseziel?**";
	_oOption.value = "Destination";
	_oSelectBox.options.add(_oOption);
	
	_oHttpRequestCountries = GetXMLHttpRequestObject();
	if(_oHttpRequestCountries){
    	RequestCountries(pRootUrl, pSeason);	
    }	
}

function RequestCountries(pRootUrl, pSeason){
	// build Url
	var _sUrl = pRootUrl + 'index.php?module=travel&page=ajax';
	// build param string to send by Post
	var _sPost = '&action='		+ 'GetCountries';
	_sPost += '&Season=' 		+ pSeason;
	
	// Execute the request
	_oHttpRequestCountries.onreadystatechange = SetCountries;
	_oHttpRequestCountries.open('post', _sUrl, true);
	_oHttpRequestCountries.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	_oHttpRequestCountries.setRequestHeader("Content-length", _sPost.length);
	_oHttpRequestCountries.send(_sPost);	
}

function SetCountries(){
	if (_oHttpRequestCountries.readyState == 4) {
		if (_oHttpRequestCountries.status == 200) {
			
			// Put response into xmlobject
			var _xmldoc = _oHttpRequestCountries.responseXML;
			var _item_value = "";
			
			//check the response if there we got any results
			var _nbr_countries = 0;
			// Get the number of countries
			_nbr_countries = _xmldoc.documentElement.getElementsByTagName('nbr_countries').item(0).firstChild.nodeValue;
		
			if (_nbr_countries > 0){
				
				// Loop through the returned countries and list them in the combobox		
				var _data = _xmldoc.documentElement.getElementsByTagName('country');
				var _oSelectBox = "";
				_oSelectBox = document.getElementById('TravelSearchDestination');
				
				for (i=0; i < _data.length; i++){
					var _countryname = "";
					var _countryid = "";
					var _oOption = document.createElement("OPTION");
					
					try{
						_countryname = _data[i].getElementsByTagName('countryname').item(0).firstChild.nodeValue;
					}catch(e){
						_countryname = "";
					}
					try{
						_countryid = _data[i].getElementsByTagName('countryid').item(0).firstChild.nodeValue;
					}catch(e){
						_countryid = "";
					}
					_oOption.text = _countryname;
					_oOption.value = _countryid;
					if ((_sSelectedCountry != '') && (_sSelectedCountry == _countryid)){
						_oOption.selected = true;
					}
					_oSelectBox.options.add(_oOption);
				}
			}
		}else{
			alert('Request error: Status no given');
		}
	}
}


