﻿//Script library to do rate calculations - Include Post ASC Corrections

//--------------------New Function date_loop()-------------------------------
function date_loop(package_type_flag) {
// this function looks at the input data
// stored in the room type, total nights, and date fields
// and formats output into a text area called test results
// Input is package_type_flag where 
//  0 == no package
//  1 == ski package
//  2 == golf package

//create variables

calculated_date = new Date();
var total_nights = parseInt(document.Rate_Form.number_of_nights.options[document.Rate_Form.number_of_nights.selectedIndex].value);
var room_type = document.Rate_Form.room_number.options[document.Rate_Form.room_number.selectedIndex].value;
var room_txt = document.Rate_Form.room_number.options[document.Rate_Form.room_number.selectedIndex].text;
var cumulative_room_rate = 0;
var txtresults = "Nightly Rate" + "    " + "Date" + "\r";

//eliminate gratuity charges starting May 2011
var old_gratuity = .15;
var gratuity_year_change = 2011;
// remember that month is in date format with is actual month minus 1
var gratuity_month_change = 4;
var gratuity = 0;

// change tax rate to include Killington local option tax starting October 2008
var room_tax = .10;
var old_room_tax = .09;
var tax_year_change = 2008;
// remember that month is in date format with is actual month minus 1
var tax_month_change = 9;
var tax_grat = 0;

var special_offer = 0;
var test_special_offer_flag = 0;
var special_offer_txt = "This quote contains a special promotional discount for" + "\r" +"internet visitors to birchridge.com." + "\r" + "\r" + "It applies only to the specific room for the dates selected" + "\r" + "for reservations made directly with inn via telephone, " + "\r" + "or via through birchridge.com" + "\r" + "\r"+ "If you make your reservation online, please mention this discount" + "\r" + "in the Comment Box on the reservation form."  + "\r" + "\r"+ "If you make your reservation by calling the inn directly,"+ "\r" +"please mention this discount to the innkeeper who makes your reservation." + "\r" + "\r" + "This discount can only be honored at the time you book your reservation" + "\r" + "and may not be combined with other promotions."; 
var special_offer_disclaimer = "";
var special_offer_cancel = 0;
var invalid_data_entry_warning = "";
var invalid_data_entry_warning_flag = 0;

var ski_package_room_discount = 0;
var test_ski_package_date_flag =0;
var ski_package_message_flag = 0;
var ski_package_message_txt = "The special Ski and Stay discount is applicable only if" + "\r" + "you book a ski package and room together at the same time. " + "\r" + "\r" + "If you make your reservation online, please indentify the" + "\r" + "ski package you would like in the Comment Box on the reservation form." + "\r" + "\r" + "If you make your reservation by calling the inn directly,"+ "\r" +"please mention this discount to the innkeeper who takes your reservation." + "\r" + "\r" + "This discount can only be honored at the time you book" + "\r" + "your reservation and may not be combined with other promotions.";
var ski_package_message_header_txt = "The Total Quote calculated for the package you selected includes a special Ski and Stay discount. ";
var room_rate_undefined = 0;
var grandtotaltxt = "";

// Guest 1 variables used for packages
var guest1packagelength = 0;
var guest1packagerate = 0;
var guest1year = 0;
var guest1month = 0;
var guest1day_of_month = 0;
var guest1packagetype = 0;
var guest1packagetype_txt = 0;
var guest1packagestartdate = new Date();
var guest1packageenddate = new Date();
var guest1packageprinttxt = 0;

// Guest 2 variables used for packages
var guest2packagelength = 0;
var guest2packagerate = 0;
var guest2year = 0;
var guest2month = 0;
var guest2day_of_month = 0;
var guest2packagetype = 0;
var guest2packagetype_txt = 0;
var guest2packagestartdate = new Date();
var guest2packageenddate = new Date();
var guest2packageprinttxt = 0;

//set up Ski package start and end dates
var skipackagestart = new Date();
var skipackageend = new Date();

//set up golf package default text
var golfdetailtxt = "";
var golfbasictxt = "";
var golftotalprice = 0;

// set print out format flag...
// 0 equals detailed output
// 1 equals summary custtomer output
var print_out_style_flag = 1;
//if(document.Rate_Form.result_box.value == "detail")
if(document.getElementById("results_box").value == "detail")
	{print_out_style_flag = 0;
	}
//if(document.Rate_Form.result_box.value == "no detail")
if(document.getElementById("results_box").value == "no detail")
	{print_out_style_flag = 1;
	}
	
// initialize offer image area
//document.special_offer_image.src = "no_offer.jpg";
document.getElementById('special_offer_image').src = "no_offer.jpg";
//Read Date Info

// This function reads the arrival date from the rate form and performs a validity checks.
// It returns the a requested resultin an array delimited by ","
//  Element		Arry positon		Retun Value
//	"Year"			0				Arrival Pulldown, Year Value
//  "Month"			1				Arrival Pulldown, Month Value
//  "Day"			2				Arrival Pulldown, Day Value
//  "warning"		3				Null or Text with warning.  also generates an alert
//  "detail"		4				Null or Text with warning.  also generates and alert

var arrival_date_array = new Array(5);
arrival_date_array = read_arrival_date().split(",");
var year = arrival_date_array[0];
var month = arrival_date_array[1];
var day_of_month = arrival_date_array[2];

// validate that the arrival date is a valid date
invalid_data_entry_warning = arrival_date_array[3];
if(invalid_data_entry_warning != "") 
		{invalid_data_entry_warning_flag = 1;
		alert(invalid_data_entry_warning);
		}
// validate that arrival date is >= current date
// only check if not looking for detail information

if(print_out_style_flag ==1)
{
if(arrival_date_array[4] != "") 
		{invalid_data_entry_warning = arrival_date_array[4];
		invalid_data_entry_warning_flag = 1;
		alert(invalid_data_entry_warning);
		}
}

// now code in the changes for gratuities
var gratuity_arrival_date = new Date();
gratuity_arrival_date = getDateinfo(year,month,day_of_month,0);
if(gratuity_arrival_date.getFullYear() < (gratuity_year_change + 1))
	{if( gratuity_arrival_date.getMonth() < gratuity_month_change)
		{gratuity = old_gratuity;
		}
	}


// now code in the changes for tax
var tax_departure_date = new Date();
tax_departure_date = getDateinfo(year,month,day_of_month,total_nights);
if(tax_departure_date.getFullYear() < (tax_year_change + 1))
	{if( tax_departure_date.getMonth() < tax_month_change)
		{room_tax = old_room_tax;
		}
	}

if(package_type_flag == 1)
// -----------------------------code to set up ski packages  Validates Ski Package Dates----------------------------
{

//Read Ski Package Info Guest 1
guest1year =document.Rate_Form.guest1_ski_package_start_year.options[document.Rate_Form.guest1_ski_package_start_year.selectedIndex].value;
guest1month=document.Rate_Form.guest1_ski_package_start_month.options[document.Rate_Form.guest1_ski_package_start_month.selectedIndex].value;
guest1day_of_month=document.Rate_Form.guest1_ski_package_start_day.options[document.Rate_Form.guest1_ski_package_start_day.selectedIndex].value;
guest1packagelength=document.Rate_Form.guest1_ski_package_day_num.options[document.Rate_Form.guest1_ski_package_day_num.selectedIndex].value;
guest1packagetype=document.Rate_Form.guest1_ski_package_type.options[document.Rate_Form.guest1_ski_package_type.selectedIndex].value;
guest1packagetype_txt=document.Rate_Form.guest1_ski_package_type.options[document.Rate_Form.guest1_ski_package_type.selectedIndex].text;

guest1packagestartdate = getDateinfo(guest1year,guest1month,guest1day_of_month,0);
guest1packageenddate = getDateinfo(guest1year,guest1month,guest1day_of_month,guest1packagelength);
guest1packageprinttxt = "Ski Package Information for Guest 1" + "\r" +
						"Ski Package Type" + "      " + guest1packagetype_txt + "\r" +
						"Total Days Skiing" + "     " + guest1packagelength + "\r" +
						"First Day of Skiing" + "   " + date_to_string(getDateinfo(guest1year,guest1month,guest1day_of_month,0)) + "\r";

//  If ski package is selected for guest 1, validate room stay dates
if(guest1packagelength > 0)
{test_ski_package_date_flag = guest1packagestartdate - getDateinfo(year,month,day_of_month,0);

	if(test_ski_package_date_flag < 0)
		{invalid_data_entry_warning_flag = 1;
		invalid_data_entry_warning = "\r" + "Guest 1 Ski Package Date invalid.  Ski Package Start Date before Arrival Date";
		alert("Guest 1 Ski Package Date invalid. Ski Package start Date before Arrival Date");
		}
	else if(getDateinfo(guest1year,guest1month,guest1day_of_month,guest1packagelength) > getDateinfo(year,month,day_of_month,total_nights+1)) // total nights converted to millisecond days
		{invalid_data_entry_warning_flag = 1;
		invalid_data_entry_warning = "\r" + "Guest 1 Ski Package Date invalid.  Last day of skiing after Departure from Inn.  Number of days Guest 1 is skiing is too large, or Ski Package Start Date is incorrect.";
		alert("Guest 1 Ski Package Date invalid.  Last day of skiing after Departure from Inn.  Number of days Guest 1 is skiing is too large, or Ski Package Start Date is incorrect.");
		}
//Now set up first and last day ski package dates...
	if(invalid_data_entry_warning_flag == 0)
		{skipackagestart = guest1packagestartdate;
		skipackageend = guest1packageenddate;
		}
}

//Read Ski Package Info Guest 2
guest2year =document.Rate_Form.guest2_ski_package_start_year.options[document.Rate_Form.guest2_ski_package_start_year.selectedIndex].value;
guest2month=document.Rate_Form.guest2_ski_package_start_month.options[document.Rate_Form.guest2_ski_package_start_month.selectedIndex].value;
guest2day_of_month=document.Rate_Form.guest2_ski_package_start_day.options[document.Rate_Form.guest2_ski_package_start_day.selectedIndex].value;
guest2packagelength=document.Rate_Form.guest2_ski_package_day_num.options[document.Rate_Form.guest2_ski_package_day_num.selectedIndex].value;
guest2packagetype=document.Rate_Form.guest2_ski_package_type.options[document.Rate_Form.guest2_ski_package_type.selectedIndex].value;
guest2packagetype_txt=document.Rate_Form.guest2_ski_package_type.options[document.Rate_Form.guest2_ski_package_type.selectedIndex].text;

guest2packagestartdate = getDateinfo(guest2year,guest2month,guest2day_of_month,0);
guest2packageenddate = getDateinfo(guest2year,guest2month,guest2day_of_month,guest2packagelength);
guest2packageprinttxt = "Ski Package Information for Guest 2" + "\r" +
						"Ski Package Type" + "      " + guest2packagetype_txt + "\r" +
						"Total Days Skiing" + "     " + guest2packagelength + "\r" +
						"First Day of Skiing" + "   " + date_to_string(getDateinfo(guest2year,guest2month,guest2day_of_month,0)) + "\r";


//  If ski package is selected for guest 2, validate room stay dates
if(guest2packagelength > 0)

{test_ski_package_date_flag = guest2packagestartdate - getDateinfo(year,month,day_of_month,0);

	if(test_ski_package_date_flag < 0)
		{invalid_data_entry_warning_flag = 1;
		invalid_data_entry_warning = "\r" + "Guest 2 Ski Package Date invalid.  Ski Package start Date before Arrival Date";
		alert("Guest 2 Ski Package Date invalid.  Ski Package start Date before Arrival Date");
		}
	else if(getDateinfo(guest2year,guest2month,guest2day_of_month,guest2packagelength) > getDateinfo(year,month,day_of_month,total_nights+1)) // total nights converted to millisecond days
		{invalid_data_entry_warning_flag = 1;
		invalid_data_entry_warning = "\r" + "Guest 2 Ski Package Date invalid.  Last day of skiing after Departure from Inn.  Number of days Guest 2 is skiing is too large, or Ski Package Start Date is incorrect.";
		alert("Guest 2 Ski Package Date invalid.  Last day of skiing after Departure from Inn.  Number of days Guest 2 is skiing is too large, or Ski Package Start Date is incorrect.");
		}
//Now set up first and last day ski package dates...
	if(invalid_data_entry_warning_flag == 0)
		{if(skipackagestart == 0)
			{skipackagestart = guest2packagestartdate;
			}
		if(guest2packagestartdate < skipackagestart)
			{skipackagestart = guest2packagestartdate;
			}
		if(skipackageend == 0)
			{skipackageend = guest2packageenddate;
			}
		if(guest2packageenddate > skipackageend)
			{skipackageend = guest2packageenddate;
			}
		}
}
}
//  -------------------end of code to set up ski packages ----------------------------

if(package_type_flag == 2)
// -----------------------------code to set up golf packages ----------------------------
{
// read briteetimes cookie to get key parameters
// first see if tee time cookie exists
if(read_cookie("briteetimes") == null){
// cookie is null which means that the browser is not accepting cookies
		invalid_data_entry_warning_flag = 1;
		invalid_data_entry_warning = "\r" + "The security on your web browser is not configured to accept cookies. Please configure your web browser to accept cookies and then click on the Select Tee Times button.";
		alert("The security on your web browser is not configured to accept cookies. Please configure your web browser to accept cookies and then click on the Select Tee Times button.");  
		}
		
else {// teetime cookie exists, determine if tee times have been selected
//start by setting up tee time array
	var golfteetimeArray = new Array(54);
	golfteetimeArray= read_cookie("briteetimes").split(",");
	var total_tee_times = document.Rate_Form.number_of_tee_times.options[document.Rate_Form.number_of_tee_times.selectedIndex].value;

//test to see if element 0 is equal to 0.  If it is, and the number of tee times is greater than 0 then the select tee times button needs to be clicked.
	if(golfteetimeArray[0] == 0)
	{
// test to see if tee times have been selected.  if they have then show error.  If they have not, do nothing
	if(total_tee_times > 0) 
		{
		invalid_data_entry_warning_flag = 1;
		invalid_data_entry_warning = "\r" + "Click on Select Tee Time button to specify tee desired tee times.";
		alert("Click on Select Tee Time button to specify tee desired tee times.");  
		}
	}
	else {
// cookies work and tee time selector page has been called, process cookie
//Set element 0 in briteetimes to 2 and pass back to briteetimes cookie to prevent onfocus messageon rate calculator
golfteetimeArray[0] = 2;
// write cookie
write_cookie("briteetimes",golfteetimeArray.join(","));

// finally have all the tee time data to calculate tee times.
//golfteetime array set up as follows
// [0]  0, not ready for calculation, 1, ready for calculation , 2 calculation in process
//[1] = year (guest arrival year)
//[2] = month (guest arrival month)
//[3] = day_of_month (guest arrival day)
//[4] = total_nights (total nights stay)
//[5] = total_tee_times
//Tee time data is as follows
//tee_time_number*6] = tee_year;
//[(tee_time_number*6)+1] = tee_month;
//[(tee_time_number*6)+2] = tee_day;

//[(tee_time_number*6)+3] = tee_time;
// in the form
	// "Early Morning - before 9:00 AM"
	// "Mid Morning - 9:00 to 11:00 AM"
	//"Mid Day - 11:00 AM to 1:00 PM"
	//"Afternoon - 1:00 to 3:00 PM"

//[(tee_time_number*6)+4] = tee_people; (0, 1, or 2)

//[(tee_time_number*6)+5] = tee_course;
// in the form
	//"Green Mountain National Golf Course"
	//"Killington Resort Golf Course"

// create 2 output texts and one grand total amount 
// golfdetailtxt includes lists of tee times with prices for each time
// golfbasictxt includes just list ot tee times
// golftotalprice = total tee time price.

golfdetailtxt = "-------------------------------" + "\r" + "Golf Tee Time Information" + "\r";
golfbasictxt = golfdetailtxt;

var tee_date = new Date;
var tee_year = 0;
var tee_month = 0;
var tee_day = 0;
var tee_time = "";
var tee_people = 0;
var tee_course = "";
var tee_time_number = 0;

// now begin loop to procees tee times

total_tee_times = parseInt(golfteetimeArray[5]);

for (i = 0; i< total_tee_times; i++) {
//set up variables
var teetimetxt = "";
var teetimetxtdetail = "";
var teetimeprice = 0;
// read data from array

tee_time_number = i + 1;
teetimeprice = 0;

tee_year = golfteetimeArray[(tee_time_number*6)];
tee_month = golfteetimeArray[(tee_time_number*6)+1];
tee_day = golfteetimeArray[(tee_time_number*6)+2];
tee_time = golfteetimeArray[(tee_time_number*6)+3];
tee_people = golfteetimeArray[(tee_time_number*6)+4];
tee_course = golfteetimeArray[(tee_time_number*6)+5];

tee_date = getDateinfo(tee_year, tee_month, tee_day,0)

// now begin formatting output

teetimetxt = 	"Tee Time Number " + tee_time_number + " rates are available." + "\r" +
				"Rate includes greens fees plus golf cart." + "\r" +
				"Tee Time Date" + "         " + date_to_string(tee_date) + "\r" +     
				"Golf Course" + "           " + tee_course + "\r" +
				"Number of Players" + "     " + tee_people + "\r" +
				"Tee Time" + "              " + tee_time + "\r";
				
if(tee_people != 0) {

// now get the cost of the tee time.

switch (tee_course) {

case "Green Mountain National Golf Course" :
teetimeprice = priceGreenMountain(tee_date);
break;

case "Killington Resort Golf Course":
teetimeprice = priceKillingtonGolf(tee_date);
break;
}

}

if(teetimeprice == 0) { //tee time price is not defined.  add warning to teetimetext and continue
teetimetxt = "Tee Time Number " + tee_time_number + " rates are not available for the." + "\r" + 
			tee_course + " on " + date_to_string(tee_date) + ".\r" +
			"The total quote below is for the room plus tee times where rates are available(if any).\r"+
			"Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.\r";
teetimetxtdetail = teetimetxt;
}
else {if(tee_people == 0) {teetimetxt = teetimetxt +"No players have been selected for this tee time.   The cost of the tee time has not been included in the package calculation" + "\r";
					teetimetxtdetail = teetimetxt;}
if(tee_people != 0){teetimetxtdetail = teetimetxt +
			"Price per Player" + "     " + dollars(teetimeprice) + "\r" +
			"Total Tee Time Price" + " " + dollars(teetimeprice * tee_people) + "\r";}
  }
golftotalprice = golftotalprice + (teetimeprice*tee_people);
golfbasictxt = golfbasictxt + teetimetxt + "\r";
golfdetailtxt = golfdetailtxt + teetimetxtdetail + '\r';


// end for loop for total tee times //
}
//end else loop for valid tee time cookie//
}
//end eles loop confirming golf cookie's existance//
}
//end golf package process//
}

// -----------------------------end code to set up golf packages ----------------------------


//set up loop to look at date field

for (var i = 0; i < total_nights; i++) 

{calculated_date = getDateinfo(year,month,day_of_month,i);

	//determine if calculated_date is a weekend
	//weekend_offset = 0 for weekends
	//weekend_offset = 1 for weekdays
	// check if date is a weekend
	// for rooms, weekend start on Friday

weekend_offset = checkWeekend(calculated_date,0);

	//calculate variable to recover by computing room offset.
	//1=(queen_weekend)
	//2=(queen_weekday)
	//3=(king_weekend
	//4=(king_weekday)
	//5=(qwpl_weekend)
	//6=(qwpl_weekday)
	//7=(kwpl_weekend)
	//8=(kwpl_weekday)
	var room_offset = ((room_type * 2) - 1) + weekend_offset;

	//read array to determine room_rate
	var room_rate = room_rate_array(calculated_date,room_offset);
	
	//resd any special offer discounts
	special_offer = special_offer_array(calculated_date,room_type);
	
	// if there is a special offer, set the special offer flag for later print formatting, disclaimer, and image
	// if the special offer has not been overidden
	if(special_offer_cancel == 0){
	if(special_offer > 0)
		{
		test_special_offer_flag = 1;
		// Set up special offer disclaimer
		special_offer_disclaimer = special_offer_txt;
		// write about special offer in offer image area
		//document.special_offer_image.src="special_offer.jpg";
		document.getElementById('special_offer_image').src = "special_offer.jpg";
		}
	}
	// Test Room Rate... if 0 add special text
	if (room_rate == 0)  	{
	room_rate_undefined = 1;
							}

	// Output Rate Information
	else 			{
					if(package_type_flag == 1)
					
// -----------------------------start of code to compute daily room discounts for ski packages------------
						{
	// check to see if ski package was ordered
	// Compute Ski Package Room Discount
	//  First Check to see if package is ordered.  If it is apply room discount
							if(guest1packagelength + guest2packagelength == 0)    
							{ski_package_room_discount = 0;
	// now apply discount based upon date....						 
							}
							else
							// normalize skipackagestart - 1 day to account for Daylight Savings GMT time changes savings	
							{if(calculated_date >= getDateinfo(skipackagestart.getFullYear(),skipackagestart.getMonth(),skipackagestart.getDate(),-1))
						 		{ski_package_room_discount = ski_package_room_discount_calculator(getDateinfo(year,month,day_of_month,0), calculated_date,i,total_nights, room_type,  guest1packagelength, guest2packagelength, guest1packagestartdate, guest2packagestartdate);
									}
									// if discount, set up message flag to print out message later.
									if(ski_package_room_discount > 0) {
									ski_package_message_flag = 1;
									// now add message of a free day is given
									if(ski_package_room_discount == 1) {
									ski_package_message_header_txt = ski_package_message_header_txt + "  Your lodging for day " + (i+1) + " is free with this package.  ";
									// cancel any special offers with ski free packages
									special_offer_cancel = 1;
									test_special_offer_flag = 0;
									// Set up special offer disclaimer
									special_offer_disclaimer = "";
									// write about special offer in offer image area
									//document.special_offer_image.src = "no_offer.jpg";
									document.getElementById('special_offer_image').src = "no_offer.jpg"
									}
									}
								if(calculated_date >= skipackageend)
									{ski_package_room_discount = 0;
									}
						}
					}
// -----------------------------end of code to compute daily room discounts for ski packages------------
	
	// Print out results
	
	//  Do not offer a package discount of there is a special offer is greater than ski package...
		if(special_offer_cancel == 0 && special_offer > 0 )
		{
		if(special_offer > ski_package_room_discount)
			{
			//  Set ski_package_rate to 0 if there is a special offer	
			ski_package_room_discount = 0;
			}
		else
			{special_offer = 0;
			// Reset special offer indicators
				test_special_offer_flag = 0;
				special_offer_disclaimer = "";
				//document.special_offer_image.src = "no_offer.jpg";
				document.getElementById('special_offer_image').src = "no_offer.jpg";
			}
		}
	
	if(ski_package_room_discount > 0)
	{                                                        
	room_rate = room_rate * (1 - ski_package_room_discount);
	txtresults=txtresults +  dollars(room_rate) + "       " + date_to_string(calculated_date)+ "  Net Rate including " + truncate_decimal(100*ski_package_room_discount) + "% Ski Package Room Discount" + "\r" ;
	}

	if(special_offer_cancel == 0 && special_offer > 0)
	{                                                        
	room_rate = room_rate * (1 - special_offer);
	txtresults=txtresults +  dollars(room_rate) + "       " + date_to_string(calculated_date)+ "  Net Rate including " + truncate_decimal(100*special_offer) + "% Web Special Room Discount" + "\r" ;
	}
	
		
	if(ski_package_room_discount == 0 && (special_offer_array(calculated_date,room_type) == 0 ||special_offer_cancel == 1 ))
	{txtresults=txtresults +  dollars(room_rate) + "       " + date_to_string(calculated_date)+ "\r" ;
	}
	
							}

	//accumulate the room rate
	cumulative_room_rate = cumulative_room_rate + truncate_decimal(room_rate);
	//end for loop
}

// Test Room Rate... if any day has an undefined rate, issue a warning

if (room_rate_undefined == 1)
{
	invalid_data_entry_warning_flag = 1;
	invalid_data_entry_warning = "\r" + "Rates have not been defined for the period you desire!.  Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.";
	alert("Rates have not been defined for the period you desire!.  Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.");
	cumulative_room_rate = 0;
}



// complete writing test results
// add total line
txtresults = txtresults + "-------------------------------" + "\r";

// add room rate total
txtresults = txtresults + dollars(cumulative_room_rate) + "       " + "Total Room Rate" + "\r";

// add tax and gratuity line
tax_grat = cumulative_room_rate*(gratuity+room_tax);
gratuity_phrase = "Tax and Gratuity";
if(gratuity == 0)
	{gratuity_phrase = "Tax";}
	
txtresults = txtresults + dollars(tax_grat)  + "       " + gratuity_phrase + "\r";

// add total line
txtresults = txtresults + "-------------------------------" + "\r";

cumulative_room_rate = cumulative_room_rate + tax_grat;
txtresults = txtresults + dollars(cumulative_room_rate)  + "       " + "Total Room Charge" + "\r" + "\r";


//Test to see if Packages should be in output

if(package_type_flag == 1)

///---------------code to output ski package information
{

// Now determine if there is a ski package for Guest 1 and output information

if(guest1packagelength > 0)   {

txtresults = txtresults + guest1packageprinttxt;

//compute guest 1 ski package rate and output
ski_package_start_date = getDateinfo(guest1year,guest1month,guest1day_of_month,0);
//guest1packagerate = ski_package_rate_array(ski_package_start_date,guest1packagetype,guest1packagelength);
guest1packagerate = ski_ticket_rate_calculator(getDateinfo(year,month,day_of_month,0), total_nights, room_type, ski_package_start_date,guest1packagetype, guest1packagelength);

if (guest1packagerate == 0)
{
	invalid_data_entry_warning_flag = 1;
	invalid_data_entry_warning = "\r" + "Ski Package Rates for the package you have selected have not been defined for the period you desire!.  Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.";
	alert("Rates have not been defined for the period you desire!.  Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.");
	cumulative_room_rate = 0;
}

txtresults = txtresults + "Package rate          " + dollars(guest1packagerate) + "\r";
txtresults = txtresults + "-------------------------------" + "\r";

								}

// Now determine if there is a ski package for Guest 2 and output information

if(guest2packagelength > 0)   {

txtresults = txtresults + guest2packageprinttxt;

//compute guest 2 ski package rate and output
ski_package_start_date = getDateinfo(guest2year,guest2month,guest2day_of_month,0);
//guest2packagerate = ski_package_rate_array(ski_package_start_date,guest2packagetype,guest2packagelength);
guest2packagerate = ski_ticket_rate_calculator(getDateinfo(year,month,day_of_month,0), total_nights, room_type, ski_package_start_date,guest2packagetype, guest2packagelength);

if (guest2packagerate == 0)
{
	invalid_data_entry_warning_flag = 1;
	invalid_data_entry_warning = "\r" + "Ski Package Rates for the package you have selected have not been defined for the period you desire!.  Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.";
	alert("Rates have not been defined for the period you desire!.  Please call the Birch Ridge Inn directly at 800.435.8566 or 802.422.4293 to have a quotation prepared.");
	cumulative_room_rate = 0;
}

txtresults = txtresults + "Package rate          " + dollars(guest2packagerate) + "\r";

txtresults = txtresults + "-------------------------------" + "\r";
							}
							
}
// end of code to output ski package data

//Test to see if Packages should be in output

if(package_type_flag == 2) {

//code to output golf package information

//set guest1packagerate to goll tee time price
guest1packagelength = 1;
guest2packagelength = 0;

guest1packagerate = golftotalprice;

// set up detailed print
txtresults = txtresults + golfdetailtxt;
//set up standard printout
guest1packageprinttxt = golfbasictxt;

}
// end of code to output golf package data


							
// Now compute final quotation rate
cumulative_room_rate = cumulative_room_rate + guest1packagerate + guest2packagerate;
grandtotalgratuity_phrase = "which includes all taxes and gratuities,";
if(gratuity == 0)
	{grandtotalgratuity_phrase = "which includes all taxes";}
grandtotaltxt = "Total Quote is " + dollars(cumulative_room_rate) + "\r" + grandtotalgratuity_phrase + "\r" + "plus a full breakfast each morning.";
														
// Now Set Up Print Out Header
var printheader = "Birch Ridge Inn Rate Quote" + "\r\r" +
					"Room Information" + "\r" +
					"Arrival Date" + "          " + date_to_string(getDateinfo(year,month,day_of_month,0)) + "\r" +
					"Departure Date" + "        " + date_to_string(getDateinfo(year,month,day_of_month,total_nights)) + "\r" +
					"Total Nights" + "          " + total_nights + "\r" +
					"Room Selected " + "        " + room_txt + "\r" + "-------------------------------" + "\r";

txtresults = printheader + txtresults + grandtotaltxt;

//Print out before this is a detailed print
//now set up customer print out
if(print_out_style_flag == 1)
{txtresults = printheader;
	if(guest1packagelength > 0)
	{txtresults = txtresults + guest1packageprinttxt;
	txtresults = txtresults + "-------------------------------" + "\r";
	}
	if(guest2packagelength > 0)
	{txtresults = txtresults + guest2packageprinttxt;
	txtresults = txtresults + "-------------------------------" + "\r";
	}
	txtresults = txtresults + grandtotaltxt;
}
// we now have a simple rate message.  Save it in a cookie for use with availability_online 
// if not at the front desk and if no warnings.
//if( window.location.href.indexOf("Front_desk") == -1 && invalid_data_entry_warning_flag == 0){
//write_cookie("briAOinfo","From Online Calculator - " + txtresults);
// now preload AO Reservation page
//window.open("../res_frames/preload_ao_res.html","preload_AO","width=1,height=1");
//refocus primary window
//self.focus();
//}

// Now determine if there is a special offer and add special offer disclaimer

if(test_special_offer_flag > 0)
	{txtresults = txtresults + "\r" + "\r" + special_offer_disclaimer + "\r";
	}
	
// Now determine if there is a Ski Package Discount and add Ski Package Message

if(ski_package_message_flag > 0)
	{txtresults = ski_package_message_header_txt + "\r" + "\r" + txtresults + "\r" + "\r" + ski_package_message_txt + "\r";
	}	
                                                     
// now write results
//document.Rate_Form.result_box.value = txtresults;
document.getElementById("results_box").value = txtresults;

if(invalid_data_entry_warning_flag > 0)
	{
	// if there is a warning, over write result box
//	document.Rate_Form.result_box.value = invalid_data_entry_warning;
	document.getElementById("results_box").value = invalid_data_entry_warning;
	}
	
//write_cookie("briprint",document.Rate_Form.result_box.value);
write_cookie("briprint",document.getElementById("results_box").value);

// now form log message
if(invalid_data_entry_warning_flag == 0)
{//there are no warnings, create the log message to capture statistics
var log_message = null;
//arrival date
var date_arrive = (parseInt(month)+1) + "/" + day_of_month + "/" + year;
var num_nights = total_nights;
var selected_room = room_txt;
var completed_quote = cumulative_room_rate;
log_message = "&arrival=" + escape(date_arrive) + "&nights=" + total_nights + "&room=" + escape(room_txt) + "&quote=" + escape(completed_quote);

//Ski Package?
if(package_type_flag == 1)
	{// we have a ski package
	var ski_package_message = null;
	if(guest1packagelength >0 || guest2packagelength >0)
		{// package has been verified
			var pkgtype = "ski";
			var pkg1 =  escape(guest1packagetype_txt);
			var pkglength1 =  guest1packagelength;
			var pkgstart1 = escape((parseInt(guest1month)+1) + "/" + guest1day_of_month + "/" + guest1year);
			if(pkglength1 == 0)
				{pkg1 = "none";
				pkgstart1 = "NA";
				}
			var pkg2 =  escape(guest2packagetype_txt);
			var pkglength2 =  guest2packagelength;
			var pkgstart2 = escape((parseInt(guest2month)+1) + "/" + guest2day_of_month + "/" + guest2year);
			if(pkglength2 == 0)
				{pkg2 = "none";
				pkgstart2 = "NA";
				}
			ski_package_message = "&pkgtype=" + pkgtype + "&pkg1=" + pkg1 + "&pkglength1=" + pkglength1 + "&pkgstart1=" + pkgstart1 + "&pkg2=" + pkg2 + "&pkglength2=" + pkglength2 + "&pkgstart2=" + pkgstart2;
		}
	if(ski_package_message != null)
		{log_message = log_message + ski_package_message;
		}		
	}

//Golf Package?
// yes	number of rounds
// now create phrase
//golf Package?
if(package_type_flag == 2)
	{// we have a ski package
	var golf_package_message = null;
	if(total_tee_times >0 )
		{// package has been verified
			var pkgtype = "golf";
			var numrounds =  total_tee_times;
			golf_package_message = "&pkgtype=" + pkgtype + "&numrounds=" + numrounds;
		}
	if(golf_package_message != null)
		{log_message = log_message + golf_package_message;
		}		
	}


//now call function to store phrase
xmlLog(log_message, "../ratecalclog.php");
}

}
// -->


//--------------------New Function getDateinfo()-------------------------------
function getDateinfo(year,month,day_of_month,total_nights) {
//This function converts a pull down date into a machine readable date.
// it also adds an offset, total nights, if desited.

//create variables

normalized_date = new Date();
departure_date = new Date();

//set value of one day in milliseconds
var one_day=1000*60*60*24;

//Establish arrival_date from form input
arrival_date= new Date(year,month,day_of_month,0,0,0,0);

//Calculate departure_date and normalize out GMT and Daylight Savings Variations
departure = (arrival_date.getTime()+(one_day*total_nights) + (one_day * 0.5));

//  get day based only on Year, Month, and Day
departure_date=new Date(departure);
normalized_date = new Date(departure_date.getFullYear(),departure_date.getMonth(),departure_date.getDate(),0,0,0,0)

return(normalized_date);


}
// -->

//--------------------New Function checkDate()-------------------------------
function checkDate(year,month,day)
// this function validates that a date is entered correctly
// it returns a 0 if there is no error, 
// and returns the number of days in the month over run if the date is invalid
// were year is a 4 digit year
// month is represented in "java months where January =0...and December is 11
// day represent the current date of the month between 1 to 30
{
var leap_year = 0;
var date_error = 0;
//Start by looking for leap years
//Validate leap year for correct february  day
if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) 
	{
	leap_year = 1;
	}
if ((month == 1) && (leap_year == 1) && (day > 29)) 
	{
	 date_error = day - 29;
	}
if ((month == 1) && (leap_year != 1) && (day > 28)) 
	{
	date_error = day - 28;
	}
// validate 31 day months
if ((day > 31) && ((month == 0) || (month == 2) || (month == 4) || (month == 6) || (month == 7) || (month == 9) || (month == 11))) 
	{
	date_error = day - 31;
	}	
	
// Validate 30 day months
if ((day > 30) && ((month == 3) || (month == 5) || (month == 8) || (month == 10))) 
	{
	date_error = day - 30;
	}
// validation complete.  Return date error
return(date_error);
}
//-->

//--------------------New Function room_rate_array()-------------------------------
function room_rate_array(room_date,var_id) {
//this function searches the room rate array
// the function call inputs the room_date, and outputs the requested array parameter from 0 to 8
//the array is arranged as
//roomInfo = 
//roomInfo[n][0]=(Date(y,m-1,d)
//roomInfo[n][1]=(queen_weekend)
//roomInfo[n][2]=(queen_weekday)
//roomInfo[n][3]=(king_weekend
//roomInfo[n][4]=(king_weekday)
//roomInfo[n][5]=(qwpl_weekend)
//roomInfo[n][6]=(qwpl_weekday)
//roomInfo[n][7]=(kwpl_weekend)
//roomInfo[n][8]=(kwpl_weekday)
//where weekend is the rate for Friday, Saturday and Sunday
//where weekday is the rate for Monday through Thursday

//define the array
var arraysize = 42;
tableDate = new Date();
testDate = new Date(room_date);
//alert(testDate);
var return_null = 0;
var roomInfo = [arraysize];
// Rate Table

// 2005-2006 season
roomInfo[1] = [new Date(2005,5-1,1), 0, 0,0,0,0,0,0,0];

//Rates for 2010-2011 season
roomInfo[2] = [new Date(2010,5-1,1),90,90,130,130,170,170,170,170];
roomInfo[3] = [new Date(2010,6-1,18),90,90,130,130,170,170,170,170];
roomInfo[4] = [new Date(2010,9-1,3),100,100,140,140,180,180,180,180];
roomInfo[5] = [new Date(2010,9-1,20),160,120,200,160,240,200,240,200];
roomInfo[6] = [new Date(2010,10-1,15),100,90,140,130,180,170,180,170];
roomInfo[7] = [new Date(2010,11-1,24),120,100,160,140,200,180,200,180];
roomInfo[8] = [new Date(2010,11-1,28),100,90,140,130,180,170,180,170];
roomInfo[9] = [new Date(2010,12-1,17),120,120,160,160,200,200,200,200];
roomInfo[10] = [new Date(2010,12-1,24),190,190,240,240,290,290,290,290];
roomInfo[11] = [new Date(2010,12-1,31),200,190,250,240,300,290,300,290];
roomInfo[12] = [new Date(2011,1-1,2),160,120,200,160,240,200,240,200];
roomInfo[13] = [new Date(2011,1-1,14),160,160,200,200,240,240,240,240];
roomInfo[14] = [new Date(2011,1-1,17),160,120,200,160,240,200,240,200];
roomInfo[15] = [new Date(2011,1-1,31),160,120,200,160,240,200,240,200];
roomInfo[16] = [new Date(2011,2-1,18),190,190,240,240,290,290,290,290];
roomInfo[17] = [new Date(2011,2-1,21),160,130,200,170,240,210,240,210];
roomInfo[18] = [new Date(2011,2-1,27),160,120,200,160,240,200,240,200];
roomInfo[19] = [new Date(2011,3-1,21),120,100,160,140,200,180,200,180];

//Rates for 2011-2012 season
roomInfo[20] = [new Date(2011,5-1,1),99,99,144,144,189,189,189,189];
roomInfo[21] = [new Date(2011,6-1,24),119,109,164,154,209,199,209,199];
roomInfo[22] = [new Date(2011,9-1,2),119,109,164,154,209,199,209,199];
roomInfo[23] = [new Date(2011,9-1,19),179,139,229,184,279,229,279,229];
roomInfo[24] = [new Date(2011,10-1,16),119,99,164,144,209,189,209,189];
roomInfo[25] = [new Date(2011,11-1,23),119,99,164,144,209,189,209,189];
roomInfo[26] = [new Date(2011,11-1,27),119,99,164,144,209,189,209,189];
roomInfo[27] = [new Date(2011,12-1,16),119,99,164,144,209,189,209,189];
roomInfo[28] = [new Date(2011,12-1,23),219,219,279,279,329,329,329,329];
roomInfo[29] = [new Date(2011,12-1,30),229,219,289,279,339,339,339,339];
roomInfo[30] = [new Date(2012,1-1,2),149,109,199,154,249,199,249,199];
roomInfo[31] = [new Date(2012,1-1,13),159,179,209,224,259,269,259,269];
roomInfo[32] = [new Date(2012,1-1,16),149,109,199,154,249,199,249,199];
roomInfo[33] = [new Date(2012,1-1,30),179,139,229,184,279,229,279,229];
roomInfo[34] = [new Date(2012,2-1,5),179,139,229,184,249,199,249,199];
roomInfo[35] = [new Date(2012,2-1,13),179,109,229,154,279,199,279,199];
roomInfo[36] = [new Date(2012,2-1,17),219,219,279,279,329,329,329,329];
roomInfo[37] = [new Date(2012,2-1,20),179,129,229,174,279,239,279,239];
roomInfo[38] = [new Date(2012,2-1,26),179,129,229,174,279,229,279,229];
roomInfo[39] = [new Date(2012,3-1,5),179,139,229,184,279,229,279,229];
roomInfo[40] = [new Date(2012,4-1,1),119,109,169,154,219,199,219,199];
//Rates not defined for 2012-2013 season
roomInfo[41] = [new Date(2012,4-1,28),0,0,0,0,0,0,0,0];
//end of table
roomInfo[42] = [new Date(2020,5-1,1), 0, 0,0,0,0,0,0,0];

//search for room_date

for (i=1; i < arraysize+1; i++) {
//Find table entry too far..
	 tableDate = roomInfo[i+1][0];
if (testDate.getTime() < tableDate.getTime())
      return(roomInfo[i][var_id]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->

//--------------------New Function date_to_string()-------------------------------
function date_to_string(date_input)  {
//this function converts a local date stored in machine format
//to a string in the form
// day of week  Month of Year  Day of Month  Year
//the inout to the form is a date
//the output of the form is a string
//create vatiables

var date_return = "";
var day_name = new Array("Sun ", "Mon ", "Tue ", "Wed ", "Thu ", "Fri ", "Sat ");
var month_name = new Array("Jan ", "Feb ", "Mar ", "Apr ", "May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec ");

//parse date and format result

date_return =  day_name[date_input.getDay()] + month_name[date_input.getMonth()] + date_input.getDate() + " " + date_input.getFullYear();
return (date_return);
}
// -->

//--------------------New Function dollars()-------------------------------
function dollars(number_in) {
// this function takes a number and 
//converts it into a dollar string of the form $dollars.cents
// It pads out the dollars to thousands by adding extra spaces between
// the dollar sign and the number

var num = number_in;
var numpad = "";

//determine how many spaces to pad out between $ and number

if (num < 0) 	{
	numpad = "";}
else if (num <10) {
	numpad = "    ";}// add 4 spaces if less than 10
else if (num <100)	{
	numpad = "   ";	}// add 3 spaces if less than 100
else if (num <1000)	{
	numpad = "  ";	}// add 2 spaces if less than 1000 
else if (num <10000) {
	numpad = ""; }// add 0 spaces if less than 10000 to compensate for , 
else {
	numpad = ""; }// add 0 spaces if greater than 10000

//Process number to add commas. and decimal point
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return ('$' + numpad + num + '.' + cents);
}
// -->

//--------------------New Function write_cookie()-------------------------------
function write_cookie(cookie_name, cookie_value) {
//this function writes a cookie with name = "cookie name"
//"cookie_value" is a string to be stored.  It will escape encode the string.
//this will set an expiration date equal to 1 day (1000*60*60*24 milliseconds)	
//caution : this function does not check to see if cookie_name already exisits. 
//If cookie_name already exists it will overwrite it!

var cookie_contents = "";
var cookie_dough = "";
var exp = new Date();
exp.setTime(exp.getTime()+1000*60*60*24);
var domain_name = document.domain;
if(domain_name.search("birchridge") >0){domain_name = "birchridge.com";}

cookie_contents = escape(cookie_value);
//cookie_dough = cookie_name + '=' + cookie_contents +
//alert(cookie_dough);
//document.cookie = cookie_dough;

//function setCookie(name, value, expires, path, domain, secure) { 
var cookie_dough = cookie_name + "=" + cookie_contents + 
 "; expires=" + exp.toGMTString() +
 "; path=" + "/" +
 "; domain=" + "." + domain_name;

//+((path) ? "; path=" + path : "") + 
//((domain) ? "; domain=" + domain : "") + 
//((secure) ? "; secure" : "");
document.cookie = cookie_dough;

}
// -->

//--------------------New Function read_cookie()-------------------------------
function read_cookie(cookie_name) {
//this function examines document cookies and returns the following:
// If cookie_name is not a valid cookie name, the function returns null
// if cookie_name is a valid cookie, it returns the contents of the cookie

// first, check to see if there are any cookies.  If none, return null
var cookie_jar = document.cookie;
if (cookie_jar == "") return null;

//  now just get the cookie we want.  var the_cookie is an index into the cookie_jar string
var the_cookie = cookie_jar.indexOf(cookie_name + '=');

// is our cookie in the jar?  if not return a null
if (the_cookie == -1) return null;

//  cookie in the jar... skip past the name to find the value
the_cookie += cookie_name.length +1; //skip over name and equals sign

//  now find the total size of the cookie
var cookie_size = cookie_jar.indexOf(";", the_cookie);
// now determine if this was the last cookie in the jar. 
//If so, set cookie_size to last cookie 

if (cookie_size== -1) cookie_size=cookie_jar.length;

//  we have now found my_cookie..the one we want
var my_cookie = cookie_jar.substring(the_cookie, cookie_size);

// now unescape cookie
my_cookie = unescape(my_cookie);

return (my_cookie);
}
// -->

//--------------------New Function special_offer_array()-------------------------------
function special_offer_array(room_date,var_id) {
//this function searches the special offer array
// the function call inputs the room_date, and outputs the requested array parameter from 0 to 5
//the array is arranged as
//specialOffer = 
//specialOffer[n][0]=(Date(y,m-1,d)
//specialOffer[n][1]=(queen)
//specialOffer[n][2]=(king)
//specialOffer[n][3]=(qwpl)
//specialOffer[n][4]=(kwpl)
//where queen, king, qwpl, kqwpl refer to the special offer value in percent. 0 equates to no special offer

//define the array
var offerarraysize = 53;
offerDate = new Date();
offertestDate = new Date(room_date);
//alert(offerDate);
var return_null = 0;
var specialOffer = [offerarraysize];
// First Entry : set to null
specialOffer[1] = [new Date(2003,1-1,1), 0,0,0,0];

// Begin Discounts
specialOffer[2] = [new Date(2011,5-1,1),0,0,0,0];
specialOffer[3] = [new Date(2011,6-1,25),0,0,0,0];
specialOffer[4] = [new Date(2011,6-1,28),0,0,0,0];
specialOffer[5] = [new Date(2011,8-1,1),0,0,0,0];
specialOffer[6] = [new Date(2011,8-1,14),0.1,0.1,0.1,0.1];
specialOffer[7] = [new Date(2011,8-1,19),0,0,0,0];
specialOffer[8] = [new Date(2011,8-1,21),0.1,0.1,0.1,0.1];
specialOffer[9] = [new Date(2011,8-1,28),0.1,0.1,0.1,0.1];
specialOffer[10] = [new Date(2011,9-1,1),0,0,0,0];
specialOffer[11] = [new Date(2011,9-1,6),0,0,0,0];
specialOffer[12] = [new Date(2011,9-1,13),0,0,0,0];
specialOffer[13] = [new Date(2011,9-1,17),0,0,0,0];
specialOffer[14] = [new Date(2011,9-1,20),0,0,0,0];
specialOffer[15] = [new Date(2011,9-1,22),0,0,0,0];
specialOffer[16] = [new Date(2011,9-1,24),0,0,0,0];
specialOffer[17] = [new Date(2011,9-1,27),0,0,0,0];
specialOffer[18] = [new Date(2011,10-1,4),0,0,0,0];
specialOffer[19] = [new Date(2011,10-1,8),0,0,0,0];
specialOffer[20] = [new Date(2011,10-1,11),0,0,0,0];
specialOffer[21] = [new Date(2011,10-1,15),0,0,0,0];
specialOffer[22] = [new Date(2011,10-1,18),0,0,0,0];
specialOffer[23] = [new Date(2011,10-1,22),0,0,0,0];
specialOffer[24] = [new Date(2011,10-1,25),0,0,0,0];
specialOffer[25] = [new Date(2011,11-1,12),0,0,0,0];
specialOffer[26] = [new Date(2011,11-1,15),0,0,0,0];
specialOffer[27] = [new Date(2011,11-1,19),0,0,0,0];
specialOffer[28] = [new Date(2011,11-1,22),0,0,0,0];
specialOffer[29] = [new Date(2011,11-1,24),0.1,0.1,0.1,0.1];
specialOffer[30] = [new Date(2011,11-1,28),0,0,0,0];
specialOffer[31] = [new Date(2011,12-1,3),0,0,0,0];
specialOffer[32] = [new Date(2011,12-1,6),0,0,0,0];
specialOffer[33] = [new Date(2011,12-1,10),0,0,0,0];
specialOffer[34] = [new Date(2011,12-1,13),0,0,0,0];
specialOffer[35] = [new Date(2011,12-1,17),0,0,0,0];
specialOffer[36] = [new Date(2011,12-1,27),0.31963,0.3405,0.30395,0.30395];
specialOffer[37] = [new Date(2011,12-1,30),0.05349,0.25,0.25,0.25];
specialOffer[38] = [new Date(2012,1-1,2),0,0,0,0];
specialOffer[39] = [new Date(2012,1-1,7),0,0,0,0];
specialOffer[40] = [new Date(2012,1-1,10),0,0,0,0];
specialOffer[41] = [new Date(2012,1-1,14),0,0,0,0];
specialOffer[42] = [new Date(2012,1-1,18),0,0,0,0];
specialOffer[43] = [new Date(2012,1-1,21),0,0,0,0];
specialOffer[44] = [new Date(2012,1-1,24),0,0,0,0];
specialOffer[45] = [new Date(2012,1-1,28),0,0,0,0];
specialOffer[46] = [new Date(2012,1-1,31),0,0,0,0];
specialOffer[47] = [new Date(2012,2-1,18),0,0,0,0];
specialOffer[48] = [new Date(2012,2-1,21),0,0,0,0];
specialOffer[49] = [new Date(2012,2-1,25),0,0,0,0];
specialOffer[50] = [new Date(2012,3-1,10),0,0,0,0];
specialOffer[51] = [new Date(2012,3-1,13),0,0,0,0];
specialOffer[52] = [new Date(2012,3-1,30),0,0,0,0];
//end of table
specialOffer[53] = [new Date(2020,5-1,1),0,0,0,0];

//search for room_date

for (i=1; i < offerarraysize+1; i++) {
//Find table entry too far..
	 offerDate = specialOffer[i+1][0];
if (offertestDate.getTime() < offerDate.getTime())
	return(specialOffer[i][var_id]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->

//--------------------New Function ski_package_room_discount()-------------------------------
function ski_package_room_discount_array(room_date,var_id) {
//this function searches the ski package room discount array
// the function call inputs the room_date, and outputs the requested array parameter 
//the array is arranged as
//skiPackageRoomDiscount = 
//skiPackageRoomDiscount[n][0]=(Date(y,m-1,d)
//skiPackageRoomDiscount[n][1]=(skiPackageRoomDiscount)


//define the array
var skiPackageRoomDiscountsize = 46;
skiPackageDate = new Date();
skiPackagetestDate = new Date(room_date);
//alert(skiPackageDate);
var return_null = 0;
var skiPackageRoomDiscount = [skiPackageRoomDiscountsize];
// First Entry : set to null
skiPackageRoomDiscount[1] = [new Date(2004,5-1,1), 0];

// Beginning of 2011/2012 Ski Season
skiPackageRoomDiscount[2] = [new Date(2011,10-1,28),0.1];
skiPackageRoomDiscount[3] = [new Date(2011,11-1,11),0.04];
skiPackageRoomDiscount[4] = [new Date(2011,11-1,13),0.1];
skiPackageRoomDiscount[5] = [new Date(2011,11-1,18),0.04];
skiPackageRoomDiscount[6] = [new Date(2011,11-1,20),0.1];
skiPackageRoomDiscount[7] = [new Date(2011,11-1,24),0.04];
skiPackageRoomDiscount[8] = [new Date(2011,11-1,27),0.1];
skiPackageRoomDiscount[9] = [new Date(2011,12-1,2),0.04];
skiPackageRoomDiscount[10] = [new Date(2011,12-1,4),0.1];
skiPackageRoomDiscount[11] = [new Date(2011,12-1,9),0.04];
skiPackageRoomDiscount[12] = [new Date(2011,12-1,11),0.1];
skiPackageRoomDiscount[13] = [new Date(2011,12-1,16),0.04];
skiPackageRoomDiscount[14] = [new Date(2011,12-1,18),0.1];
skiPackageRoomDiscount[15] = [new Date(2011,12-1,23),0.04];
skiPackageRoomDiscount[16] = [new Date(2012,1-1,1),0.1];
skiPackageRoomDiscount[17] = [new Date(2012,1-1,6),0.04];
skiPackageRoomDiscount[18] = [new Date(2012,1-1,8),0.1];
skiPackageRoomDiscount[19] = [new Date(2012,1-1,13),0.04];
skiPackageRoomDiscount[20] = [new Date(2012,1-1,16),0.1];
skiPackageRoomDiscount[21] = [new Date(2012,1-1,20),0.04];
skiPackageRoomDiscount[22] = [new Date(2012,1-1,22),0.1];
skiPackageRoomDiscount[23] = [new Date(2012,1-1,27),0.04];
skiPackageRoomDiscount[24] = [new Date(2012,1-1,29),0.1];
skiPackageRoomDiscount[25] = [new Date(2012,2-1,3),0.14];
skiPackageRoomDiscount[26] = [new Date(2012,2-1,5),0.1];
skiPackageRoomDiscount[27] = [new Date(2012,2-1,10),0.04];
skiPackageRoomDiscount[28] = [new Date(2012,2-1,12),0.1];
skiPackageRoomDiscount[29] = [new Date(2012,2-1,17),0.04];
skiPackageRoomDiscount[30] = [new Date(2012,2-1,26),0.1];
skiPackageRoomDiscount[31] = [new Date(2012,3-1,2),0.04];
skiPackageRoomDiscount[32] = [new Date(2012,3-1,4),0.1];
skiPackageRoomDiscount[33] = [new Date(2012,3-1,9),0.04];
skiPackageRoomDiscount[34] = [new Date(2012,3-1,11),0.1];
skiPackageRoomDiscount[35] = [new Date(2012,3-1,16),0.04];
skiPackageRoomDiscount[36] = [new Date(2012,3-1,18),0.1];
skiPackageRoomDiscount[37] = [new Date(2012,3-1,23),0.04];
skiPackageRoomDiscount[38] = [new Date(2012,3-1,25),0.1];
skiPackageRoomDiscount[39] = [new Date(2012,3-1,30),0.04];
skiPackageRoomDiscount[40] = [new Date(2012,4-1,1),0.1];
skiPackageRoomDiscount[41] = [new Date(2012,4-1,6),0.04];
skiPackageRoomDiscount[42] = [new Date(2012,4-1,8),0.1];
skiPackageRoomDiscount[43] = [new Date(2012,4-1,13),0.04];
skiPackageRoomDiscount[44] = [new Date(2012,4-1,15),0.1];
skiPackageRoomDiscount[45] = [new Date(2012,4-1,29),0];

//end of table
skiPackageRoomDiscount[46] = [new Date(2020,5-1,1),0,];

//search for room_date

for (i=1; i < skiPackageRoomDiscountsize+1; i++) {
//Find table entry too far..
	 skiPackageDate = skiPackageRoomDiscount[i+1][0];
if (skiPackagetestDate.getTime() < skiPackageDate.getTime())
	return(skiPackageRoomDiscount[i][var_id]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->

//--------------------New Function ski_package_rate_array()-------------------------------
function ski_package_rate_array(ski_package_start_date,ski_package_type,ski_package_day_num) {
//this function searches the ski package rate array
// the function call inputs the ski_package_start_date, package type, andn umber of days
// and outputs the requested array parameter from 0 to 40
// where the parameter is (package_type-1)*8*ski_day_including mid week offset
//the array is arranged as
//skiPackageRateInfo = 
//skiPackageRateInfo[n][0]=(Date(y,m-1,d)
//skiPackageRateInfo[n][1thru 6]=(Lift Ticket)
// were 1=2 day, 2=3day, 3=4day, 4=5day, 5=6day, 6=7day
//skiPackageRateInfo[n][7 thru 12]=(lift ticket plus equipment)
//skiPackageRateInfo[n][13 thru 18]=(lift ticket plus equipment and lesson)
//skiPackageRateInfo[n][19 thru 24]=(lift ticket plus lesson, no equipment)
//skiPackageRateInfo[n][25 thru 30]=(Learn to ski)

//define the array
var skiPackageRate_arraysize = 128;	
skiPackageRate_tableDate = new Date();
skiPackageRate_testDate = new Date(ski_package_start_date);
//alert(skiPackageRate_testDate);
var return_null = 0;
var skiPackageRateInfo = [skiPackageRate_arraysize];
// Rate Table

//Ski Paclages not available after April 30, 2004
skiPackageRateInfo[1] = [new Date(2005,5-1,1),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

// Ski Package prices For 2011/2012 season.
skiPackageRateInfo[2] = [new Date(2011,11-1,19),104.4,157.1,198,232.4,278.7,326.1,167.6,247.1,311.5,365.2,427.6,487.8,269.6,400.1,515.5,620.2,733.6,844.8,206.4,310.1,402,487.4,584.7,683.1,207,207,269,332,394,446];
skiPackageRateInfo[3] = [new Date(2011,11-1,20),104.4,157.1,198,232.4,291.6,337.9,167.6,247.1,311.5,365.2,440.5,499.6,269.6,400.1,515.5,620.2,746.5,856.6,206.4,310.1,402,487.4,597.6,694.9,207,207,269,332,394,446];
skiPackageRateInfo[4] = [new Date(2011,11-1,21),104.4,157.1,198,245.4,304.5,350.8,167.6,247.1,311.5,378.2,453.4,512.5,269.6,400.1,515.5,633.2,759.4,869.5,206.4,310.1,402,500.4,610.5,707.8,207,207,269,332,394,446];
skiPackageRateInfo[5] = [new Date(2011,11-1,22),104.4,157.1,210.9,258.3,317.4,362.6,167.6,247.1,324.4,391.1,466.3,524.3,269.6,400.1,528.4,646.1,772.3,881.3,206.4,310.1,414.9,513.3,623.4,719.6,207,207,269,332,394,446];
skiPackageRateInfo[6] = [new Date(2011,11-1,23),104.4,171.1,224.9,271.2,330.4,375.6,167.6,261.1,338.4,404,479.3,537.3,269.6,414.1,542.4,659,785.3,894.3,206.4,324.1,428.9,526.2,636.4,732.6,207,207,269,332,394,446];
skiPackageRateInfo[7] = [new Date(2011,11-1,24),119.4,186.2,238.9,284.1,343.3,387.4,182.6,276.2,352.4,416.9,492.2,549.1,284.6,429.2,556.4,671.9,798.2,906.1,221.4,339.2,442.9,539.1,649.3,744.4,207,207,269,332,394,446];
skiPackageRateInfo[8] = [new Date(2011,11-1,25),133.4,200.2,252.9,297,356.2,400.3,196.6,290.2,366.4,429.8,505.1,562,298.6,443.2,570.4,684.8,811.1,919,235.4,353.2,456.9,552,662.2,757.3,207,207,269,332,394,446];
skiPackageRateInfo[9] = [new Date(2011,12-1,11),133.4,200.2,252.9,297,356.2,402.5,196.6,290.2,366.4,429.8,505.1,564.2,298.6,443.2,570.4,684.8,811.1,921.2,235.4,353.2,456.9,552,662.2,759.5,207,207,269,332,394,446];
skiPackageRateInfo[10] = [new Date(2011,12-1,12),133.4,200.2,252.9,297,358.3,405.7,196.6,290.2,366.4,429.8,507.2,567.4,298.6,443.2,570.4,684.8,813.2,924.4,235.4,353.2,456.9,552,664.3,762.7,207,207,269,332,394,446];
skiPackageRateInfo[11] = [new Date(2011,12-1,13),133.4,200.2,252.9,300.2,360.5,402.5,196.6,290.2,366.4,433,509.4,564.2,298.6,443.2,570.4,688,815.4,921.2,235.4,353.2,456.9,555.2,666.5,759.5,207,207,269,332,394,446];
skiPackageRateInfo[12] = [new Date(2011,12-1,14),133.4,200.2,254,304.5,357.3,399.2,196.6,290.2,367.5,437.3,506.2,560.9,298.6,443.2,571.5,692.3,812.2,917.9,235.4,353.2,458,559.5,663.3,756.2,207,207,269,332,394,446];
skiPackageRateInfo[13] = [new Date(2011,12-1,15),133.4,200.2,255,302.4,353,396,196.6,290.2,368.5,435.2,501.9,557.7,298.6,443.2,572.5,690.2,807.9,914.7,235.4,353.2,459,557.4,659,753,207,207,269,332,394,446];
skiPackageRateInfo[14] = [new Date(2011,12-1,16),133.4,200.2,255,300.2,349.7,392.8,196.6,290.2,368.5,433,498.6,554.5,298.6,443.2,572.5,688,804.6,911.5,235.4,353.2,459,555.2,655.7,749.8,207,207,269,332,394,446];
skiPackageRateInfo[15] = [new Date(2011,12-1,17),133.4,200.2,255,298.1,345.4,389.5,196.6,290.2,368.5,430.9,494.3,554.9,298.6,443.2,572.5,685.9,800.3,911.9,235.4,353.2,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[16] = [new Date(2011,12-1,18),133.4,200.2,252.9,292.7,340,389.5,196.6,290.2,366.4,425.5,492.6,558.6,298.6,443.2,570.4,680.5,798.6,915.6,235.4,353.2,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[17] = [new Date(2011,12-1,19),133.4,200.2,251.8,286.2,340,389.5,196.6,290.2,365.3,422.7,496.3,562.3,298.6,443.2,569.3,677.7,802.3,919.3,235.4,353.2,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[18] = [new Date(2011,12-1,20),133.4,200.2,251.8,292.7,345.4,398.2,196.6,290.2,369,432.9,505.4,574.7,298.6,443.2,573,687.9,811.4,942,235.4,353.2,455.8,547.7,651.4,765.5,207,207,269,332,394,467];
skiPackageRateInfo[19] = [new Date(2011,12-1,21),133.4,200.2,252.9,298.1,354,406.8,196.6,293.9,373.8,442,517.7,587,298.6,446.9,577.8,697,834,964.6,235.4,353.2,456.9,553.1,670.3,784.4,207,207,269,332,415,467];
skiPackageRateInfo[20] = [new Date(2011,12-1,22),146.3,206.6,255,306.7,361.6,414.3,213.2,304,379.6,454.3,529,598.2,315.2,457,583.6,719.6,855.6,986.1,248.3,359.6,459,572,688.2,802.2,207,207,269,373,415,467];
skiPackageRateInfo[21] = [new Date(2011,12-1,23),149.6,206.6,265.8,314.2,370.2,422.9,220.2,307.7,394.1,465.5,541.3,610.5,322.2,460.7,608.4,741.1,878.2,1008.7,251.6,359.6,480.1,589.8,707.1,821.1,207,207,301,373,415,467];
skiPackageRateInfo[22] = [new Date(2011,12-1,24),153.9,215.2,275.5,322.8,378.8,430.4,224.5,316.3,403.8,474.1,549.9,614.3,326.5,479.6,628.4,760,897.1,1022.8,255.9,378.5,500.1,608.7,726,838.9,207,228,301,373,415,467];
skiPackageRateInfo[23] = [new Date(2011,12-1,25),157.1,224.9,284.1,325,380.9,432.6,227.7,326,412.4,476.3,548.3,612.8,340,499.6,647.3,772.5,905.8,1031.6,269.4,398.5,519,621.2,738.4,851.4,228,228,301,373,415,467];
skiPackageRateInfo[24] = [new Date(2011,12-1,26),159.3,233.5,292.7,328.2,383.1,435.8,229.9,334.6,421,475.8,546.8,612.3,352.5,518.5,666.2,782.3,914.6,1041.4,281.9,417.4,537.9,634.7,750.9,864.9,228,228,301,373,415,467];
skiPackageRateInfo[25] = [new Date(2011,12-1,27),159.3,233.5,292.7,328.2,383.1,427.2,229.9,334.6,417.3,472.1,543.1,600,352.5,518.5,662.5,778.6,910.9,1018.8,281.9,417.4,537.9,634.7,750.9,846,228,228,301,373,415,467];
skiPackageRateInfo[26] = [new Date(2011,12-1,28),159.3,233.5,292.7,328.2,375.6,419.7,229.9,330.9,413.6,468.4,531.9,588.8,352.5,514.8,658.8,774.9,889.4,997.3,281.9,417.4,537.9,634.7,733.1,828.2,228,228,301,373,415,467];
skiPackageRateInfo[27] = [new Date(2011,12-1,29),159.3,233.5,292.7,319.6,367,411.1,226.2,327.2,409.9,456.1,519.6,576.5,348.8,511.1,655.1,752.3,866.8,974.7,281.9,417.4,537.9,615.8,714.2,809.3,228,228,301,373,415,467];
skiPackageRateInfo[28] = [new Date(2011,12-1,30),159.3,233.5,283,311,358.3,402.5,222.5,323.5,396.5,443.8,507.2,564.2,345.1,507.4,631.4,729.7,844.1,952.1,281.9,417.4,517.9,596.9,695.2,790.4,228,228,301,373,415,467];
skiPackageRateInfo[29] = [new Date(2011,12-1,31),159.3,223.8,272.3,303.5,350.8,394.9,222.5,313.8,385.8,436.3,499.7,556.6,345.1,487.4,610.4,711.9,826.3,934.2,281.9,397.4,496.9,579.1,677.4,772.5,228,228,301,373,415,467];
skiPackageRateInfo[30] = [new Date(2012,1-1,1),152.8,215.2,261.5,294.9,342.2,392.8,216,305.2,375,427.7,491.1,554.5,328.3,468.5,589.3,693,807.4,921.8,265.1,378.5,475.8,560.2,658.5,760.1,228,228,301,373,415,467];
skiPackageRateInfo[31] = [new Date(2012,1-1,2),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[32] = [new Date(2012,1-1,3),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[33] = [new Date(2012,1-1,4),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,554.9,311.5,448.5,570.4,685.9,800.3,911.9,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[34] = [new Date(2012,1-1,5),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,498,558.6,311.5,449.6,572.5,685.9,804,915.6,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[35] = [new Date(2012,1-1,6),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,434.6,501.7,562.3,314.8,449.6,572.5,689.6,807.7,919.3,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[36] = [new Date(2012,1-1,7),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,372.2,438.3,505.4,562.3,319.1,449.6,576.2,693.3,811.4,929.6,255.9,359.6,459,553.1,651.4,756.8,207,207,269,332,394,467];
skiPackageRateInfo[37] = [new Date(2012,1-1,8),149.6,206.6,252.9,292.7,340,392.8,212.8,300.3,373.8,436.6,500,565.6,314.8,453.3,577.8,691.6,816.3,943.2,251.6,359.6,456.9,547.7,656.3,770.4,207,207,269,332,415,467];
skiPackageRateInfo[38] = [new Date(2012,1-1,9),146.3,205.5,251.8,286.2,342.2,394.9,209.5,295.5,365.3,419,494.8,564,311.5,448.5,569.3,684.3,821.4,951.9,248.3,358.5,455.8,551.5,668.8,782.8,207,207,269,373,415,467];
skiPackageRateInfo[39] = [new Date(2012,1-1,10),146.3,205.5,251.8,294.9,350.8,394.9,209.5,295.5,365.3,431.4,507.1,567.7,311.5,448.5,579.6,707,844,955.6,248.3,358.5,466.1,570.5,687.7,782.8,207,207,301,373,415,467];
skiPackageRateInfo[40] = [new Date(2012,1-1,11),146.3,205.5,261.5,303.5,350.8,394.9,209.5,295.5,378.7,443.7,510.8,567.7,311.5,458.8,603.3,729.6,847.7,955.6,248.3,368.8,486.1,589.4,687.7,782.8,207,228,301,373,415,467];
skiPackageRateInfo[41] = [new Date(2012,1-1,12),146.3,215.2,272.3,303.5,350.8,394.9,209.5,308.9,393.2,447.4,510.8,567.7,321.8,482.5,628.1,733.3,847.7,955.6,258.6,388.8,507.2,589.4,687.7,782.8,228,228,301,373,415,467];
skiPackageRateInfo[42] = [new Date(2012,1-1,13),152.8,223.8,272.3,303.5,350.8,394.9,219.7,321.2,396.9,447.4,510.8,567.7,342.3,505.1,631.8,733.3,847.7,955.6,275.4,407.7,507.2,589.4,687.7,782.8,228,228,301,373,415,467];
skiPackageRateInfo[43] = [new Date(2012,1-1,14),159.3,223.8,272.3,303.5,350.8,394.9,229.9,324.9,396.9,447.4,510.8,567.7,352.5,498.5,621.5,723,837.4,945.3,281.9,397.4,496.9,579.1,677.4,772.5,228,228,301,373,415,467];
skiPackageRateInfo[44] = [new Date(2012,1-1,15),152.8,215.2,261.5,294.9,342.2,392.8,223.4,312.6,382.4,435.1,498.5,561.9,335.7,475.9,596.7,700.4,814.8,929.2,265.1,378.5,475.8,560.2,658.5,760.1,228,228,301,373,415,467];
skiPackageRateInfo[45] = [new Date(2012,1-1,16),146.3,205.5,251.8,286.2,340,389.5,213.2,299.2,369,422.7,492.6,554.9,315.2,452.2,573,677.7,798.6,911.9,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[46] = [new Date(2012,1-1,17),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[47] = [new Date(2012,1-1,18),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[48] = [new Date(2012,1-1,19),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[49] = [new Date(2012,1-1,20),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[50] = [new Date(2012,1-1,21),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[51] = [new Date(2012,1-1,22),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[52] = [new Date(2012,1-1,23),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[53] = [new Date(2012,1-1,24),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[54] = [new Date(2012,1-1,25),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[55] = [new Date(2012,1-1,26),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[56] = [new Date(2012,1-1,27),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[57] = [new Date(2012,1-1,28),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[58] = [new Date(2012,1-1,29),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[59] = [new Date(2012,1-1,30),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[60] = [new Date(2012,1-1,31),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[61] = [new Date(2012,2-1,1),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[62] = [new Date(2012,2-1,2),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[63] = [new Date(2012,2-1,3),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[64] = [new Date(2012,2-1,4),138.5,206.6,255,298.1,345.4,389.5,201.7,296.6,368.5,430.9,494.3,551.2,303.7,449.6,572.5,685.9,800.3,908.2,240.5,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[65] = [new Date(2012,2-1,5),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[66] = [new Date(2012,2-1,6),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[67] = [new Date(2012,2-1,7),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[68] = [new Date(2012,2-1,8),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[69] = [new Date(2012,2-1,9),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[70] = [new Date(2012,2-1,10),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[71] = [new Date(2012,2-1,11),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[72] = [new Date(2012,2-1,12),149.6,206.6,252.9,292.7,340,392.8,212.8,296.6,366.4,425.5,488.9,558.2,314.8,449.6,570.4,680.5,794.9,925.5,251.6,359.6,456.9,547.7,646,760.1,207,207,269,332,394,467];
skiPackageRateInfo[73] = [new Date(2012,2-1,13),146.3,205.5,251.8,286.2,342.2,394.9,209.5,295.5,365.3,419,494.8,564,311.5,448.5,569.3,674,811.1,941.6,248.3,358.5,455.8,541.2,658.5,772.5,207,207,269,332,415,467];
skiPackageRateInfo[74] = [new Date(2012,2-1,14),146.3,205.5,251.8,294.9,350.8,402.5,209.5,295.5,365.3,431.4,507.1,575.3,311.5,448.5,569.3,696.7,833.7,963.2,248.3,358.5,455.8,560.2,677.4,790.4,207,207,269,373,415,467];
skiPackageRateInfo[75] = [new Date(2012,2-1,15),146.3,205.5,261.5,303.5,358.3,411.1,209.5,295.5,378.7,443.7,518.3,587.6,311.5,448.5,593,719.3,855.2,985.8,248.3,358.5,475.8,579.1,695.2,809.3,207,207,301,373,415,467];
skiPackageRateInfo[76] = [new Date(2012,2-1,16),146.3,215.2,272.3,311,367,419.7,209.5,308.9,393.2,454.9,530.7,599.9,311.5,472.2,617.8,740.8,877.9,1008.4,248.3,378.5,496.9,596.9,714.2,828.2,207,228,301,373,415,467];
skiPackageRateInfo[77] = [new Date(2012,2-1,17),152.8,223.8,283,319.6,375.6,427.2,219.7,321.2,407.6,467.2,543,611.1,332,494.8,642.5,763.4,900.5,1029.9,265.1,397.4,517.9,615.8,733.1,846,228,228,301,373,415,467];
skiPackageRateInfo[78] = [new Date(2012,2-1,18),159.3,233.5,292.7,328.2,383.1,435.8,229.9,334.6,421,479.5,550.5,623.4,352.5,518.5,666.2,786,908,1052.5,281.9,417.4,537.9,634.7,740.6,864.9,228,228,301,373,415,467];
skiPackageRateInfo[79] = [new Date(2012,2-1,19),159.3,233.5,292.7,328.2,383.1,435.8,229.9,334.6,421,479.5,554.2,623.4,352.5,518.5,666.2,786,922,1052.5,281.9,417.4,537.9,634.7,750.9,864.9,228,228,301,373,415,467];
skiPackageRateInfo[80] = [new Date(2012,2-1,21),159.3,233.5,292.7,328.2,383.1,427.2,229.9,334.6,421,479.5,554.2,611.1,352.5,518.5,666.2,786,922,1029.9,281.9,417.4,537.9,634.7,750.9,846,228,228,301,373,415,467];
skiPackageRateInfo[81] = [new Date(2012,2-1,22),159.3,233.5,292.7,328.2,375.6,419.7,229.9,334.6,421,479.5,543,599.9,352.5,518.5,666.2,786,900.5,1008.4,281.9,417.4,537.9,634.7,733.1,828.2,228,228,301,373,415,467];
skiPackageRateInfo[82] = [new Date(2012,2-1,23),159.3,233.5,292.7,319.6,367,411.1,229.9,334.6,421,467.2,530.7,587.6,352.5,518.5,666.2,763.4,877.9,985.8,281.9,417.4,537.9,615.8,714.2,809.3,228,228,301,373,415,467];
skiPackageRateInfo[83] = [new Date(2012,2-1,24),159.3,233.5,283,311,358.3,402.5,229.9,334.6,407.6,454.9,518.3,575.3,352.5,518.5,642.5,740.8,855.2,963.2,281.9,417.4,517.9,596.9,695.2,790.4,228,228,301,373,415,467];
skiPackageRateInfo[84] = [new Date(2012,2-1,25),159.3,223.8,272.3,303.5,350.8,394.9,229.9,321.2,393.2,443.7,507.1,564,352.5,494.8,617.8,719.3,833.7,941.6,281.9,397.4,496.9,579.1,677.4,772.5,228,228,301,373,415,467];
skiPackageRateInfo[85] = [new Date(2012,2-1,26),152.8,215.2,261.5,294.9,342.2,392.8,219.7,308.9,378.7,431.4,494.8,558.2,332,472.2,593,696.7,811.1,925.5,265.1,378.5,475.8,560.2,658.5,760.1,228,228,301,373,415,467];
skiPackageRateInfo[86] = [new Date(2012,2-1,27),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[87] = [new Date(2012,2-1,28),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[88] = [new Date(2012,2-1,29),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[89] = [new Date(2012,3-1,1),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[90] = [new Date(2012,3-1,2),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[91] = [new Date(2012,3-1,3),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[92] = [new Date(2012,3-1,4),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[93] = [new Date(2012,3-1,5),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[94] = [new Date(2012,3-1,6),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[95] = [new Date(2012,3-1,7),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[96] = [new Date(2012,3-1,8),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[97] = [new Date(2012,3-1,9),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[98] = [new Date(2012,3-1,10),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[99] = [new Date(2012,3-1,11),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[100] = [new Date(2012,3-1,12),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[101] = [new Date(2012,3-1,13),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[102] = [new Date(2012,3-1,14),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[103] = [new Date(2012,3-1,15),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[104] = [new Date(2012,3-1,16),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[105] = [new Date(2012,3-1,17),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[106] = [new Date(2012,3-1,18),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[107] = [new Date(2012,3-1,19),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[108] = [new Date(2012,3-1,20),146.3,205.5,251.8,292.7,345.4,389.5,209.5,295.5,365.3,425.5,494.3,551.2,311.5,448.5,569.3,680.5,800.3,908.2,248.3,358.5,455.8,547.7,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[109] = [new Date(2012,3-1,21),146.3,205.5,252.9,298.1,345.4,389.5,209.5,295.5,366.4,430.9,494.3,551.2,311.5,448.5,570.4,685.9,800.3,908.2,248.3,358.5,456.9,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[110] = [new Date(2012,3-1,22),146.3,206.6,255,298.1,345.4,389.5,209.5,296.6,368.5,430.9,494.3,551.2,311.5,449.6,572.5,685.9,800.3,908.2,248.3,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[111] = [new Date(2012,3-1,23),149.6,206.6,255,298.1,345.4,389.5,212.8,296.6,368.5,430.9,494.3,551.2,314.8,449.6,572.5,685.9,800.3,908.2,251.6,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[112] = [new Date(2012,3-1,24),153.9,206.6,255,298.1,345.4,389.5,217.1,296.6,368.5,430.9,494.3,551.2,319.1,449.6,572.5,685.9,800.3,908.2,255.9,359.6,459,553.1,651.4,746.5,207,207,269,332,394,446];
skiPackageRateInfo[113] = [new Date(2012,3-1,25),149.6,206.6,252.9,292.7,340,389.5,212.8,296.6,366.4,425.5,488.9,551.2,314.8,449.6,570.4,680.5,794.9,908.2,251.6,359.6,456.9,547.7,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[114] = [new Date(2012,3-1,26),146.3,205.5,251.8,286.2,340,389.5,209.5,295.5,365.3,419,488.9,551.2,311.5,448.5,569.3,674,794.9,908.2,248.3,358.5,455.8,541.2,646,746.5,207,207,269,332,394,446];
skiPackageRateInfo[115] = [new Date(2012,3-1,27),146.3,205.5,251.8,292.7,345.4,392.8,209.5,295.5,365.3,425.5,494.3,554.5,311.5,448.5,569.3,680.5,800.3,911.5,248.3,358.5,455.8,547.7,651.4,749.8,207,207,269,332,394,446];
skiPackageRateInfo[116] = [new Date(2012,3-1,28),146.3,205.5,252.9,298.1,349.7,396,209.5,295.5,366.4,430.9,498.6,557.7,311.5,448.5,570.4,685.9,804.6,914.7,248.3,358.5,456.9,553.1,655.7,753,207,207,269,332,394,446];
skiPackageRateInfo[117] = [new Date(2012,3-1,29),146.3,206.6,255,300.2,353,399.2,209.5,296.6,368.5,433,501.9,560.9,311.5,449.6,572.5,688,807.9,917.9,248.3,359.6,459,555.2,659,756.2,207,207,269,332,394,446];
skiPackageRateInfo[118] = [new Date(2012,3-1,30),149.6,206.6,255,302.4,357.3,402.5,212.8,296.6,368.5,435.2,506.2,564.2,314.8,449.6,572.5,690.2,812.2,921.2,251.6,359.6,459,557.4,663.3,759.5,207,207,269,332,394,446];
skiPackageRateInfo[119] = [new Date(2012,3-1,31),153.9,204.5,255,304.5,360.5,405.7,217.1,294.5,368.5,437.3,509.4,567.4,319.1,447.5,572.5,692.3,815.4,924.4,255.9,357.5,459,559.5,666.5,762.7,207,207,269,332,394,446];
skiPackageRateInfo[120] = [new Date(2012,4-1,1),144.2,202.3,254,300.2,358.3,402.5,207.4,292.3,367.5,433,507.2,564.2,309.4,445.3,571.5,688,813.2,921.2,246.2,355.3,458,555.2,664.3,759.5,207,207,269,332,394,446];
skiPackageRateInfo[121] = [new Date(2012,4-1,2),133.4,200.2,252.9,297,356.2,400.3,196.6,290.2,366.4,429.8,505.1,562,298.6,443.2,570.4,684.8,811.1,919,235.4,353.2,456.9,552,662.2,757.3,207,207,269,332,394,446];
skiPackageRateInfo[122] = [new Date(2012,4-1,10),133.4,200.2,252.9,297,356.2,387.4,196.6,290.2,366.4,429.8,505.1,549.1,298.6,443.2,570.4,684.8,811.1,906.1,235.4,353.2,456.9,552,662.2,744.4,207,207,269,332,394,446];
skiPackageRateInfo[123] = [new Date(2012,4-1,11),133.4,200.2,252.9,297,343.3,375.6,196.6,290.2,366.4,429.8,492.2,537.3,298.6,443.2,570.4,684.8,798.2,894.3,235.4,353.2,456.9,552,649.3,732.6,207,207,269,332,394,446];
skiPackageRateInfo[124] = [new Date(2012,4-1,12),133.4,200.2,252.9,284.1,330.4,362.6,196.6,290.2,366.4,416.9,479.3,524.3,298.6,443.2,570.4,671.9,785.3,881.3,235.4,353.2,456.9,539.1,636.4,719.6,207,207,269,332,394,446];
skiPackageRateInfo[125] = [new Date(2012,4-1,13),133.4,200.2,238.9,271.2,317.4,350.8,196.6,290.2,352.4,404,466.3,512.5,298.6,443.2,556.4,659,772.3,869.5,235.4,353.2,442.9,526.2,623.4,707.8,207,207,269,332,394,446];
skiPackageRateInfo[126] = [new Date(2012,4-1,14),133.4,186.2,224.9,258.3,304.5,337.9,196.6,276.2,338.4,391.1,453.4,499.6,298.6,429.2,542.4,646.1,759.4,856.6,235.4,339.2,428.9,513.3,610.5,694.9,207,207,269,332,394,446];
skiPackageRateInfo[127] = [new Date(2012,4-1,15),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
//end of table
skiPackageRateInfo[128]=[new Date(2020,01-1,1),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

// now calculate offsets into the array
var skiPackageRateInfo_offset = 0;
var ski_package_length = Math.round(ski_package_day_num);
skiPackageRateInfo_offset = ski_package_length - 1;
	
//Now adjust offset to match package type
skiPackageRateInfo_offset = skiPackageRateInfo_offset + ((ski_package_type - 1) * 6);

//read array to determine ski_package_rate
//search for ski_package_start_date

for (i=1; i < skiPackageRate_arraysize+1; i++) {
//Find table entry too far..
	 skiPackageRate_tableDate = skiPackageRateInfo[i+1][0];
//	 alert(date_to_string(skiPackageRate_tableDate));
if (skiPackageRate_testDate.getTime() < skiPackageRate_tableDate.getTime())
      return(skiPackageRateInfo[i][skiPackageRateInfo_offset]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->
//--------------------New Function ski_package_3f2_rate_array()-------------------------------
function ski_package_3f2_rate_array(ski_package_start_date,ski_package_type,ski_package_day_num) {
//this function searches the ski package 3f2 rate array
// the function call inputs the ski_package_start_date, package type, and number of days
// and outputs the requested array parameter
// the format is identical to ski_package_rate_array


//define the array
var skiPackage3f2Rate_arraysize = 57;
skiPackage3f2Rate_tableDate = new Date();
skiPackage3f2Rate_testDate = new Date(ski_package_start_date);
//alert(skiPackage3f2Rate_testDate);
var return_null = 0;
var skiPackage3f2RateInfo = [skiPackage3f2Rate_arraysize];
// 3f2Rate Table

//Ski Paclages not available after April 30, 2005
skiPackage3f2RateInfo[1] = [new Date(2005,5-1,1),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

// ESTIMATED Ski Package prices For 2011/2012 season.
skiPackage3f2RateInfo[2] = [new Date(2011,11-1,19),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[3] = [new Date(2011,11-1,28),,148.5,219.5,,,,,238.5,333,,,,,391.5,537,,,,,301.5,423.5,,,,,207,269,,,];
skiPackage3f2RateInfo[4] = [new Date(2011,11-1,30),,148.5,0,,,,,238.5,0,,,,,391.5,0,,,,,301.5,0,,,,,207,0,,,];
skiPackage3f2RateInfo[5] = [new Date(2011,12-1,1),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[6] = [new Date(2011,12-1,5),,148.5,219.5,,,,,238.5,333,,,,,391.5,537,,,,,301.5,423.5,,,,,207,269,,,];
skiPackage3f2RateInfo[7] = [new Date(2011,12-1,7),,148.5,0,,,,,238.5,0,,,,,391.5,0,,,,,301.5,0,,,,,207,0,,,];
skiPackage3f2RateInfo[8] = [new Date(2011,12-1,8),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[9] = [new Date(2011,12-1,12),,148.5,219.5,,,,,238.5,333,,,,,391.5,537,,,,,301.5,423.5,,,,,207,269,,,];
skiPackage3f2RateInfo[10] = [new Date(2011,12-1,14),,148.5,0,,,,,238.5,0,,,,,391.5,0,,,,,301.5,0,,,,,207,0,,,];
skiPackage3f2RateInfo[11] = [new Date(2011,12-1,15),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[12] = [new Date(2011,12-1,19),,148.5,219.5,,,,,238.5,333,,,,,391.5,537,,,,,301.5,423.5,,,,,207,269,,,];
skiPackage3f2RateInfo[13] = [new Date(2011,12-1,20),,148.5,219.5,,,,,238.5,336.7,,,,,391.5,540.7,,,,,301.5,423.5,,,,,207,269,,,];
skiPackage3f2RateInfo[14] = [new Date(2011,12-1,21),,148.5,0,,,,,242.2,0,,,,,395.2,0,,,,,301.5,0,,,,,207,0,,,];
skiPackage3f2RateInfo[15] = [new Date(2011,12-1,22),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[16] = [new Date(2012,1-1,2),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[17] = [new Date(2012,1-1,4),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[18] = [new Date(2012,1-1,5),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[19] = [new Date(2012,1-1,9),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[20] = [new Date(2012,1-1,10),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,569.9,,,,,318.7,456.4,,,,,207,301,,,];
skiPackage3f2RateInfo[21] = [new Date(2012,1-1,11),,165.7,0,,,,,255.7,0,,,,,419,0,,,,,329,0,,,,,228,0,,,];
skiPackage3f2RateInfo[22] = [new Date(2012,1-1,12),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[23] = [new Date(2012,1-1,16),,165.7,242.1,,,,,259.4,359.3,,,,,412.4,563.3,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[24] = [new Date(2012,1-1,17),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[25] = [new Date(2012,1-1,18),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[26] = [new Date(2012,1-1,19),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[27] = [new Date(2012,1-1,23),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[28] = [new Date(2012,1-1,25),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[29] = [new Date(2012,1-1,26),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[30] = [new Date(2012,1-1,30),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[31] = [new Date(2012,2-1,1),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[32] = [new Date(2012,2-1,2),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[33] = [new Date(2012,2-1,6),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[34] = [new Date(2012,2-1,8),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[35] = [new Date(2012,2-1,9),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[36] = [new Date(2012,2-1,13),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[37] = [new Date(2012,2-1,15),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[38] = [new Date(2012,2-1,16),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[39] = [new Date(2012,2-1,27),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[40] = [new Date(2012,2-1,29),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[41] = [new Date(2012,3-1,1),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[42] = [new Date(2012,3-1,5),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[43] = [new Date(2012,3-1,7),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[44] = [new Date(2012,3-1,8),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[45] = [new Date(2012,3-1,12),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[46] = [new Date(2012,3-1,14),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[47] = [new Date(2012,3-1,15),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[48] = [new Date(2012,3-1,19),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[49] = [new Date(2012,3-1,21),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[50] = [new Date(2012,3-1,22),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[51] = [new Date(2012,3-1,26),,165.7,242.1,,,,,255.7,355.6,,,,,408.7,559.6,,,,,318.7,446.1,,,,,207,269,,,];
skiPackage3f2RateInfo[52] = [new Date(2012,3-1,28),,165.7,0,,,,,255.7,0,,,,,408.7,0,,,,,318.7,0,,,,,207,0,,,];
skiPackage3f2RateInfo[53] = [new Date(2012,3-1,29),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];
skiPackage3f2RateInfo[54] = [new Date(2012,4-1,2),,148.5,222.8,,,,,238.5,336.3,,,,,391.5,540.3,,,,,301.5,426.8,,,,,207,269,,,];
skiPackage3f2RateInfo[55] = [new Date(2012,4-1,4),,148.5,0,,,,,238.5,0,,,,,391.5,0,,,,,301.5,0,,,,,207,0,,,];
skiPackage3f2RateInfo[56] = [new Date(2012,4-1,5),,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,,,0,0,,,];

//end of package information
skiPackage3f2RateInfo[57] = [new Date(2020,4-1,25),,0,0,,,,,0,0,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
//end of table

// now calculate offsets into the array
var skiPackage3f2RateInfo_offset = 0;
var ski_package_length = Math.round(ski_package_day_num);
skiPackage3f2RateInfo_offset = ski_package_length - 1;
	
//Now adjust offset to match package type
skiPackage3f2RateInfo_offset = skiPackage3f2RateInfo_offset + ((ski_package_type - 1) * 6);

//read array to determine ski_package_rate
//search for ski_package_start_date

for (i=1; i < skiPackage3f2Rate_arraysize+1; i++) {
//Find table entry too far..
	 skiPackage3f2Rate_tableDate = skiPackage3f2RateInfo[i+1][0];
//	 alert(date_to_string(skiPackage3f2Rate_tableDate));
if (skiPackage3f2Rate_testDate.getTime() < skiPackage3f2Rate_tableDate.getTime())
      return(skiPackage3f2RateInfo[i][skiPackage3f2RateInfo_offset]);
else {
	continue;
     }
	}
return(return_null);
}
// -->

// -----------New Function  ski_ticket_rate_calculator() -----------------
function ski_ticket_rate_calculator(check_in_date, total_nights, room_type, ski_package_start_date,guestpackagetype, guestpackagelength) {
// this function will return a ski ticket package price based upon the following criteria
// if arrival is Sunday, Monday or Tuesday and the total nights > 2 and 
// if the guest package length is 3 or 4, it will check to see if a special 3 for 2 offer is available
// based upon the guests checkin date and the room type.
// if a special offer is available, it will return the price from the ski_package_rack_rate_array
// if a special offer is not available, or if the length is not 3 or 4 days, it will return the price
// from the ski_package_rate_array

//  A.  If Arrival date is a sunday or monday or tuesday, and ski start date is not sunday, proceed with check for 4 for 3 discount, otherwise, continue checking discounts
if(check_in_date.getDay() < 3 && ski_package_start_date.getDay() > 0) {
// 	check in day is sunday or monday or tuesday
// 	If the package length  is 3 of 4 and the length of stay are 4 days
		if(total_nights == 4 && (guestpackagelength == 4 || guestpackagelength == 3 )) {
//	Check to see if  4 for 3 is available.  
//	If it is, return package price from ski_package_rack_rate_array with packagelength set minus 1
//	otherwise, continue.
		var ski_package_free_day = ski_3for2_discount_array(check_in_date,room_type);
			if(ski_package_free_day == 1) {
				if(ski_package_3f2_rate_array(ski_package_start_date,guestpackagetype,guestpackagelength) > 0) { 
					return(ski_package_3f2_rate_array(ski_package_start_date,guestpackagetype,guestpackagelength));}
			} // end of test for ski package free day
	} // end total nights and packagelength check
} //end sunday/monday check
//B.If Arrival date is a sunday or monday or tuesday, and ski start date is not sunday, proceed with check for 4 for 3 discount,  otherwise, continue checking discounts
if(check_in_date.getDay() < 3 && ski_package_start_date.getDay() > 0) {
// 	check in day is sunday or monday or tuesday
// 	If the package length and the length of stay are 3 days
		if(total_nights == 3 && guestpackagelength == 3) {
//	Check to see if  3 for 2 is available.  
//	If it is, return package price from ski_package_rack_rate_array with packagelength set minus 1
//	otherwise, continue.
		var ski_package_free_day = ski_3for2_discount_array(check_in_date,room_type);
			if(ski_package_free_day == 1) {
			return(ski_package_3f2_rate_array(ski_package_start_date,guestpackagetype,guestpackagelength));
			} // end of test for ski package free day
	} // end total nights and packagelength check
} //end sunday/monday/tuesday check
//C.	having arrived here, no ski free days are available.  Check for normal discounted ski package prices

return(ski_package_rate_array(ski_package_start_date,guestpackagetype,guestpackagelength));
}
 //-->


// -----------New Function  ski_package_room_discount_calculator() -----------------
function ski_package_room_discount_calculator(check_in_date, calculated_date,day_of_stay,total_nights, room_type,  guest1packagelength, guest2packagelength, guest1packagestartdate, guest2packagestartdate) {
// this function will return a ski package discount based upon the following criteria
//  A.  If Arrival date is a sunday, proceed with check for ski week, 
//  otherwise, continue checking discounts
if (check_in_date.getDay() == 0) {
// 	check in day is Sunday
// 	If the package length and the length of stay are 5
		if(total_nights == 5 && (guest1packagelength == 5 || guest2packagelength == 5)) {
//	Check to see if  Ski Week Discount is available.  
//	If it is, return ski week discount
//	otherwise, continue checking discounts.
		var ski_week_discount = ski_week_discount_array(check_in_date,room_type);
			if(ski_week_discount > 0) {
			return(ski_week_discount);
			} 
			// end of test for ski week discount
	} 
	// end total nights and packagelength check
} 
// end sunday check
// B.   If Arrival date is a sunday or monday, proceed with check for 4 for 3 discount, 
// otherwise, continue checking discounts
// now verify that package start date is not sunday
var ski_packge_room_discount_startDate = "TRUE";
if(guest1packagelength >2 && guest1packagestartdate.getDay() == 0){ski_packge_room_discount_startDate = "FALSE";}
if(guest2packagelength >2 && guest2packagestartdate.getDay() == 0){ski_packge_room_discount_startDate = "FALSE";}
if(check_in_date.getDay() < 2 && ski_packge_room_discount_startDate == "TRUE") {
// 	check in day is sunday, monday or tuesday.
// 	If the package length  is 3 or 4 and the length of stay are 4 days
		if(total_nights == 4 && (guest1packagelength > 2 || guest2packagelength > 2)) {
//	Check to see if  4 for 3 is available.  
//	If it is, and this is day 0, 1, or 3, return 0 discount
//	if it is and this is day 2, return 100% discount (free day
//	otherwise, continue checking discounts.
		var ski_package_free_day = ski_3for2_discount_array(check_in_date,room_type);
			if(ski_package_free_day == 1) {
			// add exclusion dates for around thanksgiving
			nov23 = new Date(2009, 11-1, 23).getTime();
			nov24 = new Date(2009, 11-1, 24).getTime();
			exclude_check_in_date = new Date(check_in_date).getTime();
			if(exclude_check_in_date > nov24 || exclude_check_in_date < nov23)
				{ //proceedn normally
					if(day_of_stay == 2)
					{
					return(1);
					} //end of test for fourth day
				}
				// if here then the date is between Nov 22 and Nov 24
				// want to set Nov 24 to 1
			else if ((exclude_check_in_date == nov23 && day_of_stay == 1) || (exclude_check_in_date == nov24 && day_of_stay == 0))
				{// special date
				return(1);
				}
			return(0);
			} // end of test for ski package free day
	} // end total nights and packagelength check
} //end sunday/monday/tuesday check
//C.If Arrival date is a sunday or monday or tuesday, proceed with check for 4 for 3 discount, 
//  otherwise, continue checking discounts
if(check_in_date.getDay() < 3 && ski_packge_room_discount_startDate == "TRUE") {
// 	check in day is sunday or monday or tuesday
// 	If the package length and the length of stay are 3 days
		if(total_nights == 3 && (guest1packagelength == 3 || guest2packagelength == 3)) {
//	Check to see if  3 for 2 is available.  
//	If it is, and this is day 0, or 1, return 0 discount
//	if it is and this is day 2, return 100% discount (free day
//	otherwise, continue checking discounts.
		var ski_package_free_day = ski_3for2_discount_array(check_in_date,room_type);
			if(ski_package_free_day == 1) {
			// add exclusion dates for around thanksgiving
			nov23 = new Date(2009, 11-1, 23).getTime();
			nov24 = new Date(2009, 11-1, 24).getTime();
			exclude_check_in_date = new Date(check_in_date).getTime();
			if(exclude_check_in_date > nov24 || exclude_check_in_date < nov23)
				{ //proceedn normally
					if(day_of_stay == 2)
					{
					return(1);
					} //end of test for fourth day
				}
				// if here then the date is between Nov 22 and Nov 24
				// want to set Nov 24 to 1
			else if ((exclude_check_in_date == nov23 && day_of_stay == 1) || (exclude_check_in_date == nov24 && day_of_stay == 0))
				{// special date
				return(1);
				}
			return(0);
			} // end of test for ski package free day
	} // end total nights and packagelength check
} //end sunday/monday check
//D.	having arrived here, no special offers are available.  Check for normal ski discounts

//Original Code used for all seasons except 2007/2008
return(ski_package_room_discount_array(calculated_date,1));

//new variable rate code valid for 2007/2008 season only - retire in place
//var base_discount = discount_modifier(ski_package_room_discount_array(calculated_date,1), room_type, day_of_stay, total_nights);
//return(base_discount);
}
 //-->

//--------------------New Function discount_modifier()-------------------------------
function discount_modifier(base_discount, room_type, day_of_stay, total_nights) {
// these rules were implemented with the demise of ASC
if(base_discount == 0){return(0);}// if base discount is 0 do not do any work
	var room_type_adjustment = 0;
	var discount_adjustment = 0.00;
	var long_stay_adjustment = 0;
	if(room_type == 1)
		{
		room_type_adjustment = -0.025;		
		//std queen room
		if(day_of_stay > 2)
			{discount_adjustment = (day_of_stay/total_nights)*base_discount;
			}
		if(day_of_stay >3)
			{long_stay_adjustment = base_discount;
			room_type_adjustment = 0.12;
			}
		if(day_of_stay >4)
			{//long_stay_adjustment = base_discount/day_of_stay;
			long_stay_adjustment = 0;
			discount_adjustment = 0;
			room_type_adjustment = -0.015;		
			}
		if(base_discount < 0.06)
			{// weekend or holiday
//				room_type_adjustment = 0;
				discount_adjustment = 0;
				long_stay_adjustment = 0;
			}
		}

	if(room_type == 2)
		{//King room
		room_type_adjustment = -0.025;
		if(day_of_stay > 2)
			{discount_adjustment = (0.1)*base_discount;
			}
		if(day_of_stay >3)
			{long_stay_adjustment = base_discount;
			room_type_adjustment = 0.075;
			}
		if(day_of_stay >4)
			{//long_stay_adjustment = base_discount/day_of_stay;
			long_stay_adjustment = 0;
			discount_adjustment = 0;
			room_type_adjustment = -0.025;		
			}
		if(base_discount < 0.06)
			{// weekend or holiday
//				room_type_adjustment = 0;
				discount_adjustment = 0;
				long_stay_adjustment = 0;
			}

		}

	if(room_type > 2)
		{//wpl room
		room_type_adjustment = -0.045;
		if(day_of_stay > 2)
			{discount_adjustment = (0.1)*base_discount;
			}
		if(day_of_stay >3)
			{long_stay_adjustment = base_discount;
			room_type_adjustment = 0.05;
			}
		if(day_of_stay >4)
			{//long_stay_adjustment = base_discount/day_of_stay;
			long_stay_adjustment = 0;
			discount_adjustment = 0;
			room_type_adjustment = -0.035;		
			}
		if(base_discount < 0.06)
			{// weekend or holiday
//				room_type_adjustment = 0;
				discount_adjustment = 0;
				long_stay_adjustment = 0;
			}
		}
var	calculated_discount = base_discount + discount_adjustment + room_type_adjustment + long_stay_adjustment;
//alert("day of stay = " + day_of_stay + " and base_discount = " + base_discount +" and discount_adjustment = " + discount_adjustment +" and room_type_adjustment = " + room_type_adjustment +" and long_stay_adjustment = " + long_stay_adjustment+  " and calculated_discount = " + calculated_discount);
if(calculated_discount > 0 ){base_discount=calculated_discount;}
if(calculated_discount < 0 || calculated_discount == 0){base_discount = 0;}
return(base_discount);

}


//--------------------New Function ski_week_discount_array()-------------------------------
function ski_week_discount_array(room_date,var_id) {
//this function searches the ski week discount array
// the function call inputs the room_date, and outputs the requested array parameter from 0 to 5
//the array is arranged as
//skiweekDiscount = 
//skiweekDiscount[n][0]=(Date(y,m-1,d)
//skiweekDiscount[n][1]=(queen)
//skiweekDiscount[n][2]=(king)
//skiweekDiscount[n][3]=(qwpl)
//skiweekDiscount[n][4]=(kwpl)
//where queen, king, qwpl, kqwpl refer to the special offer value in percent. 0 equates to no special offer

//define the array
var offerarraysize = 8;
offerDate = new Date();
offertestDate = new Date(room_date);
//alert(offerDate);
var return_null = 0;
var skiweekDiscount = [offerarraysize];

// First Entry : set to null
skiweekDiscount[1] = [new Date(2005,10-1,1), 0,0,0,0];

//2011/2012 Season
skiweekDiscount[2] = [new Date(2011,10-1,30),0.15, 0.15,0.15,0.15];
// offer change christmas week
skiweekDiscount[3] = [new Date(2011,12-1,25),0.04, 0.04,0.04,0.04];
// offer change in first week of January
skiweekDiscount[4] = [new Date(2012,1-1,1),0.15, 0.15,0.15,0.15];
// offer change Presidents week
skiweekDiscount[5] = [new Date(2012,2-1,19),0.04, 0.04,0.04,0.04];
// offer change for remainder of season
skiweekDiscount[6] = [new Date(2012,2-1,26),0.15, 0.15,0.15,0.15];
//end of offer
skiweekDiscount[7] = [new Date(2012,5-1,6),0,0,0,0];

//end of table
skiweekDiscount[8] = [new Date(2020,5-1,1),0,0,0,0];

//search for room_date

for (i=1; i < offerarraysize+1; i++) {
//Find table entry too far..
	 offerDate = skiweekDiscount[i+1][0];
if (offertestDate.getTime() < offerDate.getTime())
	return(skiweekDiscount[i][var_id]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->


//--------------------New Function ski_3for2_discount_array()-------------------------------
function ski_3for2_discount_array(room_date,var_id) {
//this function searches the ski3for2Discount array
// the function call inputs the room_date, and outputs the requested array parameter from 0 to 5
//the array is arranged as
//ski3for2Discount = 
//ski3for2Discount[n][0]=(Date(y,m-1,d)
//ski3for2Discount[n][1]=(queen)
//ski3for2Discount[n][2]=(king)
//ski3for2Discount[n][3]=(qwpl)
//ski3for2Discount[n][4]=(kwpl)
//where queen, king, qwpl, kqwpl refer to the special offer value in percent. 0 equates to no special offer


//define the array
var offerarraysize = 12;
offerDate = new Date();
offertestDate = new Date(room_date);
//alert(offerDate);
var return_null = 0;
var ski3for2Discount = [offerarraysize];
// First Entry : set to null
ski3for2Discount[1] = [new Date(2005,10-1,1), 0,0,0,0];
//Start of Offer - Beginning of November
ski3for2Discount[2] = [new Date(2011,11-1,1),0,0,0,0];
//Not offered week before lift tickets for sale
ski3for2Discount[3] = [new Date(2011,11-1,20),0, 0,0,0];
// offered after Thanksgiving
ski3for2Discount[4] = [new Date(2011,11-1,27),1, 1,1,1];
//Not offered over Christmas
ski3for2Discount[5] = [new Date(2011,12-1,25),0, 0,0,0];
// Offered after New Years
ski3for2Discount[6] = [new Date(2012,1-1,2),1, 1,1,1];
//   Offered MLK Sunday
ski3for2Discount[7] = [new Date(2012,1-1,16),1, 1,1,1];
// Offered after MLK
ski3for2Discount[8] = [new Date(2012,1-1,17),1, 1,1,1];
// not offered presidents week
ski3for2Discount[9] = [new Date(2012,2-1,19),0, 0,0,0];
// offered after presidents week
ski3for2Discount[10] = [new Date(2012,2-1,25),1, 1,1,1];
// end if offer end of march
ski3for2Discount[11] = [new Date(2012,4-1,6),0, 0,0,0];
//end of table
ski3for2Discount[12] = [new Date(2020,5-1,1),0,0,0,0];

//search for room_date

for (i=1; i < offerarraysize+1; i++) {
//Find table entry too far..
	 offerDate = ski3for2Discount[i+1][0];
if (offertestDate.getTime() < offerDate.getTime())
	return(ski3for2Discount[i][var_id]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->

//--------------------New Function truncate to 2 decimal points()-------------------------------
function truncate_decimal(num) {
//this function takes a decimal number of undefined length and truncate's it to 2 decimal places.

var left_of_decimal_point = Math.round(num);
var right_of_decimal_point = Math.round((num - left_of_decimal_point)*100)/100;
return(left_of_decimal_point + right_of_decimal_point);
}
// -->

//--------------------New Function Get_correct_year()-------------------------------
function get_correct_year() {
//this function calculates the correct year in 4 digits.  
//It corrects for some Java implementations which return year values less 1900.
var year_offset = 1900;
var today = new Date();
if (today.getYear() > 2000)
	{year_offset = 0;
	}
return(today.getYear() + year_offset);

}
// -->

//-------------------New Function  Write Pulldown Boxfor days of month()---------
function write_day(name, num_of_days,num_tab,action,start_day) {
//This function writes a pull down box representing days of the month.
//Input parameters
// Name which represents the start of the pull dawn identification name_dayr
// num_of_days which indicates the number of days in the pull down
// start_day which indicates the first entry in the table
// num_tab indicates the tab index for this pull down
// action is of the form 'onAction = "action();"'
// This function will also set the pull down to select the current day of the month if it is in the output manth if it is in the pull down.

var today = new Date();
var day_outcode = '<!-- start of automatically generated code -->';
day_outcode = day_outcode + '<select class="listfield" name="' + name +'_day" size="1" tabindex="'+ num_tab + '" ' + action + '>';
for (i = 0; i < num_of_days ; i++) {
var select_string = ' ';
if (start_day + i == today.getDate()) {
select_string = ' selected';
}
day_outcode = day_outcode 
				+ '<option'
				+ select_string
				+ ' value="'
				+ (start_day+i)
				+ '"' 
				+ '>'
				+ (start_day+i)
				+ '</option>';
}
day_outcode = day_outcode +'</select>';
return(day_outcode);
}
// -->

//-------------------New Function  Write Pulldown Box with multiple years()---------
function write_year(name, num_of_years,num_tab,action) {
//This function writes a pull down box representing years.
//Input parameters
// Name which represents the start of the pull dawn identification name_year
// num_of_years which indicates the number of years in the pull down
// num_tab indicates the tab index for this pull down
// action is of the form 'onAction = "action();"'
// This function will also set the pull down to select the current year.

var first_year = 2011;
var year_outcode = '<!-- start of automatically generated code -->';
year_outcode = year_outcode + '<select class="listfield" name="' + name +'_year" size="1" tabindex="'+ num_tab + '" ' + action + '>';
for (i = 0; i < num_of_years ; i++) {
var select_string = ' ';
if (first_year + i == get_correct_year()) {
select_string = ' selected';
}
year_outcode = year_outcode 
				+ '<option'
				+ select_string
				+ ' value="'
				+ (first_year+i)
				+ '"' 
				+ '>'
				+ (first_year+i)
				+ '</option>';
}
year_outcode = year_outcode +'</select><br>';
return(year_outcode);
}
// -->

//-------------------New Function  Write Pulldown Box with Months()---------
function write_month(name, num_of_months,num_tab,action,m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11) {
//This function writes a pull down box representing months.
//Input parameters
// Name which represents the start of the pull dawn identification name_month
// num_of_months which indicates the number of months in the pull down
// num_tab indicates the tab index for this pull down
// action is of the form 'onAction = "action();"'
//month1....monthn represents the months to be displayed where 0 = January and 11 = December
// This function will also set the pull down to select the current month if possible.
//special case = if num_of_months = 12, month1...monthn are not required

var today = new Date();
var month_out = " ";
var month_outcode = '<!-- start of automatically generated code -->';
month_outcode = month_outcode + '<select class="listfield" name="' + name +'_month" size="1" tabindex="'+ num_tab + '" ' + action + '>';

for (i = 0; i < num_of_months ; i++) {
var select_string = ' ';
month_id = i;
if (num_of_months < 12) {
month_id = arguments[i + 4];
}

switch(month_id)  {
case 0:
month_out = 'January'
break;

case 1:
month_out = 'February'
break;

case 2:
month_out = 'March'
break;

case 3:
month_out = 'April'
break;

case 4:
month_out = 'May'
break;

case 5:
month_out = 'June'
break;

case 6:
month_out = 'July'
break;

case 7:
month_out = 'August'
break;

case 8:
month_out = 'September'
break;

case 9:
month_out = 'October'
break;

case 10:
month_out = 'November'
break

;case 11:
month_out = 'December'
break;
}


if (month_id == today.getMonth()) {
select_string = ' selected';
}
month_outcode = month_outcode 
				+ '<option'
				+ select_string
				+ ' value="'
				+ month_id
				+ '"' 
				+ '>'
				+ month_out
				+ '</option>';
}
month_outcode = month_outcode +'</select>';
return(month_outcode);
}
// -->

//-------------------New Function  Write Pulldown Box with Specified Input and incrementsl values---------
function write_pulldown(name, num_of_items,num_tab,action,selected_item,first_value,item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11,item12) {
//This function writes a pull down box representing up to 12 different items.
//It assigns a value of 0 to 11 on the item represented
//Input parameters
// Name which represents the start of the pull dawn identification name
// num_of_items a number from 0 to 11 which indicates the total number of items in the list
// num_tab indicates the tab index for this pull down
// action is of the form 'onAction = "action();"'
//selected_item is the item to be selected after the script completes
//first_value represents the first value in sequence from first_value(0) to first_value(num_of_items) in a numerical count (ie 1,2,3,4,5,6)
//Item1....itemn represents the items to be displayed where the value 1 = item 1 and 12 = item12

var pulldown_out = " ";
var pulldown_outcode = '<!-- start of automatically generated code -->';
pulldown_outcode = pulldown_outcode + '<select class="listfield" name="' + name +'" size="1" tabindex="'+ num_tab + '" ' + action + '>';

for (i = 0; i < num_of_items ; i++) {
var select_string = ' ';
if (i + 1 == selected_item) {
select_string = ' selected';
}

pulldown_outcode = pulldown_outcode 
				+ '<option'
				+ select_string
				+' value="'
				+ (i + first_value)
				+ '"' 
				+ '>'
				+ (arguments[i+6])
				+ '</option>';
}
pulldown_outcode = pulldown_outcode +'</select>';
return(pulldown_outcode);
}
// -->

//-------------------New Function  Write Pulldown Box with Specified Input and Specified Values---------
function write_spec_value_pulldown(name, num_of_items,num_tab,action,selected_item,value1,item1, value2, item2, value3, item3, value4, item4, value5, item5, value6, item6, value7, item7, value8, item8, value9, item9, value10, item10, value11, item11,value12, item12) {
//This function writes a pull down box representing up to 12 different items.
//It assigns a value of 0 to 11 on the item represented
//Input parameters
// Name which represents the start of the pull dawn identification name
// num_of_items a number from 0 to 11 which indicates the total number of items in the list
// num_tab indicates the tab index for this pull down
// action is of the form 'onAction = "action();"'
//selected_item is the item to be selected after the script completes
//first_value represents the first value in sequence from first_value(0) to first_value(num_of_items) in a numerical count (ie 1,2,3,4,5,6)
//Item1....itemn represents the items to be displayed where the value 1 = item 1 and 12 = item12

//a = new Array(name, num_of_items,num_tab,selected_item,value1,item1, value2, item2, value3, item3, value4, item4, value5, item5, value6, item6, value7, item7, value8, item8, value9, item9, value10, item10, value11, item11,value12, item12);
//alert(a.join(","));

var pulldown_out = " ";
var pulldown_outcode = '<!-- start of automatically generated code -->';
pulldown_outcode = pulldown_outcode + '<select class="listfield" name="' + name +'" size="1" tabindex="'+ num_tab + '" ' + action + '>';
for (i = 0; i < num_of_items ; i++) {
var select_string = ' ';
if (i + 1 == selected_item) {
select_string = ' selected';
}
pulldown_outcode = pulldown_outcode 
				+ '<option'
				+ select_string
				+' value="'
				+ (arguments[(i*2)+5])
				+ '"' 
				+ '>'
				+ (arguments[(i*2)+6])
				+ '</option>';
}
pulldown_outcode = pulldown_outcode +'</select>';
//alert(pulldown_outcode);
return(pulldown_outcode);
}
// -->




//-------------------New Function  trigger tee time window---------
function trigger_tee_time_window() {
// this function writes a cookie to pass information from a golf package window to a select tee time window
//  It passes the following values to the cookie:
// 1.  The arrival date from the rate form
// 2.  The Total number of nights to stay from the rate form
// 3.  The number of tee times from the rate form.

//  To begin, it must read the data:

//Read Date Info

// This function reads the arrival date from the rate form and performs a validity checks.
// It returns the a requested resultin an array delimited by ","
//  Element		Arry positon		Retun Value
//	"Year"			0				Arrival Pulldown, Year Value
//  "Month"			1				Arrival Pulldown, Month Value
//  "Day"			2				Arrival Pulldown, Day Value
//  "warning"		3				Null or Text with warning.  also generates an alert
//  "detail"		4				Null or Text with warning.  also generates and alert

// first : verify print out format
// set print out format flag...
// 0 equals detailed output
// 1 equals summary custtomer output

var print_out_style_flag = 1;
//if(document.Rate_Form.result_box.value == "detail")
if(document.getElementById("results_box").value == "detail")
	{print_out_style_flag = 0;
	}
//if(document.Rate_Form.result_box.value == "no detail")
if(document.getElementById("results_box").value == "no detail")
	{print_out_style_flag = 1;
	}

var invalid_data_entry_warning = "";
var invalid_data_entry_warning_flag = 0;

//now read and validate date information.

var arrival_date_array = new Array(5);
arrival_date_array = read_arrival_date().split(",");
var year = arrival_date_array[0];
var month = arrival_date_array[1];
var day_of_month = arrival_date_array[2];

// validate that the arrival date is a valid date
invalid_data_entry_warning = arrival_date_array[3];
if(invalid_data_entry_warning != "") 
		{invalid_data_entry_warning_flag = 1;
		alert(invalid_data_entry_warning);
		}
// validate that arrival date is >= current date
// only check if not looking for detail information

if(print_out_style_flag ==1)
{
if(arrival_date_array[4] != "") 
		{invalid_data_entry_warning = arrival_date_array[4];
		invalid_data_entry_warning_flag = 1;
		alert(invalid_data_entry_warning);
		}
}

// read golf specific information

var total_nights = document.Rate_Form.number_of_nights.options[document.Rate_Form.number_of_nights.selectedIndex].value;
var total_tee_times = document.Rate_Form.number_of_tee_times.options[document.Rate_Form.number_of_tee_times.selectedIndex].value;

//Create golf cookie array

var golf_cookie_array = new Array(5);
golf_cookie_array = [year,month,day_of_month,total_nights,total_tee_times];

// if data is wrong, print out message and end
if(invalid_data_entry_warning_flag > 0)
	{
	// if there is a warning, over write result box
	//document.Rate_Form.result_box.value = invalid_data_entry_warning;
	document.getElementById("results_box").value = invalid_data_entry_warning;
	//write_cookie("briprint",document.Rate_Form.result_box.value);
	write_cookie("briprint",document.getElementById("results_box").value);
	return;
	}

//otherwise...pass golf cookie and open new window
var vwidth = '"height=600,'
	+ 'width=500,'
	+ 'scrollbars=yes"';

write_cookie("brigolf",golf_cookie_array.join(","));

// set up output cookie briteetimes and set first set first element to 0 to indicate work to be done.

write_cookie("briteetimes",0);

window.open("select_golf_tee_times.html","tee_time_page","height=600,width=700,scrollbars=yes");
return;
}


// -->

//-------------------New Function  Read and validate arrival date---------
function read_arrival_date() {

// This function reads the arrival date from the rate form and performs a validity checks.
// It returns the a requested resulting an array delimited by ","
//  Element		Arry positon		Retun Value
//	"Year"			0				Arrival Pulldown, Year Value
//  "Month"			1				Arrival Pulldown, Month Value
//  "Day"			2				Arrival Pulldown, Day Value
//  "warning"		3				Null or Text with warning.  also generates an alert
//  "detail"		4				Null or Text with warning.  also generates and alert


//Read Date Info
var year =document.Rate_Form.arrival_year.options[document.Rate_Form.arrival_year.selectedIndex].value;
var month=document.Rate_Form.arrival_month.options[document.Rate_Form.arrival_month.selectedIndex].value;
var day_of_month=document.Rate_Form.arrival_day.options[document.Rate_Form.arrival_day.selectedIndex].value;
var warning = "";
var detail = "";

if(checkDate(year,month,day_of_month) > 0)
		{warning = "\r"+ "Reservation Arrival Date is invalid! Too many days selected for month.";
//		alert("Reservation Arrival Date is invalid!  Too many days selected for month.");
		}
var today = new Date();
if (today > getDateinfo(year,month,day_of_month,1))
		{detail = "\r" + "Reservation Arrival Date is invalid!.  Arrival date needs to be today or greater";
//		alert("Reservation Arrival Date is invalid!  Arrival date needs to be today or greater");
		}

var out_date = new Array(5)
out_date = [year,month,day_of_month,warning,detail];
return(out_date.join(","));

}

// -->

//--------------------New Function send tee time info back()-------------------------------
function send_tee_time_info_back() {
//this function acts in response to a compute golf package click on the select_golf_tee_times page
//it reads reads the selected tee time information from the page
// validates that the selected tee dates are withing the room reservation dates
// and reforms the golf cookie with complete information to send back to the golf package page

// read golf cookie contents
var golf_cookie_array = new Array(5);

//golf_cookie_array  is formed as [year,month,day_of_month,total_nights,total_tee_times]
// read and unpack golf cookie array
golf_cookie_array = read_cookie("brigolf").split(",");

//unpack contents
var year = parseInt(golf_cookie_array[0]);
var month = parseInt(golf_cookie_array[1]);
var day_of_month = parseInt(golf_cookie_array[2]);
var total_nights = parseInt(golf_cookie_array[3]);
var total_tee_times = parseInt(golf_cookie_array[4]);

// now create a new array to output cookie back to package calculator page.
var cookie_out_array = new Array(total_tee_times * 9);

// cookie_out_array will be structured
// [0]  0, not ready for calculation, 1, ready for calculation , 2 calculation in process
// [1 - 5] golf cookie array calues [0-4]
// [Total tee times * 4 +2 ]  tee time date in machine readable format
// [Total tee times * 4 +3 ]  tee time 
// [Total tee times * 4 +4 ]  tee people
// [Total tee times * 4 +5 ]  tee course


// now copy first 5 elements from golf_cookie_array to cookie_out_array elements 1 thru 6
for(i=0; i<5;i++) {
cookie_out_array[i+1] = golf_cookie_array[i];
}

// calculate an arrival date and a departure date for use in testings

var arrival_date = getDateinfo(year,month,day_of_month,0);
var total_days = total_nights+1;
var departure_day = getDateinfo(year, month, day_of_month, total_days);

//  now set up loop and read and validate tee time information

var tee_time_number = 0;

for (i=0; i<total_tee_times; i++) {
tee_time_number = i+1;

// now read tee time information.  Start by creating names to read the pull down boxes

var month_object_name = "tee_time_month_" + tee_time_number + "_month";
var day_object_name = "tee_time_day_" + tee_time_number;
var year_object_name = "tee_time_year_" + tee_time_number;
var time_object_name = "tee_time_" + tee_time_number;
var people_object_name = "tee_time_players_" + tee_time_number;
var course_object_name = "golf_course_" + tee_time_number;


var tee_month =document.golf_tee_time_selector[month_object_name].options[document.golf_tee_time_selector[month_object_name].selectedIndex].value;
var tee_day =document.golf_tee_time_selector[day_object_name].options[document.golf_tee_time_selector[day_object_name].selectedIndex].value;
var tee_year =document.golf_tee_time_selector[year_object_name].options[document.golf_tee_time_selector[year_object_name].selectedIndex].value;
var tee_time =document.golf_tee_time_selector[time_object_name].options[document.golf_tee_time_selector[time_object_name].selectedIndex].value;
var tee_people =document.golf_tee_time_selector[people_object_name].options[document.golf_tee_time_selector[people_object_name].selectedIndex].value;
var tee_course =document.golf_tee_time_selector[course_object_name].options[document.golf_tee_time_selector[course_object_name].selectedIndex].value;

// translate tee time into a machine readable date

var tee_date = getDateinfo(tee_year, tee_month, tee_day, 0);

// now validate that the tee date is greater than the arrival date
if(tee_date < arrival_date) {
alert("Please check the date of Tee Time " + tee_time_number + ".  It appears to be set to a date before you arrive at the inn.");
// if alert, abort the process and go back
return;
}

// now validate that the tee date is less than the departure date
if(tee_date > departure_day) {
alert("Please check the date of Tee Time " + tee_time_number + ".  It appears to be set to a date after you depart from the inn.");
// if alert, abort the process and go back
return;
}

// tee dates are valid.... now pass tee date plus information into cookie_out_array

cookie_out_array[tee_time_number*6] = tee_year;
cookie_out_array[(tee_time_number*6)+1] = tee_month;
cookie_out_array[(tee_time_number*6)+2] = tee_day;
cookie_out_array[(tee_time_number*6)+3] = tee_time;
cookie_out_array[(tee_time_number*6)+4] = tee_people;
cookie_out_array[(tee_time_number*6)+5] = tee_course;


}
// now set cookie_out_array[0] to 1 to indicate that tee time is ready to be processed
cookie_out_array[0] = 1;

// all done, write cookie
write_cookie("briteetimes",cookie_out_array.join(","));
self.close();
return;

}

// -->

//-------------------New Function  Price Green Mountain Golf Course---------

function priceGreenMountain(tee_date) {
//this function returns a price for golf for a single person for Green Mountain National Golf Course
//based on the tee time date requested

//this function searches the Green Mountain Price array
// the function call inputs the tee date, and outputs golf rate
//the array is arranged as
//greenmtnRates = 
//greenmtnRates [0]=(Date(y,m-1,d)
//greenmtnRates [n][1]=(weekend rates)
//greenmtnRates n][2]=(weekday rates)
// Set weekend_offset param to 0 
//where weekend is the rate for Friday, Saturday and Sunday
//where weekday is the rate for Monday through Thursday

//define the array
var arraysize = 13;
var tableDate = new Date();
var testDate = new Date(tee_date);
var weekend_offset = checkWeekend(tee_date,0);
//alert(testDate);
var return_null = 0;
var greenmtnRates = [arraysize];
// Rate Table
greenmtnRates[1] = [new Date(2004,10-1,30), 0,0];
greenmtnRates[2] = [new Date(2011,5-1,1),70.2,60.2];
greenmtnRates[3] = [new Date(2011,5-1,31),70.2,60.2];
greenmtnRates[4] = [new Date(2011,6-1,24),85,85];
greenmtnRates[5] = [new Date(2011,6-1,26),85,75];
greenmtnRates[6] = [new Date(2011,7-1,1),85,85];
greenmtnRates[7] = [new Date(2010,7-1,5),85,75];
greenmtnRates[8] = [new Date(2011,9-1,3),85,85];
greenmtnRates[9] = [new Date(2011,9-1,6),85,75];
greenmtnRates[10] = [new Date(2011,10-1,8),85,75];
greenmtnRates[11] = [new Date(2011,10-1,11),85,75];
greenmtnRates[12] = [new Date(2011,10-1,17),0,0];

//end of table
greenmtnRates[13] = [new Date(2020,5-1,1), 0, 0];


//search for room_date

for (i=1; i < arraysize+1; i++) {
//Find table entry too far..
	 tableDate = greenmtnRates[i+1][0];
if (testDate.getTime() < tableDate.getTime())
      return(greenmtnRates[i][weekend_offset+1]);
else {
	continue;
     }
                                }
return(return_null);
}
// -->

//-------------------New Function  price Killington Golf Course---------

function priceKillingtonGolf(tee_date) {
//this function returns a price for golf for a single person for Killington Resort Golf Course
//based on the tee time date requested

//this function searches the Killington Golf Price array
// the function call inputs the tee date, and outputs golf rate
//the array is arranged as
//killingtongolfRates = 
//killingtongolfRates [0]=(Date(y,m-1,d)
//killingtongolfRates [n][1]=(weekend rates)
//killingtongolfRates n][2]=(weekday rates)
//where weekend is the rate for Saturday and Sunday
//where weekday is the rate for Monday through Thursday

//define the array
var arraysize = 13;
var tableDate = new Date();
var testDate = new Date(tee_date);
var weekend_offset = checkWeekend(tee_date,1);
//alert(testDate);
var return_null = 0;
var killingtongolfRates = [arraysize];
// Rate Table
 killingtongolfRates[1] = [new Date(2004,10-1,130), 0,0]; 
killingtongolfRates[2] = [new Date(2011,5-1,1),0,0];
killingtongolfRates[3] = [new Date(2011,5-1,27),64.2,58.85];
killingtongolfRates[4] = [new Date(2011,6-1,24),69,65];
killingtongolfRates[5] = [new Date(2011,6-1,26),69,65];
killingtongolfRates[6] = [new Date(2011,7-1,1),69,65];
killingtongolfRates[7] = [new Date(2010,7-1,5),69,65];
killingtongolfRates[8] = [new Date(2011,9-1,3),69,65];
killingtongolfRates[9] = [new Date(2011,9-1,6),69,65];
killingtongolfRates[10] = [new Date(2011,10-1,8),69,65];
killingtongolfRates[11] = [new Date(2011,10-1,11),69,65];
killingtongolfRates[12] = [new Date(2011,10-1,17),0,0];
//end of table
killingtongolfRates[13] = [new Date(2020,5-1,1), 0, 0];


//search for room_date

for (i=1; i < arraysize+1; i++) {
//Find table entry too far..
	 tableDate = killingtongolfRates[i+1][0];
if (testDate.getTime() < tableDate.getTime())
      return(killingtongolfRates[i][weekend_offset+1]);
else {
	continue;
     }
                                }
return(return_null);
}

// -->

//-------------------New Function  Check Weekend---------

function checkWeekend(calculated_date, start_weekend) {

// this function determines if a date in the form getDateinfo
// is a weekeday or a weekend
// inputes are calculated_date (ie the date to check)
// start_weekend,  If start_weekend =0, weekend starts on Friday.
//  if start_weekend is 1, weekend starts on Saturday
// return weekend_offset where
//weekend_offset = 0 for weekends
//weekend_offset = 1 for weekdays

var day_of_week = calculated_date.getDay();
var weekend_offset = 0;
	if (day_of_week == 0)		{
	// Sunday is always a weekend
		weekend_offset=0;		}
	else if (day_of_week > 4 + start_weekend)	{
		weekend_offset=0;		}
	else	{
		weekend_offset=1;
			}
return(weekend_offset);
}
// -->
// new functions added when jquery adopted by site
//
//--------------------New Function toggle element()-------------------------------
function bri_toggleID(id, action) {
// this function will toggle an elements display  and visibility states
if (action=="hide") {
	document.getElementById(id).style.display = "none";
	document.getElementById(id).style.visibility = "hidden";
}
else if (action=="show") {
	document.getElementById(id).style.display = "inline";
	document.getElementById(id).style.visibility = "visible";
}
return;   
}
// -->
//--------------------Calculate Room Rates()-------------------------------
function bri_calcRates(package_type_flag){
// this function glues the Rate_Calc functions of birchridge.com into jquery
// it calls the date_loop(package_type_flag) function
// then formats the results propery for jquery
// Input is package_type_flag where 
//  0 == no package
//  1 == ski package
//  2 == golf package
// hide special offer information
bri_toggleID("bri-rateCalc-specOffer", "hide");
// hide results div
bri_toggleID("bri-rateCalc-results", "hide");
// call rate calculation functions
date_loop(package_type_flag);
// now if special offer, show special offer highlight
//if(document.special_offer_image.src != "http://www.birchridge.com/Rooms/no_offer.jpg")
if(document.getElementById('special_offer_image').src != "http://www.birchridge.com/Rooms/no_offer.jpg")
{
	//show special offer
	bri_toggleID("bri-rateCalc-specOffer", "show");
}
//now write to results div and show
//document.getElementById("bri-rateCalc-results").innerText = document.getElementById("results_box").value ;
// due to Firefox innerText bug, replace text return characters with html br tags and use innerHTML function
var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
if(!hasInnerText){
document.getElementById("bri-rateCalc-results").innerHTML = document.getElementById("results_box").value.replace(/\r/g,'<br>');
}
else {
document.getElementById("bri-rateCalc-results").innerText = document.getElementById("results_box").value ;	
}

bri_toggleID("bri-rateCalc-results", "show");
bri_toggleID("bri-rateCalc-newRate", "show");
bri_toggleID("bri-rateCalc-fields", "hide");
return;
}
// -->
//--------------------New Calculate Room Rates()-------------------------------
function bri_newCalc(){
// this function sets up the rate caluclator page for a new calculation
// hide special offer information
bri_toggleID("bri-rateCalc-specOffer", "hide");
// hide results div
bri_toggleID("bri-rateCalc-results", "hide");
// hide new rate button
bri_toggleID("bri-rateCalc-newRate", "hide");
//show calculation fields
bri_toggleID("bri-rateCalc-fields", "show");
return;
}
// -->
// EOF
