<!--
//(c) 2009 Zonum Solutions
//Last modified: January 31, 2009
//Digipoint library 






 function TbEdit()
  {
    var menu1="";
    menu1=addBtn('btn1','New',"app_new()")+'&nbsp;&nbsp;';
    menu1+=addBtn('btn2','Actions',"appImport()",false)+'&nbsp;&nbsp;|&nbsp;&nbsp;'; 
    //menu1+=addCombo('ComboIcon','Small|Median|Normal|Big','none()')+'&nbsp;&nbsp;|&nbsp;&nbsp;';
	  menu1+='When map-click ';
		menu1+=addCombo('ComboAction','Add Point|Delete Point|Edit Label|View Elevation','app_changeAction(this)',optAction)+'</div>';
    changeToolbar(menu1);
    setmsg("");
  }


 function TbExport()
  {
  var menu1="Format: ";
    menu1+=addBtn('btn0','Options',"appOptions()")+'&nbsp;&nbsp;';
    menu1+=addBtn('btn1','CSV',"app_run('CSV')");
    menu1+=addBtn('btn2','TXT',"app_run('TXT')");
	  menu1+=addBtn('btn3','TAB',"app_run('TAB')");
	  menu1+=addBtn('btn4','BLN',"app_run('BLN')");
	  menu1+=addBtn('btn5','DXF',"app_run('DXF')");
	  menu1+=addBtn('btn6','KML',"app_run('KML')");
	  //menu1+=addBtnE('btn7','KMZ',"app_run('KMZ')",false);
	  menu1+=addBtn('btn8','GPX',"app_run('GPX')");
	  menu1+=addBtn('btn9','SHP',"app_run('SHP')",true);
   changeToolbar(menu1);
   setmsg("Setup Export Options and Format");
  }

 function TbMap()
  {
    var menu1="";
	  menu1+=addBtn('btnFly','Fly To',"flyto()")+'&nbsp;&nbsp;';
	  menu1+=addBtn('btnHybrid','Terrain',"changemaptype(G_PHYSICAL_MAP)");
	  menu1+=addBtn('btnMap','Map',"changemaptype(G_NORMAL_MAP)");
	  menu1+=addBtn('btnSat','Satellite',"changemaptype(G_SATELLITE_MAP)");
	  menu1+=addBtn('btnHybrid','Hybrid',"changemaptype(G_HYBRID_MAP)");
	  menu1+=addCheck('zoompan',"Zoom/Pan","changezzoom(this.checked)",(map_zoom==true));
	  menu1+=addCheck('scalebar',"Scale Bar","changezscale(this.checked)",(map_scale==true));
	  menu1+=addCheck('overviewmap',"Overview Map","changezoview(this.checked)",(map_oview==true));
    changeToolbar(menu1);
    setmsg("Select Map Controls");
  }


  function TbPointer()
  {
    var menu1="Coordinates: ";
	  menu1+=addRadio('optPointer',"UTM (meters)","changePointer(0)",(CursorOpt==0));
	  menu1+=addRadio('optPointer',"Lat/Lon Decimal","changePointer(1)",(CursorOpt==1));
	  menu1+=addRadio('optPointer',"Deg-Min-Sec","changePointer(2)",(CursorOpt==2));
	  menu1+='&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;Elevation ';
		menu1+=addCombo('ComboElev','Meters|Feet','changePointer_Elev(this)',CursorElev);
    changeToolbar(menu1);
    setmsg("Set Pointer Coordinates Display");
  }

  function TbHelp()
  {
    var menu1="&nbsp;&nbsp;&nbsp;";
    menu1+=addBtn('Btn1','Disclaimer',"zfr_disclaimer()");
	  menu1+=addBtn('Btn2','Comments',"appComments();");
	  menu1+=addBtn('Btn4','Forum',"appForum();",false);
	  menu1+=addBtn('Btn4','Help',"appHelp();");
	  
	  menu1+=addBtn('Btn5','About',"appAbout();")+'&nbsp;&nbsp;';
	  menu1+=addBtn('Btn6','Donate',"appDonate()");
	  changeToolbar(menu1);
	  setmsg("Help sources");
  }

function zif(condition,cadtrue,cadfalse)
 {
  if(condition==true) {return cadtrue;} else {return cadfalse;}
 }

 function tab_menu(id)
  {
   for(var i=1; i<6; i++) {
    var myitem=getmyobj("tabitem"+i);
    myitem.className="";
   }
   
   var myitem=getmyobj("tabitem"+id);
   myitem.className+="active";
  switch (id) {
   case 1: TbEdit(); break;
   case 2: TbExport(); break;
   case 3: TbMap(); break;
   case 4: TbPointer(); break;
   case 5: TbHelp(); break;
  }
 }
 
  function setmsg(cad)
  {
   var toolbar=getmyobj("divmessage");
   toolbar.innerHTML='&nbsp;&nbsp;'+cad;
  }

 function changeToolbar(cad)
  {
   var toolbar=getmyobj("divToolbar");
   toolbar.innerHTML='&nbsp;&nbsp;'+cad;
  }
  

 function appOnLoad(como)
 {
   TbHelp();
   initMap();
   setmsg("<b>(c)2010 Zonum Solutions</b>");
   appNews();
 }
 

 function resize_map()
 {
 
  var info = new zget_winsize();
  var xw = 800-205;
  var xh = 550-65;

  if(info.clientWidth>800) {xw = info.clientWidth - 205;}
  if(info.clientHeight>550) {xh = info.clientHeight - 65;}

  zset_resize("divToolbar",info.clientWidth-155,25);
  
  zset_resize("divTOC",200,xh-37); //xh-37
  zset_resize("map",xw,xh);
	document.frTOC.pts.style.height = ""+(xh-280)+"px";

  
	var obj =zdoc_get("adsBottom");
  obj.style.top = ""+(xh-202)+"px";
  var obj =zdoc_get("adsTop");
  if(myad<3) {obj.style.left = ""+(xw+200-myadLen)+"px";}

  //setmsg("size:"+info.clientWidth+":"+info.clientHeight+" myadlen="+myadLen);
  
 }

 function initMap()
  {
     window.resizeTo(screen.availWidth,screen.availHeight);
     window.moveTo(0, 0);
     resize_map();
     if(myad==3) {   
     var obj =zdoc_get("adsTop");
     obj.style.zIndex=999999; 
    }
     //var obj =zdoc_get("divmessage");
     //if(!es_MSI()) { obj.style.left = "625px";}

     map = new GMap2(document.getElementById("map"));   
     changemaptype(G_PHYSICAL_MAP);
		 map.addControl(omc);       
     map.addControl(smc);
     map.addControl(sc);
     
       
      GEvent.addListener(map, "click",
                                       function(overlay, point) {
                                          zmapclick(overlay, point);
        });
      GEvent.addListener(map, "mousemove", function(point) {zmouse_move(point);}); 
      

       map.setCenter(new GLatLng(24, 0), 3);
      map.enableContinuousZoom();
     map.enableScrollWheelZoom();
     zweb_setindex(document.frTOC.ComboSymbolSize,1);
      app_setIcon(zIconId);
    // appNews();
  }

 function app_changeAction(e)
 {
   optAction = zweb_listIndex(e);
   lastMensaje="";
 } 

 function changePointer(id)
 {
   CursorOpt=id;
   setmsg("Move mouse over map to see the change");
  }
 
 function changePointer_Elev(e)
  {
   CursorElev=zweb_listIndex(e);
   setmsg("");
  }


 function app_elevationMode()
 {
  AddElevation = document.frTOC.storeElev.checked;
 }

 
 function app_new()
  {
    var combolist=document.frTOC.pts;
    if(combolist.options.length>0) {
      if(confirm("Actual information will be lost!")) {
        clearnodes();
        setmsg("Blank Document");
     }
    } 
  }
  
 function appComments()
 { 
  zfr_comments('Digipoint 3');
 }

 function appAbout()
 {
   var MSG = "<center><b>DigiPoint 3</b><br>Digitize and export your XYZ values";
   MSG+="<br>Build: 3-28.02.10<br><br>(c) 2006-2010 Zonum Solutions</center>";
   zwin_msgbox("&nbsp;About",300,110,"","",MSG);
 }


 function appNews()
 {
   var MSG = "<center><b>DigiPoint 3</b><br>Last modified: 3-28.02.10";
   MSG+="<br><br><a href=\"javascript:appWhatsNew()\">What's new</a></center>";
   MSG+='<br><center>Related Application: <a href="maptool.php">MapTool 2</a><br>';
   MSG+='<i>(Location, Areas, Distances, Profiles, etc) </i></center>';
   zwin_msgbox("&nbsp;News",310,170,"","",MSG);
 }

 function appWhatsNew()
  {
   Send_ResultWindow("digipoint.php?action=help&topic=whatsnew","help");
  }


 function appHelp()
  {
   Send_ResultWindow("digipoint.php?action=help","help");
  }

 function appForum()
  {
   Send_ResultWindow("http://forums.zonums.com/epanet","forum");
  } 

 function appDonate()
  {
   Send_ResultWindow("http://www.zonums.com/donate.php?id=digipoint","help");
  }

 function app_changeicon()
 {
  setmsg("Retrieving Icons List...");
  GE_SelectIcon('app_setIcon',zIconId);
  setmsg("");
 }

 function app_setIcon(Id)
 { zIconId = parseInt(""+Id);
   zIconName = GE_Icon_GetUrl(zIconId);
  var obj = zdoc_get("GE_Symbol");
  obj.innerHTML = '<img border="0"  width="24px" height="24px" src="'+GE_Icon_GetUrl(zIconId)+'" alt="Click here to change Icon" />';
 }


 function getcoordsMouse(point,showUTM)
 { 
   var outcoo = "";
   if(showUTM==true) {
       UTMZone = zGeo_calcUTMZone(point.lng());
       outcoo = zGeo2_LatLon2UTM_format(UTMZone,point.lat(),point.lng(),", ");
       outcoo = outcoo + " Zone " +UTMZone; 
   } else {outcoo = "Lat/Lon: "+point.toUrlValue();}
  return outcoo;
 } 


 function getDMSold(coo)
 {
  coo = "f" + coo;
  var x = coo.indexOf('.');
  var degree = coo.substring(1,x);
  coo = coo.substring(x,coo.length);

  coo = parseFloat(coo)*60.0;
  coo = "" + coo;
  x = coo.indexOf('.');
  var min = coo.substring(1,x);
  coo = coo.substring(x,coo.length);

  coo = parseFloat(coo)*60.0;
  var seg = "" + coo.toFixed(1);
   
  degree = degree + "&deg; "+min+"' "+seg+'"';

  return degree
  
 }
 
 function getDMS(coo)
 {
  coo = "f" + coo;
  if(coo!=0) {
  var x = coo.indexOf('.');
  var degree = coo.substring(1,x);
  coo = coo.substring(x,coo.length);

  coo = parseFloat(coo)*60.0;
  coo = "" + coo;
  x = coo.indexOf('.');
  var min = coo.substring(0,x);
  coo = coo.substring(x,coo.length);

  coo = parseFloat(coo)*60.0;
  var seg = "" + coo.toFixed(1);
  }
  
  if(degree=="") {degree="0";}
  if(min=="") {min ="0";}
  if(seg=="") {seg="0";}
   
  degree = degree + "&deg; "+min+"' "+seg+'"';

  return degree
 }


 function zmouse_move(point)
 {
   if(lastMensaje=="") {
   if(optAction<2) {
   var line = "";

   if(CursorOpt==2) {
    line = getDMS(point.lat())+" &nbsp;&nbsp;"+getDMS(point.lng());
    } else {
      var showUTM = (CursorOpt==0);
      line = getcoordsMouse(point,showUTM);
   }

   setmsg(line); 
  }
  }
 }

 
 function appOptions()
 {
  var xwidth = 370;
  var yheight = 160;
  var wc = new zget_centerwin(xwidth,yheight);
  
  zset_win1("<b>&nbsp;Export Options</b>",wc.left,wc.top,xwidth,yheight,"#eff3f7","#0956A6");

  var obj = zdoc_get("zfrwin");
  var cadena ='<div style="position:absolute; left:2px; top:5px; width:360px; font-family: Arial, Helvetica, sans-serif; font-size: 9pt;overflow:auto;"/>';

   cadena +='<center><form name="frCoo">';
   cadena +='<fieldset style="width:330px"><Legend> Coordinate System</Legend>';
   cadena +='<table><tr><td><select name="Geosystem" onchange="enabledUTM()" style="width:180px">';
   cadena +='<option value="item">UTM (meters)</option> <option value="item">Latitude/Longitude</option></select>';
   cadena +='&nbsp;&nbsp;&nbsp;&nbsp;Elevation&nbsp;<select name="Elev">';
   cadena +='<option value="item">Meters</option> <option value="item">Feet</option></select></td></tr>';
   cadena +='<tr><td><select name="UTMZone" style="width:80px"></select>';
   cadena +='<input type="button" name="btUTMGrid" value="?" onclick="help_UTM()" style="width:30px"/>';
   cadena +='&nbsp;&nbsp;<select name="Hemisp" style="width:200px">';
   cadena +='<option value="item">Northern Hemisphere</option> <option value="item">Southern Hemisphere</option></select>';
   cadena +='</td></tr></table></fieldset>';
  
  // cadena +='<div style="position:absolute; left:3px; top:60px;">'; 
	if(es_MSI()) {cadena +='<br>';}   
   cadena +='<br>&nbsp;&nbsp;&nbsp;';
   cadena +='<input type="button" name="btAccept" value="Accept" onClick="appAccept_Export()"/>';
   cadena +='&nbsp;&nbsp;&nbsp;<input type="button" name="btCancel" value="Cancel" onClick="zclose_zwin()"/></div></form></center>';

   obj.innerHTML = cadena;
   AddUTMZones();
   zweb_setindex(document.frCoo.UTMZone,UTMZoneOpt-1);
   zweb_setindex(document.frCoo.Geosystem,LatLonOpt-1);
   zweb_setindex(document.frCoo.Hemisp,HemispOpt-1);
   zweb_setindex(document.frCoo.Elev,ElevUnits);
   enabledUTM();
 
 }

 function appAccept_Export()
 {
   UTMZoneOpt = zweb_listIndex(document.frCoo.UTMZone) +1;
   LatLonOpt = zweb_listIndex(document.frCoo.Geosystem) +1;
   HemispOpt = zweb_listIndex(document.frCoo.Hemisp) +1 ;
   ElevUnits = zweb_listIndex(document.frCoo.Elev);
   zclose_zwin();
  }


 function help_UTM()
  {
   Send_ResultWindow(zweb_getlink('UTM_GRID'),'help');
  }


 function Link_Child_data(data)
  {
    var myfr =myWin.document.getElementById("frOut");
    if (myfr) {myfr.datamemo.value=data;
		  myfr.btn1.disabled=false;
		} else {alert("An Error Ocurred \n\nPlease try Again");}
  }
  
 function Link_Parent_data(FormatOut,sp)
 {
   // web_resultado();
   var dout="";
   if(FormatOut=="SHP") {
	  dout=prepareSHP("|");
	  Link_Child_data(dout);
	 } else {
	  dout=web_resultado(FormatOut,sp);
    Link_Child_data(dout);
   } 
    
  } 


 function Send_ResultWindow(url,name)
 {
  if(url=="") {url="_blank";}
  //myWin = window.open(url,name,"width=490,height=440,scrollbars");
  myWin = window.open(url,name,"width=520,height=480,menubar=no,directories=no,toolbar=yes,status=no,resizable=yes");
  if(myWin) {
   if (myWin.focus) {myWin.focus();} 
  }
 }


 function app_run(xf)
  {
   //var fr =document.frGeo;
   
   var combolist=document.frTOC.pts;
    if(combolist.options.length>0) { 
      combolist="";
      //extra options should be added here
			//if(xf=="SHP") {prepareSHP("|");}
      
     setmsg("Processing data... Wait");
     Send_ResultWindow("digipoint.php?action="+xf,"result");
		 setmsg("Project was processed"); 
    } else {alert ("Project is empty, click over the map to add points");};
  
    // fr.submit();
  }
  


function action_renamepoint(overlay)
 {
    zfindnode(overlay.title);
    setmsg("Selection: "+overlay.title);
    var index = zweb_listIndex(document.frTOC.pts);
    if(index>-1) {
    
      var Pt_Name = document.frTOC.pts.options[index].text;
      Pt_Name = Pt_Name.split("[")[0];    

    var xwidth = 250;
    var yheight = 95;
    var wc = new zget_centerwin(xwidth,yheight);
  
    zset_win1("<b>&nbsp;Change Point Label</b>",wc.left,wc.top,xwidth,yheight,"#eff3f7","#0956A6");

    var obj = zdoc_get("zfrwin");
    var cadena ='<div style="position:absolute; left:2px; top:0px; width:245px; height:85px;font-family: Arial, Helvetica, sans-serif; font-size: 9pt;overflow:auto;"/>';

   cadena +='<form name="frEdit">';
   cadena +='Label <input type="text" name="PointName" style="width:200px" value="'+Pt_Name+'"><br><br>';

   cadena +='<input type="button" name="btAccept" value="Accept" onClick="app_accept_name('+index+')"/>';
   cadena +='<input type="button" name="btCancel" value="Cancel" onClick="zclose_zwin()"/></form></div>';

   obj.innerHTML = cadena;

      }       
 }


 function app_accept_name(index)
 {
   var Name2 = document.frEdit.PointName.value;
   zclose_zwin();
  
   var OldName = document.frTOC.pts.options[index].text;
   OldName = "["+OldName.split("[")[1];    
   Name2 = Name2+OldName;
   document.frTOC.pts.options[index].text = Name2;
 }



 function AddUTMZones()
 {
  var UTMList = document.frCoo.UTMZone;
  for (i=1; i<61; i++){
  UTMList.options[UTMList.options.length]=new Option("Zone "+i,"Zone");
  }
  UTMList.options.selectedIndex = 11;
 }

 function enabledUTM()
 {
  var index = document.frCoo.Geosystem.options.selectedIndex;
  var showUTM = false;
  if(index==1) {showUTM = true;}
  
  document.frCoo.UTMZone.disabled = showUTM;
  document.frCoo.btUTMGrid.disabled = showUTM;
  document.frCoo.Hemisp.disabled = showUTM;
  if(showUTM==false) {setmsg("Export Coordinates as UTM (meters)");}
  else {setmsg("Export Coordinates as Lat/Lon");} 
 }

 function changeSymbol()
  {
   zIconName = GE_Icon_GetUrl(zIconId);
  }


function getcoords(text,sp,SendUTM,i,modo)
 { 
  var ylat = text.split(",")[0];
  var xlon = text.split(",")[1];
    
    ylat = parseFloat(ylat);
    xlon = parseFloat(xlon);
  
  if(SendUTM) {    
    outcoo=zGeo2_LatLon2UTM(ylat,xlon,sp,UTMZone,(HemispOpt==1));
    
    xlon = parseFloat(outcoo.split(sp)[0]);
    ylat = parseFloat(outcoo.split(sp)[1]);
  } else {
   if(modo==1) {outcoo = xlon + sp +ylat}
    else {outcoo = ylat +sp+xlon;}
  }

  if(i==0){
    EXMin=xlon;
    EXMax=xlon;
    EYMin=ylat;
    EYMax=ylat;
  }else{
   if(xlon<EXMin) {EXMin=xlon}
   if(xlon>EXMax) {EXMax=xlon}
   if(ylat<EYMin) {EYMin=ylat}
   if(ylat>EYMax) {EYMax=ylat}; 
  }
  return outcoo;

 } 


function get_gpxheader()
 {
  var cadena = '<?xml version="1.0" encoding="utf-8" ?>\n';
   cadena +='<gpx version="1.0" creator="www.zonums.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
   cadena +='xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">\n';
  return cadena
 }


 function get_kmlheader()
 {
  var Linea = '<?xml version="1.0" encoding="UTF-8"?>';
   Linea +='<kml xmlns="http://earth.google.com/kml/2.0">';
   Linea +='<Document><name>DigiPoint</name>'; 

   return Linea
 }



 function web_resultado(FormatOut,sp)
 {
   var data = document.frTOC.pts;
   var modo = 1;
   if(FormatOut=="GPX") {SendUTM=false; modo=2;} else {SendUTM = (LatLonOpt==1);}
   if(FormatOut=="KML") {SendUTM=false;}
   if(FormatOut=="DXF") {sp ="\n20\n";}

   var dout="";

   UTMZone = UTMZoneOpt;

   var line = "";
   
       
   var Pt_Name ="";
   var Pt_Icon ="";
   var Elevation = "";
   if(AddElevation==true) {Elevation = "" +sp+"Elevation ("+getElevUnits(ElevUnits)+")";}
   
   
   if(FormatOut=="DXF") {dout+='\n0\nSECTION\n2\nENTITIES\n';}
   if(FormatOut=="GPX") {
     sp='" lon="';
      dout+=get_gpxheader();
   }
   if(FormatOut=="KML") {dout+=get_kmlheader();}

   if(FormatOut=="TXT" || FormatOut=="TAB" || FormatOut=="CSV") {
     dout+='DigiPoint Export:\n';
     if(SendUTM) {
        dout+='Units: UTM(meters), Zone '+UTMZone;
				if(HemispOpt==1) {dout+=" N";} else {dout+=" S";}
				dout+='\nDatum: WGS84\n\n';
        //nwd.write('Powered by Zonum Solutions\nwww.zonums.com\n');
        dout+='id'+sp+'XCoo'+sp+'YCoo'+Elevation+'\n';
       } else {
        dout+='Units: Lat/Lon (Decimal degrees)\nDatum: WGS84\n\n';
       // nwd.write('Powered by Zonum Solutions\nwww.zonums.com\n');
        dout+='id'+sp+'Longitude'+sp+'Latitude'+Elevation+'\n';
      }
     }

    

    for (i=0; i<data.options.length; i++){
      line = data.options[i].text;
      Pt_Name = line.split("]")[0]+"]";
      Pt_Icon = line.split("~")[1];

      line = line.split("]")[1];
      line = line.split("~")[0];

      if(AddElevation==false) {Elevation = "";} 
      else {Elevation = line.split(",")[2];}

      line = getcoords(line,sp,SendUTM,i,modo);
      

      if(FormatOut=="DXF" || FormatOut=="GPX" || FormatOut=="KML") {
        if(FormatOut=="DXF") {dout+='0\nPOINT\n8\n\zPoints\n10\n'+line+'\n30\n0.0\n';}
         else {
          if(FormatOut=="GPX") {
            if(AddElevation==false) {Elevation = '<elev>'+Elevation+'</elev>\n';} 
             dout+='<wpt lat="'+line+'">\n<name>'+Pt_Name+'</name>\n'+Elevation+'</wpt>\n';
          } else {
           dout+='<Placemark><name>'+Pt_Name+'</name><Point><coordinates>'+line+',0</coordinates></Point></Placemark>\n';
          }
       }
      } else {
        if(FormatOut=="BLN") {dout+='1,1,'+Pt_Name+'\n'+line+'\n';
          } else {
           if(AddElevation==true) {Elevation = sp+getElevConv(Elevation,ElevUnits);}
           dout+=Pt_Name+sp+line+Elevation+'\n';
          }
     }
   }

   if(FormatOut=="DXF") {dout+='0\nENDSEC\n0\nEOF';}
   if(FormatOut=="GPX") {dout+='</gpx>';}
   if(FormatOut=="KML") {dout+='</Document></kml>';}


  return dout
 }




 function prepareSHP(sp)
 {
  var data = document.frTOC.pts;
  var modo = 1;
 
  UTMZone = UTMZoneOpt;
  SendUTM = (LatLonOpt==1);

   var Pt_Name ="";
   var Pt_Icon ="";
   var Elevation = "";
   var line = "";
   var memodata = "";

  for (i=0; i<data.options.length; i++){
      line = data.options[i].text;
      Pt_Name = line.split("]")[0]+"]";
      Pt_Icon = line.split("~")[1];

      line = line.split("]")[1];
      line = line.split("~")[0];

      if(AddElevation==false) {Elevation = "";} 
      else {Elevation = line.split(",")[2];}

      line = getcoords(line,sp,SendUTM,i,modo);
      
      if(AddElevation==true) {Elevation = sp+getElevConv(Elevation,ElevUnits);}
       else {Elevation = sp+"0.000";}

      line = Pt_Name+sp+line+sp+Pt_Icon+Elevation;

      if(memodata=="") { memodata = line;}
       else {memodata += "\n"+line;}
  }

  var metax="0";
  if(SendUTM==true) { metax=UTMZone;}
  metax+="|"+HemispOpt+"|"+getElevUnits(ElevUnits)+"|0\n";
  metax+=EXMin+"|"+EYMin+"|"+EXMax+"|"+EYMax+"\n"; 
   
  return metax+memodata
 }

 function clearnodes()
   {
     juncid = 0;
     document.frTOC.pts.options.length = 0;
     document.getElementById("ptscount").innerHTML = "";
     map.clearOverlays()
     lastMensaje="";
   }

 function selectPtList()
 {
   var combolist=document.frTOC.pts;  
   if(combolist.options.length>0) {
    
    var Index = combolist.options.selectedIndex
    var cadena = combolist.options[Index].text
     setmsg(cadena); 
   }
 }

 function deletenode()
  {
    var combolist=document.frTOC.pts;
    var Index = combolist.options.selectedIndex
    if(Index>-1) { 
     var cadena = combolist.options[Index].text
     combolist.options[Index]=null
     setmsg("Deleted: "+cadena);
     document.getElementById("ptscount").innerHTML = "&nbsp;&nbsp;Nodes: "+ combolist.options.length;
    }
   }

function changemaptype(newtype)
 {
  map.setMapType(newtype);
  setmsg("Map style has changed");
 }

 function changezscale(svisible)
  {
  map_scale=svisible;
  if(svisible) {
     map.addControl(sc);
     setmsg("MapScale Control: on");
   } else {
     map.removeControl(sc);
     setmsg("MapScale Control: off");
   }
 }

 function changezoview(svisible)
 {
  map_oview=svisible;
  if(svisible) {
    map.addControl(omc);
    setmsg("Overview Map: on");
   } else { 
    map.removeControl(omc);
    setmsg("Overview Map: off");
  }
 }

 function changezzoom(svisible)
  {
  map_zoom=svisible;
  if(svisible) {
    map.addControl(smc);
   setmsg("Zoom Control: on");
   } else { 
   setmsg("Zoom Control: off");
    map.removeControl(smc);
  }
}


 function action_elevation(point)
 { 
  doGetElevation(point.y,point.x);
 }


 function action_addpoint(point)
 {
   var PointName = document.frTOC.PointName.value;
   var output = "";

        if(PointName=="") {
            //if(zIconId=="DEFAULT") {PointName=" ";}
            // else {PointName=zIconId;};
         }
   
          icon.image = zIconName;
          GE_Icon_SetSizeCombo(document.frTOC.ComboSymbolSize,icon);
          var myMarker = new GMarker(point,icon); 
          
          juncid = juncid + 1;
          output = PointName + "[" + juncid + "]"; 
          myMarker.title = output;
          map.addOverlay(myMarker); 
          output =  output + " " + point.toUrlValue()+",Elevation~            "+zIconId;
          
          var nodelist=document.frTOC.pts;
          nodelist.options[nodelist.options.length]=new Option(output,"pt");
              
          document.getElementById("ptscount").innerHTML = "&nbsp;&nbsp;Points: "+ nodelist.options.length;
          output = "Added: (" + point.toUrlValue() + ")";
          
         
    document.getElementById("divmessage").innerHTML = output;     

 }


function action_addpoint2(point,Elev)
 {
   var PointName = document.frTOC.PointName.value;
   var output = "";

        if(PointName=="") {
            //if(zIconId=="DEFAULT") {PointName=" ";}
            // else {PointName=zIconId;};
         }
   
         if(AddElevation==true) {point = new GLatLng(point.y, point.x);}
          
          icon.image = zIconName;
          GE_Icon_SetSizeCombo(document.frTOC.ComboSymbolSize,icon);
          var myMarker = new GMarker(point,icon); 
          
          juncid = juncid + 1;
          output = PointName + "[" + juncid + "]"; 
          myMarker.title = output;
          map.addOverlay(myMarker); 
          output =  output + " " + point.toUrlValue()+","+Elev+"~"+zIconId;
          
          var nodelist=document.frTOC.pts;
          nodelist.options[nodelist.options.length]=new Option(output,"pt");
              
          document.getElementById("ptscount").innerHTML = "&nbsp;&nbsp;Points: "+ nodelist.options.length;
          output = "Added: (" + point.toUrlValue() + ")";
          
    setmsg(output);     
 }


 function action_delpoint(overlay)
 {
      zfindnode(overlay.title);
      setmsg("Selection: "+overlay.title);
      var answer = confirm("Delete: "+overlay.title);
       if (answer){
               map.removeOverlay(overlay);
               deletenode();
      }
 }
 
 function zmapclick(overlay, point)
   {     
     if(optAction==1) {
        if (overlay) {action_delpoint(overlay);}
     } else if (optAction==2) {
         if (overlay) {action_renamepoint(overlay);}
     } else if (point) {
           if(optAction==0) {
              if(AddElevation==false) {action_addpoint2(point,"0");}
              else {  
                lastpoint.x = point.x;
                lastpoint.y = point.y; 
                doGetElevation(point.y,point.x);
              }

             } else {action_elevation(point);}
     }         
   }

 function zmapextent()
    {var center = map.getCenter();}
    
 function zfindnode(nodeb)
 {
   var found = false;
   var nodelist=document.frTOC.pts;
   var N = nodelist.options.length;
   var cadena = "";

   for(i = 0; i < N; i++){

     cadena = nodelist.options[i].text;
     a = cadena.indexOf(nodeb);
     if(a>-1) {
        found = true;
        nodelist.options.selectedIndex = i;
        break;
    }     
   }
 }
 

function zRequest(url)
{
  setmsg("Wait...");
  lastMensaje="x";
  xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else
  {setmsg("Your browser does not support XMLHTTP.");
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {  
    parseElevation(xmlhttp.responseText);
    lastMensaje="";
  }
  else
  {setmsg("Problem retrieving data:" + xmlhttp.statusText);}
  }
}
  
  function parseElevation(TextData)
  {
   if(optAction==0) {
    action_addpoint2(lastpoint,TextData);
   } else {
     cadena = "Point Elevation = " + getElevConv(TextData,CursorElev)+" "+getElevUnits(CursorElev);
     setmsg(cadena);
   }
  }
  
 function getElevUnits(etipo)
 {
   if(etipo==0) {return "Meters";}
   else {return "Feet";}
 }

 function getElevConv(Elev,etipo)
 {
  Elev = parseFloat(Elev);
  if(etipo==1) {Elev = Elev * 3.2808398950;}
  Elev = "" + Elev.toFixed(3);
  return Elev
 }

 function doGetElevation(lat,lon)
 { var Url = '/online/zelevserver.php?lon='+lon+'&lat='+lat; 
   zRequest(Url);
 }

 
-->