function validateFormOnSubmit(theForm) {
var reason = "";
  reason += validateFirstName(theForm.firstname);
  reason += validateLastName(theForm.lastname);		
  reason += validateEmail(theForm.emailaddress);
  reason += validateSubscribe(theForm.subscribe);	
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateBeef(theForm) {
var reason = "";
  reason += validateFirstName(theForm.firstname);
  reason += validateLastName(theForm.lastname);	
  reason += validateBeefProgram(theForm.beefProgram);		
  reason += validateBeefArea(theForm.beefarea);
  reason += validateYourBeef(theForm.yourBeef);	
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateBuySell(theForm) {
var reason = "";
  reason += validateYourName(theForm.yourname);
  reason += validatePostTitle(theForm.posttitle);
  reason += validateCategory(theForm.category);		
  reason += validatePosting(theForm.posting);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateOBSBooking(theForm) {
var reason = "";
  reason += validateEventName(theForm.eventname);
  reason += validateEventDesc(theForm.eventdesc);
  reason += validateContactPerson(theForm.contactperson);		
  reason += validateEmail(theForm.emailaddress);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateYourName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in your name.\n"
    } else {
    }
    return error;  
}


function validateFirstName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in your first name.\n"
    } else {
    }
    return error;  
}

function validateLastName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
       error = "Please enter in your last name.\n"
    } else {
       }
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        error = "Please enter a valid email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        error = "The email address contains illegal characters.\n";
    } else {
       }
    return error;
}

function validateSubscribe(fld) {
    var error = "";
 
    if (fld.checked == false) {
        error = "You must authorize the FSU to send you emails.\n"
    } else {
    }
    return error;  
}

function validateBeefProgram(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in your program.\n"
    } else {
    }
    return error;  
}

function validateBeefArea(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please select a beef topic.\n"
    } else {
    }
    return error;  
}

function validateYourBeef(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in your beef.\n"
    } else {
    }
    return error;  
}

function validatePostTitle(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in a title for your posting.\n"
    } else {
    }
    return error;  
}

function validatePosting(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter a posting.\n"
    } else {
    }
    return error;  
}

function validateCategory(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please select a category.\n"
    } else {
    }
    return error;  
}

function validateEventName(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in the name of your event.\n"
    } else {
    }
    return error;  
}

function validateEventDesc(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in a short description of your event.\n"
    } else {
    }
    return error;  
}

function validateContactPerson(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "Please enter in the contact person's name.\n"
    } else {
    }
    return error;  
}
