﻿        
var datasource = "footetravis136371.136371.woodlandsrentals";
var entityName = "Rentals";
var searchRadius = 10;
var MLSLAYER = new VEShapeLayer();
MLSLAYER.SetTitle("MLS Layer");



var xmlhttp=false;

     function InitXmlHttp() 
     {
        // Attempt to initialize xmlhttp object
        try
        {
           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
           // Try to use different activex object
           try
           {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
           }
           catch (E)
           {
              xmlhttp = false;
           }
        }
        // If not initialized, create XMLHttpRequest object
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
           xmlhttp = new XMLHttpRequest();
        }

        // Define function call for when Request obj state has changed
        xmlhttp.onreadystatechange = SearchHandler;
     }

     function SearchHandler()
     {
        if (xmlhttp.readyState == 4)
        {
           //alert("Got the response text:\n" + xmlhttp.responseText);
           
           eval(xmlhttp.responseText);
        }
     }

 function AddPin(lat, lng, title, description, id)
 {
    try 
    {
       var shape = new VEShape(VEShapeType.Pushpin, 
                               new VELatLong(lat, lng));
       shape.SetTitle(title);
       
       var url = "javascript:LoadMLS(ID="+id+");";
       
       description+="<br/><a href='"+url+"'>Details</a>";
       shape.SetDescription(description);
       
       shape.SetCustomIcon("images/single_blue_small.png");

       //Dynimically build the more info url
       //var url = location.protocol+"//"+location.host +"/mlssearch.aspx?IDSearch="+id;
       //alert(url);
       
       
       shape.SetMoreInfoURL(url);
       MLSLAYER.AddShape(shape);
       //map.AddShape(shape);
    } 
    catch (err)
    {
       alert(err);
    }
 }

 function FindNearBy()
 {
    //map.DeleteAllShapes();

    var ll = map.GetCenter();
    


    InitXmlHttp();

    var msg = "MapPointServiceHandler.ashx?&FT=FindNearBy&Lat=" +
              ll.Latitude +
              "&Lng=" +
              ll.Longitude +
              "&DBS=" +
              datasource +
           "&ENTY=" +
              entityName +
              "&Dis=" +
              searchRadius;

    xmlhttp.open("GET", msg, true);
    xmlhttp.send(null);
    
   
 }

 function FindByProperty()
 {
    map.DeleteAllShapes();

    var expression = "Subdivision = {0}";
    var parameters = "%Grogan%"
    var ll = map.GetCenter();

    InitXmlHttp();

    var msg = "MapPointServiceHandler.ashx?&FT=FindByProperty&DBS=" +
              datasource +
              "&ENTY=" +
              entityName +
              "&Exp=" +
              expression +
              "&PRM=" +
              parameters;
     
    xmlhttp.open("GET", msg, true);
    xmlhttp.send(null);
 }

 function FindByID()
 {
    map.DeleteAllShapes();

    var arrayID = "-11777,-11781,-11789";

    InitXmlHttp();

    var msg = "MapPointServiceHandler.ashx?&FT=FindByID&DBS=" +
              datasource +
           "&ENTY=" +
              entityName +
              "&ID=" +
              arrayID;

    xmlhttp.open("GET", msg, true);
    xmlhttp.send(null);
 }

 function FindNearRoute()
 {
    map.DeleteAllShapes();

    var startLocation = new VELatLong(47.301036844193135, 
                                      -122.32933044433595);
    var endLocation = new VELatLong(47.441474801849466, 
                                    -122.24487304687503);
    var mappointDatasource = "MapPoint.NA"
    var distance = 5;
    var routeType = "Quickest";

    var options = new VERouteOptions;
    options.UseMWS = true;
    options.RouteOptimize = VERouteOptimize.MinimizeTime;

    var locations = new Array(startLocation, endLocation);

    map.GetDirections(locations, options); 

    InitXmlHttp();

    var msg = "MapPointServiceHandler.ashx?&FT=FindNearRoute&sLat=" +
              startLocation.Latitude +
              "&sLng=" +
              startLocation.Longitude +
              "&eLat=" +
              endLocation.Latitude +
              "&eLng=" +
              endLocation.Longitude +
              "&mDBS=" +
              mappointDatasource +
              "&DBS=" +
              datasource +
              "&ENTY=" +
              entityName +
              "&RT=" +
              routeType +
              "&DIS=" +
              distance;
    
    xmlhttp.open("GET", msg, true);
    xmlhttp.send(null);
 }


