// client.js

function isValidEmail(s) {
  var PNum = new String(s);
  var regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  return regex.test(PNum);
}

function isAllWhitespace(s) {
  var whitespace = " \t\n\r";
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) {
      return false;
    }
  }
  return true;
}

function isEmpty(s) { 
  return (s == null || s.length == 0 || isAllWhitespace(s)); 
}

function validateForm(f) {
	if (isEmpty(f.MyName.value)) {
		f.MyName.select();
		alert("Enter your name.");
		return false;
	}
	if (isEmpty(f.MyCity.value)) {
		f.MyCity.select();
		alert("Enter your city.");
		return false;
	}
	if (isEmpty(f.MyState.value)) {
		f.MyState.select();
		alert("Enter your state.");
		return false;
	}
	if (isEmpty(f.MyHomePhone.value)) {
		f.MyHomePhone.select();
		alert("Enter your Home Phone Number.");
		return false;
	}
	if (isEmpty(f.FromEmail.value) || !isValidEmail(f.FromEmail.value)) {
		f.FromEmail.select();
		alert("Enter your email address.");
		return false;
	}
	if (isEmpty(f.Event.value)) {
		f.Event.select();
		alert("Enter The Event Name.");
		return false;
	}
	if (isEmpty(f.Date.value)) {
		f.Date.select();
		alert("Enter the event date.");
		return false;
	}
	if (isEmpty(f.City.value)) {
		f.City.select();
		alert("Enter the event city.");
		return false;
	}
	if (isEmpty(f.State.value)) {
		f.State.select();
		alert("Enter the event state.");
		return false;
	}
	if (isEmpty(f.Section.value)) {
		f.Section.select();
		alert("Enter the event section.");
		return false;
	}
	if (isEmpty(f.Row.value)) {
		f.Row.select();
		alert("Enter the event row.");
		return false;
	}
	if (isEmpty(f.Seats.value)) {
		f.Seats.select();
		alert("Enter the event seats.");
		return false;
	}
	alert("Thank you. You should be receiving a confirmation email shortly.");
	return true;
}

