
    function pesca_1(Nn,Np,Nr,flag,Xp,Yp,laC,loC,G,desc,Max_d,text) {
//*    
// Nn = zone di pesca + migratori e altri punti che non chiamano display()    
// Np = zone di pesca  quelle con descrizione iniziano con "§"
// Nr = numero di punti in totale 
// * ICONE
//** pxx = zone di pesca xx = da 1 a 99 se con descrizione nome = §nome
//** p00 = rotta migratori simbolo + 
//**  pp = porto normale      
//** r00 = riserve simbolo -       
//** r01 = avvisi simbolo :   
//**  rc = selezione simbolo #
//*
   
var asc = new Array();
var ord = new Array();	    
var j = 0;
tabella = "       Nome " + "         Coordinate " + "   Miglia" + "  Rotta \n";
var nd = 0;
var rotta = 0;
var dist = 0;
var sum = 0;
document.tab_1.msg.value = " Tabella delle tratte di rotta "; 
document.tab_2.msg.value = " Selezionare un punto o un porto per averne la descrizione ";
display(0,0," "," ");
	    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
//        map.addControl(new GMapTypeControl());
		  map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(laC,loC),G);
//**********************************
// 
// flag = -1 non presenta icone
//
//**********************************
if (flag == 1){
               for (var i = 0; i < Nr+1; i++) {
//** zone di pesca icona = da p1.bmp a p12.bmp
var a_nome = "pp";
i_p = i + 1;
  if (i <= Np ){ a_nome = "p" + i_p;}
         else   {a_nome = "pp";}      
    
nome = "../icone_mappe/" + a_nome + ".bmp";
//
//** p00 = rotta migratori simbolo + 
//**  pp = porto normale      
//** r00 = riserve simbolo -       
//** r01 = avvisi simbolo :   
//**  rc = selezione simbolo #
//
icp = desc[i].substring(0,1);
  if(icp == "+"){nome = "../icone_mappe/p00.bmp"};
  if(icp == "-"){nome = "../icone_mappe/r00.bmp"};
  if(icp == ":"){nome = "../icone_mappe/r01.bmp"}; 
  if(icp == "#"){display(Xp[i],Yp[i],desc[i],text[i]);}; 

//************** 
var icon = new GIcon();   
icon.image = nome;
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]; 
MsgT = "";
display(0,0," nessun porto selezionato"," ");
document.tab_3.testo.value = MsgT;
Msg = "Rotta N. " + j + " <---- NESSUNA SELEZIONE ----> ";
porto = "/";
       for (var i = 0; i < Nr+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];
//********      
       if ( i > Nn)  {display(Xp[i],Yp[i],porto,text[i]);}
//       
//* cod = § zone di pesca con descrizione
//
        cod = desc[i].substring(0,1);
        N_len = desc[i].length;
        
        if (cod == "+") {
        porto = porto.substring(1,N_len);
        display(0,0,porto,text[i]);}
        
        if (cod == ":") {
        porto = porto.substring(1,N_len);
        display(0,0,porto,text[i]);}
          
        if (cod == "§") {
        porto = porto.substring(1,N_len);
        display(0,0,porto,text[i]);}
          
        if (cod == "-") {
        porto = porto.substring(1,N_len);
        display(0,0,porto,text[i]);}  
    
//********
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;
//***************************
            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] +"  ");
var id = prompt(" 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 + "° \n";
ndati = dati.length;
k = 45 - 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,porto,tes){
document.tab_3.testo.value = tes;
document.wp.msg.value = " ";
document.nome_p.msg.value = "   " + porto;
            if (Lati != 0){
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 = "   " + porto;
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 = 0.0;
var lon = 0.0;       
var x = Math.floor(point.lat().toFixed(6));
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(6));
var y = (point.lng().toFixed(6) - x) * 60;
var r = y.toFixed(2);
var lon = "   " + x + "°" + r ;
document.wp.msg.value = lat +"  " + lon +"'E";
            }
});   
//
//* Presenta icona di selezione prt.bmp
//     
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));
}
//
//* Azzera map_2 
//
              if (Lati == 0){
  var map = new GMap2(document.getElementById("map_2"));
        map.setCenter(new GLatLng(0,0),15);
                    }      
}