﻿var RPLayer;
var RPMap;
// This fuction search for Multi locations. Get info from XML Files
function fnLocateMultiPlaceOnMap(strMapPlaceTag, strXMLURL, intZoomFactor) {
    if (strXMLURL == null) {
        alert("strXMLURL not passed; Map Cannot Load.");
        return;
    }
    if (RPMap == null) {
        RPMap = new VEMap(strMapPlaceTag);

        RPMap.LoadMap();
    }

    if (RPLayer == null) {
        RPLayer = new VEShapeLayer();
    } else {
        RPLayer.DeleteAllShapes();
    }
    var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, strXMLURL, RPLayer);

    /*try{*/


    RPMap.ImportShapeLayerData(veLayerSpec, function() {
        var numShapes = RPLayer.GetShapeCount();
        var s, n, icon;
        var zoom = 13;

        if (numShapes == 1) {
            RPMap.SetZoomLevel(zoom);

            prop = RPLayer.GetShapeByIndex(0);
            if (prop.Title == "") {
                RPLayer.DeleteAllShapes();
                RPMap.SetCenterAndZoom(new VELatLong(33, -110), 4);
                return;
            }
        }
        var propNumReference = 1;
        for (var i = 0; i < numShapes; ++i) {

            s = RPLayer.GetShapeByIndex(i);
            if (s.Title.match(/COUNTRYSIDE CORPORATE/i)) {
                icon = "<div class='SmallPinStyleCorporate'><span class='pinText'> &nbsp; </span></div>";
            } else if (s.Title.match(/\|BUS STOP$/)) {
                icon = "<div class='SmallPinStyleBusStop'><span class='pinText'> &nbsp; </span></div>";
            } else {
                icon = "<div class='SmallPinStyleApartment'><span class='pinText'> " + propNumReference + " </span></div>";
                propNumReference++;
            }
            //replace "meta" info placed in the title
            s.SetTitle(s.Title.replace(/\|[^\|]*$/, ''));
            s.SetCustomIcon(icon);

        }
    }, true);
    /*} catch (e)
    {
       
    }*/
}