var currentFrm = '';
var currentType = '';
var mouseX = 0;
var mouseY = 0;
var destLoaderHTML = '<div style="text-align:center"><br />';
destLoaderHTML = destLoaderHTML + '<div id="csiLogoLoaderDestHelp"></div>';
destLoaderHTML = destLoaderHTML + '<br /><div style="margin-bottom:4px;"><strong>Loading destinations... Please wait.</strong></div></div>';

function getDestinationHelpDest(country, type) {
	sURL = "/includes/destinationhelp/lookup_dest.asp?country="+country+"&type="+type+"&qsss";
	if(!country) {
		openDestinationHelp(currentType, currentFrm);
	}else{
		if(document.getElementById('destinationHelpDest')) {
			document.getElementById('destinationHelpDest').innerHTML = destLoaderHTML;
			
			var so = new SWFObject("/includes/pleasewait/csi-logo-loader.swf", "soloader", "32", "32", "9", "#fff");
            so.addParam("wmode", "transparent");
            so.addVariable("varColour1", ""); // background colour - leave blank for transparency
			so.addVariable("varColour2", "d0622e"); // static circles colour
			so.addVariable("varColour3", "ea7138"); // fading circles colour
            so.write("csiLogoLoaderDestHelp");
		}
		//if(confirm('Open '+ sURL)) {
		//	window.open(sURL);
		//}
		if(sURL) {
			setTimeout("loadDestinationHelpXMLDoc('"+sURL+"','dest')", 100);
		}
	}
}

function setDestination(value) {
	document.forms[currentFrm].freetext.value = value;
	if(document.forms[currentFrm].aclocationto) 
	    document.forms[currentFrm].aclocationto.value = '';
	closeDestinationHelp();
}

function setDeparture(value) {
	document.forms[currentFrm].airportfrom.value = value;
	closeDestinationHelp();
}

function closeDestinationHelp() {
	clearInterval(intervalAutoComplete);
	document.getElementById('destinationHelp').style.display='none';
	if(document.getElementById('destinationHelpFrame')) {
		document.getElementById('destinationHelpFrame').style.display='none';
	}
	grayOut(false);
}


function openDestinationHelp(type, cform) {
	clearInterval(intervalAutoComplete);
	currentType = type;
	currentFrm = cform;
	sURL = "/includes/destinationhelp/lookup_top.asp?type="+type+"&qs";
	//if(confirm('Open '+ sURL)) {
	//	window.open(sURL);
	//}
	if(sURL) {
		grayOut(true);
		setTimeout("loadDestinationHelpXMLDoc('"+sURL+"','top')", 100);
	}
}
function loadDestinationHelpXMLDoc(url, type) {
    // branch for native XMLHttpRequest object
	if(type=='top') {
		var processChange = processDestinationHelpTop;
	}else{
		var processChange = processDestinationHelpDest;
	}
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
		req.onreadystatechange = processChange;
        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 = processChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processDestinationHelpDest() {
	if (req.readyState == 4){
		if (req.status == 200){
			//xmldoc = req.responseXML.documentElement;
			html = req.responseText;
			if(document.getElementById('destinationHelpDest')) {
				document.getElementById('destinationHelpDest').innerHTML = html;
			}
		}else{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
			grayOut(false);
		}
	}	
}

function processDestinationHelpTop() {
	if (req.readyState == 4){
		if (req.status == 200){
			//xmldoc = req.responseXML.documentElement;
			html = req.responseText;
			document.getElementById('destinationHelp').style.display='block';
			if(document.getElementById('destinationHelpFrame')) {
				//alert(document.getElementById('destinationHelp').offsetTop);
				document.getElementById('destinationHelpFrame').style.top = document.getElementById('destinationHelp').offsetTop+'px';
				document.getElementById('destinationHelpFrame').style.left = document.getElementById('destinationHelp').offsetLeft+'px';
				document.getElementById('destinationHelpFrame').style.width = '520px';
				document.getElementById('destinationHelpFrame').style.height = '350px';
				document.getElementById('destinationHelpFrame').style.display='block';
			}
			if(document.getElementById('destinationHelpTop')) {
				document.getElementById('destinationHelpTop').innerHTML = html;
			}
			if(document.getElementById('destinationHelpDest')) {
			    
				if(currentType=='airport') {
					sHTML='<div style="margin-top:25px; margin-left:10px;">';
					sHTML+='<strong>Not sure of the name of the airport?</strong><br><br>';
					
					sHTML+='<div style="float:left"><img src="/images/other/alternative_dest.gif" style="margin-left:10px;" /></div>';
					sHTML+='<div style="float:left; margin-top:5px;">';
										
					sHTML+='<ul type="square">'
					sHTML+='<li>Choose the country you are travelling to from the drop down.</li>'; 
					sHTML+='<li>All airports are listed alphabetically.</li>';
					sHTML+='<li>Click on the correct airport.</li>';
					sHTML+='<li>Search</li>';
					sHTML+='<li>Fly!</li>'; 
					sHTML+='</ul>'
					
					sHTML+='</div>'
					sHTML+='</div>'
				}else if(currentType=='departureairport') {
					sHTML='<div style="margin-top:25px; margin-left:10px;">';
					sHTML+='<strong>Not sure of the name of your departure airport?</strong><br><br>';
					
					sHTML+='<div style="float:left"><img src="/images/other/alternative_dest.gif" style="margin-left:10px;" /></div>';
					sHTML+='<div style="float:left; margin-top:5px;">';
										
					sHTML+='<ul type="square">'
					sHTML+='<li>Choose the country from which you are travelling from the dropdown list above</li>'; 
					sHTML+='<li>All airports are listed alphabetically.</li>';
					sHTML+='<li>Click on the correct airport.</li>';
					sHTML+='<li>Search</li>';
					sHTML+='<li>Fly!</li>'; 
					sHTML+='</ul>'
					
					sHTML+='</div>'
					sHTML+='</div>'
				}else{
					sHTML='<div style="margin-top:25px; margin-left:10px;">';
					sHTML+='<strong>Not sure of the name of the city?</strong><br><br>';
					
					sHTML+='<div style="float:left"><img src="/images/other/alternative_dest.gif" style="margin-left:10px;" /></div>';
					sHTML+='<div style="float:left; margin-top:5px;">';
					
					sHTML+='<ul type="square">'
					sHTML+='<li>Choose the country you are travelling to from the drop down.</li>'; 
					sHTML+='<li>All cities are listed alphabetically.</li>';
					sHTML+='<li>Click on the correct city.</li>';
					sHTML+='<li>Search</li>';
					sHTML+='</ul>'
					
					sHTML+='</div>'
					sHTML+='</div>'
				}
				document.getElementById('destinationHelpDest').innerHTML = sHTML;				
			}
		}else{
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}	
}

