// Create a method for trimming
String.prototype.normalize = function()
{ return this.replace( /^\s+/g , '' ).replace( /\s+$/g , '' ).replace( /\s+/g , " " ) ; }

var msg, orgEmail, orgFname, orgLname

function testContent(emailAddr) {
	alert(emailAddr);
}

function validEmail(emailAddr) {
  //alert(emailAddr);
	
  //alert("emailAddr is " + emailAddr + "|")
  invalidChars = "/:,;'=!$%^  "
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i)
	if (emailAddr.indexOf(badChar,0)> -1) {
	  theChar = badChar
	  if (badChar == " " || " ") { theChar = "space" }
	  msg = "» The (" + theChar + ") character is not allowed"
	  return false;
	}
  }   
  
  if (emailAddr == "") {
	msg = "» Oops, please enter an address"
	return false;
  }
  
  if (emailAddr.length < 4) { 
	msg = "» Oops, that address is too short"
	return false;
  }  
  
  atPos = emailAddr.indexOf("@")
  if (atPos < 0) {
	  msg = "» You forgot to add an @ symbol"
	  return false;
  }
  
  if(emailAddr.indexOf("@",atPos+1) != -1) {
	  msg = "» You added more than one @ symbol"
	  return false;
  }
  
  periodPos = emailAddr.indexOf(".",atPos)
  //alert("atPos = " + atPos + "; period is at: " + periodPos)
  if (periodPos == -1) {
	  msg = "» Missing '.' between '@' & end of email"
	  return false;
  }
  
  if(periodPos-atPos == 1) {
	  msg = "» Period can\'t follow the @ immediately"
	  return false;
  }
  
  if (periodPos+3 > emailAddr.length) {
	  msg = "» Should be 2 characters after the (.)"
	  return false;
  }   
  
  return true;
}

function validName(aName) {
  //alert("aName is " + aName)
  invalidChars = ">!@#$%^*()_=/:,;\\\""
  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i)
	if (aName.indexOf(badChar,0)> -1) {
	  msg = "» This character (" + badChar + ") is not allowed"
	  return false;
	}
  }   
   
  if (aName.length < 1) { 
	msg = "» Please add at least an initial, thx"
	return false;
  }
   
  return true;
} 

function checkEntry(fm){
	//check email
	if (document.getElementById('XX_email').value.indexOf(">>")==0) {
		document.getElementById('XX_email').value = '';
		return false;
	} else {
		orgEmail = document.getElementById('XX_email').value.normalize();
		if (!validEmail(orgEmail)) {
			document.getElementById('XX_email').value = msg
			return false;
		} else {
			document.getElementById('XX_email').value = orgEmail
			return true;
		}
	}
}

function checkField(fm){
	//check email
	if (document.getElementById('XX_email').value.indexOf(">>")==0) {
		document.getElementById('XX_email').value = '';
		return false;
	}
}

function checkEform() {
	if (checkEntry(document.formmail)) {
		//document.formmail.action = "http:\/\/www.webhost4life.com\/cgi-bin\/ultra\/ultra-mail.pl"
		//document.formmail.submit();
	}
}