// JScript File
var AirfieldLayer=null;
var map = null;
var ShowAirfields = true;

function SetAirfieldMAP()
{
    if(document.getElementById('myMap') != null)
    {
        if(map == null){
            map = new VEMap('myMap');
            map.LoadMap();
        }
        AirfieldLayer = new VEShapeLayer(); 
        map.AddShapeLayer(AirfieldLayer);
        map.AttachEvent('onchangeview', AddPin);
    }
}

function AddPin(){ 
    if(ShowAirfields==true)
    {
        var mapRect = map.GetMapView();
        var topleftlat = mapRect.TopLeftLatLong.Latitude;
        var topleftlon = mapRect.TopLeftLatLong.Longitude;
        var bottomrightlat = mapRect.BottomRightLatLong.Latitude;
        var bottomrightlon = mapRect.BottomRightLatLong.Longitude;
        //map.DeleteAllPushpins();
        AirfieldLayer.DeleteAllShapes();
        AJAXMethods.BoundingBoxAirfield(topleftlat,topleftlon,bottomrightlat,bottomrightlon,aspnetForm.cid.value,callback_title);
        //alert("show");
    }else{
        AirfieldLayer.DeleteAllShapes();
    }
} 

function callback_title(res)
{
    addPushPins(res.value);
}

function addPushPins(data)
{
    try
    {
        if(ShowAirfields)
        {
            //alert(data);
            var pin = null;
            var parts = null;
            if(data != null && data != ""){
                var myArray = data.split('|');
                var arLen=myArray.length; 
                for ( var i=0, len=arLen; i<len; ++i ){
                    parts = myArray[i].split(',');
                    if(myArray[i].length > 0)
                    {
                        pin = new VEShape(VEShapeType.Pushpin, new VELatLong(parseFloat(parts[0]), parseFloat(parts[1])));
                        pin.SetCustomIcon("<img src='http://www.flightnav.co.uk/images/" + parts[4] +".png'/>");
                        pin.SetDescription(parts[2] + "<br>" + parts[3]);
                        AirfieldLayer.AddShape(pin);
                    }
                }
            }   
        }
    }
    catch(err)
    {
        alert("addPushPins Exception:" + err.message +"\n\n" + parts[0]+"\n"+parts[1] );
    }
}

function ShowHideAirfields()
{
    AirfieldLayer.DeleteAllShapes();
    if(ShowAirfields == true)
    {
        ShowAirfields=false;
    }else{
        ShowAirfields=true;
        var mapRect = map.GetMapView();
        var topleftlat = mapRect.TopLeftLatLong.Latitude;
        var topleftlon = mapRect.TopLeftLatLong.Longitude;
        var bottomrightlat = mapRect.BottomRightLatLong.Latitude;
        var bottomrightlon = mapRect.BottomRightLatLong.Longitude;
        AJAXMethods.BoundingBoxAirfield(topleftlat,topleftlon,bottomrightlat,bottomrightlon,callback_title)
    }
}

function getQueryVariable(variable) 
{ 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) 
    { 
        var pair = vars[i].split("="); 
        if (pair[0] == variable) 
        { 
            return pair[1]; 
        } 
    } 
} 

<!--
var doAll = (document.all!=null)

function getCSSPElement(id) {    
// Return the positioned element with
// the specified ID       
if (doAll)       
  return document.all[id]    
else
  return document.layers[id]  
 }

function checkIFrame(destID) {
  var iframe = document.frames[destID+"target"]
  if (iframe==null) {
    document.body.insertAdjacentHTML("beforeEnd","<IFRAME STYLE='width: 0pt; height: 0pt' NAME='"+destID+"target' SRC='' ></IFRAME>")
    iframe = document.frames[destID+"target"]
  }
  return iframe
}

function pollIFrame(destID) {
  var destFrame = checkIFrame(destID)
  if (destFrame.document.readyState=='complete') {
    var el = getCSSPElement(destID)
    el.innerHTML = destFrame.document.body.innerHTML
  } else
    setTimeout("pollIFrame('"+destID+"')",200)        
}

function updateContents(destID, src) {
  var el = getCSSPElement(destID)
  if (doAll) {
    destFrame = checkIFrame(destID)
    destFrame.location.href = src        
    setTimeout("pollIFrame('"+destID+"')",200)
  }
  else
    el.src = src      
}

function update(destID, src) {
  if (src=="none") {
    var el = getCSSPElement(destID)
    if (doAll)
      el.innerHTML = ""
    else {
      el.document.open()
      el.document.write("")
      el.document.close()
    }
  }
  else
    updateContents(destID, src)
}

function showElement(id) {        
  var pEl = getCSSPElement(id);
  document.getElementById(id).style.top=800;
  document.getElementById(id).style.left=50;
  if (pEl != null)
    e = window.event;          
    if (doAll){
        pEl.style.visibility = "visible"  
        pE1.style.top = e.clientY;  
    }     
    else
        pEl.visibility = "show"      
 }      

 function hideElement(id) {
    var pEl = getCSSPElement(id)        
    if (pEl != null)          
    if (doAll)
        pEl.style.visibility = "hidden"          
    else
        pEl.visibility = "hide"      
 }

 function hideShow(destID,cb) {
   if (cb.checked)
     showElement(destID)
   else
     hideElement(destID)
 }

