﻿var pts = "";
function loadGMP() {
    var str = "";

    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("gMp"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(54.5272, -2.1599), 5);
        var baseIcon = new GIcon();

        baseIcon.iconSize = new GSize(12, 20);
        //baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(12, 20);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);


        function createMarker(point, str, clr) {
            // Create a lettered icon for this point using our icon class
            // var letter = String.fromCharCode("A".charCodeAt(0) + index);
            var icon = new GIcon(baseIcon);
            icon.image = "http://labs.google.com/ridefinder/images/mm_20_" + clr + ".png";
            var marker = new GMarker(point, icon);

            GEvent.addListener(marker, "click", function () {
                marker.openInfoWindowHtml(str);
            });
            return marker;
        }

        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();


        var arrStr = pts.split("~");
        var l = arrStr.length - 1;
        for (i = 0; i < l; i++) {
            var arrPts = arrStr[i].split("¬");
            var point = new GLatLng(arrPts[0], arrPts[1]);
            strInfo = arrPts[2] + "<br>" + arrPts[3];
            map.addOverlay(createMarker(point, strInfo, 'red'));
        }

    }
}

function AjaxSucceeded(result) {
    //alert(result.d);
    $("#mpSys").html(result.d);
}
function AjaxFailed(result) {
    alert(result.status + ' ' + result.statusText);
}
function loadMap(id, str) {
    $('#dvMP').dialog({
        autoOpen: true,
        show: 'clip',
        hide: 'clip',
        width: 780,
        modal: true,
        buttons: {
            "Close": function () {
                $(this).dialog("close");
            }
        }

    });
    loadSys();
    showMap(id, str);
}
function loadSys() {
    $.ajax({
        type: "POST",
        url: "map.asmx/lstSystems", // url: "products.asmx/getCategories",
        data: "{id:12}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            $("#mpSys").html(msg.d);
            //loadPts();
        }
    });
}
function showMap(id, stm) {
    $("#dvMP").dialog("option", "title", 'Clients :: ' + stm);
    $("#gMp").html("Loading...");
    $.ajax({
        type: "POST",
        url: "map.asmx/getPts", // url: "products.asmx/getCategories",
        data: "{id:" + id + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            pts = msg.d;
            //alert(pts);
            loadGMP();
        }
    });

}
function loadswf() {
    var ctl = "etcWanNew.swf";

    $.ajax({
        type: "POST", 
        url: "common.asmx/getSWF", // url: "products.asmx/getCategories",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            ctl = msg.d;
            var flsh = '<object type="application/x-shockwave-flash" data="flash/' + ctl + '" width="566" height="173">';
            flsh = flsh + ' <param name="movie" value="flash/' + ctl + '" />';
            flsh = flsh + '	<param name="quality" value="high" />';
            flsh = flsh + '	<param name="wmode" value="transparent" /></object>';

            $("#flashBannr").html(flsh);
        }
    });

    
}

$(document).ready(function () {
    loadswf();
});    
