// Copyright 13 August 2000, Cavalry Outpost Publications.

// This multifunction program:
//      1.0 Reads the search terms contained in the submitted data string
//      of the Reconnaissance and Surveillance DBSearch Form and validates
//      the integrity of characters in the data string, screens them for
//      the absence of invalid characters and increments to counter value.

//      2.0 Upon the detection of a string error, an alert is displayed,
//      with a message of proposed corrective action.

// *********************************************************************
// **********     Program Name = DBSearch.js Rev 05.05.04     **********
// *********************************************************************

// 1.0 Check Search Term Field for [no data] and [invalid characters],
// A. Display Alert Message if Validity Criteria Test fails

function validateSearch_Terms() {
        if (isProper(document.DBSearch.Terms.value) == false) {
                alert ('  ERROR IN SEARCH TERM\n'
                     + '\n'
                     + '  The data field is either blank\n'
                     + '\t   or\n'
                     + '  one of the invalid characters\n'
                     + '~`!@#$%^&()={}[]|\\:;\'<>?\n'
                     + '  is used in the search term\(s\).');
                document.DBSearch.Terms.focus();
                return false;
        }
        return true;
}

// Check for valid string
// B. Check for string integrity and absence of invalid characters

function isProper(string) {
        if (!string) return false;
        var iChars = "~`!@#$%^&()={}[]|\\:;\'<>?";
        for (var i = 0; i < string.length; i++) {
        if (iChars.indexOf(string.charAt(i)) != -1)
                return false;
        }
        return true;
}
