// JavaScript Document


jQuery.toNum = function(str) {
		// hackety hack hack
		str = str + " " ;
		
		str = str.replace(/[^\d\.-]/g, "");
		str-=1;
		str+=1;
		
		return str || 0;
};


jQuery.dp= function(val) {
	var val = jQuery.toNum(val || 0);
	var decimalPlaces = arguments[1] || 2;
	var debug = arguments[2] || 0;
	
	if (debug) {
		alert("dp " + val);
	}
	
	val = jQuery._round(val, decimalPlaces);	// actually get the right value
	val += ''; // make us a string;
//	alert("val:" + val + "    decimal:"+decimalPlaces);
	
	if (decimalPlaces > 0) {	
		if (val.indexOf('.') == -1) {val = val + "."};	// add a dot if there isn;t one, so we don't get stuck in a loop
		var count=0;
		while ((count < 10) && val.charAt(val.length - decimalPlaces -1) != '.') {
			val = val + "0";
			count++;
		}
	}
	return val;	
}
	
jQuery._round= function(n, places) {
	var factor = Math.pow(10, (places || 0));
	return parseInt((n * factor) + (n < 0 ? -1 : 1) * 0.5) / factor;
}


jQuery.sum = function(array) {
	var total = 0;
	$(array).each(
		function() {
			total += jQuery.toNum(this);
		}
	)
	return total;
}


	
