// function setCasinoListbox(casinoObject,destArrayVal)
// Description: It is used to populate the Casino dropdown based on the selected value in Destination dropdown
// Parameter: casinoObject maps to Casino selectbox, destArrayVal maps to selected value of Destination Dropdown 
// Author: Anamika Dahiya
// Dated: April 21, 2006 

function setCasinoListbox(casinoObject,destArrayVal) {
	
	casinoObject=document.getElementById("slctCasino");
	
	// Clear Casino dropdown
	for(var i=casinoObject.length;i>0;i--) {
		casinoObject.options[i] = null;
	} 
	
	var selectedValue = destArrayVal;

	// If no value is selected in Destination dropdown, then disable Casino dropdown.
	if (selectedValue == "") {
		casinoObject.disabled = true;
	} 
	// else if value in Destination dropdown is selected, proceed to populate the Casino dropdown
	else {

		casinoObject.disabled = false;
		var selIndex = 1;
	    var casinoArrayElement = "";
		
		// Loop for populating the casino dropdown
		for (i = 0; i < casinoArray.length; i++) {

			casinoArrayElement = casinoArray[ i ];
			
			// Convert the array into string
			casinoArrayElement = casinoArrayElement + "";
			
			// Split the string from " | " (pipe) and assign into an array casinoElement
			// where casinoElement[0] is Mapping to value in Destination dropdown, 
			// casinoElement[1] is Display Text in Casino dropdown,
			// and casinoElement[2] is the value of each option in Casino dropdown.
			var casinoElement = casinoArrayElement.split("|");

					// Comparing 'Mapping to "value"' tag of CasinoArray with the value of selected destination 
					if (casinoElement[0] == selectedValue) {
						casinoObject.options[selIndex] = new Option(casinoElement[1], casinoElement[2]);
						selIndex++;
					}
		}

		// If there are no casinos available for a destination, then disable the casino dropdown.
		if (casinoObject.length <= 1) {
					casinoObject.disabled = true;
		}
	}
	casinoObject.selectedIndex = 0;
}

// function init() 
/* Description: It is used to disable Casino dropdown box on page load and till a value is selected in Destination dropdown.
   It defaults the selected index of Destionation dropdown to "Select a Destination" option.  */ 
// This function is called on page load.

function setCasinoOptions()
{
	casinoObject=document.getElementById("slctCasino");
	destinationObject=document.getElementById("slctDestination");

	if(destinationObject && casinoObject){
		casinoObject.disabled = true;
		if(destinationObject.selectedIndex == 0){
			casinoObject.disabled = true;
		}
		else{
			setCasinoListbox("slctCasino",destinationObject.value)
		}
	}		
}

// function arrOnLoad()
// Description: Pushes the setCasinoOptions in to the array to be executed on pageLoad.
// Author: Sailesh Raghavan
// Dated: April 21, 2006 

if(arrOnLoad){
	arrOnLoad.push("setCasinoOptions()");	
}
