
function doCalc() {
    var hours = document.forms['calcTime'].hours.value.replace(',','');
    var rate = document.forms['calcTime'].rate.value.replace(',','');
    var people = document.forms['calcTime'].people.value.replace(',','');

    if (isNaN(hours) || isNaN(rate) || isNaN(people)) { alert('One of the values you entered is not a number. Please try again.'); return false; }
    if (people % 1 != 0) { alert('Your number of staff must be a whole number. Please try again.'); return false; }

    hours = parseFloat(hours);
    rate = parseFloat(rate);
    people = parseInt(people);

    // this is the total amount lost
    var totalLostPerDay = (hours * rate * people);
    var totalLostPerYear = (totalLostPerDay * 5) * 50; // five days a week, 50 weeks a year.

    // send the ajax result
    var jx = new Ajax.Request(
    '/xml/time_calculator.php',
    {
        method: 'post',
        parameters: {'hours':hours.toFixed(2),'rate':rate.toFixed(2),'people':people.toFixed(0),'total':totalLostPerYear.toFixed(2)},
        onSuccess: function(response) { 
            // nothing to do
            pageView("CALCULATOR", "08");
        },
        onFailure: Prototype.emptyFunction
    });

    document.getElementById('resultsTotalCost1').innerHTML = '$' + addCommas(totalLostPerYear.toFixed(2));
    document.getElementById('results').style.display = 'block';

    return false;

}
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;
}

