
    function pesca(Np,flag,Xp,Yp,laC,loC,G,icn) {
//    alert("Questo programma è adatto per schermo 1024 x 768 con risoluzioni diverse si possono verificare disalineamenti nella tabella delle //rotte");
var asc = new Array();
var ord = new Array();	
var j = 0;
tabella = "    Nome   " + "      Coordinate  " + "   Miglia" + "  Rotta ";
var nd = 0;
var sum = 0;
var rotta = 0;
var dist = 0;


	    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(laC,loC),G);
//*********************************************************
if (flag == 1){
               for (var i = 0; i < Np+1; i++) {
var icon = new GIcon();
nome = icn[i];
icon.image = "../icone_mappe/" + nome +".bmp";
icon.iconSize = new GSize(16, 16);
icon.iconAnchor = new GPoint(10,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));
                              }
}
						  
//*************************************************************	
//*********************************************************
if (flag == 3){
               for (var i = 0; i < Np+1; i++) {
var icon = new GIcon();
a = icn[i];
icon.image = "../icone_mappe/p" + a +".bmp";
icon.iconSize = new GSize(16, 16);
icon.iconAnchor = new GPoint(5, 10);
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);
//alert("Questo punto è già incluso nella rotta")
                      } else {
j = j + 1;
asc[j] = point.lat().toFixed(4);
ord[j] = point.lng().toFixed(4);  		  
            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] +"°N" +" " + ord[j]+"°E",'Digitare il nome del punto');
// Format nome
n = id.length;
   if ( n >8 ){nome = id.substring(0,8);}
        else nome = id;
k = nome.length;		
m = 9 - 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;}

// 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;
if ((j==1)||(d<1)){rotta = "    ";}
      else{
          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 = 5 - 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.totali.somma.value = "Percorso totale in Miglia Nautiche = " + sum;

                 }
		});		 
}
	   

