window.onerror = myOnError;
var map = null;
var geocoder = null;
var baseIcon = null;

function myOnError(msg, url, lno) {
}

function GMlocAddress(address, zip, city, state, country) {
    if (state == "")
        return address + ',' + zip + ' ' + city + ',' + country
    else
        return address + ',' + city + ', ' + state + ' ' + zip + ',' + country
}

function GMAddress(longitude, lattitude, company, company2, description, address, zip, city, state, country, phone, fax, email) {
    this.longitude = longitude;
    this.lattitude = lattitude;
    this.company = company;
    this.company2 = company2;
    this.description = description;
    this.address = address;
    this.zip = zip;
    this.city = city;
    this.state = state;
    this.county = country;
    this.phone = phone;
    this.fax = fax;
    this.email = email;
    this.locAddress = GMlocAddress(this.address, this.zip, this.city, this.state, this.county);
    this.HTML = '<div id="GoogleMapsDetail">'
    this.HTML = this.HTML + '<h3>Adresse</h3>'
    this.HTML = this.HTML + '<h4>'
    this.HTML = this.HTML + this.company
    if (this.company2 != "")
        this.HTML = this.HTML + '<br/>' + this.company2
    this.HTML = this.HTML + '</h4>'

    if (this.description != "")
        this.HTML = this.HTML + '<h5>' + this.description + '</h5>'

    this.HTML = this.HTML + this.address + '<br/>'
    if (this.state == "") {
        this.HTML = this.HTML + this.zip + ' ' + this.city + '<br />'
        this.HTML = this.HTML + this.county + '<br />'
    }
    else {
        this.HTML = this.HTML + this.city + ', ' + this.state + ' ' + this.zip + '<br />'
        this.HTML = this.HTML + this.county + '<br />'
    }
    this.HTML = this.HTML + 'Tel.: ' + this.phone + '<br />'
    this.HTML = this.HTML + 'Fax.: ' + this.fax + '<br />'

    if (this.email != "")
        this.HTML = this.HTML + 'E-Mail: <a href="mailto:' + this.email + '">' + this.email + '</a><br />'

    this.HTML = this.HTML + '</div>'
}

function GoogleMaps_createMarker(point, message, overlay, markeroptions) {
    var marker = new GMarker(point, markeroptions);
    switch (overlay) {
        case 'mouseover':
            GEvent.addListener(marker, "mouseover", function() {
                marker.openInfoWindowHtml(message);
            });

            GEvent.addListener(marker, "mouseout", function() {
                marker.closeInfoWindow();
            });

            map.addOverlay(marker);
            break;

        case 'click':
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(message);
            });
            map.addOverlay(marker);
            break;

        case 'show':
            map.addOverlay(marker);
            marker.openInfoWindowHtml(message);
            break;
    }

    return marker;
}

function GoogleMaps_markAddress(address, action, markerIcon) {
    if (geocoder) {
        if (address.longitude == '') {
            geocoder.getLatLng(
                address.locAddress,
                function(point) {
                    if (!point) {
                        // do nothing
                    }
                    else {
                        theMarker = GoogleMaps_createMarker(point, address.HTML, action, { icon: eval(markerIcon) })
                    }
                }
            );
        }
        else {
            point = new GLatLng(address.lattitude, address.longitude);
            theMarker = GoogleMaps_createMarker(point, address.HTML, action, { icon: eval(markerIcon) })
        }
    }
}

function GoogleMaps_initialize(mapCanvas) {
    if (GBrowserIsCompatible()) {

        var aaf = new GLatLng(53.671681, 9.98676);
        map = new GMap2(document.getElementById(mapCanvas));
        map.addControl(new GSmallMapControl());
        map.setCenter(aaf, 16);

        map.addControl(new GMapTypeControl());

        geocoder = new GClientGeocoder();

    }
}
