var req;
function loadXMLDocCruise(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeCruise;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangeCruise;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChangeCruise() 
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
		
			response = req.responseXML.documentElement;
			sType = response.getElementsByTagName('vType')[0].firstChild.nodeValue;
			
			if(sType != 'Ship'){
				iAccommCount = response.getElementsByTagName('vAccommCount')[0].firstChild.nodeValue;
				iDestinationCount = response.getElementsByTagName('vDestination_count')[0].firstChild.nodeValue;
				document.getElementById('Closest_Resort').options.length = 0;
				document.getElementById('Closest_Resort').options[0] = new Option('-- Any ship --', '-');

				//Accommodation dd
				for (var i=1; i <= iAccommCount; i++){
					sDestTmp = response.getElementsByTagName('vClientAccomm'+(i))[0].firstChild.nodeValue;
					var sDestArray = sDestTmp.split("|");
					if(sDestArray.length > 0){
						 document.getElementById('Closest_Resort').options[i] = new Option(sDestArray[1], sDestArray[0]);
					}
				}
				//Destination dd
				document.getElementById('cruise_destination').options[0] = new Option('-- Any destination --', '-');
				for (var i=1; i <= iDestinationCount; i++){
					sDestTmp = response.getElementsByTagName('vClientOfferDest'+(i))[0].firstChild.nodeValue;
					var sDestArray = sDestTmp.split("|");
					if(sDestArray.length > 0){
						 document.getElementById('cruise_destination').options[i] = new Option(sDestArray[1], sDestArray[0]);
					}
				}
			}else{
				iDestinationCount = response.getElementsByTagName('vCount')[0].firstChild.nodeValue;

				document.getElementById('cruise_destination').options.length = 0;
				document.getElementById('cruise_destination').options[0] = new Option('-- Any destination --', '-');
				for (var i=1; i <= iDestinationCount; i++){
					sDestTmp = response.getElementsByTagName('vDest'+(i))[0].firstChild.nodeValue;
					var sDestArray = sDestTmp.split("|");
					if(sDestArray.length > 0){
						 document.getElementById('cruise_destination').options[i] = new Option(sDestArray[1], sDestArray[0]);
					}
				}
			}
		}
		else
		{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

function clearListCruise(listElem) {
    while(listElem.options.length > 0) {
     listElem.options[0] = null;
	}
}

function checkNameCruise(input,clearDD, Type)
{
		sCruise = document.getElementById('Available_Regions')
		sShip = document.getElementById('Closest_Resort')
		sDest = document.getElementById('cruise_destination')
//		if(input!='-') {
			//if(Type=='Region') {sShip.disabled = '';}
			//if(Type=='Resort') {sDest.disabled = '';}
			// Input mode
			var ddList = null;
			ddList = clearDD;
			url  = '/includes/cruisesearch/lookup_ddData_' + Type + '.asp?Region_id=' + input;
			//if(confirm('OPEN ' + Type + 's: ' +input)) {
			//	window.open(url);
			//}
			clearListCruise(ddList);
			loadXMLDocCruise(url);
//		}else{
//			if(Type=='Region') {
//				sShip.selectedIndex = 0;
//				sDest.selectedIndex = 0;
//				//sShip.disabled = 'disabled';
//				//sDest.disabled = 'disabled';
//			}
//			if(Type=='Resort') {
//				//sDest.disabled = 'disabled';
//				sDest.selectedIndex = 0;
//			}
//		}
}