﻿//window.onunload = GUnload();

var my_icon_list = new Array();
var a = 0;
var md;

function addGoogleMap(ctlId) {
    if (GBrowserIsCompatible()) {
        if (document.getElementById(ctlId)) {
            var bounds = new GLatLngBounds();
            //var options = new Object();
            //options.clickable = true;
            md = new GMap2(document.getElementById(ctlId));
            md.setCenter(new GLatLng(0, 0), 0);
            //md.setCenter(new GLatLng(-37.91435,145.159645),2);
            md.setUIToDefault();

            var i = 0;
            var is = 0;
            var my_icons = new Array();
            var marker;
            if (my_icon_list.length > 0) {
                for (i = 0; i < my_icon_list.length; i++) {
                    if (my_icon_list[is][0] != 0 && my_icon_list[is][1] != 0) {
                        var customIcon = new GIcon(G_DEFAULT_ICON);
                        if (my_icon_list[is][3] == 'Upcoming') {
                            customIcon.image = "/DesktopModules/RolloutSites/blue-dot.png";
                            customIcon.iconSize = new GSize(32, 32);
                        }
                        marker = createMarker(new GLatLng(my_icon_list[is][0], my_icon_list[is][1]), my_icon_list[is][2], customIcon)
                        md.addOverlay(marker);
                        bounds.extend(marker.getPoint());
                        is++
                    }
                }
            }
            md.setZoom(md.getBoundsZoomLevel(bounds));
            md.setCenter(bounds.getCenter());
        }
    }
}
function createMarker(point, html, customIcon) {
    var marker;
    if (customIcon)
        marker = new GMarker(point, { icon: customIcon });
    else
        marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
    });
    return marker;
}
function move(lat, lng, zoom) {
    md.setCenter(new GLatLng(lat, lng), zoom);
    //md.panTo(new GLatLng(lat, lng));
    //md.setZoom(zoom);
}
function addIcon(lat, lng, address, status) {
    if (my_icon_list) {
        if (status != 'Hidden' && lat.length > 0 && lng.length > 0) {
            if (lat != '-1.79769313486232E+308' && lng != '-1.79769313486232E+308') {
                var addNewIcon = true
                for (i=0;i<my_icon_list.length;i++) {
                    if (my_icon_list[i][0] == lat && my_icon_list[i][1] == lng && my_icon_list[i][2] == address && my_icon_list[i][3] == status) {
                        addNewIcon = false
                    }
                }
                if (addNewIcon) {
                    my_icon_list[a] = new Array(3)
                    my_icon_list[a][0] = lat
                    my_icon_list[a][1] = lng
                    my_icon_list[a][2] = address
                    my_icon_list[a][3] = status
                    a++
                }
            }
        }
    }
}
//<script type="text/javascript" language="javascript">addIcon('<%# Eval("latitude") %>','<%# Eval("longitude") %>','<%# Eval("display_name") %><br><a href="Mapping.aspx?id=<%# Eval("store_name") %>">View Details &raquo;</a>');</script>
