﻿// JScript File
function body_onload()
{
	/*var monthOptions = document.getElementById('uxDeptMonth');
    var monthDate = new Date();
    var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');			
	var newOption; // Temporary variable used when adding new options to dropdowns.
	var targetDate = new Date();
		
	// Check that last dates were in the future.
	if (lastDeptYear > targetDate.getFullYear() || (lastDeptYear == targetDate.getFullYear() && lastDeptMonth > targetDate.getMonth())
		|| (lastDeptYear == targetDate.getFullYear() && lastDeptMonth == targetDate.getMonth() && lastDeptDay > targetDate.getDate()))
	{
		// Calculate the target date for the dropdowns to be previous.
	    targetDate = new Date(lastDeptYear, lastDeptMonth, lastDeptDay);   		
	}
	else
	{
		// Calculate the target date for the dropdowns to be today plus 1 month.
	    targetDate.setMonth(targetDate.getMonth() + 1);         
	}

    // Add month options to dropdowns.
    for (var monthIdx = 0; monthIdx < 18; monthIdx++)
    {            
        // Add option for this destination.
		newOption = document.createElement("OPTION");
		monthOptions.options.add(newOption);
		newOption.innerHTML = months[monthDate.getMonth()] + ' ' + monthDate.getFullYear().toString();

        // Create value field with date then month.
        newOption.value = monthDate.getFullYear().toString() + (monthDate.getMonth() + 1).toString();
		
		// If this is the target month then select it.
		if (targetDate.getMonth() == monthDate.getMonth() && targetDate.getFullYear() == monthDate.getFullYear())
		{
			newOption.selected = true;
		}
        
        // Add 1 month to the current date (jscript rolls the year for us if 13 is set)
        monthDate.setMonth(monthDate.getMonth() + 1);            
    }
        
    // Set the day options for the current month.
    SetDayOptions(targetDate);    */
    
	// Simulate a destination change to populate resorts.
	var testDest,test2;
	test2=document.getElementById('SRSSearchControl1_optPackage');
	
 	if(test2.checked)
	{
	    testDest= document.getElementById('uxDestination');
	   
	    if (testDest == null)
	    {
	        testDest=document.getElementById('SRSSearchControl1_uxDestination')
	        if (testDest == null)
	        {
	            testDest=document.getElementById('ctl00_SRSSearchControl1_uxDestination')
    	
	            //
	            uxDestinations_OnChange(document.getElementById('ctl00_SRSSearchControl1_uxDestination').value)
	        }
	        else
	        {
	            uxDestinations_OnChange(document.getElementById('SRSSearchControl1_uxDestination').value);	
    	    
	        }
	    }
	    else
	    {
	        uxDestinations_OnChange(document.getElementById('uxDestination').value);	    	
	    }
	}
}

function uxDeptMonth_OnChange()
{
    var monthOptions = document.getElementById('uxDeptMonth');
    var dayOptions = document.getElementById('uxDeptDay');
    var month = parseInt(monthOptions.value.substring(4, 6)) - 1;
    var year = parseInt(monthOptions.value.substring(0, 4));
	var monthDate = new Date(year, month, 1);

	// Set the day options for the specified month.
	SetDayOptions(monthDate);
}

function SetDayOptions(targetDate)
{
    var days = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
	var dayOptions = document.getElementById('uxDeptDay'); // Dropdown list of departure days.
	var currentValue = dayOptions.value;
	var currentDate = new Date();
	var dateIdx = new Date(targetDate.getFullYear(), targetDate.getMonth(), 1);
	var newOption; // Temporary variable used when adding new options to dropdowns
	var year = targetDate.getFullYear();	// Cache requested year to avoid multiple calls to getFullYear().
	var month = targetDate.getMonth(); // Cache requested year to avoid multiple calls to getMonth().
	var pos = 0;
	
	// If this is the first time options have been added then current date is that passed in.
	if (dayOptions.length == 0)
	{
		currentValue = targetDate.getDate().toString();
	}
	
	// Clear current day options.
	dayOptions.length = 0;

	// If we are in this month then the first day is today.
	if (currentDate.getFullYear() == year && currentDate.getMonth() == month)
	{
		dateIdx.setDate(currentDate.getDate());
	}

	// Add day options applicable to the current month.
	while (dateIdx.getFullYear() == year && dateIdx.getMonth() == month)
	{			    
        // Add option for this destination.
		newOption = document.createElement("OPTION");
		dayOptions.options.add(newOption);
		// newOption.innerHTML = days[dateIdx.getDay()] + ' ' + dateIdx.getDate();
		newOption.innerHTML = dateIdx.getDate();
		newOption.value = dateIdx.getDate().toString();
				
		// If this is the previously selected day then preserve.
		if (newOption.value == currentValue) 
		{
			newOption.selected = true;
		}
	
        // Increment the day by 1.
        dateIdx.setDate(dateIdx.getDate() + 1);                			
	} 
}

function uxDestinations_OnChange(value)
{
	var resortOptions = document.getElementById('uxResort'); // Reference to resoprts dropdown
	if (resortOptions == null)
	{
	 resortOptions = document.getElementById('SRSSearchControl1_uxResort');
	}
	if (resortOptions == null)
	{
	 resortOptions = document.getElementById('ctl00_SRSSearchControl1_uxResort');
	}
	
	
	var newOption; // Temporary variable used when adding new options to dropdowns.
	var destinationCur;	
	
	// Clear current resort options.
	resortOptions.length = 0;
	
	// Add any option to the resorts dropdown.	
	newOption = document.createElement("OPTION");
	resortOptions.options.add(newOption);
	newOption.value = '';
	newOption.innerHTML = 'Any Resort';
	
	// Look through the destinationList array for the currently selected destination.
	for (var destinationIdx = 0; destinationIdx < destinationList.length; destinationIdx++)
	{
		// Does this one match?
		if (destinationList[destinationIdx][0] == value)
		{						
			// Matches so stop looking for any more.
			destinationCur = destinationIdx;
			break;							
		}
	}
						
	// Add each resort option to the dropdown.
	for (var resortIdx = 1; resortIdx < destinationList[destinationCur].length; resortIdx++)
	{
		// Add option to the resorts dropdown.	
		newOption = document.createElement("OPTION");
		resortOptions.options.add(newOption);
		newOption.value = destinationList[destinationCur][resortIdx];
		newOption.innerHTML = destinationList[destinationCur][resortIdx];					
	}				
}	
function uxResorts_OnChange(value)
{
var resortVal = document.getElementById('SRSSearchControl1_txtResVal');
if (resortVal==null)
{
  resortVal = document.getElementById('ctl00_SRSSearchControl1_txtResVal');
  }
resortVal.value = value;
}

