//-------------------------------------------------------------------
// $Header: /WebSites/bahamas/javascript/DynamicSelect_Cruises.js 9     7/19/11 3:06p Mccusker $
// Performs javascript popup functions
//-------------------------------------------------------------------

function populateVessels(inForm) { 	
	if(inForm.operator.options[inForm.operator.options.selectedIndex].value == "")
		return;
		 
	var selectedArray = eval("Cruise" + inForm.operator.options[inForm.operator.options.selectedIndex].value + "Array"); 
    // window.alert (selectedArray)
	// set the drop length if we need to
	var selectedLength = selectedArray.length;

	while (selectedLength < inForm.vessel_id.options.length) { 
		inForm.vessel_id.options[(inForm.vessel_id.options.length - 1)] = null; 
	} 
	for (var i=0; i < selectedArray.length; i++) { 
	    eval("inForm.vessel_id.options[i]=" + "new Option" + selectedArray[i]); 
	//window.alert (selectedArray[i])
	} 
	if (inForm.vessel_id.options[0].value == '') { 
		inForm.vessel_id.options[0]= null; 
		if ( navigator.appName == 'Netscape') { 
			if (parseInt(navigator.appVersion) < 4) { 
				window.history.go(0); 
			} 
			else { 
				if (navigator.platform == 'Win32' || navigator.platform == 'Win16') { 
					window.history.go(0); 
				} 
			} 
		} 
	} 
}

function populateVessels_Dynamic(inForm) { 	
	if(inForm.c.options[inForm.c.options.selectedIndex].value == "")
		return;
		 
	var selectedArray = eval("Cruise" + inForm.c.options[inForm.c.options.selectedIndex].value + "Array"); 
    // window.alert (selectedArray)
	// set the drop length if we need to
	var selectedLength = selectedArray.length;

	while (selectedLength < inForm.v.options.length) { 
		inForm.v.options[(inForm.v.options.length - 1)] = null; 
	} 
	for (var i=0; i < selectedArray.length; i++) { 
	    eval("inForm.v.options[i]=" + "new Option" + selectedArray[i]); 
	//window.alert (selectedArray[i])
	} 
	if (inForm.v.options[0].value == '') { 
		inForm.v.options[0]= null; 
		if ( navigator.appName == 'Netscape') { 
			if (parseInt(navigator.appVersion) < 4) { 
				window.history.go(0); 
			} 
			else { 
				if (navigator.platform == 'Win32' || navigator.platform == 'Win16') { 
					window.history.go(0); 
				} 
			} 
		} 
	} 
}

function preselectVessel(inForm) { 

	params = getParams(); 
	
	var intVesselID = unescape(params["vessel_id"]); 
	
	for (var i=0; i < inForm.vessel_id.options.length; i++) { 
		if (inForm.vessel_id.options[i].value == intVesselID) {
			inForm.vessel_id.options.selectedIndex = i
		}
	} 
}

function getParams() { 
	var idx = document.URL.indexOf('?'); 
	var params = new Array(); 
	if (idx != -1) { 
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&'); 
		for (var i=0; i<pairs.length; i++) { 
			nameVal = pairs[i].split('='); 
			params[nameVal[0]] = nameVal[1]; 
		} 
	} 
	return params;
}

// set the ship list based on the cruiseline, if we aren't on the home page
// set up InStr if possible
//var path = location.pathname;
//path = path.slice(0,12)
//if (path != "/default.asp" && location.pathname != "/"){
	//populateVessels(window.document.forms["AdvancedForm"])
//}

//preselectVessel(document.AdvancedForm);

// End -->
