
function ProvinceSelected()
{                                    		     //alert("Submit in ProvinceSelected");
    if (document.forms[0].ViewRegion.selectedIndex != 0 &&
        document.forms[0].ViewRegion.selectedIndex !=1)
        document.forms[0].submit();
}
function MapSizeSelected(rismappa)
{
  /*  if (document.myform.MapSize.selectedIndex != 0 &&
    document.myform.MapSize.selectedIndex !=1) {
    
    //alert(document.myform.MapSize.value);
    document.forms[0].submit(); */

/*    if (document.myform["MapSize"].selectedIndex != 0 &&
    document.myform["MapSize"].selectedIndex !=1) {

    //alert(document.myform["MapSize"].value);
    document.forms[0].submit();

    } */

/*    alert("In MapSizeSelected");
    alert("Id servizi "+document.getElementById('servizi'));
    alert("myform MapSize sI "+document.myform["MapSize"].selectedIndex);
    alert("rismappa sI "+rismappa.selectedIndex);
    alert("self sI "+this.selectedIndex);
    alert("e( myform servizi MapSize sI ) "+eval('document.myform["servizi"].MapSize.selectedIndex'));
    alert(eval('document.servizi["MapSize"].selectedIndex'));
    alert(eval(document.getElementById('servizi').MapSize.selectedIndex));

    if (document.getElementById("servizi").MapSize.selectedIndex != 0 &&
        document.getElementById("servizi").MapSize.selectedIndex !=1) {

    //\\// document.getElementById("servizi").MapSize

    alert(document.getElementById("servizi").MapSize.value);
    
    document.forms[0].submit();

    } */
    
   if (rismappa.selectedIndex != 0 &&
       rismappa.selectedIndex !=1)    {

    //\\// rismappa

    //alert(rismappa.value);
                           		     //alert("Submit in MapSizeSelected");
    document.forms[0].submit();

    }
}

/*function VisualizzaGid(gid)
{
  //alert('punto 1');
  document.myform["gid"].value=gid;
  //alert('punto mezzo');
  document.myform.submit();
  //alert('punto dopo');
}*/
function VisualizzaGid(layer,gid)
{
  document.myform["layer"].value=layer;
  document.myform["gid"].value=gid;
    		     //alert("Submit in VisualizzaGid");
  document.myform.submit();
}
function InviaDatiMaptip()
{
   loadmap();
   document.myform.target="";
	document.myform.send_cmd.value="ok";
	  //alert("Submit in InviaDatiMaptip");
   document.myform.submit();
}
function ChiudiFinMaptip()
{
  document.getElementById('dati_maptips').style.visibility='hidden';
}


   // Decide browser version

//< s c  ript type="text/javascript"> < ! - -
var i_geckoproduct;
var v_geckoproduct;
var i_geckovendor;
var v_geckovendor;
var i_geckomozilla;
var v_geckomozilla;
var i_geckokmeleon;
var v_geckokmeleon;
if (typeof(navigator.product) != "undefined" && navigator.product && navigator.product == "Gecko") {
	i_geckoproduct = true;
	v_geckoproduct = navigator.product + " " + navigator.productSub;
}
if (typeof(navigator.vendor) != "undefined" && navigator.vendor) {
	i_geckovendor = true;
	v_geckovendor = navigator.vendorSub;
}
if (i_geckoproduct) {
  if (typeof(navigator.vendor) != "undefined" && navigator.vendor == "") {
	i_geckomozilla = true;
	var rv = navigator.userAgent.match(/rv:([\w.]+)/);
	if (rv) {
		rv = rv[0];
		v_geckomozilla = rv.substr(3);
	}
  }
}
var na = navigator.userAgent;
if (na.indexOf("K-Meleon")+1) {
	i_geckokmeleon = 1;
	rv = na.match(/K-Meleon ([\w.]+)/);
	if (rv) {
		v = rv[0];
		v_geckokmeleon = rv.substr(9);
	}
}
// - - > < / s c r i pt>

      var ns4 = (document.layers)? true:false;
      var ns6 = (document.getElementById)? true:false;
      var ie4 = (document.all)? true:false;
      if (ie4) var docRoot = 'document.body';
      var ie5 = false;
    
        var winWidth = document.documentElement.clientHeight;
    
      
      // variabili per aggirare di posizionamento della mappa  dovuto a #bodyContent
      	var dY = -100;
	var dX = 160+10;
      dX=0; //agg per peortae a 0
      dY=0; //+Move
        
      var myCanvasSelect = "myCanvas";

      if (ie4) {
        if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
          if(document.compatMode && document.compatMode == 'CSS1Compat') docRoot = 'document.documentElement';
          ie5 = true;
          myCanvasSelect = "myCanvas-ie5";
        }
        if (ns6) {
          ns6 = false;
        }
      }

//alert("Document Root "+docRoot);

      if (i_geckomozilla) docRoot = 'document.body';
      
      var ie7=false;
      if (navigator.userAgent.indexOf('MSIE 7') > 0) ie7=true;
      if (ie7) docRoot = 'document.body';  // With IE 6 and 7 you should use document.documentElement.scrollTop if document.compatMode != 'BackCompat'. Se no devi usare document.body. ... per IE7 non usare self. docum...


// alert("Document Root post "+docRoot);
// alert("Document CompactMode = "+ document.compatMode);
//      alert('IE7 = '+ie7);
      
// || (navigator.userAgent.indexOf('MSIE 7') > 0)
//alert(" Canvas selezionato = "+myCanvasSelect);

      function init() {
			
			 // set JavaScript name for main window
			 self.name = "main_map_window";

			
        // Default values for mouse events

        MouseMoveDefault = document.onmousemove;
        MouseDownDefault = document.onmousedown;
        MouseUpDefault = document.onmouseup;

        // Capture events



         if (ns4) {
		  
		  document.captureEvents(Event.MOUSEMOVE);
		  document.captureEvents(Event.ONDBLCLICK);
	     }  
          document.onmousemove = mouseMove;
	       document.ondblclick=mouseDblClick;

        // Calculate position of mainmap

        MainMapTop = DL_GetElementTop(document.getElementsByName('mainmap')[0]);
        MainMapLeft = DL_GetElementLeft(document.getElementsByName('mainmap')[0]);
	//alert(MainMapTop+" "+MainMapLeft)
 

	          //+Move
       	//
           document.getElementsByName('mainmap')[0].style.position = 'absolute';
        //s document.getElementsByName('mainmap')[0].style.top = -100+ MainMapTop+"px";
           document.getElementsByName('mainmap')[0].style.top = MainMapTop+"px";
       	//ndocument.getElementsByName('mainmap')[0].style.left = dX+MainMapLeft+"px";
           document.getElementsByName('mainmap')[0].style.left = MainMapLeft+"px";

           //alert(" Dopo = "+DL_GetElementTop(document.getElementsByName('mainmap')[0])+" "+DL_GetElementLeft(document.getElementsByName('mainmap')[0]));
//

        document.getElementById("cursx").style.top = MainMapTop+"px";
        document.getElementById("cursx").style.left = MainMapLeft+"px";
        document.getElementById("cursy").style.top = MainMapTop+"px";
        document.getElementById("cursy").style.left = MainMapLeft+"px";

        //

        document.getElementById(myCanvasSelect).style.top = MainMapTop+"px";
        document.getElementById(myCanvasSelect).style.left = MainMapLeft+"px";

//        document.getElementById("trasparente").style.top = MainMapTop+"px";
//        document.getElementById("trasparente").style.left = MainMapLeft+"px";
//alert(" Dimensioni finestra  t "+MainMapTop+" l "+MainMapLeft);

//var aa=document.getElementById("trasparente").style.top;
//alert("Top "+aa);
//alert("Left "+document.getElementById("trasparente").style.left);

	// Set position for keymapContainer 
/*      document.getElementById("keymapContainer").style.top = MainMapTop;
        document.getElementById("keymapContainer").style.left = MainMapLeft;
	document.getElementById("keymapContainer").style.height = document.myform.keymapxsize.value;
	document.getElementById("keymapContainer").style.width = document.myform.keymapysize.value;
	document.getElementById("keymapContainer").style.visibility ='visible' ;
*/				
        // initialize measurement line
        jg = new jsGraphics(myCanvasSelect);
        jg.setColor("#ff0000");
 
        // shows a loading map be patient image (could be a gif-animation)   
        document.getElementById("loadmap-img").style.top = (MainMapTop + (MainMapHeight / 2) - 16)+"px";
        document.getElementById("loadmap-img").style.left = (MainMapLeft + (MainMapWidth / 2) - 72)+"px";


        //

        textnode = document.createTextNode("");
        document.getElementById("tipp").appendChild(textnode);

        //

        MainMapMovedLeft = MainMapLeft;
        MainMapMovedTop = MainMapTop;
	
//	keymapInit();
        }

function calcArea(arrX, arrY) {
	//calcolo areacon teorema dei trapezi
	//A=1/2 * "sommatoria da i=0 a N-1" di xi*yi+1-xi+1*yi

	var decNumbers=3;
	var pixel_size_round=Math.round(pixel_size*Math.pow(10,decNumbers))/Math.pow(10,decNumbers);
	var numPoints_tmp= arrX.length;
	//aggiungo la prima coordinata e' udefinied, al suo aposto metto l'ultima per chiudere il poligono
	arrX[0] = arrX[numPoints_tmp - 1];
	arrY[0] = arrY[numPoints_tmp - 1];
	var numPoints = arrX.length;
	
        if (numPoints_tmp<3) // se i vertici sono meno di 3 faccio ridisegnare
        {
        alert("Numero vertici = "+numPoints_tmp+"\n Sono neccessari almeno 3\n vertici per disegnare il poligono!");
        } else {  //altrimenti chiedo se quanto disegnato ï¿½ok
		
		geoCoordX = new Array();
		geoCoordY = new Array();
		
		for (i=0; i<numPoints; i++) {
		   
		   var coordX=arrX[i];
		   var coordY=sc_height-arrY[i]; //sposto origine da top left a ll
		   geoCoordX[i]=(sc_minx*1)+(coordX*pixel_size);
		   geoCoordY[i]=(sc_miny*1)+(coordY*pixel_size);
		  // alert(i + " - " + geoCoordX[i] + " " + geoCoordY[i]);
		   
		   areaPoly=areaPoly+ ((geoCoordX[i]*geoCoordY[i+1])-(geoCoordX[i+1]*geoCoordY[i]));
		}

		var areaPoly=0;
		for (i=0; i<(numPoints-1); i++) {  		   
		   areaPoly=areaPoly+ ((geoCoordX[i]*geoCoordY[i+1])-(geoCoordX[i+1]*geoCoordY[i]));
		}
		
		areaPoly=areaPoly/2;
		areaPoly_ha=(areaPoly/10000);
		
		areaPoly_ha=Math.abs(Math.round(areaPoly_ha*Math.pow(10,decNumbers))/Math.pow(10,decNumbers));
		
		//alert("Area del poligono: \n"+areaPoly_ha + " ha \nDimensione pixel: \n" + pixel_size_round + " metri");
	
		
       }
       return areaPoly_ha;
   }
   	
	
      function DL_GetElementLeft(eElement) {

        var nLeftPos = eElement.offsetLeft;
        var eParElement = eElement.offsetParent;
        while (eParElement != null)
          {                              
            nLeftPos += eParElement.offsetLeft;
            eParElement = eParElement.offsetParent;
          }
        return nLeftPos;
      }

      function DL_GetElementTop(eElement) {

        var nTopPos = eElement.offsetTop;
        var eParElement = eElement.offsetParent;
        while (eParElement != null)
          {
            nTopPos += eParElement.offsetTop;
            eParElement = eParElement.offsetParent;
          }
        return nTopPos;
      }

      function mouseDblClick() {
	      var cmd = document.myform.cmd.value;
	      if (cmd == 'polygon') {
		      for (i=1;i<draw_x.length;i++) {
			      alert(draw_x[i]);//componi quila stringa da mandare a inc
			      }
			     // jg.clear();
			     // jg.drawPolygon(draw_x, draw_y);
			     jg.drawLine(draw_x[1], draw_y[1], draw_x[myCanvas_clicks], draw_y[myCanvas_clicks]);
			      jg.paint();
			      alert("doSomething; n punti:"+draw_x.length);
			      myCanvas_clear();
	       }
	      if (cmd == 'measure_area') {

			     jg.drawLine(draw_x[1], draw_y[1], draw_x[myCanvas_clicks], draw_y[myCanvas_clicks]);
			      jg.paint();
			      //alert(draw_x.toSource());
			      calcArea(draw_x, draw_y);
			      //alert("doSomething; n punti:"+draw_x.length);
			      myCanvas_clear();
	       }	       
		  if (cmd == 'measure') {

			      myCanvas_clear();
			       }	       
      }
      
      function mouseMove(e) {
	      
	      

        var cmd = document.myform.cmd.value;
	
	//alert(cmd);

        if ( (ns4) || (ns6) ) {mouse_x=e.pageX; mouse_y=e.pageY;}
        if (ie4) {mouse_x=event.x; mouse_y=event.y;}
        if (ie5) {mouse_x=eval('event.x+self.'+docRoot+'.scrollLeft') - 1; mouse_y=eval('event.y+self.'+docRoot+'.scrollTop');}
        if (ie7) {mouse_x=eval('event.x+'+docRoot+'.scrollLeft') - 1; mouse_y=eval('event.y+'+docRoot+'.scrollTop');}

        if ((MainMapLeft <= mouse_x) && (mouse_x <= MainMapLeft + MainMapWidth) && (MainMapTop <= mouse_y) && (mouse_y <= MainMapTop + MainMapHeight)) {

          CoordX = sc_minx +  pixel_size * (mouse_x - MainMapLeft);
          //CoordX = sc_minx +  pixel_size * (mouse_x -1- MainMapLeft);
          CoordX = DoDots(Math.round(CoordX)) + ' m';;
          CoordY = sc_miny +  (pixel_size) * (sc_height - mouse_y + MainMapTop);
          //CoordY = sc_miny +  (pixel_size) * (sc_height - mouse_y +2+ MainMapTop);
          CoordY = DoDots(Math.round(CoordY)) + ' m';;


              //document.getElementById("trovato").style.visibility='visible';
              //document.getElementById("trovato").style.display='block';
              //document.getElementById("trovato").innerHTML="X= "+event.x+" Y = "+event.y+"  Scroll X = "+self.'+docRoot+'.scrollLeft+"  Scroll Y = "+self.'+docRoot+'.scrollTop;

	  
          document.myform.coordx.value = CoordX;
          document.myform.coordy.value = CoordY;

//	  writetostatus("X= "+event.x+" Y = "+event.y+"  Scroll X = "+eval(self.'+docRoot+'.scrollLeft)+"  Scroll Y = "+eval(self.'+docRoot+'.scrollTop));
//          var topPosFix = typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement &&  document.documentElement.scrollTop ? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;

//	  writetostatus(" Body Left = "+document.body.scrollLeft+" X= "+event.x+" Y = "+event.y+" Mouse X = "+mouse_x+" Mouse Y = "+mouse_y+" -- TopFix = "+topPosFix+"  -_- El Top = "+document.documentElement.scrollTop+" Body Top = "+document.body.scrollTop+" Body Left = "+document.body.scrollLeft);

//	  writetostatus("Est: " +CoordX + " Nord: " + CoordY );

/*
          document.getElementById("cursx").style.visibility = 'visible';
          document.getElementById("cursy").style.visibility = 'visible';
          document.getElementById("cursx").style.left = mouse_x + 1;
          document.getElementById("cursy").style.top = mouse_y - 1;
*/
          // only small cursor
/*	  
	  document.getElementById("cursx").style.visibility = 'hidden';
          document.getElementById("cursy").style.visibility = 'hidden';
          document.getElementById("cursx").style.left = mouse_x + 0;
          document.getElementById("cursy").style.top = mouse_y - 0;
*///i_geckomozilla=true;
//alert("Valore di mozilla = "+i_geckomozilla);
          if (cmd == 'measure') {

//if (!i_geckomozilla)    // IMeas+
if (i_geckomozilla) document.getElementById(myCanvasSelect).style.visibility = 'visible';
            document.getElementById(myCanvasSelect).style.cursor = 'crosshair';
if (i_geckomozilla) document.getElementsByName('mainmap')[0].style.cursor = 'crosshair'; 
          }

          else if (cmd == 'polygon' || cmd == 'measure_area') {

//if (!i_geckomozilla)     // IMeas+
if (i_geckomozilla) document.getElementById(myCanvasSelect).style.visibility = 'visible';
            document.getElementById(myCanvasSelect).style.cursor = 'crosshair';
	    //document.ondblclick=mouseDblClick;
if (i_geckomozilla) document.getElementsByName('mainmap')[0].style.cursor = 'crosshair';

          }

          else if (cmd == 'zoom_out') {

if (!i_geckomozilla || ie7)  document.getElementById(myCanvasSelect).style.visibility = 'visible';
 if (i_geckomozilla) document.getElementById(myCanvasSelect).style.visibility = 'hidden';
            document.getElementById(myCanvasSelect).style.cursor = 'crosshair';
	    document.onmouseup = mouseUpZoom;
if (i_geckomozilla) document.getElementsByName('mainmap')[0].style.cursor = 'crosshair';	    
          }	 
          else if (cmd == 'maptip') {            // IMapTip+

if (!i_geckomozilla || ie7)  document.getElementById(myCanvasSelect).style.visibility = 'visible';
 if (i_geckomozilla) document.getElementById(myCanvasSelect).style.visibility = 'hidden';
             document.getElementById(myCanvasSelect).style.cursor = 'crosshair';
             
             //document.getElementsByName('mainmap')[0].style.cursor = 'hand';
             //alert("Canvas in questione = "+myCanvasSelect);
             //alert(" Puntatore Mouse in Canvas = "+document.getElementById(myCanvasSelect).style.cursor);
             //alert(" Puntatore Mouse in MainMap = "+document.getElementsByName('mainmap')[0].style.cursor);
             //if (document.getElementById(myCanvasSelect).style.visibility!="visible") alert(" Visibile in Canvas ");
             //if (document.getElementsByName('mainmap')[0].style.visibility!="visible") alert(" Visibile in MainMap ");
            //-document.getElementById(myCanvasSelect).style.cursor = 'crosshair';
	    //document.onmouseup = mouseUpMaptip;
	    document.onmousedown = mouseUpMaptip;
if (i_geckomozilla) document.getElementsByName('mainmap')[0].style.cursor = 'crosshair';	
          }	
          else if (cmd == 'moving') {            // IMoving+
if (!i_geckomozilla || ie7)  document.getElementById(myCanvasSelect).style.visibility = 'visible';
 if (i_geckomozilla) document.getElementById(myCanvasSelect).style.visibility = 'hidden';
             document.getElementById(myCanvasSelect).style.cursor = 'pointer';
	    document.onmousedown = mouseDownMoving;
if (i_geckomozilla) document.getElementsByName('mainmap')[0].style.cursor = 'pointer';	
          }	

          else if ((cmd == 'zoom_rect') || (cmd == 'query') ) {

if (!i_geckomozilla || ie7)  document.getElementById(myCanvasSelect).style.visibility = 'visible';
 if (i_geckomozilla) document.getElementById(myCanvasSelect).style.visibility = 'hidden';
            document.getElementById(myCanvasSelect).style.cursor = 'crosshair';
if (i_geckomozilla || ie7) document.getElementsByName('mainmap')[0].style.cursor = 'crosshair';
//alert (cmd);//alert("dopo");
            //
            // Entry Points (not used yet)
            //

            // if (!zoom_rect_x[1]) zoom_rect_x[1] = mouse_x + 1;
            // if (!zoom_rect_y[1]) zoom_rect_y[1] = mouse_y - 1;

            document.onmousedown = mouseDownZoom;

            if (myCanvas_clicks == 1) {

              zoom_rect_x[2] = mouse_x + 1;
              zoom_rect_y[2] = mouse_y - 1;                            

              document.getElementById("zoomrect").style.top = (Math.min(zoom_rect_y[1],zoom_rect_y[2]))+"px";
              document.getElementById("zoomrect").style.left = (Math.min(zoom_rect_x[1],zoom_rect_x[2]))+"px";
              if (ie5 || ie7) {
                document.getElementById("zoomrect").style.width = (Math.abs(zoom_rect_x[2] - zoom_rect_x[1]) + 1)+"px";
                document.getElementById("zoomrect").style.height = (Math.abs(zoom_rect_y[2] - zoom_rect_y[1]) + 1)+"px";
              }
              else { // ns6
                document.getElementById("zoomrect").style.width = (Math.abs(zoom_rect_x[2] - zoom_rect_x[1]) - 1)+"px";
                document.getElementById("zoomrect").style.height = (Math.abs(zoom_rect_y[2] - zoom_rect_y[1]) - 1)+"px";
              }

              document.getElementById("zoomrect").style.visibility = 'visible';

            }

            document.onmouseup = mouseUpZoom;

          }
          else if (cmd == 'move') {

            if (ns6) {

if (!i_geckomozilla)  document.getElementById(myCanvasSelect).style.visibility = 'visible';
 if (i_geckomozilla || ie7) document.getElementById(myCanvasSelect).style.visibility = 'hidden'; //? è per ns6 ma a volte passa per strani browser

              document.getElementById(myCanvasSelect).style.cursor = 'move';
if (i_geckomozilla) document.getElementsByName('mainmap')[0].style.cursor = 'move';

            }
            else {

              document.getElementById(myCanvasSelect).style.visibility = 'hidden';
                // sebbene come hidden quando passa sopra e muovo mi da dei problemi di aggancio, sgancio con offset alla Mappa, potrei rimuoverlo o metterlo infatti visibile il Canvas
              //++document.getElementById(myCanvasSelect).style.visibility = 'visible';
                  //++document.getElementById(myCanvasSelect).style.cursor = 'move';
              document.getElementsByName('mainmap')[0].style.cursor = 'move';

            }

            document.onmousedown = mouseDownMove;

            if (myCanvas_clicks >= 1) {

            myCanvas_clicks = 1; //alert('a');
              //document.getElementById('trovato').style.visibility='visible';
              //var s=str(mouse_x - MouseDownClickLeft + dX);
              //document.getElementById('trovato').innerHTML=s;
              //alert('Left Mappa = '+document.getElementsByName("mainmap")[0].style.left);
//               document.getElementsByName('mainmap')[0].style.left = (mouse_x - MouseDownClickLeft + MainMapLeft +dX)+"px";
              //document.getElementsByName('mainmap')[0].style.left = 277+(mouse_x - MouseDownClickLeft + dX)+"px";
        //  document.getElementsByName('mainmap')[0].style.left = (mouse_x - MouseDownClickLeft + dX)+"px";
        document.getElementsByName('mainmap')[0].style.left = MainMapLeft + (mouse_x - MouseDownClickLeft + dX)+"px";
            document.getElementsByName('mainmap')[0].style.top = (mouse_y - MouseDownClickTop + MainMapTop +dY)+"px";
             //+Move

              //document.getElementsByName('mainmap')[0].style.left = "-20px";
              //document.getElementsByName('mainmap')[0].style.top = "40px";
              //alert('Left Mappa = '+document.getElementsByName("mainmap")[0].style.left);
              //document.getElementById('trovato').style.visibility='visible';
              //document.getElementById('trovato').style.display='block';
              //confirm('SemR');
//              document.getElementById('trovato').innerHTML="Left = "+document.getElementsByName("mainmap")[0].style.left+" Top = "+document.getElementsByName('mainmap')[0].style.top;
              //alter('Vis');

              var t = (MouseDownClickTop - mouse_y)+"px";
              var r = (MouseDownClickLeft - mouse_x + MainMapWidth)+"px";
              var b = (MouseDownClickTop - mouse_y + MainMapHeight)+"px";
              var l = (MouseDownClickLeft - mouse_x)+"px";

              //alert('T '+t+' R '+r+' B '+b+' L '+l);
              //document.getElementById('trovato').innerHTML="Left = "+document.getElementsByName("mainmap")[0].style.left+" Top = "+document.getElementsByName('mainmap')[0].style.top+"   T "+t+" R "+r+" B "+b+" L "+l+"  Map "+DL_GetElementTop(document.getElementsByName('mainmap')[0])+" "+DL_GetElementLeft(document.getElementsByName('mainmap')[0]);
                            
              document.getElementsByName('mainmap')[0].style.clip = 'rect(' + t + ' ' +  r + ' ' + b + ' ' + l + ')'; //oben, rechts, unten, links

            }

            document.onmouseup = mouseUpMove;

          }
          else {

            document.getElementsByName('mainmap')[0].style.cursor = 'crosshair';
            document.getElementById(myCanvasSelect).style.cursor = 'crosshair';

            document.onmousedown = MouseDownDefault;
            document.onmouseup = MouseUpDefault;

            if (myCanvas_clicks == 1) {
              myCanvas_clear();
            }

            document.getElementById(myCanvasSelect).style.visibility = 'hidden';
	    //++document.getElementById(myCanvasSelect).style.visibility = 'visible';

          }

        }
        else {

          if ((myCanvas_clicks >= 1) && (cmd == 'move')) {

            myCanvas_clicks = 2;

            MainMapMovedLeft = parseInt(document.getElementsByName('mainmap')[0].style.left);
            MainMapMovedTop = parseInt(document.getElementsByName('mainmap')[0].style.top);

            document.onmouseup = mouseUpMove;

          }
          else if ((myCanvas_clicks == 1) && (cmd == 'zoom_rect')) {
            document.onmouseup = mouseUpZoom;
          }
          else if ((myCanvas_clicks == 1) && (cmd == 'query')) {
            document.onmouseup = mouseUpZoom;
          }	  
          else {
            document.onmouseup = MouseUpDefault;
          }

          document.onmousedown = MouseDownDefault;

          document.getElementById("cursx").style.visibility = 'hidden';
          document.getElementById("cursy").style.visibility = 'hidden';

        }
      }

      var zoom_rect_x = new Array();
      var zoom_rect_y = new Array();
      var myCanvas_clicks = 0;

      function mouseDownZoom(e) {
	if (tip_attivo==0)      
  	{
        	myCanvas_clear();
        	myCanvas_clicks = 1;
        	zoom_rect_x[1] = mouse_x + 1;
        	zoom_rect_y[1] = mouse_y - 1;
        	jg.drawLine(zoom_rect_x[1] - 5 - MainMapLeft, zoom_rect_y[1] - MainMapTop, zoom_rect_x[1] + 5 - MainMapLeft, zoom_rect_y[1] - MainMapTop);
        	jg.drawLine(zoom_rect_x[1] - MainMapLeft, zoom_rect_y[1] - 5 - MainMapTop, zoom_rect_x[1] - MainMapLeft, zoom_rect_y[1] + 5 - MainMapTop);
        	jg.paint();
	}
      }

      function mouseUpZoom() {
        myCanvas_clicks = 2;


        if (!zoom_rect_x[2]) zoom_rect_x[2] = mouse_x + 1;
        if (!zoom_rect_y[2]) zoom_rect_y[2] = mouse_y - 1;

        if (!zoom_rect_x[1]) zoom_rect_x[1] = mouse_x + 1;
        if (!zoom_rect_y[1]) zoom_rect_y[1] = mouse_y - 1;

        jg.drawLine(zoom_rect_x[2] - 5 - MainMapLeft, zoom_rect_y[2] - MainMapTop, zoom_rect_x[2] + 5 - MainMapLeft, zoom_rect_y[2] - MainMapTop);
        jg.drawLine(zoom_rect_x[2] - MainMapLeft, zoom_rect_y[2] - 5 - MainMapTop, zoom_rect_x[2] - MainMapLeft, zoom_rect_y[2] + 5 - MainMapTop);
        jg.paint();

        if ((zoom_rect_x[2] != zoom_rect_x[1]) && (zoom_rect_y[2] != zoom_rect_y[1])) {
          document.myform.zoom_rect_minx.value = Math.min(zoom_rect_x[1], zoom_rect_x[2]) - MainMapLeft;
          document.myform.zoom_rect_miny.value = Math.min(zoom_rect_y[1], zoom_rect_y[2]) - MainMapTop;
          document.myform.zoom_rect_maxx.value = Math.max(zoom_rect_x[1], zoom_rect_x[2]) - MainMapLeft;
          document.myform.zoom_rect_maxy.value = Math.max(zoom_rect_y[1], zoom_rect_y[2]) - MainMapTop;
        }
        else {
          if (zoom_rect_x[2] != zoom_rect_x[1]) {
            document.myform.zoom_x.value = (Math.min(zoom_rect_x[1], zoom_rect_x[2]) + Math.abs(zoom_rect_x[2] - zoom_rect_x[1]) / 2) - MainMapLeft;
            document.myform.zoom_y.value = zoom_rect_y[1] - MainMapTop;
          }
          else if (zoom_rect_y[2] != zoom_rect_y[1]) {
            document.myform.zoom_x.value = zoom_rect_x[1] - MainMapLeft;
            document.myform.zoom_y.value = (Math.min(zoom_rect_y[1], zoom_rect_y[2]) + Math.abs(zoom_rect_y[2] - zoom_rect_y[1]) / 2) - MainMapTop;
          }
          else {
            document.myform.zoom_x.value = zoom_rect_x[1] - MainMapLeft;
            document.myform.zoom_y.value = zoom_rect_y[1] - MainMapTop;
          }
        }
        

        loadmap();

        document.myform.target="";
	document.myform.send_cmd.value="ok";
  		     //alert("Submit in MouseUpZoom");
        document.myform.submit();

      }

      function mouseUpMaptip() { // IMapTip+
       if (tip_attivo==0) {
        myCanvas_clicks = 2;
        
        //alert(" Ci sono ");

        //document.getElementById('mis_mml').innerHTML=MainMapLeft;
        //document.getElementById('mis_mmt').innerHTML=MainMapTop;
        //document.getElementById('mis_x').innerHTML=mouse_x;
        //document.getElementById('mis_y').innerHTML=mouse_y;
        
        if (!zoom_rect_x[2]) zoom_rect_x[2] = mouse_x + 1  -1 -1 ;
        if (!zoom_rect_y[2]) zoom_rect_y[2] = mouse_y - 1  -1 ;

        if (!zoom_rect_x[1]) zoom_rect_x[1] = mouse_x + 1  -1 -1 ;
        if (!zoom_rect_y[1]) zoom_rect_y[1] = mouse_y - 1  -1 ;
        
        if ((zoom_rect_x[2] != zoom_rect_x[1]) && (zoom_rect_y[2] != zoom_rect_y[1])) {
          document.myform.zoom_rect_minx.value = Math.min(zoom_rect_x[1], zoom_rect_x[2]) - MainMapLeft;
          document.myform.zoom_rect_miny.value = Math.min(zoom_rect_y[1], zoom_rect_y[2]) - MainMapTop;
          document.myform.zoom_rect_maxx.value = Math.max(zoom_rect_x[1], zoom_rect_x[2]) - MainMapLeft;
          document.myform.zoom_rect_maxy.value = Math.max(zoom_rect_y[1], zoom_rect_y[2]) - MainMapTop;
        }
        else {
          if (zoom_rect_x[2] != zoom_rect_x[1]) {
            document.myform.zoom_x.value = (Math.min(zoom_rect_x[1], zoom_rect_x[2]) + Math.abs(zoom_rect_x[2] - zoom_rect_x[1]) / 2) - MainMapLeft;
            document.myform.zoom_y.value = zoom_rect_y[1] - MainMapTop;
          }
          else if (zoom_rect_y[2] != zoom_rect_y[1]) {
            document.myform.zoom_x.value = zoom_rect_x[1] - MainMapLeft;
            document.myform.zoom_y.value = (Math.min(zoom_rect_y[1], zoom_rect_y[2]) + Math.abs(zoom_rect_y[2] - zoom_rect_y[1]) / 2) - MainMapTop;
          }
          else {
            document.myform.zoom_x.value = zoom_rect_x[1] - MainMapLeft;
            document.myform.zoom_y.value = zoom_rect_y[1] - MainMapTop;
          }
        }

        document.getElementById('dati_maptips').style.visibility='visible';
        //document.getElementById('mis_x1').innerHTML=document.myform.zoom_x.value;
        //document.getElementById('mis_y1').innerHTML=document.myform.zoom_y.value;
        
                     document.getElementById('livelli').style.visibility='visible';
                     document.getElementById('livelli').style.display='block';
                     document.getElementById('B1').className='on';
                     document.getElementById('ricerche').style.visibility='hidden';
                     document.getElementById('ricerche').style.display='none';
                     document.getElementById('B2').className='off';
                     document.getElementById('servizi').style.visibility='hidden';
                     document.getElementById('servizi').style.display='none';
                     document.getElementById('B3').className='off';
                     document.myform['scheda'].value='livelli';

        document.getElementById('mis_xg').innerHTML=Math.round((sc_minx +  pixel_size * ( eval(document.myform.zoom_x.value) )))+' m';
        document.getElementById('mis_yg').innerHTML=Math.round((sc_miny +  (pixel_size) * (sc_height - eval(document.myform.zoom_y.value))))+' m';

        //loadmap();
           document.myform.send_cmd.value="";
           //alert("In MouseUpMaptip");
      //-  document.myform.target="";
	//-document.myform.send_cmd.value="ok";
        //document.myform.submit();
       } //end tooltip
      } //end if move

      function mouseDownMoving() { // IMoving+
       if (tip_attivo==0) {
        myCanvas_clicks = 2;

        //document.getElementById('mis_mml').innerHTML=MainMapLeft;
        //document.getElementById('mis_mmt').innerHTML=MainMapTop;
        //document.getElementById('mis_x').innerHTML=mouse_x;
        //document.getElementById('mis_y').innerHTML=mouse_y;

        if (!zoom_rect_x[2]) zoom_rect_x[2] = mouse_x + 1  -1 -1 ;
        if (!zoom_rect_y[2]) zoom_rect_y[2] = mouse_y - 1  -1 ;

        if (!zoom_rect_x[1]) zoom_rect_x[1] = mouse_x + 1  -1 -1 ;
        if (!zoom_rect_y[1]) zoom_rect_y[1] = mouse_y - 1  -1 ;

        if ((zoom_rect_x[2] != zoom_rect_x[1]) && (zoom_rect_y[2] != zoom_rect_y[1])) {
          document.myform.zoom_rect_minx.value = Math.min(zoom_rect_x[1], zoom_rect_x[2]) - MainMapLeft;
          document.myform.zoom_rect_miny.value = Math.min(zoom_rect_y[1], zoom_rect_y[2]) - MainMapTop;
          document.myform.zoom_rect_maxx.value = Math.max(zoom_rect_x[1], zoom_rect_x[2]) - MainMapLeft;
          document.myform.zoom_rect_maxy.value = Math.max(zoom_rect_y[1], zoom_rect_y[2]) - MainMapTop;
        }
        else {
          if (zoom_rect_x[2] != zoom_rect_x[1]) {
            document.myform.zoom_x.value = (Math.min(zoom_rect_x[1], zoom_rect_x[2]) + Math.abs(zoom_rect_x[2] - zoom_rect_x[1]) / 2) - MainMapLeft;
            document.myform.zoom_y.value = zoom_rect_y[1] - MainMapTop;
          }
          else if (zoom_rect_y[2] != zoom_rect_y[1]) {
            document.myform.zoom_x.value = zoom_rect_x[1] - MainMapLeft;
            document.myform.zoom_y.value = (Math.min(zoom_rect_y[1], zoom_rect_y[2]) + Math.abs(zoom_rect_y[2] - zoom_rect_y[1]) / 2) - MainMapTop;
          }
          else {
            document.myform.zoom_x.value = zoom_rect_x[1] - MainMapLeft;
            document.myform.zoom_y.value = zoom_rect_y[1] - MainMapTop;
          }
        }

        //document.getElementById('dati_maptips').style.visibility='visible';
        //document.getElementById('mis_x1').innerHTML=document.myform.zoom_x.value;
        //document.getElementById('mis_y1').innerHTML=document.myform.zoom_y.value;

        //document.getElementById('mis_xg').innerHTML=(sc_minx +  pixel_size * ( eval(document.myform.zoom_x.value) ));
        //document.getElementById('mis_yg').innerHTML=(sc_miny +  (pixel_size) * (sc_height - eval(document.myform.zoom_y.value)));

        loadmap();
        document.myform.send_cmd.value="";
        document.myform.target="";
	     document.myform.send_cmd.value="ok";
	     
	     document.myform["layer"].value="maptips_";
        document.myform["gid"].value=62;

        document.myform.submit();
       } //end tooltip
      } //end if move

      var MouseDownClickLeft = 0;
      var MouseDownClickTop = 0;

      function mouseDownMove() {
        myCanvas_clicks = 1;
        MouseDownClickLeft = mouse_x;
        MouseDownClickTop = mouse_y;
      }

      function mouseUpMove() {

        if (myCanvas_clicks == 1) {
          document.myform.move_x.value = (MainMapWidth / 2) + (MouseDownClickLeft - mouse_x);
          document.myform.move_y.value = (MainMapHeight / 2) + (MouseDownClickTop - mouse_y);
        }
        else if (myCanvas_clicks == 2) {
          document.myform.move_x.value = (MainMapWidth / 2) - MainMapMovedLeft + MainMapLeft;
          document.myform.move_y.value = (MainMapHeight / 2) - MainMapMovedTop + MainMapTop;
        }

        myCanvas_clear();

        loadmap();

        document.myform.target="";
	document.myform.send_cmd.value="ok";
            //alert("Submit in MouseUpMove");
        document.myform.submit();

      }

      function myCanvas_clear() {
        myCanvas_clicks = 0;
        //var draw_x = "";
	draw_x = draw_x.splice(0);
        //var draw_y = "";
	draw_y = draw_y.splice(0);	
        dist = 0;
	distSegment=0;
        jg.clear();
//        document.myform.distance.value = dist + ' m';
//        document.myform.dist_segment.value = distSegment + ' m';	

        document.getElementById("zoomrect").style.visibility = 'hidden';
        document.getElementById("zoomrect").style.width = "1px";
        document.getElementById("zoomrect").style.height = "1px";
	writetostatus(" ");
        return;
      }

      var draw_x = new Array();
      var draw_y = new Array();
      var dist = 0;

      
      function myCanvas_is_clicked() {
			
         // reset placename_useriput to avoid unwanted opening of placename_window
			   placename_userinput  = '';       
							
        var cmd = document.myform.cmd.value;

        if (cmd == 'measure') {

          myCanvas_clicks = myCanvas_clicks + 1;
          draw_x[myCanvas_clicks] = mouse_x - MainMapLeft;
          draw_y[myCanvas_clicks] = mouse_y - MainMapTop;

          if (myCanvas_clicks == 1) {
            jg.drawLine(draw_x[myCanvas_clicks] - 5, draw_y[myCanvas_clicks], draw_x[myCanvas_clicks] + 5, draw_y[myCanvas_clicks]);
            jg.drawLine(draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] - 5, draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] + 5);
            jg.paint();
          }
          else {
            jg.drawLine(draw_x[myCanvas_clicks] - 5, draw_y[myCanvas_clicks], draw_x[myCanvas_clicks] + 5, draw_y[myCanvas_clicks]);
            jg.drawLine(draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] - 5, draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] + 5);
            jg.drawLine(draw_x[myCanvas_clicks - 1], draw_y[myCanvas_clicks - 1], draw_x[myCanvas_clicks], draw_y[myCanvas_clicks]);
            jg.paint();

            dist_x = draw_x[myCanvas_clicks] - draw_x[myCanvas_clicks - 1];
            dist_y = draw_y[myCanvas_clicks] - draw_y[myCanvas_clicks - 1];
	    distSegment=(pixel_size) * Math.sqrt(dist_x * dist_x + dist_y * dist_y);
            dist = dist + distSegment;
//	    document.myform.dist_segment.value = Math.round(distSegment) + ' m';
//            document.myform.distance.value = Math.round(dist) + ' m';
	    
	    writetostatus("Distanza --> Segmento: " + Math.round(distSegment) + ' m' + " Totale: " + Math.round(dist) + ' m');
          }
        }

        if (cmd == 'polygon' || cmd == 'measure_area') {

          myCanvas_clicks = myCanvas_clicks + 1;
          draw_x[myCanvas_clicks] = mouse_x - MainMapLeft;
          draw_y[myCanvas_clicks] = mouse_y - MainMapTop;

          if (myCanvas_clicks == 1) {
            jg.drawLine(draw_x[myCanvas_clicks] - 5, draw_y[myCanvas_clicks], draw_x[myCanvas_clicks] + 5, draw_y[myCanvas_clicks]);
            jg.drawLine(draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] - 5, draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] + 5);
            jg.paint();
	    
          }
          else {
//		jg.clear();
            jg.drawLine(draw_x[myCanvas_clicks] - 5, draw_y[myCanvas_clicks], draw_x[myCanvas_clicks] + 5, draw_y[myCanvas_clicks]);
            jg.drawLine(draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] - 5, draw_x[myCanvas_clicks], draw_y[myCanvas_clicks] + 5);
            jg.drawLine(draw_x[myCanvas_clicks - 1], draw_y[myCanvas_clicks - 1], draw_x[myCanvas_clicks], draw_y[myCanvas_clicks]);
//	    jg.drawPolygon(draw_x, draw_y);
//	    jg.drawLine(draw_x[1], draw_y[1], draw_x[myCanvas_clicks], draw_y[myCanvas_clicks]);
            jg.paint();
	    if (myCanvas_clicks > 2) {
	    writetostatus("area: " + calcArea(draw_x,draw_y) + "ha");
	    }
          }
        }	
	
      }

      var alreadyOpen = false;
      var popupWin;

      function openWindow(url,name,w,h) {
        if (parseInt(navigator.appVersion) > 2) {
          if (alreadyOpen == name) {
            if (popupWin.closed) {
              popupWin = window.open(url,name,"directories=0,location=0,menubar=0,resizeable=1,scrollbars=1,status=1,toolbar=0,width=" + w + ",height=" + h);
            }
            else {
              popupWin.close();
              popupWin = window.open(url,name,"directories=0,location=0,menubar=0,resizeable=1,scrollbars=1,status=1,toolbar=0,width=" + w + ",height=" + h);
            }
          }
          else {
            popupWin = window.open(url,name,"directories=0,location=0,menubar=0,resizeable=1,scrollbars=1,status=1,toolbar=0,width=" + w + ",height=" + h);
            alreadyOpen = name;
          }
        }
      }

      function getRadioButtonValue(radio) {
        for (var i = 0; i < radio.length; i++) {
          if (radio[i].checked) {
            break;
          }
        }
        return radio[i].value;
      }

      var clickimg = 0;
      function is_clicked() {
        clickimg = 1; // quindi non da problemi ne vario return alert("cliccato");
        return;
      }
			
		  var nwin = 0;
		  function getWindow() {  			
  			nwin = 1;
  			return;
			}
			
/*      function QueryCheck() {
 
         loadmap();

        var cmd = getRadioButtonValue(document.myform.cmd);
				
				 if (document.myform.placename_userinput.value != ''){
//						loadmap();
          document.getElementById("loadmap-img").style.visibility = 'hidden';
            openWindow('','querywindow',320,480);
            document.myform.target="querywindow";
  					nwin = 0;
            return;  					
				 };

								

        if (cmd == 'query_point' && clickimg == 1) {
          document.getElementById("loadmap-img").style.visibility = 'hidden';
//          openWindow('','querywindow',520,650);
//          document.myform.target="querywindow";
          clickimg = 0;
          return;
        }
	      else {
  				if(nwin == 1) {
//						loadmap();
            openWindow('','querywindow',750,650);
            document.myform.target="querywindow";
  					nwin = 0;
            return;  					
          }
				
        else {
          document.myform.target="_parent";
          clickimg = 0;
          return;
        }
			 }
      }
*/
      function ChanceFunctionality() {
        myCanvas_clear();
      }


      if (ie4 || ie5) {
        var LoadMapImg = new Array();
        LoadMapImg[0] = new Image();
        LoadMapImg[0].src = "geostaf/LoadMap-1.gif";
        LoadMapImg[1] = new Image();
        LoadMapImg[1].src = "geostaf/LoadMap-1.gif";
        LoadMapImg[2] = new Image();
        LoadMapImg[2].src = "geostaf/LoadMap-2.gif";
        LoadMapImg[3] = new Image();
        LoadMapImg[3].src = "geostaf/LoadMap-3.gif";
        LoadMapImg[4] = new Image();
        LoadMapImg[4].src = "geostaf/LoadMap-4.gif";
        LoadMapImg[5] = new Image();
        LoadMapImg[5].src = "geostaf/LoadMap-5.gif";
        LoadMapImg[6] = new Image();
        LoadMapImg[6].src = "geostaf/LoadMap-6.gif";
        LoadMapImg[7] = new Image();
        LoadMapImg[7].src = "geostaf/LoadMap-7.gif";
        var LoadMapNr = 0;
      }

      function loadmap() {

//        document.getElementById("headline-img").style.visibility = 'hidden';

        document.getElementById("loadmap-img").style.visibility = 'visible';
/*
        if (ie4 || ie5) {
          LoadMapNr = LoadMapNr + 1;
          document.getElementById("loadmap-img").getElementsByTagName('img')[0].src = LoadMapImg[LoadMapNr].src;
          if (LoadMapNr == 7) {
            LoadMapNr = 0;
          }
          if (!popupWin) {
            setTimeout("loadmap()", 75);
          }
          else {
            document.getElementById("loadmap-img").getElementsByTagName('img')[0].src = LoadMapImg[0].src;
          }
        }
 */     }


      var showtippok;
      var tipptext;

      function showtipp(text) {
        showtippok = true;
        tipptext = text;
        setTimeout("showtippexecute();", 1000);
//        setTimeout("showtippexecute('" + text + "')", 1000); // Unbefriedigende Loesung, da Parameter "text" immer
                                                               // erst verzoegert uebergeben wird
      }

      function showtippexecute() {
        if (showtippok) {
          document.getElementById("tipp").style.top = (mouse_y + 10)+"px";
          document.getElementById("tipp").style.left = (mouse_x +15) + "px";
//          document.getElementById("tipp").firstChild.data = tipptext; // this doesn't work with inline images!!
          document.getElementById("tipp").innerHTML = tipptext;
          document.getElementById("tipp").style.visibility = 'visible';
        }
      }

      function hidetipp() {
        document.getElementById("tipp").style.visibility = 'hidden';
//        document.getElementById("tipp").firstChild.data = '';
        document.getElementById("tipp").innerHTML = '';
        showtippok = false;
      }

      function HighlightJsMenuLink(object) {
        object.style.backgroundColor = '#a0a0a0';
        object.style.cursor = 'pointer';
        object.style.color = '#ffffff';
      }

      function DownlightJsMenuLink(object) {
        object.style.backgroundColor = '#c0c0c0';
        object.style.cursor = 'default';
        object.style.color = '#555555';
      }

      var MenuStatus = 0;
      function ShowMenu(menubutton,menu) {
        if (MenuStatus == 0) {
          document.getElementById(menubutton).getElementsByTagName('td')[1].style.backgroundColor = '#eeeeee';
          document.getElementById(menubutton).getElementsByTagName('td')[2].style.backgroundColor = '#eeeeee';
          document.getElementById(menubutton).getElementsByTagName('td')[6].style.backgroundColor = '#a0a0a0';
          document.getElementById(menubutton).getElementsByTagName('td')[7].style.backgroundColor = '#a0a0a0';
          document.getElementById(menu).style.top = DL_GetElementTop(document.getElementById(menubutton).getElementsByTagName('td')[7]);
          document.getElementById(menu).style.left = DL_GetElementLeft(document.getElementById(menubutton).getElementsByTagName('td')[6]) - 150 + 1;
          document.getElementById(menu).getElementsByTagName('img')[1].style.width = 149 - (DL_GetElementLeft(document.getElementById(menubutton).getElementsByTagName('td')[6]) - DL_GetElementLeft(document.getElementById(menubutton).getElementsByTagName('td')[7]));
          document.getElementById(menu).style.visibility = 'visible';
          MenuStatus = 1;
        }
      }

      function AOISelected() /// Area Of Interest
      {
          if (document.forms[0].AOI.selectedIndex != 0 &&
              document.forms[0].AOI.selectedIndex !=1) {
						myTextfield_clear();	
           document.myform.caoi.value = 1;
           document.myform.target="_parent";   		     //alert("Submit in AOI");
           document.forms[0].submit();
      		 loadmap();
      		}
      }

      function LanguageSelected()
      {
          document.myform.clanguage.value = 1;
          document.myform.target="_parent";   		     //alert("Submit in LanguageSelected");
          document.forms[0].submit();
        	loadmap();
      }

/*      function MapSizeSelected()
      {
          document.myform.cmapsize.value = 1;
          document.myform.target="_parent";
          document.forms[0].submit();
        	loadmap();
      }
*/
			
//Placename search

      function myTextfield_clear()
			{
        document.myform.placename_userinput.value = '';

        return;
      }
      

      
/*      
      function changeImg(leg_or_contest) {
//	 document.myform.map_ref_status.value = ON_or_OFF;
//	 document.myform.submit();

//        document.getElementById('contest').style.position = 'absolute';
//	document.getElementById('legenda').style.position = 'absolute';
        var legTop  = document.getElementById('legenda').style.top;
        var legLeft = document.getElementById('legenda').style.left;	
        document.getElementById('contest').style.top = legTop;
        document.getElementById('contest').style.left = legLeft;

	if(leg_or_contest=="contest") {
		document.getElementById("legenda").style.visibility = 'hidden';
		document.getElementById("contest").style.visibility = 'visible';
		document.getElementById("B_con").style.visibility = 'hidden';
		document.getElementById("B_leg").style.visibility = 'visible';
	} else {
		document.getElementById("legenda").style.visibility = 'visible';
		document.getElementById("contest").style.visibility = 'hidden';	
		document.getElementById("B_con").style.visibility = 'visible';
		document.getElementById("B_leg").style.visibility = 'hidden';
	}
      }      
*/      
//var totCommandi = 6;
var totCommandi = 7;  // IMapTip+
var totCommandi = 8;  // IMoving+
//var totCommandi = 8;
var ext=".gif";
var tmpCMD;

icoOFF=new Array(totCommandi)
icoON=new Array(totCommandi)
for (i=0;i<totCommandi;i++) {
  icoOFF[i] = new Image();
  icoOFF[i].src = "images//icoOFF_" + i + ext;
  icoON[i] = new Image();
  icoON[i].src = "images//icoON_" + i + ext;
}      

function changeIcon(n) {
 for (i=0;i<totCommandi;i++) {
 	if (i==n) {
		document["icoCom"+i].src= icoON[n].src
	} else {
 		document["icoCom"+i].src= icoOFF[i].src;
 	}
 }
}

var ib=0;
function changeCMD(comm) {
// Questa Ã¨ l'istruzione che non fa funzionare i MapTips in Firefox e probabilmente neanche in IE7
// bisogna vedere come sostituirla
document.myform.cmd.value = comm;  // istruzione originale
//document.myform['cmd'].value = comm;
//document.myform["cmd"].value = comm; // istruzione modificata per testare
// con vari tentativi non risolto
//alert(comm);
  /*
  if (ib==1)
  {
  if (comm=='query')
  {
    document.getElementById('interrog').style.visibility='visible';
    alert('2');
    document.getElementById('interrog').style.display='block';
    document.getElementById('interrog').innerHTML='Il layer attualmente selezioanto è';
  } else
  {
    document.getElementById('interrog').style.visibility='hidden';
    document.getElementById('interrog').style.display='none';
  }
  }
  ib=1; */
}

function unsetCMD() {
tmpCMD = document.myform.cmd.value;
document.myform.cmd.value = "";
//document.myform.debug.value="";
//alert(tmpCMD);
}

function resetCMD() {
document.myform.cmd.value = tmpCMD;
document.myform.debug.value=document.myform.cmd.value;
//alert("resettato "+tmpCMD2);
}

//var icon_tools = new Array("zoom_rect","zoom_out","move","query","measure","measure_area","polygon","fullextent","redraw","segnala");
var icon_tools = new Array("zoom_rect","zoom_out","move","fullextent","redraw","query","measure","measure_area","maptip"); // IMapTip+
var icon_tools = new Array("zoom_rect","zoom_out","move","fullextent","redraw","query","measure","measure_area","maptip","moving"); // IMoving+
var icon_tools = new Array("zoom_rect","zoom_out","move","fullextent","redraw","query","measure","measure_area","maptip","stampa"); // IMoving+
var midPopWin='';

   function open_midpop(url) {
      larghFinestra=650;
      posizSinistraH=(screen.width/2)-(larghFinestra/2);
      altezFinestra=400;
      posizSinistraV=(screen.height/2)-(altezFinestra/2);
      // se la finestra ï¿½aperta la aggiorno
      if (!midPopWin.closed && midPopWin.location)
	{
		midPopWin.location.href = url;
	}
	else
	{
		 midPopWin = window.open (url, "","top="+posizSinistraV+",left="+posizSinistraH +",width="+larghFinestra+",height="+altezFinestra+",scrollbars=yes,resizable=yes");
		//if (!newwindow.opener) newwindow.opener = self;
	}
     
      midPopWin.window.focus();

  }
  
 function panDirection(direction) 
 {
	 document.myform["PAN_DIR"].value=direction;
	 //document.myform.submit();
 }
 
function zoom2scale (scaleNum) {
document.myform["MAP_SCALE"].value=scaleNum;   		     //alert("Submit in zoom2scale");
document.myform.submit();

}
function TuttiCivici () {
document.myform["tutticivici"].value="1";   		     //alert("Submit in TuttiCivici");
document.myform.submit();

}

function writetostatus(input){
    window.status=input
    return true
}

var NEW_WIN = "";
function prompter(url)
{
name=prompt('Inserisci il titolo per il report',"Investiin Asti");

	Response=open_window(url+"?name="+name);

}

   function open_window(url) {
      if (!NEW_WIN.closed && NEW_WIN.location)
	{
		NEW_WIN.location.href = url;
	}
	else
	{
		 NEW_WIN = window.open ("", "GeoMoll", "toolbar=no,width=400,height=300,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
		 NEW_WIN.location.href = url;
	}
     
      NEW_WIN.window.focus();      
      
}

