function LayerElementiMappa(tipo_elemento,draggablelayer,id_select,larghezzalistapoi,accordObj,objId1,objId2,types,typesName,pois) {
	this.tipo_elemento = tipo_elemento;
	this.larghezzalistapoi=larghezzalistapoi;
	this.draggablelayer=draggablelayer;
	this.id_select=id_select;
	this.testo="Selezione POI effetuata";
	this.testoselpoi1="Seleziona punti di interesse";
	this.testoselpoi2="Cerca punti di interesse";
	this.accordObj=accordObj;
	this.objId1=objId1;
	this.objId2=objId2;
	this.types=types;
	this.typesName=typesName;
	this.pois=pois;
	this.dhxAccord=null;
	this.createLayer();
}
LayerElementiMappa.prototype.createLayer = function() {
	if (this.tipo_elemento=="percorso") {
		this.testo="Selezione percorso effettuata";
		this.testoselpoi1="Seleziona percorsi";
		this.testoselpoi2="Cerca percorsi";
	} else if (this.tipo_elemento=="evento") {
		this.testo="Selezione evento effettuata";
		this.testoselpoi1="Seleziona eventi";
		this.testoselpoi2="Cerca eventi";
	}
    var result = "";
    result += '<div id="'+this.accordObj+'" style="width: 275px; height: 200px;"></div>';
    result += '<div id="'+this.objId1+'" style="width: 100%; height: 100%; overflow: auto; font-family: Tahoma; font-size: 10px;">'+LayerElementiMappa.prototype.createAlberoDeiTipi(this.larghezzalistapoi,this.types,this.typesName)+'</div>';
    result += '<div id="'+this.objId2+'" style="width: 100%; height: 100%; overflow: auto; font-family: Tahoma; font-size: 10px;">'+LayerElementiMappa.prototype.createListaDeiPoi(this.pois)+'</div>';
    this.draggablelayer.changeContent( result );
    this.dhxAccord = LayerElementiMappa.prototype.createAccordion(this.accordObj,this.testoselpoi1,this.testoselpoi2,this.objId1,this.objId2,this);   
}
LayerElementiMappa.prototype.createAccordion = function(accorObj,testoa1,testoa2,oId1,oId2,lem) {
    var dhxAccord = new dhtmlXAccordion(accorObj);
    dhxAccord.addItem("a1", testoa1);
    dhxAccord.addItem("a2", testoa2);
    dhxAccord.cells("a1").attachObject(oId1);
    dhxAccord.cells("a2").attachObject(oId2);
    dhxAccord.openItem("a1");
    dhxAccord.attachEvent("onActive", function(itemId){
        //alert("Item "+itemId+" was activated.");
        if (itemId=="a2")
        	accordionEvent1(lem,false);
    });
    return dhxAccord;
}
LayerElementiMappa.prototype.createAlberoDeiTipi = function(larghezzalistapoi,types,typesName) {
    var result = "";
        result += '<TABLE WIDTH="100%" HEIGHT="100%" CELLPADDING="0" CELLSPACING="0">';
        result += '<TR HEIGHT="100%">';
        result += ' <TD VALIGN="top" WIDTH="' + larghezzalistapoi + '">';
        result += ' <IMG SRC="img/bl.gif" WIDTH="150" HEIGHT="1">';

        if ( types.length > 0 ) {
            var act1 = types[ 0 ].substring( 0, 3 );
            var act2 = types[ 0 ].substring( 0, 6 );
            var i = 0;
            result += '<TABLE CLASS="types" ID="0" CELLPADDING="0" CELLSPACING="0" WIDTH="150" >';
            var bool = true;

            while ( bool ) {
                result += '<TR><TD align="left" ONCLICK="clickOnIcon(\'' + act1 + '\')"><IMG SRC="' + typesName[ act1 ].menu + '"/>' + typesName[ act1 ].nome + '</TD></TR>';
                result += '<TR><TD NOWRAP>';
                result += ' <TABLE CLASS="types" STYLE="display:none;" ID="' + act1 + '" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">';

                while ( bool && types[ i ].substring( 0, 3 ) == act1 ) {
                    result += ' <TR><TD NOWRAP align="left">&nbsp;&nbsp;&nbsp;<IMG ONCLICK="clickOnIcon(\'' + act2 + '\')" SRC="' + typesName[ act2 ].menu + '"/><SPAN HREF="#" ID="l2_' + act2 + '" ONCLICK="clickOnType(\'' + act2 + '\',this)">' + typesName[ act2 ].nome + '</SPAN></TD></TR>';
                    result += ' <TR><TD>';
                    result += '  <TABLE CLASS="types" STYLE="display:none;" ID="' + act2 + '" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">';

                    while ( bool && types[ i ].substring( 0, 6 ) == act2 ) {
                        result += '   <TR><TD  align="left" WIDTH="100%" NOWRAP>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG SRC="' + typesName[ types[ i ] ].menu + '" STYLE="display:inline"/><SPAN ID="' + types[ i ] + '" ONCLICK="clickOnType(\'' + types[ i ] + '\',this,\'' + typesName[ types[ i ] ].nome + '\')">' + typesName[ types[ i ] ].nome + '</SPAN></TD></TR>';
                        i++;

                        if ( types.length <= i )
                            bool = false;
                    }

                    if ( bool )
                        act2 = types[ i ].substring( 0, 6 );

                    result += '  </TABLE>';

                    result += " </TD></TR>";
                }

                if ( bool )
                    act1 = types[ i ].substring( 0, 3 );

                result += ' </TABLE>';

                result += "</TD></TR>";
            }

            result += '</TABLE>';
            act1 = null;
            act2 = null;
        }

        else {
            //alert('Nessuna categoria di POI trovata. Per cortesia effettuare il refresh della pagina.');
        }

        result += ' </TD>';
        result += '</TR>';
        result += '</TABLE>';
        //result += '</div>';
		
		/*
        if ( firsttimeinsession ) {
            for ( index = 0;index < openedcat.length;index++ ) {
                //alert(openedcat[index]);
                var found = false;

                for ( kkk = 0;kkk < types.length;kkk++ ) {
                    if ( openedcat[ index ] == types[ kkk ] )
                        found = true;
                }

                if ( found && !esclp ) {
                    openType( openedcat[ index ] );
                }
            }

            firsttimeinsession = false;
        }

        else {
            isfromchangetree = true;

            for ( index = 0;index < openTypes.length;index++ ) {
                if ( !esclp ) {
                    //alert(openTypes[index]);
                    openType( openTypes[ index ] );
                }
            }

            isfromchangetree = false;
        }
        */
        
        return result;
}
LayerElementiMappa.prototype.createListaDeiPoi = function(pois) {
	var result = "";
	//result += '   <div id="listapoi" style="height:' + ( altezzalistapoi - 60 ) + 'px; width:' + larghezzalistapoi + 'px; overflow: auto; overflow-x: hidden; border:0px solid black;">';
	result += ' <TABLE CLASS="types" ID="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" HEIGHT="100%" >';
	for ( i=0;i<pois.length;i++ ) {
	    var ap = pois[ i ];
	    //alert(ap.icon+" "+ap.type);
	    var icon = ap.icon;
	    var tipoicon = getTypeNameFromTypeOID( ap.type );
	
	    if ( ap.icon == null ) {
	        icon = "http://www.newgeo.it/images/iconng/7392.png";
	        tipoicon = "Informazione Turistica";
	    }
	    //alert(icon+" "+tipoicon+" "+ap.OID+" "+ap.type+" "+ap.name);
	    result += '  <TR><TD WIDTH="20"><IMG SRC="' + icon + '" onmouseover="return overlib(\'' + tipoicon + '\',WIDTH, 80, FGCOLOR, \'#FFFFFF\', TEXTFONT, \'Helvetica\');" onmouseout="return nd();" /></TD><TD WIDTH="130" align="left"><SPAN ID="' + ap.OID + '" ONCLICK="clickOnPOI(\'' + ap.OID + '\',\'' + ap.type + '\')">' + ap.name + '</SPAN></TD></TR>';
	}
	result += ' </TABLE>';
	//result += ' </div>'
    return result;
}
LayerElementiMappa.prototype.aggiornaListaDeiPoi = function(pois,oId2) {
	var result = LayerElementiMappa.prototype.createListaDeiPoi(this.pois);
	document.getElementById(oId2).innerHTML = result;
}
