function roundOff(value, precision) {
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".00";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

var bookHrRate=0.00, hrsWeek=0.00, insMonth=0.00, penBenefits=0.00, monthlySalary=0.00, pctOverhead=0.00, wksVacation=0.00, compIns=0.00, overhead=0.00, overhead2=0.00, payroll=0.00, bookWeek=0.00, timeWorth=0.00, hrsHiring=0.00, cpaFees=0.00, salary=0.00, insurance=0.00, pension=0.00, vacation=0.00, payrollTaxes=0.00, overheadCost=0.00, manageTime=0.00, hiring=0.00, cpaFeesCalc=0.00, totalCosts=0.00, numEmployees=0.00, monthlyRept=0.00, cashFlow=0.00, ttlCPACost=0.00, estInvestment=0.00, dollarSavings=0.00, pctSavings=0.00, other=0.00, totalMonthlyCosts=0.00, estOSIFee=750, currentCpaFeeCalc=0.00, currentCpaFee=0.00, currentBookkeeperPlusCPA=0.00

function calcForm() {
	// read the input values
	BookWeek=document.calculatorForm.txtBookWeek.value
	TimeWorth=document.calculatorForm.txtTimeWorth.value
	HrsHiring=document.calculatorForm.txtHrsHiring.value
	bookHrRate=document.calculatorForm.txtBookHrRate.value
	hrsWeek=document.calculatorForm.txtHrsWeek.value
	pctPenBenefits=document.calculatorForm.txtPenBenefits.value
	penBenefits=pctPenBenefits/100
	wksVacation=document.calculatorForm.txtWksVacation.value
	insMonth=document.calculatorForm.txtInsMonth.value
	pctCompIns=document.calculatorForm.txtCompIns.value
	compIns=pctCompIns/100
	pctOverhead=document.calculatorForm.txtOverhead.value
	overhead=pctOverhead/100
	payroll=document.calculatorForm.txtPayroll.value
	bookWeek=document.calculatorForm.txtBookWeek.value
	timeWorth=document.calculatorForm.txtTimeWorth.value
	hrsHiring=document.calculatorForm.txtHrsHiring.value
	cpaFees=document.calculatorForm.txtCpaFees.value

	// do the calculations
	ManageBookkeeper=BookWeek*TimeWorth*52/12
	HiringTraining=HrsHiring*30/12
	salary=bookHrRate*hrsWeek*52/12
	insurance=insMonth
	pension=salary*penBenefits
	vacation=bookHrRate*hrsWeek*2/12
	payrollTaxes=salary*compIns
	overheadCost=salary*overhead
	manageTime=bookWeek*timeWorth*52/12
	hiring=hrsHiring*30/12
	cpaFeesCalc=1*cpaFees

	/* set the calculated fields to their formatted values
	We have to remember to use the form of document.<object> rather than just <object>
	because Netscape is too bloody stupid to understand that objects are in documents */
	document.calculatorForm.txtInsMonth.value=formatDollar(insurance)
	document.calculatorForm.txtCompIns.value=formatDollar(payrollTaxes)
	document.calculatorForm.txtOverhead.value=formatDollar(overheadCost)
	document.calculatorForm.txtPayroll.value=formatDollar(payroll)

	monthlySalary=bookHrRate*hrsWeek*52/12
	document.calculatorForm.txtMonthlySalary.value=formatDollar(monthlySalary)
	healthInsurance=insMonth
	document.calculatorForm.txtHealthInsurance.value=formatDollar(healthInsurance)
	pensionBenefits=penBenefits*monthlySalary
	document.calculatorForm.txtPensionBenefits.value=formatDollar(pensionBenefits)
	vacation=bookHrRate*hrsWeek*wksVacation/12
	document.calculatorForm.txtVacation.value=formatDollar(vacation)
	payrollTaxes=compIns*monthlySalary
	document.calculatorForm.txtPayrollTaxes.value=formatDollar(payrollTaxes)
	overhead2=overhead*monthlySalary
	document.calculatorForm.txtOverhead2.value=formatDollar(overhead2)
	thirdPayrollService=payroll
	document.calculatorForm.txtThirdPayrollService.value=formatDollar(thirdPayrollService)

	// total bookkeeper costs
	bookkeeperCosts = monthlySalary + 1*healthInsurance + 1*pensionBenefits + 1*vacation + 1*payrollTaxes + 1*overhead2 + 1*thirdPayrollService
	document.calculatorForm.txtBookkeeperCosts.value=formatDollar(bookkeeperCosts)

	hiringTraining=getRoundedNF(HiringTraining)
	document.calculatorForm.txtHiringTraining.value=formatDollar(hiringTraining);
	manageBookkeeper=getRoundedNF(ManageBookkeeper)
	document.calculatorForm.txtManageBookkeeper.value=formatDollar(manageBookkeeper);
	cPAFeesFix=cpaFees
	document.calculatorForm.txtCPAFeesFix.value=formatDollar(cPAFeesFix);

	// total opportunity costs of owner
	costsOwner = hiringTraining + 1*manageBookkeeper + 1*cPAFeesFix
	document.calculatorForm.txtCostsOwner.value=formatDollar(costsOwner)

	// total current monthly costs
	currentMonthlyCosts = monthlySalary + 1*healthInsurance + 1*pensionBenefits + 1*vacation + 1*payrollTaxes + 1*overhead2 + 1*thirdPayrollService + 1*hiringTraining + 1*manageBookkeeper + 1*cPAFeesFix
	document.calculatorForm.txtCurrentMonthlyCosts.value=formatDollar(currentMonthlyCosts)

	// osi fee
	//document.calculatorForm.txtOSIFee.value=OSIFee

	// savings with osi
	//savingsOSI = currentMonthlyCosts - 1*OSIFee
	//document.calculatorForm.txtSavingsOSI.value=formatDollar(savingsOSI)

	// roi
	//rOI = savingsOSI/currentMonthlyCosts
	//rOIResult = rOI*100
	//document.calculatorForm.txtROI.value=parseInt(rOIResult/1)

	// set input fields to their formatted values
	document.calculatorForm.txtBookHrRate.value=formatDollar(bookHrRate)
	document.calculatorForm.txtHrsWeek.value=hrsWeek
	document.calculatorForm.txtInsMonth.value=formatDollar(insMonth)
	document.calculatorForm.txtPenBenefits.value=100*penBenefits
	document.calculatorForm.txtWksVacation.value=wksVacation
	document.calculatorForm.txtCompIns.value=100*compIns
	document.calculatorForm.txtOverhead.value=100*overhead
	document.calculatorForm.txtPayroll.value=payroll
	document.calculatorForm.txtBookWeek.value=bookWeek
	document.calculatorForm.txtTimeWorth.value=formatDollar(timeWorth)
	document.calculatorForm.txtHrsHiring.value=hrsHiring
	document.calculatorForm.txtCpaFees.value=formatDollar(cpaFeesCalc)

	// set initial calculated values to zero to prevent errors from happening when recalculating
	bookHrRate=0.00
	bookWeek=0.00
	BookWeek=0.00
	TimeWorth=0.00
	HrsHiring=0.00
	bookkeeperPctSavings=0.00
	bookkeeperSavings=0.00
	compIns=0.00
	txtCompIns=0.00
	txtOverhead=0.00
	controllershipSavings=0.00
	cpaFees=0.00
	cpaFeesCalc=0.00
	cpaSupervision=0.00
	estBYBFee=0.00
	hiring=0.00
	HiringTraining=0.00
	hrsHiring=0.00
	hrsWeek=0
	insMonth=0.00
	insurance=0.00
	ManageBookkeeper=0.00
	manageTime=0.00
	overhead=0.00
	overheadCost=0.00
	payroll=0.00
	payrollTaxes=0.00
	txtMonthlySalary=0.00
	pctCompIns=0.00
	pctOverhead=0
	pctPenBenefits=0.00
	penBenefits=0.00
	pension=0.00
	salary=0.00
	timeWorth=0.00
	transactions=0.00
	vacation=0.00
	wksVacation=0.00
	thirdPayrollService=0.00
	overhead2=0.00
	monthlySalary=0.00
	healthInsurance=0.00
	pensionBenefits=0.00
	thirdPayrollService=0.00
	bookkeeperCosts=0.00
	manageBookkeeper=0.00
	hiringTraining=0.00
	cPAFeesFix=0.00
	costsOwner=0.00
	currentMonthlyCosts=0.00
	oSIFee=0.00
	OSIFee=0.00
	savingsOSI=0.00
	rOI=0.00
}

/* added by website providers, inc. on 06.20.02
   if the value is null the next line will assign XX.XX to the value
   if the value is not null the value will not be changed */
function initialValues() {
	if (document.calculatorForm.txtBookHrRate.value == "")
		document.calculatorForm.txtBookHrRate.value = "18.00"

	if (document.calculatorForm.txtHrsWeek.value == "")
		document.calculatorForm.txtHrsWeek.value = "25"

	if (document.calculatorForm.txtInsMonth.value == "")
		document.calculatorForm.txtInsMonth.value = "350.00"

	if (document.calculatorForm.txtPenBenefits.value == "")
		document.calculatorForm.txtPenBenefits.value = "5"

	if (document.calculatorForm.txtWksVacation.value == "")
		document.calculatorForm.txtWksVacation.value = "2"

	if (document.calculatorForm.txtCompIns.value == "")
		document.calculatorForm.txtCompIns.value = "15"

	if (document.calculatorForm.txtOverhead.value == "")
		document.calculatorForm.txtOverhead.value = "20"

	if (document.calculatorForm.txtPayroll.value == "")
		document.calculatorForm.txtPayroll.value = "100.00"

	if (document.calculatorForm.txtBookWeek.value == "")
		document.calculatorForm.txtBookWeek.value = "2"

	if (document.calculatorForm.txtTimeWorth.value == "")
		document.calculatorForm.txtTimeWorth.value = "100.00"

	if (document.calculatorForm.txtHrsHiring.value == "")
		document.calculatorForm.txtHrsHiring.value = "25"

	if (document.calculatorForm.txtCpaFees.value == "")
		document.calculatorForm.txtCpaFees.value = "300.00"

	//if (document.calculatorForm.txtOSIFee.value == "")
		//document.calculatorForm.txtOSIFee.value = "75.00"

	/*
	if (document.calculatorForm.txtNumCustInvoices.value == "")
		document.calculatorForm.txtNumCustInvoices.value = "38"

	if (document.calculatorForm.txtNumVendInvoices.value == "")
		document.calculatorForm.txtNumVendInvoices.value = "88"

	if(document.calculatorForm.txtNumEmployees.value == "")
		document.calculatorForm.txtNumEmployees.value = "8"

	if (document.calculatorForm.txtCurrentTotalMonthlyCost1.value == "")
		document.calculatorForm.txtCurrentTotalMonthlyCost1.value = "3,654.67"

	if (document.calculatorForm.txtEstBYBFee1.value == "")
		document.calculatorForm.txtEstBYBFee1.value = "2,257.50"
	*/
}

// formatting routine
function formatDollar(number) {
	if (number != 0) {
		var myNumber = new NumberFormat(number);
		myNumber.setCommas(true);
		myNumber.setPlaces(2);
		myNumber.setCurrencyPrefix("")
		return myNumber.toFormatted()
	} else {
		nullValue = ""
		return nullValue
	}
}

function formatDollarSign(number) {
	if (number != 0) {
		var myNumber = new NumberFormat(number);
		myNumber.setCommas(true);
		myNumber.setPlaces(2);
		myNumber.setCurrencyPrefix("$")
		return myNumber.toFormatted()
	} else {
		nullValue = ""
		return nullValue
	}
}

/*
 * NumberFormat -The constructor
 * num - The number to be formatted
 */
function NumberFormat(num) {
	// member variables
	this.num;
	this.isCommas;
	this.isCurrency;
	this.currencyPrefix;
	this.places;

	// external methods
	this.setNumber = setNumberNF;
	this.toUnformatted = toUnformattedNF;
	this.setCommas = setCommasNF;
	this.setCurrency = setCurrencyNF;
	this.setCurrencyPrefix = setCurrencyPrefixNF;
	this.setPlaces = setPlacesNF;
	this.toFormatted = toFormattedNF;

	// internal methods
	this.getRounded = getRoundedNF;
	this.preserveZeros = preserveZerosNF;

	// setup defaults
	this.setNumber((num==null) ? 0 : num);
	this.setCommas(true);
	this.setCurrency(true);
	this.setCurrencyPrefix('$');
	this.setPlaces(2);
}

/*
 * setNumber - Sets the number
 * num - The number to be formatted
 */
function setNumberNF(num) {
	this.num = num;
}

/*
 * toUnformatted - Returns the number as is (a number)
 */
function toUnformattedNF() {
	return (this.num);
}

/*
 * setCommas - Sets a switch that indicates if there should be commas
 * isC - true, if should be commas; false, if no commas
 */
function setCommasNF(isC) {
	this.isCommas = isC;
}

/*
 * setCurrency - Sets a switch that indicates if should be displayed as currency
 * isC - true, if should be currency; false, if not currency
 */
function setCurrencyNF(isC) {
	this.isCurrency = isC;
}

/*
 * setCurrencyPrefix - Sets the symbol that precedes currency.
 * cp - The symbol
 */
function setCurrencyPrefixNF(cp) {
	this.currencyPrefix = cp;
}

/*
 * setPlaces - Sets the precision of decimal places
 * p - The number of places. Any number of places less than or equal to zero is considered zero.
 */
function setPlacesNF(p) {
	this.places = p;
}

/*
 * toFormatted - Returns the number formatted according to the settings (a string)
 */
function toFormattedNF() {
	var pos;
	var nNum = this.num; // v1.0.1 - number as a number
	var nStr;            // v1.0.1 - number as a string

	// round decimal places
	nNum = this.getRounded(nNum);
	nStr = this.preserveZeros(Math.abs(nNum)); // this step makes nNum into a string. v1.0.1 Math.abs

	if (this.isCommas)
	{
		pos = nStr.indexOf('.');
		if (pos == -1)
		{
			pos = nStr.length;
		}
		while (pos > 0)
		{
			pos -= 3;
			if (pos <= 0) break;
			nStr = nStr.substring(0,pos) + ',' + nStr.substring(pos, nStr.length);
		}
	}
	
	nStr = (nNum < 0) ? '-' + nStr : nStr; // v1.0.1

	if (this.isCurrency)
	{
		// add dollar sign in front
		nStr = this.currencyPrefix + nStr;
	}

	return (nStr);
}

/*
 * getRounded - Used internally to round a value
 * val - The number to be rounded
 */
function getRoundedNF(val) {
	var factor;
	var i;

	// round to a certain precision
	factor = 1;
	for (i=0; i<this.places; i++)
	{	factor *= 10; }
	val *= factor;
	val = Math.round(val);
	val /= factor;

	return (val);
}

/*
 * preserveZeros - Used internally to make the number a string
 * 	that preserves zeros at the end of the number
 * val - The number
 */
function preserveZerosNF(val) {
	var i;

	// make a string - to preserve the zeros at the end
	val = val + '';
	if (this.places <= 0) return val; // leave now. no zeros are necessary - v1.0.1 less than or equal
	
	var decimalPos = val.indexOf('.');
	if (decimalPos == -1)
	{
		val += '.';
		for (i=0; i<this.places; i++)
		{
			val += '0';
		}
	}
	else
	{
		var actualDecimals = (val.length - 1) - decimalPos;
		var difference = this.places - actualDecimals;
		for (i=0; i<difference; i++)
		{
			val += '0';
		}
	}
	
	return val;
}