function round(amt,decplaces) {
	// decplaces is optional, defaulting to 2
	// todo: preserve trailing zeroes (eg 1.6 should == 1.60)
	decplaces = decplaces ? Math.pow(10,decplaces) : 100;
 	return Math.round(amt*decplaces)/decplaces;
}

function removeElementById(id) {
	var el = document.getElementById(id);
	if (el) {
		el.parentNode.removeChild(el);
	}
}

function checkall(el,check) {
	for(var i=0 ; i<el.length ; i++) {
		if(check==1) {
			el[i].checked = true;
		} else {
			el[i].checked = false;
		}
	}
}

function toggleText(el,toggleOne,toggleTwo) {
	// depends on jQuery
	if($("#"+el).text()==toggleTwo) {
		$("#"+el).text(toggleOne);
	} else {
		$("#"+el).text(toggleTwo);
	}

}

function number_format(a, b, c, d) {
	// this horrific-looking function copied from gg.
    // number_format(number, decimals, comma, formatSeparator)
    a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
    e = a + '';
    f = e.split('.');
    if(!f[0]) f[0] = '0';
    if(!f[1]) f[1] = '';
    if(f[1].length < b){
        g = f[1];
        for(i = f[1].length + 1; i <= b; i++) {
            g += '0';
        }
        f[1] = g;
    }
    if(d != '' && f[0].length > 3) {
        h = f[0];
        f[0] = '';
        for(j = 3; j < h.length; j += 3) {
            i = h.slice(h.length - j, h.length - j + 3);
            f[0] = d + i +  f[0] + '';
        }
        j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
        f[0] = j + f[0];
    }
    c = (b <= 0) ? '': c;
    return f[0] + c + f[1];
}
