//
function SetCalc()
{
	SetNumeric();
	ConvertToM3();
	ConvertToLineal();
	ConvertLogToM3();
	ConvertLinealCost();
}
function ConvertToM3()
{
	var cl = document.getElementById("_txtCostLineal").value;
	var l = document.getElementById("txtLength").value;
	var w = document.getElementById("txtWidth").value;
	var t = document.getElementById("txtThick").value;
	var linealMetresInM3 = 1000000 / (w * t);
	var m3 = Mill3ToMetre3(l*w*t);
	var cm3 = cl * linealMetresInM3;
	var totalCost = cl * (l / 1000);
	document.getElementById("spnLinealToM3").innerHTML = RoundTo(m3, 3) +" m&sup3; @ £"+ cm3.toFixed(2) +" / m&sup3; = £"+ totalCost.toFixed(2);
    document.getElementById("spnLinealToM3Exp").innerHTML = RoundTo(linealMetresInM3, 3) +" lineal metres of "+ w +" &times; "+ t +" = 1m&sup3;";
}
function ConvertToLineal()
{
	var cm3 = parseInt(document.getElementById("_txtCostM3").value);
	var m3 = document.getElementById("_txtM3").value * 1000000000; // in mm3
	var w = document.getElementById("txtWidth2").value;
	var t = document.getElementById("txtThick2").value;
	var linealMetresInM3 = 1000000 / (w * t);
	var lm = (m3) / (w*t);
	var clm = cm3 / linealMetresInM3;
	var totalCost = cm3 * document.getElementById("_txtM3").value;
	document.getElementById("spnM3ToLineal").innerHTML = RoundTo((lm/1000), 3) +" metres @ £"+ clm.toFixed(2) +" / metre = £"+ totalCost.toFixed(2);
	document.getElementById("spnM3ToLinealExp").innerHTML = "1m&sup3; of "+ w +" &times; "+ t +" = "+ RoundTo(linealMetresInM3, 3) +" lineal metres";
}
function ConvertLinealCost()
{
	var cm3 = parseInt(document.getElementById("_txtCostLC").value);
	var l = document.getElementById("txtLengthLC").value;
	var w = document.getElementById("txtDepthLC").value;
	var t = document.getElementById("txtThickLC").value;
	var m3 = Mill3ToMetre3(l*w*t);
	var totalCost = m3 * cm3;
	document.getElementById("spnLinealCost").innerHTML = RoundTo((l/1000), 3) +" lineal metres of "+ w +" x "+ t +" = "+ m3.toFixed(2) +"m&sup3;";
    document.getElementById("spnLinealCost2").innerHTML = RoundTo(m3, 3) +" m&sup3; @ £"+ cm3.toFixed(2) +"/m&sup3; = £"+ totalCost.toFixed(2);
}
function ConvertLogToM3()
{
	var l = document.getElementById("txtLogLength").value;
	var d = document.getElementById("txtLogGirthOrDiameter").value;
	if (document.getElementById("ddLogVolType").value == "Diameter")
	{
	    document.getElementById("spnLogVolAlt").innerHTML = "Girth";
	    var circ = Math.PI * d;
        document.getElementById("spnLogGirthOrDiameter").innerHTML = Math.round(circ) +" mm";
	}
	else 
	{
	    d = d / Math.PI;
	    document.getElementById("spnLogVolAlt").innerHTML = "Diameter";
        document.getElementById("spnLogGirthOrDiameter").innerHTML = Math.round(d) +" mm";
	}
	var area = Math.PI * Math.pow((d/2), 2);
	document.getElementById("spnLogToM3").innerHTML = RoundTo(Mill3ToMetre3(l*area), 3) +" m&sup3;";
}
function Mill3ToMetre3(mm)
{
	return mm/1000000000;
}
function RoundTo(val, places)
{
    places = Math.pow(10, places);
    d = Math.round(val * places) / places;
    return d;
}