﻿//the map object
var map = null;

//load map    
function Page_Load() {  
    var mapArgs = new Rhc.Mapping.MapArgs("myMap", new VELatLong(53.23234504341257, -3.0596923828124964), 6, VEMapStyle.Shaded, false, VEMapMode.Mode2D, VEDistanceUnit.Kilometers);
    map = new Rhc.Mapping.Map(Rhc.Mapping.MapService, mapArgs);
}  

//Clean up all objects
function Page_Unload() {
    if (map!=null) {
        map.Dispose();
        map = null;
    }
}

function ValueChanged(param, val)
{
    switch (param)
    {
        case 'minPrice':
            map.setMinPrice(val);
            break;
            
        case 'maxPrice':
            map.setMaxPrice(val);
            break;
            
        case 'beds':
            map.setBeds(val);
            break;
            
        case 'baths':
            map.setBaths(val);
            break;
            
        case 'type':
            map.setType(val);
            break;
        
        case 'listedin':
            map.setListedIn(val);
            break;
            
        default:
            break;
    }
    
    map._GetPinData();
    
    
}  



function FeatureValueChanged(param, featureNumber, val)
{
    if(featureList[featureNumber] != null)
    {
       featureList[featureNumber] = null; 
    }
    else
    {
        featureList[featureNumber] = val;
    }

    var features = "";

    for (i=0; i<=featureList.length; i=i+1) 
    {
        if(featureList[i] != null && featureList[i] != 0)
        {
            if(features == '')
                features += featureList[i];
            else
                features += "," + featureList[i];
        }
    }

    map.setFeatures(features);
    
    map._GetPinData();
}


function MapSearch(text)
{
    try         
    {
        map.Find(text + ', United Kingdom');
    }  
    catch(e)
    {
        alert(e.message);
    }
}

function SearchTextChanged(event, text)
{
    iAscii = event.keyCode ? event.keyCode : event.which

    if(iAscii == null)
    {
        return false;
    }

    // if they press enter
    if(iAscii == 13)
    {
        MapSearch(text);
        event.returnValue=false;
    }        
}

//set page event handlers
if (window.attachEvent) {
	window.attachEvent("onload", Page_Load);
	window.attachEvent("onunload", Page_Unload);	
} else {
	window.addEventListener("DOMContentLoaded", Page_Load, false);
	window.addEventListener("unload", Page_Unload, false);
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
