function checkMainForm(form) {
	
	var incomplete=0;
	var alertMsg = "The following fields are required:\n";
		
	if(allTrim(form.EMAIL.value) == "") {
		incomplete++;
		alertMsg = alertMsg +"Email Address\n";
	}
	//if(allTrim(form.PHONE.value) == "") {
		//incomplete++;
		//alertMsg = alertMsg +"Telephone\n";
	//}
	
		
	if (incomplete > 0){
		alert(alertMsg);
		return false;
	}

	if (checkEmail(form.EMAIL.value) == false) {
			form.EMAIL.focus();
			return false;
	}

	return checkCounter();
}


function checkEmail(addr) {
//  Will check for @, period after @ and text in between
	
	var in_space = addr.indexOf(" ");
	if (in_space != -1)
	{ alert ("Email address should contain no spaces and be of the form jdoe\@domain.com");
			return false;  }

	var len = addr.length;
	var alpha = addr.indexOf("@");
	var last_alpha = addr.lastIndexOf("@");

	if (alpha != last_alpha)
	 {  alert ("Bad email address. Should contain only one @ and be of the form jdoe\@domain.com");
			 return false; }

	// No @, in first position, or name too short
	if (alpha == -1 || alpha == 0 || len<6 )
	 {  alert ("Bad email address. Should contain an @ and be of the form jdoe\@domain.com");
			 return false; }

	var last_p = addr.lastIndexOf(".");
			// Be sure period at least two spaces after @, but not last char.
			
	if (last_p - alpha < 2 || last_p == (len - 1) )
		{  alert ("Bad email address. Should contain a period after the @ and be of the form jdoe\@domain.com");
				return false; }
}

function allTrim(cValue){
  var lDone=false;
  while (lDone==false){
    if (cValue.length==0) {return cValue;}
    if (cValue.indexOf(' ')==0){cValue=cValue.substring(1);lDone=false; continue;}
    else {lDone=true;}
    if (cValue.lastIndexOf(' ')==cValue.length-1){cValue=cValue.substring(0, cValue.length-1);lDone=false;continue;}
    else {lDone=true;}
  }
  return cValue;
}

var iSubmitCounter=0;

function checkCounter(){
	iSubmitCounter++;
	if (iSubmitCounter==1) {
		return true;
	} else {
		alert('Please Wait.'); 
		return false;
	}
}
