var gmarkers = [];
var dates = [];
var times = [];
var descriptions = [];
var plaindescriptions = [];
var titles = [];
var ids = [];
var fotos = [];
var points = [];
var nPoints = 0;
var map;
var canEdit;
var txLatClientID;
var txLngClientID;
var txDataClientID;
var txOraClientID;
var txMessaggioClientID;
var txIDClientID;
var bounds = new GLatLngBounds();
var track;
var drawPath = true;
function eliminaPos(i){
if (confirm('Sicuro di voler eliminare la posizione dalla mappa?')){
sPath = window.location.pathname;
sPage = sPath.substring(sPath.lastIndexOf('/')+1);
p = sPage.indexOf("?");
if (p >= 0) sPage = sPage.substring(0, p);
window.location=sPage+"?delete="+i;}
return false;}
function eliminaFoto(i){
if (confirm('Sicuro di voler eliminare la foto?')){
sPath = window.location.pathname;
sPage = sPath.substring(sPath.lastIndexOf('/')+1);
p = sPage.indexOf("?");
if (p >= 0) sPage = sPage.substring(0, p);
alert(sPage);
window.location = sPage+"?deletefoto="+i;}
return false;}
function myclick(i){
map.panTo(gmarkers[i].getLatLng());
GEvent.trigger(gmarkers[i], "click");}
function writeMarkerFields(marker){
for (var i = 0; i < gmarkers.length; i++){
if (marker == gmarkers[i]) break;}
if ($get(txIDClientID)) $get(txIDClientID).value = ids[i];
if ($get("TitoloPosizione")) $get("TitoloPosizione").innerHTML=titles[i];
if (!$get(txLatClientID)) return;
var latlng = marker.getLatLng();
$get(txLatClientID).value = latlng.lat();
$get(txLngClientID).value = latlng.lng();
$get(txDataClientID).value = dates[i];
$get(txOraClientID).value = times[i];
$get(txMessaggioClientID).value = plaindescriptions[i];}
function newPoint(){
var i = gmarkers.length;
var titolo = new Date().format('dd MMM yyyy ore HH:mm');
var data = new Date().format('dd/MM/yyyy');
var ora = new Date().format('HH:mm');
var m = createMarker(i,'0',map.getCenter(),titolo,'Descrizione','Descrizione',data,ora) ;
writeSidebar();
writeMarkerFields(m);
GEvent.trigger(m, "click");}
function writeSidebar(){}
function selectData(index){
var li=$get("elenco_wpt");
if (li){
li=li.getElementsByTagName("span");
if (li){
for (var i=0;i<li.length;i++){
if (i == index)
li[i].className="selected"
else
li[i].className="unselected"}}}}
function createMarker(i,id,point,name,plaindescription,html,date,time,foto){
if (canEdit)
var marker = new GMarker(point, {draggable: true});
else
var marker = new GMarker(point);
ids[i] = id;
gmarkers[i] = marker;
dates[i] = date;
times[i] = time;
titles[i] = name;
descriptions[i] = html;
plaindescriptions[i] = plaindescription;
fotos[i] = foto;
points[i] = point;
GEvent.addListener(marker, "click", function(){
marker.openInfoWindowHtml(creaInfoWindow(id,name,html,foto));
writeMarkerFields(marker);
selectData(i);});
if (canEdit)
GEvent.addListener(marker, "dragend", function(){
GEvent.trigger(marker, "click");
writeMarkerFields(marker);});
map.addOverlay(marker);
descriptions[i] = descriptions[i].replace(/<\/?[^>]+(>|$)/g, "");
return marker;}
function creaInfoWindow(id,name,html,foto){
var cmds="";
if (isOwner){
cmds="<a class='user-info' href='#' onClick='return eliminaPos("+id+");'>Elimina posizione</a>";
if (foto != ''){
cmds = cmds+"<a class='user-info' href='#' onClick='return eliminaFoto("+id+");'>Elimina foto</a>"  ;}}
var xhtml = '<div class="wpDescription">'+html+'</div>'
return '<div style="width:320px;"><div class="wpTitle"><b>'+name+'</b></div>'+xhtml+cmds+'</div>';}
function drawMap(){
if (GBrowserIsCompatible()){
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(45.907787,9.359741), 8);
loadData();
map.setCenter(bounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(bounds));
map.setMapType(G_HYBRID_MAP);
writeSidebar();
if (nPoints>1 && (drawPath)){
track = new GPolyline(points, "#FF0000", 6, .5);
map.addOverlay(track);}
if (gmarkers[0]) GEvent.trigger(gmarkers[0], "click");}
else{
alert("Spiacenti, ma questo browser non può visualizzare le mappe");}}
function loadData(){
var html = '';
var plaindescription = '';
var label = '';
var lat = 0;
var lng = 0;
var date = '';
var time = '';
var id = '';
var label='';
var foto='';
bounds = new GLatLngBounds();
var div = $get("posizioni");
if (div){
var posizioni=div.getElementsByTagName("div");
if (posizioni){
nPoints=posizioni.length;
for (var i = 0; i < posizioni.length; i++){
try {
html = $get("messaggio"+i).innerHTML;
plaindescription = $get("messaggioplain"+i).innerHTML;
label = $get("titolo"+i).innerHTML;
lat = parseFloat($get("lat"+i).innerHTML);
lng = parseFloat($get("lng"+i).innerHTML);
date = $get("data"+i).innerHTML;
time = $get("ora"+i).innerHTML;
id = $get("id"+i).innerHTML;
foto = $get("foto"+i).innerHTML;
var point = new GLatLng(lat, lng);
var marker = createMarker(i, id, point, label, plaindescription, html, date, time, foto);
bounds.extend(point)}
catch (e){ }}}}}
var playing;
var stopClick;
var count;
function mvStop(){
if(playing) {
clearTimeout(playing);
stopClick = true;}}
function mvContinue() {
if(stopClick == true) mvGo();
stopClick = false;}
function mvNext(){
count++;
if(count < points.length){
myclick(count);
var delay = 8000;
playing = setTimeout("mvNext()", delay);}
else{
clearTimeout(playing);
count =-1;
playing = null;}}
function mvAgain() {
if(playing) clearTimeout(playing);
stopClick = false;
count =-1;
mvNext();}
