var alertmsg = "";


//
// called from onSubmit email signup form
//
function checkAllFields(formobj) {
	if (checkRequiredFields(formobj)) {
		if (isEmailValid(formobj.scr_email)) {
			return true
		}
		else {
			alert("The email address is not valid.  It must contain the characters '@' and '.'.");
			return false;
		}
		
	}
	else {
		alert(alertmsg)
		return false
	}	
}

//	
//	returns a TRUE if all required fields are filled in.
//
function checkRequiredFields(formobj) {
	alertmsg = "";
	var tempmsg = "";
	
	if(isEmpty(formobj.scr_email)) {
		tempmsg = "\nEmail Address"
	}
		
		
	if (tempmsg == "") {
		return true
	}
	else {
		alertmsg = "The following required field(s) are blank:" +tempmsg 
		return false
	}
}


//
// Returns a TRUE if field is empty
//
function isEmpty(textObj){
	var status = true;
	if (textObj.value.length == 0)
		status = true;
	else {
		for (var i=0; i<textObj.value.length; ++i){
	    	var ch = textObj.value.charAt(i);
	    	if (ch != ' ' && ch != '\t'){
	 			status = false;
	        }
		}
	}
	return (status)
}


//
// Validate email address
// Ensures there is an '@' sign and a '.' that follows the '@' character.
//
function isEmailValid(textObj) {
	if (isEmpty(textObj)) {
		return true;
	}
	var status = true;
	var at = textObj.value.indexOf('@', 0);
	if (at == -1 || at == 0) {
		status = false;
	}
	else {
		if (textObj.value.indexOf('.', at) == -1){
			status = false;
		}
	}
		
	return (status);
	
}

