function checkAll(theForm) {
  var aFormElements = theForm.elements;
  var aFormElement;
  for (var i = 1; i < aFormElements.length; i++) {
    aFormElement = aFormElements[i];
    if (aFormElement.type == "checkbox") {
      aFormElement.checked = theForm.selectAll.checked;
    }
  }
}

/*
  Detail report values are defined in QueryResultsForm
  Since were using the selectReport form item to store the value of the detail report, and since at least 1 report
  must be selected before we can run a query, we are selecting the first radio in the list, at which point an
  object is created in the form, and then chaning its value to the detail report.
*/
function getDetailReport (theForm, theID, theReportType, theReportViewType) {
  if ((theReportType == "trustDetail") || (theReportType == "unionDetail")) {
    theForm.reportType.value = "detailResults";
  }
  else {
    theForm.reportType.value = "formReport";
  }
  theForm.detailID.value = theID;
  theForm.detailReport.value = theReportType;
  if (theReportViewType != null) {
    theForm.rptView.value = theReportViewType;
  }
  theForm.submit ();
/*
  if (theForm.reportType.value == "formReport") {
    window.open (theForm.action, "_blank", "location=no,status=no,toolbar=no", false);
  }
  else {
    theForm.submit ();
  }
*/
}

function queryResultResetForm (theForm, theReportType) {
  theForm.reportType.value = theReportType;
  theForm.detailID.value = "";
  theForm.detailReport.value = "undefined";
  return true;
}

/*
  Actions are as follows:
  First:      0
  Previous:   1
  Next:       2
  Last:       3
  Sort:       4
*/
function goToPage (theForm, theAction) {
  theForm.pageAction.value = theAction;
  theForm.submit();
}

function sortColumn (theForm, theSortColumn, theSortAscending) {
  if (theForm.endRow.value <= 0) {
    window.alert ("There are no records to sort.");
  }
  else if ((theForm.endRow.value - theForm.startRow.value) >= 1){
    theForm.pageAction.value = 4;
    theForm.sortColumn.value = theSortColumn;
    if (theForm.reportTypeSave != null) {
      theForm.reportType.value = theForm.reportTypeSave.value;
    }
    if ((theForm.reportType.value == "orgResults") || (theForm.reportType.value == "indResults")) {
      theForm.selectReport.value = null;
    }
    theForm.submit ();
  }
}
