function validatesearch(type) {
/***************************************************************************/
/* Special Req's :- None                                                   */
/* Related Files :- None                                                   */
/* Purpose       :- Check data has been entered correctly                  */
/* Version       :- 1.00                                                   */
/* Author        :- Trevor McDermott                                       */
/* Date          :- 11/05/2003                                             */
/***************************************************************************/
/* Desc of Mod   :-                                                        */
/* Modified By   :-                                                        */
/* Date          :-                                                        */
/***************************************************************************/

var strthisformis

if (type == 'emptyorfull') {
  strthisformis = "frmimagesearch"
}

document.forms[strthisformis].txtsearchterm.value = trim(document.forms[strthisformis].txtsearchterm.value)

if (document.forms[strthisformis].txtsearchterm.value.length < 3) { 
 alert('Please enter at least three characters in your search');
 document.forms[strthisformis].txtsearchterm.focus();
 return;
}

if (document.forms[strthisformis].txtsearchterm.value.indexOf("'") > 0) { 
 alert('Please do not enter apostrophes in your search');
 document.forms[strthisformis].txtsearchterm.focus();
 return;
}

if (document.forms[strthisformis].txtsearchterm.value.indexOf("\"") > 0) { 
 alert('Please do not enter speech marks in your search');
 document.forms[strthisformis].txtsearchterm.focus();
 return;
}

if (! isvalidsearchstring(document.forms[strthisformis].txtsearchterm.value)) { 
 alert('Please only use letters numbers spaces and hyphens in your search');
 document.forms[strthisformis].txtsearchterm.focus();
 return;
}

/* form is validated ok */
/* document.forms[strthisformis].submit()  */
document.location="imageresults.asp?txtsearchterm=" + document.forms[strthisformis].txtsearchterm.value
return;
}

/***************************************************************************/	
/* end of validatesearch.js                                                */
/***************************************************************************/

// isvalidsearchstring (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isvalidsearchstring (s) {   

	 var i;

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

/*		  alert(c)
		  alert( !(isLetter(c) || isDigit(c) || isSpace(c) || isHyphen(c) )) */
		  
        if (! (isLetter(c) || isDigit(c) || isSpace(c) || isHyphen(c) ))
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

// Returns true if character c is a letter or digit.


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isSpace (c)
{   return ((c == " "))
}

function isHyphen (c)
{   return ((c == "-"))
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
