﻿
function PopupGallery(id) {
    w = 520;
    h = 360;

    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;
    var frm = 'gallery.aspx?id=' + id

    window.open(frm, '', 'top=' + t + ',left=' + l + ',width=' + w + ',height=' + h + ',scrollbars=no,status=no,location=no,toolbar=no');

}

 function PopupMappa(localita) {
    w = 800;
    h = 600;

    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;
    var frm = 'latlngz.aspx?l=' + localita

    window.open(frm, '', 'top=' + t + ',left=' + l + ',width=' + w + ',height=' + h + ',scrollbars=no,status=no,location=no,toolbar=no');

}


function PopupPosizione(tipo, idoggetto) {
    w = 800;
    h = 600;

    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;
    var frm = 'posizione.aspx?t=' + tipo + '&id=' + idoggetto;



    window.open(frm, '', 'top=' + t + ',left=' + l + ',width=' + w + ',height=' + h + ',scrollbars=no,status=no,location=no,toolbar=no');

}

function PopupMappaLatLng(lat, lng, z) {
    w = 800;
    h = 600;

    var l = (screen.width - w) / 2;
    var t = (screen.height - h) / 2;
    var frm = 'latlngz.aspx?lat=' + lat + '&lng=' + lng + '&z=' + z

    window.open(frm, '', 'top=' + t + ',left=' + l + ',width=' + w + ',height=' + h + ',scrollbars=no,status=no,location=no,toolbar=no');

}

function PopupContratto(url) {
    window.open(url, '', 'width=800,height=600,scrollbars=yes,status=no,location=no,toolbar=no');
}


function PopupImgStruttura(url) {
    window.open(url, '', 'width=800,height=750,scrollbars=no,status=no,location=no,toolbar=no');
}

var map = null;
var marker = null;

function showAddress(address) {

    var geocoder = new GClientGeocoder();
    geocoder.getLatLng(address, function(point) {
        if (!point) {
            alert(address + " non trovato!");
        }
        else {
            map.setCenter(point, 6);
        }
    }
                );

}


function showAddressZoom(address, zoom) {

    var geocoder = new GClientGeocoder();
    geocoder.getLatLng(address, function(point) {
        if (!point) {
            alert(address + " non trovato!");
        }
        else {
            map.setCenter(point, zoom);
            marker = new GMarker(point, { draggable: true });
            map.addOverlay(marker);
            PosizioneMappa(point);
            GEvent.addListener(marker, "dragend", function() {
                PosizioneMappa(marker.getLatLng());
            });
        }
    }
                );

}


function showLatLngZoom(lat, lng, zoom) {

    map.setCenter(new google.maps.LatLng(lat, lng), zoom);
    if (marker) {
        map.removeOverlay(marker);
    }

    marker = new GMarker(new google.maps.LatLng(lat, lng), { draggable: true });
    map.addOverlay(marker);
    PosizioneMappa(new google.maps.LatLng(lat, lng));
    ModificaZoom(zoom);
    GEvent.addListener(marker, "dragend", function() {
        PosizioneMappa(marker.getLatLng());
    });
}


function ResetMappa() {
    document.getElementById('Indirizzo').value = '';
    map.setCenter(new google.maps.LatLng(41.790656, 12.389081), 2);
}


function PosizioneMappa(latlng) {

    document.getElementById('txtLongitudine').value = latlng.x;
    document.getElementById('txtLatitudine').value = latlng.y;

    if (!marker) {
        marker = new GMarker(latlng);
        map.addOverlay(marker);
    }
    else {
        marker.setLatLng(latlng);
    }
}


function ModificaZoom(z) {
    document.getElementById('txtZoom').value = z;
}
