
	var starOptions = new Array();
	var hotelOptions = new Array();
	var boardOptions = new Array();
	var resortOptions = new Array();
	durationOptions = new Array();
	var xmlhttp;
	
	function closeBox(){
		document.getElementById("hotelBox").style.display = "none";
	}
	
	function autoSelect(duration)
	{
		var durationCount = document.getElementById("durationCount").innerHTML;
		durationInt = duration*1;
		
		for (x =0;x<durationCount;x++){
			//alert(document.dropdown.durationDrop[x].value + "|" + duration);		
			compareInt = document.dropdown.durationDrop[x].value*1;
			if (compareInt==duration){
				document.dropdown.durationDrop[x].selected = "1";
			}
		}
	}	
	
	function loadXMLDoc(outdepair,outarrair,outdepdate,url,reqType)
	{
		if (reqType=="1"){
			url = url + outdepdate;
			document.getElementById("duration").style.display = "none";
			document.getElementById("loading").style.display = "block";
		}else{
			document.getElementById("hotelBox").style.display = "block";
			document.getElementById("loadingHotel").style.display = "block";			
		}
	
		xmlhttp=null;
		if (window.XMLHttpRequest)
		{// code for Firefox, Opera, IE7, etc.
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttp!=null)
		{	
			if (reqType=="1"){		
				xmlhttp.onreadystatechange=state_Change;
			}else{
				xmlhttp.onreadystatechange=state_ChangeHotel;			
			}
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		}
		else
		{
			alert("Your browser does not support XMLHTTP.");
		}
	}

	function state_Change()
	{
		if (xmlhttp.readyState==4)
		{// 4 = "loaded"
			if (xmlhttp.status==200)
			{// 200 = "OK"
				outputString = xmlhttp.responseText.split("|");
				document.getElementById('duration').length = 0;				
				for (x=0;x<outputString.length;x++){
					if (outputString[x]!=''){		
					var optn = document.createElement("OPTION");
					optn.text = outputString[x];
					optn.value = outputString[x].replace("nights","");
					document.bigbox.duration.options.add(optn);		
					}
				}			
				document.getElementById("duration").style.display = "block";
				document.getElementById("loading").style.display = "none";	
				document.getElementById("findHolidays").disabled = false;					
				
			}
			else
			{
				alert("Problem retrieving data:" + xmlhttp.statusText);
			}
		}
	}
	
	function state_ChangeHotel()
	{	
		if (xmlhttp.readyState==4)
		{// 4 = "loaded"
			if (xmlhttp.status==200)
			{// 200 = "OK"
				document.getElementById("hotelBox").innerHTML = '<div style="width:500px;background-color:#ffffff;color:red;text-align:center;padding:10px;display:none;font-size:14px;height:21px" id="loadingHotel"><img src="images/loading.gif"> Loading Hotel Information</div>' + xmlhttp.responseText;		
			}
			else
			{
				alert("Problem retrieving data:" + xmlhttp.statusText);
			}
		}
	}	
	
	function compare(a,b){
		return a-b;
	}
	
	function populateDropDowns(){

		// Select unique values for dropdown
		boardOptions = boardOptions.unique();
		ressortOptions = resortOptions.unique();
		durationOptions = durationOptions.unique();

		// Order unqiue values, also order numbers via sub function		
		boardOptions.sort();
		resortOptions.sort();
		durationOptions.sort(compare);

		for (x=0;x<boardOptions.length;x++){
			if (boardOptions[x]){
				var optn = document.createElement("OPTION");
				optn.text = boardOptions[x];
				optn.value = boardOptions[x];
				document.dropdown.boardDrop.options.add(optn);
			}
		}
		for (x=0;x<resortOptions.length;x++){
			if (resortOptions[x]){
				var optn = document.createElement("OPTION");
				optn.text = resortOptions[x];
				optn.value = resortOptions[x];
				document.dropdown.resortDrop.options.add(optn);
			}
		}
		
		z = 0
		
		for (x=0;x<durationOptions.length;x++){
			if (durationOptions[x]){		
				var optn = document.createElement("OPTION");
				optn.text = durationOptions[x];
				optn.value = durationOptions[x];
				document.dropdown.durationDrop.options.add(optn);
				z++
			}
		}
		
		document.getElementById("durationCount").innerHTML = z;
		
		// Clear memory alloc
		starOptions.length = 0;
		hotelOptions.length = 0;
		boardOptions.length = 0;
		resortOptions.length = 0;
		durationOptions.length = 0;		
	}
	
	function addOption(starValue,hotelValue,boardValue,resortValue,durationValue,id,limiter){
		if(boardOptions.indexOf(boardValue)=="-1" && boardValue!=''){
			boardValue.replace(/^\s\s*/, '').replace(/\s\s*$/, '');		
			boardOptions[id] = boardValue;
		}
		if(resortOptions.indexOf(resortValue)=="-1" && resortValue!=''){
			resortValue.replace(/^\s\s*/, '').replace(/\s\s*$/, '');		
			resortOptions[id] = resortValue;
		}
		if(durationOptions.indexOf(durationValue)=="-1" && durationValue!=''){		
			durationValue.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			durationOptions[id] = durationValue*1;
		}
	}
	
	function filterValues(){
		if (document.getElementById("boardDrop").value){
			var boardCriteria = document.getElementById("boardDrop").value;
		}else{
			var boardCriteria = "";		
		}
		if (document.getElementById("resortDrop").value){
			var resortCriteria = document.getElementById("resortDrop").value;
		}else{
			var resortCriteria = "";		
		}
		if (document.getElementById("durationDrop").value){
			var durationCriteria = "&nbsp;" + document.getElementById("durationDrop").value.replace(/^\s*|\s*$/g,'') + " nights";
		}else{
			var durationCriteria = "";
		}
		
		
		// Scrapping Data
		var ext=document.getElementById('dealTable');
		
		// Memory Alloc
		var bannerArray = new Array();
		var holidayArray = new Array();
		
		// Counters
		bannerCounter = 0;
		holidayCounter = 0;
		
		for (x=0;x<ext.rows.length;x++){
			var thisString=ext.rows[x].innerHTML;
			// Remove all banners
			if (thisString.indexOf("yellowBanner")=="-1" && thisString.indexOf("select")=="-1" && thisString.indexOf("colSpan")=="-1"){
				if (ext.rows[x].cells[5] && ext.rows[x].cells[4] && ext.rows[x].cells[3]){
				if (ext.rows[x].cells[5].innerHTML.indexOf(durationCriteria)=="-1" || ext.rows[x].cells[4].innerHTML.indexOf(resortCriteria)=="-1" || ext.rows[x].cells[3].innerHTML.indexOf(boardCriteria)=="-1"){
					ext.rows[x].style.display='none';
				}else{
					ext.rows[x].style.display='block';
					holidayArray[x] = "BLOCK";
					holidayCounter++;
				}
				}
			}else{
				ext.rows[x].style.display='none';
				if (thisString.indexOf("yellowBanner")!="-1"){
					bannerArray[bannerCounter] = "" + x + "";
					bannerCounter++;
				}
			}
		}
		
		// Fix for removing banners with no deals underneath them
		for (y=0;y<bannerArray.length;y++){
			var lineSwitch = 0;
		
			// Find section start and end
			startBannerLineNumber = bannerArray[y];
			if (bannerArray[y+1]){
				limitBannerLineNumber = (bannerArray[y+1]*1)-1;
			}else{
				limitBannerLineNumber = (holidayArray.length*1);
			}
			
			for (x=0;x<holidayArray.length;x++){
				if(holidayArray[x]){
					if (x>startBannerLineNumber && x<limitBannerLineNumber){
						lineSwitch = 1;
						ext.rows[startBannerLineNumber].style.display='block';						
					}
				}
			}
		}
		
		// Display amount of hotels after filter
		document.getElementById("holidayCount").innerHTML = "Displaying " + holidayCounter + " holiday(s)";			
		
		// Release Memory Alloc
		bannerArray.length = 0;
		holidayArray.length = 0;
	}

	
		// image gallery stuff	
	
		function changeImage(picimage){
			//alert(picimage);
			document['picture'].src=picimage;
		}
			
		function showNoPic(placeHolder){
			document.getElementById(placeHolder).style.display = 'none';
		}
		
		function resize(){
		
			var box = document.getElementById("imgViewer");
			var img = document.getElementById("picture");

			// Grab the image's dimensions
			var imgH = img.clientHeight;
			var imgW = img.clientWidth;
			

			// Find which dimension is scaled the most
			var scaleH = box.clientHeight / img.clientHeight;
			var scaleW = box.clientWidth / img.clientWidth;

			// Scale the image
			if (scaleH < scaleW) {
				img.style.height = box.clientHeight + "px";
				img.style.width = Math.round(imgW * scaleH) + "px";
			} else {
				img.style.width = box.clientWidth + "px";0
				img.style.height = Math.round(imgH * scaleW) + "px";
			}
		}