
    function riserve_nav_1(Np,Nr,Nt,Nu,flag,Xp,Yp,laC,loC,G,desc,Max_d,text) {
// Tre zone piu' testo    
var asc = new Array();
var ord = new Array();	    
var j = 0;
tabella = "       Nome " + "         Coordinate " + "   Miglia" + "  Rotta ";
var nd = 0;
var rotta = 0;
var dist = 0;
var sum = 0;
var Id = desc[0];
document.tab_2.msg.value = " Area marina protetta  " + Id; 

	    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GMapTypeControl());
		  map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(laC,loC),G);
                     
//*********************************************************        
                 for (var i = Np+1; i < Nr; i++) {
var A1=Xp[i];
var B1=Yp[i];
var A2=Xp[i+1];
var B2=Yp[i+1];

//**********************
     if ((A1!=0.0)&&(A2!=0.0)) {
                		 
var polyline = new GPolyline([new GLatLng(A1,B1),new GLatLng(A2,B2)], "#FF0000", 2);
map.addOverlay(polyline);}                 
             }
                 for (var i = Nr+1; i < Nt; i++) {
var A1=Xp[i];
var B1=Yp[i];
var A2=Xp[i+1];
var B2=Yp[i+1];

       if ((A1!=0.0)&&(A2!=0.0)) {
                		 
var polyline = new GPolyline([new GLatLng(A1,B1),new GLatLng(A2,B2)], "#0000FF", 2);
map.addOverlay(polyline);
                                    }
                                             }   
                                             

                   for (var i = Nt+1; i < Nu; i++) {
var A1=Xp[i];
var B1=Yp[i];
var A2=Xp[i+1];
var B2=Yp[i+1];

       if ((A1!=0.0)&&(A2!=0.0)) {
                		 
var polyline = new GPolyline([new GLatLng(A1,B1),new GLatLng(A2,B2)], "#FFFF80", 2);
map.addOverlay(polyline);
                                    }
                                             }
                                                            
//*********************************************************
if (flag == 1){
               for (var i = 0; i < Np+1; i++) {
var icon = new GIcon();
//*****************************
// di base r00 = riseva       
//*** pp = porto normale  simbolo -
//** r00 = riserve i>Np       
//** r01 = avvisi simbolo :   
//*** pe = selezione simbolo #
//*****************************
icon.image = "../icone_mappe/r00.bmp";
icp = desc[i].substring(0,1);
  if(icp == "-"){icon.image = "../icone_mappe/pp.bmp"};
  if(icp == ":"){icon.image = "../icone_mappe/r00.bmp"};
  if(icp == "#"){icon.image = "../icone_mappe/pe.bmp"};
icon.iconSize = new GSize(16, 16);
icon.iconAnchor = new GPoint(5,5);
icon.infoWindowAnchor = new GPoint(5, 100);
    	A = Xp[i];
		B = Yp[i];
   var point = new GLatLng(A,B);
   map.addOverlay(new GMarker(point,icon));
                              }
}
							  
	      }
		  
GEvent.addListener(map, "click", function(marker, point) {
          if (marker){
       map.removeOverlay(marker);
                      } else {
j = j + 1;
asc[j] = point.lat().toFixed(4);
ord[j] = point.lng().toFixed(4);
//***************************
Ap = asc[j];
Bp = ord[j]; 
Msg = "Rotta N. " + j + " <---- NESSUNA SELEZIONE ----> ";
MsgT =" ";
document.nome_p.msg.value = "nessun porto selezionato";
document.tab_3.testo.value = MsgT;
porto = "/";
       for (var i = 0; i < Np+1; i++) with (Math){
       delt_1 = abs(Ap - Xp[i]).toFixed(4);
       delt_2 = abs(Bp - Yp[i]).toFixed(4);
       if (( delt_1 <= Max_d) && ( delt_2 <= Max_d)){
       porto = desc[i];
       display(Xp[i],Yp[i],porto); 
       
n = porto.length;
   if ( n >25 ){nome = porto.substring(0,24);}
        else nome = porto;
k = nome.length;		
m = 25 - k;
b = "  --------------- ";
filler = b.substring(0,m);       
MsgT = nome + filler + text[i];       
Msg = " Alla rotta N. " + j +" è' selezionato : " + porto;}
                         }
document.tab_2.msg.value = Msg;
document.tab_3.testo.value = MsgT;
//***************************
            map.addOverlay(new GMarker(point));
// Format	coordinate	
x = Math.floor(point.lat().toFixed(4));
 if ( x < 10){x=" " + x;} 
y = (point.lat().toFixed(4) - x) * 60;
r = y.toFixed(0);
 if ( r < 10){r=" " + r;}
lat = x + "°" + r + "'N";
x = Math.floor(point.lng().toFixed(4));
 if ( x < 10){x=" " + x;}
y = (point.lng().toFixed(4) - x) * 60;
r = y.toFixed(0);
 if ( r < 10){r=" " + r;}
lon = x + "°" + r + "'E ";
//
var id = prompt(" Coordinate punto " + " = " + j + "  " + asc[j] +"  " + ord[j] +"  ",'Digitare il nome del punto');
// Format nome
if (id == "Digitare il nome del punto"){id = "           ";}
if (porto != "/"){id = porto;}
n = id.length;
   if ( n >11 ){nome = id.substring(0,11);}
        else nome = id;
k = nome.length;		
m = 12 - k;
b = "  --------------- ";
filler = b.substring(0,m);

// distanza
var Cx = 0;
var Cy = 0;
var d = 0;
 if (j==1) {dist = "....";}
       else with(Math){
             Cy = (asc[j] - asc[j-1]) * 60;
			 Cx = (ord[j] - ord[j-1]) * 46.1583;
			 dist = sqrt((Cx*Cx)+(Cy*Cy)).toFixed(0);
			 d = parseFloat(dist);
			 sum = sum + d;
var A1=asc[j];
var B1=ord[j];
var A2=asc[j-1];
var B2=ord[j-1];		 
var polyline = new GPolyline([new GLatLng(A1,B1),new GLatLng(A2,B2)], "#000000", 2);
map.addOverlay(polyline);			 
			 }

// Format distanza
nd = dist.length;
b1 ="        ";
   if ( nd > 6){dist = "Errore";}
m = 6 - nd;
filler2 = b1.substring(0,m);   
//Rotta
var Tg = 0;
var alfa = 0;
          Tg = Cy/d;
		    alfa = (Math).acos(Tg);
	        rotta = parseFloat((alfa * 57.2958));
		  if (Cx <0){rotta = 360 - rotta;} 
		  rotta = rotta.toFixed(0);
          if (Tg > 1){rotta = "0";}              
		  if (Tg < -1){rotta = "180";}            

//Format Rotta	
nd = rotta.length;
m = 7 - nd;
filler3 = b1.substring(0,m);
//
//var kd=prompt("nd = " + nd + " Tg = " + Tg + "  alfa = " + alfa + " rotta = " + rotta)		  
//End Rotta

 	  
var dati = j + "  " + nome + filler + "  " + lat + "  " + lon + filler2 + dist + filler3 + rotta + "° ";
ndati = dati.length;
k = 50 - ndati;
var bl = "   ";
filler3 = bl.substring(0,k);
dati = dati + filler3;
tabella = tabella + dati;
document.tab_1.msg.value = tabella;
document.tab_2.msg.value = " Percorso totale " + sum + " Nm"; 

                 }
		});		 
}
	   
function display(Lati,Long,prt){

var map = new GMap2(document.getElementById("map_2"));
        map.addControl(new GMapTypeControl());
		  map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(Lati,Long),15);
        document.nome_p.msg.value = " " + prt;
GEvent.addListener(map, "click", function(marker, point) {
          if (marker){
       map.removeOverlay(marker);
       blk = "                                        ";
       document.wp.msg.value = blk;
                      } else {
       map.addOverlay(new GMarker(point));
var lat = 00;
var lon = 00;       
var x = Math.floor(point.lat().toFixed(2));
var y = (point.lat().toFixed(6) - x) * 60;
var r = y.toFixed(2);
var lat = "  " + x + "°" + r + "'N";

var x = Math.floor(point.lng().toFixed(2));
var y = (point.lng().toFixed(6) - x) * 60;
var r = y.toFixed(2);
var lon = x + "°" + r ;
document.wp.msg.value = lat +"  " + lon +"'E";
            }
});        
var icon = new GIcon();
nome = "../icone_mappe/prt.bmp";
icon.image = nome;
icon.iconSize = new GSize(16, 16);
icon.iconAnchor = new GPoint(5,5);
icon.infoWindowAnchor = new GPoint(5, 100);
    	A = Lati;
		B = Long;
   var point = new GLatLng(A,B);
   map.addOverlay(new GMarker(point,icon));

}

