function stringFilter (tString, filter) {
 var s = tString;
 var filteredValues = filter;     // Characters stripped out
 var i;
 var returnString = "";
 for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
  var c = s.charAt(i);
  if (filteredValues.indexOf(c) == -1) returnString += c;
 }
 
 return returnString;
}
function stringFilterLength (tString, filter) {
 var s = tString;
 var filteredValues = filter;     // Characters stripped out
 var i;
 var returnString = "";
 for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
  var c = s.charAt(i);
  if (filteredValues.indexOf(c) == -1) returnString += c;
 }
 
 return returnString.length;
}
//left trim function
function LTrim(str)
{
   var whitespace = new String(" \t\n\r@~");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}
//right trim function
function RTrim(str)
{
   var whitespace = new String(" \t\n\r@~");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}
//combo left/right trim function
function Trim(str)
{
   return RTrim(LTrim(str));
}
//handle form data
function validateForm(path) 
{
 buffer  = stringFilter(Trim(document.forms[0].elements['uName'].value),"!@#$%^&*(){}[]|\:;<>?/~`'=-+'");
 buffer2 = stringFilter(Trim(document.forms[0].elements['pWord'].value),"!@#$%^&*(){}[]|\:;<>?/~`'=-+'");
 
 if(Trim(document.forms[0].elements['email'].value)=="")
	{
  alert("Please fill in the \"E-mail Address\" field.");
	 event.returnValue=false;
	 return false;
	}
	else if(stringFilter(Trim(document.forms[0].elements['email'].value),"@")==Trim(document.forms[0].elements['email'].value)||stringFilterLength(Trim(document.forms[0].elements['email'].value),"@")!=document.forms[0].elements['email'].value.length-1||stringFilter(Trim(document.forms[0].elements['email'].value),".")==Trim(document.forms[0].elements['email'].value))
	{
  alert("Please enter a valid e-mail address in the \"E-mail Address\" field.");
	 event.returnValue=false;
	 return false;
	} 
 else if(Trim(document.forms[0].elements['uName'].value)=="")
	{
  alert("Please fill in the \"Username\" field.");
	 event.returnValue=false;
	 return false;
	}
	else if(stringFilter(Trim(document.forms[0].elements['uName'].value),"!@#$%^&*(){}[]|\:;<>?/~`'=-+'")!=Trim(document.forms[0].elements['uName'].value))
	{
  alert("Special characters are not allowed in the \"Username\" field.");
	 event.returnValue=false;
	 return false;
	}
	else if(buffer.length<4)
	{
  alert("Your username must be longer than 4 characters.");
	 event.returnValue=false;
	 return false;
	}
 else if(Trim(document.forms[0].elements['pWord'].value)=="")
	{
  alert("Please fill in the \"Password\" field.");
	 event.returnValue=false;
	 return false;
	}
	else if(stringFilter(Trim(document.forms[0].elements['pWord'].value),"!@#$%^&*(){}[]|\:;<>?/~`'=-+'")!=Trim(document.forms[0].elements['pWord'].value))
	{
  alert("Special characters are not allowed in the \"Password\" field.");
	 event.returnValue=false;
	 return false;
	}
	else if(buffer.length<4)
	{
  alert("Your password must be at least 5 characters long.");
	 event.returnValue=false;
	 return false;
	} 
	else if(document.forms[0].elements['pWord2'].value!=Trim(document.forms[0].elements['pWord'].value))
	{
  alert("The \"Password\" and \"Confirm Password\" fields do not match.");
	 event.returnValue=false;
	 return false;
	}

 //form data is allowed to pass through if it has reached this point
 return true;  
} 
