var xmlDoc;
var depAirport;
var tempSki = '';
function loadPackageXML(sSki){
	tempSki = sSki;
	// code for IE
	var sFilename = '';
	if(sSki == 'Ski'){
		sFilename = 'packageholidays_destinations_ski'
	}else{
		sFilename = 'packageholidays_destinations'
	}
	if (window.ActiveXObject){
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load("/includes/" + sFilename + ".xml");
		getPackageDestinations();
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.load("/includes/" + sFilename + ".xml");
		xmlDoc.onload=getPackageDestinations;
	}else{
		alert('Your browser cannot handle this script');
	}
}
//Clear List
function clearListPackage(listElem) {
	if(listElem!=0){
		while(listElem.options.length > 0) {
			listElem.options[0] = null;
		}
		while(listElem.hasChildNodes()) {
			listElem.removeChild(listElem.firstChild);
		}
		listElem.options[0] = new Option('- Loading destination -','');
	}
}


function getPackageDestinations(depairport, sSki) {
	if(tempSki != ''){
		sSki = tempSki;
	}
	if(sSki){
		//alert('in ski')
		sDDLID = 'packageLocationToPackages_Ski';
	}else{
		//alert('in package')
		sDDLID = 'packageLocationToPackages';
	}

	sDestinationDDL = document.getElementById(sDDLID)
	sDestinationDDL.disabled = 'disabled';
	
	clearListPackage(sDestinationDDL);
	if(depairport!=undefined) {
		depAirport = depairport;
	}
	
	if(typeof xmlDoc=='object') {
		Departure = xmlDoc.getElementsByTagName('Departure');
		for(x=0;x<Departure.length;x++) {
			//alert(Departure[x].attributes.getNamedItem("AirportCode").nodeValue);
			if(Departure[x].attributes.getNamedItem("AirportCode").nodeValue == depAirport) {
				Destination = Departure[x].getElementsByTagName('Destination');
				for(y=0;y<Destination.length;y++) {
					sAirportCode = Destination[y].attributes.getNamedItem("AirportCode").nodeValue
					sAirportName = Destination[y].attributes.getNamedItem("AirportName").nodeValue
					sCountryName = Destination[y].attributes.getNamedItem("CountryName").nodeValue
					
					if(sPreCountry!=sCountryName){
						var CountryName = document.createElement('optgroup');
						CountryName.label = sCountryName;
						sDestinationDDL.appendChild(CountryName);
					}
					var sPreCountry = sCountryName
					sDestinationDDL.options[sDestinationDDL.options.length] = new Option(sAirportName, sAirportCode);
					
				}
			}
		}
		sDestinationDDL.options[0].innerHTML = '- Select your destination -';
		sDestinationDDL.disabled = '';
	}else{
		loadPackageXML(sSki);
	}
}

function getTourNames(intCountryCode){
	sDestinationDDL = document.getElementById('packageLocationTours')
	
	if(intCountryCode!= ''){
		sDestinationDDL.disabled = 'disabled';
		clearListPackage(sDestinationDDL);
		
		var sResponse = readFile('/includes/search/LookupTourOpXML.asp?searchtype=tour&location=' + intCountryCode);
		if(window.DOMParser) {
			var parser=new DOMParser();
			var XMLDocTemp=parser.parseFromString(sResponse,"text/xml");
		}else{
			var XMLDocTemp=new ActiveXObject("Microsoft.XMLDOM");
			XMLDocTemp.async='false';
			XMLDocTemp.loadXML(sResponse);
		}
	
		
		sDestinationDDL.options[0] = new Option("- All tours -","");		
		var oTours = XMLDocTemp.getElementsByTagName('Location');
		if(oTours.length > 0) {
			for(x=0;x<oTours.length;x++) {
				sDestinationDDL.options[sDestinationDDL.options.length] = new Option(oTours[x].attributes.getNamedItem("title").nodeValue,oTours[x].attributes.getNamedItem("code").nodeValue);
			}
		}
		sDestinationDDL.disabled = '';
	}else{
		sDestinationDDL.disabled = 'disabled';
		clearListPackage(sDestinationDDL);
		sDestinationDDL.options[0] = new Option("- Select a country -","");		
	}	
}


