
	// initial area select boxes using possible if there are cookie values
	function initialiseLocationSelectBoxes(theform)  {
		var activity, areaid, areaid, starrating, doc, maxelements, selindex;
		areaid = readCookie("areaid");
		destinationid = readCookie("destinationid");
		if (areaid!="")   {
			setSelectedIndex(theform.areaid, areaid);
			filterDestinations(theform, theform.areaid);
			if (destinationid!="") setSelectedIndex(theform.destinationid, destinationid);
			}
		}

	// general purpose select box, using cookie
	function initializeGeneralSelectBox(theform, elementName)  {
		var thevalue, felement;
		thevalue = readCookie(elementName);
		eval("felement=theform."+elementName+";");
		setSelectedIndex(felement, thevalue);
		}

	// setting value of select box
	function setSelectedIndex(felement, thetext)  {
		var maxelements, selindex;
		maxelements = felement.length;
		for (i=0; i<maxelements; i++ )  {
			if (felement.options[i].text==thetext) selindex=i;
			}	
		felement.selectedIndex = selindex;
		}

	// creates object which maps each area to all it's child destinations
	function initParentChildObject(hiddenobjectname) 	{
		
		var szInfo, arryInfo, maxElements, i, j, doc, obj, strAreaDestinationMapping="||";
		doc = document.forms.form_hotel_search;
		szInfo = document.getElementById(hiddenobjectname).innerHTML;

		// get rid of final |
		szInfo=szInfo.substring(0,szInfo.length-1);
		obj = new Object();
		arryInfo = szInfo.split("|");
		maxElements = arryInfo.length / 5;

		// create initial string 
		for (i=0; i<maxElements*5; i+=5 )  {
			destID = arryInfo[i];
			destname = arryInfo[i+1];
			strAreaDestinationMapping = addItem(strAreaDestinationMapping, arryInfo[i+2], destID, destname);
			strAreaDestinationMapping = addItem(strAreaDestinationMapping, arryInfo[i+3], destID, destname);
			strAreaDestinationMapping = addItem(strAreaDestinationMapping, arryInfo[i+4], destID, destname);
			}

		// now create the area array, maps each area to all it's destinations
		j=0;
		obj.areaID = new Array();
		obj.strdest= new Array();
		areaarray = strAreaDestinationMapping.split("||");
		maxElements = areaarray.length;
		for (i=1; i<maxElements - 1; i++ )  {
			thepos=areaarray[i].indexOf("|");
			strA = areaarray[i].substring(0, thepos);
			strB = areaarray[i].substring(thepos+1);
			obj.areaID[j] = strA;
			obj.strdest[j] = strB;
			j++;
			}
		return obj;
		}

	// func used to add to mappings string
	function addItem (strAreaDestinationMapping, areaID, destID, destname)   {
		thepos=strAreaDestinationMapping.indexOf("||"+areaID+"|");
		if (thepos==-1) strAreaDestinationMapping = strAreaDestinationMapping + areaID + "|" + destID + "*" + destname + "||";
		else  {
			strA = strAreaDestinationMapping.substring(thepos+1);
			strY = strAreaDestinationMapping.substring(0, thepos+1);
			thepos=strA.indexOf("||");
			strB = strA.substring(0, thepos);
			strZ = strA.substring(thepos);
			strB = strB + "|" + destID + "*" + destname;
			strAreaDestinationMapping = strY + strB + strZ;
			}
		return strAreaDestinationMapping;
		}

	//Generates a list of months and years (current and next) and populates the departure month drop down box on the search form
	function InitializeMonthOptions(theform, elementName) {
		var currentDate, currentYear, nextYear, currentMonth, selectElement, totalCurrentMonths, selval;
		thevalue = readCookie(elementName);
		eval("selectElement = theform." + elementName + ";");
		totalCurrentMonths = 0;
		departureMonths = new Array();
		departureMonthsVal = new Array();
		months = new Array(12);
		months[1] = 'January';
		months[2] = 'February';
		months[3] = 'March';
		months[4] = 'April';
		months[5] = 'May';
		months[6] = 'June';
		months[7] = 'July';
		months[8] = 'August';
		months[9] = 'September';
		months[10] = 'October';
		months[11] = 'November';
		months[12] = 'December';
		currentDate = new Date();
		currentMonth = currentDate.getMonth() + 1;
		currentYear = currentDate.getYear();
		strcurrentYear = currentYear.toString();
		strcurrentYearabbrev = strcurrentYear.substring(strcurrentYear.length - 2);
		nextYear = currentYear + 1;
		strnextYear = nextYear.toString();
		strnextYearabbrev = strnextYear.substring(strnextYear.length - 2);
		for (i = currentMonth; i <= 12; i++) {
			totalCurrentMonths = totalCurrentMonths + 1;
			departureMonths[totalCurrentMonths] = months[i] + " 20" + strcurrentYearabbrev;
			if (i < 10) departureMonthsVal[totalCurrentMonths] = "20" + strcurrentYearabbrev + "-0" + i + "-01";
			else departureMonthsVal[totalCurrentMonths] = "20" + strcurrentYearabbrev + "-" + i + "-01";
			}
		for (i = 1; i <= 12; i++) {
			totalCurrentMonths = totalCurrentMonths + 1;
			departureMonths[totalCurrentMonths] = months[i] + " 20" + strnextYearabbrev;
			if (i < 10) departureMonthsVal[totalCurrentMonths] = "20" + strnextYearabbrev + "-0" + i + "-01";
			else departureMonthsVal[totalCurrentMonths] = "20" + strnextYearabbrev + "-" + i + "-01";
			}
		for (i=1; i<departureMonths.length; i++)   {
			if (departureMonths[i]==thevalue) selval=i;
			selectElement.options[i] = new Option(departureMonths[i], departureMonthsVal[i]);
			}
		selectElement.selectedIndex=selval;
		}

	// changes destination select options when area options changed
	function filterDestinations(theform, thearea)  {		
		var areaID, areaname, maxAreas, i, j;
		destinationSelect = theform.destinationid;
		destinationSelect.length = 0;
		areaID = thearea.options[thearea.selectedIndex].value;
		areaname = thearea.options[thearea.selectedIndex].text;
		destinationSelect.options[destinationSelect.options.length] = new Option("All destinations in " + areaname, "");
		maxAreas = objDestinationList.areaID.length;
		for (i=0; i<maxAreas; i++)   {
			if (objDestinationList.areaID[i]==areaID)  {
				destarray = objDestinationList.strdest[i].split("|");
				for (j=0; j<destarray.length; j++)  {
					subdestarray = destarray[j].split("*");
					destinationSelect.options[destinationSelect.options.length] = new Option(subdestarray[1], subdestarray[0]);
					}
				}
			}
		return;
		}
