
function showWindow( m_url, winname, winwidth, winheight, wndparams)
{
	if ((winname == null) || (winname == "")) winname = "bwc";
	
	if (screen.availHeight < winwidth) winheight= screen.availWidth;
	if (screen.availWidth < winwidth) winwidth = screen.availWidth;
	wintop = (screen.availHeight / 2) - (winheight / 2);
	winleft = (screen.availWidth / 2) - (winwidth / 2);
	wintop = (screen.availHeight / 2) - (winheight / 2);
	
	if (wndparams == null) wndparams = "scrollbars=no,resizable=no";
	window.open(m_url, winname,"left=" + winleft + ",top=" + wintop + ",width=" + winwidth + ",height=" + winheight + "," + wndparams);
}

var ResURL="http://book.bestwestern.com/bestwestern/priceAvail.do?propertyCode=05426&suppressSSLPopup=true&disablenav=true&sob=P377";

function openReservationWindow() {
showWindow(ResURL, 'Reservations', 840, 810, 'scrollbars,resizable,location,toolbar');
}
function viewReservationWindow() {
showWindow('http://book.bestwestern.com/bestwestern/reservationRetrieve.do?propertyCode=05426&suppressSSLPopup=true&disablenav=true&sob=P377', 'Reservations', 840, 700, 'scrollbars,resizable,location,toolbar');
}
function openVirtualTour() {
showWindow("http://www.vfmii.com/exc/aspquery?command=invoke&ipid=BW05426&ids=42470", 'newWin',566,464,'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes');
}
function openBestRateGuaranteed() {
showWindow("http://www.bestwesterncapitola.com/best_rate_guaranteed.htm", 'newWin',320,440,"status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
}


// ERROR MESSAGE TEXT - EDIT TEXT AS REQUIRED
var invalidDatePriorTxt = "Arrival Date selected is prior Today's date. Please change...";
var invalidDepartTxt = "Departure Date is prior to Arrival Date. Please change...";
var invalidMaxDateTxt = "Dates are too far in the future. Please contact hotel directly to book.";

// DATE SETTINGS - EDIT AS REQUIRED
var daysinAdvance = 0; // Sets default days in advance from current date
var numberNights = 1;  // Sets default number of nights
var maxDays = 366; //  Maximun days in the future that you can book

// WEEK DAY AND NUMBER NIGHTS TEXT - EDIT TEXT AS REQUIRED
var wdArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var nightTxt = " Night";
var nightsTxt = " Nights";

function GoToBooking(form){
	if (checkDates(form) == false) return;
	var URLis;
	URLis=ResURL;
	URLis=URLis+"&arrivalDay="+document.bookNowForm.checkInDay.value;
	URLis=URLis+"&arrivalMonthYear="+document.bookNowForm.checkInYear.value+document.bookNowForm.checkInMonth.value;
	URLis=URLis+"&departureDay="+document.bookNowForm.checkOutDay.value;
	URLis=URLis+"&departureMonthYear="+document.bookNowForm.checkOutYear.value+document.bookNowForm.checkOutMonth.value;
	URLis=URLis+"&ratePlan="+document.bookNowForm.ratePlan.value;
	//  this.location.href = URLis;
	//  window.status=('Connecting to ' + URLis); 
//	window.open(URLis, 'Reservations', 'scrollbars,resizable,location,toolbar,width=800,height=595');
	showWindow(URLis, 'Reservations', 840, 810, 'scrollbars,resizable,location,toolbar');
}
function langLaunch(lang){
	var URLis;
	URLis="http://book.bestwestern.com/bestwestern/priceAvail.do?propertyCode=05426&suppressSSLPopup=true&disablenav=true&sob=P377";
	URLis=URLis+"&language="+lang;
	showWindow(URLis, 'Reservations', 840, 700, 'scrollbars,resizable,location,toolbar');
}


//Load current dates on form load
function LoadDates(form) {
	var today = new Date();
	var setDate = new Date(today.getTime() + (daysinAdvance * 86400000));
	var setDay = setDate.getDate();
	var setMonth = setDate.getMonth();
	var setYear = setDate.getFullYear() - form.checkInYear.options[0].text;
	// Set Arrival Dates
	form.checkInDay.selectedIndex = setDay-1;
	form.checkInMonth.selectedIndex = setMonth;
	form.checkInYear.selectedIndex = setYear;
	// Set the Departure Dates
	var nextdate=new Date();
	nextdate.setDate(setDay+numberNights);
	var nextDay = nextdate.getDate();
	var nextMonth = nextdate.getMonth();
	var nextYear = nextdate.getFullYear() - form.checkOutYear.options[0].text;

	form.checkOutDay.selectedIndex = nextDay-1;
	form.checkOutMonth.selectedIndex = nextMonth;
	form.checkOutYear.selectedIndex = nextYear;

	setWkd(form);
}


function setCheckOutDate(form)
{
	for (var i = 0; i < form.checkInYear.length; i++) {
		if (form.checkInYear.options[i].selected) var fyear = form.checkInYear.options[i].text;
		if (form.checkOutYear.options[i].selected) var tyear = form.checkOutYear.options[i].text;
	}
	var checkInDate = new Date(fyear,form.checkInMonth.selectedIndex,form.checkInDay.selectedIndex+1);
	var checkOutDate = new Date(tyear,form.checkOutMonth.selectedIndex,form.checkOutDay.selectedIndex+1);
	
	if(checkInDate >= checkOutDate) {
		checkInDate.setDate(checkInDate.getDate() + numberNights );
		
		var nextDay = checkInDate.getDate();
		var nextMonth = checkInDate.getMonth();
		var nextYear = checkInDate.getFullYear() - form.checkOutYear.options[0].text;
//console.log("day",nextDay,"month",nextMonth,"Year",nextYear); /////////////////////////////////////////////////////////////
		
		form.checkOutDay.selectedIndex = nextDay-1;
		form.checkOutMonth.selectedIndex = nextMonth;
		form.checkOutYear.selectedIndex = nextYear;
	}
}

function setWkd(form, calendar) {
//function setWkd(form) {
	for (var i = 0; i < form.checkInYear.length; i++) {
		if (form.checkInYear.options[i].selected) var fyear = form.checkInYear.options[i].text;
		if (form.checkOutYear.options[i].selected) var tyear = form.checkOutYear.options[i].text;
	}
	var checkinDate = new Date(fyear,form.checkInMonth.selectedIndex,form.checkInDay.selectedIndex+1);
	var checkoutDate = new Date(tyear,form.checkOutMonth.selectedIndex,form.checkOutDay.selectedIndex+1);
	var numNights = Math.round((checkoutDate - checkinDate) / 86400000);
	if (numNights == 1) numNights += nightTxt;
	else numNights += nightsTxt;
	//Set Days of the week display
	if(document.getElementById) {
	// change form object if returned from calendar
		if(calendar) {
			opener.document.getElementById('inWd').firstChild.nodeValue = '(' + wdArray[checkinDate.getDay()] + ')';
			opener.document.getElementById('outWd').firstChild.nodeValue = '(' + wdArray[checkoutDate.getDay()] + ')';
			opener.document.getElementById('lengthStay').firstChild.nodeValue = numNights;
		} else {
			document.getElementById('inWd').firstChild.nodeValue = '(' + wdArray[checkinDate.getDay()] + ')';
			document.getElementById('outWd').firstChild.nodeValue = '(' + wdArray[checkoutDate.getDay()] + ')';
			document.getElementById('lengthStay').firstChild.nodeValue = numNights;
		}
	}
}


//Days in each month Array
var aNumDays = new Array (31,0,31,30,31,30,31,31,30,31,30,31);

//check days in the month
function checkDaysInMonth(form) {
	//check Leap Year
	if(form.checkInMonth.selectedIndex==1)  {
	  var leapYear  = new Date (form.checkInYear.options[form.checkInYear.selectedIndex].text,form.checkInMonth.selectedIndex+1,1);
	  var leapYear  = new Date (leapYear  - (24*60*60*1000));
	  var numDaysInMonth = leapYear.getDate();
	}else{
	  var numDaysInMonth = aNumDays[form.checkInMonth.selectedIndex];
	}
	if(form.checkInDay.selectedIndex > numDaysInMonth-1)  
		form.checkInDay.selectedIndex = numDaysInMonth-1;

	//check Leap Year
	if(form.checkOutMonth.selectedIndex==1)  {
	  var leapYear  = new Date (form.checkOutYear.options[form.checkOutYear.selectedIndex].text,form.checkOutMonth.selectedIndex+1,1);
	  leapYear  = new Date (leapYear  - (24*60*60*1000));
	  var numDaysOutMonth = leapYear.getDate();
	}else{
	  var numDaysOutMonth = aNumDays[form.checkOutMonth.selectedIndex];
	}
	if(form.checkOutDay.selectedIndex > numDaysInMonth-1)  
		form.checkOutDay.selectedIndex = numDaysInMonth-1;
//console.log("out",numDaysInMonth, "  ", form.checkOutDay.selectedIndex ); /////////////////////////////////////////////////////////////
}



 //Check to see if the dates are valid before sending to BW.com
function checkDates(form) {
    var curDate = new Date();
    for (var i = 0; i < form.checkInYear.length; i++) {
      if (form.checkInYear.options[i].selected) var fyear = form.checkInYear.options[i].text;
      if (form.checkOutYear.options[i].selected) var tyear = form.checkOutYear.options[i].text;
    }
    var checkinDate = new Date(fyear,form.checkInMonth.selectedIndex,form.checkInDay.selectedIndex+2);
	var checkoutDate = new Date(tyear,form.checkOutMonth.selectedIndex,form.checkOutDay.selectedIndex+2);
	var numNights = Math.round((checkoutDate - checkinDate) / 86400000);
    
    if(checkinDate.getTime() < curDate.getTime()) {
      alert(invalidDatePriorTxt);
      return false;
    }
    if(numNights < 1) {
      alert(invalidDepartTxt);
      return false;
    }

    var maxDate = new Date(curDate.getTime() + (maxDays * 86400000));
    if(checkoutDate.getTime() > maxDate.getTime()) {
      alert(invalidMaxDateTxt);
      return false;
    }

	return true;
}






















function swapImg(name,src){
eval('document.'+name+'.src='+src+'.src;');
}
homeOut=new Image();
homeOut.src='http://www.bestwesterncapitola.com//images2/home_lb.gif';
homeOvrer=new Image();
homeOvrer.src='http://www.bestwesterncapitola.com/images2/home_y.gif';

amenitiesOut=new Image();
amenitiesOut.src='http://www.bestwesterncapitola.com/images2/amenities_lb.gif';
amenitiesOver=new Image();
amenitiesOver.src='http://www.bestwesterncapitola.com/images2/amenities_y.gif';

areaOut=new Image();
areaOut.src='http://www.bestwesterncapitola.com/images2/area_information_lb.gif';
areaOver=new Image();
areaOver.src='http://www.bestwesterncapitola.com/images2/area_information_y.gif';

mapOut=new Image();
mapOut.src='http://www.bestwesterncapitola.com/images2/map_directions_lb.gif';
mapOver=new Image();
mapOver.src='http://www.bestwesterncapitola.com/images2/map_directions_y.gif';

meetingsOut=new Image();
meetingsOut.src='http://www.bestwesterncapitola.com/images2/meeting_lb.gif';
meetingsOver=new Image();
meetingsOver.src='http://www.bestwesterncapitola.com/images2/meeting_y.gif';

