function OnSubmitForm() {

    DEBUG = false;

/* Define and set flags for relevant form parameters */

    // start with all 'false'
    SEQinput = false;
    upfileInput = false;
    AccNoInput = false;
    beginInput = false;
    endInput = false;
    surroundInput = false;

    // set flags to 'true' when corresponding form elements have content
    SEQvalue = document.submit_form.SEQ.value;
    if ( SEQvalue.match(/\w+/) ) {
        if (DEBUG) { alert( "SEQvalue exists: " + SEQvalue ); }
        SEQinput = true;
    }
    upfileValue = document.submit_form.upfile1.value;
    if ( upfileValue.match(/\w+/) ) {
        if (DEBUG) { alert( "upfileValue exists: " + upfileValue ); }
        upfileInput = true;
    }
    AccNoValue = document.submit_form.AccNo.value;
    if ( AccNoValue.match(/\w+/) ) {
        if (DEBUG) { alert( "AccNoValue exists: " + AccNoValue ); }
        AccNoInput = true;
    }
    beginValue = document.submit_form.begin.value;
    if ( beginValue.match(/\w+/) ) {
        if (DEBUG) { alert( "beginValue exists: " + beginValue ); }
        beginInput = true;
    }
    endValue = document.submit_form.end.value;
    if ( endValue.match(/\w+/) ) {
        if (DEBUG) { alert( "endValue exists: " + endValue ); }
        endInput = true;
    }
    if ( document.submit_form.surround.checked == true ) {
        if (DEBUG) { alert( "the surround box is checked" ); }
        surroundInput = true;
    }

    // set a single flag for any 'location' form elements filled
    locateInput = false;
    if ( SEQinput || upfileInput || AccNoInput ) {
        locateInput = true;
    }

    // set a single flag for any 'retrieve' form elements filled
    retrieveInput = false;
    if ( beginInput || endInput || surroundInput ) {
        retrieveInput = true;
    }

       /* Set form action according to form contents - or raise error on bad input */

    if ( locateInput && !retrieveInput ) {

        // at least one 'locate' form element has been filled
        // no 'retrieve' form elements have been filled
        if (DEBUG) { alert( "Leaving form action unchanged." ); }
        // allow normal submission to locate.cgi

    }
    else
    if ( !locateInput && beginInput && surroundInput ) {

        // no 'locate' information has been entered,
        // a 'begin' coordinate has been entered (possibly also an end coordinate),
        // and the 'include surrounding region' box has been checked
        if (DEBUG) { alert( "Changing form action to rt.cgi..." ); }
        // redirect submission to rt.cgi
        // (HCV will use rt instead of rttr for this)
        document.submit_form.action =
        "/cgi-bin/LOCATE/NEWLOCATE/rt.cgi";

    }
    // these two options (^ and \/) could now be combined...
    else
    if ( !locateInput && beginInput && endInput && !surroundInput ) {

        // 'begin' and 'end' coordinates have been entered
        // nothing else has been filled or checked
        if (DEBUG) { alert( "Changing form action to rt.cgi..." ); }
        // redirect submission to rt.cgi
        document.submit_form.action =
        "/cgi-bin/LOCATE/NEWLOCATE/rt.cgi";

    }
    else
    if ( beginInput && !locateInput && !endInput && !surroundInput ) {

        // only a 'begin' number has been provided - cannot process, so warn...
        alert( "You have given only a 'from' value; you must either provide a matching 'to' value or check the 'include surrounding region' option." );
        // ...and cancel the submission
        return false;

    }
    else
    if ( endInput && !locateInput && !beginInput ) {

        // an 'end' number has been provided, but no 'begin' - cannot process, so warn...
        alert( "You have entered a number in the 'to' box, but nothing in the 'from' box." );
        // ...and cancel the submission
        return false;

    }
    else
    if ( !locateInput && !retrieveInput ) {

        // no data were entered on the form at all, so warn...
        alert( "You have entered nothing in the form." );
        // ...and cancel the submission
        return false;

    }
    else
    if ( locateInput && retrieveInput ) {

        // input has been entered in both parts of the form, so warn...
        alert( "Please enter either sequence location information OR retrieval information; not both." );
        // ...and cancel the submission
        return false;

    }
    else {

        // some incorrect combination of fields has been filled out, so warn...
        if (DEBUG) { alert( "You have done something I didn't think of!" ); }
        alert( "The input is inconsistent." );
        // ...and cancel the submission
        return false;

    }

       /* Check form contents for validity - numbers for coordinates, etc. */

    // check that coordinates given are numbers
    if ( beginValue.match(/\D/) || ( endValue.match(/\D/) && !endValue.match(/^end$/) ) ) {
        // one coordinate or the other was not a number (or 'end' for the second coord), so warn...
        if (DEBUG) { alert( "Sneaky form-filler-outer!" ); }
        alert( "Coordinates must be numbers." );
        // ...and cancel the submission
        return false;
    }

       /* If all form checks have been passed,
          return 'true' so that the form action can take place;
          which is to submit page to appropriate cgi script. */

    return true;

}
