// JavaScript Document

    // Removes leading and trailing spaces from the passed string. If something besides 
    // a string is passed in (null, custom object, etc.) then return the input.
     function trim(inputString )
	{
      
         if(typeof inputString != "string" )
		 { 
			return inputString; 
		 }
			 
		 var retValue = inputString;
         var ch = retValue.substring(0, 1);

         while(ch == " ") 
	     { 
			// Check for spaces at the beginning of the string
            retValue = retValue.substring(1, retValue.length);
            ch = retValue.substring(0, 1);

         } //End while loop
			 
	     ch = retValue.substring(retValue.length-1, retValue.length);
             
	     while(ch == " ") 
		 { 
			// Check for spaces at the end of the string
            retValue = retValue.substring(0, retValue.length-1);
            ch = retValue.substring(retValue.length-1, retValue.length);

         }//End while loop
         
						
		  //erase space in the middle of string
		  var index = retValue.indexOf("  ");
		  while(index != -1)
		  {  
		      retValue = retValue.substring(0, index) + retValue.substring(index + 1, retValue.length);
			  index = retValue.indexOf("  ");
		  }
		  return retValue; // Return the trimmed string back to the user
            
   } // End trim()


	function validation(input, legalInput )
	{
        var checkOK = legalInput;
        var checkStr = input;
        var allValid = true;

        for(i = 0;  i < checkStr.length;  i++)
        {
              ch = checkStr.charAt( i );
             
               for(j = 0;  j < checkOK.length;  j++)
                     if(ch == checkOK.charAt(j) )
                           break;

                if(j == checkOK.length )
                {
                     allValid = false;
                     break;
                 }

          } //End for loop
                      
	      return allValid;

} // End validataion( )

function check()
{
	var keywordValue = document.searchform.keywords.value;

	var legalString = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	if(!validation(keywordValue, legalString))
	{
		alert("Keywords allows digit or characters only");
        document.searchform.keywords.focus();
		return false;
	}

	return true;

  } //End check()


  function send()
  {
	 if(!check())
	   return false;

	  var keywordValue = trim(document.searchform.keywords.value);
	  if(keywordValue.length <= 2)
	  {
		 alert("Keywords must be at lease two characters");
		 document.searchform.keywords.focus();
		 return false;
	  }
     
	 document.searchform.keywords.value = keywordValue;
	 document.searchform.action = "search.php";
	 document.searchform.submit();
	 
	  return true;

 } //End send()

