// Converts amount to a formatted string with leading dollar sign
// and rounded to 2 decimal places
// Copyright 1998-2005 Millennia Logix, Inc by Paul F Johnson
function Round2DollarsOld(amount) {
	var dollars = "$"+Math.floor(amount)+".";
	var cents = 100*(amount-Math.floor(amount))+0.5;
	result = dollars + Math.floor(cents/10) + Math.floor(cents%10);
	return result;
}

// Converts amount to a formatted string with leading dollar sign
// and rounded to 2 decimal places
// Copyright 2005 Millennia Logix, Inc by John B Lisle, john@milogix.com
function Round2Dollars(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '- '; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + "$" + s;
	return s;
}


// Converts amount to a formatted string with leading dollar sign
// and rounded up to 2 decimal places
// Copyright 2005 Millennia Logix, Inc by John B Lisle, john@milogix.com
function Round2DollarsUp(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '- '; }
	i = Math.abs(i);
	var dincr = 1;
	if (parseInt((i*1000)%10) == 0) { dincr = 0 };
	i = parseInt(i * 100) + dincr;
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + "$" + s;
	return s;
}

// Converts amount to a number and rounded up to 2 decimal places
// Copyright Millennia Logix, Inc by John B Lisle, john@milogix.com
function Round2Up(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = 1;
	if(i < 0) { minus = -1; }
	i = Math.abs(i);
	var dincr = 1;
	if (parseInt((i*1000)%10) == 0) { dincr = 0 };
	i = parseInt(i * 100) + dincr;
	i = minus * (i / 100);
	return i;
}

// Converts amount to a formatted string with leading dollar sign
// and rounded to nearest five dollars
// Copyright Millennia Logix, Inc by Paul F Johnson 
function Round2Five(amount) {
	var Amt10 = Math.floor((amount/10)) * 10;
	var Remainder = amount - Amt10;
	var Near5 = 0;
 	if (Remainder >= 7.5) {
		Near5 = 10;
	}
	else if (Remainder >= 2.5) {
		Near5 = 5;
	}
	result = "$"+(Amt10 + Near5)+".00";
	return result;
}

// Converts amount to a formatted string with leading dollar sign
// and rounded to nearest five dollars and takes final amount and formats 
// amounts greater than $9999 with commas.
// Copyright 2005 Millennia Logix, Inc by John B Lisle, john@milogix.com
function Round2FiveComma(amount) {
	var Amt10 = Math.floor((amount/10)) * 10;
	var Remainder = amount - Amt10;
	var Near5 = 0;
 	if (Remainder >= 7.5) {
		Near5 = 10;
	}
	else if (Remainder >= 2.5) {
		Near5 = 5;
	}
	adjAmount = Amt10 + Near5 + ""
	lenAmount = adjAmount.length
	adjAmountComma = ""
	adjAmountLeft = adjAmount
	if (lenAmount > 4) {
		for (var iLen = 1 ; lenAmount > 3 ; iLen++) {
			adjAmountComma =  "," + adjAmountLeft.substring(lenAmount-3,lenAmount) + adjAmountComma
			lenAmount = lenAmount - 3		
			adjAmountLeft = adjAmountLeft.substring(0,lenAmount)
			}

//		alert ("ok. length = " + lenAmount + "*" + adjAmountComma + "*" + adjAmountLeft)
		adjAmountComma = adjAmountLeft + adjAmountComma
		}
	if (adjAmountComma == "") { adjAmountComma = adjAmount }
	result = "$"+(adjAmountComma)+".00";
	return result;
}

// Converts amount to a formatted string with NO leading dollar sign
// and rounded to 2 decimal places
// Copyright 1998 Millennia Logix, Inc by Paul F Johnson pfj@msi-web.com
function Round2(amount) {
	var dollars = Math.floor(amount)+".";
	var cents = 100*(amount-Math.floor(amount))+0.5;
	result = dollars + Math.floor(cents/10) + Math.floor(cents%10);
	return result;
}

// Converts amount to a formatted string with NO leading dollar sign
// and rounded up to 2 decimal places
// Copyright 2005 Millennia Logix, Inc by John B Lisle, john@milogix.com
function Round2up(amount) {
	var dollars = Math.floor(amount)+".";
	var cents = 100*(amount-Math.floor(amount))+0.5;
	result = dollars + Math.floor(cents/10) + Math.ceil(cents%10);
	return result;
}

// Calculate estimated taxes based on MA average formula
// Formula is currently 3% of purchase price of house
function calcEstTaxes() {
	var rRate = 2.50;
	var rEstTax = (document.forms[0].PurchPrice.value) * rRate / 100;
	document.forms[0].Taxes.value = Math.round(rEstTax);
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

