function isEmpty(s) // Returns true if empty or null
{
	return ((s == null) || (s.length == 0))
}

function isLetter (c) // Returns true if character c is an English letter (A .. Z, a..z).
{
	state=(((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
	return ( state )
}

function isDigit (c)// Returns true if character c is a digit (0 .. 9).
{
	state=((c >= "0") && (c <= "9"))
	return (state)
}

function isAlphanumeric(c) {
	stateA=(isLetter(c))
	stateB=(isDigit(c))
	stateC=stateA || stateB
	return(stateC)
}


function removeXSWhitespace(item) {
  var t1=item.value;
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index=0; index<item_length; index++) {
    if (item.value.charAt(index) != ' ') {
      tmp += item.value.charAt(index);
    } else {
      if (tmp.length > 0) {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1) {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  item.value = tmp;
  t2=item.value
}

function search_validator(theForm)
{
	var errString="Your search query could not be processed:\n\n ";
	var baseLength=errString.length;
	var allNum = "";

	var searchString=theForm.keywords.value;

	if (searchString == "") {
		errString=errString+"No search term was entered.\n";
	} else {
		// check for space only
		if (searchString == " ") {
			errString=errString+"Search terms need to be more than a space.\n";
		} else {
			if (searchString.length==1) {
				if (!isLetter(searchString)) {
					errString=errString+"Search queries need to be more than non-alphanumeric or single numeric characters.\n";
				}
			} else {
				testChar1=searchString.charAt(0);
				testChar2=searchString.charAt((searchString.length)-1);

				if  (! (testChar1=='"' &&  testChar2=='"')) {
					
					if ( (!isAlphanumeric(testChar1)) || (!isAlphanumeric(testChar2)) ) {
						errString=errString+"Search terms should not contain non-alphanumeric characters in the first or last position.\n";
					}
				} else {
					if (!(searchString.length>2)) {
						errString=errString+"Search terms should have literal keywords between quotes.\n";
					} else {
						quotecount=0;
						for (i=0; i<searchString.length; i++) {
							if (searchString.charAt(i)=='"' ) {
								quotecount++;
							}
						}
						if (quotecount>2) {
							errString=errString+"Literal keyword searchs should not contain qoutes.\n";
						}
					}
				}
			}
			if ( (searchString.toUpperCase()=="AND") || (searchString.toUpperCase()=="OR") || (searchString.toUpperCase()=="NOT") || (searchString.toUpperCase()=="AT") ) {
				errString=errString+"This word is not a valid query on its own.\n";
			}
		}
	}
	// PROCEED OR NOT ?
	if (errString.length>baseLength) {
		alert(errString);
		theForm.keywords.focus()
		return (false);
	} else {
		return (true);
	}
}