function ValidateEmail( email, invalidMessage )
{
	var index = email.indexOf( "@" ) ;
	if( index <= 0 )
	{
		alert( invalidMessage );
		return false ;
	}
	if( index != email.lastIndexOf( "@" ) )
	{
		alert( invalidMessage );
		return false ;
	}
	if( email.indexOf( "." ) == -1 )
	{
		alert( invalidMessage );
		return false ;
	}
	return true ;
}
function checkValidChars(in_str, message)
{
    lis = in_str.toLowerCase();
    validChars=" abcdefghijklmnopqrstuvwxyz0123456789";
	for(i=0; i< lis.length; i++) {
		myChar=lis.substring(i,i+1);
		if (validChars.indexOf(myChar)< 0) {
			alert (message);
			return false;
		}
	}
    return true;
}
function removeBlanks(in_str)
{
    // Remove all the leading white space characters
    // from the string in_str
    var re=/(\w+)/;
    var charIndex = in_str.search(re);
    if(charIndex != -1) {
        in_str = in_str.substr(charIndex);
    }
    else {
        in_str = '';
    }
        return in_str ;
}

function checkTextValue( in_str, message )
{
    var val = removeBlanks(in_str) ;
    if( val == "" )
        {
                alert( message ) ;
                return false ;
        }
        return true ;
}

function checkForm() {
  theForm = document.sendmail;
  val = theForm.name.value;
  if (!checkTextValue(val, "Please enter your Name")) {
        theForm.name.focus();
	theForm.name.select();
        return false;
  }
    else if (!checkValidChars (val,"Name can only have letters & numbers")){
        theForm.name.focus();
	theForm.name.select();
        return false;
  }  
  val = theForm.email.value;
  if (val == null || val == "" || val.length < 6) {
        alert("Please enter valid email address");
        theForm.email.focus();
	theForm.email.select();
        return false;
  }
  else if (!ValidateEmail(val, "Invalid Email Address")) {
  	theForm.email.focus();
	theForm.email.select();
	return false;
  }
  val = theForm.sub.value;
  if (!checkTextValue(val, "Please enter a subject for your email")) {
        theForm.sub.focus();
	theForm.sub.select();
        return false;
  }  
  val = theForm.Comments.value;
  if (!checkTextValue(val, "Please type a message")) {
        theForm.Comments.focus();
	theForm.Comments.select();
        return false;
  }
  return true;
}
