var xmlhttp;

function showFlights(dir,desName,depName,desCountry,depCountry,desCode,depCode,f,t,source) {

	xmlhttp=GetXmlHttpObject();

	if (xmlhttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url=dir + "getflights.php?dir="+dir+"&dsN="+desName+"&dpN="+depName+"&dsCy="+desCountry+"&dpCy="+depCountry+"&dsC="+desCode+"&dpC="+depCode+"&f="+f+"&t="+t+"&s="+source;
	
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged() {
	if (xmlhttp.readyState==4) {
		document.getElementById("TOSflights").innerHTML=xmlhttp.responseText;
	}
}

function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function closeInfoPopup(e, type) {
	switch(type) {
		case "airport" : var infoPopup = document.getElementById("infoAirportPopup"); break;
		case "month" : var infoPopup = document.getElementById("infoMonthPopup"); break;		
	}
	if (document.all){ //win
		infoPopup.style.display = "none";
	}
	else { //moz
		infoPopup.setAttribute("style", "display: none;");
	}	
}
function openInfoPopup(e, type, airport, info) {

	// get cursor position
	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	}
	else {
		var de = document.documentElement;
		var b = document.body;
		cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
		cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	}
	
	//show and position the layer
	switch(type) {
		case "airport" : var infoPopup = document.getElementById("infoAirportPopup");
			document.getElementById("popupAirportText").innerHTML = "Sorry, we do not currently offer flights to "+airport+" from "+info+".";
		break;
		case "month" : var infoPopup = document.getElementById("infoMonthPopup");
			document.getElementById("popupMonthText").innerHTML = "Sorry, we do not currently offer flights to "+airport+" in "+info+".";
		break;		
	}

	if (document.all){ //win
		infoPopup.style.display = "block";
		infoPopup.style.top = (cursor.y-20);
		infoPopup.style.left = (cursor.x-0);
	}
	else { //moz
	//	infoPopup.setAttribute("style", "display: block; position: absolute; top: " + (cursor.y - 20) + "px ; left: " + (cursor.x - 0) + "px ;");
		infoPopup.setAttribute("style", "display: block; position: absolute; top: " + (cursor.y - 20) + "px ; left: 110px ;");
	}
}

