// *******************************************************************************************************************************************
//  global functions
// *******************************************************************************************************************************************

function escapeString(string){
	var _escapedString = escape(string);
	// !!! take care javascript escape function has problems with the + symbol an it is replace by an space on the server side
	_escapedString = _escapedString.replace(/\+/g, '%2B');
	return _escapedString;
};

function initTips(className){

	var _className = (typeof(className) == 'string')? '.'+className : '.Tips1';

	var _tips = $$(_className).each(function(el){
		var tipContent	= el.title;
		var tipBulle	= tipContent.split('::');
		var tipTitle	= tipBulle[0];
		var tipText		= tipBulle[1];
		el.store('tip:title', tipTitle);
		el.store('tip:text', tipText);
	});
	
	var _tips = new Tips($$(_className), {
		maxTitleChars : 75,
		onShow: function(tip) {
			tip.fade('in');
		},
		onHide: function(tip) {
			tip.fade('out');
		}
	});
};

function refreshTips(className){
	initTips(className);
};

function clearValidationErrors(){

	$$('.validationErrorTip').each(function(el){
		el.hide();
	});
	$$('.validationError').each(function(el){
		el.removeClass('validationError');
	});
};

function getErrorMessage(array_errors, line_break) {
	
	var length = array_errors.length;
	var message = '';
	var line_break = (typeof(line_break) == 'string')? line_break:'\n';
	
	if(length > 0){
				
		for (var i = 0; i < length; i++) {
			
			if(array_errors[i].error.type != 'VALIDATION_ERRORS'){
				try{
					 message += (array_errors[i].error.message != '') ? array_errors[i].error.message+line_break : '';
				} catch(e){}
			}
		}
	}
	return message;
};

function displayFormValidationErrors(array_errors) {

	var length = array_errors.length;

	if(length > 0){
				
		for (var i = 0; i < length; i++) {
	
			if(array_errors[i].error.type == 'VALIDATION_ERRORS'){
				try{
					var field_name = array_errors[i].error.property_name;
				}catch(e){var field_name = '';}
				
				try{
					var short_note =  array_errors[i].error.short_note;
				}catch(e){var short_note = '';}
				
				try{
					var message = array_errors[i].error.message;
				}catch(e){var message = '';}
	
				try{
					$(field_name).addClass('validationError');
					errTip = $('validationErrorTip' + field_name);
					errTip.title = short_note+'::'+message;
					errTip.show();
				} catch (e){}
			}
		}
		refreshTips('validationErrorTip');
	}
};

function displayValidationErrors(pArrayXMLError) {

	var _iLength = pArrayXMLError.length;
	
	if(_iLength > 0){
				
		for (var i = 0; i < _iLength; i++) {
			
			try{
				var _fieldName = pArrayXMLError[i].getElementsByTagName('property_name').item(0).firstChild.nodeValue;
			}catch(e){var _fieldName = '';}
			
			try{
				var _fieldValue = pArrayXMLError[i].getElementsByTagName('property_value').item(0).firstChild.nodeValue;
			}catch(e){var _fieldValue = '';}
			
			try{
				var _sShortNote = pArrayXMLError[i].getElementsByTagName('short_note').item(0).firstChild.nodeValue;
			}catch(e){var _sShortNote = '';}
			
			try{
				var _sMessage = pArrayXMLError[i].getElementsByTagName('message').item(0).firstChild.nodeValue;
			}catch(e){var _sMessage = '';}
			
			_oField = $(_fieldName);

			try{
				_oField.addClass('validationError');
				_oTips = $('validationErrorTip' + _fieldName);
				_oTips.title = _sShortNote+'::'+_sMessage;
				_oTips.show();
			} catch (e){}
		}
		refreshTips('validationErrorTip');
	}
};

// *******************************************************************************************************************************************
//  global vars
// *******************************************************************************************************************************************
	/**
	 * Http request object 
	 * @type {XMLHttpRequest or ActiveXObject}
	 */
	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 HideDiv(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 ShowDiv(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;
		}
	}
	
	//------------------------------------------------------------------------
	//------------------------------------------------------------------------
	
	
// *******************************************************************************************************************************************
//  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 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);
	}
	
	
// *******************************************************************************************************************************************
//  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}
}

// *******************************************************************************************************************************************
// Travel Search function
// *******************************************************************************************************************************************

function TravelSearch(pRootUrl){
	var _sType = document.getElementById('TravelSearchType').value;
	var _sDestination = document.getElementById('TravelSearchDestination').value;
	//document.getElementById('frmTravelSearch').submit();
	
	window.location = pRootUrl + 'index.php?module=travel&page=list&Type=' + _sType + '&Destination=' + _sDestination + '&Action=1';
}



// *******************************************************************************************************************************************
// Datepicker
// *******************************************************************************************************************************************

function makeTwoChars(inp) {
        return String(inp).length < 2 ? "0" + inp : inp;
}

function initialiseInputs() {
        // Clear any old values from the inputs (that might be cached by the browser after a page reload)
       /* document.getElementById("sd").value = "";
        document.getElementById("ed").value = "";

        // Add the onchange event handler to the start date input
        document.getElementById("sd").onchange = setReservationDates;
        
        setLowRangeToBeSixWeeksAfterToday();*/
}
function setLowRangeToBeSixWeeksAfterToday() {
        if(!("sd" in datePickerController.datePickers)) {
                setTimeout("setLowRangeToBeSixWeeksAfterToday()", 50);
                return;
        }
        
        var dt = new Date();
        dt.setDate(dt.getDate() +  (6 * 7));
        
        var stringDt = dt.getFullYear() + String(makeTwoChars(dt.getMonth())) + makeTwoChars(dt.getDate());

        datePickerController.datePickers["sd"].setRangeLow(stringDt);
        datePickerController.datePickers["ed"].setRangeLow(stringDt);
}

function setReservationDates(e) {
        // Check the associated datePicker object is available (be safe)
        if(!("sd" in datePickerController.datePickers)) {
                return;
        }
        
        // Check the value of the input is a date of the correct format
        var dt = datePickerController.dateFormat(this.value, datePickerController.datePickers["sd"].format.charAt(0) == "m");
        
        // If the input's value cannot be parsed as a valid date then return
        if(dt == 0) return;

        // Grab the value set within the endDate input and parse it using the dateFormat method
        // N.B: The second parameter to the dateFormat function, if TRUE, tells the function to favour the m-d-y date format
        var edv = datePickerController.dateFormat(document.getElementById("ed").value, datePickerController.datePickers["ed"].format.charAt(0) == "m");

        // Grab the end date datePicker Objects
        var ed = datePickerController.datePickers["ed"];

        ed.setRangeLow( dt );
        
        // If theres a value already present within the end date input and it's smaller than the start date
        // then clear the end date value
        if(edv < dt) {
                document.getElementById("ed").value = "";
        }
}

//datePickerController.addEvent(window, 'load', initialiseInputs);

//*******************************************************************************************************************************************
//functions used all over the site 
//*******************************************************************************************************************************************
/** 
* Passwort Anfrage
*
*/
function requestPwd(url, okMsgContainer){

	try{$(okMsgContainer).hide();} catch(e){}
	clearValidationErrors();

	var request = new Request.JSON({  
	 	
		method: 'post',
		url: url,
		data: 'Email=' + $('Email').value,
		async: false,
		
		onSuccess: function(responseJSON, responseText){
			var resultObj = responseJSON;
			if(resultObj){
				if(resultObj.errors){
					displayFormValidationErrors(resultObj.errors);
					errMsg = getErrorMessage(resultObj.errors);
					if(errMsg != '') alert(errMsg);
				} else if(resultObj.result_code == '1') {
					try{$(okMsgContainer).show();} catch(e){}
				}
			} else {
				alert('Error occured while receiving data from server.');
			}
		},
		onFailure: function(){
			alert('Error occured while receiving data from server.');
		}
	}).send();
};

function submitLoginForm(){
	
	if($('Password').value.length > 0){
		$('isRegisteredYes').checked = true;
	}
};

//*******************************************************************************************************************************************
//initial js code to execute
//*******************************************************************************************************************************************

window.addEvent('domready', function() {

	// init tips
	initTips();
	
	// init multiBox
	var initMultiBox = new multiBox({
		mbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
		container: $(document.body),//where to inject multiBox
		descClassName: 'multiBoxDesc',//the class name of the description divs
		//path: './Files/',//path to mp3 and flv players
		useOverlay: true,//use a semi-transparent background. default: false;
		maxSize: {w:700, h:500},//max dimensions (width,height) - set to null to disable resizing
		addDownload: false,//do you want the files to be downloadable?
		pathToDownloadScript: './Scripts/ForceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)
		addRollover: false,//add rollover fade to each multibox link
		addOverlayIcon: false,//adds overlay icons to images within multibox links
		addChain: false,//cycle through all images fading them out then in
		recalcTop: true,//subtract the height of controls panel from top position
		addTips: false//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
	});
	
});
