﻿// JScript File
function onAirportBoxKeyUp(edName,hdName,dvName,imName)
{
    var ed=$get(hdName);
    ed.value="";
    var im=$get(imName);
    im.style.display="none";
    var dv=$get(dvName);
    ed=$get(edName);
    var loc=new String((ed.value!=null?ed.value:""));
    
    if (loc.length<=2) dv.style.display="none";
    else airports.List(ed.value,false,airportsListCallback,airportsListFailed, edName+";"+hdName+";"+dvName+";"+imName);
}
function airportsListCallback(result,userContext,methodName)
{
    var s=String(userContext).split(";");
    var edName=s[0],hdName=s[1],dvName=s[2],imName=s[3],tbl="";
    var xmlObjs=result.documentElement.getElementsByTagName("airport");
    var dv=$get(dvName);
    if (xmlObjs!=null && xmlObjs.length>0)
    {
        tbl="<table border='0' cellpadding='0' cellspacing='0' style='cursor:"+(IsIE()?"hand":"pointer")+";width:100%'>";
        
        for(var i=0;i<xmlObjs.length;i++)
        {
            tbl+="<tr class='airDiv' id='"+dvName+i+"' ";
            tbl+=(IsIE()?"onmouseenter":"onmouseover")+"='onAirportsListDraw(true,\""+dvName+i+"\")' ";
            tbl+=(IsIE()?"onmouseleave":"onmouseout")+"='onAirportsListDraw(false,\""+dvName+i+"\")' ";
            tbl+="onmousedown='onAirportsListL(\""+edName+"\",\""+hdName+"\",\""+dvName+"\",\""+imName+"\",\""+xmlObjs[i].getAttribute("code")+"\",\""+escape(xmlObjs[i].getAttribute("name"))+"\")'>";
            tbl+="<td style='padding:2px' valign='top'>"+xmlObjs[i].getAttribute("name")+"</td>";
            tbl+="<td style='padding:2px' valign='top'><b>"+xmlObjs[i].getAttribute("ccode")+"</b></td></tr>";
        }
        
        if (xmlObjs.length==1)
        {
            var ed=$get(edName);
            ed.value=xmlObjs[0].getAttribute("name");
            ed.focus();
        
            ed=$get(hdName);
            ed.value=xmlObjs[0].getAttribute("code");
            
            var im=$get(imName);
            im.style.display="";

            dv.style.display="none";
        }
        else
        {
            xmlObjs=result.documentElement.getElementsByTagName("country");
            if (xmlObjs.length>1)
            {
                tbl+="<tr><td colspan='2'>";
                tbl+="<table border='0' cellspacing='1' cellspacing='2' style='margin:4px;width:94%'>";
                for(var i=0;i<xmlObjs.length;i++)
                    tbl+="<tr class='airDivSel'><td><b>"+xmlObjs[i].getAttribute("code")+"</b>:</td><td>"+xmlObjs[i].getAttribute("name")+"</td></tr>";                
                tbl+="</table>";
                tbl+="</td></tr>";
            }

            dv.style.display="";
        }
        
        tbl+="</table>";
        dv.innerHTML=tbl;
    }
    else
        dv.style.display="none";
}
function onAirportsListL(edName,hdName,dvName,imName,code,name)
{
    var hd=$get(hdName);
    hd.value=code;

    var im=$get(imName);
    im.style.display="";

    var dv=$get(dvName);
    dv.style.display="none";

    var ed=$get(edName);
    ed.value=unescape(name);
    ed.focus();
}
function onAirportsListDraw(high,id)
{
    var tr=$get(id);
    tr.className=(high?"airDivSel":"airDiv");
}
function airportsListFailed()
{
}
function onAirportBoxBlur(edName,dvName)
{
    var dv=$get(dvName);
    dv.style.display="none";
}

