function checkMainForm(form) {
	var incomplete=0;
	var alertMsg = "The following fields are required:\n";
	var friendsemail;
	var strZipCode = form.zip.value;

	if(allTrim(form.zip.value) == "") {
			incomplete++;
			alertMsg = alertMsg +"ZIP Code\n";
	}
	if (incomplete > 0){
		alert(alertMsg);
		return false;
	}
	
 //Given a zip code was entered, check to see if its in 5 or 5-4 digit
 //format for US or A5W 4W2 format for Canadian Zip codes.
 boolValidateZip = bwwValidateZipCode(strZipCode);
   
 //If the zip code is not in the required format, throw out this error.
 if (boolValidateZip == false)
 {
  form.zip.focus(strZipCode);
  alert("Please enter your ZIP Code in the following format:\n55555\n");
		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;
}

function bwwValidateZipCode(zipCode)
{
 var regexProperZip=/^\d{5}-\d{4}$|^\d{5}$|[A-Z]\d[A-Z] \d[A-Z]\d$/
      
 if (zipCode.search(regexProperZip)==-1)
 {  
  return false;
 }
 return true;
}
 