﻿var activeElement;
function setNewDate(theDateStr)
{
//	departure_date
	document.getElementById(activeElement).value		= theDateStr;
	document.getElementById("calendar").style.display	= "none";
	try
	{
		eval(evalOnDateChange);
		
	}catch(e){}
	document.getElementById(activeElement).focus();
	//Check();
}
	
function showCalendar(theActiveDateBox)
{
	activeElement	= theActiveDateBox;
	var my_datebox	= document.getElementById(theActiveDateBox);
	var my_calendar = document.getElementById("calendar");	
	try
	{
		if (calPassedDate)
			my_calendar.setAttribute("src","Calendar.aspx?pd=true");			
	}
	catch(e){}

	if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
		my_calendar.style.top		= mY +10;
	else
		my_calendar.style.top		= window.document.body.scrollTop +  window.event.clientY +10;
	my_calendar.style.left		= mX - 10;
	my_calendar.style.position	= "absolute";
	my_calendar.style.display	= "block";
}

	//var CheckOutDT_Id='ctl00_ctl02_ctl00_txtCheckOut';  	
	var CheckOutDT_Id=''; 
	var evalOnDateChange = "SetNumberOfNights()";
	function SetNumberOfNights()
	{
		//alert("Check-out date cannot be before check-in date.");
		checkInDate = document.getElementById('txtArrivalDate').value;
		//alert("Check-in date" + checkInDate);
		checkOutDate = document.getElementById('ctl00_ctl02_ctl00_txtCheckOut').value;
		//alert("Check-out date" + checkOutDate);
		dateDiff(checkInDate,checkOutDate);
	}	
	function dateDiff(firstdate,seconddate){

	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
	//alert("0");

	if (isValidDate(firstdate)) { // Validates first date 
	date1temp = new Date(firstdate + " " + "00:00:00 AM");
	date1.setTime(date1temp.getTime());
	//alert("1");
	}
	else return false; // otherwise exits

	if (isValidDate(seconddate)) { // Validates second date 
	date2temp = new Date(seconddate + " " + "00:00:00 AM");
	date2.setTime(date2temp.getTime());
	//alert("2");
	}
	else return false; // otherwise exits

	// sets difference date to difference of first date and second date
	objNights = document.getElementById('ctl00_ctl02_ctl00_lblNights');
	if((date2.getTime() - date1.getTime())==0)
	{
			objNights.firstChild.nodeValue = 1;
		return;
	}
	else if((date2.getTime() - date1.getTime())<0)
	{
		return;
	}

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff = days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;
	//alert("4");

	objNights.firstChild.nodeValue = (parseInt(weeks)*7) + parseInt(days);
	//alert(objNights.firstChild.nodeValue);
}


