//**********************************************************************************************************************
//  Module Global Functions
//**********************************************************************************************************************
	var sRootUrl 	= null;
	var sModule		= null;
	
	
	function Init(pRootUrl, pModule){
		sRootUrl	= pRootUrl;
		sModule		= pModule;
		InitAjaxDebugDataElements();
		ClearCustomerValidationErrors();
	}

// *******************************************************************************************************************************************
// Set Traveltype in Traveldates Template
// *******************************************************************************************************************************************

function SetTravelType(pRootUrl,pAgency){
	var _sType	= document.getElementById('travelTypeSelect').value;
	var _sUrl	= pRootUrl + 'index.php?module=travel&page=traveldates&'+_sType+'&agency='+pAgency;
	window.location = _sUrl; 
}

// *******************************************************************************************************************************************
// Set Booking Button Activ
// *******************************************************************************************************************************************

function SetBookingButton(){
	var dropdownIndex = document.getElementById('travelDateSelect').selectedIndex;
	var dropdownValue = document.getElementById('travelDateSelect')[dropdownIndex].value;
	
	if (dropdownValue == '') {
		document.getElementById('travelDateSelectButton').disabled = true;
		document.getElementById('travelDateSelectButton').readOnly = true;	
	} else {
		document.getElementById('travelDateSelectButton').disabled = false;
		document.getElementById('travelDateSelectButton').readOnly = false;	
	}
}

//************************************************************************************************************************
// Booking Request
//************************************************************************************************************************

		//===========================
		// Page Functions
		//===========================
		function SetAdditionalPerson(pFieldID){		
			var tbody = document.getElementById("tabeladditionalpersons").getElementsByTagName("TBODY")[0];
			var _arrTrs = '';
			var _NbrRows = 0;
			_arrTableRows = tbody.getElementsByTagName("TR");
			_NbrRows = _arrTableRows.length - 1;
			
			
			var _arrMainPricesFields = document.getElementById("MainPricesContainer").getElementsByTagName("INPUT");
			var _NbrPersons = 0;
			var _iTmpNbrPerson = 0;
			for(var i = 0; i < _arrMainPricesFields.length; i++){
				
				if(navigator.appName.indexOf('Microsoft') > -1){
					/* IE */
					var _oNode = _arrMainPricesFields[i].getAttributeNode('onchange');
					var _sFieldOnclickText = _oNode.nodeValue;
				} else {
					/* FF */
					var _sFieldOnclickText = _arrMainPricesFields[i].getAttribute('onchange');
				}
				
				if((_arrMainPricesFields[i].id.search("tbHotelDateRangePrice") > -1) && 
					(_sFieldOnclickText.search("SetAdditionalPerson") > -1)){
					_iTmpNbrPerson = new Number(_arrMainPricesFields[i].value);
					if(isNaN(_iTmpNbrPerson) || _iTmpNbrPerson <= 0){
						_arrMainPricesFields[i].value = 0;
					} else {
						_NbrPersons += _iTmpNbrPerson;
					}
				}
			}
			
			
			if (_NbrRows < (_NbrPersons - 1)) {
				//we have to add one or multiple rows
				for (i=_NbrRows; i < (_NbrPersons - 1); i++) {
					AddRow("tabeladditionalpersons");
				}
			} else if ((_NbrPersons - 1) >= 0) {
				//we have to remove one or multiple rows
				for (i=_NbrRows; i > (_NbrPersons - 1); i--) {
					RemoveRow("tabeladditionalpersons");
				}
			}
			
			if ((_NbrPersons) > 1) {
				ShowDiv("divAdditionalPersons");
			} else {
				HideDiv("divAdditionalPersons");
			}
		}
		
		function AddRow(pTableID){
			var tbody = document.getElementById(pTableID).getElementsByTagName("TBODY")[0];
			var _arrTableRows = '';
			_arrTableRows = tbody.getElementsByTagName("TR");
			//alert(_arrTableRows.length);
			var row = document.createElement("TR");
			
			var tdfirstname = document.createElement("TD");
			tdfirstname.name = "tdfirstname";
			var _oInputFirstName = document.createElement("INPUT");
			_oInputFirstName.className = "forms92percent";
			tdfirstname.appendChild(_oInputFirstName);
			
			var tdlastname = document.createElement("TD");
			tdlastname.name = "tdlastname";
			var _oInputLastName = document.createElement("INPUT");
			_oInputLastName.className = "forms92percent";
			tdlastname.appendChild (_oInputLastName);
			
			var tdbirthday = document.createElement("TD");
			tdbirthday.name = "tdbirthday";
			var _oInputBirthday = document.createElement("INPUT");
			_oInputBirthday.className = "forms92percent";
			tdbirthday.appendChild (_oInputBirthday);
			
			var tdsexe = document.createElement("TD");
			tdsexe.name = "tdsexe";
			var _oSelectBox = document.createElement("SELECT");
			_oSelectBox.className = "forms92percent";
			
			var _OptionChoose = document.createElement("OPTION");
			_OptionChoose.text = "Bitte auswählen";
			_OptionChoose.value = "-1";
			_oSelectBox.options.add(_OptionChoose);
			
			var _OptionMale = document.createElement("OPTION");
			_OptionMale.text = "M";
			_OptionMale.value = "0";
			_oSelectBox.options.add(_OptionMale);
			
			var _OptionFemale = document.createElement("OPTION");
			_OptionFemale.text = "W";
			_OptionFemale.value = "1";
			_oSelectBox.options.add(_OptionFemale);
		
			tdsexe.appendChild (_oSelectBox);
			row.appendChild(tdfirstname);
			row.appendChild(tdlastname);
			row.appendChild(tdbirthday);
			row.appendChild(tdsexe);
			tbody.appendChild(row);
		}
		
		function RemoveRow(pTableID){
			var tbody = document.getElementById(pTableID).getElementsByTagName("TBODY")[0];
			var _arrTableRows = '';
			var _NbrRows = 0;
			_arrTableRows = tbody.getElementsByTagName("TR");
			_NbrRows = _arrTableRows.length;
			tbody.deleteRow(_NbrRows - 1);
		}
		
		function CalculateTotals() {
			
			//
			var _iNbrNights	= 1;
			try{
				_iNbrNights = new Number(document.getElementById('tfNumberNights').value);
			}catch(e){}
			 
			//first get the div with the price spans
			var _divPrices = document.getElementById('divPrices');
			
			//now fill the array with all the spans who contains the price objects
			var _arrPriceSpans 		= _divPrices.getElementsByTagName('span');
			var _arrPriceObjects 	= Array();
			var _dtotalprice 		= 0;
			var _spanAmount 		= 1;
			var _iNbrAmountObjects 	= 0;
			var _bAddSpanAmount 	= true;
			var _iCounter 			= 0;
			var _sAmountKind 		= "";
			var _sMathOperator 		= "";
			var _bMultiplyByNights	= false;

			//start pharsing the array
			for (i = 0; i < _arrPriceSpans.length; i++){
				_iCounter 			= 0;
				_spanAmount 		= 1;
				_bAddSpanAmount		= true;
				_arrPriceObjects 	= new Array();
				_bMultiplyByNights	= false;
		
				for(j=0; j < _arrPriceSpans[i].getElementsByTagName('input').length; j++){
					_arrPriceObjects.push(_arrPriceSpans[i].getElementsByTagName('input')[j]);
				}
				for(j=0; j < _arrPriceSpans[i].getElementsByTagName('select').length; j++){
					_arrPriceObjects.push(_arrPriceSpans[i].getElementsByTagName('select')[j]);
				}
		
				_iNbrAmountObjects = _arrPriceObjects.length;
				//alert("nbr Objects: " + _iNbrAmountObjects);
				while ((_iCounter < _iNbrAmountObjects) && (_bAddSpanAmount)) {
					var _oField = _arrPriceObjects[_iCounter];
					
					if ((_oField.name != "ItemName") && (_oField.name != "AllocationTypeID") && (_oField.name != "TextAddOn")) {				
						if (_oField.name == "AmountKind"){
							_sAmountKind = _oField.value;
						}else if (_oField.name == "MathOperator") {
							_sMathOperator = _oField.value;
						}else if (_oField.name == "MultiplyByNights") {
							_bMultiplyByNights = true;
						}else if (_oField.name == "Amount") {
							_spanAmount = _spanAmount * new Number(_oField.value);
						}else{
							switch (_oField.type) {
								case "checkbox" :	if (!_oField.checked) {
														_bAddSpanAmount = false;
													} else {
														_spanAmount = _spanAmount * new Number(_oField.value);
													}
													break;
													
								default :			_spanAmount = _spanAmount * new Number(_oField.value);
													break;
							}
						}
					}
					_iCounter ++;
				}
				
				//alert( _sAmountKind + " -- " + _sMathOperator);
				if (_bAddSpanAmount) {
					if (_sAmountKind == 0){
						//alert("span amount: " + _spanAmount);
						//AmountKind 0 = Euro
						switch (_sMathOperator){
							case '0':	if (_bMultiplyByNights){
											_dtotalprice += _spanAmount * _iNbrNights;
										} else {
											_dtotalprice += _spanAmount;
										}
										break;
							case '1':	_dtotalprice -= _spanAmount;
										break;
							case '2':
										break;
							case '3':
										break;
						}
						
					}else if (_sAmountKind == 1){
						//AmountKind 1 = Percentage
						//to do
					}
				}
				
			}
			
			var _oTotalPriceSpan = document.getElementById('spTotalPrice');
			_oTotalPriceSpan.innerHTML = _dtotalprice;

			document.getElementById('hfTotalPrice').value = _dtotalprice;
		}
		
		function SetNbrNights(){
			
			var _oField_StartDate	= document.getElementById('tbPreferedStartDate');
			var _oField_EndDate		= document.getElementById('tbPreferedEndDate');
			var _oField_NbrNights	= document.getElementById('tfNumberNights');
			_oField_NbrNights.value = DateDiff(_oField_StartDate.value, _oField_EndDate.value);
			
			CalculateTotals();
		}
		
		function SetSelectBoxAmount(pID){
			//first get the selected value of the selectbox
			var _oSelectBox = document.getElementById('sb' + pID);
			var _sValue = _oSelectBox.value;
			var _iSelectedIndex = _oSelectBox.selectedIndex;
			var _sSelectedText = _oSelectBox.options[_iSelectedIndex].text;

			//now set the value to the hidden amount field
			var _oAmountField = document.getElementById('hfAmount' + pID);
			_oAmountField.value = _sValue;
			var _oAddOnField = document.getElementById('hfTextAddOn' + pID);
			_oAddOnField.value = _sSelectedText;
		}
		
		function SetBookingButtonState(){
			var _ocbTAC	= document.getElementById('cbTAC');
			if (_ocbTAC.checked){
				document.getElementById('btnSubmitBooking').disabled = false;
			} else {
				document.getElementById('btnSubmitBooking').disabled = true;
			}
		}
		
		function GetBookingBranches(pAgency){
			//first clear the list box
			_oSelectBox = document.getElementById('BookingBranch');
			EmptyListbox(_oSelectBox);
			//add the default item
			var _oOption = document.createElement("OPTION");
			_oOption.text = "Bitte Agentur auswählen";
			_oOption.value = "0";
			_oSelectBox.options.add(_oOption);
			
			if (pAgency != 0){
				if(CreateXMLHttpRequest()){
			    	RequestBookingBraches(pAgency);	
			    }	
			}
		}
		
		function RequestBookingBraches(pAgency){
			// build Url
			var _sUrl = sRootUrl + 'index.php?module=' + sModule + '&page=ajax';
			// build param string to send by Post
			var _sPost = '&action='		+ 'GetBraches';
			_sPost += '&Agency=' 		+ pAgency;
			
			SetAjaxDebugData (_sUrl + _sPost);
			
			// Execute the request
			oHttpRequest.onreadystatechange = SetBookingBranches;
			oHttpRequest.open('post', _sUrl, true);
			oHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			oHttpRequest.setRequestHeader("Content-length", _sPost.length);
			oHttpRequest.send(_sPost);	
		}
		
		function SetBookingBranches(){
			if (oHttpRequest.readyState == 4) {
				if (oHttpRequest.status == 200) {
					
					// Put response into xmlobject
					var _xmldoc = oHttpRequest.responseXML;
					var _item_value = "";
					
					//check the response if there we got any results
					var _nbr_branches = 0;
					// Get the number of branches
					_nbr_branches = _xmldoc.documentElement.getElementsByTagName('nbr_branches').item(0).firstChild.nodeValue;
				
					if (_nbr_branches > 0){
						
						// Loop through the returned branches and list them in the combobox		
						var _data = _xmldoc.documentElement.getElementsByTagName('branch');
						var _oSelectBox = "";
						_oSelectBox = document.getElementById('BookingBranch');
						
						if (_nbr_branches == 1){
							EmptyListbox(_oSelectBox);
						}
						
						for (i=0; i < _data.length; i++){
							var _branchname = "";
							var _oOption = document.createElement("OPTION");
							
							try{
								_branchname = _data[i].getElementsByTagName('branchname').item(0).firstChild.nodeValue;
							}catch(e){
								_branchname = "";
							}
							_oOption.text = _branchname;
							_oOption.value = _branchname;
							_oSelectBox.options.add(_oOption);
						}
					} else {
						alert('Es sind keine Reisebüros definiert!')
					}
				}
			}
		}
		
		//===========================
		// Save Booking Functions
		//===========================
		function SaveBooking(){
			
			//hide validation errors
			var _oField = document.getElementById('BookingBranch');
			_oField.className.replace(' validationError', '');
			_oField.className.replace('validationError', '');
			
			//alert('Save Booking');
			if(CreateXMLHttpRequest()){
		    	RequestBookingValidationAndSave();	
		    }
		}
		
		function RequestBookingValidationAndSave(){
			
			// build Url
			var _sUrl = sRootUrl + 'index.php?module=' + sModule + '&page=ajax';
			// build param string to send by Post
			var _sPost = '&action=' + 'SaveBooking';
			
			var _iCustomerID = document.getElementById('hfCustomerID').value;
			
			_sPost += GetCustomerData();
			_sPost += '&CustomerID=' 		+ _iCustomerID;
			_sPost += '&TravelID=' 			+ document.getElementById('hfTravelID').value;
			_sPost += '&TravelSupInfoID='	+ document.getElementById('hfTravelSupInfoID').value;
			_sPost += '&TravelDateRangeID=' + document.getElementById('hfTravelDateRangeID').value;
			_sPost += '&TravelStart=' 		+ escape(document.getElementById('hfTravelStart').value);
			_sPost += '&TravelEnd=' 		+ escape(document.getElementById('hfTravelEnd').value);
			_sPost += '&TotalPrice=' 		+ escape(document.getElementById('hfTotalPrice').value);
			_sPost += '&Comment=' 			+ escape(document.getElementById('taComment').value);
			_sPost += '&BookingAgency='		+ escape(document.getElementById('BookingAgency').value);
			_sPost += '&AgencyBranch='		+ escape(document.getElementById('BookingBranch').value);

			_sPost += GetHotels();
			_sPost += GetPaymentItems();
			_sPost += GetAdditionalPersons();
			
			if (document.getElementById('hfCustomerDateField').value == 1){
				_sPost += '&PreferedStartDate='	+ escape(document.getElementById('tbPreferedStartDate').value);
				_sPost += '&PreferedEndDate='	+ escape(document.getElementById('tbPreferedEndDate').value);
			}

			SetAjaxDebugData (_sUrl + _sPost);
	
			// Execute the request
			oHttpRequest.onreadystatechange = SetBookingValidationErrors;
			oHttpRequest.open('post', _sUrl, true);
			oHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			oHttpRequest.setRequestHeader("Content-length", _sPost.length);
			oHttpRequest.send(_sPost);	
		}
		
		function SetBookingValidationErrors(){
			if (oHttpRequest.readyState == 4) {
				if (oHttpRequest.status == 200) {
					
					// Put response into xmlobject
					var _xmldoc = oHttpRequest.responseXML;
					
					//check the response if there where any errors
					var _nbr_errors = 0;
					// Get the number of errors
					_nbr_errors = _xmldoc.documentElement.getElementsByTagName('nbr_errors').item(0).firstChild.nodeValue;
				
					if (_nbr_errors > 0){
						
						// Loop through the returned validation errors and highlight the errors in the template			
						var _data = _xmldoc.documentElement.getElementsByTagName('error');
						var _oField = "";
					
						if(_data.length > 0){
							
							ClearCustomerValidationErrors();
							ClearBookingValidationErrors();
							ShowBlockElement('divError');
							$('ctErrorNoPaymentItemsMsg').hide();
							clearPriceValidationErrors();
							
							for (var i=0; i < _data.length; i++){
								var _Area = "";
								
								try{
									_Area = _data[i].getElementsByTagName('additional_info').item(0).firstChild.nodeValue;
								}catch(e){
									_Area = "";
								}
								
								switch (_Area){
								
									case "ADDITIONALPERSON"						:	SetAdditionalPersonError();
																					break;
									case "BOOKING_USED_AGENCY"					: 	_oField = document.getElementById('BookingAgency');
																					_oField.className += ' validationError';
																					break;
									case "BOOKING_AGENCY_BRANCH"				: 	_oField = document.getElementById('BookingBranch');
																					_oField.className += ' validationError';
																					break;
									case "CUSTOMER_DATA"						: 	SetCustomerDataError(_data[i]);
																					break;
									case 'BOOKING_NO_PAYMENT_ITEMS'				: 	displayPriceValidationErrors();
																					$('ctErrorNoPaymentItemsMsg').show();
																					break;
								}
							}
							refreshTips('Tips2');
						}
					} else {
						//everything is ok send the user to the booking has been save page
						var _iBookingID = "";
						try{
							_iBookingID = _xmldoc.documentElement.getElementsByTagName('booking_id').item(0).firstChild.nodeValue;
						}catch(e){
							_iBookingID = "";
						}
						window.location = sRootUrl + 'index.php?module=' + sModule + '&page=booking_saved&booking=' + _iBookingID;
					}
				}
			}
		}
		
		function SetAdditionalPersonError(){
			var tbody = document.getElementById('tabeladditionalpersons').getElementsByTagName("TBODY")[0];
			var _arrTableRows = '';
			var _arrTableCells = '';
			var _iNbrRows = 0;
			var _oField = null;
			var _oSelect = null;
			_arrTableRows = tbody.getElementsByTagName("TR");
			_iNbrRows = _arrTableRows.length;
		
			for (var i = 1; i < _iNbrRows; i++){			
				_arrTableCells = _arrTableRows[i].getElementsByTagName("TD");
				
				for (var j = 0; j < _arrTableCells.length; j++){
					if ((_arrTableCells[j].name != "tdsexe") && (_arrTableCells[j].name != "tdbirthday")){
						_oField = _arrTableCells[j].getElementsByTagName('INPUT');
						
						_oField[0].className = _oField[0].className.replace(' validationError', '');
						_oField[0].className = _oField[0].className.replace('validationError', '');
						if (_oField[0].value == ''){
							//Set error style
							_oField[0].className += " validationError";
						}
					}
					if (_arrTableCells[j].name == "tdbirthday"){
						_oField = _arrTableCells[j].getElementsByTagName('INPUT');
						
						_oField[0].className = _oField[0].className.replace(' validationError', '');
						_oField[0].className = _oField[0].className.replace('validationError', '');	
						if (_oField[0].value == ''){
							//Set error style
							_oField[0].className += " validationError";
						}else if (!CheckDate(_oField[0].value)){
							_oField[0].className += " validationError";
						}
					}
					
					if (_arrTableCells[j].name == "tdsexe"){
						_oSelect = _arrTableCells[j].getElementsByTagName('SELECT');
						
						_oSelect[0].className = _oSelect[0].className.replace(' validationError', '');
						_oSelect[0].className = _oSelect[0].className.replace('validationError', '');
						if (_oSelect[0].value < 0){
							_oSelect[0].className += " validationError";
						}
					}
				}
			}
		}
		
		function GetPaymentItems(){
			//first get the div with the price spans
			var _divPrices = document.getElementById('divPrices');
			var _sReturn = "";
			//now fill the array with all the spans who contains the price objects
			var _arrPriceSpans 		= _divPrices.getElementsByTagName('span');
			var _arrPriceObjects 	= Array();

			var _spanAmount 		= 1;
			var _iNbrAmountObjects 	= 0;
			var _iCounter 			= 0;

		
			//start pharsing the array
			for (i = 0; i < _arrPriceSpans.length; i++){
				_sReturn += "&arrPaymentItems[" + i + "][Name]=[NameValue]";
				_sReturn += "&arrPaymentItems[" + i + "][NameAddOn]=[NameAddOnValue]";
				_sReturn += "&arrPaymentItems[" + i + "][Amount]=[AmountValue]";
				_sReturn += "&arrPaymentItems[" + i + "][Quantity]=[QuantityValue]";
				_sReturn += "&arrPaymentItems[" + i + "][AllocationTypeID]=[AllocationTypeIDValue]";
				
				_iCounter 			= 0;
				_spanAmount 		= 1;

				_arrPriceObjects 	= new Array();
		
				for(j=0; j < _arrPriceSpans[i].getElementsByTagName('input').length; j++){
					_arrPriceObjects.push(_arrPriceSpans[i].getElementsByTagName('input')[j]);
				}
				for(j=0; j < _arrPriceSpans[i].getElementsByTagName('select').length; j++){
					_arrPriceObjects.push(_arrPriceSpans[i].getElementsByTagName('select')[j]);
				}
		
				_iNbrAmountObjects = _arrPriceObjects.length;

				while (_iCounter < _iNbrAmountObjects) {
					var _oField = _arrPriceObjects[_iCounter];
					if (_oField.name == "ItemName"){
						_sReturn = _sReturn.replace('[NameValue]', escape(_oField.value));
					}else if (_oField.name == "AllocationTypeID") {
						_sReturn = _sReturn.replace('[AllocationTypeIDValue]', escape(_oField.value));
					}else if (_oField.name == "Amount") {
						_sReturn = _sReturn.replace('[AmountValue]', escape(_oField.value));
					}else if (_oField.name == "TextAddOn") {
						_sReturn = _sReturn.replace('[NameAddOnValue]', escape(_oField.value));
						
					}else{
						switch (_oField.type) {
							case "checkbox" :	if (_oField.checked) {
													_sReturn = _sReturn.replace('[QuantityValue]', escape(_oField.value));
												}else{
													_sReturn = _sReturn.replace('[QuantityValue]', '0');
												}
												break;
												
							default :			_sReturn = _sReturn.replace('[QuantityValue]', escape(_oField.value));
												break;
						}
					}
					_iCounter ++;
				}
				
			}
			
			return _sReturn;
		}
		
		function GetAdditionalPersons(){
			var _sReturn = "";
			
			var tbody = document.getElementById('tabeladditionalpersons').getElementsByTagName("TBODY")[0];
			var _arrTableRows = '';
			var _arrTableCells = '';
			var _iNbrRows = 0;
			var _oField = null;
			var _oSelect = null;
			
			_arrTableRows = tbody.getElementsByTagName("TR");
			_iNbrRows = _arrTableRows.length;
			
			for (i = 1; i <= _iNbrRows - 1; i++){
				_sReturn += "&arrPersonns[" + (i - 1) + "][Lastname]=[LastnameValue]";
				_sReturn += "&arrPersonns[" + (i - 1) + "][Firstname]=[FirstnameValue]";
				_sReturn += "&arrPersonns[" + (i - 1) + "][Birthday]=[BirthdayValue]";
				_sReturn += "&arrPersonns[" + (i - 1) + "][Sexe]=[SexeValue]";
				
				_arrTableCells = _arrTableRows[i].getElementsByTagName("TD");
				for (j = 0; j <= _arrTableCells.length - 1; j++){
					if (_arrTableCells[j].name == "tdlastname"){
						_oField = _arrTableCells[j].getElementsByTagName('INPUT')
						_sReturn = _sReturn.replace('[LastnameValue]', escape(_oField[0].value));
					}
					if (_arrTableCells[j].name == "tdfirstname"){
						_oField = _arrTableCells[j].getElementsByTagName('INPUT')
						_sReturn = _sReturn.replace('[FirstnameValue]', escape(_oField[0].value));
					}
					if (_arrTableCells[j].name == "tdbirthday"){
						_oField = _arrTableCells[j].getElementsByTagName('INPUT')
						_sReturn = _sReturn.replace('[BirthdayValue]', escape(_oField[0].value));
					}
					if (_arrTableCells[j].name == "tdsexe"){
						_oSelect = _arrTableCells[j].getElementsByTagName('SELECT')
						_sReturn = _sReturn.replace('[SexeValue]', escape(_oSelect[0].value));
					}
				}
			}
			
			return _sReturn;
		}
		
		function GetHotels(){
			var _sReturn 		= "";
			
			var _arrHotelIDs 	= document.getElementsByName('hfHotels[]');
			var _sHotelID		= "";
			var _sStartDate 	= "";
			var _sEndDate 		= "";
			
			//alert (_arrHotelIDs.length);
			
			for (i = 0; i < _arrHotelIDs.length; i++){
				_sStartDate = "";
				_sEndDate = "";
				//alert (_arrHotelIDs[i].value);
				//build the array (string) to post afer
				//get the id of the hotel
				_sHotelID = document.getElementById('hfHotelID_' + _arrHotelIDs[i].value).value;
				_sReturn += "&arrHotels[" + i + "][HotelID]=" + _sHotelID;
				//_sReturn += "\r\n";
				//now get the starting date of the hotel
				_sStartDate = document.getElementById('hfHotelStart_' + _arrHotelIDs[i].value).value;
				_sReturn += "&arrHotels[" + i + "][StartDate]=" + _sStartDate;
				//_sReturn += "\r\n";
				//now get the end date of the hotel
				_sEndDate = document.getElementById('hfHotelEnd_' + _arrHotelIDs[i].value).value;
				_sReturn += "&arrHotels[" + i + "][EndDate]=" + _sEndDate;
				//_sReturn += "\r\n";
			}
			
			//alert (_sReturn);
			return _sReturn;
		}
		
		function ClearBookingValidationErrors(){
			
			try{
				_oField = $('fDepartureLoctionTime');
				_oField.className = _oField.className.replace(' validationError', '');
			}catch(e){}
			
			try{
				_oField = $('BookingAgency');
				_oField.className = _oField.className.replace(' validationError', '');
			}catch(e){}
			
			try{
				_oField = $('BookingBranch');
				_oField.className = _oField.className.replace(' validationError', '');
			}catch(e){}
		}
		
		//================================
		// Customer Direct Registration
		// (added the 09/07/08)
		//================================
		
		function ClearCustomerValidationErrors(){
	
			var _arrValidationErrors = document.getElementsByName('validationError');
			var _oField = null;
			var _sFieldId = null;
			for($i=0;$i<_arrValidationErrors.length;$i++){
				HideBlockElement( _arrValidationErrors[$i].id);
				try{
					_sFieldId = 'f'+(_arrValidationErrors[$i].id.replace('img','')).replace('Err','');
					_oField = document.getElementById(_sFieldId);
					_oField.className = _oField.className.replace(/\s{0,1}validationError/, '');
				}catch(e){}
			}
		};
		
		function SetCustomerDataError(pData){
			
			var _fieldName = pData.getElementsByTagName('property_name').item(0).firstChild.nodeValue;
				
			try{
				var _fieldValue = pData.getElementsByTagName('property_value').item(0).firstChild.nodeValue;
			}catch(e){var _fieldValue = '';}
			
			try{
				var _fieldShortNote = pData.getElementsByTagName('short_note').item(0).firstChild.nodeValue;
			}catch(e){var _fieldShortNote = '';}
			
			try{
				var _fieldMessage = pData.getElementsByTagName('message').item(0).firstChild.nodeValue;
			}catch(e){var _fieldMessage = '';}
			
			var _fieldType = pData.getElementsByTagName('type').item(0).firstChild.nodeValue;
			
			
			//create the tipster for this error
			_oField = document.getElementById('f'+_fieldName);
			_oField.className += ' validationError';
			_oTips = document.getElementById('img' + _fieldName + 'Err');
			_oTips.title = _fieldShortNote+'::'+_fieldMessage;
			ShowBlockElement(_oTips.id);
		}
		
		function GetCustomerData(){
			var _sData = '';
			// customer data
			_sData += '&Shortspeech=' 	 + document.getElementById('fShortspeech').value;
			_sData += '&Lastname=' 		 + escapeString(document.getElementById('fLastname').value);
			_sData += '&Firstname=' 	 + escapeString(document.getElementById('fFirstname').value);
			_sData += '&Address=' 		 + escapeString(document.getElementById('fAddress').value);
			_sData += '&Zip=' 			 + escapeString(document.getElementById('fZip').value);
			_sData += '&Location=' 		 + escapeString(document.getElementById('fLocation').value);
			
			try{
				_sData += '&CountryCode=' + escape(document.getElementById('fCountryCode').value);
				_sData += '&Country=' + GetItemTextFromListbox(document.getElementById('fCountry'), document.getElementById('fCountryCode').value);
			} catch(e) {
				_sData += '&Country=' + document.getElementById('fCountry').value;
			}
			
			_sData += '&Phone=' 		 + escapeString(document.getElementById('fPhone').value);
			_sData += '&Gsm=' 		 	 + escapeString(document.getElementById('fGsm').value);
			_sData += '&Fax=' 			 + escapeString(document.getElementById('fFax').value);
			_sData += '&Email=' 	     + escapeString(document.getElementById('fEmail').value);
			return _sData;
		}
		
		//=============================================
		// Price (Allocationtypes) selection validation 
		// (added the 10/09/2009)
		//=============================================
		function displayPriceValidationErrors (){
			$$('.main_price').each(function(el){
				el.addClass('validationError');
			});
		};
		
		function clearPriceValidationErrors (){
			$$('.main_price').each(function(el){
				el.removeClass('validationError');
			});
		};
