

function include(script_filename) {
    document.write('<' + 'script');
    document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');
}

var GLOUUseAsync = 0;
var old_coordX = 0;
var old_coordY



// Luca 
var LayerTmp = -1;
//
try
{
  var esiste = useasync;
  GLOUUseAsync = useasync;  
}
catch(e)
{
    GLOUUseAsync = 0;  
}
finally
{  
}


try
{
  var esiste = preleva;
}
catch(e)
{
    preleva = 0;  
}
finally
{  
}

try
{
  var esiste = GLOPubblicatiComuni;
}
catch(e)
{
    GLOPubblicatiComuni = '/PubblicatiComuni';  
}
finally
{  
}


//Modificata 
try
{
  var esiste = ip;
}
catch(e)
{
    ip = '';  
}
finally
{  
}


var TimeRedraw = 0;

// 20050927 - Copyright (C) 2005-2006 Simone Manca <simone.manca@gmail.com>
// http://datacrossing.crs4.it/en_Documentation_mscross.html
// v1.1.5 20060706
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Imposta una nuova variabile a Object (genitore di tutti gli oggetti)
Object.prototype.objRef = null;

//HTMLElement.prototype.objRef = null;
var pixel_img = new Image(); pixel_img.src = GLOPubblicatiComuni + '/imgmappa/pixel.gif'; //MCS
var browser = new Browser();
var dragObj = new Object();
dragObj.zIndex = 0;
	var a;
	var b;
	var lunghezza;
	
function pause(numberMillis) {


        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true) {
            now = new Date();
            if (now.getTime() > exitTime)
                return;
        }
    }

// msMap class prototype
function msMap(DivTag, ControlType, p_protocol)
{
  if ( ControlType == null ) { ControlType = 'standard'; }

  // Private vars
  var i        = this;
  var _tagMain = DivTag;
  var _map_w   = parseFloat( _tagMain.style.width );
  var _map_h   = parseFloat( _tagMain.style.height );

  var _protocol = p_protocol; // 'mapservercgi', 'wms'
  if (_protocol == null) { _protocol = 'mapservercgi'; }

  // Hidden map border in in pixel. You can set map size highter respect
  // div size (visible map)
  var _map_w_bord = 0; var _map_h_bord = 0;

  var _action  = 'pan';			// pan, zoom, none
  var _control = ControlType;
  var _cgi     = '/cgi-bin/mapserv';
  var _mode    = 'map';
  var _layers  = '';
  var _map_file; var _args;
  var _attachedMsMap = null; var _referenceMap  = null;
  var _report = null;
  var _loading_counter = 0;

  var _ext_Xmin_orig; var _ext_Xmax_orig;
  var _ext_Ymin_orig; var _ext_Ymax_orig;
  var _ext_Xmin = null; var _ext_Xmax = null;
  var _ext_Ymin = null; var _ext_Ymax = null;
  
  var _zoombox_x_first; var _zoombox_y_first;
  var _zoombox_x_last;  var _zoombox_y_last;
  var _pixel_w; var _pixel_h;

  // Double buffering
  var _tagMap = document.createElement('img');
  var _tagMap_B = document.createElement('img');
  var _tagSelectZoombox   = document.createElement('div');
  
  var _tagZoombox   = document.createElement('div');
  var _tagToolbar   = document.createElement('div');
  var _tagReference = document.createElement('div');
  var _tagLoading   = document.createElement('img');
  var _tagOverlay   = document.createElement('div'); // Overlay Layer
  var _tagPoints    = document.createElement('div'); // Points Overlay container
  var _tagInfo      = document.createElement('div'); // Info win Overlay container
  var _drawLayer=null;  
  var _tagDraw=null;
  var _oldXDraw=0;
  var _oldYDraw=0;
  
  
  var arrXDraw=new Array();
  var arrXDrawReal=new Array();
  
  var arrYDraw=new Array();
  var arrYDrawReal=new Array();

  //MCS variabile che serve a sapere se ho già ridisegnato la mappa
  var _done = false;
  var _usaScalimetro='SI'; //Oppure NO per overview
  var _time0=0;
  var _x_time0=0;
  var _y_time0=0;

  var area=0;
  var _http_request;
  
  //Aggiunte Coiro
  var my_img_pannord;
  var my_img_pansud;
  var my_img_panest;
  var my_img_panovest;
  var my_img_pannordovest;
  var my_img_pannordest;
  var my_img_pansudovest;
  var my_img_pansudest;

  
  // Disable text/images selection.
  if ( browser.isIE )
  {
    _tagMain.onselectstart = function(){return false;};
    _tagMain.ondrag = function(){return false;};
  } else
  { _tagMain.style.setProperty("-moz-user-select", "none", ""); }

  var _Xselect; var _Yselect;

  // Point Overlay array
  var _pointsOverlayArray = new Array();

  // Toolbar Default Icons...
  var _iconFullExtentButton = GLOPubblicatiComuni + '/imgmappa/ZoomTutto_OFF.gif';
  var _iconZoomboxButton    = GLOPubblicatiComuni + '/imgmappa/ZoomRettangolo_OFF.GIF';
  var _iconPanButton        = GLOPubblicatiComuni + '/imgmappa/ZoomPan_OFF.GIF';
  var _iconZoominButton     = GLOPubblicatiComuni + '/imgmappa/ZoomPiu_OFF.GIF';
  var _iconZoomoutButton    = GLOPubblicatiComuni + '/imgmappa/ZoomMeno_OFF.GIF';
  var _iconSelectButton     = GLOPubblicatiComuni + '/imgmappa/Info_OFF.GIF'; //MCS
  var _iconLoading          = gd_loading; //Variabile globale con l'immagine da visualizzare 
  
  var _iconPanNord          = GLOPubblicatiComuni + '/imgbottoni/pan/nord.png';
  var _iconPanSud           = GLOPubblicatiComuni + '/imgbottoni/pan/sud.png';
  var _iconPanEst           = GLOPubblicatiComuni + '/imgbottoni/pan/est.png';
  var _iconPanWest          = GLOPubblicatiComuni + '/imgbottoni/pan/ovest.png';
  
  var _iconPanNordWest      = GLOPubblicatiComuni + '/imgbottoni/pan/nordovest.png';
  var _iconPanNordEst       = GLOPubblicatiComuni + '/imgbottoni/pan/nordest.png';
  var _iconPanSudWest       = GLOPubblicatiComuni + '/imgbottoni/pan/sudovest.png';
  var _iconPanSudEst        = GLOPubblicatiComuni + '/imgbottoni/pan/sudest.png';
  
  var _OverviewImg			= '';
  var _guidSession          = ''; 
  
   var old_coordX = 0;
  var old_coordY = 0;
  //var _iconSelectButton     = 'xxx';

  var _toolbarArray = new Array();
  this.setIcon      = function(p_id, p_url) { _toolbarArray[p_id].src = p_url; }

  //MCS
  this.getImg= function()
  {  
    return _tagMap;
  }
  //MCS Funzione che imposta la variabile privata per l'overview
  this.setOverviewImg = function(img)
  {
  	_OverviewImg=img;
  }  
  
  this.setSessionGuid = function(guid)
  {
  	_guidSession=guid;
  }
  
    //
  
  this.nascondiPopup = function()
  {
		nascondiPopup();
  }
   
   this.goPopup = function(){
		goPopup();		
   }
 
  // MCS Funzione che restituisce l'extent della mappa visualizzata
  // Check if a box (x, y, width, height) is within a map
  this.getViewerExtent = function()
  {
    var ext='';
    
    ext += _ext_Xmin;
    ext += " " + _ext_Ymin;
    ext += " " + _ext_Xmax;
    ext += " " + _ext_Ymax;
    
    return ext;
  }
  
  //Funzione che restituisce l'array dei punti disegnati  :arrXDrawReal
  this.getArrXDraw=function()
  {
    return arrXDrawReal;
  }
  
  //Funzione che restituisce l'array dei punti disegnati  :arrYDrawReal
  this.getArrYDraw=function()
  {
    return arrYDrawReal;  
  }
  
  this.setReport = function(p)
  {
    if (_report != null)
    {
      _tagInfo.removeChild( _tagInfo.childNodes[0] );
      i.setReportNull();
    }
    _report = p;
  }
  this.getMainTag = function() { return _tagMain; }
  this.getDrawTag = function() { return _tagDraw; }
  this.getInfoTag = function() { return _tagInfo; }
  this.setReportNull = function() { delete _report; _report = null; }

  i.show_loading_image = function(p)
  {
    if (p == true)
    {
      _loading_counter++;
      _tagLoading.style.display = '';
    }
    if (p == false)
    {
      _loading_counter--;  if (_loading_counter < 0) { _loading_counter = 0; }
      //xxx errore!!! da risolvere!!!    if (_loading_counter == 0)
      { _tagLoading.style.display = 'none'; }
    }
  }

  // Check if a box (x, y, width, height) is within a map
  this.isPointInMap = function( p_x, p_y, p_w, p_h )
  {
    if ( (p_x > (_ext_Xmax+i.wPixel2real(_map_w_bord))) ||
         ((p_x+p_w) < (_ext_Xmin-i.wPixel2real(_map_w_bord))) ) return false;
    if ( ((p_y-p_h) > (_ext_Ymax+i.hPixel2real(_map_h_bord))) ||
         ((p_y+p_h-p_h) < (_ext_Ymin-i.hPixel2real(_map_h_bord))) ) return false;
    return true;
  }
  
  // Aggiunta Coiro
  this.ridimensiona_mappa=function (w,h){
		var l = w/2;
        var a = h/2;

        //MCS con -18 e -35 centro le immagini rispetto alla mappa
       setPos(my_img_pannord, l-35, 1);
        setPos(my_img_pansud, l-35, h-18);
        setPos(my_img_panest, w-18, a-35);
        setPos(my_img_panovest, 1, a-35);
        
        setPos(my_img_pannordovest, 1, 1);
        setPos(my_img_pannordest, w-22, 1);
        setPos(my_img_pansudovest, 1, h-22);
        setPos(my_img_pansudest,w-22,h-22);
		}

  // Aggiunta Coiro
 this.setWidth = function(valore)
  {
    _map_w = valore;
  }
  
  // Aggiunta Coiro
  this.setHeight = function(valore)
  {
    _map_h = valore;
  }
  
  // Imposta il bordo intorno alla mappa.
  this.setBorder = function(p)
  {
    _map_w_bord = p;
    _map_h_bord = p;

    // First image buffer (double buffer)
    _tagMap.style.width  = (i.width()+_map_w_bord+_map_w_bord)+'px';
    _tagMap.style.height = (i.height()+_map_h_bord+_map_h_bord)+'px';
    _tagMap.style.top    = (- _map_w_bord) +'px';
    _tagMap.style.left   = (- _map_h_bord) +'px';

    // Second image buffer (double buffer)
    _tagMap_B.style.width  = _tagMap.style.width;
    _tagMap_B.style.height = _tagMap.style.height;
    _tagMap_B.style.top    = _tagMap.style.top;
    _tagMap_B.style.left   = _tagMap.style.left;
  }

  this.addClickTool = function()
  { //xxx
    var selectTool=i.addMapTool('Select', i.setActionSelect, _iconSelectButton, 6, 6);
    return selectTool;
  }

  this.addMapTool = function(p_title, p_function, p_icon, p_left, p_top)
  {
    var tool  = document.createElement('img');
    tool.oncontextmenu = function(){return false;};
    tool.onmousedown = function(){return false;};  // Disable drag'n drop
    add_event(tool, 'click', p_function );
    setAlphaPNG(tool, p_icon);
    tool.title = p_title;
    setZindex(tool, '200');
    //tool.style.border = '1px solid #c2c2c2';    //'0 none';
    tool.style.margin = '0'; tool.style.padding = '0';
    tool.style.position = 'absolute';
    tool.style.cursor = 'pointer';
    tool.style.display = 'none';

    // xxx verificare se senza queste 2 righe explorer da problemi
    //tool.style.width = '35px';   // Explorer si incasina altrimenti
    //tool.style.height = '35px';  //

    _toolbarArray.push(tool);
    _tagToolbar.appendChild(tool);
    if (p_left != null) { setPos(tool, p_left, p_top) }
    return tool;
  }

  this.width      = function() { return _map_w; }
  this.height     = function() { return _map_h; }
  this.action     = function() { return _action; }
  this.control    = function() { return _control; }
  this.setCgi     = function(path) { _cgi = path; }
  this.setMapFile = function(p_mapFile) { _map_file = 'map='+p_mapFile; }
  this.setMode    = function(p_mode) { _mode = p_mode; }
  this.setLayers  = function(p_layers) { _layers = p_layers }
  this.setArgs    = function(p_args) { _args = p_args; }
  this.attachMap  = function(myMap) { _attachedMsMap = myMap; }
  this.setReferenceMap = function(myMap) { _referenceMap = myMap; }

  //MCS
  //Permette di decidere se visualizzare o no lo scalimetro
  this.VisualizzaScalimetro = function(visScalimetro)
  { 
    if (visScalimetro == true) 
        _usaScalimetro = 'SI'; 
    else
        _usaScalimetro = 'NO';
        
  }

  // Permette di disegnare un box (oggetto _tagReference) nella mappa, usato
  // internamente per impostare il reference di un'altra mappa.
  this.setReferenceBox = function(p_Xmin, p_Xmax, p_Ymin, p_Ymax)
  {
    //i.fullExtentNoRedraw();  // 20060316
    Xmin = i.xReal2pixel(p_Xmin); Ymin = i.yReal2pixel(p_Ymin);
    Xmax = i.xReal2pixel(p_Xmax); Ymax = i.yReal2pixel(p_Ymax);

    _tagReference.style.left    = Xmin +'px';
    _tagReference.style.top     = Ymax +'px';
    _tagReference.style.width   = Xmax - Xmin +'px';
    _tagReference.style.height  = Ymin - Ymax +'px';
    _tagReference.style.display = '';
  }
  
  //Lettura dei parametri della mappa
  this.getXmin = function()
  {
    return _ext_Xmin;
  }

  this.getYmin = function()
  {
    return _ext_Ymin;
  }

  this.getXmax = function()
  {
    return _ext_Xmax;
  }
  this.getYmax = function()
  {
    return _ext_Ymax;
  }

  // Converte una coordinata X/Y reale in pixel (rispetto al bordo
  // sinistro/superiore dell'immagine)
  
  
  this.xReal2pixel = function(p_x)
  { 
	return Math.round( _map_w * (p_x - _ext_Xmin) / (_ext_Xmax - _ext_Xmin) ) ; 
  }
  
  this.yReal2pixel = function(p_y)
  { 
    return Math.round( _map_h * (_ext_Ymax - p_y) / (_ext_Ymax - _ext_Ymin) ) ; 
  }
  this.wPixel2real = function(p_w) { return (p_w * _pixel_w); }
  this.hPixel2real = function(p_h) { return (p_h * _pixel_h); }
  this.wReal2pixel = function(p_w) { return (p_w / _pixel_w); }
  this.hReal2pixel = function(p_h) { return (p_h / _pixel_w); }

  this.setExtent  = function(Xmin, Xmax, Ymin)
  {

    //MCS : limitazione extent della mappa
 //   if (Xmin < _ext_Xmin_orig)   Xmin = _ext_Xmin_orig;
 //   if (Ymin < _ext_Ymin_orig)   Ymin = _ext_Ymin_orig;
 //   if (Xmax > _ext_Xmax_orig)   Xmax = _ext_Xmax_orig;
    
    _ext_Xmin = Xmin; _ext_Xmax = Xmax; _ext_Ymin = Ymin;
    _ext_Ymax = ((_map_h/_map_w)*(_ext_Xmax-_ext_Xmin)) + _ext_Ymin;
  }

  this.setFullExtent = function(Xmin, Xmax, Ymin)
  {

    _ext_Xmin_orig = Xmin; _ext_Xmax_orig = Xmax; _ext_Ymin_orig = Ymin;
    _ext_Ymax_orig = ((_map_h/_map_w)*(_ext_Xmax_orig-_ext_Xmin_orig)) + _ext_Ymin_orig;
    i.fullExtentNoRedraw();	// 20060316 (IE bugfix)
  }

  this.setZoomboxFirst = function(x, y)
  {
    _zoombox_x_first = x - DL_GetElementLeft(_tagMain);
    _zoombox_y_first = y - DL_GetElementTop(_tagMain);
  }

  this.setZoomboxWH = function(x, y)
  {
    _zoombox_x_last = x - DL_GetElementLeft(_tagMain);
    _zoombox_y_last = y - DL_GetElementTop(_tagMain);
    _tagZoombox.style.left   = min(_zoombox_x_first, _zoombox_x_last) + 'px';
    _tagZoombox.style.top    = min(_zoombox_y_first, _zoombox_y_last) + 'px';
    _tagZoombox.style.width  = max(_zoombox_x_last,  _zoombox_x_first) -
                               min(_zoombox_x_last,  _zoombox_x_first) + 'px';
    _tagZoombox.style.height = max(_zoombox_y_last,  _zoombox_y_first) -
                               min(_zoombox_y_last,  _zoombox_y_first) + 'px';
    _tagZoombox.style.display = '';
  }

  this.setSelectZoomboxWH = function(x, y)
  {
    _zoombox_x_last = x - DL_GetElementLeft(_tagMain);
    _zoombox_y_last = y - DL_GetElementTop(_tagMain);
    _tagSelectZoombox.style.left   = min(_zoombox_x_first, _zoombox_x_last) + 'px';
    _tagSelectZoombox.style.top    = min(_zoombox_y_first, _zoombox_y_last) + 'px';
    _tagSelectZoombox.style.width  = max(_zoombox_x_last,  _zoombox_x_first) -
                               min(_zoombox_x_last,  _zoombox_x_first) + 'px';
    _tagSelectZoombox.style.height = max(_zoombox_y_last,  _zoombox_y_first) -
                               min(_zoombox_y_last,  _zoombox_y_first) + 'px';
    _tagSelectZoombox.style.display = '';
  }
  
  /*  
  this.zoomboxExtent = function()
  {
    _tagZoombox.style.display = 'none';

    var ll = min(_zoombox_x_last, _zoombox_x_first);
    var rr = max(_zoombox_x_last, _zoombox_x_first);
    var bb = max(_zoombox_y_last, _zoombox_y_first);
    var tt = min(_zoombox_y_last, _zoombox_y_first);

    _ext_Xmin += ll * _pixel_w;
    _ext_Xmax -= (_map_w - rr) * _pixel_w;
    _ext_Ymax -= tt * _pixel_h;
    _ext_Ymin += (_map_h - bb) * _pixel_h;

    i.redraw();
  }
  */
  


  this.zoomboxExtent = function()
  {

    _tagZoombox.style.display = 'none';

    var ll = min(_zoombox_x_last, _zoombox_x_first);
    var rr = max(_zoombox_x_last, _zoombox_x_first);
    var bb = max(_zoombox_y_last, _zoombox_y_first);
    var tt = min(_zoombox_y_last, _zoombox_y_first);

    _ext_Xmin += ll * _pixel_w;
    _ext_Xmax -= (_map_w - rr) * _pixel_w;
    _ext_Ymax -= tt * _pixel_h;
    _ext_Ymin += (_map_h - bb) * _pixel_h;

    i.redraw();
  }

  //MCS
  this.selectboxExtent = function()
  {
    _tagSelectZoombox.style.display = 'none';
    
    var ll = min(_zoombox_x_last, _zoombox_x_first);
    var rr = max(_zoombox_x_last, _zoombox_x_first);
    var bb = max(_zoombox_y_last, _zoombox_y_first);
    var tt = min(_zoombox_y_last, _zoombox_y_first);
    
    doSelectBox(_ext_Xmin+(ll * _pixel_w),_ext_Ymin+((_map_h - bb) * _pixel_h),_ext_Xmax-((_map_w - rr) * _pixel_w),_ext_Ymax-(tt * _pixel_h),ActiveLayerIndex);
   }
 
  //MCS
  this.identifyboxExtent = function()
  {
    _tagSelectZoombox.style.display = 'none';
    
    var ll = min(_zoombox_x_last, _zoombox_x_first);
    var rr = max(_zoombox_x_last, _zoombox_x_first);
    var bb = max(_zoombox_y_last, _zoombox_y_first);
    var tt = min(_zoombox_y_last, _zoombox_y_first);
    
    doIdentifyBox(_ext_Xmin+(ll * _pixel_w),_ext_Ymin+((_map_h - bb) * _pixel_h),_ext_Xmax-((_map_w - rr) * _pixel_w),_ext_Ymax-(tt * _pixel_h),ActiveLayerIndex);
   }   
  
  this.identifyMultiboxExtent = function()
  {

    _tagSelectZoombox.style.display = 'none';
    
    var ll = min(_zoombox_x_last, _zoombox_x_first);
    var rr = max(_zoombox_x_last, _zoombox_x_first);
    var bb = max(_zoombox_y_last, _zoombox_y_first);
    var tt = min(_zoombox_y_last, _zoombox_y_first);
    
    i.segnaPunto(_zoombox_x_first,_zoombox_y_first);
            
    doIdentifyBoxMulti(_ext_Xmin+(ll * _pixel_w),_ext_Ymin+((_map_h - bb) * _pixel_h),_ext_Xmax-((_map_w - rr) * _pixel_w),_ext_Ymax-(tt * _pixel_h),"");
  
   } 
   
   this.selecttooltipExtent = function()
  {
    _tagSelectZoombox.style.display = 'none';
    
    var ll = min(_zoombox_x_last, _zoombox_x_first);
    var rr = max(_zoombox_x_last, _zoombox_x_first);
    var bb = max(_zoombox_y_last, _zoombox_y_first);
    var tt = min(_zoombox_y_last, _zoombox_y_first);

    getTooltip(_ext_Xmin+(ll * _pixel_w),_ext_Ymin+((_map_h - bb) * _pixel_h),_ext_Xmax-((_map_w - rr) * _pixel_w),_ext_Ymax-(tt * _pixel_h),ActiveLayerIndex,i);
   }  



  this.zoomExtent = function(xmin,ymin,xmax,ymax,scala)
  {
    
    _ext_Xmin = parseFloat(xmin);
    _ext_Xmax = parseFloat(xmax);
    _ext_Ymax = parseFloat(ymax);
    _ext_Ymin = parseFloat(ymin);

    //alert('ZE:'+xmin+'   '+ymin);
    
    //MCS
    //Se sto facendo lo zoom su un punto aumento un po la mia estensione
    if ((xmin == xmax ) && (ymin == ymax))
    {
        _ext_Xmin -= i.wPixel2real(5);
        _ext_Xmax += i.wPixel2real(5);
        _ext_Ymax += i.wPixel2real(5);
        _ext_Ymin -= i.wPixel2real(5);   
    }

    if (scala != null)
        //Ricalcolo gli extent data la scala
        i.zoomScala(scala);
        
    i.redraw();
  }


  this.recalc_pixel_size = function()
  {
    _pixel_w  = (_ext_Xmax - _ext_Xmin) / _map_w;
    _pixel_h  = (_ext_Ymax - _ext_Ymin) / _map_h;
  }


  this.redraw = function(redrawAttached)
  {
    i.recalc_map_size();

 	goPopup();
 	
	try
	{
  		if(window.self.name == 'zyxabc') {
			myMap1.ClearPunti();
			}
	}
	catch(e)
	{
	}
	finally
	{  
	}    
    
    // Luca - Lasciare questo tra il calcolo delle nuove dimensioni e il redraw vero e proprio
	if(window.self.name == 'Turismo Asti' && DivTag.id != 'mappaov') {
		myMap1.ClearPunti();
		AggiornaPercorsi("");		
	}


    //MCS
    var imgurl=i.get_map_url();
   
    if (imgurl != '')
    {
        _tagMap_B.src = imgurl;
    }
    
    if ( (_attachedMsMap != null) && (redrawAttached != false) )
    {
      _attachedMsMap.attachMap(i);
      _attachedMsMap.setExtent(_ext_Xmin, _ext_Xmax, _ext_Ymin);
      _attachedMsMap.redraw(false);
    }

    if ( _referenceMap != null )	// Draw zoom box in the reference map
    {
      _referenceMap.setReferenceBox(_ext_Xmin, _ext_Xmax, _ext_Ymin, _ext_Ymax);
    }
            
    try
	{
  	if(parent.frames['lista'].name == 'lista')
		parent.frames['lista'].caricapunti();
	}
	catch(e)
	{
		//Luca
		try
		{
  		if(parent.frames['toponimi'].frames['lista'].name == 'lista')
			parent.frames['toponimi'].frames['lista'].caricapunti();
		}
		catch(e)
		{    
		}
		finally
		{  
		}	
	}
	finally
	{  
	}	
	// - Script che cambia la selezione del'eventuale gradino delle scale 
    try
	{	    
		if(window.self.name == 'zyxabc')	{	
            
			sc_vett = new Array(300000,200000,100000,75000,50000,25000,10000,5000,2500);
			var sc = myMap1.GetScala();
			if(sc < sc_vett[0])  {
				for(ii=0; ii<9; ii++) {
					if(sc > sc_vett[ii+1] && sc < sc_vett[ii]) {	
						
						var tmp_sc = ((sc_vett[ii+1] + sc_vett[ii])/2);
						if(sc < tmp_sc) 
							window.self.change_bgc(sc_vett[ii]);
						else  
							window.self.change_bgc(sc_vett[ii+1]);
		}}}}
	}
	catch(e)
	{
	}
	finally
	{  
	}
	
	//Luca - Viewpoint
	if(TimeRedraw >= 2) {
		if(window.self.name == 'Turismo Asti' && DivTag.id != 'mappaov')	{
			Change_Tipologia(guidSession,"");
		}
		TimeRedraw = TimeRedraw + 1;
	}
	else {
		TimeRedraw = TimeRedraw + 1;
    }
    
	gdAfterRedraw();
  }

  this.fullExtentNoRedraw = function()
  {
    _ext_Xmin = _ext_Xmin_orig; _ext_Xmax = _ext_Xmax_orig;
    _ext_Ymin = _ext_Ymin_orig; _ext_Ymax = _ext_Ymax_orig;
  }

  this.fullExtent = function() {  i.fullExtentNoRedraw();   i.redraw(); }

  //
  this.setActionTick = function()
  { _action = 'tick'; }
  
  // Luca per Asti
  this.setActionPercorsiIdentify = function()
  { _action = 'percorsiidentify'; _tagMap.style.cursor = "crosshair"; }
  
  this.setActionZoombox = function()
  { _action = 'zoom'; _tagMap.style.cursor = "crosshair"; }

  this.setActionPan = function()
  { _action = 'pan'; _tagMap.style.cursor = "move"; }

  this.setActionIdentify = function()
  { _action = 'identifyzoom'; _tagMap.style.cursor = "crosshair"; }

  this.setActionIdentifyPunto = function()
  { _action = 'identifypunto'; _tagMap.style.cursor = "default"; }

 this.setActionIdentifyPuntoMulti = function()
  { _action = 'identifypuntomulti'; _tagMap.style.cursor = "crosshair"; }
  
 this.setActionIdentifyPuntoMultiPoly = function()
  { _action = 'identifypuntomultipoly'; _tagMap.style.cursor = "crosshair"; }

  this.setActionSelect = function()
  { _action = 'selectzoom'; _tagMap.style.cursor = "crosshair"; }

  //MCS
  this.setActionTooltip = function()
  { _action = 'selecttooltip'; _tagMap.style.cursor = "crosshair"; 
    //Avvio il gestore dei tooltip  
    if (enableTooltip == true )
        setTimeout("getSingleTooltipTimer('"+ActiveLayerIndex+"');",1000);
  }

  this.setActionTooltipBox = function()
  { _action = 'selecttooltipbox'; _tagMap.style.cursor = "crosshair"; 
  }
  
  this.setActionDisegna = function()
  { _action = 'disegna'; _tagMap.style.cursor = "crosshair"; }


  this.setActionSelezionaPoligono = function()
  { _action = 'selectpoly'; _tagMap.style.cursor = "crosshair"; }
  
  this.setActionMisuraArea = function()
  { _action = 'misuraArea'; _tagMap.style.cursor = "crosshair";
    var winPop;
        
    winPop=getDocumentPopup('disegna_misura');
        
  	winPop.getElementById('istruzioni').style.display="none";
  	winPop.getElementById('info_varie').innerHTML="Clicca sulla mappa per inserire il primo vertice del poligono.";

  }
  
 this.setActionMisuraSegmento = function()
  { _action = 'misuraSegmento'; _tagMap.style.cursor = "crosshair";
    var winPop;
        
    winPop=getDocumentPopup('disegna_misura');
        
    winPop.getElementById('istruzioni').style.display="none";
  	winPop.getElementById('info_varie').innerHTML="Clicca sulla mappa per inserire il primo punto del segmento da misurare.";
  }
  
 this.setActionBufferSegmento = function()
  { _action = 'bufferSegmento'; _tagMap.style.cursor = "crosshair";

  }
 this.setActionBufferArea = function()
  { _action = 'bufferArea'; _tagMap.style.cursor = "crosshair";

  }
//Buffer dato il centro e il valore del raggio
 this.setActionBufferCircolare = function()
  { 
  _action = 'areaCircolareFissa'; _tagMap.style.cursor = "crosshair";
  }
  
  //Buffer dato il click del centro e il click per il raggio
 this.setActionBufferCircolare2Punti = function()
  { 
  _action = 'areaCircolare'; _tagMap.style.cursor = "crosshair";
  }
    
  //Buffer dato il click del centro e il click per il raggio
 this.setActionBufferGeometriaEsistente = function()
  { 
  _action = 'bufferGeometria'; _tagMap.style.cursor = "crosshair";
  }


  this.setActionNone = function()
  {
    _action = 'none'; _tagToolbar.style.display = 'none';
    _tagMap.style.cursor = "";
  }

  this.setActionZoomIn = function()
  {


    if ( isNaN(_tagLoading.style.display) )
    { i.zoomPerc(1.40); i.redraw(); }
  }

  this.setActionZoomOut = function()
  {
  
    if ( isNaN(_tagLoading.style.display) )
    { i.zoomPerc(0.30); i.redraw(); }
  }
  
  this.setActionZoomScala = function(scala)
  {
  
    if ( isNaN(_tagLoading.style.display) )
    { i.zoomScala(scala); i.redraw(); }
  }
  
  //MCS
  this.setActionSposta = function(direzione)
  {
    if (direzione == 'N')
        i.panMap(0,0.2);
    if (direzione == 'S')
        i.panMap(0,-0.2);
    if (direzione == 'E')
        i.panMap(0.2,0);
    if (direzione == 'W')
        i.panMap(-0.2,0);
        
    if (direzione == 'SW')
        i.panMap(-0.2,-0.2);
    if (direzione == 'NW')
        i.panMap(-0.2,0.2);
    if (direzione == 'SE')
        i.panMap(0.2,-0.2);
    if (direzione == 'NE')
        i.panMap(0.2,0.2);    
    i.redraw();
  }
  
  this.setActionPanNord = function()
  {
    i.panMap(0,0.2);
    i.redraw();
  }

  this.setActionPanSud = function()
  {
    i.panMap(0,-0.2);
    i.redraw();
  }

  this.setActionPanEst = function()
  {
    i.panMap(0.2,0);
    i.redraw();
  }

  this.setActionPanWest = function()
  {
    i.panMap(-0.2,0);
    i.redraw();
  }

  this.setActionPanNordWest = function()
  {
    i.panMap(-0.2,0.2);
    i.redraw();
  }

  this.setActionPanNordEst = function()
  {
    i.panMap(0.2,0.2);
    i.redraw();
  }

  this.setActionPanSudWest = function()
  {
    i.panMap(-0.2,-0.2);
    i.redraw();
  }

  this.setActionPanSudEst = function()
  {
    i.panMap(0.2,-0.2);
    i.redraw();
  }

  //MCS
  this.panMap= function(perc_sx,perc_alto)
  {
    

    var wx     = _ext_Xmax - _ext_Xmin;
    var wx_part = wx * Math.abs(perc_sx);
    var kx     = 0;
    if (perc_sx>0) 
        kx = wx_part;
    else
        kx = -wx_part;
    
    var wy     = _ext_Ymax - _ext_Ymin;
    var wy_part = wy * Math.abs(perc_alto);
    var ky     = 0;
    if (perc_alto>0) 
        ky = wy_part;
    else
        ky = -wy_part;
    

    i.setExtent(_ext_Xmin + kx, _ext_Xmax + kx, _ext_Ymin + ky);
  }

  this.zoomPerc = function(p_perc)
  {
    var wx     = _ext_Xmax - _ext_Xmin;
    var wx_new = wx * p_perc;
    var kx     = (wx_new - wx) / 2;
    var wy     = _ext_Ymax - _ext_Ymin;
    var wy_new = wy * p_perc;
    var ky     = (wy_new - wy) / 2;
    i.setExtent(_ext_Xmin + kx, _ext_Xmax - kx, _ext_Ymin + ky);
  }

  //MCS Zoom alla scala richiesta
  this.zoomScala = function(p_scala)
  {
  
    var ppi=getdpi(15); // 1024 pixels / 15 inches = pixels per inch
    var constant = 39.3701; //inches per meter     
    
    var mapScaleFactor=p_scala / (ppi * constant) ; // meters per pixel 
    
    var newMapWidth=mapScaleFactor * _map_w; //Dimensione Reale Mappa da far vedere
    var newMapHeight=mapScaleFactor * _map_w; //Dimensione Reale Mappa da far vedere
    
    var xcentro=(_ext_Xmax + _ext_Xmin)/2;
    var ycentro=(_ext_Ymax + _ext_Ymin)/2;
    //alert(ycentro -(newMapHeight/2));
   
    i.setExtent(xcentro - (newMapWidth/2), xcentro +(newMapWidth/2), ycentro -(newMapHeight/2));
  }

  //MCS Restituisce la scala corrispondente alla visualizzazione attuale
  this.GetScala = function()
  {
  
    var ppi=getdpi(15); // 1024 pixels / 15 inches = pixels per inch
    var constant = 39.3701; //inches per meter 

    var mapWidth=i.wPixel2real(_map_w);
    
    var scala = 0;
    
    //scala = round2((ppi * constant)*(mapWidth/_map_w));
    scala = parseInt((ppi * constant)*(mapWidth/_map_w));
    
    return scala;
  }
  
  //Aggiunta Coiro
  this.setMapImage = function (imageurl)
  {
	  
		var imgurl;
		_tagMap.src=imageurl;
		_tagMap_B.src=imageurl;
	}
	
  //Aggiunta Coiro	
  this.setDimensioniImage= function (w,h)
  {
		_tagMap.style.width=w+"px";
		_tagMap.style.height=h+"px";
  }
  
  this.mapLoaded = function()
  {
    // Swap image buffer (double buffering)
    var tmp = _tagMap;
    _tagMap = _tagMap_B;
    _tagMap_B = tmp;
    
    // Disegna gli overlay puntuali
    _tagOverlay.style.left = '0'; _tagOverlay.style.top  = '0';
    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _pointsOverlayArray[j].redraw(); }
    if ( _report != null ) { _report.redraw(); }

    _tagMap.style.cursor = _tagMap_B.style.cursor;
    _tagMap.style.left = (- _map_w_bord) +'px';
    _tagMap.style.top  = (- _map_h_bord) +'px';
    _tagMap_B.style.display = 'none';
    _tagMap.style.display = '';
  }

  this.get_map_url = function()
  {
    var my_url;

    if (_protocol == 'mapservercgi')
    {
      var size = 'mapsize=' + (_map_w+_map_w_bord+_map_w_bord) + '+'
                            + (_map_h+_map_h_bord+_map_h_bord);
      var ext  = 'mapext=' + (_ext_Xmin-i.wPixel2real(_map_w_bord)) + '+'
                           + (_ext_Ymin-i.hPixel2real(_map_h_bord)) + '+'
                           + (_ext_Xmax+i.wPixel2real(_map_w_bord)) + '+'
                           + (_ext_Ymax+i.hPixel2real(_map_h_bord)) ;

      my_url = _cgi + '?mode=' + _mode + '&' + _map_file + '&' +
               ext + '&' + size + '&layers=' + _layers;

      // Opera9 Bug Fix (onload event don't work if image is in cache)
      if ( browser.isOP ) { my_url = my_url + '&' + Math.random(); }

//      if ( i.action() == 'select' )
//      { my_url += '&imgxy='+_Xselect+"+"+_Yselect; }

    return my_url + '&' + _args;



    }

    if (_protocol == 'gdmanagerws')
    {
		//Se sto gestendo l'ov verifico se devo usare un img
		//fissa o chiederla al server
		if (DivTag.id == 'mappaov')
	    {
			if (_OverviewImg != '')
				return _OverviewImg;
		}    
      
      if (GLOUUseAsync  == 1)
        my_url = this.getMappaWS_asincrono();
      else
        my_url = this.getMappaWS();
        
        // Opera9 Bug Fix (onload event don't work if image is in cache)
//ALEX MODIFICA
//      if ( browser.isOP ) { my_url = my_url + '&' + Math.random(); }
      if ( browser.isOP ) { my_url = my_url + '?' + Math.random(); }
//ALEX MODIFICA

//      if ( i.action() == 'select' )
//      { my_url += '&imgxy='+_Xselect+"+"+_Yselect; }

    
    return my_url;

    }

    if (_protocol == 'gdmanagerwsproxy')
    {
		//Se sto gestendo l'ov verifico se devo usare un img
		//fissa o chiederla al server
		if (DivTag.id == 'mappaov')
	    {
			if (_OverviewImg != '')
				return _OverviewImg;		        
		}    
      my_url = this.getMappaWSProxy();

        // Opera9 Bug Fix (onload event don't work if image is in cache)
//ALEX MODIFICA
//      if ( browser.isOP ) { my_url = my_url + '&' + Math.random(); }
      if ( browser.isOP ) { my_url = my_url + '&' + Math.random(); }
//ALEX MODIFICA

    return my_url;

    }
  }

  this.addDraw =function() {
    _tagDraw   = document.createElement('div'); // Overlay Layer
    _tagDraw.style.left = '0'; _tagDraw.style.top  = '0';
    setZindex(_tagDraw, '30');
    _tagDraw.style.position   = 'absolute';
    _tagDraw.style.border   = '1px solid #ff0000';
    _tagMain.appendChild(_tagDraw);
    _tagDraw.style.width='200px';
    _tagDraw.style.height='200px';
    }


  this.setPan = function(x, y)
  {
    
    i.recalc_pixel_size();
    var x_real = x * _pixel_w; 
    var y_real = y * _pixel_h;
    
    _ext_Xmin = _ext_Xmin - x_real; 
    _ext_Xmax = _ext_Xmax - x_real;
    _ext_Ymin = _ext_Ymin + y_real; 
    _ext_Ymax = _ext_Ymax + y_real;
    
    i.setExtent(_ext_Xmin, _ext_Xmax, _ext_Ymin);
    i.redraw();
  }
  
  this.segnaPunto = function(x,y)
  {
      //Disegno un simbolo nel punto in cui ho fatto identify
    if (_drawLayer == null){
        _drawLayer = new jsGraphics("mappa");
        _drawLayer.setPrintable(true);
    }
    ripulisciDrawLayer(true);
    _drawLayer.fillEllipse(x-2,y-2,4,4);
    _drawLayer.paint();    
  }
  
  this.addVertice = function(x, y)
  {
    if (_drawLayer == null){
        _drawLayer = new jsGraphics("mappa");
        _drawLayer.setPrintable(true);
	}
    else
        ripulisciDrawLayer(true);
        
    var xReale;
    var yReale;
    

    //document.gdmanager.coordextxmappa.value = (_ext_Xmin+i.wPixel2real(x - DL_GetElementLeft(_tagMap)));
    //document.gdmanager.coordextymappa.value = (_ext_Ymax-i.hPixel2real(y - DL_GetElementTop(_tagMap)));

	//alert(_ext_Ymax-i.hPixel2real(y));
    
    xReale=_ext_Xmin+i.wPixel2real(x);
    arrXDraw.push(x);
    arrXDrawReal.push(xReale);
    
    yReale=_ext_Ymax-i.hPixel2real(y);
    arrYDraw.push(y);
    arrYDrawReal.push(yReale);
    
    _drawLayer.setColor("#ff0000"); // red
    
    if ((_oldXDraw !=0) && (_oldYDraw != 0)){
    
		if (i.action() == 'misuraArea')
        {
			_drawLayer.fillPolygon(arrXDraw,arrYDraw);
			_drawLayer.drawPolygon(arrXDraw,arrYDraw);
        }
		
        if (i.action() == 'misuraSegmento'){
			    _drawLayer.drawPolyline(arrXDraw,arrYDraw);
		    }
            
        if (i.action() == 'bufferSegmento'){
			    _drawLayer.drawPolyline(arrXDraw,arrYDraw);
        }   
             
        if (i.action() == 'bufferArea'){
        	    _drawLayer.fillPolygon(arrXDraw,arrYDraw);
			    _drawLayer.drawPolygon(arrXDraw,arrYDraw);
        }       
        if (i.action() == 'areaCircolare')
        {
            
            if (arrXDraw.length == 2) {
                //Se ho una coppia di punti allora disegno il cerchio
                var xx=arrXDraw[0];
                var yy=arrYDraw[0];
                
                var ww=arrXDraw[1];
                var hh=arrYDraw[1];
                
                var raggio=Math.sqrt(((ww-xx)*(ww-xx))+((hh-yy)*(hh-yy)))
                
         
            if ((LayerTmp != '') && (LayerTmp != -1))
				var ID_FW=LayerTmp;
			else
			    var ID_FW=ActiveLayerIndex;
			    
			// Luca
			if(winPop.getElementById('buffer'))
                gloBufferRaggio=winPop.getElementById('buffer').value;
            else
                gloBufferRaggio=1;
			//////////////
            
            IdentifyCirconferenza(ID_FW,round2(arrXDrawReal[0]),round2(arrYDrawReal[0]), round2(i.wPixel2real(gloBufferRaggio)));
            
            //Azzero l'elenco dei punti per un nuovo disegno
            arrXDraw=new Array();
            arrXDrawReal=new Array();
            
            arrYDraw=new Array();
            arrYDrawReal=new Array();      
            }
			
    }        
        
    if (i.action() == 'selectpoly')
			_drawLayer.fillPolygon(arrXDraw,arrYDraw);
        //drawLayer.drawLine(_oldXDraw , _oldYDraw, x, y);
       // _drawLayer.fillPolygon(arrXDraw,arrYDraw);
		//_drawLayer.drawPolyline(arrXDraw,arrYDraw);
        //_drawLayer.drawPolygon(arrXDraw,arrYDraw);
    }
	
    if (i.action() == 'areaCircolareFissa'){
        
        if (arrXDraw.length == 1) {
            //Se ho il centro dle cerchio
            var xx=arrXDraw[0];
            var yy=arrYDraw[0];                
            var winPop;
            
            if(document.getElementById ("AnalisiSpaziale"))
	            winPop = window.frames['AnalisiSpaziale'].document;
            else
                winPop=getDocumentPopup('analisi_spaziale');
        
            var gloBufferRaggio=winPop.getElementById('buffer').value;                                                                          
            
            // Modificata 
            if((LayerTmp != '') && (LayerTmp != -1))
				var ID_FW=LayerTmp;
			else
			    var ID_FW=ActiveLayerIndex;
			    
			 // Luca   
			if(winPop.getElementById('buffer'))
                gloBufferRaggio=winPop.getElementById('buffer').value;
            else
                gloBufferRaggio=1;
			//
			
            gloBufferXCentro=arrXDrawReal[0];
            gloBufferYCentro=arrYDrawReal[0];
            
            DisegnaCirconferenza(round2(gloBufferXCentro),round2(gloBufferYCentro), round2(gloBufferRaggio));
            
            //Luca
            if((ID_FW != '') && (ID_FW != -1))
                winPop.getElementById('boxBottoneAnalisi').style.display="";
            //
                            
            winPop.getElementById('btnEseguiAnalisi').setAttribute('onClick',"parent.IdentifyCirconferenza('"+ID_FW+"','"+round2(gloBufferXCentro)+"','"+round2(gloBufferYCentro)+"','"+round2(gloBufferRaggio)+"');");
            //per IE
            winPop.getElementById('btnEseguiAnalisi').onclick=new Function( "parent.IdentifyCirconferenza('"+ID_FW+"','"+round2(gloBufferXCentro)+"','"+round2(gloBufferYCentro)+"','"+round2(gloBufferRaggio)+"');");
            
            //Azzero l'elenco dei punti per un nuovo disegno
            arrXDraw=new Array();
            arrXDrawReal=new Array();
            
            arrYDraw=new Array();
            arrYDrawReal=new Array();
            
            i.redraw();
        }
        
    }
    //
    if (i.action() == 'bufferGeometria'){
        
        if (arrXDraw.length == 1) {
            //ho le coordinate del punto cliccato
            var xx=arrXDraw[0];
            var yy=arrYDraw[0];
                             
            // Modificata 
            if((LayerTmp != '') && (LayerTmp != -1))
				var ID_FW=LayerTmp;
			else
			    var ID_FW=ActiveLayerIndex;
			
			//alert(ID_FW);
			//alert(ActiveLayerIndex);
			//////////////
			
            gloBufferXCentro=arrXDrawReal[0];
            gloBufferYCentro=arrYDrawReal[0];
            
           //Identifico la geometria cliccata
            doIdentifyPunto(gloBufferXCentro,gloBufferYCentro,ID_FW);
        }        
    }
    
    //misura lunghezza Segmenti
    if (i.action() == 'misuraSegmento'){
    
        var winPop;
        
        winPop=getDocumentPopup('disegna_misura');
                     
        winPop.getElementById('istruzioni').style.display="none";
        
        if( (a>0) && (b>0) ){
            if(lunghezza>0)
             lunghezza=lunghezza + Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
            else
             lunghezza=Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
             lunghezza_ultimo_segmento=Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
    
         winPop.getElementById('lunghezza').style.display="";
         winPop.getElementById('info_varie').style.display="none";
         winPop.getElementById('lunghezza').innerHTML="<br /><b>Lunghezza Totale: m. " + round2(lunghezza) +"</b><br /><br />";
         if(arrXDraw.length>2)
            winPop.getElementById('lunghezza').innerHTML+="<b>Lunghezza dell'ultimo segmento: m. " + round2(lunghezza_ultimo_segmento) +"</b><br /><br />";
         winPop.getElementById('lunghezza').innerHTML+="Inserisci un altro punto per calcolare la lunghezza totale dei segmenti, oppure <a href='javascript:parent.fineDisegno(); parent.myMap1.ClearPunti();'>Clicca qui</a> per terminare la misurazione";
         _drawLayer.drawString(round2(lunghezza_ultimo_segmento), x,y);  
        
        /*
        if(document.getElementById('select_temi')){
        var ID_FW=document.getElementById('select_temi').value;
        doIdentifyPoly(arrXDrawReal,arrYDrawReal,ID_FW );
        }
        */
        a=round2(i.wPixel2real(x));
         b=round2(i.hPixel2real(y));
        }else{
        winPop.getElementById('info_varie').innerHTML="Clicca ancora, per inserire il punto di chiusura del segmento dal misurare";
         a=round2(i.wPixel2real(x));
         b=round2(i.hPixel2real(y));
        }

    }
    //FINE MISURA Segmenti

    //misura lunghezza Segmenti  per Buffer
    if (i.action() == 'bufferSegmento'){
       
        var winPop;
        
        if(document.getElementById ("AnalisiSpaziale"))
	        winPop = window.frames['AnalisiSpaziale'].document;
        else
	    	winPop=getDocumentPopup('analisi_spaziale');
		
        if( (a>0) && (b>0) ){
            
        if(lunghezza>0)
			lunghezza=lunghezza + Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
        else
			lunghezza=Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
         
         a=round2(i.wPixel2real(x));
         b=round2(i.hPixel2real(y));
         
        }else{   
         winPop.getElementById('info_varieAnalisi').innerHTML="Clicca ancora, per inserire il punto di chiusura del segmento dal misurare";
			a=round2(i.wPixel2real(x));
			b=round2(i.hPixel2real(y));
        }
    }
    
        //misura lunghezza Segmenti  per Buffer
    if (i.action() == 'bufferArea'){
       
        var winPop;
        if(document.getElementById ("AnalisiSpaziale"))
	        winPop = window.frames['AnalisiSpaziale'].document;
        else
    		winPop=getDocumentPopup('analisi_spaziale');
		
        if( (a>0) && (b>0) ){
            
        if(lunghezza>0)
			lunghezza=lunghezza + Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
        else
			lunghezza=Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
         
         a=round2(i.wPixel2real(x));
         b=round2(i.hPixel2real(y));
         
        }else{   
         winPop.getElementById('info_varieAnalisi').innerHTML="Clicca ancora, per inserire il punto di chiusura del segmento dal misurare";
			a=round2(i.wPixel2real(x));
			b=round2(i.hPixel2real(y));
        }
    }
	
	// Luca Modifiche
    //misura Area e Perimetro
    if (i.action() == 'misuraArea'){
        
        var winPop;
	        
			winPop=getDocumentPopup('disegna_misura');

			winPop.getElementById('istruzioni').style.display="none";
			
        if( (a>0) && (b>0) ){
            
        if(lunghezza>0)
			lunghezza=lunghezza + Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
        else
			lunghezza=Math.sqrt( ((i.wPixel2real(x)-a)*(i.wPixel2real(x)-a)) +  ((i.hPixel2real(y)-b)* (i.hPixel2real(y)-b))   )
	        
			winPop.getElementById('lunghezza').style.display="";
			winPop.getElementById('info_varie').style.display="none";
			winPop.getElementById('lunghezza').innerHTML="<br /><b>Perimetro: m. " + round2(lunghezza) +"</b><br /><br />";
         
        if(arrXDraw.length>2){
			area = getAreaPoly(arrXDrawReal,arrYDrawReal);
			winPop.getElementById('lunghezza').innerHTML+="<br /><b>Area del Poligono: m&sup2;"+ area +"</b><br /><br />";
			eliminaTesti();
			_drawLayer.drawString(area+" m²", x,y); 
        } 
         winPop.getElementById('lunghezza').innerHTML+="Inserisci un altro vertice del poligono, oppure <a href='javascript:parent.fineDisegno(); parent.myMap1.ClearPunti(); '>Clicca qui</a> per terminare la misurazione";
         a=round2(i.wPixel2real(x));
         b=round2(i.hPixel2real(y));
         
        }else{
    
			winPop.getElementById('info_varie').innerHTML="Clicca ancora, per inserire il successivo vertice del poligono";
			a=round2(i.wPixel2real(x));
			b=round2(i.hPixel2real(y));
        }
    }
    //FINE MISURA Area e Perimetro

    _drawLayer.setColor("#ff0000"); // red
    
    _oldXDraw=x;
    _oldYDraw=y;    
   _drawLayer.paint();
  }
  
    this.getHtmlDisegno=function()
    {
        return _drawLayer.cnv.innerHTML;
    }
    this.getDrawlayer=function()
    {
        return _drawLayer;
    }
    
    this.disegnaUltimoSegmento=function(x,y)
    {
        if (arrXDraw.length > 0){
            ripulisciDrawLayer(true);
            _drawLayer.drawPolyline(arrXDraw,arrYDraw);            
            _drawLayer.drawLine(x-5,y-5,arrXDraw[arrXDraw.length-1],arrYDraw[arrYDraw.length-1]);
            _drawLayer.fillEllipse(arrXDraw[0]-3,arrYDraw[0]-3,6,6);
            _drawLayer.paint();
        }
    }

  this.recalc_map_size = function()
  {
    saveLastExtent(_ext_Xmin,_ext_Xmax,_ext_Ymin,_ext_Ymax);
    i.recalc_pixel_size();

    if ( _pixel_w > _pixel_h )
    { // Modify only Y (box width > height)
      var middle = ((_ext_Ymax - _ext_Ymin) / 2) + _ext_Ymin;
      var new_h = (_map_h / _map_w) * (_ext_Xmax - _ext_Xmin);
      _ext_Ymin = middle - (new_h / 2);
      _ext_Ymax = middle + (new_h / 2);
    } else
    { // Modify only X (box width < height)
      var middle = ((_ext_Xmax - _ext_Xmin) / 2) + _ext_Xmin;
      var new_w = (_map_w / _map_h) * (_ext_Ymax - _ext_Ymin);
      _ext_Xmin = middle - (new_w / 2);
      _ext_Xmax = middle + (new_w / 2);
    }

    i.recalc_pixel_size();
  }

  this.init = function()
  {
    _tagMain.className = 'mscross';  // css
    _tagMain.oncontextmenu  = function(){return false;};
    //_tagMain.style.border   = '1px solid #7ea3bf';  // set by css
    _tagMain.style.width    = i.width()+'px';
    _tagMain.style.height   = i.height()+'px';
    _tagMain.style.overflow = 'hidden';
    _tagMain.style.position = 'relative';

    var myDiv_1           = document.createElement('div');
    myDiv_1.oncontextmenu = function(){return false;};
    //myDiv_1.objRef = i;
    add_event(myDiv_1, 'mousedown', function(event){ChiamaEvento(event);});
    add_event(myDiv_1, 'mousemove', function(event){ChiamaEventoMove(event);});
    setZindex(myDiv_1, '0');
    // myDiv_1.style.position = 'absolute';
    myDiv_1.style.position = 'static';//risolve il problema della mappa tagliata su IE
    myDiv_1.left           = '0';
    myDiv_1.top            = '0';

    // First buffer (double buffer)
    _tagMap.objRef = i;
    _tagMap.oncontextmenu  = function(){return false;};
    _tagMap.onmousedown = function(){return false;};  // Disable drag'n drop
    add_event(_tagMap, 'load', i.mapLoaded );
    //i.tagMap.setAttribute('style', '-moz-user-select:none;');
    setZindex(_tagMap, '0');
    _tagMap.galleryImg = "no";
    _tagMap.style.width    = (i.width()+_map_w_bord+_map_w_bord)+'px';
    _tagMap.style.height   = (i.height()+_map_h_bord+_map_h_bord)+'px';
    _tagMap.style.border   = '0 none';
    _tagMap.style.margin   = '0'; _tagMap.style.padding  = '0';
    _tagMap.style.position = 'absolute';
    _tagMap.style.top      = (- _map_w_bord) +'px';
    _tagMap.style.left     = (- _map_h_bord) +'px';
    _tagMap.style.display  = 'none';

    // Second buffer (double buffer)
    _tagMap_B.objRef = _tagMap.objRef;
    _tagMap_B.oncontextmenu = _tagMap.oncontextmenu;
    _tagMap_B.onmousedown = _tagMap.onmousedown;
    add_event(_tagMap_B, 'load', i.mapLoaded );
    setZindex(_tagMap_B, '0');
    _tagMap_B.galleryImg = "no";
    _tagMap_B.style.width    = _tagMap.style.width;
    _tagMap_B.style.height   = _tagMap.style.height;
    _tagMap_B.style.border   = _tagMap.style.border;
    _tagMap_B.style.margin   = _tagMap.style.margin; _tagMap_B.style.padding = _tagMap.style.padding;
    _tagMap_B.style.position = _tagMap.style.position;
    _tagMap_B.style.top      = _tagMap.style.top;
    _tagMap_B.style.left     = _tagMap.style.left;
    _tagMap_B.style.display  = 'none';

    _tagReference.oncontextmenu    = function(){return false;};
    setZindex(_tagReference, '100');
    _tagReference.style.display    = 'none';
    _tagReference.style.position   = 'absolute';
    _tagReference.style.margin     = '0'; _tagReference.style.padding    = '0';
    _tagReference.style.lineHeight = '0';
    _tagReference.style.border     = '2px solid #FF0000'; //MCS
    _tagReference.style.background = '#a0a0a0';
    _tagReference.style.opacity    = '0.5';               // Gecko
    _tagReference.style.filter     = 'alpha(opacity=50)';  // Windows

    _tagZoombox.oncontextmenu    = function(){return false;};
    setZindex(_tagZoombox, '100');
    _tagZoombox.style.position   = 'absolute';
    _tagZoombox.style.display    = 'none';
    _tagZoombox.style.border     = '2px dashed #FF0000';
    _tagZoombox.style.margin     = '0px'; _tagZoombox.style.padding    = '0px';
    _tagZoombox.style.lineHeight = '0';
    _tagZoombox.style.background = '#606060';	         //'#f0f0f0';
    _tagZoombox.style.opacity    = '0.5';                // Gecko
    _tagZoombox.style.filter     = 'alpha(opacity=50)';  // Windows

    _tagSelectZoombox.oncontextmenu    = function(){return false;};
    setZindex(_tagSelectZoombox, '100');
    _tagSelectZoombox.style.position   = 'absolute';
    _tagSelectZoombox.style.display    = 'none';
    _tagSelectZoombox.style.border     = '2px solid #ff0000';
    _tagSelectZoombox.style.margin     = '0px'; _tagSelectZoombox.style.padding    = '0px';
    _tagSelectZoombox.style.lineHeight = '0';
    _tagSelectZoombox.style.background = '#606060';	         //'#f0f0f0';
    _tagSelectZoombox.style.opacity    = '0.2';                // Gecko
    _tagSelectZoombox.style.filter     = 'alpha(opacity=20)';  // Windows

    // Overlay Layer
    _tagOverlay.oncontextmenu    = function(){return false;};
    setZindex(_tagOverlay, '30');
    _tagOverlay.style.position   = 'absolute';

    _tagPoints.oncontextmenu    = function(){return false;};
    setZindex(_tagPoints, '40');
    _tagPoints.style.position   = 'absolute';

    _tagInfo.oncontextmenu   = function(){return false;};
    setZindex(_tagInfo, '50');
    _tagInfo.style.position  = 'absolute';

    // "Loading" image tag
    _tagLoading.oncontextmenu    = function(){return false;};
    _tagLoading.onmousedown = function(){return false;};  // Disable drag'n drop
    setZindex(_tagLoading, '100');
    _tagLoading.style.position   = 'absolute';
    _tagLoading.style.display    = 'none';
    _tagLoading.style.border     = '0';
    _tagLoading.style.margin     = '0'; _tagLoading.style.padding    = '0';
    _tagLoading.style.lineHeight = '0';
    setAlphaPNG(_tagLoading, _iconLoading);
    _tagLoading.style.left = (_map_w - 130) / 2 + 'px';
    _tagLoading.style.top  = (_map_h - 122) / 2 + 'px';

    _tagToolbar.oncontextmenu  = function(){return false;};
    _tagToolbar.style.position = 'absolute';
    _tagToolbar.style.left     = '0'; _tagToolbar.style.top = '0';

// ---> ToolBar ---------------------------------------------------------------

    //MCS
    //Se non è l'overview disegno i bottoni per il pan
    if (DivTag.id != 'mappaov')
    {
        my_img_pannord = i.addMapTool('Pan Nord', i.setActionPanNord, _iconPanNord);
        my_img_pansud = i.addMapTool('Pan Sud', i.setActionPanSud, _iconPanSud);
        my_img_panest = i.addMapTool('Pan Est', i.setActionPanEst, _iconPanEst);
        my_img_panovest = i.addMapTool('Pan Ovest', i.setActionPanWest, _iconPanWest);
        
        my_img_pannordovest = i.addMapTool('Pan Nord/Ovest', i.setActionPanNordWest, _iconPanNordWest);
        my_img_pannordest = i.addMapTool('Pan Nord/Est', i.setActionPanNordEst, _iconPanNordEst);
        my_img_pansudovest = i.addMapTool('Pan Sud/Ovest', i.setActionPanSudWest, _iconPanSudWest);
        my_img_pansudest = i.addMapTool('Pan Sud/Est', i.setActionPanSudEst, _iconPanSudEst);
        
        var l = i.width()/2;
        var h = i.height()/2;
        
        //MCS con -18 e -35 centro le immagini rispetto alla mappa
        setPos(my_img_pannord, l-35, 1);
        setPos(my_img_pansud, l-35, i.height()-18);
        setPos(my_img_panest, i.width()-18, h-35);
        setPos(my_img_panovest, 1, h-35);
        
        setPos(my_img_pannordovest, 1, 1);
        setPos(my_img_pannordest, i.width()-22, 1);
        setPos(my_img_pansudovest, 1, i.height()-22);
        setPos(my_img_pansudest,i.width()-22,i.height()-22);
    }
    
    /*
    //MCS
    var my_img_fullext = i.addMapTool('Full Extent', i.fullExtent, _iconFullExtentButton);
    var my_img_zoom    = i.addMapTool('Zoom', i.setActionZoombox, _iconZoomboxButton);
    var my_img_pan     = i.addMapTool('Pan', i.setActionPan, _iconPanButton);
    var my_img_zoomin  = i.addMapTool('Zoom In', i.setActionZoomIn, _iconZoominButton);
    var my_img_zoomout = i.addMapTool('Zoom Out', i.setActionZoomOut, _iconZoomoutButton);
    //var my_img_select = i.addMapTool('Select', i.setActionIdentify, _iconIdentifyButton); //MCS 
    var my_img_select = i.addClickTool(); //MCS 

    
    if ( ( _control == 'standard' )      ||
         ( _control == 'standardRight' )  )
    {
      var l = i.width()-38;
      setPos(my_img_fullext, l, 1);
      setPos(my_img_zoom,    l, 39);
      setPos(my_img_pan,     l, 77);
      setPos(my_img_zoomin,  l, 115);
      setPos(my_img_zoomout, l, 153);
      setPos(my_img_select, l, 191); //MCS 
    }

    if ( _control == 'standardLeft' )
    {
      var l = 1;
      setPos(my_img_fullext, l, 1);
      setPos(my_img_zoom,    l, 39);
      setPos(my_img_pan,     l, 77);
      setPos(my_img_zoomin,  l, 115);
      setPos(my_img_zoomout, l, 153);
    }

    if ( _control == 'standardUp' )
    {
      var l = 1;
      setPos(my_img_fullext, 1,   l);
      setPos(my_img_zoom,    39,  l);
      setPos(my_img_pan,     77,  l);
      setPos(my_img_zoomin,  115, l);
      setPos(my_img_zoomout, 153, l);
    }

    if ( _control == 'standardCornerLeft' )
    {
      var l = 1;
      setPos(my_img_fullext, 1,  l);
      setPos(my_img_zoom,    39, l);
      setPos(my_img_pan,     77, l);
      setPos(my_img_zoomin,  1,  39);
      setPos(my_img_zoomout, 1,  77);
    }

    if ( _control == 'standardCornerRight' )
    {
      var l = i.width()-38;
      setPos(my_img_fullext, l,    1);
      setPos(my_img_zoom,    l-38, 1);
      setPos(my_img_pan,     l-76, 1);
      setPos(my_img_zoomin,  l,    39);
      setPos(my_img_zoomout, l,    77);
    }
*/
// <--- ToolBar ---------------------------------------------------------------

    var myLink              = document.createElement('a');
    var ref                 = 'http://datacrossing.crs4.it/en_Documentation_mscross.html';
    if (myLink.setAttribute)
    { myLink.setAttribute('href', ref); } else
    { myLink.href = ref }
    myLink.oncontextmenu    = function(){return false;};
    setZindex(myLink, '110');
    myLink.style.position   = 'absolute';
    myLink.style.fontFamily = 'Verdana, Arial, Helvetica, sans-serif';
    myLink.style.fontSize   = '11px';
    myLink.style.left       = '2px';
    myLink.style.top        = i.height()-13+'px';
    myLink.style.fontWeight = 'normal';
    myLink.style.textDecoration = 'overline';
    //MCS myLink.appendChild(document.createTextNode("msCross"));
    myLink.appendChild(document.createTextNode(""));

    // Double buffer
    myDiv_1.appendChild(_tagMap);
    myDiv_1.appendChild(_tagMap_B);

    _tagOverlay.appendChild(_tagPoints);
    _tagOverlay.appendChild(_tagInfo);

    _tagMain.appendChild(myDiv_1);
    _tagMain.appendChild(_tagOverlay);
    _tagMain.appendChild(_tagZoombox);
    _tagMain.appendChild(_tagSelectZoombox);
    _tagMain.appendChild(_tagReference);
    _tagMain.appendChild(myLink);
    _tagMain.appendChild(_tagToolbar);
    _tagMain.appendChild(_tagLoading);

    if ( i.action() == 'zoom' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'selectzoom' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'identifyzoom' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'identifypunto' ) { _tagMap.style.cursor = "default"; }
    if ( i.action() == 'identifypuntomulti' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'identifypuntomultipoly' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'selecttooltip' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'selecttooltipbox' ) { _tagMap.style.cursor = "crosshair"; }
    // Luca per Asti
    if ( i.action() == 'percorsiidentify' ) { _tagMap.style.cursor = "crosshair"; }
    if ( i.action() == 'pan' ) { _tagMap.style.cursor = "move"; }
  }

  this.dragStart = function(event)
  {
    var el;
    var x, y;
    
    if (window.frames['protoframe'].wsBusy == 1)
        alert('Attendere la fine della richiesta');

    dragObj.elNode = _tagMap;

    // Get cursor position with respect to the page.
    if ( browser.isNS )
    {
      x = event.clientX + window.scrollX;
      y = event.clientY + window.scrollY;
    } else
    {
      x = window.event.clientX + document.documentElement.scrollLeft
        + document.body.scrollLeft;
      y = window.event.clientY + document.documentElement.scrollTop
        + document.body.scrollTop;
    }

    // Save starting positions of cursor and element.
    dragObj.cursorStartX = x; dragObj.cursorStartY = y;
    dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
    dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

    if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
    if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

    // Update element's z-index.
    //dragObj.elNode.style.zIndex = ++dragObj.zIndex;       // Serve???

    // Capture mousemove and mouseup events on the page.

// xxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyyyyy
if ( isNaN(_tagLoading.style.display) )
{

    if (browser.isNS)
    {
      document.addEventListener("mousemove", i.dragGo,   true);
      document.addEventListener("mouseup",   i.dragStop, true);
      event.preventDefault();
    } else
    {
      document.attachEvent("onmousemove", i.dragGo);
      document.attachEvent("onmouseup",   i.dragStop);
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }

    if ( i.action() == 'zoom' ) { i.setZoomboxFirst(x, y); }
    //Luca per Asti
    if ( i.action() == 'percorsiidentify' ) { i.setZoomboxFirst(x, y); }
   
    if ( i.action() == 'selectzoom' ) { i.setZoomboxFirst(x, y); }
    if ( i.action() == 'identifyzoom' ) { i.setZoomboxFirst(x, y); }
    if ( i.action() == 'identifypuntomultipoly' ) { i.setZoomboxFirst(x, y); }
    if ( i.action() == 'identifypunto' ) { 
            //i.setZoomboxFirst(x, y); 
          _Xselect = x - DL_GetElementLeft(_tagMain);  //xxx
          _Yselect = y - DL_GetElementTop(_tagMain);   //xxx  
          //MCS alert((_ext_Xmin-i.wPixel2real(_Xselect))+'-----'+(_ext_Ymin-i.hPixel2real(_Yselect)));
          //MCS i.redraw();
          //alert(i.hPixel2real(_Yselect));
           doIdentifyPunto((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex);
    }    
    if ( i.action() == 'identifypuntomulti' ) { 
            //i.setZoomboxFirst(x, y); 
          _Xselect = x - DL_GetElementLeft(_tagMain);  //xxx
          _Yselect = y - DL_GetElementTop(_tagMain);   //xxx  
          //MCS alert((_ext_Xmin-i.wPixel2real(_Xselect))+'-----'+(_ext_Ymin-i.hPixel2real(_Yselect)));
          //MCS i.redraw();
          //alert(i.hPixel2real(_Yselect));
              //alert(_drawLayer);
         

            i.segnaPunto(_Xselect,_Yselect);

           doIdentifyPuntoMulti((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),"");
    }
    if ( i.action() == 'selecttooltipbox' ) { i.setZoomboxFirst(x, y); }


 }

  }

  this.mouseMove = function(event)
  {
    var x, y;

    // Get cursor position with respect to the page.
    if (browser.isNS)
    {
      x = event.clientX + window.scrollX;
      y = event.clientY + window.scrollY;
    } else
    {
      x = window.event.clientX + document.documentElement.scrollLeft
        + document.body.scrollLeft;
      y = window.event.clientY + document.documentElement.scrollTop
        + document.body.scrollTop;
    }
	
    document.gdmanager.coordextxmappa.value = (_ext_Xmin+i.wPixel2real(x - DL_GetElementLeft(_tagMap)));
    document.gdmanager.coordextymappa.value = (_ext_Ymax-i.hPixel2real(y - DL_GetElementTop(_tagMap)));
    
    if (browser.isNS)
    { event.preventDefault(); } else
    {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
  }

  this.dragGo = function(event)
  {
    var x, y;

    // Get cursor position with respect to the page.
    if (browser.isNS)
    {
      x = event.clientX + window.scrollX;
      y = event.clientY + window.scrollY;
    } else
    {
      x = window.event.clientX + document.documentElement.scrollLeft
        + document.body.scrollLeft;
      y = window.event.clientY + document.documentElement.scrollTop
        + document.body.scrollTop;
    }

    if ( i.action() == 'pan' )
    {
      // Move map by the same amount the cursor has moved.
      dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
      dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

      // Move Overlay layer
      _tagOverlay.style.left = parseInt(dragObj.elNode.style.left) +_map_w_bord +'px';
      _tagOverlay.style.top  = parseInt(dragObj.elNode.style.top)  +_map_h_bord +'px';
    }

    if ( i.action() == 'zoom' ) { i.setZoomboxWH(x, y); }
    //Luca per Asti
    if ( i.action() == 'percorsiidentify' ) { i.setZoomboxWH(x, y); }

    if ( i.action() == 'selectzoom' ) { i.setSelectZoomboxWH(x, y); }
    if ( i.action() == 'identifyzoom' ) { i.setSelectZoomboxWH(x, y); }
    if ( i.action() == 'identifypuntomultipoly' ) { i.setSelectZoomboxWH(x, y); }
    if ( i.action() == 'selecttooltipbox' ) { i.setSelectZoomboxWH(x, y); }

    if (browser.isNS)
    { event.preventDefault(); } else
    {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
  }

  this.dragStop = function(event)
  {
    // Clear the drag element global.
    //dragObj.elNode = null;
    
    // Stop capturing mousemove and mouseup events.
    if (browser.isNS)
    {
      document.removeEventListener("mousemove", i.dragGo,   true);
      document.removeEventListener("mouseup",   i.dragStop, true);
    } else
    {
      document.detachEvent("onmousemove", i.dragGo);
      document.detachEvent("onmouseup",   i.dragStop);
    }
        
    if (event.button == 2)
    {
        //Pulsante Destro
        var x, y, xx, yy;
        if (browser.isNS)
        {
          x = event.clientX + window.scrollX;
          y = event.clientY + window.scrollY;
        } else
        {
          x = window.event.clientX + document.documentElement.scrollLeft
            + document.body.scrollLeft;
          y = window.event.clientY + document.documentElement.scrollTop
            + document.body.scrollTop;
        }
        // Move drag element by the same amount the cursor has moved.
        xx = (dragObj.elStartLeft + x - dragObj.cursorStartX);
        yy = (dragObj.elStartTop  + y - dragObj.cursorStartY);
    
        // Add buffer size
        xx += _map_w_bord;
        yy += _map_h_bord;
        
        _zoombox_x_last = x - DL_GetElementLeft(_tagMain);
        _zoombox_y_last = y - DL_GetElementTop(_tagMain);
        
        
        if ( i.action() == 'selectpoly' ) { 
            doSelectPoly(arrXDrawReal,arrYDrawReal,ActiveLayerIndex );
            fineDisegno();
        }
        
        if ( i.action() == 'misuraArea') {
            _drawLayer.fillPolygon(arrXDraw,arrYDraw);
            eliminaTesti();
            _drawLayer.drawString(round2(area/2)+" m²", arrXDraw[arrXDraw.length-1],arrYDraw[arrYDraw.length-1]);             
            _drawLayer.paint();
        }
        
        // Luca Buffer poligonale
        if (i.action() == 'bufferArea'){
        
             _drawLayer.fillPolygon(arrXDraw,arrYDraw);
            _drawLayer.paint();

            if (arrXDraw.length >= 2) {
               
                var winPop;
	
	            if(document.getElementById ("AnalisiSpaziale"))
	                winPop = window.frames['AnalisiSpaziale'].document;
                else
                    winPop=getDocumentPopup('analisi_spaziale');

	            // Modificata 
                if((LayerTmp != '') && (LayerTmp != -1))
				    var ID_FW=LayerTmp;
			    else
			        var ID_FW=ActiveLayerIndex;
				
			     // Luca   
			    if(winPop.getElementById('buffer'))
                    gloBufferRaggio=winPop.getElementById('buffer').value;
                else
                    gloBufferRaggio=1;
			    //

                gloBufferArrX=arrXDrawReal;
                gloBufferArrY=arrYDrawReal;
                
                DisegnaBufferArea(arrXDrawReal,arrYDrawReal,gloBufferRaggio);
                
                //Luca
                if((ID_FW != '') && (ID_FW != -1)) {
                    winPop.getElementById('boxBottoneAnalisi').style.display="";
                    }
                //                    
                // Luca    
                winPop.getElementById('btnEseguiAnalisi').setAttribute('onClick',"parent.IdentifyBufferLinea('"+ID_FW+"',parent.gloBufferArrX,parent.gloBufferArrY,parent.round2(parent.gloBufferRaggio));");
                //per IE
                winPop.getElementById('btnEseguiAnalisi').onclick=new Function( "parent.IdentifyBufferLinea('"+ID_FW+"',parent.gloBufferArrX,parent.gloBufferArrY,parent.round2(parent.gloBufferRaggio)); return false;");
                
                //Azzero l'elenco dei punti per un nuovo disegno
                arrXDraw=new Array();
                arrXDrawReal=new Array();
                
                arrYDraw=new Array();
                arrYDrawReal=new Array();
                
                i.redraw();      
               
            }
        }	
        
        if (i.action() == 'bufferSegmento'){
        
            if (arrXDraw.length >= 2) {
               
                var winPop;
                
	            if(document.getElementById ("AnalisiSpaziale"))
	                winPop = window.frames['AnalisiSpaziale'].document;
                else
                    winPop=getDocumentPopup('analisi_spaziale');

	            // Modificata 
                if((LayerTmp != '') && (LayerTmp != -1))
				    var ID_FW=LayerTmp;
			    else
			        var ID_FW=ActiveLayerIndex;
				
			     // Luca   
			    if(winPop.getElementById('buffer'))
                    gloBufferRaggio=winPop.getElementById('buffer').value;
                else
                    gloBufferRaggio=1;
			    //

                gloBufferArrX=arrXDrawReal;
                gloBufferArrY=arrYDrawReal;
                
                DisegnaBufferLinea(arrXDrawReal,arrYDrawReal,gloBufferRaggio);
                
                //Luca
                if((ID_FW != '') && (ID_FW != -1)) {
                    winPop.getElementById('boxBottoneAnalisi').style.display="";
                    }
                //                    
                // Luca    
                winPop.getElementById('btnEseguiAnalisi').setAttribute('onClick',"parent.IdentifyBufferLinea('"+ID_FW+"',parent.gloBufferArrX,parent.gloBufferArrY,parent.round2(parent.gloBufferRaggio));");
                //per IE
                winPop.getElementById('btnEseguiAnalisi').onclick=new Function( "parent.IdentifyBufferLinea('"+ID_FW+"',parent.gloBufferArrX,parent.gloBufferArrY,parent.round2(parent.gloBufferRaggio)); return false;");
                
                //Azzero l'elenco dei punti per un nuovo disegno
                arrXDraw=new Array();
                arrXDrawReal=new Array();
                
                arrYDraw=new Array();
                arrYDrawReal=new Array();
                
                i.redraw();                     
            }
        }	
    }
    else
    {
        //Pulsante Sinistro
        var x, y, xx, yy;
        if (browser.isNS)
        {
          x = event.clientX + window.scrollX;
          y = event.clientY + window.scrollY;
        } else
        {
          x = window.event.clientX + document.documentElement.scrollLeft
            + document.body.scrollLeft;
          y = window.event.clientY + document.documentElement.scrollTop
            + document.body.scrollTop;
        }
        // Move drag element by the same amount the cursor has moved.
        xx = (dragObj.elStartLeft + x - dragObj.cursorStartX);
        yy = (dragObj.elStartTop  + y - dragObj.cursorStartY);
    
        // Add buffer size
        xx += _map_w_bord;
        yy += _map_h_bord;
        
        var winPop;
        
              
        
        winPop=getDocumentPopup('analisi_spaziale');    
           
        if(winPop.getElementById('buffer'))
            gloBufferRaggio=winPop.getElementById('buffer').value;
        else
            gloBufferRaggio=1;
        
        _zoombox_x_last = x - DL_GetElementLeft(_tagMain);
        _zoombox_y_last = y - DL_GetElementTop(_tagMain);
        
        if ( (i.action() == 'pan') && (xx != 0) && (yy != 0) ) { i.setPan(xx, yy); }
        if ( i.action() == 'zoom' ) { i.zoomboxExtent(); }
        if ( i.action() == 'selectzoom' ) { i.selectboxExtent(); }
        if ( i.action() == 'identifyzoom' ) { i.identifyboxExtent(); }
        if ( i.action() == 'identifypuntomultipoly' ) { i.identifyMultiboxExtent(); }
        if ( i.action() == 'selectpoly' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }
        if ( i.action() == 'misuraArea' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }
        if ( i.action() == 'misuraSegmento' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }
        if ( i.action() == 'bufferSegmento' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }
        if ( i.action() == 'bufferArea' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }
        if ( i.action() == 'areaCircolare' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }        
        if ( i.action() == 'areaCircolareFissa' ) { 
            i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); 
        }        
        if ( i.action() == 'bufferGeometria' ) { 
            _Xselect = x - DL_GetElementLeft(_tagMain);  //xxx
            _Yselect = y - DL_GetElementTop(_tagMain);   //xxx  
            
            //Ricavo l'Id della feature cliccata
            IDFeatureSelezionata=getIdFeature((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex,"FeatureID");
            CampoFeatureSelezionata="FeatureID";
            if (IDFeatureSelezionata == ''){
                IDFeatureSelezionata=getIdFeature((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex,"FID");
                CampoFeatureSelezionata="FID";
            }
            if (IDFeatureSelezionata == ''){
                IDFeatureSelezionata=getIdFeature((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex,"OBJECTID");
                CampoFeatureSelezionata="OBJECTID";
            }
            if (IDFeatureSelezionata == ''){
                IDFeatureSelezionata=getIdFeature((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex,"#ID#");
                CampoFeatureSelezionata="#ID#";
            }
            if (IDFeatureSelezionata == ''){
                IDFeatureSelezionata=getIdFeature((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex,"IDXSHAPE");
                CampoFeatureSelezionata="IDXSHAPE";
            }
            
            
            if ((IDFeatureSelezionata == '') || (IDFeatureSelezionata.indexOf(";") > 0) )
                {
                    if (IDFeatureSelezionata == '')
                    {
                        alert("Nessun oggetto selezionato. Buffer non possibile.");
                    }
                    else
                    {
                        alert("Sono state selezionati più oggetti. Buffer non possibile.");
                    }
                    CampoFeatureSelezionata='';
                    IDFeatureSelezionata='';
                }
            else
            {
                
                globalXmlSelezione=getXMLSelezioneSingolo();
                var winPop;
                
                winPop=getDocumentPopup('analisi_spaziale');            
                
                if(winPop.getElementById('buffer'))
                    gloBufferRaggio=winPop.getElementById('buffer').value;
                else
                    gloBufferRaggio=1;           

                //i.redraw();  
                //alert(GetCoordinateByCampiById(ActiveLayerIndex,CampoFeatureSelezionata,IDFeatureSelezionata));
                globalCoordinateSelezione=GetCoordinateByCampiById(ActiveLayerIndex,CampoFeatureSelezionata,IDFeatureSelezionata);
                DisegnaBufferPoligono(globalCoordinateSelezione,gloBufferRaggio);
                
                winPop.getElementById('boxBottoneAnalisi').style.display="";
                winPop.getElementById('btnEseguiAnalisi').setAttribute('onClick',"parent.doIdentifyGeometria('"+globalCoordinateSelezione+"','-1','"+gloBufferRaggio+"');");
                //per IE
                winPop.getElementById('btnEseguiAnalisi').onclick=new Function( "parent.doIdentifyGeometria('"+globalCoordinateSelezione+"','-1','"+gloBufferRaggio+"');");
                i.redraw();
            }
        }
    
        if ( i.action() == 'disegna' ) { i.addVertice(x - DL_GetElementLeft(_tagMain),y - DL_GetElementTop(_tagMain)); }
    
        if ( i.action() == 'select' )
        {
          _Xselect = x - DL_GetElementLeft(_tagMain);  //xxx
          _Yselect = y - DL_GetElementTop(_tagMain);   //xxx  
          //MCS alert((_ext_Xmin-i.wPixel2real(_Xselect))+'-----'+(_ext_Ymin-i.hPixel2real(_Yselect)));
          //MCS i.redraw();
          //alert(i.hPixel2real(_Yselect));
           doIdentifyPunto((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex);
        }
        //MCS
        if ( i.action() == 'selecttooltipbox' )
        {
       
            //alert('tooltip');
            _Xselect = x - DL_GetElementLeft(_tagMain);  //xxx
            _Yselect = y - DL_GetElementTop(_tagMain);   //xxx  
            i.selecttooltipExtent();
            //alert(getTooltip((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)));
            //i.addPunto((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),Date());
            //getSingleTooltip((_ext_Xmin+i.wPixel2real(_Xselect)),(_ext_Ymax-i.hPixel2real(_Yselect)),ActiveLayerIndex);
        
            _tagSelectZoombox.style.display = 'none';
    
        }  
        
        if ( i.action() == 'tick' )
        {
            _Xselect = x - DL_GetElementLeft(_tagMain);  //xxx
            _Yselect = y - DL_GetElementTop(_tagMain);   //xxx  
            
            X = _ext_Xmin+i.wPixel2real(_Xselect);
            Y = _ext_Ymax-i.hPixel2real(_Yselect);

		   if(preleva == 1)
    			SettaCoordinateDB(X,Y);       
        }  
        
        if (i.action() == 'percorsiidentify'){
    
			var coord_tmp;
		
			 _tagZoombox.style.display = 'none';
			 
			goPopup(); 
				
			if(_zoombox_x_first > _zoombox_x_last) {
				coord_tmp = _zoombox_x_first;
				_zoombox_x_first = _zoombox_x_last;
				_zoombox_x_last = coord_tmp;
			}
			if(_zoombox_y_first < _zoombox_y_last) {
				coord_tmp = _zoombox_y_first;
				_zoombox_y_first = _zoombox_y_last;
				_zoombox_y_last = coord_tmp;
			}			
            
            Xmin = _ext_Xmin+i.wPixel2real(_zoombox_x_first);
            Ymin = _ext_Ymax-i.hPixel2real(_zoombox_y_first);
            Xmax = _ext_Xmin+i.wPixel2real(_zoombox_x_last);
            Ymax = _ext_Ymax-i.hPixel2real(_zoombox_y_last);

			var viewpoints;
			viewpoints = getViewpoints(guidSession,Xmin,Xmax,Ymin,Ymax,"","SI");
			
			window.open('percorsi_identify.asp?IdSession='+ guidSession +'&Xmin='+ Xmin +'&Xmax=' + Xmax +'&Ymin=' + Ymin +'&Ymax=' + Ymax,'winIdentify','toolbar=no,directiores=no,resizable=yes,scrollbars=yes,top=600,left=1000,width=600,height=500');
	    
		}

    }
    
    if (browser.isNS)
    { event.preventDefault(); } else
    {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }    
  }

  // WFS protocol
  //this.loadPointsOverlay = function(p_name, p_icon, p_mapfile, p_infoSkin)
  this.loadPointsOverlayWFS = function(p_serv, p_name, p_icon, p_infoSkin)
  {
    i.show_loading_image(true);  // Show "loading" image

    var _infoicon = p_infoSkin;
    if (_infoicon == null)
    {
     // Create a default Info-window icon object...
      _infoicon = new msInfoSkin(GLOPubblicatiComuni + '/images/box/angolo_a.png',GLOPubblicatiComuni + '/images/box/angolo_b.png',
            GLOPubblicatiComuni + '/images/box/angolo_c.png',GLOPubblicatiComuni +  '/images/box/angolo_d.png',
            GLOPubblicatiComuni + '/images/box/report_t.png',GLOPubblicatiComuni + '/images/box/report_d.png',
            GLOPubblicatiComuni + '/images/box/report_l.png',GLOPubblicatiComuni + '/images/box/report_r.png',
            GLOPubblicatiComuni + '/images/box/report_x.png',GLOPubblicatiComuni + '/images/box/close.png',
            GLOPubblicatiComuni + '/images/box/report_arrow.png');     
     }
    http_request = false;
    if (window.XMLHttpRequest) // Mozilla, Safari,...
    {
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType)
      {
        http_request.overrideMimeType('text/xml');
        // See note below about this line
      }
    } else if (window.ActiveXObject) // IE
    {
      try
      {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e)
      {
        try
        {
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
    }
    if (!http_request)
    {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
    }
    http_request.onreadystatechange = function()
    {
      if (http_request.readyState == 4)
      {
        if (http_request.status == 200)
        {
          var xml = http_request.responseXML;
          var mydata = parsePointsFromGML(xml);
          i.setOverlayPoints(mydata, p_icon, _infoicon);
        } else
        { alert('There was a problem with the request.'); }
      }
    }
    //if ( p_mapfile == null ) { p_mapfile = _map_file }
    //var url = _cgi +'?map='+ p_mapfile +
    //          '&SERVICE=WFS&VERSION=1.0.0&REQUEST=getfeature&TYPENAME='+
    //           p_name;
    var url = p_serv +
              '?SERVICE=WFS&VERSION=1.0.0&REQUEST=getfeature&TYPENAME='+
              p_name;
    http_request.open('GET', url, true);
    http_request.send(null);

    // Hide "loading" image when map is loaded
    i.show_loading_image(false);
  }

  this.setOverlayPoints = function(p, p_icon, p_infoSkin)
  {
    for(var j=0; j<p[0].length; j++)
    {
      var myPoint = new pointOverlay( p_icon, p_infoSkin, 'Info', p[0][j], p[1][j], p[2][j], p[3][j] );
      myPoint.setMap(i);
      _pointsOverlayArray.push( myPoint );
    }

    // Z sorting array...
    _pointsOverlayArray.sort(
      function(a,b){if (a.getY()>b.getY()){return -1;}else{return 1;}}
    );

    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _tagPoints.appendChild( _pointsOverlayArray[j].getShd() ); }
    // Non sono nello stesso ciclo perche` Explorer li sovrappone in base
    // all'ordine dell'appendChild anziche` dello z-index. Cosi` le ombre
    // si sovrapponevano alle icone.
    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _tagPoints.appendChild( _pointsOverlayArray[j].getImg() ); }

    // Redraw...
    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _pointsOverlayArray[j].redraw(); }
  }
  
  // Luca - Viewpoint
  this.addViewPoints = function(p_x,p_y,nome,valore,img,color)
  {
    
    var _infoicon;
    if (_infoicon == null)
    {
      _infoicon = new msInfoSkin(GLOPubblicatiComuni + '/images/box/angolo_a.png',GLOPubblicatiComuni + '/images/box/angolo_b.png',
								 GLOPubblicatiComuni + '/images/box/angolo_c.png',GLOPubblicatiComuni + '/images/box/angolo_d.png',
								 
								 GLOPubblicatiComuni + '/images/box/report_t.png',GLOPubblicatiComuni + '/images/box/report_d.png',
								 GLOPubblicatiComuni + '/images/box/report_l.png',GLOPubblicatiComuni + '/images/box/report_r.png',
								 
								 GLOPubblicatiComuni + '/images/box/report_x.png','',
								 GLOPubblicatiComuni + '/images/box/report_arrow.png');   
    }
    var names = new Array(); 
    var values = new Array();
	
	if(nome != "")
		names.push(nome);
	else 
		names.push(" ");
		
	if (valore != "")
		values.push(valore);
	else
		values.push(" ");
	
	if(img != "") {
		myIcon_img = new msIcon(GLOBase  + img, GLOBase  + img, 0, 0);  
		var myPoint = new pointOverlay( myIcon_img, _infoicon, '', p_x, p_y, names,values);
	}					 
	else
		var myPoint = new pointOverlay( myIcon_red, _infoicon, '', p_x, p_y, names,values);
	
	myPoint.setMap(i);
	_pointsOverlayArray = myPoint;
	_tagPoints.appendChild( _pointsOverlayArray.getShd() );
	_tagPoints.appendChild( _pointsOverlayArray.getImg() );
	_pointsOverlayArray.redraw();
  }

//MCS
  this.addPunto = function(p_x,p_y,nome,valore)
  {
    var _infoicon;
    if (_infoicon == null)
    {
      // Create a default Info-window icon object...
      _infoicon = new msInfoSkin(GLOPubblicatiComuni + '/images/box/angolo_a.png',GLOPubblicatiComuni + '/images/box/angolo_b.png',
            GLOPubblicatiComuni + '/images/box/angolo_c.png',GLOPubblicatiComuni + '/images/box/angolo_d.png',
            GLOPubblicatiComuni + '/images/box/report_t.png',GLOPubblicatiComuni + '/images/box/report_d.png',
            GLOPubblicatiComuni + '/images/box/report_l.png',GLOPubblicatiComuni + '/images/box/report_r.png',
            GLOPubblicatiComuni + '/images/box/report_x.png',GLOPubblicatiComuni + '/images/box/close.png',
            GLOPubblicatiComuni + '/images/box/report_arrow.png');   
    }
    
    var names = new Array(); var values = new Array();

    names.push(nome);
    values.push(valore);
    
    var myPoint = new pointOverlay( myIcon, _infoicon, 'Info', p_x, p_y, names,values);
    myPoint.setMap(i);
    _pointsOverlayArray.push( myPoint );
    
    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _tagPoints.appendChild( _pointsOverlayArray[j].getShd() ); }
    // Non sono nello stesso ciclo perche` Explorer li sovrappone in base
    // all'ordine dell'appendChild anziche` dello z-index. Cosi` le ombre
    // si sovrapponevano alle icone.
    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _tagPoints.appendChild( _pointsOverlayArray[j].getImg() ); }

    // Redraw...
    for(var j=0; j<_pointsOverlayArray.length; j++)
    { _pointsOverlayArray[j].redraw(); }
  }
    // Luca new Vallo
    // immagine presa dal nome della categoria tipo _on _off ?
    // scala presa dal database ?
  this.addPunto2 = function(p_x,p_y,nome,descrizione,selezionato,immagine,scala)
  {
    if (myMap1.GetScala() < scala) {
    
        var _infoicon;
        var tmp = new String();
        var names = new Array(); var values = new Array();
        tmp = descrizione + " " + nome;
        names.push(tmp);
        values.push("");
                
        
        if (_infoicon == null)
        {
          _infoicon = new msInfoSkin(GLOPubblicatiComuni + '/images/box/angolo_a.png',GLOPubblicatiComuni + '/images/box/angolo_b.png',
                GLOPubblicatiComuni + '/images/box/angolo_c.png',GLOPubblicatiComuni + '/images/box/angolo_d.png',
                GLOPubblicatiComuni + '/images/box/report_t.png',GLOPubblicatiComuni + '/images/box/report_d.png',
                GLOPubblicatiComuni + '/images/box/report_l.png',GLOPubblicatiComuni + '/images/box/report_r.png',
                GLOPubblicatiComuni + '/images/box/report_x.png','',
                GLOPubblicatiComuni + '/images/box/report_arrow.png');   
        }
        
        if(selezionato == 0) {
            myIcon = new msIcon(GLOPubblicatiComuni + '/imgmappa/'+ immagine + '_off.gif', '', 1, 2);  
	        var myPoint = new pointOverlay( myIcon, _infoicon, '', p_x, p_y, names,values);
	    }
	    else if(selezionato == 1) {
            myIcon = new msIcon(GLOPubblicatiComuni + '/imgmappa/'+ immagine + '_on.gif', '', 1, 2);  
	        var myPoint = new pointOverlay( myIcon, _infoicon, '', p_x, p_y, names,values);
	    }
    	myPoint.setOffsetX(11);
    	myPoint.setOffsetY(1100);
    	
        myPoint.setMap(i);
	    _pointsOverlayArray = myPoint;
        _tagPoints.appendChild( _pointsOverlayArray.getShd() );
        _tagPoints.appendChild( _pointsOverlayArray.getImg() );
        _pointsOverlayArray.redraw();
    }
  }

    // Luca old Vallo
  this.addPunto = function(p_x,p_y,nome,valore,colore)
  {
    var _infoicon;

    var names = new Array(); var values = new Array();

    names.push(valore + " " + nome );
    values.push("");

    if (_infoicon == null)
    {
      _infoicon = new msInfoSkin(GLOPubblicatiComuni + '/images/box/angolo_a.png',GLOPubblicatiComuni + '/images/box/angolo_b.png',
            GLOPubblicatiComuni + '/images/box/angolo_c.png',GLOPubblicatiComuni + '/images/box/angolo_d.png',
            GLOPubblicatiComuni + '/images/box/report_t.png',GLOPubblicatiComuni + '/images/box/report_d.png',
            GLOPubblicatiComuni + '/images/box/report_l.png',GLOPubblicatiComuni + '/images/box/report_r.png',
            GLOPubblicatiComuni + '/images/box/report_x.png','',
            GLOPubblicatiComuni + '/images/box/report_arrow.png');   
    }
    
    if(colore == 0) {
	    var myPoint = new pointOverlay( myIcon_red, _infoicon, '', p_x, p_y, names,values);
	}
	else if(colore == 1) {
	    var myPoint = new pointOverlay( myIcon_white, _infoicon, '', p_x, p_y, names,values);
	}
	
    myPoint.setMap(i);
	_pointsOverlayArray = myPoint;
    _tagPoints.appendChild( _pointsOverlayArray.getShd() );
    _tagPoints.appendChild( _pointsOverlayArray.getImg() );
    _pointsOverlayArray.redraw();
  }

//MCS
  this.ClearPunti= function()
  {
    //Svuoto l'array dei Punti disegnati per i Tooltip
    _pointsOverlayArray = new Array();
    _tagPoints.innerHTML='';
    
    if (_tagInfo.childNodes.length >0)
    {
        _tagInfo.removeChild( _tagInfo.childNodes[0] );
        i.setReportNull();
    }
    
    if (_drawLayer != null){
    	_drawLayer.setPrintable(false);
	}
    arrXDraw=new Array();
    arrXDrawReal=new Array();
    
    arrYDraw=new Array();
    arrYDrawReal=new Array();
    
//    if(window.self.name == "zyxabc")  {
//        update_ViewBeni();
//    }

    }

 
//MCS

this.getMappaWS = function ()
  {
    
    _done=false;//MCS Devo ridisegnare la mappa
    var imgUrl= getUrlMappaWS((_ext_Xmin-i.wPixel2real(_map_w_bord)),(_ext_Ymin-i.hPixel2real(_map_h_bord)),(_ext_Xmax+i.wPixel2real(_map_w_bord)),(_ext_Ymax+i.hPixel2real(_map_h_bord)),(_map_w+_map_w_bord+_map_w_bord),(_map_h+_map_h_bord+_map_h_bord),_usaScalimetro)



    imgUrl=imgUrl.replace('\r\n',"");
    
    //_tagMap.src=imgUrl;
    //_tagMap_B.src=imgUrl;
    _done=true;//MCS Devo ridisegnare la mappa


    return imgUrl;
  }

this.getMappaWSProxy = function ()
  {
    
    _done=false;//MCS Devo ridisegnare la mappa

    var imgUrl= getUrlMappa((_ext_Xmin-i.wPixel2real(_map_w_bord)),(_ext_Ymin-i.hPixel2real(_map_h_bord)),(_ext_Xmax+i.wPixel2real(_map_w_bord)),(_ext_Ymax+i.hPixel2real(_map_h_bord)),(_map_w+_map_w_bord+_map_w_bord),(_map_h+_map_h_bord+_map_h_bord),_usaScalimetro)

    //alert(imgUrl);
    
    imgUrl=imgUrl.replace('\r\n',"");
    
    //_tagMap.src=imgUrl;
    //_tagMap_B.src=imgUrl;
    _done=true;//MCS Devo ridisegnare la mappa



    return imgUrl;
  }

this.getMappaWS_asincrono = function ()
  {
    
   _http_request=window.frames['protoframe'].GetXmlHttpObject();

   _http_request.onreadystatechange = function()
        {
        if (_http_request.readyState == 4)
          {
            if (_http_request.status == 200)
            {  
                if (! _done)
                {
                    _done=true;
                    var xml = _http_request.responseText;
                 
                    var imgUrl=xml.replace('<string xmlns=\"GDManagerWS\">',"");
                    imgUrl=imgUrl.replace('</string>',"");
                    imgUrl=imgUrl.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>","");
                    
                    // Luca
                    var s = new String();					
					var s_tmp = new String();
					var coords = new String();
					
					s=imgUrl;
					if(s.indexOf("-EXTCORRETTA-") > 0) {
						s_tmp = s.split("-EXTCORRETTA-");
						coords = s_tmp[1].split("-");
						_ext_Xmin = parseInt(coords[0]);
						_ext_Xmax = parseInt(coords[1]);
						_ext_Ymin = parseInt(coords[2]);
						_ext_Ymax = parseInt(coords[3].substring(0,coords[3].length-4));							
                    }
                    //////                    
                   
                    if (gdManagerWrapper == '') 
                    {
                    _tagMap.src=imgUrl;
                    _tagMap_B.src=imgUrl;
                    }
                    else
                    {
                    _tagMap.src=ip+imgUrl;
                    _tagMap_B.src=ip+imgUrl;
                    }
 
					setTimeout("nascondiPopup()", 4000);

                }
			} else
            { 
                alert('There was a problem with the request.'); 
            }
          }
          
        }
        
        
    var size = 'mapsize=' + (_map_w+_map_w_bord+_map_w_bord) + '+'
                          + (_map_h+_map_h_bord+_map_h_bord);
                          
                
    var ext  = 'mapext=' + (_ext_Xmin-i.wPixel2real(_map_w_bord)) + '+'
                         + (_ext_Ymin-i.hPixel2real(_map_h_bord)) + '+'
                         + (_ext_Xmax+i.wPixel2real(_map_w_bord)) + '+'
                         + (_ext_Ymax+i.hPixel2real(_map_h_bord)) ;
    
    var guid='';
    if (_guidSession != '')
        guid=_guidSession;
    else
        guid=guidSession;    
    
    var thisdate=getDataUnivoca();
    gloDataMappa=glogetDataMappa();
    var xmlLayer= getXMLLayerAttivi(guid);
    var xmlSelezione= '';

    xmlSelezione=globalXmlSelezione; //getXMLSelezioneALL();
    
    // Modificata 
	if (gdManagerWrapper == '')
	{
	    var url = gdManagerWS+"FW_DrawProject?TXTListaCOORDSPolTodraw=&GUIDSession="+guid+"&XMIN="+(_ext_Xmin-i.wPixel2real(_map_w_bord))+"&XMAX="+(_ext_Xmax+i.wPixel2real(_map_w_bord))+"&YMIN="+(_ext_Ymin-i.hPixel2real(_map_h_bord))+"&YMAX="+(_ext_Ymax+i.hPixel2real(_map_h_bord))+"&PixelsIMGX="+(_map_w+_map_w_bord+_map_w_bord)+"&PixelsIMGY="+(_map_h+_map_h_bord+_map_h_bord)+"&SCALIMETER="+_usaScalimetro+"&TXTXMLListaIDFeaturesDaSelezionare="+xmlSelezione+"&TXTXMLListaLayers=" +xmlLayer+"&TXTDateRequest="+gloDataMappa+"dataora="+thisdate;
	}
	else
	{
		var url = gdManagerWrapper+"?opcode=FW_DrawProject&TXTListaCOORDSPolTodraw=&GUIDSession="+guid+"&XMIN="+(_ext_Xmin-i.wPixel2real(_map_w_bord))+"&XMAX="+(_ext_Xmax+i.wPixel2real(_map_w_bord))+"&YMIN="+(_ext_Ymin-i.hPixel2real(_map_h_bord))+"&YMAX="+(_ext_Ymax+i.hPixel2real(_map_h_bord))+"&PixelsIMGX="+(_map_w+_map_w_bord+_map_w_bord)+"&PixelsIMGY="+(_map_h+_map_h_bord+_map_h_bord)+"&SCALIMETER="+_usaScalimetro+"&TXTXMLListaIDFeaturesDaSelezionare="+xmlSelezione+"&TXTXMLListaLayers=" +xmlLayer+"&TXTDateRequest="+gloDataMappa+"dataora="+thisdate;	
	}
    
    _done=false;//MCS Devo ridisegnare la mappa
    _http_request.open('GET', url, true);
    _http_request.send(null);
    return '';
  }
  
  
  i.init();
}

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Determining Element Page Coordinates, Part 4:
// http://www.webreference.com/dhtml/diner/realpos4/9.html

function DL_GetElementLeft(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)                             // if browser is IE, then...
      {
         if( (eParElement.tagName != "TABLE") && (eParElement.tagName != "BODY") )
         {                                   // if parent is not a table or the body, then...
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }
      else                                   // if browser is Gecko, then...
      {
         if(eParElement.tagName == "TABLE")  // if parent is a table, then...
         {                                   // get its border as a number
            var nParBorder = parseInt(eParElement.border);
            if(isNaN(nParBorder))            // if no valid border attribute, then...
            {                                // check the table's frame attribute
               var nParFrame = eParElement.getAttribute('frame');
               if(nParFrame != null)         // if frame has ANY value, then...
               {
                  nLeftPos += 1;             // append one pixel to counter
               }
            }
            else if(nParBorder > 0)          // if a border width is specified, then...
            {
               nLeftPos += nParBorder;       // append the border width to counter
            }
         }
         // sm 20051010
         if(eParElement.tagName == "DIV")
         {
           var bord = parseInt(eParElement.style.border);
           if ( bord > 0 ) { nLeftPos += bord; }
         }
      }
      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}

function DL_GetElementTop(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE

   var nTopPos = eElement.offsetTop;         // initialize var to store calculations
   var eParElement = eElement.offsetParent;  // identify first offset parent element

   while (eParElement != null)
   {                                         // move up through element hierarchy
      if(DL_bIE)                             // if browser is IE, then...
      {
         if( (eParElement.tagName != "TABLE") && (eParElement.tagName != "BODY") )
         {                                   // if parent a table cell, then...
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }
      else                                   // if browser is Gecko, then...
      {
         if(eParElement.tagName == "TABLE")  // if parent is a table, then...
         {                                   // get its border as a number
            var nParBorder = parseInt(eParElement.border);
            if(isNaN(nParBorder))            // if no valid border attribute, then...
            {                                // check the table's frame attribute
               var nParFrame = eParElement.getAttribute('frame');
               if(nParFrame != null)         // if frame has ANY value, then...
               {
                  nTopPos += 1;              // append one pixel to counter
               }
            }
            else if(nParBorder > 0)          // if a border width is specified, then...
            {
               nTopPos += nParBorder;        // append the border width to counter
            }
         }
         // sm 20051010
         if(eParElement.tagName == "DIV")
         {
           var bord = parseInt(eParElement.style.border);
           if ( bord > 0 ) { nTopPos += bord; }
         }
      }
      nTopPos += eParElement.offsetTop;      // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                           // return the number calculated
}

// Determine browser and version.
function Browser()
{
  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.isOP    = false;
  this.name    = navigator.appName;
  this.version = null;
  

  ua = navigator.userAgent;
  //alert(navigator.vendor);

  // Firefox:
  // Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

  // Explorer:
  // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

  // Opera:
  // Mozilla/4.0 (compatibile; MSIE 6.0; Windows NT 5.1; en) Opera 8.50

  if ((navigator.userAgent).indexOf("Opera")!=-1)
  {
    this.isOP = true;
  } else
  if (navigator.appName=="Netscape")
  {
    this.isNS = true;
    //s = "Netscape6/";
    //this.version = parseFloat(ua.substr(i + s.length));
  } else
  if ( (navigator.appName).indexOf("Microsoft") != -1 )
  {
    this.isIE = true;
    //s = "MSIE";
    //this.version = parseFloat(ua.substr(i + s.length));
  }

  return;
}

function min(a, b) { if ( a < b ) { return a; } else { return b; } }
function max(a, b) { if ( a > b ) { return a; } else { return b; } }

function add_event(obj, event_id, func)
{
  if (obj.addEventListener)
  {
    obj.addEventListener( event_id, func, false )
  } else if(obj.attachEvent)
  {
    event_id = 'on'+event_id;
    obj.attachEvent( event_id, func )
  } else
  { obj[event_id] = func; }
}



// Non e` molto elegante come soluzione... ma sembra funzionare...
function ChiamaEvento(e)
{
  var i;
  if (e.srcElement) {i = e.srcElement.objRef}
  if (e.target)     {i = e.target.objRef}
  i.dragStart(e);
}

// Non e` molto elegante come soluzione... ma sembra funzionare...
function ChiamaEventoMove(event)
{
  //var i;
  //if (e.srcElement) {i = e.srcElement.objRef}
  //if (e.target)     {i = e.target.objRef}
    var el;
    var x, y;
    var xx,yy;

    nascondiToolTip();

    // Get cursor position with respect to the page.
    if ( browser.isNS )
    {
      x = event.clientX + window.scrollX;
      y = event.clientY + window.scrollY;
    } else
    {
      x = window.event.clientX + document.documentElement.scrollLeft
        + document.body.scrollLeft;
      y = window.event.clientY + document.documentElement.scrollTop
        + document.body.scrollTop;
    } 
    
    xx = parseInt(myMap1.getXmin()+myMap1.wPixel2real(x - DL_GetElementLeft(document.getElementById('mappa'))));
    yy = parseInt(myMap1.getYmax()-myMap1.hPixel2real(y - DL_GetElementTop(document.getElementById('mappa'))));    
    
    if (document.getElementById('txtXY'))
        document.getElementById('txtXY').innerHTML=xx+'&nbsp;&nbsp;&nbsp;'+yy;
   
    //Luca
    if (document.getElementById('txtX')) 
        document.getElementById('txtX').value = xx;
    if (document.getElementById('txtY')) 
        document.getElementById('txtY').value = yy;
    if (document.getElementById('minmax')) 
        document.getElementById('minmax').value = "Xmin: " + myMap1.getXmin() + " - Xmax: " + myMap1.getXmax() +" - Ymin: " + myMap1.getYmin() + " - Ymax: " + myMap1.getYmax();
    
    if ( (myMap1.action() == 'misuraSegmento') ||  (myMap1.action() == 'bufferSegmento') ){
    
        myMap1.disegnaUltimoSegmento(x - DL_GetElementLeft(document.getElementById('mappa')),y - DL_GetElementTop(document.getElementById('mappa')));
    }    
    
    /*
    if (_x_time0 != xx) || (_y_time0 != yy)
    {
        time0=0;
        _x_time0=xx;
        _y_time0=yy;
    }
    else
    {
        
    }
    */
    
    //if ( (myMap1.action() == 'selecttooltip') || (myMap1.action() == "selecttooltipbox") ){
        gloXTooltip=xx;
        gloYTooltip=yy;
        //setTimeout("getSingleTooltipTimer();",500);
        //getSingleTooltip(xx,yy,ActiveLayerIndex);    
    //}
    
}
// Luca
function setPos(p_obj, p_x, p_y)
{
  p_obj.style.left    = p_x+'px';
  p_obj.style.top     = p_y+'px';
  p_obj.style.display = '';
}





// pointOverlay class prototype
function pointOverlay( p_icon, p_infoSkin, p_title, p_x, p_y, p_item_name, p_item_value )
{
  var _msMap = null;
  var _img   = null;	//document.createElement('img');
  var _shd   = null;	//document.createElement('img');
  var _x     = parseFloat(p_x);	// Real coord X
  var _y     = parseFloat(p_y);	// Real coord Y
  var _title = p_title;
  var _icon  = p_icon;
  var _infoSkin = p_infoSkin;
  var _item_name = p_item_name; var _item_value = p_item_value;
  var _offsetX = 0;  var _offsetY = 0;
  var _offsetXSimbolo = 5;  var _offsetYSimbolo = -28; //MCS
  


  if (_title == null) { _title = 'Info'; }

  // Functions...
  this.setMap = function(m) { _msMap = m; }
  this.getMap = function()  { return _msMap; }
  this.getImg = function()  { return _img; }
  this.getShd = function()  { return _shd; }
  this.getX   = function()  { return _x; }
  this.getY   = function()  { return _y; }
  this.getHtmlAttributes = function()
  {
    var ret = "<table>";
    for (var j=0; j<_item_name.length; j++)
    {
      // css
      ret += "<tr><td class=\"mscross_report_attr_name\">"+ _item_name[j] +
             "</td><td class=\"mscross_report_attr_value\" "+
             "style='padding-left: 8px;'>"+ _item_value[j] +"</td></tr>";
    }
    ret += "</table>";
    return ret;
  }
  this.getInfoX = function() { return _msMap.xReal2pixel(_x); }
  this.getInfoY = function() { return Math.round(_msMap.yReal2pixel(_y) - (parseInt(_img.offsetHeight)/2) ); }
  
  //Luca
  this.setOffsetX = function(offX) { _offsetX = offX; }
  this.setOffsetY = function(offY) { _offsetY = offY; }  
/*
  this.redraw = function()
  {  

    // se e` visibile (coordinate del punto interne al box della mappa)...
    if ( _msMap.isPointInMap( _x - _msMap.wPixel2real(_offsetX),
                              _y + _msMap.hPixel2real(_offsetY),
                              _msMap.wPixel2real(_offsetX),
                              _msMap.hPixel2real(_offsetY) ) )
    {
       setPos(_img, _msMap.xReal2pixel(_x) - _offsetX -_offsetXSimbolo,
                   _msMap.yReal2pixel(_y) - _offsetY -_offsetYSimbolo);
      setPos(_shd, _msMap.xReal2pixel(_x) - _offsetX -_offsetXSimbolo,
                   _msMap.yReal2pixel(_y) - _offsetY -_offsetYSimbolo);
    } else
    { this.setVisible(false); }
  }
*/
//Luca
  this.redraw = function()
  {  
	
    // se e` visibile (coordinate del punto interne al box della mappa)...
    if ( _msMap.isPointInMap( _x ,_y ,_msMap.wPixel2real(_offsetX),_msMap.hPixel2real(_offsetY) ) )
    {
      setPos(_img, _msMap.xReal2pixel(_x) - _offsetX,_msMap.yReal2pixel(_y)) - _offsetX;
      setPos(_shd, _msMap.xReal2pixel(_x) + _offsetX, _msMap.yReal2pixel(_y) + _offsetX);
    } else
    { this.setVisible(false); }
  }

  this.getInfoSkin = function()
  {
    return _infoSkin;
  }

  this.setVisible = function(p_bool)
  {
    var str = null;
    if (p_bool) {str = '';} else {str = 'none';}
    _img.style.display = str;
    _shd.style.display = str;
  }

  this.getWidth  = function() { return parseInt(_img.style.width); }
  this.getHeight = function() { return parseInt(_img.style.height); }
  this.showReport = function()
  {
    var pnt = new msReport(this, _title);
    _msMap.setReport(pnt);
  }

  // Initialization...
  _img = _icon.getImage(); _shd = _icon.getShadow();
  _offsetX = _icon.getShiftX() -1;
  _offsetY = _icon.getShiftY() -1;
//////////////////////////////////////////////////////////////////
// xxx Etichetta del punto, visualizzata al passaggio del mouse...
//  if (p_title != null) { _img.title = p_title; }
//////////////////////////////////////////////////////////////////
  _img.objRef = this;
  //Luca - Aggiunte x Vallo
  if(window.self.name == 'zyxabc') {
	add_event(_img, 'click', function(event){   _msMap.zoomExtent( _x-100,_y-100,_x+100,_y+100,5000 ); 
												// Luca Nuove Aggiunte per Vallo
												var id = new Array(2);
												if(parent.frames['toponimi'].frames['lista'].name = 'lista') {
												    id = parent.frames['toponimi'].frames['lista'].cerca_id(_x,_y);
												    if(id[1]!= "") {
												        if(parent.frames['toponimi'].frames['lista'].categoria_list_js = "Beni Culturali") {
												            window.open(parent.frames['toponimi'].frames['lista'].link_list_js[id[1]],'Descrizione','toolbar=no,directiores=no,resizable=yes,scrollbars=yes,top=300,left=350,width=800,height=600');
												             _msMap.addPunto2(_x,_y,_item_name,'',0,parent.frames['toponimi'].frames['lista'].categoria_list_js[i],'50000'); 
												        }
												        else {
												            parent.frames['toponimi'].frames['lista'].change_bgc(id);
												            parent.frames['zyxabc'].OnOffLayer('foto');
											                if(parent.parent.frames['descrizione'].name = 'descrizione') 												  	
									  			                parent.parent.frames['descrizione'].location = "viewpoint_descrizione.asp?id="+id[0]+"&lingua=IT&campi="+parent.frames['toponimi'].frames['lista'].document.getElementById('campi'+id[0]).innerHTML;
									  		                if(parent.parent.frames['descrizione_foto'].name = 'descrizione_foto')
									  			                parent.parent.frames['descrizione_foto'].location = "viewpoint_descrizione_foto.asp?id="+id[0]
										                    _msMap.addPunto(_x,_y,_item_name,'',0 ); 
										                }
										            }
										            else
										                alert("Esercizio non trovato");		
										        }										
												});
  }
  //Luca - Aggiunte x Asti
  else if(window.self.name == 'Turismo Asti') {
	add_event(_img, 'click', function(event){   var id = 00000;
												_msMap.ClearPunti();	
												_msMap.zoomExtent( _x-100,_y-100,_x+100,_y+100,5000 ); 
												window.self.CaricaViewPoints();
												id = window.self.CercaIdViewpoints(_x,_y);
												window.open(link_list_js[id],'Descrizione','toolbar=no,directiores=no,resizable=yes,scrollbars=yes,top=300,left=350,width=500,height=500');
												}
												);
  }
 
  add_event(_img, 'mouseover', function(event){  		pointOverlayEvent(event);
														old_coordX = _x;
														old_coordY = _y;
													});		// Creazione della nuvoletta
  
  add_event(_img, 'mouseout',  function(event){		var taginfo =_msMap.getInfoTag(); 
													taginfo.removeChild( taginfo.childNodes[0]);
													});	// Cancellazione della nuvoletta
}// Imposta un'immagine PNG con trasparenza
// (risolve il limite di Internet Explorer)
function setAlphaPNG( p_imgTag, p_src )
{
  if ( browser.isIE )
  {
    //p_imgTag.src = '/img/pixel.gif';
    p_imgTag.src = pixel_img.src;
    p_imgTag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader"+
                            "(src='"+p_src+"',sizingMethod='image')";
      //# "image": Keep the original size of the image.
      //# "scale": Stretch or compress the image to the container boundaries.
      //# "crop": Crop the image to the container dimensions.
/*
    // Trucco per ricavare le dimensioni dell'immagine...
    // Tanto l'immagine p_src dovrebbe essere caricata solo una volta.
    var tmp = new Image();
    tmp.onload=function()
    {
      p_imgTag.style.width  = tmp.width+'px';
      p_imgTag.style.height = tmp.height+'px';
    }
    tmp.src = p_src;
*/
  } else
  {
    p_imgTag.src = p_src;
  }
}



function setAlphaBackgroundPNG( p_Tag, p_src )
{
  if ( browser.isIE )
  {
    p_Tag.style.backgroundImage = 'none';
    p_Tag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader"+
                         "(src='"+p_src+"',sizingMethod='scale')";
  } else
  {
    p_Tag.style.backgroundImage = "url('"+p_src+"')";
  }
}



function setZindex(p_tag, p)
{
  if (p_tag.setAttribute)
  { p_tag.setAttribute('style', 'z-index:'+p+';'); } else
  { p_tag.style.zIndex = p; }
}



function msInfoSkin( p_corner_a, p_corner_b, p_corner_c, p_corner_d,
                     p_top, p_bottom, p_left, p_right,
                     p_fill, p_close, p_arrow)
{
  var _corner_a = new Image(); _corner_a.src = p_corner_a;
  var _corner_b = new Image(); _corner_b.src = p_corner_b;
  var _corner_c = new Image(); _corner_c.src = p_corner_c;
  var _corner_d = new Image(); _corner_d.src = p_corner_d;

  var _bord_top    = new Image(); _bord_top.src = p_top;
  var _bord_bottom = new Image(); _bord_bottom.src = p_bottom;
  var _bord_left   = new Image(); _bord_left.src = p_left;
  var _bord_right  = new Image(); _bord_right.src = p_right;

  var _fill  = new Image(); _fill.src = p_fill;
  var _close = new Image(); _close.src = p_close;
  var _arrow = new Image(); _arrow.src = p_arrow;

  this.getCornerA = function() { return _corner_a.src; }
  this.getCornerB = function() { return _corner_b.src; }
  this.getCornerC = function() { return _corner_c.src; }
  this.getCornerD = function() { return _corner_d.src; }
  this.getFill = function() { return _fill.src; }
  this.getLeft = function() { return _bord_left.src; }
  this.getRight = function() { return _bord_right.src; }
  this.getTop = function() { return _bord_top.src; }
  this.getBottom = function() { return _bord_bottom.src; }

this.getClose = function() { return _close.src; }
this.getArrow = function() { return _arrow.src; }
}



// msIcon class prototype
function msIcon( p_img, p_shd, p_offsetX, p_offsetY )
{
  var _img_name = p_img;
  var _shd_name = p_shd;
  var _offsetX = 1;	// Distanza del target dall'angolo
  var _offsetY = 1;	// alto-sinistra.

  if ( p_offsetX != null ) { _offsetX = p_offsetX; }
  if ( p_offsetY != null ) { _offsetY = p_offsetY; }

  if ( p_img == null )
  {
    _img_name = GLOPubblicatiComuni + '/images/tooltip/mm_20_red.png'; //MCS
    _shd_name = GLOPubblicatiComuni + '/images/tooltip/mm_20_shadow.png'; //MCS
    _offsetX  = 6; _offsetY = 19;
  }

  this.getShiftX = function() { return _offsetX; }
  this.getShiftY = function() { return _offsetY; }
  this.getImage = function()
  {
    var tmp = document.createElement('img');
    tmp.oncontextmenu  = function(){return false;};
    tmp.onmousedown = function(){return false;};  // Disable drag'n drop
    setZindex(tmp, '110');
    tmp.style.position = 'absolute';
    tmp.style.cursor   = 'pointer';
    setAlphaPNG(tmp, _img_name);
    return tmp;
  }
  this.getShadow = function()
  {
    var tmp = document.createElement('img');
    tmp.oncontextmenu  = function(){return false;};
    tmp.onmousedown = function(){return false;};
    setZindex(tmp, '109');
    tmp.style.position = 'absolute';
    setAlphaPNG(tmp, _shd_name);
    return tmp;
  }
}



// msReport class prototype
function msReport( p_pnt, p_title )
{
  var _pointOverlay = p_pnt;
  var d = document.createElement('div'); p_pnt.getMap().getInfoTag().appendChild(d);
  var _content = document.createElement('div');
  var _scrollX = 16;  // Gli offset devono essere impostati dinamicamente
  var _scrollY = 0;
  var _title = p_title;
  var j = this;
  var _infoSkin = p_pnt.getInfoSkin();

  // Set _content style
  _content.style.paddingTop = '6px';
  _content.style.fontSize = '80%';

  this.redraw = function()
  {
    var h = parseInt(d.offsetHeight);
    var os_x = _scrollX;
    var os_y = _scrollY +h;

    d.style.left = p_pnt.getInfoX() -os_x +'px';
    d.style.top  = p_pnt.getInfoY() -os_y +'px';
  }

  // Chiude la finestra
  this.close = function()
  {
    //d.removeChild( d.childNodes[0] );
    var taginfo = p_pnt.getMap().getInfoTag();
    taginfo.removeChild( taginfo.childNodes[0] );
    p_pnt.getMap().setReportNull();
    delete j;
  }

  // Imposta il contenuto
  this.setContent = function(p_html) { _content.innerHTML = p_html; }

  this.init = function()
  {
    // Main DIV container
    d.oncontextmenu  = function(){return false;};
    d.style.position = 'absolute';

    // External table (borders)
    var t_b  = document.createElement('table');
    t_b.cellSpacing = '0'; t_b.cellPadding = '0';
    var tb_b = document.createElement('tbody'); t_b.appendChild(tb_b);
    var tr_a = document.createElement('tr'); tb_b.appendChild(tr_a);
    var tr_w = document.createElement('tr'); tb_b.appendChild(tr_w);
    var tr_b = document.createElement('tr'); tb_b.appendChild(tr_b);
    var tr_c = document.createElement('tr'); tb_b.appendChild(tr_c);
    var tr_d = document.createElement('tr'); tb_b.appendChild(tr_d);

    var td_a1 = document.createElement('td'); tr_a.appendChild(td_a1);
    var td_a2 = document.createElement('td'); tr_a.appendChild(td_a2);
    var td_a3 = document.createElement('td'); tr_a.appendChild(td_a3);

    // Close button
    var td_w1 = document.createElement('td'); tr_w.appendChild(td_w1);
    var td_w2 = document.createElement('td'); tr_w.appendChild(td_w2);
    var td_w3 = document.createElement('td'); tr_w.appendChild(td_w3);

    var td_b1 = document.createElement('td'); tr_b.appendChild(td_b1);
    var td_b2 = document.createElement('td'); tr_b.appendChild(td_b2);
    var td_b3 = document.createElement('td'); tr_b.appendChild(td_b3);

    var td_c1 = document.createElement('td'); tr_c.appendChild(td_c1);
    var td_c2 = document.createElement('td'); tr_c.appendChild(td_c2);
    var td_c3 = document.createElement('td'); tr_c.appendChild(td_c3);

    var td_d1 = document.createElement('td'); tr_d.appendChild(td_d1);
    var td_d2 = document.createElement('td'); tr_d.appendChild(td_d2);
    var td_d3 = document.createElement('td'); tr_d.appendChild(td_d3);

    var ang_a = document.createElement('img'); setAlphaPNG(ang_a, _infoSkin.getCornerA());
    ang_a.onmousedown = function(){return false;};
    var ang_b = document.createElement('img'); setAlphaPNG(ang_b, _infoSkin.getCornerB());
    ang_b.onmousedown = function(){return false;};
    var ang_c = document.createElement('img'); setAlphaPNG(ang_c, _infoSkin.getCornerC());
    ang_c.onmousedown = function(){return false;};
    var ang_d = document.createElement('img'); setAlphaPNG(ang_d, _infoSkin.getCornerD());
    ang_d.onmousedown = function(){return false;};
    var arrow = document.createElement('img'); setAlphaPNG(arrow, _infoSkin.getArrow());
    arrow.onmousedown = function(){return false;};

    td_a1.appendChild(ang_a); td_a3.appendChild(ang_b);
    td_c1.appendChild(ang_d); td_c3.appendChild(ang_c);
    td_d2.appendChild(arrow);
    td_b2.appendChild(_content);

    setAlphaBackgroundPNG(td_b2, _infoSkin.getFill());
    setAlphaBackgroundPNG(td_b1, _infoSkin.getLeft());
    setAlphaBackgroundPNG(td_b3, _infoSkin.getRight());
    setAlphaBackgroundPNG(td_a2, _infoSkin.getTop());
    setAlphaBackgroundPNG(td_c2, _infoSkin.getBottom());
    setAlphaBackgroundPNG(td_w1, _infoSkin.getLeft());
    setAlphaBackgroundPNG(td_w2, _infoSkin.getFill());
    setAlphaBackgroundPNG(td_w3, _infoSkin.getRight());

    var close = document.createElement('img'); setAlphaPNG(close, _infoSkin.getClose());
    add_event(close, 'click', function(){ j.close(); } );

    // Info window Title
    var tt = document.createElement('table'); tt.style.width = "100%";
    var tt_b = document.createElement('tbody'); tt.appendChild(tt_b);
    var tt_tr = document.createElement('tr'); tt_b.appendChild(tt_tr);
    var tt_td1 = document.createElement('td'); tt_tr.appendChild(tt_td1);
    var tt_td2 = document.createElement('td'); tt_tr.appendChild(tt_td2);
    var title = document.createTextNode(_title);

    tt_td1.className = 'mscross_report_title';  // css

    tt_td1.style.fontWeight = 'bold'; tt.cellSpacing = '0'; tt.cellPadding = '0';
    tt_td1.style.borderBottom = '1px dashed #d0d0d0';
    tt_td1.appendChild(title); tt_td2.appendChild(close);
    tt_td2.style.textAlign = 'right';
    td_w2.appendChild(tt);

    d.appendChild(t_b);

// BUG Firefox 1.0.7 ??? ////////
    if (browser.isNS)
    {
      d.style.display = 'table';
//      t.style.display = 'table-cell';
      //d.style.setProperty("-moz-box-align", "stretch", "");
      //d.style.setProperty("-moz-box-sizing", "padding-box", "");
      // -moz-box-align stretch
      // -moz-box-sizing
    }
/////////////////////////////////
  }

  this.init();
  this.setContent( p_pnt.getHtmlAttributes() );
  this.redraw();
}



function pointOverlayEvent(e)
{
  var p;
  if (e.srcElement) { p = e.srcElement.objRef; }
  if (e.target)     { p = e.target.objRef; }
	pnt = new msReport(p,"");
    //pnt.showReport();
}

// .......................................

function parsePointsFromGML(myxml)
{
  var _coords = null;
  var _name = null;
  var prefix = "";
  var featureMember_Name = "featureMember";
  var msGeometry_Name    = "msGeometry";
  var Point_Name         = "Point";
  var _add               = 0; // Mozilla utilizza gli indici di "childNodes" + 1.
  var _molt              = 1; // Mozilla moltiplica per 2

  if (window.XMLHttpRequest)  // Mozilla, Safari,...
  {
    _add  = 1;
    _molt = 2;
  } else 
  if (window.ActiveXObject)   // IE
  {
    featureMember_Name = "gml:"+featureMember_Name;
    msGeometry_Name    = "myns:"+msGeometry_Name;
    Point_Name         = "gml:"+Point_Name;
  }

  var _data = new Array();
  _data[0] = new Array();	// X
  _data[1] = new Array();	// Y
  _data[2] = new Array();	// Name
  _data[3] = new Array();	// Value

  // For each point in GML file...
  var count = myxml.getElementsByTagName(featureMember_Name).length;
  for(var i=0; i<count; i++)
  {
    _coords = myxml.getElementsByTagName(featureMember_Name)[i].
                    getElementsByTagName(msGeometry_Name)[0].
                    childNodes[0+_add].
                    childNodes[0+_add].childNodes[0].nodeValue;
    var tmp = new Array(); tmp = _coords.split(',');
    var names = new Array(); var values = new Array();

    // Per ogni attributo alfanumerico...
    var size = (myxml.getElementsByTagName(featureMember_Name)[3].
               childNodes[0+_add].childNodes.length - _add) / _molt;

    for (var j=2; j<size; j++)
    {
      nam = myxml.getElementsByTagName(featureMember_Name)[i].
                  childNodes[0+_add].childNodes[(j * _molt) +_add].tagName;
      var nam = nam.split(":");

      val = myxml.getElementsByTagName(featureMember_Name)[i].
                 childNodes[0+_add].childNodes[(j * _molt) +_add].
                 childNodes[0].nodeValue;

      names.push(nam[1]);
      values.push(val);
    }
/////////////////////////////////////

    _data[0][i] = tmp[0];	// X
    _data[1][i] = tmp[1];	// Y

    _data[2][i] = names;	// Attributes Name
    _data[3][i] = values;	// and Values
  }

  return _data;
}

