//////////////////////////////////////////////////////////////////////
// Error handling
//////////////////////////////////////////////////////////////////////
function handleError() {
	alert("You have encountered a JavaScript error. This page will not work.");
	return true;
}

window.onerror = handleError;
//////////////////////////////////////////////////////////////////////
// icsCommon.js
// Common functions that should be overwritten
//////////////////////////////////////////////////////////////////////
function RequiredField(aName, aLabel) {
  this.name = aName;
  this.label = aLabel;
};

requiredFields = new Array();

function isRequiredOK(thisForm) {
// Return true if all of the fields have permissible values.
  if (window.isRequiredOKLocal) {
    if (!isRequiredOKLocal(thisForm)) return false;
  }
  for (i=0; i<requiredFields.length; i++) {
    if (!checkString(thisForm.elements[requiredFields[i].name], requiredFields[i].label)) return false;
  }
  return true;
}

function entry(thisForm) {
// Return a string representing the form entry.
  var theResult = "";
  return theResult;
}
//////////////////////////////////////////////////////////////////////
// Common data functions
//////////////////////////////////////////////////////////////////////
function isValidForm(thisForm) {
  if (isRequiredOK(thisForm)) {
    fillStdFields(thisForm);
    //yahooFormFix(thisForm);
    return true;
    }
  else
    return false;
}
function fillStdFields(thisForm) {
// Fill standard form fields.
// Required TEXT fields: formEntry, formSubmitter, formBrowser
  thisForm.formEntry.value = entry(thisForm);
  thisForm.formSubmitter.value = submitter(thisForm);
  thisForm.formBrowser.value = browser();
}
function browser() {
// Return a string representing the browser being used to submit the form.
  return navigator.appName + " " + navigator.appVersion;
}
function submitter(thisForm) {
// Return a string describing the submitter.
// Requires the TEXT fields: realname, email
  var today = new Date();
  theResult = "Submitted on " + today.toString()
    + " by " + textValue(thisForm.realname)
    + " <" + textValue(formElement(thisForm, "email")) + ">";
  return theResult;
}
function formElement(thisForm, elementName) {
// Return the element in the form with the given name.
// If there is no such element, return null.
  var theResult = null;
  for ( var i = 0; i < thisForm.length; i++ ) {
    if (thisForm.elements[i].name == elementName)
      theResult = thisForm.elements[i];
  }
  return theResult;
}
//////////////////////////////////////////////////////////////////////
// Utility functions
//////////////////////////////////////////////////////////////////////
function selectValue (thisSelect) {
// Given a SELECT group, return the value of the SELECTED option.
// If the SELECTED option does not have an explicit value, return its text.
// If there is no SELECTED option return an empty string.
  var theResult = "";
  for ( var i = 0; i < thisSelect.length; i++ ) {
    if (thisSelect.options[i].selected) {
      if (thisSelect.options[i].value == "")
        theResult = thisSelect.options[i].text
      else
        theResult = thisSelect.options[i].value
    }
  }
  return theResult;
}
function radioValue(thisRadio) {
// Given a RADIO group, return the value of the CHECKED button.
// If there is no CHECKED button, return an empty string.
  var theResult = "";
  for ( var i = 0; i < thisRadio.length; i++ ) {
    if (thisRadio[i].checked) theResult = thisRadio[i].value
  }
  return theResult;
}
function textValue(thisText) {
// Given a TEXT field, return its value.
// If the TEXT field is null, return an empty string.
  var theResult = "";
  if (thisText.value != null) {
    theResult = thisText.value;
  }
  return theResult;
}

