/*
 This file should only contain JavaScript that is accessed after the page is loaded.
 Things that deal directly with how the page is written go in header.js.
 We try our best to follow progressive enhancement methodology.
*/

function selectCheckboxes(el,name) {
  var nodes, i, input;

  if(!el) {
    return false;
  }

  nodes=el.elements;
  for(i=0; i < nodes.length; i++) {
    input=nodes[i];
    if (input.type == 'checkbox') {
      // If name is specified, only toggle checkboxes with the specified name
      // If name is not specified, toggle all checkboxes
      if (name) {
	if ( input.name == name) {
          input.checked=true;
        }
      }
      else {
        input.checked=true;
      }
    }
  }

  return true;
}

function unselectCheckboxes(el,name) {
  var nodes, i, input;

  if(!el) {
    return false;
  }

  nodes=el.elements;
  for(i=0; i < nodes.length; i++) {
    input=nodes[i];
    if (input.type == 'checkbox') {
      // If name is specified, only toggle checkboxes with the specified name
      // If name is not specified, toggle all checkboxes
      if (name) {
	if ( input.name == name) {
          input.checked=false;
        }
      }
      else {
        input.checked=false;
      }
    }
  }

  return true;
}

function toggleCheckboxes(el,name) {
  var nodes, i, input;

  if(!el) {
    return false;
  }

  nodes=el.elements;
  for(i=0; i < nodes.length; i++) {
    input=nodes[i];
    if (input.type == 'checkbox') {
      // If name is specified, only toggle checkboxes with the specified name
      // If name is not specified, toggle all checkboxes
      if (name) {
	if ( input.name == name) {
          input.checked=input.checked ? false : true;
        }
      }
      else {
        input.checked=input.checked ? false : true;
      }
    }
  }

  return true;
}
