var isIE3 = (navigator.appVersion.indexOf('MSIE 3') != -1);
function validation(realName, formEltName, eltType, upToSnuff, format) {
  this.realName = realName;
  this.formEltName = formEltName;
  this.eltType = eltType;
  this.upToSnuff = upToSnuff;
  this.format = format;
}

var educationLevel = new validation('Education Level', 'educationLevel', 'select', 'isSelect(formObj)', null);
var program = new validation('Program of Interest', 'program', 'select', 'isSelect(formObj)', null);
var elts = new Array(educationLevel, program);

var allAtOnce = true;

var beginRequestAlertForText = "Please include ";
var beginRequestAlertGeneric = "Please choose a ";
var endRequestAlert = ".";
var beginInvalidAlert = " ";
var endInvalidAlert = " is invalid";
var beginFormatAlert = "  Use this format: ";

function isText(str) {
  return (str != "");
}

function isSelect(formObj) {
  return ((formObj.options[formObj.selectedIndex].value != "0") && (formObj.options[formObj.selectedIndex].value != ""));
}

function isSelectGradYr(formObj) {
  if ((formObj.value == "") || (formObj.value =="2006")) {
    alert ("This program is only for current high school graduates");
  }
  return (formObj.value != "");
}

function isRadio(formObj) {
  for (j=0; j<formObj.length; j++) {
    if (formObj[j].checked) {
      return true;
    }
  }
  return false;
}

function isCheck(formObj, form, begin, num) {
  for (j=begin; j<begin+num; j++) {
    if (form.elements[j].checked) {
      return true;
    }
  }
  return false;
}

function isEmail(str) {
  return (str.match(/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/))
}

function isZipCode(str) {
  var l = str.length;
  if ((l != 5) && (l != 10)) { return false }
  for (j=0; j<l; j++) {
    if ((l == 10) && (j == 5)) {
      if (str.charAt(j) != "-") { return false }
    } else {
      if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
    }
  }
  return true;
}

function isPhoneNum(str) {
	if (str.length == 12)
	{
		for (j=0; j<str.length; j++) {
		if ((j == 3) || (j == 7)) {
		  if (str.charAt(j) != "-") { return false }
			} else {
		  if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
			}
		}
		return true;
	}
	else if(str.length == 10)
	{
		for (j=0; j<str.length; j++) {
			if ((str.charAt(j) < "0") || (str.charAt(j) > "9")) { return false }
		}
	}
	else{
		return false;
	}
	return true;
}

function validateForm(form) {

  var formEltName = "";
  var formObj = "";
  var str = "";
  var realName = "";
  var alertText = "";
  var firstMissingElt = null;
  var hardReturn = "\r\n";

  for (i=0; i<elts.length; i++) {
    formEltName = elts[i].formEltName;
    formObj = eval("form." + formEltName);
    realName = elts[i].realName;

    if (elts[i].eltType == "text") {
      str = formObj.value;

      if (eval(elts[i].upToSnuff)) continue;

      if (str == "") {
        if (allAtOnce) {
          alertText += beginRequestAlertForText + realName + endRequestAlert + hardReturn;
          if (firstMissingElt == null) {firstMissingElt = formObj};
        } else {
          alertText = beginRequestAlertForText + realName + endRequestAlert + hardReturn;
          alert(alertText);
        }
      } else {
        if (allAtOnce) {
          alertText += str + beginInvalidAlert + realName + endInvalidAlert + hardReturn;
        } else {
          alertText = str + beginInvalidAlert + realName + endInvalidAlert + hardReturn;
        }
        if (elts[i].format != null) {
          alertText += beginFormatAlert + elts[i].format + hardReturn;
        }
        if (allAtOnce) {
          if (firstMissingElt == null) {firstMissingElt = formObj};
        } else {
          alert(alertText);
        }
      }
    } else {
      if (eval(elts[i].upToSnuff)) continue;
      if (allAtOnce) {
        if (elts[i].eltType == "custom") {
          alertText += realName + hardReturn;
          if (firstMissingElt == null) {firstMissingElt = formObj};
        } else {
          alertText += beginRequestAlertGeneric + realName + endRequestAlert + hardReturn;
          if (firstMissingElt == null) {firstMissingElt = formObj};
		}
      } else {
        alertText = beginRequestAlertGeneric + realName + endRequestAlert + hardReturn;
        alert(alertText);
      }
    }
    if (!isIE3) {
      var goToObj = (allAtOnce) ? firstMissingElt : formObj;
      if (goToObj.select) goToObj.select();
      if (goToObj.focus) goToObj.focus();
    }
    if (!allAtOnce) {return false};
  }
  if (allAtOnce) {
    if (alertText != "") {
      alert(alertText);
      return false;
   }
  } 
  return true;
}
