function txtCustAdults_onchange() {
	updateElements('Birdhouse')
}
function updateElements(room){
	var status = eval('frmReservations.chk' + room + '.status')
	var rate = '';
	var totalizer = parseFloat('0.00');
	var tempNum = parseFloat('0.00');
	var roomCtr = 0;
	var extraGuestCharge = parseFloat('10.00');
	//get the element
	var el = eval("document.getElementById('txt" + room + "')");
	//get the rate
	switch (room) {
		case 'Birdhouse': rate = '125.00'; break;
		case 'CoalCracker': rate = '135.00'; break;
		case 'CoveredBridges': rate = '85.00'; break;
		case 'Homestead': rate = '85.00'; break;
		case 'Lighthouse': rate = '85.00'; break;
		default: rate = 0.00;
	}
	//toggle the output textbox with the appropriate rate
	if (status) {
		el.value = rate;
	} else {
		el.value = '';
	}
	//update the total nightly rate textbox
	if (frmReservations.txtBirdhouse.value != '') {
		totalizer = parseFloat(frmReservations.txtBirdhouse.value);
		roomCtr++;
	}
	if (frmReservations.txtCoalCracker.value != '') {
		totalizer += parseFloat(frmReservations.txtCoalCracker.value);
		roomCtr++;
	}
	if (frmReservations.txtCoveredBridges.value != '') {
		totalizer += parseFloat(frmReservations.txtCoveredBridges.value);
		roomCtr++;
	}
	if (frmReservations.txtHomestead.value != '') {
		totalizer += parseFloat(frmReservations.txtHomestead.value);
		roomCtr++;
	}
	if (frmReservations.txtLighthouse.value != '') {
		totalizer += parseFloat(frmReservations.txtLighthouse.value);
		roomCtr++;
	}
	frmReservations.txtTotNightRate.value = rnd(totalizer);
	//if we have a room value and a calendar value then let's run the totals	
	if (frmReservations.calCounter.value != '' && frmReservations.txtTotNightRate.value != '') {
		//calculate extra guest charges
		if (frmReservations.txtCustAdults.value != '') {
			if ((frmReservations.txtCustAdults.value * 1) > (roomCtr * 2)) {
				frmReservations.txtExtraGuest.value = rnd(((frmReservations.txtCustAdults.value * 1) - (roomCtr * 2)) * extraGuestCharge * frmReservations.calCounter.value);
			} else {
				frmReservations.txtExtraGuest.value = rnd('0');
			}
		}
		frmReservations.txtSubtotal.value = rnd((frmReservations.calCounter.value * frmReservations.txtTotNightRate.value) + (frmReservations.txtExtraGuest.value * 1));
		
		//calculate state (6%) and local (3%) taxes, then sum up the total
		if (frmReservations.txtSubtotal.value != '') {
			frmReservations.txtTaxes.value = rnd(frmReservations.txtSubtotal.value * 0.09);
			frmReservations.txtTotal.value = rnd((frmReservations.txtSubtotal.value * 1) + (frmReservations.txtTaxes.value * 1));
		}
	}
}
function rnd(rnum) {
	var rlength = 2; //the number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) { //to fix known bug in javascript
		rnum = rnum-5000; 
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = pad(newnumber)
	}
	return newnumber;
}
function pad(rounded_value) {
    // Convert the number to a string
    var value_string = rounded_value.toString()
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")
    // Is there a decimal point?
    if (decimal_location == -1) {
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        // If decimal places is greater than zero, tack on a decimal point
        value_string += 2 > 0 ? "." : ""
    }
    else {
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = 2 - decimal_part_length
    if (pad_total > 0) {
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}