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!

	if ((c+d)*e>8)

	//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!
	
	{
	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 8 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)	{
//alert(hotelID);

	var sel = document.form1.theText;
	for(i=0; i <sel.length;i++) 	{
		if(sel.options[i].value==hotelID+'_1')
		{
		 
		 sel.options[i].selected = true;
		 selectProduct(document.form1.theText);
		}
	}
}

function searchAgain()	{

	//alert('henkje22'+document.form1.BoardBasisCheck.value.length);
	//alert( document.form1.BoardBasisCheck.value.length+' '+ document.form1.BoardBasisCheck.value + ' ' + document.form1.boardbasis[form1.boardbasis.selectedIndex].value)
	
	if (!eval(document.form1))
		//no hidden form values in document (.e.g. when error message comes up)
		//start a new search anyway. 
		{startCompleteSearch();}
	else

	{
	// 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: 

		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();
		}
	

	}
	
	
}


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);
			//alert(selectAge);
			//alert (document.getElementById(selectAge).selectedIndex);

			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)
{
	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)
{	
	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";
	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):

	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.all['tbl' + name])!=null)
					{window.document.all['tbl' + name].style.display = "block";}*/
					if ((window.document.getElementById('tbl' + name))!=null)
					{window.document.getElementById('tbl' + name).style.display = "block";}					
				}
				else if (name.match("_")!=null )//hide
				{	
					
					/*if ((window.document.all['tbl' + name])!=null)
					{window.document.all['tbl' + name].style.display = "none";}*/
					if ((window.document.getElementById('tbl' + name))!=null)
					{window.document.getElementById('tbl' + name).style.display = "none";}
				}
			}			
			//-----------------------------------------------------------------------
		}
		else if(vProduct!=document.form1.pageNo.value)	//--for individual hotelnames--
		{	
			//-----------------------------------------------------------------------
			/*if ((window.document.all['tbl' + vProduct])!=null)
				{window.document.all['tbl' + vProduct].style.display = "block";}*/
			
			
			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;}
}





