function SetBoardBasisFrmSearch() {
// synchronize on other form
if (eval(document.frmSearch.boardbasis)) 
	{document.frmSearch.boardbasis.selectedIndex=document.form1.boardbasis.selectedIndex;}
}


function SetBoardBasisForm() {
// synchronize on other form
if (eval(document.form1.boardbasis)) 
	{document.form1.boardbasis.selectedIndex=document.frmSearch.boardbasis.selectedIndex;}
}

function SetSortOrderForm() {
// synchronize on other form
if (eval(document.form1.sortOrder)) 
	{document.form1.sortOrder.selectedIndex=document.frmSearch.sortOrder.selectedIndex;}
}

function SubmitOrRedirect() 	{
	//check if the no of persons are more than 8, if so refer to group booking
	
	var c = parseInt(document.frmSearch.AdultsPerRoom[frmSearch.AdultsPerRoom.selectedIndex].value);
	var d = parseInt(document.frmSearch.ChildrenPerRoom[frmSearch.ChildrenPerRoom.selectedIndex].value);
	var e = document.frmSearch.numRooms1.value;
	//alert((c+d)*e); // no of of persons!

	//group booking we need to redirect to groups.asp. 
	//Find out the domain name and subfolders, this script assumes that 
	//groups.asp is in the same folder as the current page!
	if ((c+d)*e>12)
	{
  	var arr_url = document.URL.split("/");
  	var x; 
  	var myurl;
  	myurl="http:/";
  
  	for (x=2;x<arr_url.length-1;x++)
  		{myurl=myurl+"/"+(arr_url[x]);}
  
  	//alert(myurl);
  	alert("For bookings referring to more than 12 people, you will be referred to the groups booking page.")
  	//now redirect to the url formed:
  	window.location=myurl+"/groups.asp";
	}
  else
	{
  	searchAgain();
	}
}

function SetComboTheTextandSearch(hotelID)	{
	// 2010-05-28 DWR: This method seems to be called from the Standalone Transfer page even though
	// it doesn't have a "theText" element. I haven't properly looked into this yet, but adding
	// this check to prevent the javascript error for now.
  var sel = document.form1.theText;
	if (!sel) {
	 return;
	}
	for(i=0; i <sel.length;i++) {
		if(sel.options[i].value==hotelID) {
		 sel.options[i].selected = true;
		 selectProduct(document.form1.theText);
		}
	}
}

function searchAgain()	{

	//document.form1.boardbasis[form1.boardbasis.selectedIndex].value;
	
	if (typeof(document.form1) === "undefined")
	{
		//no hidden form values in document (.e.g. when error message comes up)
		//start a new search anyway. 
    startCompleteSearch();
    return;
	}
	
	// this is the search on the left column in the result form.    SetBoardBasisFrmSearch();startCompleteSearch();
	// if essential values (e.g. dates number of nights etc) stayed 
	// the same we don't need to do a complete new seearch but can work 
	// with the temporary record set (search buffer) we have... 
	// New search: submit frmSearch     Requery the search buffer: submit form1
	// So first define whether fields stayed the same: 

	// 2010-07-21 DWR: This doesn't consider the scenario where there is a form1 element present but it is not
	// the form1 it expects (this happens on the "My Bookings" screen) - the best way to do this would be some
	// way to identify that form or maybe ensure that all the fields we need are present on it, but for now
	// we're just going to swallow the error we get trying to access the not-present fields and fire off
	// a new search
  try
  {
    if (document.frmSearch.startDate.value!=document.form1.startDate.value ||
  	document.frmSearch.numnight[document.frmSearch.numnight.selectedIndex].value!=document.form1.numnight.value ||
  	document.frmSearch.country[document.frmSearch.country.selectedIndex].value!=document.form1.country.value ||
  	document.frmSearch.city[document.frmSearch.city.selectedIndex].value!=document.form1.city.value ||
  	document.frmSearch.hotelname.value!=document.form1.hotelname.value ||
  	document.frmSearch.numRooms1.value!=document.form1.numRooms1.value ||
  	document.frmSearch.AdultsPerRoom[frmSearch.AdultsPerRoom.selectedIndex].value!=document.form1.AdultsPerRoom.value ||
  	document.frmSearch.ChildrenPerRoom[frmSearch.ChildrenPerRoom.selectedIndex].value!=document.form1.ChildrenPerRoom.value ||
  	document.frmSearch.roomType1Age1[frmSearch.roomType1Age1.selectedIndex].value!=document.form1.roomType1Age1.value ||
  	document.frmSearch.roomType1Age2[frmSearch.roomType1Age2.selectedIndex].value!=document.form1.roomType1Age2.value ||
  	document.frmSearch.roomType1Age3[frmSearch.roomType1Age3.selectedIndex].value!=document.form1.roomType1Age3.value ||
  	document.frmSearch.roomType1Age4[frmSearch.roomType1Age4.selectedIndex].value!=document.form1.roomType1Age4.value ||
  	(document.form1.BoardBasisCheck.value.length>0 &&  document.form1.BoardBasisCheck.value!=document.form1.boardbasis[form1.boardbasis.selectedIndex].value)) 
    {
  		//NOTE THAT THIS CODE IS ONLY CALLED BY THE SEARCH RESULTS PAGE 
  		//NOT BY THE OPENING PAGE - SEE ALSO FUNCTIONS.JS
  		//submit frmSearch - which means a complete new search; 
  		//check city value:
  		//alert("Complete new search");
  		startCompleteSearch();
    }
  	else 
  	{
  		//submit form 1 - which means query the searchbuffer again:	
  		document.form1.sortOrder.selectedIndex=document.frmSearch.sortOrder.selectedIndex;
  		document.form1.iConfirm.value=frmSearch.iConfirm[frmSearch.iConfirm.selectedIndex].value;
  		document.form1.MaxPrice.value=frmSearch.MaxPrice[frmSearch.MaxPrice.selectedIndex].value;
  		document.form1.category.selectedIndex=document.frmSearch.category.selectedIndex;
  		document.form1.boardbasis.selectedIndex=document.frmSearch.boardbasis.selectedIndex;
  		//alert("Only search search buffer - essential criteria stayed the same");
  		StartSearch();
  		document.form1.submit();
  	}
  }
  catch(e)
  {
    startCompleteSearch();
  }
}


function startCompleteSearch() {
  if (document.frmSearch.city[document.frmSearch.city.selectedIndex].value.length==0) {
  	alert("Please specify a city");
  	document.frmSearch.city.focus();
  	return false;
	}

	// if no. of children > 0 then 
	// check whether ages are completed 

	if (frmSearch.ChildrenPerRoom[frmSearch.ChildrenPerRoom.selectedIndex].value != 0) {
		var k=frmSearch.ChildrenPerRoom[frmSearch.ChildrenPerRoom.selectedIndex].value*frmSearch.numRooms1[frmSearch.numRooms1.selectedIndex].value;
		var selectAge;
		
		for(var i = 0; i < k; i++) {
			selectAge = "roomType1Age" + (i + 1);
			if (document.getElementById(selectAge)) {
        if (document.getElementById(selectAge).selectedIndex==0) {
  				alert ("Please select the age of the chid(ren)");
  				return false;
				}
			}
		}
  }
		
	StartSearch();
	document.frmSearch.submit();	
}


function resetSortOrder(searchID)
{
	//if (document.form1.sortorder.selectedIndex ==1){document.form1.pageNo.value=1;}
	document.form1.pageNo.value=1;
	document.form1.action='hotel_search_result.asp';
	document.form1.SearchID.value=searchID;//
	StartSearch();
	document.form1.submit();
}
function resetPageNo(searchID)
{
	//when we want to change page, we want to make sure no hotelfilters are used, with a hotelfilter there is one page anyway, and scrolling to page 2 for example would then lead to an error.
	window.document.form1.FindInSearch.value='';
	window.document.form1.FindInSearchHidden.value='';
	window.document.form1.hotelname.value='';
	window.document.form1.SearchPreformed.value='';
	window.document.form1.hotelid.value='';



	document.form1.pageNo.value=document.form1.pageNo1[document.form1.pageNo1.selectedIndex].value;
	document.form1.action='hotel_search_result.asp';
	document.form1.SearchID.value=searchID;//
	StartSearch();
	document.form1.submit();
}
function scrollPages(searchID)
{	

	//when we want to change page, we want to make sure no hotelfilters are used, with a hotelfilter there is one page anyway, and scrolling to page 2 for example would then lead to an error.
	window.document.form1.FindInSearch.value='';
	window.document.form1.FindInSearchHidden.value='';
	window.document.form1.hotelname.value='';
	window.document.form1.SearchPreformed.value='';
	window.document.form1.hotelid.value='';
	document.form1.action='hotel_search_result.asp';
	document.form1.SearchID.value=searchID;//
	StartSearch();
	document.form1.submit();
}
function StartSearch()
{	
	document.all.blkSearchResult.style.display="none";
	document.all.blkSearch.style.display="block";
	$(".TopLinks").hide();
	window.status = 'Please wait while we find properties for your selected dates.';
}

//------------------------------------------------------------------
//--Display all those products matching the criteria in the find box
//------------------------------------------------------------------
function findProductInSearch()
{
	//if the user is on a page following a search, he should be able 
	// to go back to the page listing again by clearing the text box 
	// and press search again. 
	// Normally, if text box is empty alert the user. 

	if (document.form1.FindInSearch.value.length==0)
		{
		if (document.form1.SearchPreformed.value.length==0)
			{alert("Please enter a search phrase.");}
		else
			{window.document.form1.submit();}
		}
	else 
		{
		document.form1.FindInSearchHidden.value=document.form1.FindInSearch.value;
		window.document.form1.submit();
		}
}

//------------------------------------------------------------------
//--Display a product based on the selection in the drop down--
//------------------------------------------------------------------
function selectProduct(obj)
{
	
	//Submit the form if the name is not theText (which show all the hotels):

 	window.document.form1.hotelid.value=obj[obj.selectedIndex].value;

	//alert (window.document.form1.hotelid.value);
	window.document.form1.submit();
	return;



	if (obj[obj.selectedIndex].value.length==0||obj.name!="theText")
		 {
		  window.document.form1.submit();
		  return;	
			}
	var vProduct = obj[obj.selectedIndex].value;	


	if ((vProduct!=null)&&(vProduct!=''))
	{	//alert(vProduct.length)

			

		if (((vProduct.length)<=2)&&(vProduct!=document.form1.pageNo.value))	//--for pages--
		{	document.form1.pageNo.value	= vProduct;//change the pageno else the current page wont show later
			//-----------------------------------------------------------------------			
			var objProducts = document.form1.theText;
			var len=objProducts.length;						
			for(var i=0;i<len;i++)
			{
				var name=objProducts.options[i].value;	

				

			
				if (name.match("_"+vProduct)!=null )//show
				
				{
					if ((window.document.getElementById('Result:HotelId=' + name))!=null)
					{window.document.getElementById('Result:HotelId=' + name).style.display = "block";}					
				}
				else if (name.match("_")!=null )//hide
				{	
					if ((window.document.getElementById('Result:HotelId=' + name))!=null)
					{window.document.getElementById('Result:HotelId=' + name).style.display = "none";}
				}
			}			
			//-----------------------------------------------------------------------
		}
		else if(vProduct!=document.form1.pageNo.value)	//--for individual hotelnames--
		{	
			//alert('Henk');

			if ((window.document.getElementById('tbl' + vProduct))!=null)
				{window.document.getElementById('tbl' + vProduct).style.display = "block";
				 // alert("result");
				}
			else
				{
				 //alert("no result");
				 window.document.form1.hotelid.value=obj[obj.selectedIndex].value;
				 window.document.form1.submit();
				}
			//------------------------------------------------------------------------
		}
    }
    
	if ((vProduct!=null)&&(vProduct!=''))
	{window.location.hash = vProduct;}
}




