﻿var map;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"), { draggableCursor: 'crosshair' });
        setMapCenter();
        map.addControl(new GSmallMapControl());
        //map.disableDragging();
        for (stateCode in stateBorders) {
            var polygon = createPoly(stateCode);
            map.addOverlay(polygon);
        }

        if (placePushPins) placePushPins();
    }
}

function createPoly(stateCode) {
    var polygon = new GPolygon(stateBorders[stateCode], "#f33f00", 0, 0, "#ff0000", 0.01);
    GEvent.addListener(polygon, "click", function(latlng) {
        //map.openInfoWindow(latlng, "You clicked " + stateCode);
        updateState(stateCode);
    });
    return polygon;
}

// This function needs to be created server side so we can include the ClientID of the DropDown control.
//function updateState(stateCode) {
//    updateStateDropDown(stateCode, 'ClientID');
//}

function updateStateDropDown(stateCode, stateDropDownId, submitButton) {
    //alert('in updateStateDropDown');
    var ddl = document.getElementById(stateDropDownId);
    var btn = document.getElementById(submitButton);
    if (ddl && btn) {
        ddl.value = stateCode;
        //ddl.form.submit();
        btn.click();
    }
}
