var maxCapacity=5;

function popUpConfirm() {
   var sAgent = navigator.userAgent.toLowerCase();
   var sAgent1=navigator.appName.toLowerCase();
   var isNetScape=false;
   if(sAgent.indexOf("netscape")>=0 || sAgent1.indexOf("netscape")>=0)
	isNetScape=true;
  
   var errcode=arguments[0];
   var defaultproblem="";
   var defaultsolution="";
   if (arguments[1] != null)
   	defaultproblem=arguments[1];
   if (arguments[2] != null)
   	defaultsolution=arguments[1];
   if(isNetScape) {
      if(errcode=='E100-006') {return confirm("You  are welcome to continue with your booking, but we wanted you to be aware of its length.  We welcome long stays.");}


      return confirm("Are you sure you want to do it?");
   }
   var winleft=100;var wintop=100;var winwidth=550;var winheight=400;
   if(errcode=='E502-001') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-002') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-004') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-005') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-006') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-007') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-009') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-010') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-011') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-012') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-014') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-017') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-021') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-022') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-023') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-025') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-026') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-027') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-029') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-033') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-034') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-035') {winleft=220; wintop=150;winwidth=250;winheight=220;}
if(errcode=='E502-037') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-016') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-018') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-019') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-031') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-032') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-042') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-045') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-047') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-048') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-008') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-020') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-028') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-049') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-050') {winleft=220; wintop=150;winwidth=250;winheight=230;}
if(errcode=='E502-003') {winleft=250; wintop=200;winwidth=250;winheight=200;}
if(errcode=='E502-013') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-015') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-030') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-036') {winleft=220; wintop=150;winwidth=250;winheight=220;}
if(errcode=='E502-038') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-043') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-053') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-109') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-051') {winleft=220; wintop=150;winwidth=250;winheight=250;}
if(errcode=='E502-101') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-104') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-111') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-054') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-041') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-044') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-046') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-052') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-102') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-105') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-106') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-107') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-039') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-040') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-055') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-103') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-108') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E502-110') {winleft=100; wintop=100;winwidth=250;winheight=200;}

   var url="https://www.bookdirect.com/HTMLJSP/confirmWin.jsp?errcode="+errcode+"&defaultproblem="+defaultproblem+"&defaultsolution="+defaultsolution+"&drdr="+Math.ceil(Math.random()*10000000);
   var winName="ERRORWIN";
   return showModalDialog(url,"","dialogLeft:"+winleft+"px;dialogTop:"+wintop+"px;dialogWidth:"+winwidth+"px;dialogHeight:"+winheight+"px;status:no;help:no;edge:sunken;scroll:no");
}

function adultshelp()
{
   // alert("The maximum number of adults is limited to the maximum capacity (5) that Best Western Victoria Park Suites accepts for it's room/suites.  If you wish to make a reservation for more people, then you should make multiple reservations.");
   popUp("https://www.bookdirect.com/HTMLJSP/checkavahelp.jsp?cap=5&hotelname=%42%65%73%74%20%57%65%73%74%65%72%6e%20%56%69%63%74%6f%72%69%61%20%50%61%72%6b%20%53%75%69%74%65%73","win1",200,200,400,200);
   // alert("You are in the process of booking one room/suite only.The maximum number of guests is limited to the maximum number of guests that the Best Western Victoria Park Suites accepts for its rooms/suites, which is 5.  If you wish to make a reservation for more than the allowable room/suite maximum, please make multiple reservations. First complete the reservation for this room at or below the maximum, then reserve other rooms until all of your party has been accommodated.Thank you.");
}

function setMaxLenBySlt(sltObj1,sltObj2) {
	var len1=sltObj1.options[sltObj1.selectedIndex].value;
	var len2=sltObj2.length;
	setMaxToSlt(sltObj2,maxCapacity-len1+1);
}

function setMaxToSlt(sltObj,maxLen) {
	var sltLen=sltObj.length;
	if(maxLen<sltLen) {
		for(var i=sltLen-1;i>=maxLen;i--) {
			sltObj.options[i]=null;
		}
	}
	else if(maxLen>sltLen) {
		for(var i=sltLen;i<maxLen;i++) {
			sltObj.options[sltObj.length]=new Option(i,i,0,0);
		}
	}
	if(sltObj.length==0)
		sltObj.options[sltObj.length]=new options(0,0,0,0);
}

function comp2Days(yearObj1,monthObj1,dayObj1,yearObj2,monthObj2,dayObj2,errorMsg) {
       	var year1=parseInt(yearObj1.options[yearObj1.selectedIndex].value, 10);//yearObj1.value;
       	var month1=parseInt(monthObj1.options[monthObj1.selectedIndex].value, 10);
       	var day1=parseInt(dayObj1.options[dayObj1.selectedIndex].value, 10);

       	var year2=parseInt(yearObj2.options[yearObj2.selectedIndex].value, 10);//yearObj2.value;
       	var month2=parseInt(monthObj2.options[monthObj2.selectedIndex].value, 10);
       	var day2=parseInt(dayObj2.options[dayObj2.selectedIndex].value, 10);
	    if(year2>year1 || (year2==year1 && month2>month1) || (year2==year1 && month2==month1 && day2>day1)) {
			return true;
	    }
	    else if(year2==year1 && month2==month1 && day2==day1) {
		popUpErr("E100-003");
        	return false;
            }
            else {
		popUpErr("E100-002");
        	return false;
            }
}

function checkAvaliability(dateParam) {
	var formObj=document.getElementById("myForm");
	// alert("The function has NOT been finished!");
	var checkInYearObj=formObj.checkInYear;
	var checkInMonthObj=formObj.checkInMonth;
	var checkInDayObj=formObj.checkInDay;

	var checkOutYearObj=formObj.checkOutYear;
	var checkOutMonthObj=formObj.checkOutMonth;
	var checkOutDayObj=formObj.checkOutDay;
	
	var begintime=dateParam.getTime() - 86400000;
	
	var starttime=new Date(checkInYearObj.options[checkInYearObj.selectedIndex].value,parseInt(checkInMonthObj.options[checkInMonthObj.selectedIndex].value, 10)-1,checkInDayObj.options[checkInDayObj.selectedIndex].value).getTime();
	var tmpstarttime=new Date(checkInYearObj.options[checkInYearObj.selectedIndex].value,parseInt(checkInMonthObj.options[checkInMonthObj.selectedIndex].value, 10)-1,checkInDayObj.options[checkInDayObj.selectedIndex].value);
	var tmpendtime = new Date(checkOutYearObj.options[checkOutYearObj.selectedIndex].value,parseInt(checkOutMonthObj.options[checkOutMonthObj.selectedIndex].value, 10)-1,checkOutDayObj.options[checkOutDayObj.selectedIndex].value);
	var endtime=new Date(checkOutYearObj.options[checkOutYearObj.selectedIndex].value,parseInt(checkOutMonthObj.options[checkOutMonthObj.selectedIndex].value, 10)-1,checkOutDayObj.options[checkOutDayObj.selectedIndex].value).getTime();
	var nights=(endtime-starttime)/(3600*24*1000);
	//alert(nights);
	
	var Adlts=formObj.Adlts.options[formObj.Adlts.selectedIndex].value;
	var kids=formObj.kids.options[formObj.kids.selectedIndex].value;
	var dd=dateParam;

	if (begintime>starttime) {
	 
	popUpErr('E100-001');
	
	 return ;
	   
	 }
	if(Adlts+kids==0) {
	   popUpErr("E100-004");
	}
	else if(comp2Days(checkInYearObj,checkInMonthObj,checkInDayObj,checkOutYearObj,checkOutMonthObj,checkOutDayObj,'It is not possible to have an arrival date before departure date. Please re-enter your dates.')) {
		//if(fieldIsDigital(formObj.Adlts,"Only number is acceptable for the area!") && fieldIsDigital(formObj.kids,"Only number is acceptable for the area!")) {
			var tosubmit=true;
			if(nights>60) {
				tosubmit=popUpConfirm("E100-006","You have selected a date range greater than 60 nights, are you sure?","choose 'OK' to continue, choose 'CANCEL' to cancel");
			}
			if(tosubmit) {
				formObj.whichButtonClick.value="check";
				formObj.submit();
			}
		//}
	}
	
	
	
}




   function popUpErrWithParam() {
 var errcode=arguments[0];
   var winleft=100;var wintop=100;var winwidth=800;var winheight=600;
   
    var url="https://www.bookdirect.com/HTMLJSP/errormsg.jsp?errcode="+errcode
      for (var i=1;i<6;i++ ){
      if (arguments[i] != "" || arguments[i] != null) {
       url = url + "&"+(i-1)+"="+arguments[i];
      }
      }
     url=url+ "&drdr="+Math.ceil(Math.random()*10000000)+"&adjustWin=1";
   
   
   var sAgent = navigator.userAgent.toLowerCase();
   var sAgent1=navigator.appName.toLowerCase();
   var isNetScape=false;
   if(sAgent.indexOf("netscape")>=0 || sAgent1.indexOf("netscape")>=0)
	isNetScape=true;
   if(!isNetScape) {
          showModalDialog(url,"","dialogLeft:"+winleft+"px;dialogTop:"+wintop+"px;dialogWidth:"+winwidth+"px;dialogHeight:"+winheight+"px;status:no;help:no;edge:sunken;scroll:no");
     }
     else {
     	var winobj=open(url,winName,"left="+winleft+",top="+wintop+",width="+winwidth+",height="+winheight+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0");
     	winobj.focus();
   }
   
}




function popUpErr() {
   var errcode=arguments[0];
   var defaultproblem="";
   var defaultsolution="";
   if (arguments[1] != null)
   	defaultproblem=arguments[1];
   if (arguments[2] != null)
   	defaultsolution=arguments[1];
   var winleft=100;var wintop=100;var winwidth=500;var winheight=300;
   if(errcode=='E100-001') {winleft=200; wintop=200;winwidth=290;winheight=180;}
if(errcode=='E100-002') {winleft=100; wintop=200;winwidth=300;winheight=200;}
if(errcode=='E100-003') {winleft=200; wintop=200;winwidth=300;winheight=200;}
if(errcode=='E100-004') {winleft=150; wintop=250;winwidth=300;winheight=200;}
if(errcode=='E100-005') {winleft=150; wintop=300;winwidth=300;winheight=250;}
if(errcode=='E100-107') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E100-108') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E100-109') {winleft=100; wintop=100;winwidth=250;winheight=200;}
if(errcode=='E100-006') {winleft=100; wintop=100;winwidth=250;winheight=250;}
if(errcode=='E100-399') {winleft=100; wintop=100;winwidth=250;winheight=200;}

   var url="https://www.bookdirect.com/HTMLJSP/errormsg.jsp?errcode="+errcode+"&defaultproblem="+defaultproblem+"&defaultsolution="+defaultsolution+"&drdr="+Math.ceil(Math.random()*10000000);
   // alert(url);
   var winName="ERRORWIN";
   var sAgent = navigator.userAgent.toLowerCase();
   var sAgent1=navigator.appName.toLowerCase();
   var isNetScape=false;
   if(sAgent.indexOf("netscape")>=0 || sAgent1.indexOf("netscape")>=0)
	isNetScape=true;
   if(!isNetScape) {
        showModalDialog(url,"","dialogLeft:"+winleft+"px;dialogTop:"+wintop+"px;dialogWidth:"+winwidth+"px;dialogHeight:"+winheight+"px;status:no;help:no;edge:sunken;scroll:no");
   }
   else {
   	var winobj=open(url,winName,"left="+winleft+",top="+wintop+",width="+winwidth+",height="+winheight+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0");
   	winobj.focus();
   }
}
function BDpopUp(url) {
     var winobj=open(url,"","left=10,top=20,width=750,height=450,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
     winobj.focus();
}


function popUp(url,winName,left,top,winwidth,winheight) {
	var sealWin=open(url,winName,'left='+left+',top='+top+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+winwidth+',height='+winheight);
	sealWin.focus();
}

function setSecondDate(form,yearObj,monthObj,dayObj,y,m,d) {
	if(parseInt(y+"")<1900)
		y = y + 1900;
	today = new Date();
	yearObj.options[y - today.getFullYear()].selected='selected';
	monthObj.options[m-1].selected='selected';
	dayObj.options[d-1].selected='selected';
	setYearMonthDay(form,yearObj,monthObj,dayObj,2)
}

function setYearMonthDay(form,yearObj,monthObj,dayObj,type)	{
	var year=yearObj.options[yearObj.selectedIndex].value;
	var month=monthObj.options[monthObj.selectedIndex].value;
	var day=dayObj.options[dayObj.selectedIndex].value;

	var dayObjLen=dayObj.length;
	var maxDay=31;
	if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
		maxDay=31;
	else if (month==4 || month==6 || month==9 || month==11)
		maxDay=30;
	else if(year%4==0 && month==2)
		maxDay=29;
	else if(year%4!=0 && month==2)
		maxDay=28;
	var i=dayObjLen-maxDay;
	if(i>0) {
		while(i>0) {
		   dayObj.options[dayObj.length-1]=null;
		   i--;
		}
	}
	else if(i<0){
		while(i<0) {
		   dayObj.options[dayObj.length]=new Option((dayObj.length+1)+"",dayObj.length+1,0,0);
		   i++;
		}
	}
	if(day>maxDay) {
		dayObj.options[dayObj.length-1].selected=true;
	}
	if(type==1) {
		year=yearObj.options[yearObj.selectedIndex].value;
		month=monthObj.options[monthObj.selectedIndex].value;
		day=dayObj.options[dayObj.selectedIndex].value;

		var tempTime=new Date(year,parseInt(month)-1,parseInt(day));
		tempTime.setTime(tempTime.getTime()+(24*3600*1000));
		year=tempTime.getYear();
		month=tempTime.getMonth()+1;
		day=tempTime.getDate();

		setSecondDate(form,form.checkOutYear,form.checkOutMonth,form.checkOutDay,year,month,day);
	}
}