/*
function name: echeck
purpose: check for valid email address format
author:  (http://www.smartwebby.com/dhtml/)
date: borrowed on 08/02/07, modified somewhat
parameters: string containing email to check
 */
function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	// empty string
	if ((str==null)||(str=="")){
		alert("Please enter an email address.");
		return false;
	}
	// '@' at the beginning or the end or missing
	if (lat==-1 || lat==0 || lat==lstr-1){
		alert("'@' missing or in the wrong place. Please enter a valid email address.");
		return false;
	}
	// '.' at the beginning or the end or missing
	if (ldot==-1 || ldot==0 || ldot==lstr-1){
		alert("'.' missing or in the wrong place. Please enter a valid email address.");
		return false;
	}
	// more than one '@'
	if (str.indexOf(at,(lat+1))!=-1){
		alert("Only one '@' allowed. Please enter a valid email address.");
		return false;
	}
	// nothing between '@' and '.'
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	 	alert("Need at least one character between '@' and '.'. Please enter a valid email address.");
	 	return false;
	}
	//must have at least one '.' after the '@'
	if (str.indexOf(dot,(lat+2))==-1){
		alert("There is no '.' after the '@'. Please enter a valid email address.");
		return false;
	}
	// no spaces allowed	
	if (str.indexOf(" ")!=-1){
		alert("No spaces allowed.  Please enter a valid email address.");
		return false;
	}
 		 return true;					
} /* end of function echeck */


/*
function name: chkRefer
purpose: check the fields in the refer-a-friend form
author: Heather Ross
date: 08/02/07
parameters: none
*/
function chkRefer() {
	var Sender=document.frmRefer.txtSender;
	var Recipient=document.frmRefer.txtRecipient;

	if (echeck(Sender.value)==false){
		Sender.value="";
		Sender.focus();
		return false;
	}
	if (echeck(Recipient.value)==false){
		Recipient.value="";
		Recipient.focus();
		return false;
	}
	return true;
}
