// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// File:					calculate-deposit.js
// Created by:			Robert Lim
// Date Created:		12/09/2008
// Last Modified:		28/01/2009
//
// Purpose:
// This javascript page calculates the deposit price for the Snips And Snoozes Online booking form 
//
// Functions:
// getDays				-- returns the amount of days the pet will be staying
// calculatePetPrice -- returns the total sigular pet cost
// getTaxiPrice		-- returns the taxi service cost
// getHeatingPrice	-- returns the winter heating cost
// bPackageType		-- returns whether any of the packages Gold or Silver (used for heating price)
// calculateDeposit	-- calculates and displays the deposit amount and the options chosen
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


function getDays()
{
	var checkinTemp = document.Bookings._5_StayFromDate.value;									//get the checkin date
	var checkoutTemp = document.Bookings._6_StayToDate.value;								//get the checkout date
	v_split = checkinTemp.indexOf("/");
   v_split2 = checkinTemp.indexOf("/", v_split + 1);
	var days = 1;																								//initial day value

	//make sure the dates are valid
	if (IsValidDate(checkinTemp) && IsValidDate(checkoutTemp)) {
		//split the checkin date
		var checkinTempDD = checkinTemp.substring(0, checkinTemp.indexOf("/"));
		var checkinTempMM = checkinTemp.substring(v_split + 1, v_split2)-1;					// minus 1 to suit javascript dates (0-11 not 1-12)
		var checkinTempYYYY = checkinTemp.substring(v_split2 + 1, checkinTemp.length);
		//split the cehckout date
		var checkoutTempDD = checkoutTemp.substring(0, checkoutTemp.indexOf("/"));
		var checkoutTempMM = checkoutTemp.substring(v_split + 1, v_split2)-1;				// minus 1 to suit javascript dates (0-11 not 1-12)
		var checkoutTempYYYY = checkoutTemp.substring(v_split2 + 1, checkoutTemp.length);

		var checkinDate = new Date(checkinTempYYYY, checkinTempMM, checkinTempDD);			//set the checkin date
		var checkoutDate = new Date(checkoutTempYYYY, checkoutTempMM, checkoutTempDD);	//set the checkout date
		var one_day=1000*60*60*24;																			//Set 1 day in milliseconds
																					
		days = Math.ceil((checkoutDate.getTime()-checkinDate.getTime())/(one_day)) + 1;

		if (days <= 0)
		{
			days = 1;
		}
	}

	return days;
}



function calculateDeposit ()
{							
	var days = getDays();						//retrieve the number of days planning to stay
	var nights = days - 1;

	//show the user the total days booked
	$("input#Days_Staying").val(nights + ' night(s)');


}

