

//------------------------------ submit the form after a SELECT change

function submit_gform( action ) {

  mf = this.document.gform;

  //---------- Field validation

  msg = "";
  if ( !valid(mf.product) ) msg += "Please select a Product\n";

  if ( action == "Version" ) {
     if ( !valid(mf.version) )  msg += "Please select a Version\n";
  }

  if ( action == "Document" ) {
     if ( !valid(mf.version) )  msg += "Please select a Version\n";
     if ( !valid(mf.document) ) msg += "Please select a Document\n";
  }

  //---------- Display a popup if errors were found

  if ( msg !== "") { 
    alert( "<<< Warning >>>\n\n" + msg );
    return false;
  }

  //---------- Really submit the form

  mf["do"].value = action;   // set action to do here
  mf.target = "_self";
  mf.submit();            // and submit the form

  return true;

}

//------------------------------ Check empty fields

function valid( obj ) {

  if ( obj == null ) return false;
  if ( typeof(obj) == "undefined" ) return false;
  if ( obj.value == null ) return false;
  if ( obj.value == "" ) return false;
  if ( obj.value == "..." ) return false;
  if ( obj.value == "none" ) return false;
  if ( obj.value == "select..." ) return false;

  return true;
}

//------------------------------ check a Numeric fields value

function check_num( field ) {

    var data = field.value + "";

    if ( isNaN(data) ) {
        alert ("Not a valid numeric value: " + data);
        field.value = "";   // clear field value
        field.focus();
        return false;
    } else {
        return true;    }
}

//------------------------------ check an email address

function check_email( field ) {

    var data = field.value + "";

    return (data.indexOf(".") > 2) && (data.indexOf("@") > 0);
 
}

//------------------------------ end of JavaScript


