<!--
//(c) 2006 Zonum Solutions
//Last modified: December 11,2006


 function zGeo_WGS84_a()
 {
   return 6378137;
 }

 function zGeo_WGS84_f()
 {
  return 1/298.2572236;
 }

 function zGeo_Datumb(a,f)
 {
  return a-(a*f);
 }

 function zGeo_Datume2(f)
 {
  return 2*f-(f*f);
 }

 function zGeo_GetUTMZones(UTMList,Cad)
 {  
  if(Cad=="") {Cad = "UTM Zone ";}
  for (i=1; i<61; i++){
   UTMList.options[UTMList.options.length]=new Option(Cad+i,"Zone");
  }
  UTMList.options.selectedIndex = 11;
 }


function zGeo_calcUTMZoneOld(Longitude)
 {
  var Zone = 12;
  if(Longitude<0) {Zone=Math.round((180+Longitude)/6)+1}
    else {Zone=Math.round(Longitude/6)+31};



  if(Zone>60) {Zone =60;}
  if(Zone<1) {Zone=1;}
  return Zone
 }

function zGeo_calcUTMZone(Longitude)
 {
  var Zone = 12;
  var cadTXT = ""
  cadTXT = " "+Longitude;
  Longitude = Longitude + 180;
  if(Longitude<=0) {Longitude = 1;}
  if(Longitude>359) {Longitude = 359;}

  cadTXT +=" "+Longitude;

   Zone=""+ ((Longitude/6)+1);

   
   //x = Zone.indexOf('.');
   //Zone = Zone.substring(1,x-1);
   //document.getElementById("message").innerHTML = cadTXT+ " Zone = " +Zone;
   Zone = parseInt(Zone);
  
  if(Zone>60) {Zone =60;}
  if(Zone<1) {Zone=1;}

  return Zone
 }

function zGeo_LatLon2UTM_pt(UTMZone,Lat,Lon)
 {
   var X = 0;
   var Y = 0;
     var isNorth = (Lat>0);
     

     ZoneCM=6*UTMZone-183;
     p=(Lon-ZoneCM)*3600/10000;
     Lat=Lat*Math.PI/180;  
     Lon=Lon*Math.PI/180;  
     
     b=Datum_b;
     a=Datum_a;

     e2=Datum_e2;

     e=Math.sqrt(e2);
     e2p=e2/(1-e2);
     k0=0.9996;
     sin1=Math.PI/(180*60*60);
     nu=a/Math.sqrt(1-e2*Math.pow(Math.sin(Lat),2));

     n=(a-b)/(a+b);

     Ap=a*(1-n+(5/4)*(Math.pow(n,2)-Math.pow(n,3))+(81/64)*(Math.pow(n,4)-Math.pow(n,5)));
     Bp=(3*a*n/2)*(1-n+(7/8)*(Math.pow(n,2)-Math.pow(n,3))+(55/64)*(Math.pow(n,4)-Math.pow(n,5)));
     Cp=(15*a*Math.pow(n,2)/16)*(1-n+(3/4)*(Math.pow(n,2)-Math.pow(n,3)));
     Dp=(35*a*Math.pow(n,3)/48)*(1-n+(11/16)*(Math.pow(n,2)-Math.pow(n,3)));
     Ep=(315*a*Math.pow(n,4)/51)*(1-n);
     S=Ap*Lat-Bp*Math.sin(2*Lat)+Cp*Math.sin(4*Lat)-Dp*Math.sin(6*Lat)+Ep*Math.sin(8*Lat);
   
     K1=S*k0;
     K2=k0*Math.pow(sin1,2)*nu*Math.sin(Lat)*Math.cos(Lat)*100000000/2;
     K3=(k0*Math.pow(sin1,4)*nu*Math.sin(Lat)*Math.pow(Math.cos(Lat),3)/24)*(5-Math.pow(Math.tan(Lat),2)+9*e2p*Math.pow(Math.cos(Lat),2)+4*e2p*e2p*Math.pow(Math.cos(Lat),4))*10000000000000000;
   
     Y=K1+K2*Math.pow(p,2)+K3*Math.pow(p,4);
     if(isNorth==false) {Y=10000000+Y};
     
     K4=k0*sin1*nu*Math.cos(Lat)*10000;
     K5=(k0*Math.pow(sin1,3)*nu*Math.pow(Math.cos(Lat),3)/6)*(1-Math.pow(Math.tan(Lat),2)+e2p*Math.pow(Math.cos(Lat),2))*1000000000000;

     X=500000+K4*p+K5*Math.pow(p,3);

    this.CY = Y;
    this.CX = X;
  }
  

function zGeo_LatLon2UTM(UTMZone,Lat,Long,csp)
 {
   var X = 0;
   var Y = 0;

     ZoneCM=6*UTMZone-183;
     p=(Long-ZoneCM)*3600/10000;
     Lat=Lat*Math.PI/180;  
     Long=Long*Math.PI/180;  
     
     b=Datum_b;
     a=Datum_a;

     e2=Datum_e2;

     e=Math.sqrt(e2);
     e2p=e2/(1-e2);
     k0=0.9996;
     sin1=Math.PI/(180*60*60);
     nu=a/Math.sqrt(1-e2*Math.pow(Math.sin(Lat),2));

     n=(a-b)/(a+b);

     Ap=a*(1-n+(5/4)*(Math.pow(n,2)-Math.pow(n,3))+(81/64)*(Math.pow(n,4)-Math.pow(n,5)));
     Bp=(3*a*n/2)*(1-n+(7/8)*(Math.pow(n,2)-Math.pow(n,3))+(55/64)*(Math.pow(n,4)-Math.pow(n,5)));
     Cp=(15*a*Math.pow(n,2)/16)*(1-n+(3/4)*(Math.pow(n,2)-Math.pow(n,3)));
     Dp=(35*a*Math.pow(n,3)/48)*(1-n+(11/16)*(Math.pow(n,2)-Math.pow(n,3)));
     Ep=(315*a*Math.pow(n,4)/51)*(1-n);
     S=Ap*Lat-Bp*Math.sin(2*Lat)+Cp*Math.sin(4*Lat)-Dp*Math.sin(6*Lat)+Ep*Math.sin(8*Lat);
   
     K1=S*k0;
     K2=k0*Math.pow(sin1,2)*nu*Math.sin(Lat)*Math.cos(Lat)*100000000/2;
     K3=(k0*Math.pow(sin1,4)*nu*Math.sin(Lat)*Math.pow(Math.cos(Lat),3)/24)*(5-Math.pow(Math.tan(Lat),2)+9*e2p*Math.pow(Math.cos(Lat),2)+4*e2p*e2p*Math.pow(Math.cos(Lat),4))*10000000000000000;
   
     Y=K1+K2*Math.pow(p,2)+K3*Math.pow(p,4);
     
     K4=k0*sin1*nu*Math.cos(Lat)*10000;
     K5=(k0*Math.pow(sin1,3)*nu*Math.pow(Math.cos(Lat),3)/6)*(1-Math.pow(Math.tan(Lat),2)+e2p*Math.pow(Math.cos(Lat),2))*1000000000000;

     X=500000+K4*p+K5*Math.pow(p,3);

    return X+csp+Y;
  }

function zGeo_LatLon2UTM2(UTMZone,Lat,Lon,csp)
 {
     
     var pt =  new zGeo_LatLon2UTM_pt(UTMZone,Lat,Lon);
     var X = parseInt(""+pt.CX);
     var Y = parseInt(""+pt.CY);

     var isNorth = (Lat>0);
     var isWest = (Lon<0);

    if(isWest==true) {X= "" + X +" W"; } else {X=""+X+" E";} 
    if(isNorth==true) {Y="" + Y +" N";} else {Y=""+Y+" S";}
    return X+csp+Y;
  }



  function UTM2LatLon(UTMZone,isNorth,X,Y)
 
   {
     if(isNorth==false) {Y=10000000-Y;}
     var Lat = 0;
     var Lon = 0;
     
     e2=Datum_e2;
     e=Math.sqrt(e2);
     k0=0.9996;
     long0=6*UTMZone-183;
     
     X=500000-X;
     M=Y/k0;
     mu=M/(Datum_a*(1-Math.pow(e,2)/4-3*Math.pow(e,4)/64-5*Math.pow(e,6)/256));
     e1=(1-Math.sqrt(1-Math.pow(e,2)))/(1+Math.sqrt(1-Math.pow(e,2)));
     J1=(3*e1/2-27*Math.pow(e1,3)/32);
     J2=(21*Math.pow(e1,2)/16-55*Math.pow(e1,4)/32);
     J3=151*Math.pow(e1,3)/96;
     J4=1097*Math.pow(e1,4)/512;

     fp=mu+J1*Math.sin(2*mu)+J2*Math.sin(4*mu)+J3*Math.sin(6*mu)+J4*Math.sin(8*mu);

     e2p=Math.pow((e*Datum_a/Datum_b),2);
     C1=e2p*Math.pow(Math.cos(fp),2);
     T1=Math.pow(Math.tan(fp),2);

     R1=Datum_a*(1-e2)/Math.pow((1-e2*Math.pow(Math.sin(fp),2)),3/2);
     N1=Datum_a/Math.sqrt(1-e2*Math.pow(Math.sin(fp),2));
     D=X/(N1*k0);

     Q1=N1*Math.tan(fp)/R1;
     Q2=Math.pow(D,2)/2;
     Q3=(5+3*T1+10*C1-4*Math.pow(C1,2)-9*e2p)*Math.pow(D,4)/24;
     Q4=(61+90*T1+298*C1+45*Math.pow(T1,2)-3*Math.pow(C1,2)-252*e2p)*Math.pow(D,6)/720;
     Lat=fp-Q1*(Q2-Q3+Q4);
     Lat=180*Lat/Math.PI;

     if(isNorth==false) {Lat = Lat*-1;}

     Q5=D;
     Q6=(1+2*T1+C1)*Math.pow(D,3)/6;
     Q7=(5-2*C1+28*T1-3*Math.pow(C1,2)+8*e2p+24*Math.pow(T1,2))*Math.pow(D,5)/120;
     Lon=(Q5-Q6+Q7)/Math.cos(fp);
     Lon=(Lon*180/Math.PI)-long0;
     if(UTMZone<=30) {Lon=-1*Lon;} else {Lon = Math.abs(Lon);}

     //Lat = "" + Lat + ", " + Long;

     //return Lat
     this.Lat = Lat;
     this.Lon = Lon;
   }


 //Improved function for South Hemisphere
 //Feb 17, 2009
 
 
 function zGeo2_LatLon2UTM_pt(Lat,Lon,UTMZone,isNorth)
 {
   var X = 0;
   var Y = 0;
     
     ZoneCM=6*UTMZone-183;
     p=(Lon-ZoneCM)*3600/10000;
     Lat=Lat*Math.PI/180;  
     Lon=Lon*Math.PI/180;  
     
     b=Datum_b;
     a=Datum_a;

     e2=Datum_e2;

     e=Math.sqrt(e2);
     e2p=e2/(1-e2);
     k0=0.9996;
     sin1=Math.PI/(180*60*60);
     nu=a/Math.sqrt(1-e2*Math.pow(Math.sin(Lat),2));

     n=(a-b)/(a+b);

     Ap=a*(1-n+(5/4)*(Math.pow(n,2)-Math.pow(n,3))+(81/64)*(Math.pow(n,4)-Math.pow(n,5)));
     Bp=(3*a*n/2)*(1-n+(7/8)*(Math.pow(n,2)-Math.pow(n,3))+(55/64)*(Math.pow(n,4)-Math.pow(n,5)));
     Cp=(15*a*Math.pow(n,2)/16)*(1-n+(3/4)*(Math.pow(n,2)-Math.pow(n,3)));
     Dp=(35*a*Math.pow(n,3)/48)*(1-n+(11/16)*(Math.pow(n,2)-Math.pow(n,3)));
     Ep=(315*a*Math.pow(n,4)/51)*(1-n);
     S=Ap*Lat-Bp*Math.sin(2*Lat)+Cp*Math.sin(4*Lat)-Dp*Math.sin(6*Lat)+Ep*Math.sin(8*Lat);
   
     K1=S*k0;
     K2=k0*Math.pow(sin1,2)*nu*Math.sin(Lat)*Math.cos(Lat)*100000000/2;
     K3=(k0*Math.pow(sin1,4)*nu*Math.sin(Lat)*Math.pow(Math.cos(Lat),3)/24)*(5-Math.pow(Math.tan(Lat),2)+9*e2p*Math.pow(Math.cos(Lat),2)+4*e2p*e2p*Math.pow(Math.cos(Lat),4))*10000000000000000;
   
     Y=K1+K2*Math.pow(p,2)+K3*Math.pow(p,4);
     if(isNorth==false) {Y=10000000+Y};
     
     K4=k0*sin1*nu*Math.cos(Lat)*10000;
     K5=(k0*Math.pow(sin1,3)*nu*Math.pow(Math.cos(Lat),3)/6)*(1-Math.pow(Math.tan(Lat),2)+e2p*Math.pow(Math.cos(Lat),2))*1000000000000;

     X=500000+K4*p+K5*Math.pow(p,3);

    this.CY = Y;
    this.CX = X;
  }
 

 function zGeo2_LatLon2UTM_format(UTMZone,Lat,Lon,csp)
 {     
     var pt = new zGeo2_LatLon2UTM_pt(Lat,Lon,UTMZone,(Lat>=0));
     var X = parseInt(""+pt.CX);
     var Y = parseInt(""+pt.CY);

     var isNorth = (Lat>0);
     var isWest = (Lon<0);

    if(isWest==true) {X= "" + X +" E"; } else {X=""+X+" E";} 
    if(isNorth==true) {Y="" + Y +" N";} else {Y=""+Y+" S";}
    return X+csp+Y;
  }
 
 
 function zGeo2_LatLon2UTM(Lat,Lon,csp,UTMZone,isNorth)
 {
    var pt = new zGeo2_LatLon2UTM_pt(Lat,Lon,UTMZone,isNorth);
    return pt.CX+csp+pt.CY;
  }



-->