// JavaScript Document


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=575');");
}

function updateDepartDate()
{
document.roomfinder.dMonth2.value = document.roomfinder.dMonth.value;
document.roomfinder.dDay2.value = document.roomfinder.dDay.value;
document.roomfinder.dYear2.value = document.roomfinder.dYear.value;
}

function setArrivalDate()
{
document.roomfinder.arrivaldate.value = document.roomfinder.dMonth.value + "/" + document.roomfinder.dDay.value  + "/" +  document.roomfinder.dYear.value;  
}

function setDepartDate()
{
document.roomfinder.departdate.value = document.roomfinder.dMonth2.value + "/" + document.roomfinder.dDay2.value  + "/" +  document.roomfinder.dYear2.value;  
}

function checkDate()
{
currentdate = new Date();
currenttime = Date.UTC(currentdate.getYear(),currentdate.getMonth(),currentdate.getDate(),0,0,0);
arrivaldate = Date.UTC(document.roomfinder.dYear.value,(document.roomfinder.dMonth.value-1),document.roomfinder.dDay.value,0,0,0);
departdate = Date.UTC(document.roomfinder.dYear2.value,(document.roomfinder.dMonth2.value-1),document.roomfinder.dDay2.value,0,0,0);
if (arrivaldate <= currenttime) 
	{
	alert("Arrival date cannot before today's date.");
	}
	else if (departdate <= arrivaldate)
		{
		alert("Depart Date must be after arrival date.");
		}
		else
			{
			roomfinder.submit();
			}
}

function add_favorite(){
	var is_4up = parseInt(navigator.appVersion);
	var is_mac   = navigator.userAgent.toLowerCase().indexOf("mac")!=-1;
	var is_ie   = navigator.userAgent.toLowerCase().indexOf("msie")!=-1;
	var thePage = location.href;
	if (thePage.lastIndexOf('#')!=-1)
		thePage = thePage.substring(0,thePage.lastIndexOf('#'));
	if (is_ie && is_4up && !is_mac) 
		window.external.AddFavorite(thePage,document.title);
	else if (is_ie || document.images)
		booker_hp = window.open(thePage,'booker_','menubar,width=325,height=100,left=140,top=60');
	//booker_hp.focus();
	}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; ia.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*
////////////////////////////////
//  Generic linked date boxes //
////////////////////////////////

*****************************************
*   Another fine mess by Torsten Mauz   *
*****************************************

*/

//Declare date arrays
var arrYears = new Array();
var arrMonths = new Array();
var arrDays = new Array();

//the object which represents our date boxes
function dateObj(dObj, mObj, yObj)
{
	this.dayObj = dObj;
	this.dayObj.parent = this;
	this.monthObj = mObj;
	this.monthObj.parent = this;
	this.monthObj.onchange = populateDays;
	this.yearObj = yObj;
	this.yearObj.parent = this;
	this.yearObj.onchange = populateDays;
	this.dayObj.onchange = updateSelDay;
	this.selDay;
}

//main initialisation routine
function initDates(yFrom, yTo, selectedYear, selectedMonth, selectedDay, dateObject)
{
	initYears(yFrom, yTo);
	initMonths();
	initDays();
	dateObject.selDay = selectedDay;
	populateYears(arrYears, selectedYear, dateObject);
	populateMonths(arrMonths, selectedMonth, dateObject);
	populateDays(selectedDay, dateObject);
}

//setup the years array
function initYears(yFrom, yTo)
{	
	var IDX = 0;
	
	for(var i = yFrom; i < (yTo+1); i++, IDX++)
	{
		arrYears[IDX] = i;
	}
}

//setup the months array
function initMonths()
{
	arrMonths[0] = 'January';
	arrMonths[1] = 'Febuary';
	arrMonths[2] = 'March';
	arrMonths[3] = 'April';
	arrMonths[4] = 'May';
	arrMonths[5] = 'June';
	arrMonths[6] = 'July';
	arrMonths[7] = 'August';
	arrMonths[8] = 'September';
	arrMonths[9] = 'October';
	arrMonths[10] = 'November';
	arrMonths[11] = 'December';
}

//setup the days array
function initDays()
{
	arrDays[0] = 31;
	arrDays[1] = 28;
	arrDays[2] = 31;
	arrDays[3] = 30;
	arrDays[4] = 31;
	arrDays[5] = 30;
	arrDays[6] = 31;
	arrDays[7] = 31;
	arrDays[8] = 30;
	arrDays[9] = 31;
	arrDays[10] = 30;
	arrDays[11] = 31;
}

//render the years dropdown
function populateYears(arrIn, selYear, dObj)
{
	dObj.yearObj.options.length = 0;
	
	for(var i = 0; i < arrIn.length; i++)
	{
		dObj.yearObj.options.length += 1;
		dObj.yearObj.options[i].value = arrYears[i];
		dObj.yearObj.options[i].text = arrYears[i];
		if(arrYears[i] == selYear)
		{
			dObj.yearObj.options[i].selected = true;
		}
	}
}

//render the months dropdown
function populateMonths(arrIn, selMonth, dObj)
{
	dObj.monthObj.options.length = 0;
	
	for(var i = 0; i < arrIn.length; i++)
	{
		dObj.monthObj.options.length += 1;
		dObj.monthObj.options[i].value = (i+1);
		dObj.monthObj.options[i].text = arrMonths[i];
		if(i == selMonth - 1)
		{
			dObj.monthObj.options[i].selected = true;
		}
	}
}

//render the days dropdown
function populateDays(selDay, dObj)
{
	//if the calling object is a property of a date object then
	//get the parent date object
	if(dObj == null)
	{
		dObj = this.parent;
	}
	
	var month = dObj.monthObj.selectedIndex;
	var days = arrDays[month];
	
	//if the selected day is nothing then retrieve from object
	if(selDay == null)
	{
		selDay = dObj.selDay;
		
		//if selected day is larger then number of days
		//in new months the set it to the last day of the month
		if(selDay > days)
		{
			selDay = days;
			dObj.selDay = selDay;
		}
	}
	
	//reset the day list
	dObj.dayObj.options.length = 0;
	
	//check to see if we are dealing with febuary
	if(month == 1)
	{
		//if the year divided by 4 does not contain a decimal place then it is a leapyear
		if((dObj.yearObj.options[dObj.yearObj.selectedIndex].value / 4).toString().indexOf('.') == -1)
		{
			days = arrDays[month] + 1;
		}
	}

	//loop through the days for each month
	for(var i = 1; i < days + 1; i++)
	{
		dObj.dayObj.options.length += 1;
		dObj.dayObj.options[i-1].value = i;
		dObj.dayObj.options[i-1].text = i;
		if(i == selDay)
		{
			dObj.dayObj.options[i-1].selected = true;
		}
	}
}

//update the currently selected day
function updateSelDay(dObj)
{
	if(dObj == null)
	{
		dObj = this.parent;
	}
	dObj.selDay = dObj.dayObj.selectedIndex + 1;
}
