// JavaScript Document
//character fields cannot take space.
function isValidText(str) //space is not a valid character
{
  var parsed = false;
  var validchars = "abcdefghijklmnopqrstuvwxyz";
  for (var i=0; i < str.length; i++) 
  {
    var letter = str.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
    {
	  parsed = true;
      break;
	}
  }
  return parsed;
}
//email should have all valid characters.
function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) 
  {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
//check the validity of the email address.
function checkemail(email)
{
	if (email.indexOf("@") < 1) //  must contain @ and it should not be the first character.
	{
		alert("please enter a valid email address");
		return false;
	}
	else if (email.lastIndexOf(".") <= email.indexOf("@"))// dot must come after @
	{
		alert("please enter a valid email address");
		return false;
	}
	else if (email.indexOf(".") == (email.length-1)) // dot must not be the last character
	{  
		alert("please enter a valid email address");
		return false;
    }
	
    return true;
}
