var pi=3.14159265358979;var sm_a=6378137;var sm_b=6356752.314;var sm_EccSquared=0.00669437999013;var UTMScaleFactor=0.9996;function DegToRad(deg){return(deg/180*pi)}function RadToDeg(rad){return(rad/pi*180)}function ArcLengthOfMeridian(phi){var alpha,beta,gamma,delta,epsilon,n;var result;n=(sm_a-sm_b)/(sm_a+sm_b);alpha=((sm_a+sm_b)/2)*(1+(Math.pow(n,2)/4)+(Math.pow(n,4)/64));beta=(-3*n/2)+(9*Math.pow(n,3)/16)+(-3*Math.pow(n,5)/32);gamma=(15*Math.pow(n,2)/16)+(-15*Math.pow(n,4)/32);delta=(-35*Math.pow(n,3)/48)+(105*Math.pow(n,5)/256);epsilon=(315*Math.pow(n,4)/512);result=alpha*(phi+(beta*Math.sin(2*phi))+(gamma*Math.sin(4*phi))+(delta*Math.sin(6*phi))+(epsilon*Math.sin(8*phi)));return result}function UTMCentralMeridian(zone){var cmeridian;cmeridian=DegToRad(-183+(zone*6));return cmeridian}function FootpointLatitude(y){var y_,alpha_,beta_,gamma_,delta_,epsilon_,n;var result;n=(sm_a-sm_b)/(sm_a+sm_b);alpha_=((sm_a+sm_b)/2)*(1+(Math.pow(n,2)/4)+(Math.pow(n,4)/64));y_=y/alpha_;beta_=(3*n/2)+(-27*Math.pow(n,3)/32)+(269*Math.pow(n,5)/512);gamma_=(21*Math.pow(n,2)/16)+(-55*Math.pow(n,4)/32);delta_=(151*Math.pow(n,3)/96)+(-417*Math.pow(n,5)/128);epsilon_=(1097*Math.pow(n,4)/512);result=y_+(beta_*Math.sin(2*y_))+(gamma_*Math.sin(4*y_))+(delta_*Math.sin(6*y_))+(epsilon_*Math.sin(8*y_));return result}function MapLatLonToXY(phi,lambda,lambda0,xy){var N,nu2,ep2,t,t2,l;var l3coef,l4coef,l5coef,l6coef,l7coef,l8coef;var tmp;ep2=(Math.pow(sm_a,2)-Math.pow(sm_b,2))/Math.pow(sm_b,2);nu2=ep2*Math.pow(Math.cos(phi),2);N=Math.pow(sm_a,2)/(sm_b*Math.sqrt(1+nu2));t=Math.tan(phi);t2=t*t;tmp=(t2*t2*t2)-Math.pow(t,6);l=lambda-lambda0;l3coef=1-t2+nu2;l4coef=5-t2+9*nu2+4*(nu2*nu2);l5coef=5-18*t2+(t2*t2)+14*nu2-58*t2*nu2;l6coef=61-58*t2+(t2*t2)+270*nu2-330*t2*nu2;l7coef=61-479*t2+179*(t2*t2)-(t2*t2*t2);l8coef=1385-3111*t2+543*(t2*t2)-(t2*t2*t2);xy[0]=N*Math.cos(phi)*l+(N/6*Math.pow(Math.cos(phi),3)*l3coef*Math.pow(l,3))+(N/120*Math.pow(Math.cos(phi),5)*l5coef*Math.pow(l,5))+(N/5040*Math.pow(Math.cos(phi),7)*l7coef*Math.pow(l,7));xy[1]=ArcLengthOfMeridian(phi)+(t/2*N*Math.pow(Math.cos(phi),2)*Math.pow(l,2))+(t/24*N*Math.pow(Math.cos(phi),4)*l4coef*Math.pow(l,4))+(t/720*N*Math.pow(Math.cos(phi),6)*l6coef*Math.pow(l,6))+(t/40320*N*Math.pow(Math.cos(phi),8)*l8coef*Math.pow(l,8));return}function MapXYToLatLon(x,y,lambda0,philambda){var phif,Nf,Nfpow,nuf2,ep2,tf,tf2,tf4,cf;var x1frac,x2frac,x3frac,x4frac,x5frac,x6frac,x7frac,x8frac;var x2poly,x3poly,x4poly,x5poly,x6poly,x7poly,x8poly;phif=FootpointLatitude(y);ep2=(Math.pow(sm_a,2)-Math.pow(sm_b,2))/Math.pow(sm_b,2);cf=Math.cos(phif);nuf2=ep2*Math.pow(cf,2);Nf=Math.pow(sm_a,2)/(sm_b*Math.sqrt(1+nuf2));Nfpow=Nf;tf=Math.tan(phif);tf2=tf*tf;tf4=tf2*tf2;x1frac=1/(Nfpow*cf);Nfpow*=Nf;x2frac=tf/(2*Nfpow);Nfpow*=Nf;x3frac=1/(6*Nfpow*cf);Nfpow*=Nf;x4frac=tf/(24*Nfpow);Nfpow*=Nf;x5frac=1/(120*Nfpow*cf);Nfpow*=Nf;x6frac=tf/(720*Nfpow);Nfpow*=Nf;x7frac=1/(5040*Nfpow*cf);Nfpow*=Nf;x8frac=tf/(40320*Nfpow);x2poly=-1-nuf2;x3poly=-1-2*tf2-nuf2;x4poly=5+3*tf2+6*nuf2-6*tf2*nuf2-3*(nuf2*nuf2)-9*tf2*(nuf2*nuf2);x5poly=5+28*tf2+24*tf4+6*nuf2+8*tf2*nuf2;x6poly=-61-90*tf2-45*tf4-107*nuf2+162*tf2*nuf2;x7poly=-61-662*tf2-1320*tf4-720*(tf4*tf2);x8poly=1385+3633*tf2+4095*tf4+1575*(tf4*tf2);philambda[0]=phif+x2frac*x2poly*(x*x)+x4frac*x4poly*Math.pow(x,4)+x6frac*x6poly*Math.pow(x,6)+x8frac*x8poly*Math.pow(x,8);philambda[1]=lambda0+x1frac*x+x3frac*x3poly*Math.pow(x,3)+x5frac*x5poly*Math.pow(x,5)+x7frac*x7poly*Math.pow(x,7);return}function LatLonToUTMXY(lat,lon,zone,xy){MapLatLonToXY(lat,lon,UTMCentralMeridian(zone),xy);xy[0]=xy[0]*UTMScaleFactor+500000;xy[1]=xy[1]*UTMScaleFactor;if(xy[1]<0){xy[1]=xy[1]+10000000}return zone}function UTMXYToLatLon(x,y,zone,southhemi,latlon){var cmeridian;x-=500000;x/=UTMScaleFactor;if(southhemi){y-=10000000}y/=UTMScaleFactor;cmeridian=UTMCentralMeridian(zone);MapXYToLatLon(x,y,cmeridian,latlon);return}function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas){if(isNaN(parseInt(num))){return"NaN"}var tmpNum=num;var iSign=num<0?-1:1;tmpNum=Math.round(tmpNum*Math.pow(10,decimalNum))/Math.pow(10,decimalNum);var tmpNumStr=new String(tmpNum);if(!bolLeadingZero&&num<1&&num>-1&&num!=0){if(num>0){tmpNumStr=tmpNumStr.substring(1,tmpNumStr.length)}else{tmpNumStr="-"+tmpNumStr.substring(2,tmpNumStr.length)}}if(bolCommas&&(num>=1000||num<=-1000)){var iStart=tmpNumStr.indexOf(".");if(iStart<0){iStart=tmpNumStr.length}iStart-=3;while(iStart>=1){tmpNumStr=tmpNumStr.substring(0,iStart)+","+tmpNumStr.substring(iStart,tmpNumStr.length);iStart-=3}}if(bolParens&&num<0){tmpNumStr="("+tmpNumStr.substring(1,tmpNumStr.length)+")"}return tmpNumStr}function convertutm(zone,easting,northing){var latlon=new Array(2);var lathemi,lonhemi;UTMXYToLatLon(easting,northing,zone,0,latlon);if(latlon[0]>0){lathemi="N"}else{lathemi="S"}if(latlon[1]>0){lonhemi="E"}else{lonhemi="W"}return" "+FormatNumber(Math.abs(RadToDeg(latlon[0])),4,true,false,false)+"\u00B0"+lathemi+" "+FormatNumber(Math.abs(RadToDeg(latlon[1])),4,true,false,false)+"\u00B0"+lonhemi}function CalculateDistanceInMeters(lat1,lon1,lat2,lon2){var EARTH_RADIUS=6367000;var a=DegToRad(90-lat1);var b=DegToRad(90-lat2);var theta=DegToRad(lon2-lon1);var c=Math.acos(Math.cos(a)*Math.cos(b)+Math.sin(a)*Math.sin(b)*Math.cos(theta));return c*EARTH_RADIUS}function UpdateLatLonFormat(format){switch(format){case"dd":document.getElementById("center-point").innerHTML=FormatNumber(centerLat,4,true,false,false)+"&deg;N "+FormatNumber(Math.abs(centerLon),4,true,false,false)+"&deg;W ";document.getElementById(lnkPrintPortraitID).href=document.getElementById(lnkPrintPortraitID).href.replace("&co="+coordinateoutput,"&co=dd");document.getElementById(lnkPrintLandscapeID).href=document.getElementById(lnkPrintLandscapeID).href.replace("&co="+coordinateoutput,"&co=dd");coordinateoutput="dd";break;case"ddm":document.getElementById("center-point").innerHTML=DDtoDDM(centerLat)+" N "+DDtoDDM(centerLon)+" W";document.getElementById(lnkPrintPortraitID).href=document.getElementById(lnkPrintPortraitID).href.replace("&co="+coordinateoutput,"&co=ddm");document.getElementById(lnkPrintLandscapeID).href=document.getElementById(lnkPrintLandscapeID).href.replace("&co="+coordinateoutput,"&co=ddm");coordinateoutput="ddm";break;case"dms":document.getElementById("center-point").innerHTML=DDtoDMS(centerLat)+" N "+DDtoDMS(centerLon)+" W";document.getElementById(lnkPrintPortraitID).href=document.getElementById(lnkPrintPortraitID).href.replace("&co="+coordinateoutput,"&co=dms");document.getElementById(lnkPrintLandscapeID).href=document.getElementById(lnkPrintLandscapeID).href.replace("&co="+coordinateoutput,"&co=dms");coordinateoutput="dms";break;case"utm":document.getElementById("center-point").innerHTML="UTM Zone "+UTMzone+" "+Math.round(easting)+"E "+Math.round(northing)+"N";document.getElementById(lnkPrintPortraitID).href=document.getElementById(lnkPrintPortraitID).href.replace("&co="+coordinateoutput,"&co=utm");document.getElementById(lnkPrintLandscapeID).href=document.getElementById(lnkPrintLandscapeID).href.replace("&co="+coordinateoutput,"&co=utm");coordinateoutput="utm";break;default:document.getElementById("center-point").innerHTML=FormatNumber(centerLat,4,true,false,false)+"&deg;N "+FormatNumber(Math.abs(centerLon),4,true,false,false)+"&deg;W ";document.getElementById(lnkPrintPortraitID).href=document.getElementById(lnkPrintPortraitID).href.replace("&co="+coordinateoutput,"&co=dd");document.getElementById(lnkPrintLandscapeID).href=document.getElementById(lnkPrintLandscapeID).href.replace("&co="+coordinateoutput,"&co=dd");coordinateoutput="dd"}return}function DDtoDMS(dd){var decimaldegrees=Math.abs(dd);var degrees,minutes,seconds;var DMS;degrees=parseInt(decimaldegrees);minutes=(decimaldegrees-degrees)*60;seconds=(minutes-parseInt(minutes))*60;DMS=degrees+"&deg;N "+parseInt(minutes)+"' "+FormatNumber(seconds,2,true,false,false)+'"';return DMS}function DDtoDDM(dd){var decimaldegrees=Math.abs(dd);var degrees,minutes;var DDM;degrees=parseInt(decimaldegrees);minutes=(decimaldegrees-degrees)*60;DDM=degrees+"&deg;N "+FormatNumber(minutes,2,true,false,false)+"'";return DDM};