/*================================================================
	Ravello Software Duration Estimator
 	version:1.0
 	Copyright 2008 by Ravello Software LLC
	
================================================================*/

function duration() {
	//fetch values
	var doc = document;
	var h = doc.getElementById("hCost").value;
	var s = doc.getElementById("sCost").value;
	var r = doc.getElementById("cRate").value;
	
	
	//compute duration 
	var rv = Math.log(1 + (h / s)) / Math.log(1 + (r / 100));
	
	//check result for a good number
	if(!isNaN(rv) &&
		(rv != Number.POSITIVE_INFINITY) &&
		(rv != Number.NEGATIVE_INFINITY))
	{
		document.getElementById("durResult").value =  Math.round(rv * Math.pow(10,2)) / Math.pow(10,2); 	
	}
	//otherwise, the input was proabably bad so return an empty value
	else
	{
		document.getElementById("durResult").innerText = "error";
	}
}

