// $Id: fa.js,v 1.9 2007/04/12 19:58:27 dbaker Exp $ 

// -- Global Functions
function changeImages() {
	d = document;
	if (d.images) {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (d.layers) {img = findElement(changeImages.arguments[i],0);}
			else {img = d.images[changeImages.arguments[i]];}
			if (img) {img.src = changeImages.arguments[i+1];}
		}
	}
}

function newImage(arg) {
        if (document.images) {
                rslt = new Image();
                rslt.src = arg;
                return rslt;
        }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
                (new Image(170,29)).src = "/images/nav/ltover.gif";
                (new Image(170,29)).src = "/images/nav/statsover.gif";
                (new Image(170,29)).src = "/images/nav/commservover.gif";
                (new Image(170,29)).src = "/images/nav/discover.gif";
                (new Image(170,29)).src = "/images/nav/newsover.gif";
                (new Image(170,29)).src = "/images/nav/resover.gif";
                (new Image(170,29)).src = "/images/nav/aboutover.gif";
                (new Image(170,30)).src = "/images/nav/contactover.gif";

                preloadFlag = true;
        }
}

function setAirportCode(code) {	
 document.airport.airport.value=code;
 document.getElementById("AirportQueryResult").style.display = "none"
 //document.getElementById("AirportQuery").style.display = "none"
 var res = document.getElementById("AirportQuery");
 //res.style.display = "block";
 res.innerHTML = "<p align=\"left\"><strong>One Moment Please</strong><div class=\"indent\">Loading airport status. . .</div></p>";
 document.airport.submit(); 
}

function checkAirportPrefix() {
 if (document.airport.airport.value <3) {
	alert('You must either type in an an airport code or use the "Don\'t Know The Code?" pop-over tool to search for and select an airport before clicking "View Airport Activity."');
        return false;
 }

 return true;
}

function DoLoginBox() {
	var res1 = document.getElementById("headerText");
	res1.style.display = "none";
	var res2 = document.getElementById("LoginBox");
	res2.style.display = "block";
	var res3 = document.getElementById("LiveFlightTracking");
	res3.style.display = "none";
	document.login.flightaware_username.focus();
}

function NoLoginBox() {
	var res2 = document.getElementById("LoginBox");
	res2.style.display = "none";
	var res1 = document.getElementById("headerText");
	res1.style.display = "block";
	var res3 = document.getElementById("LiveFlightTracking");
	res3.style.display = "inline";
}

/*
// +----------------------------------------------------------------------+
// | Livesearch Copyright (c) 2004 Bitflux GmbH                           |
// +----------------------------------------------------------------------+
// | Licensed under the Apache License, Version 2.0 (the "License");      |
// | you may not use this file except in compliance with the License.     |
// | You may obtain a copy of the License at                              |
// | http://www.apache.org/licenses/LICENSE-2.0                           |
// | Unless required by applicable law or agreed to in writing, software  |
// | distributed under the License is distributed on an "AS IS" BASIS,    |
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
// | implied. See the License for the specific language governing         |
// | permissions and limitations under the License.                       |
// +----------------------------------------------------------------------+
// | Author: Bitflux GmbH <l@bitflux.ch>                              |
// +----------------------------------------------------------------------+
*/

var liveSearchReq = false;
var t = null;
var liveSearchLast = "";
var isIE = false;
// on !IE we only have to initialize it once


function liveSearchInit() {
//	if (navigator.userAgent.indexOf("Safari") > 0) {
//		document.getElementById('livesearch').addEventListener("keydown",liveSearchSubmit,false);
//	} else if (navigator.product == "Gecko") {
//		document.getElementById('livesearch').addEventListener("keypress",liveSearchKeyPress,false);
//		document.getElementById('livesearch').addEventListener("blur",liveSearchHideDelayed,false);
//	} else {
//		document.getElementById('livesearch').attachEvent('onkeydown',liveSearchKeyPress);
//		isIE = true;
//	}

	defaultFormText = 'Enter Airline Name Here';
        if (defaultFormText == document.forms.searchform.q.value) {
		document.forms.searchform.q.value = '';
	}

	document.getElementById('livesearch').setAttribute("autocomplete","off");
}

function liveSearchKeyPress(event) {
	if (event.keyCode == 40 )
	//KEY DOWN
	{
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("LSResult").firstChild.firstChild.firstChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}
		if (highlight) {
			highlight.setAttribute("id","LSHighlight");
		} 
		if (!isIE) { event.preventDefault(); }
	} 
	//KEY UP
	else if (event.keyCode == 38 ) {
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("LSResult").firstChild.firstChild.lastChild;
		} 
		else {
			highlight.removeAttribute("id");
			highlight = highlight.previousSibling;
		}
		if (highlight) {
				highlight.setAttribute("id","LSHighlight");
		}
		if (!isIE) { event.preventDefault(); }
	} 
	//ESC
	else if (event.keyCode == 27) {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		document.getElementById("LSResult").style.display = "none";
		document.forms.searchform.q.value = '';
	} 
}
function liveSearchStart() {

	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveSearchDoSearch()",200);
}

function liveSearchDoSearch() {
        var agt=navigator.userAgent.toLowerCase();
        var is_major = parseInt(navigator.appVersion);
        var is_minor = parseFloat(navigator.appVersion);
        var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        var is_ie7 = (is_ie && (agt.indexOf("msie 7.")!=-1) );
	if ((!is_ie) || (is_ie7)) {
		liveSearchReq = new XMLHttpRequest();
 	}

	document.forms.searchform.ident_prefix.value = '';

	if (liveSearchLast != document.forms.searchform.q.value) {
	if (liveSearchReq && liveSearchReq.readyState < 4) {
		liveSearchReq.abort();
	}
	if ( document.forms.searchform.q.value == "") {
		document.getElementById("LSResult").style.display = "none";
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		return false;
	}
	if (window.XMLHttpRequest) {
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	liveSearchReq.onreadystatechange= liveSearchProcessReqChange;
	liveSearchReq.open("GET", "http://flightaware.com/include/search.rvt?type=airline;query=" + document.forms.searchform.q.value);
	liveSearchLast = document.forms.searchform.q.value;
	liveSearchReq.send(null);
	}
}

function liveSearchProcessReqChange() {
	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("LSResult");
		res.style.display = "block";
		res.innerHTML = liveSearchReq.responseText;
	}
}

function liveSearchSubmit() {
	var highlight = document.getElementById("LSHighlight");
	if (highlight && highlight.firstChild) {
		window.location = highlight.firstChild.getAttribute("href");
		return false;
	} 
	else {
		return true;
	}
}

function liveSearchHighlightEntryArea() {
  var livesearchBox = document.getElementById("livesearch");
}

function setCode(code,name) {	
 document.searchform.ident_prefix.value=code;
 document.searchform.livesearch.value=name;
 document.getElementById("LSResult").style.display = "none"
 if (document.searchform.ident_suffix.value.length > 1) {
  var  res = document.getElementById("LSResult");
  res.style.display = "block";
  res.innerHTML = "<p align=\"left\"><strong>One Moment Please</strong><div class=\"indent\">Loading flight status. . .&nbsp;&nbsp;</div></p>";
  document.searchform.submit();
 }
}

function checkPrefix() {
 if (document.searchform.ident_prefix.value.length < 3) {
 	if (document.searchform.q.value.length < 4) {
		alert('You must type in part of an airline name and then select the correct one from the box below the search form.');
	} else {
		alert('You must select the correct airline name from the box below the search form.');
	}
        document.searchform.q.focus();
        return false;
 }

 if (document.searchform.ident_suffix.value.length < 1) {
	alert('You must type in a flight number in the field next to your selected airline name.');
	return false;
 }

 return true;
}
function DoAirportBox() {
	var res = document.getElementById("AirportQuery");
	res.style.display = "block";
	res.innerHTML = "<table width='100%'><tr><td colspan='2' align='right' style='border:0; font-size: 12px;'><a href='javascript:XAirportBox()'>Close</a></td></tr><tr><td align='center' style='border: 0;'>Type part of an airport or city name:</td></tr><tr><td align='left' style='border: 0;'><input id='livesearch2' type='text' name='q' onkeypress='liveSearchStart2()' size='25' autocomplete='off' /></td></tr><tr><td style='border: 0;'><div id=\"AirportQueryWait\"></div></td></tr></table>"; 
	document.AirportQueryForm.q.focus();
}

function XAirportBox() {
	document.getElementById("AirportQuery").style.display = "none"
}


var liveSearchReq = false;
var t = null;
var liveSearchLast = "";
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest) {
	liveSearchReq = new XMLHttpRequest();
}

function liveSearchInit2() {
	if (navigator.userAgent.indexOf("Safari") > 0) {
		document.getElementById('livesearch2').addEventListener("keydown",liveSearchKeyPress2,false);
	} else if (navigator.product == "Gecko") {
		document.getElementById('livesearch2').addEventListener("keypress",liveSearchKeyPress2,false);
	} else {
		document.getElementById('livesearch2').attachEvent('onkeydown',liveSearchKeyPress2);
		isIE = true;
	}

}

function liveSearchKeyPress2(event) {


	if (event.keyCode == 40 )
	//KEY DOWN
	{
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("AirportQueryResult").firstChild.firstChild.firstChild;
		} else {
			highlight.removeAttribute("id");
			highlight = highlight.nextSibling;
		}
		if (highlight) {
			highlight.setAttribute("id","LSHighlight");
		} 
		if (!isIE) { event.preventDefault(); }
	} 
	//KEY UP
	else if (event.keyCode == 38 ) {
		highlight = document.getElementById("LSHighlight");
		if (!highlight) {
			highlight = document.getElementById("AirportQueryResult").firstChild.firstChild.lastChild;
		} 
		else {
			highlight.removeAttribute("id");
			highlight = highlight.previousSibling;
		}
		if (highlight) {
				highlight.setAttribute("id","LSHighlight");
		}
		if (!isIE) { event.preventDefault(); }
	} 
	//ESC
	else if (event.keyCode == 27) {
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		document.getElementById("AirportQueryResult").style.display = "none";
		document.forms.AirportQueryForm.q.value = '';
	} 
}
function liveSearchStart2() {
        var wait = document.getElementById("AirportQueryWait");
       	wait.style.display = "block";
       	wait.innerHTML = "<p align=\"center\">I'll guess when I know what you mean.</p>";

	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveSearchDoSearch2()",200);
}

function liveSearchDoSearch2() {
        var agt=navigator.userAgent.toLowerCase();
        var is_major = parseInt(navigator.appVersion);
        var is_minor = parseFloat(navigator.appVersion);
        var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        var is_ie7 = (is_ie && (agt.indexOf("msie 7.")!=-1) );
	if ((!is_ie) || (is_ie7)) {
		liveSearchReq = new XMLHttpRequest();
 	}

	document.forms.airport.airport.value = '';

	if (liveSearchLast != document.forms.AirportQueryForm.q.value) {
	if (liveSearchReq && liveSearchReq.readyState < 4) {
		liveSearchReq.abort();
	}
	if ( document.forms.AirportQueryForm.q.value == "") {
		document.getElementById("AirportQueryResult").style.display = "none";
		highlight = document.getElementById("LSHighlight");
		if (highlight) {
			highlight.removeAttribute("id");
		}
		return false;
	}
	if (window.XMLHttpRequest) {
	// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		 liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	liveSearchReq.onreadystatechange= liveSearchProcessReqChange2;
	liveSearchReq.open("GET", "http://flightaware.com/include/search.rvt?type=airport;query=" + document.forms.AirportQueryForm.q.value);
	liveSearchLast = document.forms.AirportQueryForm.q.value;
	liveSearchReq.send(null);
	}
}

function liveSearchProcessReqChange2() {
	if (liveSearchReq.readyState == 4) {
		var  res = document.getElementById("AirportQueryResult");
		res.style.display = "block";
		res.innerHTML = liveSearchReq.responseText;
	}
}

function liveSearchSubmit2() {
	var highlight = document.getElementById("LSHighlight");
	if (highlight && highlight.firstChild) {
		window.location = highlight.firstChild.getAttribute("href");
		return false;
	} 
	else {
		return true;
	}
}

function liveSearchHighlightEntryArea2() {
  var livesearchBox = document.getElementById("livesearch2");
}
