// JavaScript function library
// Author : Bill Vines, Birch Ridge Inn, Killington VT
// Copyright : 2011

// Functions which bind across all pages

// Check Availability function 
$(document).delegate('#submitAvailability','click', function() {
	document.getElementById("monthselect").value = parseInt(document.getElementById("Arrival_month").value)+1;
	document.getElementById("dayselect").value = document.getElementById("Arrival_day").value;
	document.getElementById("yearselect").value = document.getElementById("Arrival_year").value;
// changes when went to 2 week calendar //	
//	document.ao_availability_search.submit().value = "Search Availability";
// added 2 lines below
	document.ao_availability_search.submit().name = "Look at All";
	document.ao_availability_search.submit().value = "Go";
	document.ao_availability_search.submit();	
});

//--------------------New Function Get_correct_year()-------------------------------
function briFunc_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 briFunc_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 name="' + name +'_day" id="' + 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 briFunc_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 = briFunc_get_correct_year();
var year_outcode = '<!-- start of automatically generated code -->';
year_outcode = year_outcode + '<select name="' + name +'_year" id="' + name +'_year" size="1" tabindex="'+ num_tab + '" ' + action + '>';
for (i = 0; i < num_of_years ; i++) {
var select_string = ' ';
if (first_year + i == briFunc_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>';
return(year_outcode);
}
// -->

//-------------------New Function  Write Pulldown Box with Months()---------
function briFunc_write_month(name, num_of_months,num_tab,action,value_type,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();"'
// value_type identifies the output value.  T for text values (January-December), J for script values (0-11)
//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 name="' + name +'_month" id="' + 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 + 5];
}

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_value = month_id;
if(value_type == "T"){month_value = month_out;}
month_outcode = month_outcode 
				+ '<option'
				+ select_string
				+ ' value="'
				+ month_value
				+ '"' 
				+ '>'
				+ month_out
				+ '</option>';
}
month_outcode = month_outcode +'</select>';
return(month_outcode);
}
// -->

//-------------------New Function  Write Pulldown Box with Specified Input and incrementsl values---------
function briFunc_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 name="' + name +'" id="' + 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 briFunc_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 name="' + name +'" id="' + 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 toggle element()-------------------------------
function briFunc_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;   
}
// -->

