﻿  var map = null;
  var br = null;
    function whichBrs() 
    {
        var agt=navigator.userAgent.toLowerCase();
        if (agt.indexOf("opera") != -1) 
            return 'Opera';
        if (agt.indexOf("staroffice") != -1) 
            return 'Star Office';
        if (agt.indexOf("webtv") != -1) 
            return 'WebTV';
        if (agt.indexOf("beonex") != -1) 
            return 'Beonex';
        if (agt.indexOf("chimera") != -1) 
            return 'Chimera';
        if (agt.indexOf("netpositive") != -1) 
            return 'NetPositive';
        if (agt.indexOf("phoenix") != -1) 
            return 'Phoenix';
        if (agt.indexOf("firefox") != -1) 
            return 'Firefox';
        if (agt.indexOf("safari") != -1) 
            return 'Safari';
        if (agt.indexOf("skipstone") != -1) 
            return 'SkipStone';
        if (agt.indexOf("msie") != -1) 
            return 'Internet Explorer';
        if (agt.indexOf("netscape") != -1) 
            return 'Netscape';
        if (agt.indexOf("mozilla/5.0") != -1) 
            return 'Mozilla';
        if (agt.indexOf('\/') != -1) 
        {
            if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') 
            {
                return navigator.userAgent.substr(0,agt.indexOf('\/'));
            }
                else 
                    return 'Netscape';
        } 
        else if (agt.indexOf(' ') != -1)
            return navigator.userAgent.substr(0,agt.indexOf(' '));
        else 
            return navigator.userAgent;
    }   
  function GetMap(tkn)
  {
     map = new VEMap('zalesMap');
     map.SetClientToken(tkn);
     map.LoadMap();
     var printOptions = new VEPrintOptions(true);
     map.SetPrintOptions(printOptions);
     map.SetMapStyle(VEMapStyle.Road);
     document.getElementById('MSVE_obliqueNotification').style.visibility='hidden';
     br = whichBrs();
  }
  function ZoomAndCenter()
  {
     var lat = document.getElementById('txtLat').value;
     var lng = document.getElementById('txtLong').value;
     map.SetCenterAndZoom(new VELatLong(lat, lng), 15);
     var t = document.getElementById('txtType').value;
     var mn = document.getElementById('txtMallName').value;
     var storePic = document.getElementById('txtStorePicture').value; 
     if( t != ' ')
     {
        shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,lng));
        //shape.SetTitle(mn);
        shape.SetTitle(mn+'<br />'+'<img src="'+storePic+'" />');
        shape.SetCustomIcon('<img src="'+t+'" />');
        map.AddShape(shape); 
        map.ShowInfoBox(shape);
     }
  }
  function ClearMap()
  {
     map.DeleteAllShapes();
  }
  
   function GetDir()
  {
     var t = document.getElementById('txtType').value;
     var stPic = document.getElementById('txtStorePicture').value;
     var mn = document.getElementById('txtMallName').value; 
     var from = document.getElementById('txtFrom').value;
     var to = document.getElementById('txtTo').value;
     var myOptions = new VERouteOptions();
     myOptions.UseMWS = true;
     myOptions.ShowDisambiguation = false;
     var frmLat = from.split(',')[0];var frmLong = from.split(',')[1];
     var toLat = to.split(',')[0];var toLong = to.split(',')[1];
     if( !(t == ' ' || t == ''))
     {
        //clear map
        ClearMap();
        shape = new VEShape(VEShapeType.Pushpin, new VELatLong(toLat,toLong));
        shape.SetTitle(mn+'<br />'+'<img src="'+stPic+'" />');
        shape.SetCustomIcon('<img src="'+t+'" />');
        map.AddShape(shape); 
        map.ShowInfoBox(shape);
     }
     map.GetDirections([new VELatLong(parseFloat(frmLat),parseFloat(frmLong)), new VELatLong(parseFloat(toLat),parseFloat(toLong))], myOptions);
  }
  
  function CenterAtSelectedPin(latitude, longitude, type, mapFrame)
  { 
    if(map == null)
    {
        var lat; var lng;  var btnZoom;
         br = whichBrs();
        if(br == 'Internet Explorer' || br == 'Safari')
        {
             lat = window.frames[mapFrame].document.getElementById('txtLat'); 
             lng = window.frames[mapFrame].document.getElementById('txtLong');
             btnZoom =  window.frames[mapFrame].document.getElementById('zoomBt');
             window.frames[mapFrame].document.getElementById('txtType').value = type;
        }
        if(br == 'Firefox')
        {
             lat = document.getElementById(mapFrame).contentDocument.getElementById('txtLat'); 
             lng = document.getElementById(mapFrame).contentDocument.getElementById('txtLong');
             btnZoom =  document.getElementById(mapFrame).contentDocument.getElementById('zoomBt');
             document.getElementById(mapFrame).contentDocument.getElementById('txtType').value = type;
        }
        lat.value = latitude; 
        lng.value = longitude; 
        btnZoom.click();
    }
    else
        map.SetCenterAndZoom(new VELatLong(latitude, longitude), 20);
  }
  
  function AddPinAndCenterMap(type, latitude, longitude, mallName, storePic, mapFrame)
  {  
        var lat; var lng; var tTp; var tMName; var tStorePic; var btnZoom;
        br = whichBrs();
        if(br == 'Internet Explorer' || br == 'Safari')
        {        
            lat =  window.frames[mapFrame].document.getElementById('txtLat'); 
            lng =  window.frames[mapFrame].document.getElementById('txtLong');
            tTp =  window.frames[mapFrame].document.getElementById('txtType');
            tMName = window.frames[mapFrame].document.getElementById('txtMallName');
            tStorePic= window.frames[mapFrame].document.getElementById('txtStorePicture');
            btnZoom = window.frames[mapFrame].document.getElementById('zoomBt');
            btnClr = window.frames[mapFrame].document.getElementById('clrBt');
        }
        if(br == 'Firefox')
        {        
            lat =  document.getElementById(mapFrame).contentDocument.getElementById('txtLat'); 
            lng =  document.getElementById(mapFrame).contentDocument.getElementById('txtLong');
            tTp =  document.getElementById(mapFrame).contentDocument.getElementById('txtType');
            tMName = document.getElementById(mapFrame).contentDocument.getElementById('txtMallName');
            tStorePic= document.getElementById(mapFrame).contentDocument.getElementById('txtStorePicture');
            btnZoom = document.getElementById(mapFrame).contentDocument.getElementById('zoomBt');
            btnClr = document.getElementById(mapFrame).contentDocument.getElementById('clrBt');
        }
        lat.value = latitude; 
        lng.value = longitude;
        tTp.value = type;
        tMName.value = mallName; 
        tStorePic.value = storePic;
        btnClr.click();
        btnZoom.click();
  }  
function GetDirections(frm, toD, type, mapFrame, storePic)
{
    if(map == null)
    {
        var from ; var to ; var btnGetDir; 
         br = whichBrs();       
        if(br == 'Internet Explorer' || br == 'Safari')
        { 
             from = window.frames[mapFrame].document.getElementById('txtFrom'); 
             to = window.frames[mapFrame].document.getElementById('txtTo');
             btnGetDir = window.frames[mapFrame].document.getElementById('getDir');
             window.frames[mapFrame].document.getElementById('txtType').value = type;
             window.frames[mapFrame].document.getElementById('txtStorePicture').value = storePic;
             window.frames[mapFrame].document.getElementById('txtMallName').value = mallName;
        }
        if(br == 'Firefox')
        { 
             from =  document.getElementById(mapFrame).contentDocument.getElementById('txtFrom'); 
             to =  document.getElementById(mapFrame).contentDocument.getElementById('txtTo');
             btnGetDir = document.getElementById(mapFrame).contentDocument.getElementById('getDir');
             document.getElementById(mapFrame).contentDocument.getElementById('txtType').value = type;
             document.getElementById(mapFrame).contentDocument.getElementById('txtStorePicture').value = storePic;
             document.getElementById(mapFrame).contentDocument.getElementById('txtMallName').value = mallName;
        }
        from.value = frm; 
        to.value = toD; 
        btnGetDir.click();
    }
    else
        map.GetDirections([frm, toD]);
}   