//TODO: testing?

/** 
 * @fileOverview File for storing useful generic utility functions for use
 * throughout the application.
 * 
 * @author blake, drockwell
 */

//TODO: document
function flipDisplay(elem_id)
{
  e = $(elem_id);
  if (e.style.display == 'none')
  {
    e.style.display = 'block';
  }
  else
  {
    e.style.display = 'none';
  }
}

/**
 * Selects and highlights all text of a field for easy replacement.
 * 
 * @param {string} id the ID of a selectable DOM element
 */
function selectAll(id)
{
  document.getElementById(id).focus();
  document.getElementById(id).select();
}

/**
 * Checks all checkboxes in an array of checkboxes.
 * 
 * @param {object} field an array of checkboxes
 */
function checkAll(field)
{
  for (i = 0; i < field.length; i++)
  {
    field[i].checked = true;	
  }	
}

/**
 * Unchecks all checkboxes in an array of checkboxes.
 * 
 * @param {object} field an array of checkboxes
 */
function uncheckAll(field)
{
  for (i = 0; i < field.length; i++)
  {
    field[i].checked = false;
  }
}

/**
 * Checks all checkboxes in an array of checkboxes that correspond to
 * merchants in the system.
 * 
 * @param {object} field an array of checkboxes
 */
function checkAllMerchant(field)
{
for (i = 0; i < field.length; i++) {
	if(field[i].name == "merchant[]")
	field[i].checked = true ;	
	}	
}

/**
 * Checks all checkboxes in an array of checkboxes that correspond to
 * clients in the system.
 * 
 * @param {object} field an array of checkboxes
 */
function checkAllClient(field)
{
for (i = 0; i < field.length; i++) {
	if(field[i].name == "client[]")
	field[i].checked = true ;	
	}	
}

/**
 * Checks all checkboxes in an array of checkboxes that correspond to
 * representatives in the system.
 * 
 * @param {object} field an array of checkboxes
 */
function checkAllRepresentative(field)
{
for (i = 0; i < field.length; i++) {
	if(field[i].name == "representative[]")
	field[i].checked = true ;	
	}	
}

/**
 * Removes all children from a DOM element.
 * 
 * @param {object} obj a DOM element to remove children from
 */
function removeChildren(obj)
{
  var cell = obj;
  
  if (cell.hasChildNodes())
  {
    while (cell.childNodes.length > 0)
    {
      cell.removeChild(cell.firstChild);       
    } 
  }
}
