// JavaScript Document

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}


/*
*This JavaScript takes an input number and adds commas in the proper places.
*As needed by its original purpose, also adds a dollar.
*Copyright 1998, David Turley <dturley@pobox.com>
*Feel free to use and build on this code as long as you include this notice.
*Last Modified March 3, 1998
*/
function commify(num) {
	if ( typeof num == "undefined" || num == null ) num = "0";
	var newNum = "";
	var newNum2 = "";
	var count = 0;
	
	//check for decimal number
	if (num.indexOf('.') != -1){ //number ends with a decimal point
		if (num.indexOf('.') == num.length-1) {
			num += "00";
		}
		if (num.indexOf('.') == num.length-2) { //number ends with a single digit
			num += "0";
		}
		
		var a = num.split(".");
		num = a[0]; //the part we will commify
		var end = a[1] //the decimal place we will ignore and add back later
	}	else {
		var end = "00";
	}
	
	//this loop actually adds the commas
	for (var k = num.length-1; k >= 0; k--){
		var oneChar = num.charAt(k);
		if (count == 3){
			newNum += ",";
			newNum += oneChar;
			count = 1;
			continue;
		}
		else {
			newNum += oneChar;
			count ++;
		}
	} //but now the string is reversed!
	
	//re-reverse the string
	for (var k = newNum.length-1; k >= 0; k--){
		var oneChar = newNum.charAt(k);
		newNum2 += oneChar;
	}
	
	// add decimal ending from above
	newNum2 = newNum2 + "." + end;
	return newNum2;
}

function commifyNoDecimal(num) {
	var val = commify(num);
	return val.substr( 0, val.length - 3);
}