	addLoadListener(populateMenuList);
	addLoadListener(menuOnChange);
	
	function menuOnChange() {
		if (document.getElementById("menucruiseline")) {
			attachEventListener(document.getElementById("menucruiseline"), "change", populateMenuList, true);
		}
	}
	
	function populateMenuList () {
		if (document.getElementById("menucruiseline")) {
			var strCruiseLine = document.getElementById("menucruiseline").value;
			var strCruiseShip = document.getElementById("selectedcruiseship").value;
			
			var url = "/site/scripts/menu.jsp?";
	
			showLoadMsg(document.getElementById("menucruiseship"));
			url += "line="+strCruiseLine;
			if ( strCruiseShip != "" ) 
				url += "&ship=" + strCruiseShip;
	
			sendAjaxRequest("post", url, "", populateCruiseShips);
		}
	}
	
	function populateCruiseShips(success, xml){
			if (success) {
					SelectList = document.getElementById("menucruiseship");
					ClearSelectList(SelectList);
					AddXMLtoSelectOptions(SelectList, xml, "value");
					
					SelectList = document.getElementById("menuship");
					if (SelectList!==null) {
						ClearSelectList(SelectList);
						AddXMLtoSelectOptions(SelectList, xml, "code");
					}
			}
		
	}
	
	function AddXMLtoSelectOptions(SelectList, xml, attribute) {
		
			AddOptionToSelectList(SelectList, "", "Cruise Ship")		
			
			if (xml.getElementsByTagName("cruiseship")) {
			
				SelectOptions = xml.getElementsByTagName("cruiseship");			
		
				SelectList.style.color = "#000";
				
				for(i = 0 ; i < SelectOptions.length; i++) {
					OptionValue = SelectOptions[i].getAttribute(attribute);
					OptionText = SelectOptions[i].firstChild.nodeValue;
					AddOptionToSelectList(SelectList, OptionValue, OptionText);
					if (SelectOptions[i].getAttribute("selected") == "selected") {
						SelectList.selectedIndex = (i+1);
						SelectList.style.color = "#c33";
					}
				}
			
			}
		
	}
	
	function AddOptionToSelectList(SelectList, value, text) {
		
		  var newOption = document.createElement('option');
		  newOption.text = text;
		  newOption.value = value;
		
		  try {
			SelectList.add(newOption, null); 
		  }
		  catch(ex) {
			SelectList.add(newOption); 
		  }
		}

	
	function ClearSelectList(selectbox)
	{
		var j;
			for(j=selectbox.options.length-1;j>=0;j--)
			{
			selectbox.remove(j);
			}
	}
	
	function showLoadMsg(selectBox){ 
  
			ClearSelectList(selectBox);
			selectBox.style.color = "#CCC";
			AddOptionToSelectList(selectBox,"", "Loading...")
	  	
	}
	
