//************************************************************************************
function char_j_REMOVE_POSSIBLE_TAGS(input_string) {
/* This function replaces the characters "<" and ">"
   with an underscore in an attempt to eliminate
   malicious external scripts. NSSdr03155 R. W. Dougherty
   There is a copy of this function in char_j_trans.js */

 var output_string = "";
 var testchar = "";
 var testbyte = 0;

  if ( (input_string == null) || (input_string == "") )
     return input_string;

/*  Removed in favor of list of good characters below.

  for ( var i = 0; i < input_string.length; i++ ) {
     testbyte = input_string.charCodeAt(i);
     testchar = input_string.charAt(i);
     if ( ( testbyte != 60 ) && ( testbyte != 62 ) ) {
        output_string = output_string + testchar;
        } else {
        output_string = output_string + "_";
        }
     }
*/

  output_string = input_string.replace( /[^a-zA-Z0-9\_\,\:\)\(\+\-\.\!\@\ ]/g, "_" );
  return output_string;

 }


//*******************************************************************



function show_query()
    {
      qw = window.open("", "QWIN", "width=900,resizable=yes,toolbar=no,location=no,scrollbars=yes,menubar=yes,status=yes");
    }



  function val_modu_fields() {
  // Function to validate required fields for uploaded MODU.
  // All of the fields listed below must be filled out in order for the form to be submitted to NGA.

   var explanation = "";
   var poc = false;
   var company = false;
   var phone = false;
   var drill_name = false;

   if ((self.document.MODU_UPLD.Observer_Name.value != null) && (self.document.MODU_UPLD.Observer_Name.value != "") )
      poc = true;
   else
      explanation = "\nPoint of Contact is a required field.";

   if ((self.document.MODU_UPLD.Company.value != null) && (self.document.MODU_UPLD.Company.value != "") )
      company = true;
   else
      explanation += "\nCompany is a required field.";

   if ((self.document.MODU_UPLD.Phone_Number.value != null) && (self.document.MODU_UPLD.Phone_Number.value != "") )
      phone = true;
   else
      explanation += "\nPhone number is a required field.";

    if ((self.document.MODU_UPLD.Drill_Name.value != null) && (self.document.MODU_UPLD.Drill_Name.value != "") )
       drill_name = true;
   else
      explanation += "\nDrill Unit Name is a required field.";

   if (poc && company && phone && drill_name) {

     //C.Andrews 10-25-99 The following statement is used to prevent bogus data from passing to
     //the results page without passing through the javaScript validation.
     self.document.MODU_UPLD.jsbrwcmp.value = "1js_4comp$!";

     show_query();
     self.document.MODU_UPLD.submit();
     }
   else
      alert(explanation);

  } //end function val_modu_fields()


function validate_modu(obj)
{
  // validate the name query parameter
  if (obj.name_search_opt[0].checked) // all_names
  {
    if ((obj.area_search_opt[0].checked)  && 
        (obj.status_search_opt[0].checked))  // all_areas and all_status
    {
      alert('One of "Name Search" or "Area of Interest Search"\n' +
            'or "Status Search" options must not be set to "All".\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.name_search_opt[1].checked) // one_name
  {
    if (obj.specific_modu.value == "")
    {
      alert('A non-null MODU name must be entered.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else
  {
    alert("A Name Search Option is required.\n" +
          "Please make a selection and try again.");
    return false;
  }

  // validate the area query parameter
  if (obj.area_search_opt[0].checked) // all_areas
  {
    if ((obj.name_search_opt[0].checked)  && 
        (obj.status_search_opt[0].checked))  // all_names and all_status
    {
      alert('One of "Name Search" or "Area of Interest Search"\n' +
            'or "Status Search" options must not be set to "All".\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.area_search_opt[1].checked) // navarea
  {
    if (obj.navarea_lst.selectedIndex == 0)
    {
      alert('A NAVAREA must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.area_search_opt[2].checked) // region
  {
    if (obj.region.selectedIndex == 0)
    {
      alert('Region must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.area_search_opt[3].checked) // subregion
  {
    if (obj.subregion.selectedIndex == 0)
    {
      alert('Subregion must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.area_search_opt[4].checked) // mbr
  {

//C.Andrews 10-25-99 The following statement is used to prevent bogus data from passing to the results page
//without passing through the javaScript validation.
   obj.jsbrwcmp.value = "1js_4comp$!";
    return validate_mbr(obj.ur_lat_deg,
                        obj.ur_lat_min,
                        obj.ur_lat_dir,
                        obj.ur_lon_deg,
                        obj.ur_lon_min,
                        obj.ur_lon_dir,
                        obj.ll_lat_deg,
                        obj.ll_lat_min,
                        obj.ll_lat_dir,
                        obj.ll_lon_deg,
                        obj.ll_lon_min,
                        obj.ll_lon_dir);
  }
  else
  {
    alert("An Area of Interest Search Option is required.\n" +
          "Please make a selection and try again.");
    return false;
  }

  // validate the status query parameter
  if (obj.area_search_opt[0].checked) // all_status
  {
    if ((obj.name_search_opt[0].checked)  && 
        (obj.status_search_opt[0].checked))  // all_names and all_area
    {
      alert('One of "Name Search" or "Area of Interest Search"\n' +
            'or "Status Search" options must not be set to "All".\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.status_search_opt[1].checked) // all_status
  {
    if (obj.rig_status.selectedIndex == 0)
    {
      alert('MODU Status must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }

  // validate the date query parameter
  if (obj.date_search_opt[1].checked) // single_date
  {
    if (obj.date_mm.selectedIndex == 0)
    {
      alert('Month must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
    if (obj.date_dd.selectedIndex == 0)
    {
      alert('Day must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
    if (obj.date_yyyy.selectedIndex == 0)
    {
      alert('Year must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.date_search_opt[2].checked) // single_year
  {
    if (obj.single_year.selectedIndex == 0)
    {
      alert('Year must be selected.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }
  else if (obj.date_search_opt[3].checked) // date_range
  {
    if ((obj.fr_date_mm.selectedIndex == 0) ||
        (obj.fr_date_dd.selectedIndex == 0) ||
        (obj.fr_date_yyyy.selectedIndex == 0) ||
        (obj.to_date_mm.selectedIndex == 0) ||
        (obj.to_date_dd.selectedIndex == 0) ||
        (obj.to_date_yyyy.selectedIndex == 0))
    {
      alert('Values for all date fields must be provided.\n' +
            'Please modify your selections and try again.');
      return false;
    }
    if (obj.fr_date_yyyy.options[obj.fr_date_yyyy.selectedIndex].text +
        obj.fr_date_mm.options[obj.fr_date_mm.selectedIndex].text +
        obj.fr_date_dd.options[obj.fr_date_dd.selectedIndex].text >
        obj.to_date_yyyy.options[obj.to_date_yyyy.selectedIndex].text +
        obj.to_date_mm.options[obj.to_date_mm.selectedIndex].text +
        obj.to_date_dd.options[obj.to_date_dd.selectedIndex].text)
    {
      alert('Invalid date range specified.\n' +
            'Please modify your selections and try again.');
      return false;
    }
  }

//C.Andrews 10-25-99 The following statement is used to prevent bogus data from passing to the results page
//without passing through the javaScript validation.
   obj.jsbrwcmp.value = "1js_4comp$!";

  window.open("", "modu_res", 
              "resizable=yes,toolbar=no,location=no," +
              "scrollbars=yes,menubar=yes,status=yes");
  return true;
}
