﻿

var map = null;
var z = null;        
var Latitude = null;                    //Map Center Latitude from Querystring
var Longitude = null;                  //Map Center Longitude from Querystring
var hiddnefieldID="";
var hiddenFavListingID="";
var MapLatLongs=null;
var LatLongArray=null;
var tempLatitude = null;
var tempLongitude = null;
var qs =null;
var mapzoomlevel=null;
var criteriaContext = null;




    function LoadMap() {
        if (map == null) {
            showmapcon();
        }

        //alert('hit');
        ReadControlValues(this);
        GetListings();
    }

        
        function showmapcon()
        {
           //Get Lat/Long for Map Center if passed from querystring
    
                 tempLatitude = null;
                 tempLongitude = null;

                 var IMLL = GetCookie("IMLL");
                 if (IMLL != null) {
                     IMLL = IMLL.replaceAll(",", ";");
                     document.getElementById(hiddnefieldID).value = IMLL;
                     MapLatLongs = document.getElementById(hiddnefieldID).value
                     LatLongArray = MapLatLongs.split(";");
                 }
     
               
               if(LatLongArray!= null && LatLongArray[4] != "" && LatLongArray[5] !="") //check if center lat long given
                {
                    Latitude=LatLongArray[4];
                    Longitude=LatLongArray[5];
                    mapzoomlevel=LatLongArray[6];

                    $("#hfLatitude").val(Latitude);
                    $("#hfLongitude").val(Latitude);
                                    
                }
                else
                {
                    // No Query string,
                    // Set to defaults
                    Latitude = "47.63115648664201";
                    Longitude = "-122.19509124755862";
                    mapzoomlevel = "10"; 
                    
                }
                
                
                map = new VEMap('veMap');         
                 map.LoadMap(new VELatLong(Latitude, Longitude), mapzoomlevel, 'r', false);
                var search = document.getElementById('divpopup');

                
                map.AttachEvent("onendzoom", GetListings);
                map.AttachEvent("onendpan", GetListings);
               //map.AttachEvent("onstartzoom",GetListings);
               
                
               // Attacht Evenet Lsitner from Here
               // catch and call listners here
               
                if(criteriaContext == null)
                    criteriaContext = $("#InteractiveMapSearFormArea");
                    
               // Dropdowns 
                $(".ddlSelectPriceFrom", criteriaContext).change(function(){ PriceFrom=$(this).val(); GetListings(this);});
                $(".ddlSelectPriceTo", criteriaContext).change(function(){ PriceTo=$(this).val(); GetListings(this);});
                $(".ddlBeds", criteriaContext).change(function(){ Bedrooms=$(this).val(); GetListings(this);});
                $(".ddlBaths", criteriaContext).change(function(){ Bathrooms=$(this).val(); GetListings(this);});
                $(".ddlSquareFeet", criteriaContext).change(function(){ SquareFeet=$(this).val(); GetListings(this);});
                $(".ddlTimeOnMarket", criteriaContext).change(function(){ Timeonmarket=$(this).val(); GetListings(this);});                
                $(".ddlyearbuild", criteriaContext).change(function(){ YearBuilt=$(this).val(); GetListings(this);});
                $(".ddlMinAcreage", criteriaContext).change(function(){ MinAcreage=$(this).val(); GetListings(this);});
                $(".ddlMaxAcreage", criteriaContext).change(function(){ MaxAcreage=$(this).val(); GetListings(this);});
                $(".ddlStories", criteriaContext).change(function(){ Stories=$(this).val(); GetListings(this);});
                $(".ddlGarage", criteriaContext).change(function() { Garages = $(this).val(); GetListings(this); });

                $(".ddlOpenHouses", criteriaContext).change(function() { OpenHouses = $(this).val(); GetListings(this); });
                
                $(".ddlPropertiesPerPage").change(PageListingTable);
                  

                  //set lotland checkboxed to disabled
                   $(".chkGas  :checkbox ", criteriaContext).attr('disabled', true); 
                   $(".chkElectric :checkbox", criteriaContext).attr('disabled', true); 
                   $(".chkWater :checkbox", criteriaContext).attr('disabled', true); 
                   $(".chkSewer :checkbox", criteriaContext).attr('disabled', true); 
                        
         
                // CHECK BOXES  
                 // (Property Types)
                  $(".chkSingleFamily :checkbox", criteriaContext).click(function(){ SingleFamily=$(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this);})
                  $(".chkCondo :checkbox", criteriaContext).click(function(){ Condo=$(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this);});
                  $(".chkMultiFamily :checkbox", criteriaContext).click(function(){ MultiFamily=$(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this);});
                  $(".chkManufacturedHome :checkbox", criteriaContext).click(function(){ ManuHome=$(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this);});
                  $(".chkFarm :checkbox", criteriaContext).click(function(){ Farm=$(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this);});                
                
                   // Lots and Land
                   $(".chknLotsLand :checkbox", criteriaContext).click(function(){ LotsLand=$(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this);});
                   $(".chkGas :checkbox", criteriaContext).click(function(){ Gas=$(this).is(":checked"); GetListings(this);});
                   $(".chkElectric :checkbox", criteriaContext).click(function(){ Electric=$(this).is(":checked"); GetListings(this);});
                   $(".chkWater :checkbox", criteriaContext).click(function(){ Water=$(this).is(":checked"); GetListings(this);});
                   $(".chkSewer :checkbox", criteriaContext).click(function(){ Sewer=$(this).is(":checked"); GetListings(this);});
                   
                   // featuers
                   $(".chkView :checkbox", criteriaContext).click(function(){ FeatureView=$(this).is(":checked"); GetListings(this);});
                   $(".chkWaterFront :checkbox", criteriaContext).click(function(){ FeatureFront=$(this).is(":checked"); GetListings(this);});
                   $(".CheckbchkHouseBoatox :checkbox", criteriaContext).click(function(){ FeatureBoat=$(this).is(":checked"); GetListings(this);});

                  $(".chkSeperateDwelling :checkbox", criteriaContext).click(function(){ SeperateDwelling=$(this).is(":checked"); GetListings(this);});
                  $(".chkBonusRoom :checkbox", criteriaContext).click(function(){ BonusRoom=$(this).is(":checked"); GetListings(this);});
                  $(".chkMasterOnMain :checkbox", criteriaContext).click(function(){ MasterOnMain=$(this).is(":checked"); GetListings(this);});

                  $(".chkIsSold :checkbox").click(function() { IsSold = $(this).is(":checked"); GetListings(this); });
                  $(".chkOpenHouses :checkbox").click(function() { OpenHouseOnly = $(this).is(":checked"); ValidateCheckBoxes(this); GetListings(this); });
                  $(".chkNewOnMarket :checkbox").click(function() { ValidateCheckBoxes(this); if (!$(this).is(":checked")) { GetListings(this); } });
                  // Chk ViewLegend
                  //$(".chkViewLegends :checkbox").click(GetListings);
                  $(".lnkViewLegends").click(function() { ShowHideLegend(true,500,200); return false; });
                  $(".divLegendClose").click(function() { ShowHideLegend(false,500,200); });
                  
                  
                 
                  // also check if View Office listing is called
                  // attach listner here
                  $(".chkShowOffices :checkbox").click(GetOffices);
                 
                //Swiitching Classes so the map has more room to operate in.
                //There has to be a better way to do this (remove these remarks).
                $('#Canvas').width("998px");
                $('#Header').width("998px");
            

        
        }
      