﻿
var xmlhttp;
function loadXMLDoc(url)
{
    //http://www.w3schools.com/XML/xml_http.asp
    xmlhttp = null;
    if (window.XMLHttpRequest)
    {// code for Firefox, Opera, IE7, etc.
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp != null)
    {
        xmlhttp.onreadystatechange = state_Change;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);
    }
    else
    {
        alert("Your browser does not support XMLHTTP.");
    }
}
function state_Change()
{
    if (xmlhttp.readyState == 4)// 4 = "loaded"
    {
        if (xmlhttp.status == 200)// 200 = "OK"
        {
            currentMarker.openInfoWindowHtml(xmlhttp.responseText);
        }
        else
        {
            alert("Problem retrieving data:" + xmlhttp.statusText);
        }
    }
}
var currentMarker;
//dan glantz Friday, March 13, 2009
function createMarker(BridgeID, PopupDivID, map, point, html, blue)
{
    var myIcon = new GIcon(G_DEFAULT_ICON);
    if (blue)
        myIcon.image = "./blue.png";
    else
        myIcon.image = "./green.png";

    var marker = new GMarker(point, { icon: myIcon });
    map.addOverlay(marker);
    GEvent.addListener(marker, "click", function()
    {
        currentMarker = marker;
        loadXMLDoc('projectdetails.aspx?BridgeID=' + BridgeID);
    });
    return marker;
}

var map;


//Lat/Longs pulled from the db, included as an array to display immediately
//the rest is loaded on demand by the xmlhttprequest - dan glantz - Friday, March 13, 2009
var latlngarr = new Array(
[42.5584,-71.932,1,0],
[42.215,-72.0778,3,0],
[42.363,-71.5908,4,1],
[42.4861,-73.1281,6,0],
[42.6614,-72.7153,7,0],
[42.8351,-70.9118,8,0],
[42.2437,-72.6585,10,0],
[42.2603,-72.2357,11,0],
[42.1039,-72.6794,12,0],
[42.2253,-73.4075,13,0],
[42.2187,-72.0224,14,0],
[42.0702,-72.0152,15,0],
[42.4367,-73.2578,16,0],
[42.4335,-71.8117,23,0],
[42.0923,-71.7469,24,0],
[42.0547,-71.6171,25,0],
[42.2508,-71.5219,26,0],
[42.3814,-71.8525,27,0],
[42.2435,-71.8335,28,0],
[42.5831,-71.8185,29,0],
[42.2342,-72.8786,31,0],
[42.2342,-72.8786,32,1],
[42.6352,-72.8458,33,0],
[42.7013,-71.1657,37,1],
[42.5656,-71.9972,38,0],
[42.1213,-72.6093,39,1],
[42.0978,-72.5978,40,0],
[42.116,-72.2019,42,0],
[42.5936,-73.1414,43,0],
[42.8104,-71.0001,44,0],
[42.0398,-72.785,46,0],
[42.688,-70.8478,47,0],
[42.4897,-73.0006,48,0],
[41.8984,-71.3699,49,1],
[41.7362,-71.2034,55,0],
[41.95,-71.2883,56,0],
[42.6607,-71.1438,57,0],
[42.2589,-71.2637,58,0],
[42.0939,-73.0758,60,0],
[42.2969,-71.4478,61,0],
[42.3258,-71.3978,62,0],
[42.6252,-71.3205,64,0],
[42.1179,-72.5854,66,1],
[42.2885,-71.5865,69,1],
[42.0973,-72.0859,70,0],
[42.0619,-71.0617,73,1],
[42.672,-71.5777,74,0],
[42.2127,-72.6109,75,0],
[42.616,-71.2966,76,1],
[42.5837,-71.8189,80,0],
[42.2012,-72.0579,81,0],
[42.2743,-71.7552,82,0],
[42.0296,-71.604,83,0],
[42.6122,-71.8272,84,0],
[42.6758,-71.9431,85,1],
[42.0421,-72.0435,86,0],
[42.1091,-71.6657,87,0],
[42.0551,-71.9797,88,0],
[42.2071,-72.1029,89,0],
[42.4195,-71.6669,90,0],
[42.0735,-71.7159,91,0],
[42.2217,-72.5903,92,1],
[42.2298,-72.1469,94,0],
[42.0109,-71.0586,96,0],
[41.6531,-70.9619,97,0],
[41.7753,-71.2815,98,0],
[42.1498,-71.6494,99,0],
[42.3001,-71.4351,100,1],
[42.1933,-71.0783,103,1],
[42.3731,-71.8279,104,0],
[42.5609,-71.9836,105,0],
[42.3347,-73.1033,106,1],
[42.1844,-71.7051,107,1],
[42.4083,-72.097,108,0],
[42.461,-72.1648,109,1],
[42.0776,-72.5802,111,1],
[42.5767,-72.1712,113,0],
[42.0814,-72.5832,114,1],
[42.5042,-72.7469,116,0],
[42.6467,-71.2997,119,1],
[42.5238,-70.9194,122,0],
[42.8159,-70.8729,123,0],
[42.563,-72.2475,125,0],
[42.5189,-70.9942,128,1],
[42.2585,-71.4559,130,0],
[42.3903,-71.571,131,0],
[42.1491,-72.6082,132,0],
[42.3917,-71.085,135,0],
[42.383,-71.0901,136,0],
[42.2636,-71.1049,137,0],
[42.281,-71.0859,138,0],
[42.1729,-71.205,139,0],
[41.9343,-71.1086,140,0],
[41.6959,-71.1232,141,0],
[41.9016,-71.0457,142,0],
[41.9034,-71.0983,143,0],
[41.7019,-71.1615,148,0],
[41.7037,-71.161,157,1],
[41.7037,-71.161,158,0],
[41.7436,-71.1223,161,1],
[41.6738,-70.1407,162,0],
[41.9472,-70.9371,163,0],
[41.67,-69.961,164,0],
[42.078,-71.0236,165,0],
[41.7467,-70.6214,166,0],
[41.6876,-70.3369,167,0],
[41.9236,-70.9971,169,1],
[41.6671,-70.1471,171,0],
[41.9906,-70.7352,173,0],
[42.3155,-71.2471,174,0],
[42.2029,-71.0965,175,1],
[42.6194,-72.9083,177,1],
[41.8475,-71.0196,182,0],
[42.2745,-71.4374,190,0],
[42.138,-71.3592,191,0],
[42.2779,-72.9796,192,1],
[42.1159,-72.551,199,1],
[42.2443,-70.9679,200,0],
[42.1353,-72.6133,202,1],
[42.2791,-71.033,206,1],
[42.0905,-70.866,207,0],
[42.0795,-71.0187,208,0],
[42.3083,-71.2796,210,0],
[41.9363,-71.2889,211,0],
[42.3615,-71.0754,212,0],
[42.3852,-71.0911,213,0],
[42.4038,-71.0726,214,0],
[42.3209,-71.0509,215,0],
[42.4176,-71.1102,217,0],
[42.3527,-71.1106,218,0],
[42.3527,-71.1106,219,1],
[42.4,-70.9913,220,0],
[42.3494,-71.0923,221,1],
[42.404,-71.0174,222,0],
[42.3014,-71.1131,223,0],
[42.3267,-71.2612,224,0],
[42.3412,-71.2582,225,0],
[42.2758,-71.3095,226,0],
[42.4437,-70.9662,227,0],
[42.3264,-71.0524,228,0],
[42.369,-71.1232,229,0],
[42.356,-71.1139,230,0],
[42.3803,-71.0897,231,0],
[42.4146,-71.1324,232,0],
[42.2843,-71.0394,233,0],
[42.3129,-71.0465,234,0],
[42.2457,-71.1363,235,1],
[42.3612,-71.1167,236,0],
[42.3556,-71.0752,237,1],
[42.3401,-71.2559,238,0],
[42.3642,-71.1169,239,0],
[42.4049,-71.0044,240,0],
[42.3672,-71.0691,241,1],
[42.4038,-71.0726,242,1]
);
function load()
{
    if (GBrowserIsCompatible())
    {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.enableContinuousZoom();
        map.enableScrollWheelZoom();

        map.setCenter(new GLatLng(42, -71.75), 8);

        for (var i = 0; i < latlngarr.length; i++)
        {
            var lat = latlngarr[i][0];
            var lng = latlngarr[i][1];
            var BridgeID = latlngarr[i][2];
            var design = latlngarr[i][3] == 1; // construction, do a blue marker
            var PopupDivID = 'PopupDiv' + i;
            createMarker(BridgeID, PopupDivID, map, new GLatLng(lat, lng), '<div id="' + PopupDivID + '" style="width: 450px; height: auto; overflow: auto;">Loading data...</div>', design);
        }
    }
}
