/*
 *  MindShareHDV, LLC
 *
 *  The following is the property of MindShareHDV, LLC.
 *  Copyright reserved June 2008
 *
 *
 *  FileName: reservation.js
 *  Handles reservation creation and renter validatoin
 */
function validRenter 
(
    reservationForm
)
{
    firstName = reservationForm.form.firstName.value;
    lastName = reservationForm.form.lastName.value;
    address1 = reservationForm.form.address1.value;
    city = reservationForm.form.city.value;
    state = reservationForm.form.state.value;
    postalCode = reservationForm.form.postalCode.value;
    country = reservationForm.form.country.value;
    email = reservationForm.form.email.value;
    phone = reservationForm.form.phone.value;
                 
    passed = true;
    message = "";
    if (firstName == "")
    {
        message += "<li>Please enter your first name.</li>";
        passed = false;
    }
    if (lastName == "")
    {
        message += "<li>Please enter your last name.</li>";
        passed = false;
    }
    if (address1 == "")
    {
        message += "<li>Please enter your address.</li>";
        passed = false;
    }
    if (city == "")
    {
        message += "<li>Please enter your city.</li>";
        passed = false;
    }
    if (state == "")
    {
        message += "<li>Please enter your state.</li>";
        passed = false;
    }
    if (postalCode == "")
    {
        message += "<li>Please enter your zip code.</li>";
        passed = false;
    }
    if (country == "")
    {
        message += "<li>Please enter your country.</li>";
        passed = false;
    }
    if (email == "")
    {
        message += "<li>Please enter your email address.</li>";
        passed = false;
    }
    if (phone == "")
    {
        message += "<li>Please enter your phone number.</li>";
        passed = false;
    }

    reservationForm.form.errMsg.value = message;

    return passed;
}
function makeReservation 
(
    reservationForm, 
    email
)
{
	
	selectedCheckinMonthYear = reservationForm.form.checkinMonthYear[reservationForm.form.checkinMonthYear.selectedIndex].value;
	selectedCheckinDay = reservationForm.form.checkinDay[reservationForm.form.checkinDay.selectedIndex].value;
	selectedCheckoutMonthYear = reservationForm.form.checkoutMonthYear[reservationForm.form.checkoutMonthYear.selectedIndex].value; 
	selectedCheckoutDay = reservationForm.form.checkoutDay[reservationForm.form.checkoutDay.selectedIndex].value;

	if (selectedCheckinMonthYear != -1 &&
		selectedCheckinDay != -1 &&
		selectedCheckoutMonthYear != -1 &&
		selectedCheckoutDay != -1)
	{
		var monthYear = selectedCheckinMonthYear.split("/");
		var month = monthYear[0];
		var year = monthYear[1];  
		selectedCheckin = month + "/" + selectedCheckinDay + "/" + year;

		var checkinYear = year;
		var checkinMonth = month;
		var checkinDate = new Date(checkinYear, checkinMonth - 1, selectedCheckinDay)
		
		var monthYear = selectedCheckoutMonthYear.split("/");
		var month = monthYear[0];
		var year = monthYear[1];  
		selectedCheckout = month + "/" + selectedCheckoutDay + "/" + year;
		
		var checkoutYear = year;
		var checkoutMonth = month;
		var checkoutDate = new Date(checkoutYear, checkoutMonth - 1, selectedCheckoutDay);


		checkinDateSecond = checkinDate.getTime();

		checkoutDateSecond = checkoutDate.getTime();

		deltaSeconds = checkoutDateSecond - checkinDateSecond;
		deltaDays = Math.round(deltaSeconds / 60 /60 / 24 / 1000);	
	
		if (checkoutYear < checkinYear)
		{
			alert("Check-in date can not be equal or greater than check-out date. Please select appropriate values");
		}
		else if (checkinYear == checkoutYear && checkinMonth > checkoutMonth)
		{
			alert("Check-in date can not be equal or greater than check-out date. Please select appropriate values");
		}
		else if (checkinYear == checkoutYear && checkinMonth == checkoutMonth && selectedCheckoutDay <= selectedCheckinDay)
		{
			alert("Check-in date can not be equal or greater than check-out date. Please select appropriate values");
		}
		else if (deltaDays < 7)
		{
			alert("Your reservation is less than 7 days. Please contact " + email); 
		}
		else
		{
            validRenter(reservationForm);
			reservationForm.form.selectedCheckin.value = selectedCheckin;
			reservationForm.form.selectedCheckout.value = selectedCheckout;
	  
			reservationForm.form.submit();
		}
	}
	else
	{
		alert ("Must select the checkin and checkout dates");
	}
}

function reservationIsTaken
(
)
{
	alert ("These dates are reserved. Please choose another start and end dates for this unit or you can select other units that are available for your travel dates.");
}

function noRateIsAvailable
(
)
{
	alert ("No Rate is available for this unit for the date selected.");
}