/*Javascript for Salary Survey */

function formatCurrency(strValue)
{

	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + dblValue + '.' + strCents);
}

function isInt(x) {
	var intValue = parseInt(x);
	if (isNaN(x)) {
		return false;
	} else {
		return true;
	}
}

function UpdateCharge(price){
	
	var cotaxnum = window.document.form1.cotaxnum.value;
	var dentaxnum = window.document.form1.dentaxnum.value;
	var xcity = window.document.form1.city.value;
	var xzip = window.document.form1.zip.value;
	
	var xsubtotal = price;
	
	if( xsubtotal == 0 ){
		xsubtotal = parseFloat(window.document.form1.subtotal.value);
	}
	
	var xshipping = 0;
	
	var xcotaxrate = 0;
	var xdentaxrate = 0;
	
	
	if( window.document.form1.dentaxnum.checked ){
		xdentaxrate = 0;
	} else {
		xdentaxrate = .035;
	}


	
	if( cotaxnum == "" || ! isInt( cotaxnum.substr(0,1))) {
		var xcotaxrate = .041;
	} else {
		var xcotaxrate = 0;
	}


	var xtax = (xsubtotal*xcotaxrate)+(xsubtotal*xdentaxrate);

	var xtotal = xsubtotal+xtax;

	window.document.form1.subtotal.value = xsubtotal.toFixed(2);
	window.document.form1.tax.value = xtax.toFixed(2);
	window.document.form1.total.value = xtotal.toFixed(2);
}