// JavaScript Document

//takes in a number, and spits out a string with the commas added at the right places
function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/*
 * This function has to go on checkbox. When it's checked, it will select all the other
 * checkboxes in the entire document or within a certain element (optional second 
 * argument).
 */

function selectAll(cbox) {
   var cont = (arguments[1]) ? document.getElementById(arguments[1]) : document;
   var inputs = cont.getElementsByTagName('input');
   for (var i=0; i<inputs.length; i++) {
      if (inputs[i].type == 'checkbox' && inputs[i].disabled == false) inputs[i].checked = cbox.checked;
   }
}

/*
 * This function has to go on checkbox. When it's checked, it will disable all the other
 * checkboxes in the entire document or within a certain element (optional second
 * argument).
 */

function disableAll(cbox) {
   var cont = (arguments[1]) ? document.getElementById(arguments[1]) : document;
   var inputs = cont.getElementsByTagName('input');
   for (var i=0; i<inputs.length; i++) {
      inputs[i].disabled = (inputs[i].type == 'checkbox' && cbox.checked) ? "" : "disabled";
   }
}

// alternate table colors
function alternate_table_row_colors(table_id){
 if(document.getElementsByTagName){  
   var table = document.getElementById(table_id);  
   var rows = table.getElementsByTagName("tr");  
   for(i = 0; i < rows.length; i++){          
 //manipulate rows
     if(i % 2 == 0){
       rows[i].className = "even";
     }else{
       rows[i].className = "odd";
     }      
   }
 }
}

