﻿var oConn = new ActiveXObject("ADODB.Connection");
//var strConn = "Dsn=NEW_AMI";
var strConn = "Provider=SQLOLEDB.1;initial catalog=Ami;user id=autopubbAdmin;password=987654mnb";
//var strConn = "Provider=SQLOLEDB.1;user id=sa;data source=PLATONE;persist security info=False;initial catalog=Ami;password=MaRpIo1717"

var ElencoCorner= new Array;
var Shape = new Array;

function AggiungiPunti() {

    var d = document.getElementById("Impianti");
    d.innerHTML=" <b><span class='corpotesto'>IMPIANTI</span></b><br />"
    d = document.getElementById("Casa");
    d.innerHTML = " <b><span class='corpotesto'>CASA DELL'ACQUA</span></b><br />"
    d = document.getElementById("Sportelli");
    d.innerHTML = " <b><span class='corpotesto'>SPORTELLI</span></b><br />"
    d = document.getElementById("ElencoPunti");
    d.innerHTML = ""
    
    var par;
    var Singolo = 0;
    var Paese = "";
    
    var fullURL = parent.document.URL;
    if (fullURL.indexOf('?') != -1) {
  
        if (fullURL.indexOf('id') != -1) {
            par = fullURL.substring(fullURL.indexOf('?') + 4, fullURL.length);
            Singolo = 1;
           
            par = par.replace("#", "")
           
        }
        if (fullURL.indexOf('nome') != -1) {
            Paese = fullURL.substring(fullURL.indexOf('?') + 6, fullURL.length);
            Paese = Paese.replace("#", "")
        }
    }

    oConn.Open(strConn);
    alert(323234543)
    var rs = new ActiveXObject("ADODB.Recordset");
    var strSQL = "SELECT ID, Titolo, Tipo, Indirizzo, Comune, Nota1, Nota2, Nota3, Latitudine, Longitudine FROM tbPunti";
    
    if (Singolo == 1) {
    strSQL=strSQL + " WHERE id=" + par;
    }
    if (Paese != "") {
        //strSQL = strSQL + " WHERE Replace(Comune,' ','')='" + Paese + "'";
        strSQL = strSQL + " WHERE Comune='" + Paese + "'";
    }
    
    strSQL=strSQL + " order by comune, titolo;"

  
    rs.Open(strSQL, oConn);
    var i;
    i = 0;
    var descrizione;
    while (!rs.eof) {

        ElencoCorner[i] = new VELatLong(parseFloat(rs(8)), parseFloat(rs(9)));
        Shape[i] = null;

      
        Shape[i] = new VEShape(VEShapeType.Pushpin, ElencoCorner[i]);
        Shape[i].SetTitle(String(rs(1)));
        
        if (rs(2) == "1") {
            Shape[i].SetCustomIcon('<img src="img/imoinanto2.png">');
        }
        if (rs(2) == "2") {
            Shape[i].SetCustomIcon('<img src="img/home.png">');
        }
        if (rs(2) == "3") {
            Shape[i].SetCustomIcon('<img src="img/info.png">');
        }

        descrizione = String(rs(3)) + "<br />" + String(rs(4)) + "<br />" + "<br />"
        if (rs(5) != "null") {
            descrizione = descrizione + rs(5)
        }
        if (rs(6) != "null") { 
        descrizione = descrizione + rs(6)
    }

            if (rs(7) != "null") {
                descrizione = descrizione + rs(7)
            }
    
        descrizione = descrizione.replace(/\r\n/g, "<br />"); 
        
        Shape[i].SetDescription(descrizione);
//        if ((num == 38) || (num == -1)) { map.AddShape(c38Shape); }


        if (Singolo == 0 && Paese == "") {
            if (rs(2) == "1") {
                var d = document.getElementById("Impianti");
                d.innerHTML = d.innerHTML  + "<a href='#' onclick='GetMapZoom(" + rs(8)  + ", " + rs(9) + ",14);' class='corpotesto'>" + rs(4) + "</a><br />";
            }
            if (rs(2) == "2") {
                var d = document.getElementById("Casa");
                d.innerHTML = d.innerHTML  + "<a href='#' onclick='GetMapZoom(" + rs(8)  + ", " + rs(9) + ",14);' class='corpotesto'>" + rs(4) + "</a><br />";
            }
            if (rs(2) == "3") {
                var d = document.getElementById("Sportelli");
                d.innerHTML = d.innerHTML  + "<a href='#' onclick='GetMapZoom(" + rs(8)  + ", " + rs(9) + ",14);' class='corpotesto'>" + rs(4) + "</a><br />";
            }

            var d = document.getElementById("ElencoPunti");
            d.style.display = "none";
            
        }
        else {
            var d = document.getElementById("ElencoPunti");
            d.innerHTML = d.innerHTML + "<a href='#' onclick='GetMapZoom(" + rs(8) + ", " + rs(9) + ",14);' class='corpotesto'>" + rs(1) + "</a><br />";
                d = document.getElementById("Impianti");
                d.style.display="none";
                d = document.getElementById("Casa");
                d.style.display="none";
                d = document.getElementById("Sportelli");
                d.style.display="none";
            }
        map.AddShape(Shape[i]);
        rs.MoveNext()
        i = i + 1;
        
    }

    rs.close();
    oConn.close();
}


function GetMapZoom(lat, lon, zz) {
    var latLon = new VELatLong(parseFloat(lat), parseFloat(lon));

    map = new VEMap('myMap');
    map.LoadMap(latLon, zz, selStyle, 0, selMode, 0);
    AggiungiPunti()

}


function Trasp(Si) {
    if (Si == 0) {
        var d = document.getElementById("All");
        d.style.filter = " alpha(opacity=100)";
    }
    if (Si == 1) {
        var d = document.getElementById("All");
        d.style.filter = " alpha(opacity=50)";
    }
}