var frozen = true;
var rangeset = false;
var statusMSG = "Click To Set Check-In Date";




function gomonth ( PropertyID ) {
	// FORM JUMP TO
	var chmonth = document.RentalInfo.checkin_month.value;
	var chday    = document.RentalInfo.checkin_day.value;
	var chyear   = document.RentalInfo.checkin_year.value;
	
	var gomonth   = document.GoTo.month.value;
	var goyear      = document.GoTo.year.value;
	
	window.location='../Rentals/Rental_View.asp?PropertyID=' + PropertyID + '&month=' + gomonth + '&year=' + goyear + '&chmonth=' + chmonth + '&chday=' + chday + '&chyear=' + chyear + '#calstop';
}

function gomonth2 ( PropertyID, PartnerID, month, year ) {
	// NEXT MONTH IMAGE
	var chmonth = document.RentalInfo.checkin_month.value;
	var chday    = document.RentalInfo.checkin_day.value;
	var chyear   = document.RentalInfo.checkin_year.value;
	
	window.location='../iFrame-wide/calendar.asp?iFrame=true&PropertyID=' + PropertyID + '&Partner=' + PartnerID + '&month=' + month + '&year=' + year + '&chmonth=' + chmonth + '&chday=' + chday + '&chyear=' + chyear + '#calstop';
}


function goreserve ( PropertyID, PartnerID ) {

	var cimonth = document.RentalInfo.checkin_month.value;
	var ciday    = document.RentalInfo.checkin_day.value;
	var ciyear   = document.RentalInfo.checkin_year.value;

	var comonth = document.RentalInfo.checkout_month.value;
	var coday    = document.RentalInfo.checkout_day.value;
	var coyear   = document.RentalInfo.checkout_year.value;
	
	if ( !cimonth ) {
		alert('Check-In month has not been selected. Please click an available start date on the calendar, or use the pull down menu to pick your dates'); 
	} else if ( !ciday ) {
		alert('Check-In day has not been selected. Please click an available start date on the calendar, or use the pull down menu to pick your dates'); 
	} else if ( !ciyear ) {
		alert('Check-In year has not been selected. Please click an available start date on the calendar, or use the pull down menu to pick your dates'); 
	} else if ( !comonth ) {
		alert('Check-Out month has not been selected. Please click an available start date on the calendar, or use the pull down menu to pick your dates'); 
	} else if ( !coday ) {
		alert('Check-Out day has not been selected. Please click an available start date on the calendar, or use the pull down menu to pick your dates'); 
	} else if ( !coyear ) {
		alert('Check-Out year has not been selected. Please click an available start date on the calendar, or use the pull down menu to pick your dates'); 
	} else {

		var CheckInDate = "In-" + document.RentalInfo.checkin_month.value + "/" + document.RentalInfo.checkin_day.value + "/" + document.RentalInfo.checkin_year.value + "-";
		var CheckOutDate = "Out-" + document.RentalInfo.checkout_month.value + "/" + document.RentalInfo.checkout_day.value + "/" + document.RentalInfo.checkout_year.value + "-";
		window.open('https://www.ivacationonline.com/Rentals/Rental_Reservation.asp?iFrame=true&PropertyID=' + PropertyID + '&Partner=' + PartnerID + '&CheckInDate=' + CheckInDate + '&CheckOutDate=' + CheckOutDate);
	
	}
}



function leasetype () {
	document.RentalInfo.LeaseType.value = "Daily Rental";
}

function freezer() {
	if ( frozen == false ) { frozen = true; } else { frozen = false; }
}

function startbooking(RentalID, LeaseType, WeeklyDay) {
	freezer();
	
	splitString = RentalID.split("/")
	
	// alert ( RentalID + ' - ' + splitString[0] + ' ' + splitString[1] + ' ' + splitString[2] + ' ' + WeeklyDay ) ;
	


	if ( frozen == true ) {
		
		// alert('true ' + splitString[0] + ' - ' + splitString[1] + ' - ' + splitString[2] );
		
		document.RentalInfo.checkout_month.value = splitString[0];
		document.RentalInfo.checkout_day.value = splitString[1];
		document.RentalInfo.checkout_year.value = splitString[2];
		
		// statusMSG = "Next Click Check-Out Date";
		// alert( statusMSG );
		// document.RentalInfo.Status.value = "Next Click Check-Out Date";
		
		// Rate = parseFloat(Rate);
		// Security = parseFloat(Security);
		// TaxTotal = parseFloat(TaxTotal);
		
		// document.RentalInfo.Rate.value = '$ ' + Rate.toFixed(2);
		// document.RentalInfo.Security.value = '$ ' + Security.toFixed(2);
		
		// document.RentalInfo.StartDate.value = StartDate;
		
		
		
	 } else {
		
		// alert('false ' + splitString[0] + ' - ' + splitString[1] + ' - ' + splitString[2] );
		
		var CheckInDate = document.RentalInfo.StartDate.value;
		var CheckOutDate = document.RentalInfo.EndDate.value;
		
		document.RentalInfo.checkin_month.value = splitString[0];
		document.RentalInfo.checkin_day.value = splitString[1];
		document.RentalInfo.checkin_year.value = splitString[2];
		
		//alert( document.RentalInfo.StartDate.value + ' ' + document.RentalInfo.EndDate.value ) ;
		
		//window.location='../Rentals/Rental_Daily.asp?RentalID=' + RentalID + '&LeaseType=' + LeaseType + '&CheckInDate=' + CheckInDate + '&CheckOutDate=' + CheckOutDate;
	 	
	}
	
}





function DisplayRates(StartDate, CheckInTime, EndDate, CheckOutTime, WeeklyDay, LeaseType, Rate, Security, TaxRate1, TaxRate2, TaxTotal ){
	
		var CheckInDate = WeeklyDay + '-' + StartDate + '-' + CheckInTime;
		var CheckOutDate = WeeklyDay + '-' + StartDate + '-' + CheckOutTime;
		var RentSubtotal = ( parseFloat(Rate) + parseFloat(Security) );
		var TheTotal = ( parseFloat(RentSubtotal) + parseFloat(TaxTotal) );
		
		Rate = parseFloat(Rate);
		Security = parseFloat(Security);
		TaxTotal = parseFloat(TaxTotal);
		
		document.RentalInfo.Rate.value = '$ ' + Rate.toFixed(2) + ' (per night)';
		document.RentalInfo.Security.value = '$ ' + Security.toFixed(2) + ' (per visit)';
		document.RentalInfo.Status.value = "Click Check-In Date";
}


function ReservedRates(message, StartDate, CheckInTime, EndDate, CheckOutTime, WeeklyDay, LeaseType, Rate, Security, TaxRate1, TaxRate2, TaxTotal ){
	
		var CheckInDate = WeeklyDay + '-' + StartDate + '-' + CheckInTime;
		var CheckOutDate = WeeklyDay + '-' + StartDate + '-' + CheckOutTime;
		var RentSubtotal = ( parseFloat(Rate) + parseFloat(Security) );
		var TheTotal = ( parseFloat(RentSubtotal) + parseFloat(TaxTotal) );
		
		Rate = parseFloat(Rate);
		Security = parseFloat(Security);
		TaxTotal = parseFloat(TaxTotal);
		
		document.RentalInfo.Rate.value = ' (RESERVED)';
		document.RentalInfo.Security.value = ' ';
		document.RentalInfo.Status.value = "Click Check-In Date";
}





function clearRates(){
	
	if ( rangeset == false ) {
	
		//if ( frozen == false ) {
		
			//document.RentalInfo.LeaseType.value = "";
			document.RentalInfo.Rate.value = "";
			document.RentalInfo.Security.value = "";
			document.RentalInfo.Status.value = "";
			document.RentalInfo.StartDate.value = "";
		//}
		
		document.RentalInfo.EndDate.value = "";
		document.RentalInfo.RentSubtotal.value = "";
		document.RentalInfo.TaxTotal.value = "";
		document.RentalInfo.Total.value = "";
		
	}
}


function myRound(field) {
	sm = "" + ((Math.round(field.value * 100)) / 100);
	dec1 = sm.substring(sm.length-3, sm.length-2);
	dec2 = sm.substring(sm.length-2, sm.length-1);
	
	if (dec1 != '.') { // adds trailing zeroes if necessary
		if (dec2 == '.')
		sm += "0";
	else
		sm += ".00";
	}
	field.value = sm;
}


function Reserved(message){

	if ( frozen == false ) {
		if ( message == "Checkout-Only" ) {
			document.RentalInfo.Status.value = "Checkout-Only";
		} else {
			document.RentalInfo.Status.value = "Reserved";
		}
		
		// document.RentalInfo.Status.value = message;
		document.RentalInfo.StartDate.value = "";
		document.RentalInfo.EndDate.value = "";
		
		//document.RentalInfo.LeaseType.value = "";
		document.RentalInfo.Rate.value = "";
		document.RentalInfo.Security.value = "";
		document.RentalInfo.RentSubtotal.value = "";
		document.RentalInfo.TaxTotal.value = "";
		document.RentalInfo.TaxTotal.value = "";
		document.RentalInfo.Total.value = "";
	}
}

		//var TheTotal = ( parseFloat(RentSubtotal) + parseFloat(TaxTotal) );
		//document.RentalInfo.Total.value = '$ ' + TheTotal.toFixed(2);

