﻿// JScript File

var map = null;
var _blueIcon = "<img src='images/UI/blue-marker.png' />";  //Set blue icon           
function GetMap(lat,lng,address,caprate,broker,photo,propname,price,sqft,proptype) {   
    
    MapOn();

    // Only show the map if the lat/lng exist
    if (lat != 0.0 && lng != 0.0) {
              
        // Pull out all the detailed information
        var latitude = Number(lat);
        var longitude = Number(lng);
        
        if (photo == "") {
            photo = "No Photo Available";
        } else {
            photo = "<img src=\"" + photo + "\" style=\"width:100px;border:1px solid #333333\"/>"
        }
        
        if (proptype == 0) {
        
            // The Info Bubble
            var html = "<table style=\"padding:2px;border:1px solid #333333;\"><tr>" + 
                "<td colspan=\"1\" style=\"background-color:#225783;color:#ffffff;padding:15px;width:300px\"><b>Address</b><br/>" + address + "</td>" +
                "</tr><tr>" +
                "<td rowspan=\"1\" valign=\"top\">" + photo + "</td>" +
                "</tr>" +
                "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Price:</b> $" + price + "</td></tr>" +
                "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Space:</b> " + sqft + " SqFt</td></tr>" +
                "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Cap. Rate:</b> " + caprate + "</td></tr>" +
                "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Broker:</b> " + broker + "</td></tr>" +
                "<table>";
        }
        else {
        
            // The Info Bubble
            var html = "<table style=\"padding:2px;border:1px solid #333333;\"><tr>" + 
                "<td colspan=\"1\" style=\"background-color:#225783;color:#ffffff;padding:15px;width:300px\"><b>Address</b><br/>" + address + "</td></tr>" +
                "<tr><td rowspan=\"1\" valign=\"top\">" + photo + "</td>" +
                "</tr>" +
                "<tr><td colspan=\"1\" style=\"padding:10px;color:#333333;\"><b>Property Type:</b> " + sqft + "</td></tr>" +
                "<table>";

        }
        //Disable Birds Eye View
        var mo = new VEMapOptions();
        mo.EnableBirdseye = false;

        // Load the base map
        var location = new VELatLong(lat, lng);
        map = new VEMap('eGovMap'); 
        map.LoadMap(null, null, null, null, null, null, null, mo);   
        map.SetCenterAndZoom(location, 15);
        // map.ClearInfoBoxStyles();
        
        // Place the point on the map
        var shape = new VEShape(VEShapeType.Pushpin, location);
        shape.SetCustomIcon(_blueIcon);
        shape.SetTitle(propname);
        shape.SetDescription(html); 
                
        map.AddShape(shape);   
    }
    else {
        document.getElementById('eGovMap').style.textAlign = "center";
        document.getElementById('eGovMap').style.color ="#333333";
        document.getElementById('eGovMap').innerHTML = "<br/><br/><br/><br/>Sorry, there is no location/map data available for this listing.";
    }
    
}

//Lat Lng for Demographic Page
var dLat = null;
var dLon = null;
var PropName = null;

//Get vars passed in
function getLatLng() {
    if (window.location.search.substring(1)) {
        // Take everything after 'Map.aspx'
        dLat = querySt("lat");
        dLon = querySt("lng");
        PropName = decodeURIComponent(querySt("name"));
        PropName = PropName.replace(/\+/g," ");
    }
    else {
        alert("no lat/long submitted");
    }
}

//Load the map on the demographics page and zoom to the area of interest.
var _drawingLayer = new VEShapeLayer();
function LoadDemographicMap()//zoom is boolean
{

        getLatLng();
        
        if(dLat != null || dLon != null) {
          //Disable Birds Eye View
          var mo = new VEMapOptions();
          mo.EnableBirdseye = false;
            
          var location = new VELatLong(dLat, dLon);
          map = new VEMap('eGovMap');
          map.LoadMap(null, null, null, null, null, null, null, mo);   

          map.SetCenterAndZoom(location, 12);

          map.AddShapeLayer(_drawingLayer);
        }
        
        if(PropName != null) 
        {
            document.getElementById('demTitle').innerHTML = PropName;
        }
}

function runDemographicSearch()
{
    //Get the radius from the drop down list
    var radius = getRadiusFromList();
    //Lat Long are globals - dLat, dLon
    
    //Draw the map.
    //Clear drawing layer.
    _drawingLayer.DeleteAllShapes();
    
    drawCircle(radius, dLat, dLon);
}

function getRadiusFromList()
{
    var bufferSize = 0;
    var radiusList = $('uxRadius');
    if(radiusList)
    {
      bufferSize = (radiusList.options[radiusList.selectedIndex].value); //miles
      return bufferSize;
    }
    //Default
    return 0;
}


function setMapProps(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10) {

    var MapProps = new Array();
    MapProps[0] = v1;
    MapProps[1] = v2;
    MapProps[2] = v3;
    MapProps[3] = v4;
    MapProps[4] = v5;
    MapProps[5] = v6;
    MapProps[6] = v7;
    MapProps[7] = v8;
    MapProps[8] = v9;
    MapProps[9] = v10;

    MainMapOn();

    //Disable Birds Eye View
    var mo = new VEMapOptions();
    mo.EnableBirdseye = false;

    map = new VEMap('wrapper-mainMap');
    map.LoadMap(null, null, null, null, null, null, null, mo);   
    var iconCounter = 1;

    for(i=0;i<MapProps.length;i++) {
    
        if (MapProps[i] != null) {
            var vars = MapProps[i].split('|');
            
            if (vars[0] != 0.0 && vars[1] != 0.0) {
            
                if (vars[5] == "") {
                    photo = "No Photo Available";
                } else {
                    photo = "<img src=\"" + vars[5] + "\" style=\"width:100px;border:1px solid #333333\"/>";
                }
                
                if (vars[9] == 0) {
                    var html = "<table style=\"padding:2px;border:1px solid #333333;\"><tr>" + 
                        "<td colspan=\"1\" style=\"background-color:#225783;color:#ffffff;padding:15px;width:300px\"><b>Address</b><br/>" + vars[2] + "</td>" +
                        "</tr><tr>" +
                        "<td rowspan=\"1\" valign=\"top\">" + photo + "</td>" +
                        "</tr>" +
                        "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Price:</b> $" + vars[7] + "</td></tr>" +
                        "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Space:</b> " + vars[8] + " SqFt</td></tr>" +
                        "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Cap. Rate:</b> " + vars[3] + "</td></tr>" +
                        "<tr><td colspan=\"2\" style=\"padding:10px;color:#333333;\"><b>Broker:</b> " + vars[4] + "</td></tr>" +
                        "<table>";
                 }
                 else {
                    var html = "<table style=\"padding:2px;border:1px solid #333333;\"><tr>" + 
                        "<td colspan=\"1\" style=\"background-color:#225783;color:#ffffff;padding:15px;width:300px\"><b>Address</b><br/>" + vars[2] + "</td></tr>" +
                        "<tr><td rowspan=\"1\" valign=\"top\">" + photo + "</td>" +
                        "</tr>" +
                        "<tr><td colspan=\"1\" style=\"padding:10px;color:#333333;\"><b>Property Type:</b> " + vars[8] + "</td></tr>" +
                        "<table>";
                 }
                // var icon = "<div style='font-size:12px;font-weight:bold;border:2px solid #ffffff;background-color:#225783;padding:3px;color:#ffffff;width:20px;text-align:center;'>" + iconCounter + "</div>";
                var icon = "<div style=\"width:30px;height:30px;padding-top:2px;font-size:10px;text-align:center;color:#ffffff;background: url('images/UI/blue-marker.png');\">" + iconCounter + "</div>"
                 
                var location = new VELatLong(vars[0], vars[1]);
                var shape = new VEShape(VEShapeType.Pushpin, location);
                shape.SetCustomIcon(icon);
                shape.SetTitle(vars[6]);
                shape.SetDescription(html);
                map.AddShape(shape);
                map.SetCenterAndZoom(location, 12);
                
                iconCounter++;
            }
        }
    }
}

