<!--

/**
* A class to hold search parameters to be sent to the catalogue search programmes via JSON
*/
var SearchParms = new Class({

	initialize: function(pageNumber, sessionId, regionLetters){
		this.pageNumber = 0;
		this.pageNumber = pageNumber * 1;
		this.sessionId = sessionId;
		//we need all the regionLetters together as a String for the search programme
		this.regionLetter = this.getRegionLetters(regionLetters);
		//we also need the regionLetters as a String[] array for the SearchParmsBean in the session
		this.regionLetterArray = this.getRegionLettersArray(regionLetters);
		this.pax = 0;
		//we use the pax field to tell us if there are search parms on the page
		if($defined($('pax'))){
			this.pax = $('pax').value * 1;
			this.data_arrivo = (document.getElementById("data_arrivo")).value;
			this.noOfDays = 0;
			this.noOfDays = ((document.getElementById("noOfDays")).value) * 1;

			var spendingLimitObj = document.getElementById("spendingLimit");
		
			if(spendingLimitObj != null){
				this.spendingLimit = spendingLimitObj.value;
			}else{
				this.spendingLimit = null;		
			}
			this.spendingLimitType = this.getSpendingLimitType();
			this.dogs = this.getCheckBoxValue("dogs");
			this.broadband = this.getCheckBoxValue("broadband");
		}
		var houseTypeObj = document.getElementById("houseType");
		if(houseTypeObj != null && houseTypeObj != undefined){
			this.houseType = houseTypeObj.value;
		}
		//tells us if we're on the wishlist
		if($defined($('wishList'))){
			this.wishList = true;
		}//end if		
		
		/**
		* a div with id isASearch is on the FindAvailability page so we can distinguish
		* the search page from the regions pages.
		*/
		var isASearchObj = document.getElementById("isASearch");
		if(isASearchObj != null){
			this.search = true;
		}
		var currentHouseNumberObj = document.getElementById("currentHouseNumber");
		if(currentHouseNumberObj != null){
			this.currentHouseNumber = currentHouseNumberObj.value;
		}
		
		var zoneObj = document.getElementById("zona");
		if(zoneObj){
//			this.zona = escape(zoneObj.options[zoneObj.selectedIndex].value);
			//it's all in UTF-8 so no need to encode
			this.zona = zoneObj.options[zoneObj.selectedIndex].value;
		}else{
			//we had to add this senseless line otherwise it always took the 
			//line above...
			this.zona = null;
		}

	},

	 getCheckBoxValue: function(checkBoxId){
		var cBoxObj = document.getElementById(checkBoxId);
		if(cBoxObj != null){
			if(cBoxObj.checked){
				return "on";
			}else{
				return null;
			}//end if
		}else{
			return null;
		}//end if
	},//end function
	
	 getSpendingLimitType: function(){
		var spendingLimitPerWeekRadioObj = document.getElementById("spendingLimitPerWeekRadio");
		var spendingLimitPerHolidayRadioObj = document.getElementById("spendingLimitPerHolidayRadio");
		if(spendingLimitPerWeekRadioObj != null){
			if(spendingLimitPerWeekRadioObj.checked){
				return spendingLimitPerWeekRadioObj.value;
			}else{
				return spendingLimitPerHolidayRadioObj.value;
			}//end if
		}else{
			return null;
		}//end if
	},//end getSpendingLimitType()

	getRegionLetters: function(regionLetters){
		//if we've got the region letters, we're on the regions page
		if(regionLetters != null && regionLetters.length > 0){
			return regionLetters;
		}//end if
		//otherwise get them off the page
		
		//on the house type pages eg Luxury they're in the regionLetterHouseTypes select box
		var regionLetterHouseTypesObj = document.getElementById('regionLetterHouseTypes');
		if(regionLetterHouseTypesObj != null){
			return regionLetterHouseTypesObj.value;
		}
		
		//first check the AllRegions checkbox
		var allRegionsCheckboxObj = document.getElementById("zonesBoxesCheckboxAll");
		if(allRegionsCheckboxObj != null && allRegionsCheckboxObj.checked){
			return allRegionsCheckboxObj.value;
		}//end if
		
		var currentCheckboxObj = null;
		var regionLetterString = "";
		for(var i = 0; i < 30; i = i + 1){
			currentCheckboxObj = document.getElementById("zonesBoxesCheckbox" + i);
			if(currentCheckboxObj == null){
				break;
			}//end if
			if(currentCheckboxObj.checked){
				regionLetterString = regionLetterString + currentCheckboxObj.value;
			}//end if
		}//end for
		
		//timeaway index.jsp
		if(regionLetterString.length == 0 && $defined($('regionLetter'))){
			regionLetterString = $('regionLetter').value;
		}
		
		return regionLetterString;
	},//end function()

	getRegionLettersArray: function(regionLetters){
		//if we've got the region letters, we're in the regions
		if(regionLetters != null && regionLetters.length > 0){
			return null;
		}//end if

		var regionLettersArray = new Array();
		//first check the AllRegions checkbox
		var allRegionsCheckboxObj = document.getElementById("zonesBoxesCheckboxAll");
		if(allRegionsCheckboxObj == null){
			return null;
		}
		if(allRegionsCheckboxObj.checked){
			regionLettersArray[0] = allRegionsCheckboxObj.value;
		}//end if
		
		var currentCheckboxObj = null;
		for(var i = regionLettersArray.length; i < 30; i = i + 1){
			currentCheckboxObj = document.getElementById("zonesBoxesCheckbox" + i);
			if(currentCheckboxObj == null){
				break;
			}//end if
			if(currentCheckboxObj.checked){
				regionLettersArray[i] = currentCheckboxObj.value;
			}//end if
		}//end for
		return regionLettersArray;
	},//end function()
	

	setParams: function(pax, data_arrivo, regionLetter, noOfDays, sessionId){
		this.pageNumber = 1;
		this.sessionId = sessionId;

		this.regionLetter = regionLetter;
		//we also need the regionLetters as a String[] array for the SearchParmsBean in the session
		this.regionLetterArray = this.getRegionLettersArray(regionLetter);
		this.pax = pax;

		this.data_arrivo = data_arrivo;
		this.noOfDays = noOfDays;
		
		//search as opposed to a regions page
		this.search = true;
		this.currentHouseNumber = 0;
		this.zona = null;
		
		this.dogs = null;
		this.broadband = null;
		this.spendingLimit = null;
		this.spendingLimitType = null;
		

	}//end function
		

});



// end hide -->
