function calcCOIN(did, property, loss, deduct, cutoff, target, target2) {
	// turn percentage into decimal
	if (cutoff >= 1) { cutoff = cutoff/100; }
	
	var should = property * cutoff;
	var payout = ((did - should) < 0) ? ((did / should) * loss) - deduct : loss - deduct;
	if (payout > did) { payout = did; }
	
	var message;
	if ((did - should) < 0) {
		message = "Coinsurance requirement was not met.";
	} else {
		message = "Coinsurance requirement met.";
	}
	
	setDivText(target, message);
	
	var curPayout = new Number(payout).toFixed(2);
	var prcPayout = new Number((curPayout / (loss - deduct)) * 100).toFixed(2);
	setDivText(target2, "Amount Payable:  $" + curPayout + " (" + prcPayout + "%)");
}

function calcBAC(oz, prcAlc, weight, time, target, drunk, notdrunk, waynotdrunk, always) {
	var pBAC = Math.max((oz * prcAlc * 0.075) / weight - (time * 0.015), 0.0);
	
	if (target.hasChildNodes()) { 
		target.replaceChild(document.createTextNode("This person's blood alcohol content is " + (new Number(pBAC)).toPrecision(3) + "%."), target.firstChild);
	 } else { 
		target.appendChild(document.createTextNode("This person's blood alcohol content is " + (new Number(pBAC)).toPrecision(3) + "%."));
	}
	
	always.style.display = "block";
	if (pBAC == 0.000) {
		drunk.style.display = "none";
		notdrunk.style.display = "none";
		waynotdrunk.style.display = "block";
	} else if (pBAC < .08) {
		drunk.style.display = "none";
		notdrunk.style.display = "block";
		waynotdrunk.style.display = "none";
	} else {
		drunk.style.display = "block";
		notdrunk.style.display = "none";
		waynotdrunk.style.display = "none";
	}
}

function calcVOM(amt, intr, years, present, future, target){
	if ((amt.value == "") || (amt.value <= 0)) { 
		alert("Please enter a non-negative, non-zero value in the Amount field.");
		amt.select();
		return false;
	}
	if ((intr.value == "") || (intr.value <= 0)) {
		alert("Please enter a non-negative, non-zero value in the Interest Rate field.");
		intr.select();
		return false;
	}
	if ((years.value == "") || (years.value <= 0)) {
		alert("Please enter a non-negative, non-zero value in the Number of Years field.");
		years.select();
		return false;
	}
	if (!(present.checked || future.checked)) {
		alert("Please select either a Present Value or Future Value calculation.");
		return false;
	}
	
	if (present.checked) {
		target.replaceChild(document.createTextNode("The "+present.value+" is "+(new Number(amt.value / Math.pow((1+(intr.value/100)),years.value))).toFixed(2)), target.firstChild);
	} else {
		target.replaceChild(document.createTextNode("The "+future.value+" is "+(new Number(amt.value * Math.pow((1+(intr.value/100)),years.value))).toFixed(2)), target.firstChild);
	}
}

function setDivText(target, text) {
	if (target.hasChildNodes()) { 
		target.replaceChild(document.createTextNode(text), target.firstChild);
	 } else { 
		target.appendChild(document.createTextNode(text));
	}
}