
var xmlHttp;

function showHint(direction, str)
{
    //xmlHttp = GetXmlHttpObject()
    xmlHttp = initXMLHttpClient();
    
    if (xmlHttp == null)
    {
        alert ("Your browser does not support AJAX!");
        
        return;
    } 
    
    var url = ""; 
	
    switch (direction)
    {
        case "locator": 
            
			if(str.length > 0)
            {
				//fullOpacity('locatorExpanded', 500, str);
                document.getElementById('locatorExpanded').style.visibility = "visible";
            }
            else
            {
				//noneOpacity('locatorExpanded', 500, str);
                document.getElementById('locatorExpanded').style.visibility = "hidden";
                
                return;
            }
            
            url = "/locator/LocatorSearch.aspx";
            
            break;
        case "details":
            
            url = "/locator/GetAirportDetails.aspx";
            
            break;
        default:
    }
	
	var strValues = str.split("=");
    
    if(strValues.length > 1)
    {
        url = url + "?" + strValues[0] + "=" + strValues[1];
    }
    else
    {
        url = url + "?q=" + str;
    }
	
//alert ('url ' + url);
   
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
} 

function stateChanged() 
{ 
    if (xmlHttp.readyState == 4)
    { 
        if(xmlHttp.status == 200) 
        { 
            var rValue = xmlHttp.responseText; 
            var str = rValue.split("¤");
            
            switch (str[0])
            {
                case "locator": 
					
                    if(rValue.length > 0)
                    {
						//fullOpacity('locatorExpanded', 500, rValue);
						document.getElementById('locatorExpanded').style.visibility = "visible";
					}
					else
                    {
						//noneOpacity('locatorExpanded', 500, rValue);
						document.getElementById('locatorExpanded').style.visibility = "hidden";
                    }
    
                    if(str[1] != null)
                    {
                        document.getElementById("countryDiv").innerHTML = str[1];
                    }
                    if(str[2] != null)
                    {
                        document.getElementById("cityDiv").innerHTML = str[2];
                    }
                    if(str[3] != null)
                    {
                        document.getElementById("airportNameDiv").innerHTML = str[3];
                    }
                    if(str[4] != null)
                    {
                        document.getElementById("airportCodeDiv").innerHTML = str[4];
                    }
                    
                    break;
                case "details": 

                    if(str[1] != null)
                    {
						if(document.getElementById("detailCountryDiv") != null)
						{
							document.getElementById("detailCountryDiv").innerHTML = str[1];
						}
                    }
                    
                    if(str[2] != null)
                    {
						if(document.getElementById("detailCityDiv") != null)
						{
							document.getElementById("detailCityDiv").innerHTML = str[2];
						}
                    }
                    
                    if(str[3] != null)
                    {
						if(document.getElementById("airportDiv") != null)
						{
							document.getElementById("airportDiv").innerHTML = str[3];
						}
                    }
                    
                    if( str[4] != null)
                    {
                        var details = str[4].split("#");
                        
                        if(details[0] != null)
                        {
                            document.getElementById("airportInfoHeader").innerHTML = details[0];
                        }
                        if(details[1] != null)
                        {
                            document.getElementById("airportInfoDetails").innerHTML = details[1];
                        }
                        if(details[2] != null)
                        {
                            document.getElementById("airportInfoServices").innerHTML = details[2];
                        }
                        if(details[3] != null)
                        {
                            document.getElementById("airportInfoContacts").innerHTML = details[3];
                        }
                    }
                    
                    break;
                default: 
                    break;
            }
        }
        else 
        { 
            //alert("Error message : xmlHttp.readyState - " + xmlHttp.readyState + ", xmlHttp.status - " + xmlHttp.status + ", xmlHttp.responseText - " + xmlHttp.responseText); 
        } 
    }
}

//function GetXmlHttpObject()
//{
//    var xmlHttp = null;
//    
//    try
//    {
//        // Firefox, Opera 8.0+, Safari
//        xmlHttp = new XMLHttpRequest();
//    }
//    catch (e)
//    {
//        // Internet Explorer
//        try
//        {
//            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
//        }
//        catch (e)
//        {
//            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
//        }
//    }
//    
//    return xmlHttp;
//}

// function to create an XMLHttpClient in a cross-browser manner
function initXMLHttpClient() 
{
    var xmlhttp;
    
    try 
    {
        // Mozilla / Safari / IE7
        xmlhttp = new XMLHttpRequest();
    } 
    catch (e) 
    {
        // IE
        var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
            'MSXML2.XMLHTTP.4.0',
            'MSXML2.XMLHTTP.3.0',
            'MSXML2.XMLHTTP',
            'Microsoft.XMLHTTP' );
            
        var success = false;
        
        for (var i=0;i < XMLHTTP_IDS.length && !success; i++) 
        {
            try 
            {
                xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
                success = true;
            } 
            catch (e) {}
        }
        
        if (!success) {
            throw new Error('Unable to create XMLHttpRequest.');
        }
    }
        
    return xmlhttp;
}

function PageQuery(q) 
{
    if(q.length > 1) 
    {
        this.q = q.substring(1, q.length);
    }
    else this.q = null;
    
    this.keyValuePairs = new Array();
    
    if(q) 
    {
        for(var i=0; i < this.q.split("&").length; i++) 
        {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    
    this.getValue = function(s) 
    {
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            if(this.keyValuePairs[j].split("=")[0] == s)
            {
                return this.keyValuePairs[j].split("=")[1];
            }
        }
        
        return false;
    }

    this.getParameters = function() 
    {
        var a = new Array(this.getLength());
        
        for(var j=0; j < this.keyValuePairs.length; j++) 
        {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        
        return a;
    }
    
    this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key)
{
    var page = new PageQuery(window.location.search); 
    
    //alert(unescape(page.getValue(key)));
    
    return unescape(page.getValue(key)); 
}

function displayItem(key)
{
    if(queryString(key)=='false') 
    {
        document.write("you didn't enter a ?name=value querystring item.");
    }
    else
    {
        document.write(queryString(key));
    }
}

/*
function getDetails()
{
    var page = new PageQuery(window.location.search); 
    
    var key = page.getParameters();
    var value = queryString(key);
    
    showHint('details', key + "=" + value); 
}
*/


function getDetails()
{
    var page = new PageQuery(window.location.search); 
    
    var keys = page.getParameters();
	
	var value = '';
	var theKey = '';
	
	for(var i=0; i <= keys.length; i++)
	{
		var key = keys[i];

		if(key != null) 
		{
			if("node" != key)
			{
				thekey = key;
				value = queryString(key);
			}
		}
		
	}
    
    showHint('details', thekey + "=" + value); 
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

/*
<div id="locatorExpanded" visible="false" style="filter:alpha(opacity=100);-moz-opacity:1;opacity:1;" onmouseout="shiftOpacity('locatorExpanded', 1000)">
*/
/*
function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it invisible 
    if(document.getElementById(id).style.opacity == 0) 
	{
		opacity(id, 0, 100, millisec); 
    } 
	else 
	{ 
        opacity(id, 100, 0, millisec); 
    } 
} 
*/

function fullOpacity(id, millisec, str) 
{ 
	
	if(str.length > 0)
	{
		document.getElementById(id).style.visibility = 'visible';
	
		// TODO - fix
		/*
		if(document.getElementById(id).style.visibility != 'visible')
		{
			//if an element is invisible, make it visible, else make it invisible 
			opacity(id, 0, 100, millisec); 
			
			document.getElementById(id).style.visibility = 'visible';
		}
		*/
	}
	
}

function noneOpacity(id, millisec) 
{
	document.getElementById(id).style.visibility = 'hidden';
	
	// TODO - fix
    /*
	opacity(id, 100, 0, millisec); 
	
	setTimeout("CloseLocator('" + id + "')", millisec);
	*/
}

function opacity(id, opacStart, opacEnd, millisec) 
{ 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) 
	{ 
        for(i = opacStart; i >= opacEnd; i--) 
		{ 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			
            timer++; 
        } 
    } 
	else if(opacStart < opacEnd) 
	{ 
        for(i = opacStart; i <= opacEnd; i++) 
        { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
        
			timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) 
{ 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function CloseLocator(id)
{
	document.getElementById(id).style.visibility = 'hidden';
}

/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->



var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}
*/
