﻿//<![CDATA[

var map = null;

function load() 
{
  if (GBrowserIsCompatible()) 
  {
    var loc = new GLatLng(61.8327881, 18.0644881);
    var zoomStart = 5; 
 
  
  
  
    map = new GMap2(document.getElementById("map"));
    map.setCenter(loc, zoomStart);
    map.addControl(new GLargeMapControl());
    //map.enableScrollWheelZoom();


    
   
  }
}

function LoadPoints(strSearch, strGroupIds) {
    var url = "/service/mapservice.aspx?strSearch=" + strSearch + "&strGroupIds=" + strGroupIds + '&rand=' + Math.floor(Math.random() * 1001);
    GDownloadUrl(url, function(doc) {
        var xmlDoc = GXml.parse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
        var lastPoint = null;
        for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat, lng);
            var id = markers[i].getAttribute("id");
            var type = markers[i].getAttribute("type");
            //var city = markers[i].getAttribute("city");
            var phone = markers[i].getAttribute("phone");
            var name = markers[i].getAttribute("name");
            var url = markers[i].getAttribute("url");
            var html = "<div style=\"width:200px;\"><b>" + name + "</b><br/>";
            if (type.length > 0)
                html += type + "<br/>";
            if (phone.length > 0)
                html += phone + "<br/>";
            if (url.length > 0) {
                if (url.indexOf('http://') < 0)
                    html += "<a target=\"_blank\" href=\"http://" + url + "\">" + url + "</a>";
                else
                    html += "<a target=\"_blank\" href=\"" + url + "\">" + url.replace("http://", "") + "</a>";

            }
            html += "</div>";
            // create the marker
            lastPoint = point;
            var marker = createMarker(point, name, html);
            map.addOverlay(marker);
        }
        if (markers.length == 1) {
            map.setCenter(lastPoint, 15);
        }

    });
}

// A function to create the marker and set up the event window
function createMarker(point, name, html) {
  // alert(html);
    //var marker = new GMarker(point, gicons[category]);
    var marker = new GMarker(point);
    // === Store the category and name info as a marker properties ===
   // marker.mycategory = category;
    marker.myname = name;
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
        
    });
    //gmarkers.push(marker);
    return marker;
}

//]]>