<!--
var CONST_DEFAULT_LATITUDE = 47.740607;
var CONST_DEFAULT_LONGITUDE = -122.616648;
var CONST_DEFAULT_ZOOM = 8;
var CONST_DEFAULT_TYPE = google.maps.MapTypeId.TERRAIN;
var CONST_DEFAULT_FILTER = 0;
var CONST_COOKIE_DAYS = 365;
var CONST_IMAGE_URL = "http://www.outsideconnection.com/_img/";
var CONST_MAX_OBSERVATIONS = 500;

var map;
var markersArray;
var filter;

function initializeMain() {
    var defView = getDefaultView();

    var myLatlng = new google.maps.LatLng(defView.latitude,defView.longitude);
    var myOptions = {
        zoom: parseInt(defView.zoom),
        center: myLatlng,
        mapTypeId: defView.type
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    //google.maps.event.addListener(map, 'bounds_changed', function() { appendDebug("bounds_changed"); });
    google.maps.event.addListener(map, 'idle', function() { handleMapChange(); });
    google.maps.event.addListener(map, 'click', function(event) { showForecast(event.latLng); });

    markersArray = [];

    document.getElementById('filter').value = filter;
    document.getElementById('legend').src = '_img/'+filter+'_legend.gif';

    resizeMap();
}


function showForecast(location)
{
    var clickedLocation = new google.maps.LatLng(location);
    var ll = splitLatLong(location);

    window.open ('http://forecast.weather.gov/MapClick.php?textField1='+ll.latitude+'&textField2='+ll.longitude+'&site=mtr','forecast');
}


function zeroPad(i)
{
    if (i<10) {
        // add a zero in front of numbers<10
        i="0" + i;
    }
    return i;
}


function handleFilterChange()
{
//appendDebug("handleFilterChange");

    filter = document.getElementById('filter').value;

    document.getElementById('legend').src = '_img/'+filter+'_legend.gif';
    handleMapChange();
}


function handleMapChange()
{
//appendDebug("handleMapChange");

    var ctr;
    var ajaxURL;
    var bounds;
    var xmlhttp;
    var zoom;

    clearMarkers();

    bounds = map.getBounds();
    if (bounds) {
        bounds = splitBounds(bounds);

//document.getElementById('swlat').value = bounds.sw_latitude;
//document.getElementById('swlon').value = bounds.sw_longitude;
//document.getElementById('nelat').value = bounds.nw_latitude;
//document.getElementById('nelon').value = bounds.nw_longitude;

        zoom = map.getZoom();
//document.getElementById('zoomLevel').value = zoom;

        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else {
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                showMarkers(xmlhttp);
                showLinks(xmlhttp);
            }
        }
        ajaxURL = "OCResponse.asp?cmd=obs&f="+filter+"&sw_lat="+bounds.sw_latitude+"&sw_long="+bounds.sw_longitude+"&ne_lat="+bounds.nw_latitude+"&ne_long="+bounds.nw_longitude;
//alert(ajaxURL);
//appendDebug("Getting:"+ajaxURL);
        xmlhttp.open("GET", ajaxURL, true);
        xmlhttp.send();
    }
}


function showMarkers(xmlhttp)
{
//appendDebug("showMarkers");

    var markerImgName;
    var markerTitle;
    var markerLatitude;
    var markerLongitude;
    var markerSourceID;
    var xx;

    document.getElementById('utcClock').innerHTML = 'GMT: ' + xmlhttp.responseXML.documentElement.getAttribute("utc");

    var x = xmlhttp.responseXML.documentElement.getElementsByTagName("obs");
    for (i=0; i<x.length; i++)
    {
        xx = x[i].getElementsByTagName("img");
        {
            try { markerImgName = xx[0].firstChild.nodeValue; }
            catch (er) { continue; }
        }

        xx = x[i].getElementsByTagName("title");
        {
            try { markerTitle = xx[0].firstChild.nodeValue; }
            catch (er) { continue; }
        }

        xx = x[i].getElementsByTagName("lat");
        {
            try { markerLatitude = xx[0].firstChild.nodeValue; }
            catch (er) { continue; }
        }

        xx = x[i].getElementsByTagName("lng");
        {
            try { markerLongitude = xx[0].firstChild.nodeValue; }
            catch (er) { continue; }
        }

        xx = x[i].getElementsByTagName("srcid");
        {
            try { markerSourceID = xx[0].firstChild.nodeValue; }
            catch (er) { continue; }
        }
        showMarker(map, CONST_IMAGE_URL+markerImgName, markerLatitude, markerLongitude, markerTitle, markerSourceID)
    }

}


function showLinks(xmlhttp)
{
//appendDebug("showLinks");

    var txt = '';
    var x;
    var link_text = '';
    var link_url = '';

    var x = xmlhttp.responseXML.documentElement.getElementsByTagName("link");
        for (i=0; i<x.length; i++)
        {
        xx = x[i].getElementsByTagName("link_text");
        {
            try { link_text = xx[0].firstChild.nodeValue; }
                catch (er) { continue; }
        }

        xx = x[i].getElementsByTagName("link_url");
        {
            try { link_url = xx[0].firstChild.nodeValue; }
                catch (er) { continue; }
        }


        txt = txt + '<p><a href="' + link_url + '" class="infoLink" target="new">' + link_text + '</a>'
    }
    document.getElementById('links').innerHTML = txt;
}



function showMarker(map, imgURL, lat, lng, markerTitle, srcID)
{
//appendDebug("showMarker(" + imgURL + ")");
    var myLatLng = new google.maps.LatLng(lat, lng);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: imgURL,
        title: markerTitle

    });

    //marker.setZIndex(srcID);

    // Add marker to collection.
    markersArray.push(marker);

    google.maps.event.addListener(marker,"click",function(){ alert(markerTitle); });
}


function clearMarkers()
{
//appendDebug("clearMarkers");
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(null);
        }
    }
}


function resizeMap()
{
//appendDebug("resizeMap");
    document.getElementById('map_canvas').style.height = getHeight() - 75 + 'px';
    document.getElementById('links').style.height = getHeight() - 445 + 'px';
}


function getHeight()
{
        var y = 0;
        if (self.innerHeight) { y = self.innerHeight; }
        else if (document.documentElement && document.documentElement.clientHeight) { y = document.documentElement.clientHeight; }
        else if (document.body) { y = document.body.clientHeight; }
        return y;
}


function appendDebug(s)
{
    document.getElementById("debug").value = document.getElementById("debug").value + s + "\n";
}


function getDefaultView()
{
//appendDebug("getDefaultView");

    var lat = getCookie('primary_latitude');
    var lng = getCookie('primary_longitude');
    var zm = getCookie('primary_zoom');
    var tp = getCookie('primary_type');
    var flt = getCookie('primary_filter');

    if (isBlank(lat) || isNaN(lat) || isBlank(lng) || isNaN(lng) || isBlank(zm) || isNaN(zm) || isBlank(tp) ||  isBlank(flt) || isNaN(flt)) {

        lat = getCookie('secondary_latitude');
        lng = getCookie('secondary_longitude');
        zm = getCookie('secondary_zoom');
        tp = getCookie('secondary_type');
        flt = getCookie('secondary_filter');

        if (isBlank(lat) || isNaN(lat) || isBlank(lng) || isNaN(lng) || isBlank(zm) || isNaN(zm) || isBlank(tp) ||  isBlank(flt) || isNaN(flt)) {

            lat = CONST_DEFAULT_LATITUDE;
            lng = CONST_DEFAULT_LONGITUDE;
            zm = CONST_DEFAULT_ZOOM;
            tp = CONST_DEFAULT_TYPE;
            flt = CONST_DEFAULT_FILTER;
        }
    } else {
        document.getElementById('goDefaultViewDiv').style.display = 'block';
    }

    filter = flt;

    return { latitude:lat, longitude:lng, zoom:zm, type:tp, filter:flt };
}

function showCookies() {
    var tmp;

    tmp = 'primary_latitude:[' + getCookie('primary_latitude') + ']';
    tmp = tmp + '\n primary_longitude:[' + getCookie('primary_longitude') + ']';
    tmp = tmp + '\n primary_zoom:[' + getCookie('primary_zoom') + ']';
    tmp = tmp + '\n primary_type:[' + getCookie('primary_type') + ']';
    tmp = tmp + '\n primary_filter:[' + getCookie('primary_filter') + ']';

    tmp = tmp + '\n secondary_latitude:[' + getCookie('secondary_latitude') + ']';
    tmp = tmp + '\n secondary_longitude:[' + getCookie('secondary_longitude') + ']';
    tmp = tmp + '\n secondary_zoom:[' + getCookie('secondary_zoom') + ']';
    tmp = tmp + '\n secondary_type:[' + getCookie('secondary_type') + ']';
    tmp = tmp + '\n secondary_filter:[' + getCookie('secondary_filter') + ']';

    alert(tmp);
}


function goDefaultView()
{
//appendDebug("goDefaultView");

    filter = getCookie('primary_filter');
    document.getElementById('legend').src = '_img/'+filter+'_legend.gif';

    var myLatlng = new google.maps.LatLng(getCookie('primary_latitude'), getCookie('primary_longitude'));
    var myOptions = {
        zoom: parseInt(getCookie('primary_zoom')),
        center: myLatlng,
        mapTypeId: getCookie('primary_type')
    }
    map.setOptions(myOptions);

    var filterSelect = document.getElementById('filter');
    filterSelect.selectedIndex = filter;

    //handleMapChange();
}

function setCookie(c_name, value, expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + '=' + escape(value)+
    ((expiredays==null) ? '' : ';expires='+exdate.toUTCString());
}


function getCookie(c_name)
{
    if (document.cookie.length>0)   {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return '';
}


function saveView(defaultViewType)
{
//appendDebug("saveView");
    var tmp = splitLatLong(map.center);

    setCookie(defaultViewType + '_latitude', tmp.latitude, CONST_COOKIE_DAYS);
    setCookie(defaultViewType + '_longitude', tmp.longitude, CONST_COOKIE_DAYS);

    setCookie(defaultViewType + '_zoom', map.zoom, CONST_COOKIE_DAYS);

    setCookie(defaultViewType + '_type', map.getMapTypeId(), CONST_COOKIE_DAYS);

    setCookie(defaultViewType + '_filter', document.getElementById('filter').value, CONST_COOKIE_DAYS);

    if (defaultViewType == 'primary') {
        document.getElementById('goDefaultViewDiv').style.display = 'block';
    }
}


function splitLatLong(combinedValue)
{
    var aLoc = String(combinedValue).replace(/\(/g,"").replace(/\)/g,"").replace(/ /g,"").split(",");

    return { latitude:aLoc[0], longitude:aLoc[1] }
}


function splitBounds(combinedValue)
{
    var aLoc = String(combinedValue).replace(/\(/g,"").replace(/\)/g,"").replace(/ /g,"").split(",");

    return { sw_latitude:aLoc[0], sw_longitude:aLoc[1], nw_latitude:aLoc[2], nw_longitude:aLoc[3] }
}


function isBlank(val)
{
    if(val == null || val == '' || typeof(val) == "undefined") {
        return true;
    } else {
        return false;
    }
}

-->
