//
function selectAll (pendingform, state) {
  // Sets all of the radio buttons or select boxes to the same item.
  var counter = 0;
  var blah;
  blah = new String (state);
  while (pendingform.elements[counter] != null) {
    if (("checkbox".indexOf (pendingform.elements[counter].type)) != -1) {
        pendingform.elements[counter].checked=state;
    } else {
      if (("radio".indexOf (pendingform.elements[counter].type)) != -1) {
        if ((blah.indexOf (pendingform.elements[counter].value)) != -1) {
          pendingform.elements[counter].click();
        }
      } else {
        if (pendingform.elements[counter].options != null) {
          if(pendingform.elements[counter].options[state] != null) {
            pendingform.elements[counter].options[state].selected = true;
          }
        }
      }
    }
    counter++;
  }
  return false;
}

function newSelectAll (pendingform, state, testname) {
  // Sets all of the radio buttons or select boxes to the same item.
  var counter = 0;
  var arLen, nameLen, i;
  var elName;
  var found = 0;

  if (state == "reset") {
    pendingform.reset();
    return false;
  }

  while (pendingform.elements[counter] != null) {
    if (pendingform.elements[counter].name == "bulkset") {
      counter++;
      continue;
    }

    if (testname) {
      found = 0;
      arLen = testname.length;
      for(i=0;(i<arLen) && !found;i++) {
        nameLen = testname[i].length;
        elName = pendingform.elements[counter].name.substring(0,nameLen)
        if (elName == testname[i]) {
          found = 1;
        }
      }

      if (!found) {
        counter++;
        continue;
      }
    }

    if (("radio".indexOf(pendingform.elements[counter].type)) != -1) {
      if (pendingform.elements[counter].value == state) {
        pendingform.elements[counter].click();
      }
    } else {
      if (pendingform.elements[counter].options != null) {
        i = 0;
        while (pendingform.elements[counter].options[i] != null) {
          if (pendingform.elements[counter].options[i].value == state) {
            pendingform.elements[counter].options[i].selected = true;
          }
          i++;
        }
      }
    }
    counter++;
  }
  return false;
}

function CheckAll (pendingform, state, testname) {
  // Sets all of the checkbox.
  var counter = 0;
  var arLen, nameLen, i;
  var elName;
  var found = 0;

  if (state == "reset") {
    pendingform.reset();
    return false;
  }

  while (pendingform.elements[counter] != null) {
    if (pendingform.elements[counter].name == "bulkset" ||
        pendingform.elements[counter].name == "checkbox_bulkset") {
      counter++;
      continue;
    }

    if (testname) {
      found = 0;
      arLen = testname.length;
      for(i=0;(i<arLen) && !found;i++) {
        nameLen = testname[i].length;
        elName = pendingform.elements[counter].name.substring(0,nameLen)
        if (elName == testname[i]) {
          found = 1;
        }
      }

      if (!found) {
        counter++;
        continue;
      }
    }

    if (("checkbox".indexOf(pendingform.elements[counter].type)) != -1) {
      if (pendingform.elements[counter].checked != state) {
        pendingform.elements[counter].checked = state;
      }
    }
    counter++;
  }
  return false;
}

