/*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(){
	
	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 = 0;
	var xshipping = 0;
	
	var xcotaxrate = 0;
	var xdentaxrate = 0;
	
	
	if( window.document.form1.dentaxnum.checked ){
		xdentaxrate = 0;
	} else {
		xdentaxrate = .035;
	}

	
	
	if( window.document.form1.product[0].checked ){
		xsubtotal = xsubtotal + 15;
		xshipping = 2;
	}

	if( window.document.form1.product[1].checked ){
		xsubtotal = xsubtotal + 15;
		xshipping = xshipping + 2;
	}
	


	
	if( cotaxnum == "" || ! isInt( cotaxnum.substr(0,1))) {
		var xcotaxrate = .041;
	} else {
		var xcotaxrate = 0;
	}


	var xtax = ((xsubtotal+xshipping)*xcotaxrate)+((xsubtotal+xshipping)*xdentaxrate);

	var xtotal = xsubtotal+xtax+xshipping;

	window.document.form1.subtotal.value = xsubtotal.toFixed(2);
	window.document.form1.shipping.value = xshipping.toFixed(2);
	window.document.form1.tax.value = xtax.toFixed(2);
	window.document.form1.total.value = xtotal.toFixed(2);
}