﻿var map = null;
var ppar = new GLatLng(38.84061, -104.82364);
var marker = null;
var marker2 = null;
var polygon = null;

function init() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));

        map.setMapType(G_NORMAL_MAP);
        map.addControl(new GLargeMapControl3D());
        map.addControl(new GScaleControl());
        map.addControl(new GMapTypeControl());

        map.disableDoubleClickZoom();
        map.setCenter(ppar, 10);

        GEvent.addListener(map, "click", m0);
    }
    else {
        alert('Please use current browsers for map search');
    }
    document.getElementById("latlnglimits").value = null;
}
function m0(overlay, latlng, latlng2) {
    if (polygon) {
        map.removeOverlay(polygon);
    }
    if (marker) {
        map.removeOverlay(marker);
    }
    if (marker2) {
        map.removeOverlay(marker2);
    }

    marker = new GMarker(latlng, { draggable: true });
    map.addOverlay(marker);
    marker2 = new GMarker(latlng, { draggable: true });
    map.addOverlay(marker2);
    GEvent.addListener(marker, "dragend", mFinish);
    GEvent.addListener(marker2, "dragend", mFinish);
    GEvent.addListener(marker, "drag", m1);
    GEvent.addListener(marker2, "drag", m2);
}
function m1(latlng) {
    boxMe(latlng, marker2.getLatLng());
}
function m2(latlng) {
    boxMe(marker.getLatLng(), latlng);
}
function boxMe(point, point2) {

    if (polygon) {
        map.removeOverlay(polygon);
    }

    var northLimit = null;
    var southLimit = null;
    var eastLimit = null;
    var westLimit = null;

    if (point.lat() > point2.lat()) {
        northLimit = point.lat();
        southLimit = point2.lat();
    }
    else {
        northLimit = point2.lat();
        southLimit = point.lat();
    }
    if (point.lng() > point2.lng()) {
        eastLimit = point.lng();
        westLimit = point2.lng();
    }
    else {
        eastLimit = point.lng();
        westLimit = point2.lng();
    }

    var neCorner = new GLatLng(northLimit, eastLimit);
    var seCorner = new GLatLng(southLimit, eastLimit);
    var swCorner = new GLatLng(southLimit, westLimit);
    var nwCorner = new GLatLng(northLimit, westLimit);

    polygon = new GPolygon(
        [neCorner, seCorner, swCorner, nwCorner, neCorner], "#ff0000", 3, 1, "#000000", .1);

    map.addOverlay(polygon);
}
function mFinish() {
    var point = marker.getLatLng();
    var point2 = marker2.getLatLng();

    document.getElementById("latlnglimits").value =
        point.lat() + '|' +
        point2.lat() + '|' +
        point.lng() + '|' +
        point2.lng();
}
function mapJump(mLat, mLong, mZoom) {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));

        map.setMapType(G_NORMAL_MAP);
        map.addControl(new GLargeMapControl3D());
        map.addControl(new GScaleControl());
        map.addControl(new GMapTypeControl());
        map.disableDoubleClickZoom();
        map.setCenter(new GLatLng(mLat, mLong), mZoom);
        if (polygon) { map.removeOverlay(polygon); }

        GEvent.addListener(map, "click", m0);
    }
    else {
        alert('Please use current browsers for map search');
    }
    document.getElementById("latlnglimits").value = null;

}
function cs_jump() {
    if (polygon) { map.removeOverlay(polygon); }
    map.setCenter(new GLatLng(38.84061, -104.82364), 13);
}
function wp_jump() {
    if (polygon) { map.removeOverlay(polygon); }
    map.setCenter(new GLatLng(38.99487, -105.05294), 14);
}
function fal_jump() {
    if (polygon) { map.removeOverlay(polygon); }
    map.setCenter(new GLatLng(38.94112, -104.60765), 13);
}
function fou_jump() {
    if (polygon) { map.removeOverlay(polygon); }
    map.setCenter(new GLatLng(38.68879, -104.6955), 13);
}
function mon_jump() {
    if (polygon) { map.removeOverlay(polygon); }
    map.setCenter(new GLatLng(39.09203, -104.86991), 13);
}
function bla_jump() {
    if (polygon) { map.removeOverlay(polygon); }
    map.setCenter(new GLatLng(39.04079, -104.70074), 13);
}
