var statusWin;
var gotoWin;
var pidWin;
var fileWin;
var optionsWin;
var topoZoneWin;
var projectWin;
var fbnbool = false;
var appendToEnd = true;
var statein = "";
var labelin = "";
var boundaryin = "";



if (typeof dbArray == "undefined") {
  var dbArray = new Array();
}
if (typeof viewArray == "undefined") {
  var viewArray = new Array();
}

if (typeof dbLastClicked == "undefined") {
  var dbLastClicked = void 0;
}
if (typeof grabTop == "undefined") {
  var grabTop    = void 0;
  var grabBottom = void 0;
  var grabRight  = void 0;
  var grabLeft   = void 0;
}
if (typeof zoomXYString == "undefined") {
  var zoomXYString = void 0;
}
if (typeof controlType == "undefined") {
  var controlType = void 0;
}
//-----------------------------------
function initMap() {
  if (parent.MapFrame.getCorsStatus() == true) {
    getMarksCors();
  }

}
//-----------------------------------
function storeGotoData(zoomStr) {
  zoomXYString = zoomStr;
}
function storeDbGrabBox(eTop, eBottom, eRight, eLeft) {
  grabTop = eTop;
  grabBottom = eBottom;
  grabRight = eRight;
  grabLeft = eLeft;
}
//-----------------------------------
function getGotoData() {
  return zoomXYString;
}
//------------------------------------
function mergeDbString(dbstr) {
  var newArray = new Array();
  var keepArray = new Array();
  var oldPids = new Array();
  var fields = new Array();
  var mapNum=0;
  var i=0;
  var j=0;
  var k=0;
  var start=0;


//alert(" tom rocks the house "); //tom rocks


  if (typeof dbArray[0] != "undefined") {
     keepArray = dbArray;
     start = keepArray.length;
  } else {
     start = 0;
  }

  newArray = dbstr.split("$");

  //----------------------------
  // Extract the old PIDs
  //----------------------------
  for (i=0;i<keepArray.length;i++) {
    fields = keepArray[i].split("|");
    oldPids[j++] = fields[2];
  }


  //------------------------------------------------------
  // For each record see if the PID was already stored.
  //------------------------------------------------------
  k=start;
  for (i=0;i<newArray.length;i++) {
    isSame=0;
    if (newArray[i] == "") {
      break;
    } else {
        for (j=0;j<oldPids.length;j++) {
          if (oldPids[j] == "") {
            break;
          } else if (newArray[i].indexOf(oldPids[j]) >= 0) {
            isSame=1;
            break;
          }
      }
      if (isSame == 0) {
        keepArray[k]  = newArray[i];
        k++;
      }
    }
   }

  newArray = void 0;
  newArray = new Array();


  //-------------------------
  // Reassign the mapIds
  //-------------------------
  var temp = "";

  j=0;
  for (i=0;i<keepArray.length;i++) {
    if (keepArray[i] == "") {
      break;
    } else {
        temp = keepArray[i].substr(5);
        ++mapNum;
        mapId = getMapId(mapNum);
        newArray[j++] = mapId + temp;
    }
  }

  parent.NgsMap2.dbArray = newArray;
  //dumpArray(newArray);
  //alert("length = " +  newArray.length);

}
//-------------------------------------
function getMapId(num) {
  var mapId = 0;


  if (num < 10) {
    mapId = "...." + num.toString();
  } else if (num < 100) {
    mapId = "..." + num.toString();
  } else if (num < 1000) {
    mapId = ".." + num.toString();
  } else if (num < 10000) {
    mapId = "." + num.toString();
  } else {
    mapId = num.toString();
  }

  return(mapId);
}
//----------------------------------------
function Perl_map_request_call(mapData) {   // called from map_request.prl
   
//alert("map = " + mapData); // tom rocks
 
opener.mergeDbString(mapData);
opener.showMarks();

//alert(" went all the way through "); // tom rocks

}
//----------------------------------------
function Perl_map_request_call_cors(mapData) {   // called from map_request.prl
    opener.mergeDbString(mapData);
    opener.showMarks();
}
//------------------------------------
function storeViewString(loc) {
  var fields = new Array();
  var mapID = "";
  var mapXY = "";
  var xy = new Array();
  var pid = "";
  var orders = "";
  var ecode = "";
  var lat = "";
  var lon = "";
  var stab = "";
  var desig = "";
  var types = "";
  var start=0;
  var k=0;

  fields = parent.NgsMap2.dbArray[loc].split("|");


  mapID = fields[0];
  xy = fields[1].split(/\s/);
  lon = MapPos2dms(xy[0], "W");
  lat = MapPos2dms(xy[1], "N");
  pid = fields[2];
  orders = fields[3];
  ecode = fields[4];
  stab = fields[5];
  desig = fields[6];
  types = fields[7];

  if (parent.NgsMap2.viewArray[0] == "undefined") {
    start = 0;
  } else {
    start = parent.NgsMap2.viewArray.length;
  }

  k = start;


  if (k == 0) {
    parent.NgsMap2.viewArray[k++] = "MapID|Pid...|H-V|Vert_Source|Lat....|Lon.....|Stab|Designation";
    parent.NgsMap2.viewArray[k++] = "-----|------|---|-----------|-------|--------|----|------------------------------";
  }


  parent.NgsMap2.viewArray[k++] = mapID + "|" + pid + "|" + orders + "|" + ecode + "|" + lat + "|" + lon + "|" + stab + "|" + desig;

  fields = void 0;



}
//------------------------------------
function storeViewTrailer() {
  var last=0;


  if (parent.NgsMap2.viewArray[0] != "undefined") {
    last = parent.NgsMap2.viewArray.length;
    parent.NgsMap2.viewArray[last] = "=====|======|===|===========|=======|========|==============================";
  }
}
//------------------------------------
function storeDbClick(c1) {


  dbLastClicked = c1;
}
//-------------------------------------
function storeControlType(controlStr) {
  controlType = controlStr;
}
//-------------------------------------
function getControlType() {
  return(controlType);
}
//------------------------------------
function clearMap() {
   dbArray.length = 0;
   dbArray = void 0;

   parent.NgsMap2.dbArray = new Array();
   dbLastClicked = -1;
   zoomXYString = "";
   controlType = "";
   parent.MapFrame.clearSelected(1);
}
//------------------------------------
function clearSelected(resetLastClicked) {
   if (resetLastClicked == 1) {
     dbLastClicked = -1;
   }

   if (typeof parent.NgsMap2.viewArray != "Undefined") {
     parent.NgsMap2.viewArray = new Array();
    parent.NgsMap2.viewArray[0] = "MapID|Pid...|H-V|Vert_Source|Lat....|Lon.....|Stab|Designation";
    parent.NgsMap2.viewArray[1] = "-----|------|---|-----------|-------|--------|----|------------------------------";
   }

}
//------------------------------------
function getLastClick() {
  return dbLastClicked;
}
//=======================================
function getGrabTop () {
  return grabTop;
}
//=======================================
function getGrabBottom () {
  return grabBottom;
}
//=======================================
function getGrabRight () {
  return grabRight;
}
//=======================================
function getGrabLeft () {
  return grabLeft;
}
//-------------------------------
function goTo(mIndex) {
  var myFeatures = "";
  var myHeight=300;
  var myWidth=500;


  if ((typeof parent.NgsMap2.dbArray != "undefined")
  &&  (parent.NgsMap2.dbArray.length > 0)) {
      parent.MapFrame.drawMyAcetate = true;
  } else {
      parent.MapFrame.drawMyAcetate = false;
  }

  parent.MapFrame.storeDbClick(-1);

  if (mIndex == 1) {
      myHeight = 350;
      myWidth  = 500;
  } else if (mIndex == 2) {
      myHeight = 300;
      myWidth  = 500;
  } else if (mIndex == 3) {
      myHeight = 400;
      myWidth = 500;
  } else if (mIndex == 4) {
      myHeight = 400;
      myWidth = 400;
  } else if (mIndex == 5) {
      myHeight = 450;
      myWidth = 500;
  } else if (mIndex == 6) {
      myHeight = 400;
      myWidth = 300;
  } else if (mIndex == 7) {
      myHeight = 350;
      myWidth = 550;
  } else if (mIndex == 8) {
      myHeight = 350;
      myWidth = 450;
  } else if (mIndex == 9) {
      myHeight = 350;
      myWidth = 500;
  } else if (mIndex == 10) {
      myHeight = 400;
      myWidth = 600;
  } else if (mIndex == 11) {
      myHeight = 250;
      myWidth = 450;
  } else {
      return;
  }
  myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,toolbar=1,scrollbars=1,resizable=1";
  gotoWin = window.open('', 'gotoWin', myFeatures);
  gotoWin.document.open('text/html');
  gotoWin.document.bgColor='skyblue';
  gotoWin.document.fgColor='black';

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
//  if (mIndex == 1) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=POS";
//  } else if (mIndex == 2) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=PID";
//  } else if (mIndex == 3) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=COUNTY";
//  } else if (mIndex == 4) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=CITY";
//  } else if (mIndex == 5) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=QUAD";
//  } else if (mIndex == 6) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=CORS";
//  } else if (mIndex == 7) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=FBN";
//  } else if (mIndex == 8) {
//      gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=AIRPORT";
//  } else if (mIndex == 9) {
//	  gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=USNG";
//  } else if (mIndex == 10) {
//	  gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=XYMAP";
//  } else if (mIndex == 11) {
//	  gotoWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_goto.prl?GOTO=ZIPCODE";
//  } else {
//    return;
//  }

  if (mIndex == 1) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=POS";
  } else if (mIndex == 2) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=PID";
  } else if (mIndex == 3) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=COUNTY";
  } else if (mIndex == 4) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=CITY";
  } else if (mIndex == 5) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=QUAD";
  } else if (mIndex == 6) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=CORS";
  } else if (mIndex == 7) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=FBN";
  } else if (mIndex == 8) {
      gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=AIRPORT";
  } else if (mIndex == 9) {
          gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=USNG";
  } else if (mIndex == 10) {
          gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=XYMAP";
  } else if (mIndex == 11) {
          gotoWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_goto.prl?GOTO=ZIPCODE";
  } else {
    return;
  }

//  if (mIndex == 1) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=POS";
//  } else if (mIndex == 2) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=PID";
//  } else if (mIndex == 3) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=COUNTY";
//  } else if (mIndex == 4) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=CITY";
//  } else if (mIndex == 5) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=QUAD";
//  } else if (mIndex == 6) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=CORS";
//  } else if (mIndex == 7) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=FBN";
//  } else if (mIndex == 8) {
//      gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=AIRPORT";
//  } else if (mIndex == 9) {
//          gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=USNG";
//  } else if (mIndex == 10) {
//          gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=XYMAP";
//  } else if (mIndex == 11) {
//          gotoWin.location = "http://205.156.38.36/cgi-bin/Craig/map_goto.prl?GOTO=ZIPCODE";
//  } else {
//    return;
//  }

  gotoWin.focus();
}


//--------------------------------
function Perl_map_goto_call(zoomdata) {
  var fields = new Array();

  opener.storeGotoData(zoomdata);
  opener.gotoWin.close();


  fields = zoomdata.split("|");



  if ((fields[0] == "BY_POS") || (fields[0] == "BY_XY") || (fields[0] == "BY_ZIP")) {
      opener.gotoXY();
  } else if (fields[0] == "BY_QUAD") {
	  var quadbool = false;
      opener.gotoEnvelope(quadbool);
  } else {
     opener.alert("String not captured");
  }
}
//----------------------------------------
function Perl_map_request_call_fbn(mapData) {  // called from map_fbn.prl
  var areaLabel = "";

  areaLabel = statein;
	areaZoom(mapData, "BY_FBN", areaLabel);
}

//----------------------------------------
function Perl_map_request_call_ht_mod(mapData) {  // called from map_ht_mod.prl
  var areaLabel = ""

   areaLabel = labelin;

        areaLabel = labelin;
	areaZoom(mapData, "BY_HTMOD", areaLabel);
}

//-------------------------------
function Perl_set_state(state) {
        statein = state;
}

//-------------------------------
function Perl_set_label(label) {
        labelin = label;
}

//-------------------------------
function Perl_set_boundary(boundary) {
        boundaryin = boundary;
}

function areaZoom(mapData, method, label) {
        var minx = 0;
        var maxx = 0;
        var miny = 0;
        var maxy = 0;
        var mapArray = new Array();
	var coord = new Array();
        var fields = new Array();
        var storedX=0;
        var storedY=0;
        var temp="";
        var zoomdata = "";
        var i=0;


        if ((mapData == "") && (method == "BY_FBN")) {
            alert ("No FBN data available for " + label);
            return;
        } else if ((mapData == "") && (method == "BY_HTMOD")) {
            alert ("No Height Mod data available for " + label);
            return;
        }

        //---------------------------------------------
        // Could be an State FBN already displayed.
        // Use only the "Just Retrieved" coordinates
        // to get the zoomToEnvelope boundaries
        //---------------------------------------------
        if ((method == "BY_HTMOD") && (boundaryin != "")) {
           fields = boundaryin.split("|");
            minx = fields[0];
            maxx = fields[1];
            miny = fields[2];
            maxy = fields[3];
        } else {
              mapArray = mapData.split("$");
              coord = xCoord(mapArray);
              for (i=0;i<coord.length;i++) {
                temp = coord[i].toString();
                fields = temp.split(/\s/);
                storedX = parseFloat(fields[0]);
                storedY = parseFloat(fields[1]);
                if ((storedX < maxx) || (maxx == 0)) {
                        maxx = storedX;
                }
                if ((storedX >= minx) || (minx == 0)) {
                        minx = storedX;
                }
                if ((storedY < miny) || (miny == 0)) {
                        miny = storedY;
                }
                if ((storedY >= maxy) || (maxy == 0)) {
                        maxy = storedY;
                }
              }
        }


  //alert ("BEFORE = " + minx + "|" + maxx + "|" + miny + "|" + maxy);

        //----------------------------------------------------
        // Extent Box boundary so the displayed box
        // is slightly larger than the project boundaries.
        //----------------------------------------------------
        if (method == "BY_HTMOD") {
            maxx = parseFloat(maxx) - .02;
            minx = parseFloat(minx) + .02;
            maxy = parseFloat(maxy) + .02;
            miny = parseFloat(miny) - .02;
        } else {
            maxx = parseFloat(maxx) - .1;
            minx = parseFloat(minx) + .1;
            maxy = parseFloat(maxy) + .1;
            miny = parseFloat(miny) - .1;
        }
        zoomdata = method + "|" + maxx + "|" + miny + "|" + minx + "|" + maxy + "|" +  label;

  //alert ("AFTER = " + minx + "|" + maxx + "|" + miny + "|" + maxy);
        //--------------------------------------
        // Merge after bounday was extracted.
        //--------------------------------------
        opener.mergeDbString(mapData);

        opener.storeGotoData(zoomdata);
        opener.drawMyAcetate2 = true;

        fbnbool = true;
    opener.gotoEnvelope(fbnbool);
}


//----------------------------------------
function gotoXY() {
   var fields = new Array();
  var x = 0;
  var y = 0;
  var label = "";
  //--------------------------------------------------------
  // If coming from Zoomout, parent.NgsMap2 does not exist
  //--------------------------------------------------------
  if (!parent.NgsMap2.xyString) {
    var xyString = getGotoData();
    fields = xyString.split("|");
  }



  x = parseFloat(fields[1]);
  y = parseFloat(fields[2]);
  label = fields[3];


  //------------------------------------------------
  // Zoom in more for dense areas
  //------------------------------------------------
  if ((Math.abs(x) > 76.9) && (Math.abs(x) < 77.1)
  &&  (Math.abs(y) > 38.85) && (Math.abs(y) < 38.95)) {
      parent.MapFrame.selectPointMargin = 25/125000;
  } else {
      parent.MapFrame.selectPointMargin = 25/15000;
  }
  parent.MapFrame.zoomToPoint(x, y, 1, label);
}
//----------------------------------------
function gotoEnvelope(mybool) {
  var fields = new Array();
  var minx = 0;
  var miny = 0;
  var maxx = 0;
  var maxy = 0;
  var e_minx = 0;
  var e_miny = 0;
  var e_maxx = 0;
  var e_maxy = 0;
  var type="";
  var label = "";
  var disportion = 0.0;



  //--------------------------------------------------------
  // If coming from Zoomout, parent.NgsMap2 does not exist
  //--------------------------------------------------------
  if (!parent.NgsMap2.xyString) {
    var xyString = getGotoData();
    fields = xyString.split("|");
  }
  //------------------------------------------------------------------
  // Extend the boundaries slightly so the box is displayed on screen
  //------------------------------------------------------------------
  type = fields[0];
  minx = parseFloat(fields[1]);
  miny = parseFloat(fields[2]);
  maxx = parseFloat(fields[3]);
  maxy = parseFloat(fields[4]);




  //alert ("BEFORE = " + minx + "|" + maxx + "|" + miny + "|" + maxy);
  if (type == "BY_FBN") {
      e_minx = -(parseFloat(Math.abs(minx) - .3));
      e_miny = miny - .3;
      e_maxx = -(parseFloat(Math.abs(maxx) + .3));
      e_maxy = maxy + .3;
  } else if  (type == "BY_HTMOD") {
      e_minx = -(parseFloat(Math.abs(minx) - .3));
      e_miny = miny - .3;
      e_maxx = -(parseFloat(Math.abs(maxx) + .3));
      e_maxy = maxy + .3;
  } else {
      e_minx = -(parseFloat(Math.abs(minx) - .05));
      e_miny = miny - .05;
      e_maxx = -(parseFloat(Math.abs(maxx) + .05));
      e_maxy = maxy + .05;
  }
  var lonDiff=0;
  var latDiff=0;
  lonDiff = (Math.abs(maxx) - Math.abs(minx));
  latDiff = (Math.abs(maxy) - Math.abs(miny));
  if (latDiff > lonDiff) {
      e_minx = e_minx - ((latDiff - lonDiff) / 3);
      e_maxx = e_maxx + ((latDiff - lonDiff) / 3)
  } else {
      e_miny = e_miny - ((lonDiff - latDiff) / 3);
      e_maxy = e_maxy + ((lonDiff - latDiff) / 3)
  }

  //alert ("AFTER  = " + e_minx + "|" + e_maxx + "|" + e_miny + "|" + e_maxy);


    parent.MapFrame.drawMyAcetate2 = true;
    if (mybool == true) {
            parent.MapFrame.enablefbn = true;
    }
    parent.MapFrame.zoomToEnvelope(e_minx, e_miny, e_maxx, e_maxy);
}
//-------------------------------
function selectMap(mIndex) {
  var notFoundText = "";
  var controlString = "";
  var myFeatures = "";
  var myHeight = parent.MapFrame.innerHeight - 50;
  var myWidth  = parent.MapFrame.innerWidth - 50;

  var top = parent.MapFrame.eTop;
  var bottom = parent.MapFrame.eBottom;
  var left = parent.MapFrame.eLeft;
  var right = parent.MapFrame.eRight;

  var Lat = top - (top-bottom)*0.5;
  var Long = left - (left-right)*0.5;

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
  if (mIndex == 1) {
      //parent.window.location = 'http://www.ngs.noaa.gov/ims/NgsMap2/';
      parent.window.location = 'http://www.ngs.noaa.gov/ngsims/NgsMap2/';
      //parent.window.location = 'http://205.156.38.36/website/NgsMap2/';
  } else if (mIndex == 2) {
      //parent.window.location = 'http://www.ngs.noaa.gov/ims/NgsMap2/viewer.htm?MAP=SDTS';
      parent.window.location = 'http://www.ngs.noaa.gov/ngsims/NgsMap2/viewer.htm?MAP=SDTS';
      //parent.window.location = 'http://205.156.38.36/websiteNgsMap2/viewer.htm?MAP=SDTS';
  } else if (mIndex == 3) {
      //parent.window.location = 'http://www.ngs.noaa.gov/ims/NgsMap2/viewer.htm?MAP=CORS';
      parent.window.location = 'http://www.ngs.noaa.gov/ngsims/NgsMap2/viewer.htm?MAP=CORS';
      //parent.window.location = 'http://205.156.38.36/website/NgsMap2/viewer.htm?MAP=CORS';
  } else if (mIndex == 4) {

	myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,locationbar=1,toolbar=1,scrollbars=1,resizable=1";
	topoZoneWin = window.open('', 'topoZoneWin', myFeatures);
	topoZoneWin.location = 'http://www.topozone.com/map.asp?lat='+Lat+'&lon='+Long+'&s=100&size=s&u=2';
	topoZoneWin.focus();
  } else if (mIndex == 5) {
	myHeight = 400;
	myWidth = 350;

	// Section for the Perl call to FBN thing
//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
    myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,toolbar=0,scrollbars=1,resizable=1";
    fbnWin = window.open('', 'fbnWin', myFeatures);
	fbnWin.document.open('text/html');
	fbnWin.document.bgColor='skyblue';
	fbnWin.document.fgColor='black';
	//fbnWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_fbn.prl";
        fbnWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_fbn.prl";
        //fbnWin.location = "http://205.156.38.36/cgi-bin/Craig/map_fbn.prl";
	fbnWin.focus();
  } else if (mIndex == 6) {
	myHeight = 400;
	myWidth = 500;

	// Section for the Perl call to HT MOD thing
//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
    myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,toolbar=0,scrollbars=1,resizable=1";
    htmodWin = window.open('', 'htmodWin', myFeatures);
	htmodWin.document.open('text/html');
	htmodWin.document.bgColor='skyblue';
	htmodWin.document.fgColor='black';
	//htmodWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_ht_mod.prl";
        htmodWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_ht_mod.prl";
        //htmodWin.location = "http://205.156.38.36/cgi-bin/Craig/map_ht_mod.prl";
	htmodWin.focus();
  } else {
      return;
  }


}
//-------------------------------
function markPoints(mIndex) {
  var coord = new Array();
  var types = new Array();
  var notFoundText = "";
  var count=0;
  var i=0;
  var myData = "";
  var myRay = new Array();
  var tempRay = new Array();




  if (mIndex == 1) {
      parent.MapFrame.clearSelected(1);
      parent.MapFrame.storeDbClick(-100);
      parent.TOCFrame.updateLayers();
      return;
  } else if (mIndex == 2) {
      parent.NgsMap2.clearSelected(1);
      controlString = "X-0";
      notFoundText = "No Marks Found";
  } else if (mIndex == 3) {
      controlString = "CORS";
      notFoundText = "No CORS marks Found";
  } else if (mIndex == 4) {
      controlString = "H-0";
      notFoundText = "No Horizontal Marks Found";
  } else if (mIndex == 5) {
      controlString = "H-A";
      notFoundText = "No Horz. A-Order marks Found";
  } else if (mIndex == 6) {
      controlString = "H-B";
      notFoundText = "No Horz. Order-B marks Found";
  } else if (mIndex == 7) {
      controlString = "H-1";
      notFoundText = "No Horz. Order-1 marks Found";
  } else if (mIndex == 8) {
      controlString = "H-2";
      notFoundText = "No Horz. Order-2 marks Found";
  } else if (mIndex == 9) {
      controlString = "V-0";
      notFoundText = "No Vertical marks Found";
  } else if (mIndex == 10) {
      controlString = "V88";
      notFoundText = "No Vert. NAVD 88 Heights Found";
  } else if (mIndex == 11) {
      controlString = "V-1";
      notFoundText = "No Vert. Order-1 marks Found";
  } else if (mIndex == 12) {
      controlString = "V-2";
      notFoundText = "No Vert. Order-2 marks Found";
  } else if (mIndex == 13) {
      controlString = "TID";
      notFoundText = "No Tidal Bench Marks Found";
  } else {
      return;
  }


  if (typeof parent.NgsMap2.dbArray[0] == "undefined") {
    alert("ERROR(100) - Nothing to mark\nDo 'Display Stations' first\n");
    return;
  }

  types = xTypes(parent.NgsMap2.dbArray);



  if (controlString == "X-0") {
      parent.MapFrame.storeDbClick(-99);
  } else {
      parent.MapFrame.storeDbClick(-98);
  }

  parent.NgsMap2.storeControlType(controlString);



  //-------------------------------------------------------------
  // Clear out the previous View List if checkbox is not checked
  //-------------------------------------------------------------
  if (parent.MapFrame.appendToEnd != true) {
    parent.MapFrame.clearSelected(0);
  }


  found=0;
  for (i=0;i<types.length;i++) {
    if (controlString == "X-0") {
      parent.NgsMap2.storeViewString(i);
      found=1;
    } else if (isMatch(controlString, types[i]) == true) {
      parent.NgsMap2.storeViewString(i);
      found=1;
    }
  }




  if (found == 0) {
    alert(notFoundText);
    return;
  } else {
    parent.NgsMap2.storeViewTrailer();
  }


  if (parent.MapFrame.getSdtsStatus() == true) {
    openSdtsPidWindow(10);
  } else {
    openPidWindow(10);
  }
  parent.TOCFrame.updateLayers();


}
//-------------------------------
function unmarkAll() {

  //----------------------------------
  // Do not attempt pidWin.close()
  //----------------------------------


  parent.MapFrame.clearSelected(1);
  parent.MapFrame.storeDbClick(-100);
  parent.TOCFrame.updateLayers();
}
//-------------------------------
function findClickedMark(clickedX, clickedY) {
  var pid;
  var storedX=0;
  var storedY=0;
  var diffX=0;
  var diffY=0;
  var minDX = .005;
  var minDY = .005;
  var coord = new Array();
  var fields = new Array();
  var temp = "";
  var closest = -1;
  var i=0;


  minDX = 2 * (eTop - eBottom) / 100;
  minDY = 2 * (eTop - eBottom) / 100;


  if (typeof parent.NgsMap2.dbArray[0] == "undefined") {
    alert("ERROR(101) - Nothing to mark\nDo 'Display Stations' first\n");
    return;
  }



  coord = xCoord(parent.NgsMap2.dbArray);



   closest = -1;
   for (i=0;i<coord.length;i++) {
     temp = coord[i].toString();
    fields = temp.split(/\s/);
     storedX = parseFloat(fields[0]);
     storedY = parseFloat(fields[1]);
     diffX = Math.abs(clickedX - storedX);
     if (diffX <= minDX) {
       diffY = Math.abs(clickedY - storedY);
       if (diffY < minDY) {
         minDX = diffX;
         minDY = diffY;
         closest = i;
       }
     }

   }


   fields = void 0;
   coord = void 0;

  //-------------------------------------------------------------
  // Clear out the previous View List if checkbox is not checked
  //-------------------------------------------------------------
  if (parent.MapFrame.appendToEnd != true) {
    parent.MapFrame.clearSelected(1);
  }

   if (closest >= 0) {
     storeDbClick(closest);
     parent.NgsMap2.storeViewString(closest);
     parent.NgsMap2.storeViewTrailer();

     if (parent.MapFrame.getSdtsStatus() == true) {
          openSdtsPidWindow(10);
        } else {
          openPidWindow(10);
        }
     parent.TOCFrame.updateLayers();
   }

}
//===============================================
function findGrabbedMarks(eTop, eBottom, eLeft, eRight) {
   //alert ("GOT : " + eTop + "|" + eBottom + "|" + eRight + "|" + eLeft);
  var coord = new Array();
  var storedX=0;
  var storedY=0;
  var fields = new Array();
  var temp = "";
  var found=0;
  var i;

  coord = xCoord(parent.NgsMap2.dbArray);

  for (i=0;i<coord.length;i++) {
    temp = coord[i].toString();
    fields = temp.split(/\s/);
    storedX = parseFloat(fields[0]);
    storedY = parseFloat(fields[1]);
    if ((storedX > eRight) && (storedX < eLeft)
    &&  (storedY > eBottom) && (storedY < eTop)) {
        parent.NgsMap2.storeViewString(i);
        found=1;
    }
  }


   if (found == 1) {
     storeDbClick(-101);
     storeDbGrabBox(eTop, eBottom, eRight, eLeft);


     parent.NgsMap2.storeViewTrailer();
     if (parent.MapFrame.getSdtsStatus() == true) {
          openSdtsPidWindow(10);
     } else {
          openPidWindow(10);
     }
     parent.TOCFrame.updateLayers();
   }
}
//------------------------------------
function grabPoly(xval, yval) {
	var coord = new Array();
	var storedX=0;
	var storedY=0;
	var fields = new Array();
	var temp = "";
	var found=0;
	var i;
	var cnt = 0;
	cnt = xval.length;
	xpolyray = xval;
	ypolyray = yval;

	coord = xCoord(parent.NgsMap2.dbArray);

	// Loop through all the stations displayed on map.

	for (i=0;i<coord.length;i++) {
		temp = coord[i].toString();
		fields = temp.split(/\s/);
		storedX = parseFloat(fields[0]);
		storedY = parseFloat(fields[1]);

		xo = storedX;
		yo = storedY;

		if (is_in_poly(xo, yo, xval, yval)) {
			 parent.NgsMap2.storeViewString(i);
			 found = 1;
		}	// end if


	}  // end for loop

	if (found == 1) {
		     storeDbClick(-102);
 
		     parent.NgsMap2.storeViewTrailer();
		     if (parent.MapFrame.getSdtsStatus() == true) {
		          openSdtsPidWindow(10);
		     } else {
		          openPidWindow(10);
		     } // end if
		     parent.TOCFrame.updateLayers();
	   }  // end if

}	// end grabPoly

//------------------------------------
function is_in_poly(xo, yo, xval, yval) {
    var inside = 0;     // Boolean for if in poly
    var cross = 0;      // Boolean for if cross line
    var tt = 0.0;
    var xl, xi = 0.0;       // initialize to set to last pt x
    var yl, yi = 0.0;       // initialize to set to last pt y
    var dx1 = 0.0;      // initialize difference1
    var dx2 = 0.0;      // initialize difference2
    var xl = xval[cnt-1];   // stores last x-value
    var yl = yval[cnt-1];   // stores last y-value
	var cnt = 0;
	cnt = xval.length;
    var n = cnt;


		dx1 = xl - xo;

		   /*--------------------------------------------------------*/
		   /* If either of the coordinates in question matches one   */
		   /* of the coordinates at either end of the line seqment   */
		   /* in question, the line segment is moved east or south.  */
		   /* This has the effect of putting the point in the more   */
		   /* northwesterly polygon.                                 */
		   /*--------------------------------------------------------*/
		   for (k=0;k<n;k++)
		     {
		       if ((xo == xval[k]) || (xo == xl))
		         {
		           xi = xval[k] - 0.0003;
		           xl = xl - 0.0003;
		           dx1 = xl - xo;
		         }
		       else
		         xi = xval[k];
		
		       dx2 = xi - xo;

		       if ((yo == yval[k]) || (yo == yl))
		         {
		           yi = yval[k] - 0.0003; 
		           yl = yl - 0.0003;
		         }
		       else
		         yi = yval[k];


		     /*-------------------------------------------------------------------*/
		     /* If the line segment between two vertices has one x-coordinate < 0 */
		     /* and the other >=xo, then the line segment must intersect the      */
		     /* infinite vertical line through xo the point of intersection is    */
		     /* (xo,yo+tt).                                                       */
		     /*-------------------------------------------------------------------*/

			 // had double cast in front of 0.0

		     if (((dx1 < 0.0) && (dx2 >= 0.0))
		        || ((dx1 >= 0.0) && (dx2 < 0.0)))
		        {
		          tt = (yl - yo) - (xl - xo)*(yi - yl)/(xi - xl);
		          if (yo <= (yo + tt))
					{
			            ++cross;
						//alert("cross " + cross + " at " + i);
					}

			    }
		
			     xl = xi;
			     yl = yi;
			     dx1 = dx2;

		  } // end for loop

             for (j=0;j<cnt;j++)
             {
                  if (cross == (j-1))
                    {
                      inside=1;
					  return(inside);
                    }   // end if
                  ++j;
             }   // end for

		return(inside);
} // end is_in_poly

//--------------------------------------
function getMarks() {

  var startNum=0;



  //---------------------------------------------
  // Check the size of the retrieval area
  //---------------------------------------------
  var scaleDist = parent.MapFrame.getScaleBarDistance();



  if (scaleDist > 6.0) {
    alert ("Area too large to retrieve'\nZoom in until scalebar shows 5 mi or less.\n");
    return;
  }


  parent.MapFrame.storeDbClick(-1);



  var minlon = Math.abs(parent.MapFrame.eRight);
  var maxlon = Math.abs(parent.MapFrame.eLeft);
  var minlat = Math.abs(parent.MapFrame.eBottom);
  var maxlat = Math.abs(parent.MapFrame.eTop);


  //-----------------------------------------------------------
  // Enable marks when first retrieved.
  //-----------------------------------------------------------
  //parent.MapFrame.clickFunction('markIcon');
  //parent.ToolFrame.setToolPic('Enable Marks');
  //parent.MapFrame.status='Enable Marks';
  //-----------------------------------------------------------

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
  statusWin = window.open('', 'statusWin', 'height=300,width=500,scrollbars=1,resizable=1');
  with (statusWin.document) {
    writeln ("<HTML>" +
     "<TITLE>Status Window</TITLE>" +
     "<HEAD>" +
     "<BODY>" +
     "<TT><B>RETRIEVING DATA, PLEASE STAND BY...</B></TT>" +
     "</BODY>" +
     "</HTML>");
     close();
  }
  //statusWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_request.prl?MINLAT=" + minlat + "&MAXLAT=" + maxlat + "&MINLON=" + minlon + "&MAXLON=" + maxlon;
  statusWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_request.prl?MINLAT=" + minlat + "&MAXLAT=" + maxlat + "&MINLON=" + minlon + "&MAXLON=" + maxlon;
  //statusWin.location = "http://205.156.38.36/cgi-bin/Craig/map_request.prl?MINLAT=" + minlat + "&MAXLAT=" + maxlat + "&MINLON=" + minlon + "&MAXLON=" + maxlon;
  statusWin.focus();
}
//--------------------------------------
function getMarksCors() {

  var startNum=0;



  //---------------------------------------------
  // Check the size of the retrieval area
  //---------------------------------------------
  var scaleDist = parent.MapFrame.getScaleBarDistance();





  parent.MapFrame.storeDbClick(-1);



  var minlon = Math.abs(parent.MapFrame.eRight);
  var maxlon = Math.abs(parent.MapFrame.eLeft);
  var minlat = Math.abs(parent.MapFrame.eBottom);
  var maxlat = Math.abs(parent.MapFrame.eTop);



  statusWin = window.open('', 'statusWin', 'height=300,width=500,scrollbars=1,resizable=1');
  with (statusWin.document) {
    writeln ("<HTML>" +
     "<TITLE>Status Window</TITLE>" +
     "<HEAD>" +
     "<BODY>" +
     "<TT><B>RETRIEVING DATA, PLEASE STAND BY...</B></TT>" +
     "</BODY>" +
     "</HTML>");
     close();
  }

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
    //statusWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_request.prl?MAP=CORS";
    statusWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_request.prl?MAP=CORS";
    //statusWin.location = "http://205.156.38.36/cgi-bin/Craig/map_request.prl?MAP=CORS";
  statusWin.focus();
}
//--------------------------------------------
function showMarks() {
  var i=0;

//alert(" got this far into showMarks "); //tom rocks

  if ((!parent.NgsMap2.dbArray)
  ||  (typeof parent.NgsMap2.dbArray[0] == "undefined")) {
    parent.NgsMap2.clearMap();
     alert("No Marks Found");
     return;
   }

  //-------------------------------------------------------------
  // Clear out the previous View List if checkbox is not checked
  //-------------------------------------------------------------
  if (parent.MapFrame.appendToEnd != true) {
    parent.MapFrame.clearSelected(1);
  }

  parent.MapFrame.drawMyAcetate = true;
  for (i=0;i<parent.NgsMap2.dbArray.length;i++) {
    parent.NgsMap2.storeViewString(i);
  }
  parent.NgsMap2.storeViewTrailer();

  parent.MapFrame.enablePostView = true;
  parent.TOCFrame.updateLayers();
}
//------------------------------------
function removeMarks() {

  parent.NgsMap2.clearMap();


  parent.MapFrame.showGeocode = false;
  parent.MapFrame.drawMyAcetate = false;
  parent.MapFrame.drawMyAcetate2 = false;
  parent.TOCFrame.updateLayers();
  return(0);
}
//--------------------------------------------
function addMapPoints() {

  var coord = new Array();
  var types = new Array();
  var mapIds = new Array();
  var fields = new Array();
  var storedX=0;
  var storedY=0;
  var fields = new Array();
  var temp = "";
  var xy = new Array();
  var clickLoc=-1;
  var markWidth=5;
  var searchString = "";
  var found=0;
  var controlText = " ";
  var markBlueText = "";
  var grabTop=0;
  var grabBottom=0;
  var grabRight=0;
  var grabLeft=0;
  var num=0;
  var i=0;
  var j=0;


  var controlType = parent.NgsMap2.getControlType();






  if (controlType == "X-0") {
      controlText = "All Stations";
  } else if (controlType == "CORS") {
      controlText = "CORS";
  } else if (controlType == "H-0") {
      controlText = "Any Horizontal Control";
  } else if (controlType == "H-A") {
      controlText = "Horz. Order-A";
  } else if (controlType == "H-B") {
      controlText = "Horz. Order-B or better";
  } else if (controlType == "H-1") {
      controlText = "Horz. Order-1 or better";
  } else if (controlType == "H-2") {
      controlText = "Horz. Order-2 or better";
  } else if (controlType == "V-0") {
      controlText = "Any Vertical Control";
  } else if (controlType == "V-1") {
      controlText = "Vert. Order-1 or better";
  } else if (controlType == "V-2") {
      controlText = "Vert. Order-2 or better";
  } else {
      controlText = "Unknown Type";
  }




  if (typeof parent.NgsMap2.dbArray[0] == "undefined") {
    alert("ERROR(103) - Nothing to mark\nDo 'Display Stations' first\n");
    return;
  }


   //--------------------------------------------------------------------
   // Attempting to plot stations outside the currect view will cause slowdown.
   // This occurs when a user retrieves stations, then zooms in again.
   // The next step overcomes this problem by disregarding any station
   // which falls outside the current view.
   // The stations are not deleted, they are still in dbArray.
   // If the user zooms out they will be available again.
   //--------------------------------------------------------------------
   j=0;
   found=0;
   clickLoc = getLastClick();


   if (clickLoc > 0) {
       coord = xCoord(parent.NgsMap2.dbArray);
       types = xTypes(parent.NgsMap2.dbArray);
       mapIds = xMapIds(parent.NgsMap2.dbArray);
       found=1;
   } else {
       for (i=0;i<parent.NgsMap2.dbArray.length;i++) {
         if (parent.NgsMap2.dbArray[i] == "")  {
           alert("ERROR - Array element lost");
         }
         fields = parent.NgsMap2.dbArray[i].split("|");
         xy = fields[1].split(/\s/);
         if ((parseFloat(xy[0]) > eLeft)
         &&  (parseFloat(xy[0]) < eRight)
         &&  (parseFloat(xy[1]) > eBottom)
         &&  (parseFloat(xy[1]) < eTop)) {
           found=1;
           mapIds[j] = fields[0]
           coord[j] = fields[1];
           types[j] = fields[7];
           ++j;
         }
       }
   }


   fields = void 0;
   xy = void 0;
   if (found == 0) {
     return theText;
   }

  var fields = new Array();


   found=0;
   if (clickLoc >= 0) {    // Individually selected mark
        num = clickLoc.valueOf();
        theText += '<LAYER type="ACETATE" name="MyAcetate">\n';
        theText += '<OBJECT units="DECIMAL_DEGREES">\n';
        theText += '<POINT coord="' + coord[num] + '">\n';
        theText += getMarkSymbolRed(types[num]);
        theText += '</POINT>\n';
        theText += '</OBJECT>\n';
        theText += '</LAYER>\n';
   } else if (clickLoc == -98) {   // -98 set in markPoints() for certain type
        found=0;
        for (i=0;i<coord.length;i++) {
          if (isMatch(controlType, types[i]) == true) {
            if (found == 0) {
                theText += '<LAYER type="ACETATE" name="MyAcetate">\n';
                found=1;
            }
            theText += '<OBJECT units="DECIMAL_DEGREES">\n';
            theText += '<POINT coord="' + coord[i] + '">\n';
            theText += getMatchSymbol(controlType, types[i]);
            theText += '</POINT>\n';
            theText += '</OBJECT>\n';
          }
        } //end-for
        if (found == 1) {
          theText += '</LAYER>\n';
        }
   } else if (clickLoc == -99) {   // -99 set in markAll() for ALL types
        theText += '<LAYER type="ACETATE" name="MyAcetate">\n';
        for (i=0;i<coord.length;i++) {
          theText += '<OBJECT units="DECIMAL_DEGREES">\n';
          theText += '<POINT coord="' + coord[i] + '">\n';
          theText += getMarkSymbolRed(types[i]);
          theText += '</POINT>\n';
          theText += '</OBJECT>\n';
        }
        theText += '</LAYER>\n';
   } else if (clickLoc == -100) {   // -100 set in unmarkAll() None types
        theText += '<LAYER type="ACETATE" name="MyAcetate">\n';
        for (i=0;i<coord.length;i++) {
          theText += '<OBJECT units="DECIMAL_DEGREES">\n';
          theText += '<POINT coord="' + coord[i] + '">\n';
          theText += getMarkSymbol(types[i]);
          theText += '</POINT>\n';
          theText += '</OBJECT>\n';
        }
        theText += '</LAYER>\n';
   } else if (clickLoc == -101) {   // -101 set in findGrabbedMarks()
        grabTop = getGrabTop();
        grabBottom = getGrabBottom();
        grabRight = getGrabRight();
        grabLeft = getGrabLeft();
        found=0;
        for (i=0;i<coord.length;i++) {
           temp = coord[i].toString();
           fields = temp.split(/\s/);
           storedX = parseFloat(fields[0]);
           storedY = parseFloat(fields[1]);
           if ((storedX > grabRight) && (storedX < grabLeft)
           &&  (storedY > grabBottom) && (storedY < grabTop)) {
                 if (found == 0) {
                      theText += '<LAYER type="ACETATE" name="MyAcetate">\n';
                      found=1;
                 }
                 theText += '<OBJECT units="DECIMAL_DEGREES">\n';
                 theText += '<POINT coord="' + coord[i] + '">\n';
                 theText += getMarkSymbolRed(types[i]);
                 theText += '</POINT>\n';
                 theText += '</OBJECT>\n';
           }
        }
        if (found == 1) {
            theText += '</LAYER>\n';
        }
   } else {
        theText += '<LAYER type="ACETATE" name="MyAcetate">\n';
        for (i=0;i<coord.length;i++) {
          theText += '<OBJECT units="DECIMAL_DEGREES">\n';
          theText += '<POINT coord="' + coord[i] + '">\n';
          theText += getMarkSymbol(types[i]);
          theText += '</POINT>\n';
          theText += '</OBJECT>\n';
          theText += '<OBJECT units="DECIMAL_DEGREES">\n';
          theText += '<TEXT coord="' + coord[i] + '" label="' + mapIds[i] + '">\n';
          theText += '<TEXTMARKERSYMBOL font="Arial" />\n';
          theText += '</TEXT>\n';
          theText += '</OBJECT>\n';
        }
        theText += '</LAYER>\n';
   }



   //parent.MapFrame.storeDbClick(-1);

   if (typeof coord != "undefined") {
     coord = void 0;
     types = void 0;
     mapIds = void 0;
   }
   return theText;

 }
//--------------------------------------------
function addMapBox() {
  var fields = new Array();
  var type="";
  var minx = 0;
  var miny = 0;
  var maxx = 0;
  var maxy = 0;
  var labelXY = "";
  var labelText = "";


  var xyString = parent.NgsMap2.getGotoData();

  fields = xyString.split("|");



  type = fields[0];

  if ((type != "BY_QUAD") && (type != "BY_FBN") && (type != "BY_HTMOD")) {
    return(theText);
  }

  minx = parseFloat(fields[1]);
  miny = parseFloat(fields[2]);
  maxx = parseFloat(fields[3]);
  maxy = parseFloat(fields[4]);

  labelText = fields[5];

  labelXY = minx + " " + maxy;



   fields = void 0;

   theText += '<LAYER type="ACETATE" name="MyAcetate2">\n';
   theText += '<OBJECT units="DECIMAL_DEGREES">\n';
   theText += '<LINE coords="' + minx + ' ' + miny + ' ' + maxx + ' ' + miny + ' ' + maxx + ' ' + maxy + ' ' + minx + ' ' + maxy + ' ' + minx + ' ' + miny + '">n';
   theText += '<SIMPLELINESYMBOL color="255,0,255" />\n';
   theText += '</LINE>\n';
   theText += '</OBJECT>\n';
   theText += '<OBJECT units="DECIMAL_DEGREES">\n';
   theText += '<TEXT coord="' + labelXY + '" label="' + labelText + '">\n';
   theText += '<TEXTMARKERSYMBOL font="Arial" glowing="255,255,000" />\n';
   theText += '</TEXT>\n';
   theText += '</OBJECT>\n';
   theText += '</LAYER>\n';

   return theText;

 }
//-----------------------------------------------
function openPropWindow(theWin) {



  var newWin = window.open('', 'newWin', 'height=423,width=786,scrollbars=1,resizable=1');
  newWin.document.open('text/html');
  newWin.document.bgColor='skyblue';
  newWin.document.fgColor='black';

  with (newWin.document) {
     write("+++++++++++++++++++++++++++++++++++++++++<br><br>");
      for (prop in theWin) {
        write("theWin." + prop + " = " + theWin[prop] + "<br>");
     }
     close();
  }
}
//-------------------------------------
function xCoord(myArray) {
   var loc=0;
   var fields = new Array();
   var coord = new Array();


   for (i=0;i<myArray.length;i++) {
     if (myArray[i] == "")  {
       alert("ERROR - Array element lost");
     }
     fields = myArray[i].split("|");
     coord[i] = fields[1];
   }

  fields = void 0;

  return(coord);
}
//-------------------------------------
function xTypes(myArray) {
   var loc=0;
   var fields = new Array();
   var types = new Array();


   //---------------------------------------------------------------------------
   // myArray[0] = 1|-103.0,38.0|MN0298|B-1|N380000|W1030000|B...|JONES TANK|H-B,V-1
   //---------------------------------------------------------------------------
   for (i=0;i<myArray.length;i++) {
     fields = myArray[i].split("|");
     types[i] = fields[7];
   }

  fields = void 0;

  return(types);
}
//-------------------------------------
function xMapIds(myArray) {
   var loc=0;
   var fields = new Array();
   var mapIds = new Array();


   //---------------------------------------------------------------------------
   // myArray[0] = 1|-103.0,38.0|MN0298|B-1|N380000|W1030000|B...|JONES TANK|H-B,V-1
   //---------------------------------------------------------------------------
   for (i=0;i<myArray.length;i++) {
     fields = myArray[i].split("|");
     mapIds[i] = fields[0]
   }

  fields = void 0;

  return(mapIds);

}
//--------------------------------------
//--------------------------------------

function zoom2Topo(list) {
  var listText = "";
  var count = 0;
  var fields = new Array();
  var lat = "";
  var lon = "";
  var y=0.0;
  var x=0.0;

  for (i=0;i<list.length;i++) {
    if (list[i].selected) {
      listText = list[i].text;
      ++count;
    }
  }

  if (count == 0) {
    alert("No mark selected\nGo back and click on a station\nyou want to zoom to\nbefore clicking ZoomTo.\n");
  } else if (count > 1) {
    alert("You have more than one mark selected\nGo back and select ONLY ONE.\n\nbefore clicking ZoomTo\n");
  } else {
      fields = listText.split("|");
      lat = fields[4];
      lon = fields[5];

      fields = void 0;

      if ((lat.substr(0, 3) == "Lat") || (lat.substr(0, 3) == "---")) {
        alert("ERROR - Attemping to use header as input to ZoomTo\nGo Back and click on a valid station\nthen click ZoomTo");
        return;
      }

      y = dms2MapPos(lat);
      x = dms2MapPos(lon);


      var myHeight = parent.MapFrame.innerHeight - 50;
      var myWidth  = parent.MapFrame.innerWidth - 50;
      var myFeatures = "";

      //y = 38.8893559;   //Wash Mon in DC for testing
      //x = -77.035543;   //Wash Mon in DC for testing

//*** Changed, moved application from Seashore to Jupiter 3/5/04 *** //
//
      myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1, locationbar=1,toolbar=1,scrollbars=1,resizable=1";
      topoZonewin = window.open('', 'topoZonewin', myFeatures);
      //topoZonewin.location = 'http://www.topozone.com/map.asp?lat='+y+'&lon='+x+'&s=25&sym=http://www.ngs.noaa.gov/ims/NgsMap2/images/cross.gif&symy=50&symx=50&u=2';
      topoZonewin.location = 'http://www.topozone.com/map.asp?lat='+y+'&lon='+x+'&s=25&sym=http://www.ngs.noaa.gov/ngsims/NgsMap2/images/cross.gif&symy=50&symx=50&u=2';
      //topoZonewin.location = 'http://www.topozone.com/map.asp?lat='+y+'&lon='+x+'&s=25&sym=http://205.156.38.36/website/NgsMap2/images/cross.gif&symy=50&symx=50&u=2';
      topoZonewin.focus();
   }
}



//--------------------------------------
function zoom2Mark(list) {
  var listText = "";
  var count = 0;
  var fields = new Array();
  var lat = "";
  var lon = "";
  var y=0.0;
  var x=0.0;

  for (i=0;i<list.length;i++) {
    if (list[i].selected) {
      listText = list[i].text;
      ++count;
    }
  }

  if (count == 0) {
    alert("No mark selected\nGo back and click on a station\nyou want to zoom to\nbefore clicking ZoomTo.\n");
  } else if (count > 1) {
    alert("You have more than one mark selected\nGo back and select ONLY ONE.\n\nbefore clicking ZoomTo\n");
  } else {
      fields = listText.split("|");
      lat = fields[4];
      lon = fields[5];

      fields = void 0;

      if ((lat.substr(0, 3) == "Lat") || (lat.substr(0, 3) == "---")) {
        alert("ERROR - Attemping to use header as input to ZoomTo\nGo Back and click on a valid station\nthen click ZoomTo");
        return;
      }

      y = dms2MapPos(lat);
      x = dms2MapPos(lon);



      parent.MapFrame.selectPointMargin = 25/15000;

      parent.MapFrame.zoomToPoint(x, y, 1, "");
  }

}
//--------------------------------------
function openFileWin(mIndex, list) {
  var myFeatures = "";
  var myHeight;
  var myWidth;
  var listText = "";
  var mySize=10;
  var myMsg="";
  var i=0;




  if (mIndex == 0) {
    return;
  } else if (mIndex == 1) {
      myMsg = "Use File button in top menu bar to Print";
  } else if (mIndex == 2) {
  }
      myMsg = "Use File button in top menu bar to Save";
  //------------------------------------------------------------------------
  // If user previously moved the window then open it where he/she left it
  //------------------------------------------------------------------------

  myHeight = (mySize * 20) + 50;
  myWidth  = 750;

  if (isNaN(myHeight)) {
    myHeight = 150;
  }

  if (isNaN(myWidth)) {
    myWidth = 600;
  }



  myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,toolbar=1,scrollbars=1,resizable=1";

  fileWin = window.open('', 'fileWin', myFeatures);


  with (fileWin.document) {
    writeln ("<HTML>" +
    "<TITLE>Station Record Window</TITLE>" +
    "<HEAD>" +
     "<STYLE>" +
     "SELECT\{font-family: monospace\;\}" +
     "</STYLE>" +
     "</HEAD>" +
"<BODY BGCOLOR='#ffffcc'>" +
     "<FONT FACE = 'COURIER'>" +
     "<PRE>");
     for (i=0;i<list.length;i++) {
       writeln(list[i].text);
     }
     writeln ("</BODY>" +
     "</HTML>");
     close();
  }


  fileWin.focus();
}
//--------------------------------------
function sortPidWin(mIndex) {
  var tempRay = new Array();
  var lastStored="";
  var cnt=2;    // start adding after header
  var i=0;



       //----------------------------
       //0 = Sort (Do Nothing
       //1 = MapID
       //2 = Pid
       //3 = H-Order
       //4 = V-Order
       //5 = Vert_Source
       //6 = Lat
       //7 = Lon
       //8 = Stab
       //9 = Designation
       //----------------------------

  if (mIndex == 0) {
    return;
  }


  //--------------------------------------------
  // Sort the View Array
  //--------------------------------------------
  tempRay = parent.NgsMap2.viewArray;
  if (mIndex == 1) {
       tempRay.sort();
  } else if (mIndex == 2) {
       tempRay.sort(compare_pid);
  } else if (mIndex == 3) {
       tempRay.sort(compare_horder);
  } else if (mIndex == 4) {
       tempRay.sort(compare_vorder);
  } else if (mIndex == 5) {
       tempRay.sort(compare_vsource);
  } else if (mIndex == 6) {
       tempRay.sort(compare_lat);
  } else if (mIndex == 7) {
       tempRay.sort(compare_lon);
  } else if (mIndex == 8) {
       tempRay.sort(compare_stab);
  } else if (mIndex == 9) {
       tempRay.sort(compare_desig);
  }

  parent.MapFrame.clearSelected(1);

  cnt=2;
  for (i=0;i<tempRay.length;i++) {
    if (tempRay[i] == lastStored) {
         continue;
    } else if ((tempRay[i].indexOf("MapID", 0) == 0)
    ||  (tempRay[i].indexOf("=====", 0) == 0)
    ||  (tempRay[i].indexOf("-----", 0) == 0)) {
        continue;
    } else {
        parent.NgsMap2.viewArray[cnt++] = tempRay[i];
        lastStored = tempRay[i];
    }
  }

  //alert("Cnt = " + cnt);
  //dumpArray(parent.NgsMap2.viewArray);
  tempRay = void 0;

  if (parent.MapFrame.getSdtsStatus() == true) {
    openSdtsPidWindow(10);
  } else {
    openPidWindow(10);
  }
}
//==========================================
function compare_pid(a, b) {
  var pid1 = a.substr(6,6);
  var pid2 = b.substr(6,6);

  if (pid1 < pid2) {
      return(-1);
  } else if (pid1 > pid2) {
      return(1);
  } else {
      return(0);
  }
}
//==========================================
function compare_horder(a, b) {
  var h1 = a.substr(13,1);
  var h2 = b.substr(13,1);

   if ((h1 == "A") && (h2 != "A")) {
       return(-1);
   } else if ((h1 == "B") && (h2 != "A") && (h2 != "B")){
       return(-1);
   } else if ((h2 == "A") && (h1 != "A")) {
       return(1);
   } else if ((h2 == "B") && (h1 != "A") && (h1 != "B")){
       return(1);
   } else if ((h1 == ".") && (h2 == ".")) {
       return(0);
   } else if (h1 == ".") {
       return(1);
   } else if (h2 == ".") {
       return(-1);
   } else if (h1 < h2) {
       return(-1);
   } else if (h1 > h2) {
       return(1);
   } else {
       return(0);
   }
}
//==========================================
function compare_vorder(a, b) {
  var v1 = a.substr(15,1);
  var v2 = b.substr(15,1);


   if ((v1 == ".") && (v2 == ".")) {
       return(0);
   } else if (v1 == ".") {
       return(1);
   } else if (v2 == ".") {
       return(-1);
   } else if (v1 < v2) {
       return(-1);
   } else if (v1 > v2) {
       return(1);
   } else {
       return(0);
   }
}

//==========================================
function compare_vsource(a, b) {
  var v1 = a.substr(17,1);
  var v2 = b.substr(17,1);


   if ((v1 == "8") && (v2 != "8")) {
     return(-1);
   } else if ((v1 == "2") && (v2 != "8") && (v2 != "2")){
     return(-1);
   } else if ((v2 == "8") && (v1 != "8")) {
     return(1);
   } else if ((v2 == "2") && (v1 != "8") && (v1 != "2")){
     return(1);
   } else if ((v1 == ".") && (v2 == ".")) {
     return 0;
   } else if (v1 == ".") {
     return 1;
   } else if (v2 == ".") {
     return -1;
   } else if (v1 < v2) {
       return(-1);
   } else if (v1 > v2) {
       return(1);
   } else {
       return(0);
   }
}
//==========================================
function compare_lat(a, b) {
  var lat1 = a.substr(29,7);
  var lat2 = b.substr(29,7);


  if (lat1 < lat2) {
      return(-1);
  } else if (lat1 > lat2) {
      return(1);
  } else {
      return(0);
  }
}
//==========================================
function compare_lon(a, b) {
  var lon1 = a.substr(37,8);
  var lon2 = b.substr(37,8);

  if (lon1 < lon2) {
      return(-1);
  } else if (lon1 > lon2) {
      return(1);
  } else {
      return(0);
  }
}
//==========================================
function compare_stab(a, b) {
  var stab1 = a.substr(46,1);
  var stab2 = b.substr(46,1);

   if ((stab1 == "A") && (stab2 != "A")) {
       return(-1);
   } else if ((stab1 == "B") && (stab2 != "A") && (stab2 != "B")){
       return(-1);
   } else if ((stab1 == "C") && (stab2 != "A") && (stab2 != "B") && (stab2 != "C")){
       return(-1);
   } else if ((stab1 == "D") && (stab2 != "A") && (stab2 != "B") && (stab2 != "C") && (stab2 != "D")){
       return(-1);
   } else if ((stab2 == "A") && (stab1 != "A")) {
       return(1);
   } else if ((stab2 == "B") && (stab1 != "A") && (stab1 != "B")){
       return(1);
   } else if ((stab2 == "C") && (stab1 != "A") && (stab1 != "B") && (stab1 != "C")){
       return(1);
   } else if ((stab2 == "D") && (stab1 != "A") && (stab1 != "B") && (stab1 != "C") && (stab1 != "D")){
       return(1);
   } else if ((stab1 == ".") && (stab2 == ".")) {
       return(0);
   } else if (stab1 == ".") {
       return(1);
   } else if (stab2 == ".") {
       return(-1);
   } else if (stab1 < stab2) {
       return(-1);
   } else if (stab1 > stab2) {
       return(1);
   } else {
       return(0);
   }
}
//==========================================
function compare_desig(a, b) {
  var desig1 = a.substr(51);
  var desig2 = b.substr(51);

  if (desig1 < desig2) {
      return(-1);
  } else if (desig1 > desig2) {
      return(1);
  } else {
      return(0);
  }
}
//======================================
function resetPidWin() {
  parent.MapFrame.clearSelected(1);
  if (parent.MapFrame.getSdtsStatus() == true) {
    openSdtsPidWindow(10);
  } else {
    openPidWindow(10);
  }
}
//--------------------------------------
function openPidWindow(mySize) {
  var myFeatures = "";
  var myHeight;
  var myWidth;
  var i=0;



  //------------------------------------------------------------------------
  // If user previously moved the window then open it where he/she left it
  //------------------------------------------------------------------------

  myHeight = (mySize * 20) + 120;
  myWidth  = 750;

  if (isNaN(myHeight)) {
    myHeight = 150;
  }

  if (isNaN(myWidth)) {
    myWidth = 600;
  }






  myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,toolbar=1,scrollbars=1,resizable=1";

  pidWin = window.open('', 'pidWin', myFeatures);

  with (pidWin.document) {

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
    //writeln ("<HTML>" +
    //"<TITLE>Station Record Window</TITLE>" +
    //"<HEAD>" +
     //"<STYLE>" +
     //"SELECT\{font-family: monospace\;\}" +
     //"</STYLE>" +
     //"</HEAD>" +
     //"<BODY>" +
     //"<FORM NAME='PidForm' ACTION = 'http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_ds.prl' METHOD = POST> " +
     //"<FONT FACE = 'COURIER'>" +
     //"<A HREF='http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_help.prl?DISPLAY_MARK_LIST_FORMAT=1'>Explain Format</A>" +
     //"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");

    writeln ("<HTML>" +
    "<TITLE>Station Record Window</TITLE>" +
    "<HEAD>" +
     "<STYLE>" +
     "SELECT\{font-family: monospace\;\}" +
     "</STYLE>" +
     "</HEAD>" +
     "<BODY>" +
     "<FORM NAME='PidForm' ACTION = 'http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_ds.prl' METHOD = POST> " +
     "<FONT FACE = 'COURIER'>" +
     "<A HREF='http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_help.prl?DISPLAY_MARK_LIST_FORMAT=1'>Explain Format</A>" +
     "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");

    //writeln ("<HTML>" +
    //"<TITLE>Station Record Window</TITLE>" +
    //"<HEAD>" +
     //"<STYLE>" +
     //"SELECT\{font-family: monospace\;\}" +
     //"</STYLE>" +
     //"</HEAD>" +
     //"<BODY>" +
     //"<FORM NAME='PidForm' ACTION = 'http://205.156.38.36/cgi-bin/Craig/map_ds.prl' METHOD = POST> " +
     //"<FONT FACE = 'COURIER'>" +
     //"<A HREF='http://205.156.38.36/cgi-bin/Craig/map_help.prl?DISPLAY_MARK_LIST_FORMAT=1'>Explain Format</A>" +
     //"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");



     if (parent.MapFrame.appendToEnd == true) {
         writeln("<INPUT TYPE='checkbox' NAME='SaveBox' VALUE='1' onClick='opener.SetCheckBox(this.form.SaveBox.checked)' CHECKED>Always append new selections to end of list<br>");
     } else {
         writeln("<INPUT TYPE='checkbox' NAME='SaveBox' VALUE='1' onClick='opener.SetCheckBox(this.form.SaveBox.checked)'>Always append new selections to end of list<br>");
     }

     writeln ("<SELECT NAME='PidList' SIZE='" + mySize + "' MULTIPLE>");
     for (i=0;i<parent.NgsMap2.viewArray.length;i++) {
       writeln ("<OPTION VALUE=" + parent.NgsMap2.viewArray[i].substr(6,6) + ">" + parent.NgsMap2.viewArray[i]);
     }
    writeln("</SELECT><BR>" +
     "<INPUT TYPE = 'submit' VALUE='Get Datasheets'>" +
     //"<INPUT TYPE = 'button' VALUE='ZoomTo' onclick='opener.zoom2Mark(document.PidForm.PidList.options)'>" +


     "<SELECT NAME='ZoomMenu' SIZE='1' onChange=' if (navigator.appName.indexOf(\"Netscape\")>=0){ if (this.form.ZoomMenu.options.selectedIndex != 0){ if (this.form.ZoomMenu.options.selectedIndex == 1) { opener.zoom2Mark(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true} else { opener.zoom2Topo(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true } } }' onClick='if (this.form.ZoomMenu.options.selectedIndex != 0) { if (this.form.ZoomMenu.options.selectedIndex == 1) { opener.zoom2Mark(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true} else { opener.zoom2Topo(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true}}'>" +
        "<OPTION SELECTED> Zoom..." +
        "<OPTION> ZoomTo" +
        "<OPTION> ZoomTo TopoZone" +
        "</SELECT>" +
         "<SELECT NAME='SortViewMenu' SIZE='1' onChange='if (navigator.appName.indexOf(\"Netscape\")>=0){if (this.form.SortViewMenu.options.selectedIndex != 0){opener.sortPidWin(this.form.SortViewMenu.options.selectedIndex)}}' onClick='if (this.form.SortViewMenu.options.selectedIndex != 0) {opener.sortPidWin(this.form.SortViewMenu.options.selectedIndex)}'>" +
           "<OPTION SELECTED> Sort..." +
           "<OPTION> By MapID" +
           "<OPTION> Pid" +
           "<OPTION> H-Order" +
           "<OPTION> V-Order" +
           "<OPTION> Vert_Source" +
           "<OPTION> Lat" +
           "<OPTION> Lon" +
           "<OPTION> Stab" +
           "<OPTION> Designation" +
           "</SELECT>" +
     "<SELECT NAME='FileMenu' SIZE='1' onChange=' if (navigator.appName.indexOf(\"Netscape\")>=0){ if (this.form.FileMenu.options != 0){ opener.openFileWin(this.form.FileMenu.options.selectedIndex,this.form.PidList.options) ;this.form.FileMenu.options[0].selected=true } }' onClick=' if (this.form.FileMenu.options != 0) { opener.openFileWin(this.form.FileMenu.options.selectedIndex,this.form.PidList.options) ;this.form.FileMenu.options[0].selected=true }'>" +
        "<OPTION SELECTED> Move..." +
        "<OPTION> to Print Window" +
        "<OPTION> to Save Window." +
        "</SELECT>" +
        "<BR>" +
     "<SELECT NAME='ClearMenu' SIZE='1' onChange='if (navigator.appName.indexOf(\"Netscape\")>=0){if (this.form.ClearMenu.options.selectedIndex != 0){if (this.form.ClearMenu.options.selectedIndex == 1) {opener.resetPidWin()} else {opener.sortPidWin(1)}}}' onClick='if (this.form.ClearMenu.options.selectedIndex != 0) {if (this.form.ClearMenu.options.selectedIndex == 1) {opener.resetPidWin()} else {opener.sortPidWin(1)}}'>" +
        "<OPTION SELECTED> Clear..." +
        "<OPTION> Clear All" +
        "<OPTION> Clear Duplicates" +
        "</SELECT>" +

     "<INPUT TYPE = 'button' VALUE='Close' onclick='opener.ClosePidWin(window, this.form.SaveBox.checked)'>" +
     "</FORM>" +
     "</BODY>" +
     "</HTML>");
     close();
  }



  pidWin.focus();
}
//--------------------------------------
function openSdtsPidWindow(mySize) {
  var myFeatures = "";
  var myHeight;
  var myWidth;
  var i=0;
  var rnum;
  var mText = "";
  var modualId = "SDTS";



  //-----------------------------------------------------------
  // Was originally setting Modual ID to 4 random letters
  // letter 1 + letter2 + letter3 + letter4
  // But changed it to just "SDTS"
  // This should be okay since the returned files
  // are stored in individually unique directories
  //-----------------------------------------------------------

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
  //mText = "<a href='http://www.ngs.noaa.gov/ims-cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_MODUAL_ID'>MODUAL ID</a>:<INPUT TYPE = 'text' SIZE=4 MAXSIZE=4 NAME='DAID' VALUE='" + modualId + "'>";
  mText = "<a href='http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_MODUAL_ID'>MODUAL ID</a>:<INPUT TYPE = 'text' SIZE=4 MAXSIZE=4 NAME='DAID' VALUE='" + modualId + "'>";
  //mText = "<a href='http://205.156.38.36/cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_MODUAL_ID'>MODUAL ID</a>:<INPUT TYPE = 'text' SIZE=4 MAXSIZE=4 NAME='DAID' VALUE='" + modualId + "'>";
  //------------------------------------------------------------------------
  // If user previously moved the window then open it where he/she left it
  //------------------------------------------------------------------------

  myHeight = (mySize * 20) + 150;
  myWidth  = 750;

  if (isNaN(myHeight)) {
    myHeight = 150;
  }

  if (isNaN(myWidth)) {
    myWidth = 600;
  }






  myFeatures = "height=" + myHeight + ",width=" + myWidth + ",menubar=1,toolbar=1,scrollbars=1,resizable=1";

  pidWin = window.open('', 'pidWin', myFeatures);

  with (pidWin.document) {
//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
    //writeln ("<HTML>" +
    //"<TITLE>Station Record Window</TITLE>" +
    //"<HEAD>" +
     //"<STYLE>" +
     //"SELECT\{font-family: monospace\;\}" +
     //"</STYLE>" +
     //"</HEAD>" +
     //"<BODY>" +
     //"<FORM NAME='PidForm' ACTION = 'http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_sdts.prl' METHOD = POST> " +
     //"<FONT FACE = 'COURIER'>" +
     //"<A HREF='http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_help.prl?DISPLAY_MARK_LIST_FORMAT=1'>Explain Format</A>" +
     //"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");

    writeln ("<HTML>" +
    "<TITLE>Station Record Window</TITLE>" +
    "<HEAD>" +
     "<STYLE>" +
     "SELECT\{font-family: monospace\;\}" +
     "</STYLE>" +
     "</HEAD>" +
     "<BODY>" +
     "<FORM NAME='PidForm' ACTION = 'http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_sdts.prl' METHOD = POST> " +
     "<FONT FACE = 'COURIER'>" +
     "<A HREF='http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_help.prl?DISPLAY_MARK_LIST_FORMAT=1'>Explain Format</A>" +
     "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");

    //writeln ("<HTML>" +
    //"<TITLE>Station Record Window</TITLE>" +
    //"<HEAD>" +
     //"<STYLE>" +
     //"SELECT\{font-family: monospace\;\}" +
     //"</STYLE>" +
     //"</HEAD>" +
     //"<BODY>" +
     //"<FORM NAME='PidForm' ACTION = 'http://205.156.38.36/cgi-bin/Craig/map_sdts.prl' METHOD = POST> " +
     //"<FONT FACE = 'COURIER'>" +
     //"<A HREF='http://205.156.38.36/cgi-bin/Craig/map_help.prl?DISPLAY_MARK_LIST_FORMAT=1'>Explain Format</A>" +
     //"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");


     if (parent.MapFrame.appendToEnd == true) {
         writeln("<INPUT TYPE='checkbox' NAME='SaveBox' VALUE='1' onClick='opener.SetCheckBox(this.form.SaveBox.checked)' CHECKED>Always append new selections to end of list<br>");
     } else {
         writeln("<INPUT TYPE='checkbox' NAME='SaveBox' VALUE='1' onClick='opener.SetCheckBox(this.form.SaveBox.checked)'>Always append new selections to end of list<br>");
     }

     writeln("<SELECT NAME='PidList' SIZE='" + mySize + "' MULTIPLE>");
     for (i=0;i<parent.NgsMap2.viewArray.length;i++) {
       writeln ("<OPTION VALUE=" + parent.NgsMap2.viewArray[i].substr(6,6) + ">" + parent.NgsMap2.viewArray[i]);
     }

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
    //writeln("</SELECT><BR>" +
     //"File <a href='http://www.ngs.noaa.gov/ims-cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_FORMAT'>Format</a>:" +
     //"<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='Zipped' CHECKED>ZIP" +
     //"<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='Compressed'>TAR" +
     //"<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='None'>MultiFile" +
     //"<BR>" +
     //" ");
    writeln("</SELECT><BR>" +
     "File <a href='http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_FORMAT'>Format</a>:" +
     "<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='Zipped' CHECKED>ZIP" +
     "<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='Compressed'>TAR" +
     "<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='None'>MultiFile" +
     "<BR>" +
     " ");
    //writeln("</SELECT><BR>" +
     //"File <a href='http://205.156.38.36/cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_FORMAT'>Format</a>:" +
     //"<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='Zipped' CHECKED>ZIP" +
     //"<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='Compressed'>TAR" +
     //"<INPUT TYPE = 'radio' NAME='COMPRESS' VALUE='None'>MultiFile" +
     //"<BR>" +
     //" ");

     writeln(mText);

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
     writeln(" //<a href='http://205.156.38.36/cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_TITLE'>Title</a>:<INPUT TYPE = 'text' SIZE=40 MAXSIZE=80 NAME='DTITLE' VALUE='National Geodetic Survey SDTS Dataset'>" +

     "<a href='http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_TITLE'>Title</a>:<INPUT TYPE = 'text' SIZE=40 MAXSIZE=80 NAME='DTITLE' VALUE='National Geodetic Survey SDTS Dataset'>" +
     //"<a href='http://www.ngs.noaa.gov/ims-cgi-bin/Craig/craigs_ref.prl?Topic=SDTS_TITLE'>Title</a>:<INPUT TYPE = 'text' SIZE=40 MAXSIZE=80 NAME='DTITLE' VALUE='National Geodetic Survey SDTS Dataset'>" +

     "<BR>" +
     "<INPUT TYPE = 'submit' VALUE='Get SDTS'>" +
     //"<INPUT TYPE = 'button' VALUE='ZoomTo' onclick='opener.zoom2Mark(document.PidForm.PidList.options)'>" +

     "<SELECT NAME='ZoomMenu' SIZE='1' onChange=' if (navigator.appName.indexOf(\"Netscape\")>=0){ if (this.form.ZoomMenu.options.selectedIndex != 0){ if (this.form.ZoomMenu.options.selectedIndex == 1) { opener.zoom2Mark(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true} else { opener.zoom2Topo(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true } } }' onClick='if (this.form.ZoomMenu.options.selectedIndex != 0) { if (this.form.ZoomMenu.options.selectedIndex == 1) { opener.zoom2Mark(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true} else { opener.zoom2Topo(document.PidForm.PidList.options) ;this.form.ZoomMenu.options[0].selected=true}}'>" +

        "<OPTION SELECTED> Zoom..." +
        "<OPTION> ZoomTo" +
        "<OPTION> ZoomTo TopoZone" +
        "</SELECT>" +


         "<SELECT NAME='SortViewMenu' SIZE='1' onChange='if (navigator.appName.indexOf(\"Netscape\")>=0){if (this.form.SortViewMenu.options.selectedIndex != 0){opener.sortPidWin(this.form.SortViewMenu.options.selectedIndex)}}' onClick='if (this.form.SortViewMenu.options.selectedIndex != 0) {opener.sortPidWin(this.form.SortViewMenu.options.selectedIndex)}'>" +
           "<OPTION SELECTED> Sort..." +
           "<OPTION> By MapID" +
           "<OPTION> Pid" +
           "<OPTION> H-Order" +
           "<OPTION> V-Order" +
           "<OPTION> Vert_Source" +
           "<OPTION> Lat" +
           "<OPTION> Lon" +
           "<OPTION> Stab" +
           "<OPTION> Designation" +
           "</SELECT>" +

     "<SELECT NAME='FileMenu' SIZE='1' onChange=' if (navigator.appName.indexOf(\"Netscape\")>=0){ if (this.form.FileMenu.options != 0){ opener.openFileWin(this.form.FileMenu.options.selectedIndex,this.form.PidList.options) ;this.form.FileMenu.options[0].selected=true } }' onClick=' if (this.form.FileMenu.options != 0) { opener.openFileWin(this.form.FileMenu.options.selectedIndex,this.form.PidList.options) ;this.form.FileMenu.options[0].selected=true }'>" +
        "<OPTION SELECTED> Move..." +
        "<OPTION> Print list" +
        "<OPTION> Save list" +
        "</SELECT>" +
        "<BR>" +
     "<SELECT NAME='ClearMenu' SIZE='0' onChange='if (navigator.appName.indexOf(\"Netscape\")>=0){if (this.form.ClearMenu.options.selectedIndex != 0){if (this.form.ClearMenu.options.selectedIndex == 1) {opener.resetPidWin()} else {opener.sortPidWin(1)}}}' onClick='if (this.form.ClearMenu.options.selectedIndex != 0) {if (this.form.ClearMenu.options.selectedIndex == 1) {opener.resetPidWin()} else {opener.sortPidWin(1)}}'>" +
     "<OPTION SELECTED> Clear..." +
     "<OPTION> Clear All" +
     "<OPTION> Clear Duplicates" +
     "</SELECT>" +


     "<INPUT TYPE = 'button' VALUE='Close' onclick='opener.ClosePidWin(window, this.form.SaveBox.checked)'>" +
     "</FORM>" +
     "</BODY>" +
     "</HTML>");
     close();
  }



  pidWin.focus();
}
//--------------------------------------
//--------------------------------------
function ClosePidWin(listWindow, value) {
  parent.MapFrame.appendToEnd = value;
  if (value != true) {
    parent.MapFrame.clearSelected(1);
  }
  listWindow.close();
}
//--------------------------------------
function SetCheckBox(value) {
  parent.MapFrame.appendToEnd = value;
}
//-------------------------------
function openOptionsWindow() {

  optionsWin = window.open('', 'postMessage', 'height=300,width=600,scrollbars=1,resizable=1');
  optionsWin.document.open('text/html');
  optionsWin.document.bgColor='skyblue';
  optionsWin.document.fgColor='black';

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
  //optionsWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_options.prl";
  optionsWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_options.prl";
  //optionsWin.location = "http://205.156.38.36/cgi-bin/Craig/map_options.prl";
  optionsWin.focus();
}
//-------------------------------------
function dumpArray(ray) {
   var dumpWin;
   var myFeatures = "";
   var oMsg = "";
   var i=0;

   for (i=0;i<ray.length;i++) {
     oMsg = oMsg + ray[i] + "\n";
   }
   //alert(oMsg);

  myFeatures = "height=400,width=1000,menubar=1,toolbar=0,scrollbars=1,resizable=1";

  dumpWin = window.open('', 'dumpWin', myFeatures);
  dumpWin.document.bgColor='yellow';
  with (dumpWin.document) {
    writeln ("<HTML>" +
             "<BODY>" +
             "<TT>" +
             oMsg +
             "</TT></BODY></HTML>");
    close();
  }

  dumpWin.focus();
}
//------------------------
function openHelpWindow() {
  var helpWin;
  var winHeight = parent.MapFrame.innerHeight - 50;
  var winWidth  = parent.MapFrame.innerWidth - 50;




  myFeatures = "height=" + winHeight + ",width=" + winWidth + ",menubar=1,toolbar=0,scrollbars=1,resizable=1";

  helpWin = window.open('', 'helpWin', myFeatures);

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
  //helpWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_help.prl";
  helpWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_help.prl";
  //helpWin.location = "http://205.156.38.36/cgi-bin/Craig/map_help.prl";
  helpWin.focus();
}
//------------------------
function openWhatsNewWindow() {
  var whatsNewWin;
  var winHeight = parent.MapFrame.innerHeight - 50;
  var winWidth  = parent.MapFrame.innerWidth - 50;

  myFeatures = "height=" + winHeight + ",width=" + winWidth + ",menubar=1,tollbar=0,scrollbars=1,resizable=1";

  whatsNewWin = window.open('', 'whatsNewWin', myFeatures);

//*** Changed, moved application from Seashore to Jupiter 3/5/04 ***//
//
  //whatsNewWin.location = "http://www.ngs.noaa.gov/ims-cgi-bin/Craig/map_whatsnew.prl";
  whatsNewWin.location = "http://www.ngs.noaa.gov/ngs-cgi-bin/Craig/map_whatsnew.prl";
  //whatsNewWin.location = "http://205.156.38.36/cgi-bin/Craig/map_whatsnew.prl";
  whatsNewWin.focus();
}
//-------------------------------------------------
function getMarkSymbol(type) {

   var hvText = '<SIMPLEMARKERSYMBOL color="000,191,255" jointype="miter" outline="255,000,000" type="square" width="8" />\n';
   var corsText = '<SIMPLEMARKERSYMBOL color="238,130,238" jointype="miter" outline="255,000,000" type="star" width="14" />\n';
   var horzText = '<SIMPLEMARKERSYMBOL color="255,255,000" jointype="miter" outline="255,000,000" type="triangle" width="8" />\n';
   var vertText = '<SIMPLEMARKERSYMBOL color="0,255,127" outline="255,000,000" type="circle" width="7" />\n';

  if (type.indexOf("CORS") >= 0) {
      return(corsText);
  } else if ((type.indexOf("H-") >= 0) && (type.indexOf("V-") >= 0)) {
      return(hvText);
  } else if (type.indexOf("H-") >= 0) {
      return(horzText);
  } else if  (type.indexOf("V-") >= 0) {
      return(vertText);
  }
}
//-----------------------------------------------------
function isMatch(myControlType, type) {

   if ((myControlType == "X-0")
   && (type.indexOf("H-") >=0) && (type.indexOf("V-") >= 0)) {
       return(true);
   } else if (myControlType == "H-A")  {
       if ((type.indexOf("CORS") >= 0)
       ||  (type.indexOf("H-A") >= 0)) {
              return(true);
       }
   } else if (myControlType == "H-B")  {
       if ((type.indexOf("CORS") >= 0)
       ||  (type.indexOf("H-A") >= 0)
       ||  (type.indexOf("H-B") >= 0)) {
              return(true);
       }
   } else if (myControlType == "H-1")  {
       if ((type.indexOf("CORS") >= 0)
       ||  (type.indexOf("H-A") >= 0)
       ||  (type.indexOf("H-B") >= 0)
       ||  (type.indexOf("H-1") >= 0)) {
              return(true);
       }
   } else if (myControlType == "H-2")  {
       if ((type.indexOf("CORS") >= 0)
       ||  (type.indexOf("H-A") >= 0)
       ||  (type.indexOf("H-B") >= 0)
       ||  (type.indexOf("H-1") >= 0)
       ||  (type.indexOf("H-2") >= 0)) {
              return(true);
       }
   } else if ((myControlType == "H-0")
     && ((type.indexOf("H-") >= 0) || (type.indexOf("CORS") >= 0))) {
       return(true);
   } else if (myControlType == "V-1")  {
       if (type.indexOf("V-1") >= 0) {
              return(true);
       }
   } else if (myControlType == "V-2")  {
       if ((type.indexOf("V-1") >= 0)
       ||  (type.indexOf("V-2") >= 0)) {
              return(true);
       }
   } else if ((myControlType == "V-0") && (type.indexOf("V-") >= 0)) {
       return(true);
   } else if (type.indexOf(myControlType) >= 0) {
       return(true);
   }

  return(false);


}
//-----------------------------------------------
function getMatchSymbol(myControlType, type) {
  var redText = "";
  var errorText = '<SIMPLEMARKERSYMBOL color="255,255,255" jointype="miter" outline="255,000,000" type="star" width="18" />\n';

    //----------------------------------------------------------------
    // Handle special cases where myControlType implies certain types.
    // NOTE - Variable type is of the form "V-1, FBN, TID"
    //        therefore use indexOF()
    //----------------------------------------------------------------
    if (myControlType == "X-0") {
        redText = getMarkSymbolRed(type);
        return(redText);
    } else if ((myControlType == "CORS")
      &&       (type.indexOf("CORS") >= 0)) {
          redText = getMarkSymbolRed(type);
          return(redText);
    } else if (myControlType == "H-A") {
       if (type.indexOf("CORS") >= 0) {
          redText = getMarkSymbolRed(type);
          return(redText);
       } else if (type.indexOf("H-A") >= 0) {
          redText = getMarkSymbolRed(type);
          return(redText);
       }
    } else if (myControlType == "H-B") {
       if (type.indexOf("CORS") >= 0) {
          redText = getMarkSymbolRed(type);
          return(redText);
       } else if ((type.indexOf("H-A") >= 0)
         ||      (type.indexOf("H-B") >= 0)) {
          redText = getMarkSymbolRed(type);
          return(redText);
       }
    } else if (myControlType == "H-1") {
       if (type.indexOf("CORS") >= 0) {
          redText = getMarkSymbolRed(type);
          return(redText);
       } else if ((type.indexOf("H-A") >= 0)
         ||       (type.indexOf("H-B") >= 0)
         ||       (type.indexOf("H-1") >= 0)) {
          redText = getMarkSymbolRed(type);
          return(redText);
       }
    } else if (myControlType == "H-2") {
       if (type.indexOf("CORS") >= 0) {
          redText = getMarkSymbolRed(type);
          return(redText);
       } else if ((type.indexOf("H-A") >= 0)
         ||       (type.indexOf("H-B") >= 0)
         ||       (type.indexOf("H-1") >= 0)
         ||       (type.indexOf("H-2") >= 0)) {
          redText = getMarkSymbolRed(type);
          return(redText);
       }
    } else if ((myControlType == "H-0")
      &&       ((type.indexOf("H-") >= 0) || (type.indexOf("CORS") >= 0))) {
        redText = getMarkSymbolRed(type);
        return(redText);
    } else if (myControlType == "V-2") {
       if  ((type.indexOf("V-1") >= 0)
       ||  (type.indexOf("V-2") >= 0)) {
          redText = getMarkSymbolRed(type);
          return(redText);
       }
    } else if ((myControlType == "V-0") && (type.indexOf("V-") >= 0)) {
        redText = getMarkSymbolRed(type);
        return(redText);
    } else if (type.indexOf(myControlType) >= 0) {
        redText = getMarkSymbolRed(type);
        return(redText);
    }

    //-------------------------------------
    // If Problem, mark it with white star
    //-------------------------------------
    return(errorText);
}
//-------------------------------------------------
function getMarkSymbolRed(type) {
   var redCorsText = '<SIMPLEMARKERSYMBOL color="255,000,000" jointype="miter" outline="255,000,000" type="star" width="14" />\n';
   var redHvText = '<SIMPLEMARKERSYMBOL color="255,000,000" jointype="miter" outline="255,000,000" type="square" width="8" />\n';
   var redHorzText = '<SIMPLEMARKERSYMBOL color="255,000,000" jointype="miter" outline="255,000,000" type="triangle" width="8" />\n';
   var redVertText = '<SIMPLEMARKERSYMBOL color="255,000,000" outline="255,000,000" type="circle" width="7" />\n';


  if (type.indexOf("CORS") >= 0) {
      return(redCorsText);
  } else if ((type.indexOf("H-") >= 0) && (type.indexOf("V-") >= 0)) {
      return(redHvText);
  } else if (type.indexOf("H-") >= 0) {
      return(redHorzText);
  } else if  (type.indexOf("V-") >= 0) {
      return(redVertText);
  }
}
//-------------------------------------
function dms2MapPos(pos) {
  var dir="";
  var deg=""
  var min="";
  var sec="";
  var decDeg="";

  dir = pos.substr(0, 1);

  if ((dir == 'N') || (dir == 'S')) {
      deg = pos.substr(1, 2);
      min = pos.substr(3, 2);
      sec = pos.substr(5, 2);
  } else if ((dir == 'W') || (dir == 'E')) {
      deg = pos.substr(1, 3);
      min = pos.substr(4, 2);
      sec = pos.substr(6, 2);
  } else {
    alert("Cannot convert Lat-Lon to Dec-Deg");
  }

  decDeg = parseFloat(deg) + parseFloat(min)/60.0 + parseFloat(sec)/3600.0;


  if (dir == 'W') {
    decDeg = -1.0 * decDeg;
  }

  return(decDeg);

}
//----------------------------------
function MapPos2dms (map_pos, dir) {
  var ideg = 0;
  var imin=0;
  var isec=0;
  var cdeg = "";
  var cmin = "";
  var csec = "";
  var deg = 0.0;
  var min = 0.0;
  var sec = 0.0;
  var dbPos = "";

   deg = Math.abs(map_pos);
   ideg = Math.floor(deg);
   min = (deg - ideg) * 60.0;
   imin = Math.floor(min);
   sec = (min - imin) *60;
   isec = Math.round(sec);


   if ((dir == "N") || (dir == "S")) {
     if (ideg < 10) {
         cdeg = "0" + ideg;
     } else {
         cdeg = String(ideg);
     }
   } else {
     if (ideg < 10) {
         cdeg = "00" + ideg;
     } else if (ideg < 100) {
         cdeg = "0" + ideg;
     } else {
         cdeg = String(ideg);
     }
   }

   if (imin < 10) {
       cmin = "0" + imin;
   } else {
       cmin = String(imin);
   }

   if (isec < 10) {
       csec = "0" + isec;
   } else {
       csec = String(isec);
   }

   dbPos = dir + cdeg + cmin + csec;


   return (dbPos);

  }
