﻿//<![CDATA[

var appN = navigator.appName; var appV = navigator.appVersion.substring(0, 1);
var ie = (appN == "Microsoft Internet Explorer" && appV >= 4) ? true : false;
var ns = (appN == "Netscape" && (appV >= 4 && appV < 5)) ? true : false;
var nsix = (appN == "Netscape" && appV >= 5) ? true : false;

var map;
var iscompatible = false;
var gIcons = Array();
var iIcons = 0;
var gMarker = Array();
var geocoder = null;
var arrEstabsAddress = null;
var arrEstabsInfo = null;

function returnCoords(coords) {
    var returnfield = window.opener.document.getElementById("");

    map.closeInfoWindow();
    returnfield.value = coords;
    returnfield.focus();
    top.close();

}

function breakUpLatLng(coords) {
    if (coords.indexOf(",") > "-1") {
        coords = coords.split(",");
        return coords;
    }
}

function scrollMapTo(coords) {

    if (coords != "-1" && coords != "-2") {

        coords = coords.split(",");
        cLat = coords[0];
        cLng = coords[1];
        map.setCenter(new GLatLng(parseFloat(cLat), parseFloat(cLng)), 15);

    }
}

function openInfoWindowFromOutside(id) {
    try {
        gMarker[id][0].openInfoWindowHtml(gMarker[id][1]);
    } catch (e) {
    }
}

function zoom(z) {
    if (z < 0) {
        map.zoomIn();
    } else if (z > 0) {
        map.zoomOut();
    }
}

function zoomproject() {
    var currentZoom = map.getZoom()
    var toZoom = 15;
    if (currentZoom >= toZoom) {
        toZoom = 17;
    }
    map.setZoom(toZoom);
}

function AddEstablishment(address, info) {
    if (arrEstabsAddress == null) {
        arrEstabsAddress = new Array();
    }
    var i = arrEstabsAddress.length;
    if (i != 0) i++;
    arrEstabsAddress[i] = address;

    if (arrEstabsInfo == null) {
        arrEstabsInfo = new Array();
    }

    if (info) {
        arrEstabsInfo[i] = info;
    }
}

function AddAddress(address, info) {

    if (iscompatible && geocoder) {
        var current_address = address;
        geocoder.getLatLng(
				address,
				function(point) {
				    if (point) {
				        map.setCenter(point, 15);
				        var marker = new GMarker(point);
				        map.addOverlay(marker);
				        map.openInfoWindowHtml(point, info);
				        GEvent.addListener(marker, "mousedown", function() { marker.openInfoWindowHtml(info); });
				    }
				}
				);
    }
    return false;
}
function load() {

    iscompatible = GBrowserIsCompatible()
    if (iscompatible) {
        // Class instancen
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById("map"));
        //map.setMapType(G_HYBRID_MAP);
        // Controls toevoegen
        map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 20)));
        map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 5)));
        map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 5)));
        map.enableContinuousZoom();
        map.enableDoubleClickZoom();

        if (arrEstabsAddress != null) {

            for (i = 0; i < arrEstabsAddress.length; i++) {
                var address = arrEstabsAddress[i];
                var info = arrEstabsInfo[i];
                if (address) {
                    AddAddress(address, ((info) ? info : ''));
                }
            }
        }
    }
}

function CheckRouteForm() {
    var oRoute = document.forms[0];
    var errLvl = 0;
    var errMsg = "Niet alle velden zijn ingevuld!\n";
    if ((oRoute.routeAddress.value == '') && (oRoute.routeZipcode.value == '') && (oRoute.routePlace.value == '')) { errLvl = 1; errMsg; }
    if (errLvl != 0) {
        alert(errMsg);
    } else {
        GRoute();
    }
}
function GRoute() {
    var address = '';
    var oAddress = document.getElementById('routeAddress');
    var oZipcode = document.getElementById('routeZipcode');
    var oPlace = document.getElementById('routePlace');
    var lat;
    var lng;

    if (arrEstabsAddress != null) {

        for (i = 0; i < arrEstabsAddress.length; i++) {
            var toaddress = arrEstabsAddress[i];
            if (toaddress) {
                geocoder.getLatLng(
				toaddress,
				function(point) {
				    if (!point) {
				        //alert(error_no_map_info);
				    } else {
				        lat = point.lat();
				        lng = point.lng();

				        if (oAddress.value.length > 0 && oAddress.value != 'Straat en Huisnr.') { address += oAddress.value; }
				        if (oZipcode.value.length > 0 && oZipcode.value != 'Postcode') { address += ' ' + oZipcode.value; }
				        if (oPlace.value.length > 0 && oPlace.value != 'Plaats') { address += ' ' + oPlace.value; }
				        address = address;
				        if (address.length > 0) {
				            window.open('http://maps.google.nl/?daddr=' + lat + ', ' + lng + '&saddr=' + address, '_blank', 'width=' + (screen.width - 100) + ',height=700,left=50,top=50,resizable=yes')
				        }
				    }
				}
				);
                break;
            }
        }
    }
}
//]>>
