var submitted=true;
var locpoptimer;
function init(){
	submitted=false;
	document.InputForm.LocationID.disabled = false;
	document.InputForm.AccommodationID.disabled = false;
	document.InputForm.Currency.disabled = false;
	document.InputForm.BPrice.disabled = false;
	document.InputForm.TPrice.disabled = false;
	document.InputForm.guests.disabled = false;
	document.InputForm.SelfCatering.disabled = false;
	document.InputForm.Specials.disabled = false;
	document.InputForm.Keyword.disabled = false;
	document.onkeypress = keypressed;
	calcNights()
	initcal();
	MM_preloadImages(BaseThemeURL+"images/topleft.gif",BaseThemeURL+"images/topbg.gif",BaseThemeURL+"images/topright.gif",BaseThemeURL+"images/leftbg.gif",BaseThemeURL+"images/rightbg.gif",BaseThemeURL+"images/bottomleft.gif",BaseThemeURL+"images/bottombg.gif",BaseThemeURL+"images/bottomspace.gif",BaseThemeURL+"images/bottomright.gif",BaseThemeURL+"images/arrowbottom.gif");
	DisFac=1;
	factimer=window.setTimeout('DisplayFacilities(1);',1);
	}
function keypressed(key){
	if(window.Event && key){if (key.which == "13"){SubmitDocument();}}
	else if (event){if(event.keyCode=="13"){SubmitDocument();}}
	}
function PopulateLocations(Parent){
	document.InputForm.LocationID.length=0;					//Clear Location Drop
	var area = sAll;
	if (Parent != 0){n = FindLocation(Parent);if(LocationHasChild(Parent)){area = sAll + " " + LA[n][2]}else{area = LA[n][2]}}
	document.InputForm.LocationID.options[0]=new Option(area,Parent);
	var i=1;
	if (Parent == 0){document.InputForm.LocationID.options[i]=new Option("-------------------","NA");i++;document.InputForm.LocationID.options[i]=new Option(LA[FindLocation(10)][2],10);i++;document.InputForm.LocationID.options[i]=new Option("-------------------","NA");i++;document.rollover_up.src=BaseThemeURL+"images/updis.gif"}
	for ( var n = 0; n < LA.length ; n++ ){if(LA[n][1]==Parent){if((LA[n][0]!=10)||(Parent!=0)){document.InputForm.LocationID.options[i]=new Option(LA[n][2],LA[n][0]);i++;}}}
	document.InputForm.LocationID.selectedIndex = 0;
	document.InputForm.LocationID.options[i]=new Option(cantfind,"TextSearch");
	if (Parent!=0){document.rollover_up.src=BaseThemeURL+"images/up.gif"}
	}
function LocationHasChild(Location){
	for (var n = 0; n < LA.length ; n++){if(LA[n][1]==Location){return true}}
	return false;
	}
function FindLocation(Location){
	for (var n = 0; n < LA.length ; n++){if(LA[n][0]==Location){return n}}
	return null;
	}
function LocationChanged(InputForm){
	window.clearTimeout(locpoptimer);
	writeDIV("","locpop");
	document.InputForm.Keyword.value = dKeywords;
	if (document.InputForm.LocationID.value == "NA"){document.InputForm.LocationID.selectedIndex=0}
	if (document.InputForm.LocationID.value != "TextSearch"){
		if ((document.InputForm.LocationID.selectedIndex!=0)&&(LocationHasChild(document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value))){
			PopulateLocations(document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value);
			document.InputForm.LocationID.selectedIndex=0;
			Locclick(LA[FindLocation(document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value)][2]);
			}
		}
	else if (document.InputForm.LocationID.value == "TextSearch"){
		PopulateLocations(0);
		GB_showCenter('Location Search', '/LocationTextSearch.asp', 400, 500, '')
		}
	}
function LocationUpLevel(){
	if (document.InputForm.LocationID.value == "TextSearch"){document.InputForm.LocationID.selectedIndex = 0}
	if (document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value!=0){
		PopulateLocations(LA[FindLocation(document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value)][1]);
		document.InputForm.LocationID.selectedIndex = 0;
		if (document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value==0){MM_swapImage('rollover_up','',BaseThemeURL+'images/updis.gif',1);clrLocclick()}else{Locclick(LA[FindLocation(document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value)][2])}
		}
	}
function Locclick(LocationTxT){
	var Pos = new Array(findPos(MM_findObj("LocationID")));
	DIVtext ="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	DIVtext +="<tr><td width=\"16\" height=\"16\" valign=\"top\" background=\""+BaseThemeURL+"images/topleft.gif\"></td>";
	DIVtext +="<td width=\"150\" height=\"16\" valign=\"top\" background=\""+BaseThemeURL+"images/topbg.gif\"></td>";
	DIVtext +="<td width=\"16\" height=\"16\" valign=\"top\" background=\""+BaseThemeURL+"images/topright.gif\"></td></tr>";
	DIVtext +="<tr><td valign=\"top\" background=\""+BaseThemeURL+"images/leftbg.gif\">&nbsp;</td>";
	DIVtext +="<td width=\"150\" bgcolor=\"#FFFFFF\" class=\"greyboldverdana\">"+ALocPoP[0]+" "+LocationTxT+" "+ALocPoP[1]+"</td>";
	DIVtext +="<td valign=\"top\" background=\""+BaseThemeURL+"images/rightbg.gif\">&nbsp;</td></tr>";
	DIVtext +="<tr><td width=\"16\" height=\"16\" valign=\"top\" background=\""+BaseThemeURL+"images/bottomleft.gif\"></td>";
	DIVtext +="<td valign=\"top\" align=\"center\" background=\""+BaseThemeURL+"images/bottombg.gif\">";
	DIVtext +="<table width=\"53\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
    DIVtext +="<td height=\"16\" background=\""+BaseThemeURL+"images/bottomspace.gif\"></td>";
    DIVtext +="</tr></table>";
	DIVtext +="<td width=\"16\" height=\"16\" valign=\"top\" background=\""+BaseThemeURL+"images/bottomright.gif\"></td></tr>";
	DIVtext +="<tr><td></td>";
	DIVtext +="<td valign=\"top\" align=\"center\"><img src=\""+BaseThemeURL+"images/arrowbottom.gif\" width=\"53\" height=\"42\" /></td>";
	DIVtext +="<td></td></tr>";
	DIVtext +="</table>";
	writeDIV(DIVtext,"locpop");
	ChangeStyle("locpop","position:absolute; left:"+(Pos[0][0]+150-66).toString()+"px; top:"+(Pos[0][1]-document.getElementById('locpop').offsetHeight).toString()+"px;");
	locpoptimer=window.setTimeout('clrLocclick()',5000);
	}
function clrLocclick(){
	writeDIV('','locpop');
	}
function diplayqwikbookpop(){
	visibility('visible','qwikbookpop');
	}
function clrqwikbookpop(){
	visibility('hidden','qwikbookpop');
	}
function LocationUpOut(){
	if (document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value!=0){MM_swapImgRestore()}
	}
function LocationUpOver(){
	if (document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value!=0){MM_swapImage('rollover_up','',BaseThemeURL+'images/upover.gif',1)}
	}
function CreateFacilities(Name,Where,Data,Selected,Class,OnClick){
	var Pos = new Array(findPos(MM_findObj(Where)));
	var ASel=Selected.split(",");
	var Select;
	var OnChange="";
	var SCOnChange="";
	if(Name!=""){
		if(Class!=""){Class=" class=\""+Class+"\""}
		if(OnClick!=""){
			OnChange=" onclick=\""+OnClick+"\"";
			SCOnChange=" onclick=\""+OnClick+";if(this.checked==true){document.InputForm.SelfCatering.checked=true}else{document.InputForm.SelfCatering.checked=false}\"";
			}
		else{
			SCOnChange=" onclick=\"if(this.checked==true){document.InputForm.SelfCatering.checked=true}else{document.InputForm.SelfCatering.checked=false}\"";
			}
		var DIVTxT = "";
		for(var d=1; d < 4;d++){
			var i=0;
			DIVTxT += "<div id=\"filterSet"+d+"\" style=\"display: none;\">";
			DIVTxT += "<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
			for(var n=0; n < Data.length;n++){
				if(Data[n][0]==d){
					if(i > 0){
						DIVTxT += "<tr align=\"center\"><td colspan=\"3\" background=\""+BaseThemeURL+"images/spacer-179x1.jpg\" height=\"1\" width=\"179\"></td></tr>";
						}
					i++;
					Select = "";
					for(var m=0;m < ASel.length;m++){
						if(Data[n][1]==ASel[m]){
							Select = " checked";
							break;
							}
						}
					if(Data[n][1]==35){
						if(Select!=""){document.InputForm.SelfCatering.checked=true;}
						writeDIV(Data[n][2],"SelfCateringTxT");
						DIVTxT += "<tr><td align=\"center\" width=\"29\"><img src=\""+BaseThemeURL+"images/"+Data[n][3]+"\" width=\"22\" height=\"22\" /></td><td height=\"20\" width=\"29\" align=\"center\"><input type=\"checkbox\" name=\""+Name+"\""+SCOnChange+" value=\""+Data[n][1]+"\""+Select+" /></td><td height=\"30\" width=\"150\" align=\"left\""+Class+">"+Data[n][2]+"</td></tr>";
						}
					else{
						DIVTxT += "<tr><td align=\"center\" width=\"29\"><img src=\""+BaseThemeURL+"images/"+Data[n][3]+"\" width=\"22\" height=\"22\" /></td><td height=\"20\" width=\"29\" align=\"center\"><input type=\"checkbox\" name=\""+Name+"\""+OnChange+" value=\""+Data[n][1]+"\""+Select+" /></td><td height=\"30\" width=\"150\" align=\"left\""+Class+">"+Data[n][2]+"</td></tr>";
						}
					}
				}
			DIVTxT += "<tr><td colspan=\"3\">&nbsp;</td><td height=\"30\" align=\"right\""+Class+"><a href=\"javascript:SubmitDocument();\" class=\"btnsearch\">"+LSearch+"</a></td></tr>";
			DIVTxT += "</table>";
			DIVTxT += "</div>";
			}
		writeDIV(DIVTxT,Where);
		}
	}
function DisplayFacilities(No){
	for(var d=1; d < 4;d++){
		ChangeStyle("filterSet"+d,"display: none;");
		ChangeClass("filterbtn"+d,"filClass1");
		}
	ChangeStyle("filterSet"+No,"display: block;z-index:0;");
	ChangeClass("filterbtn"+No,"filClass2");
	}
function calcNights(){
	if ((isValidDate(document.InputForm.ArrDate.value))&&(isValidDate(document.InputForm.DepDate.value))){
		if(new Date(document.InputForm.ArrDate.value) < new Date(document.InputForm.DepDate.value)){
			var nights = ((new Date(document.InputForm.DepDate.value)-new Date(document.InputForm.ArrDate.value))/(24*60*60*1000));
			document.InputForm.Nights.value=nights;
			return nights;
			}
		else{
			document.InputForm.Nights.value=0;
			return 0;
			}
		}
	document.InputForm.Nights.value=0;
	return -1;
	}
function ResetContols(){
	document.InputForm.ArrDate.value=sNow;
	document.InputForm.DepDate.value=sNow;
	document.InputForm.guests.value=2;
	document.InputForm.SelfCatering.checked=false;
	document.InputForm.Specials.checked=false;
	document.InputForm.BPrice.selectedIndex = 0;
	document.InputForm.TPrice.selectedIndex = document.InputForm.TPrice.length - 1;
	document.InputForm.AccommodationID.selectedIndex=0;
	if(document.InputForm.LocationID.options[document.InputForm.LocationID.selectedIndex].value!=0){
		PopulateLocations(0);
		}
	for(var n=0;n<document.InputForm.CategoryID.length;n++){document.InputForm.CategoryID.item(n).checked=false}
	}
function ArrDateClick(){
	document.InputForm.Keyword.value=dKeywords;
	if(!isValidDate(document.InputForm.ArrDate.value)){document.InputForm.ArrDate.value=sNow}
	popUpCalendar(document.InputForm.ArrDate, document.InputForm.ArrDate, 'dd mmm yyyy','if(calcNights()==0){document.InputForm.DepDate.value = document.InputForm.ArrDate.value};');
	}
function DepDateClick(){
	document.InputForm.Keyword.value=dKeywords;
	if((!isValidDate(document.InputForm.DepDate.value))&&(isValidDate(document.InputForm.ArrDate.value))){document.InputForm.DepDate.value=document.InputForm.ArrDate.value}
	if(!isValidDate(document.InputForm.DepDate.value)){document.InputForm.DepDate.value=sNow}
	popUpCalendar(document.InputForm.DepDate, document.InputForm.DepDate, 'dd mmm yyyy','if(calcNights()==0){document.InputForm.ArrDate.value = document.InputForm.DepDate.value};');
	}
function SubmitDocument(){
	if(submitted){return;}
	window.clearTimeout(locpoptimer);
	writeDIV("","locpop");
	if ((isValidDate(document.InputForm.DepDate.value))&&(!isValidDate(document.InputForm.ArrDate.value))){
		alert("Invalid Arrival Date or Date format");
		document.InputForm.ArrDate.focus();
		return;
		}
	if(GoogleMapSearch){
		tKeywords=document.InputForm.Keyword.value;
		if(document.InputForm.Keyword.value == dKeywords){document.InputForm.Keyword.value ='';}
		sumbittimer=window.setTimeout("AccSearch(1)",0);
		}
	else{
		if(document.InputForm.Keyword.value == dKeywords){document.InputForm.Keyword.value ='';}
		document.body.style.cursor = "wait";
		document.InputForm.Page.value = "1";	
		document.InputForm.SearchS.value = 22;
		submitted=true;
		sumbittimer=window.setTimeout("submitted=false;document.body.style.cursor='default'",1000*20);
		document.InputForm.submit();
		}
	}
function PageingSubmit(Page){
	if(submitted){return;}
	if(document.InputForm.Keyword.value == dKeywords){document.InputForm.Keyword.value ='';}
	document.body.style.cursor = "wait";
	document.InputForm.Page.value=Page;
	document.InputForm.SearchS.value=22;
	submitted=true;
	sumbittimer=window.setTimeout("submitted=false;document.body.style.cursor='default'",1000*20);
	document.InputForm.submit();
	}
