/*
@ PURPOSE OF THE SCRIPT:
This script was written to help in the reduction of processing burdens placed on servers for large search forms
that use the GET method for form processing.  It was designed in part to reduce the SQL search timeout issue 
common in Real Estate MLS Search forms that rely on the "GET" method to reduce the number of fields passed in the 
query string. If a search form field contains a NULL or no value it will not be passed on to the GET string.

@ CONFIGURATION OF THE SCRIPT:
To use this script a variable or perminant addition to the body tag is required as follows; 
EXAMPLE: <body onload="enableEmptyFields(document.choose);">
You must also add an onSubmit event handler (property) belonging to a Form object as follows:
EXAMPLE: <form action="the-name-of-your-script.php" method="get" onsubmit="disableEmptyFields(this);" name="choose">
############################### COPYRIGHT NOTICE ENDS ############################# */
function enableEmptyFields(form) {
  var i = 0;
  var field;
  var j = 0;
  var opt;
  while (field = form.elements[i++]) {
    switch (field.nodeName) {
      case "input":
        switch (field.type) {
          case "checkbox":
          case "radio":
            field.disabled = !field.checked;
            break;
          default:
            field.disabled = false;
            break;
        }
        break;
      case "select":
        if (field.multiple) {
          j = 0;
          while (opt = field.options[j++]) {
            opt.disabled = !opt.selected;
          }
        } else {
          field.disabled = false;
        }
        break;
      default:
        field.disabled = false;
        break;
    }
  }
}
function disableEmptyFields(form) {
  var i = 0;
  var field;
  var j = 0;
  var opt;
  
  while (field = form.elements[i++]) {
    switch (field.nodeName) {
      case "input":
        switch (field.type) {
          case "checkbox":
          case "radio":
            field.disabled = !field.checked;
            break;
          default:
            field.disabled = (field.value.length > 0) ? false : true;
            break;
        }
        break;
      case "select":
        if (field.multiple) {
          j = 0;
          while (opt = field.options[j++]) {
            opt.disabled = !opt.selected;
          }
        } else {
          field.disabled = (field.value.length > 0) ? false : true;
        }
        break;
      default:
        field.disabled = (field.value.length > 0) ? false : true;
        break;
    }
  }
}
