//sets default variable values
//CONSTANTS
targeturl	= "http://arestravel.com/";
aresid 		= "35";
geonode		= "g3314";

DefaultFirstBookingDayNumDaysOut = 3;

function formSubmit(){
    
}

function write_hotdeals(){
	
	document.write("Hot Deals".link(targeturl+aresid+"/-/hotdeals/"));
	
}

function write_action(theform){
	
	theform.action=targeturl+aresid+"/-/search-submit/"+geonode;
}
function isLeapYear(year)
{
    return (year%4 == 0);
}
function getDaysInMonth(monthNumber, year)
{
    daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if (isLeapYear(year) && monthNumber == 2 )
    {
        return 29;
    }
    return daysInMonth[monthNumber];
        
}
function getDisplayYear(dateYear)
{
    year = String(dateYear);
    //fix a year display bug?
    if(year.length == 3){
        year = "20" + year.substring(1, 3);
    }
    return year;
}
/*
This function should fill some options dropdowns for the booking bot 
The ones it should fill are:
document.hotelquery.elements[1].options[i] = days in month
document.hotelquery.elements[2].options[i] = month - year
document.hotelquery.elements[3].options[i] = number of nights to stay

*/	

 function updateDate(theID)
{
	document.getElementById(theID).value = document.getElementById(theID + 'MonthYear').value + '-' + document.getElementById(theID + 'Day').value;
}

function write_date(){

	todays_date = new Date();
    //this uses the Constant from the top of the file
	defaultStartBookDay =  new Date(getDisplayYear(todays_date.getYear()), todays_date.getMonth(), todays_date.getDate() + 3 );

	months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    

	//add 31 day options in the day drop down
	for(i=1;i<=31;i++){
		option_selected = 0;
		if( defaultStartBookDay.getDate() == i ){
			option_selected = 1;
		}
		document.hotelquery.elements[0].options[i-1] = new Option(i,i,"",option_selected);
	}
    
	//add the 12 month options to the month dropdown
	selectedMonthNum = new String( defaultStartBookDay.getMonth() );
    selectedYearNum  = getDisplayYear( defaultStartBookDay.getYear() );
    
    for(i=0;i<12;i++){
		
        //generate the option month from the forr loop variable
        optionMonthDate = new Date(getDisplayYear(todays_date.getYear()), todays_date.getMonth() + i, 1);
        
        //now create the rest of the option information from that date
        option_text = months[optionMonthDate.getMonth()] + " " + getDisplayYear(optionMonthDate.getYear());
        option_selected = 0;
        if( selectedMonthNum == optionMonthDate.getMonth() && selectedYearNum == getDisplayYear( optionMonthDate.getYear() ) ){
			option_selected = 1;
		}
        option_value = getDisplayYear(optionMonthDate.getYear()) + "-" + (optionMonthDate.getMonth()+1);
        document.hotelquery.elements[1].options[i] = new Option(option_text, option_value ,"",option_selected);
	}
	
	document.hotelquery.elements[2].value =  document.hotelquery.elements[1].options[document.hotelquery.elements[1].selectedIndex].value + "-" + document.hotelquery.elements[0].options[document.hotelquery.elements[0].selectedIndex].value;


    //add year options to the dropdown
    /*
    this_year = todays_date.getYear();
    next_year = todays_date.getYear() +1;
    option_text = getDisplayYear(this_year);
    option_selected = 0;
    if ( defaultStartBookDay.getYear() == this_year )
    {
        option_selected = 1;
    }
    document.hotelquery.elements[3].options[0] = new Option(option_text, option_text ,"",option_selected);
    option_text = getDisplayYear(todays_date.getYear()+1);
    if ( defaultStartBookDay.getYear() == next_year )
    {
        option_selected = 1;
    }
    document.hotelquery.elements[3].options[1] = new Option(option_text, option_text ,"",option_selected);
		*/
	
	
	//sets options in the number of nights drop down
	for(i=0;i<40;i++){
	
		j = i + 1;
		selected_nights = 0;
		if( j == 3 ){
			selected_nights = 1;
		}
		document.hotelquery.elements[3].options[i] = new Option(j,j,"",selected_nights);
	}
	
	for(i=0;i<8;i++){
	
		j = i + 1;
		selected_rooms = 0;
		if( j == 1 ){
			selected_rooms = 1;
		}
		document.hotelquery.elements[4].options[i] = new Option(j,j,"",selected_rooms);
		
	}
	
	//sets options in the number of children dropdown
	
	for(i=0;i<6;i++){
	
		j = i + 1;
		selected_guests = 0;
		if( j == 1 ){
			selected_guests = 1;
		}
		document.hotelquery.elements[5].options[i] = new Option(j,j,"",selected_guests);
		
	} 
	
	//sets options in the number of children dropdown
	
	for(i=0;i<5;i++){
	
		j = i;
		selected_children = 0;
		if( j == 0 ){
			selected_children = 1;
		}
		document.hotelquery.elements[6].options[i] = new Option(j,j,"",selected_children);
		
	}
	
}



