var errorcheck=0;
function submitIt(UserLogin)
{
  var uid = UserLogin.userid.value; 
  var pw = UserLogin.password.value;
  uid = trimspaces(UserLogin.userid.value);
  UserLogin.userid.value = uid;
  pw = trimspaces(UserLogin.password.value);
  UserLogin.password.value = pw;

  if(!validEmail(uid))
	{
	  if(!checkForCharsUid(uid))
		{
		  if (errorCheck == 1) {
			  alert("Please enter your User ID.");		
		  } else { 
		  	alert("Please do not enter special characters or spaces in your User ID.");
		  }
		  UserLogin.userid.focus();
		  UserLogin.userid.select();
		  return false;
		}	  
	}
  if(!checkfor6(uid))
	{
	  alert("User ID must be at least 6 letters and/or numbers, without spaces or special characters.");
	  UserLogin.userid.focus();
	  UserLogin.userid.select();
	  return false;
	}
  if(!checkForChars(pw))
	{
	  if (errorCheck == 1) {
	  	alert("Please enter your Password.");
	  } else {
	  	alert("Please use letters, numbers and no spaces or special characters in the password.");
	  }
	  UserLogin.password.focus();
	  UserLogin.password.select();
	  return false;
	}
  if(!checkfor6(pw))
	{
	  UserLogin.password.focus();
	  UserLogin.password.select();
	  alert("Password must be at least 6 letters and numbers.  Please do not enter special characters or spaces in your User ID.");
	  return false;
	}
  return true;
}

function checkForChars(txtFld)
{
  var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  var ok = "yes";
  var temp;
  if (txtFld.length == 0)
	{
	  errorCheck = 1;
	  return false;
	}
  for (var i=0; i<txtFld.length; i++)
	{
	  temp = "" + txtFld.substring(i, i+1);
	  if (valid.indexOf(temp) == "-1") {
		  ok = "no";
	  }
	}
  if (ok == "no")
	{
	  errorCheck = 2;
	  return false;
	}
  return true;
}

function checkForCharsUid(txtFld)
{
  var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-_@";
  var ok = "yes";
  var temp;
  if (txtFld.length == 0)
	{
	  errorCheck = 1;
	  return false;
	}
  for (var i=0; i<txtFld.length; i++)
	{
	  temp = "" + txtFld.substring(i, i+1);
	  if (valid.indexOf(temp) == "-1") {
		  ok = "no";
	  }
	}
  if (ok == "no")
	{
	  errorCheck = 2;
	  return false;
	}
  return true;
}

function checkfor6(parm1)
{
  if (parm1.length < 6)
	{
	  return false;
	}
  else {
	  return true;
  }
}


function trimspaces(field)
{
  var x;
  var precount = 0;
  var postcount = 0;
  var retfield = "";
  for (x=0;x<field.length;x++)
	{
	  if (field.charAt(x) == " " ) {
	  	precount++;
	  }
	  else {
	  	break;
	  }
	}
  for ( x=field.length; x>0; x-- )
	{
	  if (field.charAt(x-1) == " " ) {
		  postcount++;
	  }
	  else {
	  	break;
	  }
	}
  if (field.length == precount) {
  	retfield = "";
  }
  else {
  	retfield = field.substring(precount,(field.length-postcount));
  }
  return retfield;
}


function validEmail(email) {

	invalidChars = " /:,;";
	for (i=0; i< invalidChars.length; i++) {
		 badChar = invalidChars.charAt(i);
		 if (email.indexOf(badChar,0) > -1) {
			return false; 
		 }
	}
	atPos = email.indexOf("@",1); 
	if (atPos == -1) {
	   return false; 
	}
	if (email.indexOf("@",atPos+1) > -1) {
	   return false; 
	}
	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1) {
	   return false;
	}
	if (periodPos+3 > email.length) {
	   return false; 
	}
	return true;
}

