//<script>
function Calc(whichElement) {	var f = whichElement.form	var InitialValue = whichElement.value		//alert(whichElement.name)	var EstimatedDayUses = f.EstimatedDayUses	var NightUsers = f.NightUsers	var DayUsers = f.DayUsers	var AnnualGrowth = f.AnnualGrowth	var HowLong = f.HowLong	var CalcLoad = f.CalcLoad	var FinalSize = f.FinalSize	var Microflush = f.Microflush	var NonFlush = f.NonFlush	var MaxPeriod = f.MaxPeriod	var MinSizeMicroFlush = f.MinSizeMicroFlush	var MinSizeNonFlush = f.MinSizeNonFlush		var MicroFlushFactor = 3.5	var NonFlushFactor = 1.2		var MicroFlushRating = ""	var NonFlushRating = ""	var MFLitres = ""	var NFLitres = ""	var SystemRating	var DayAndNight	
	if (whichElement == EstimatedDayUses && (whichElement.value != "" && Number(whichElement.value) != 0 ) ) {		//Disable NightUsers & DayUsers if you are using EstimatedDayUses
		DisableField(NightUsers)
		DisableField(DayUsers)	} else if (whichElement == EstimatedDayUses && Number(whichElement.value) == 0 ) {		//Re-enable NightUsers & DayUsers		EnableField(NightUsers)
		EnableField(DayUsers)	} else if ((whichElement == NightUsers || whichElement == DayUsers) && whichElement.value != "" && Number(whichElement.value) != 0 ) {		//Disable EstimatedDayUses if you are using NightUsers or DayUsers
		DisableField(EstimatedDayUses)	} else if ((whichElement == NightUsers || whichElement == DayUsers) && (Number(NightUsers.value) == 0 && Number(DayUsers.value) == 0) ) {		//Re-enable EstimatedDayUses		EnableField(EstimatedDayUses)
			} 
		var ActualCalcLoadOverride = (whichElement.name == "CalcLoad" || (NightUsers.value == "" && DayUsers.value == "")) && (!isNaN(CalcLoad.value) && CalcLoad.value != "" && CalcLoad.value != "0")	//Note: ActualCalcLoadOverride is used to determine whether the value in this field shoul be use to calculate the final system rating.		//alert(NightUsers.value == "" )	//alert(DayUsers.value == "" )	//alert(!isNaN(CalcLoad.value) && CalcLoad.value != "" && CalcLoad.value != "0" )	//alert("ActualCalcLoadOverride=" + ActualCalcLoadOverride)
		var DayUserAdj = DayUsers.value * 2 / 3.5	DayAndNight = Number(NightUsers.value) + DayUserAdj
	//alert("DayAndNight = " + DayAndNight )
		if (Number(EstimatedDayUses.value) > 0) {		DayAndNight =  Number(EstimatedDayUses.value) / 3.5 * 1.25
		SystemRating = DayAndNight	} else {		SystemRating = DayAndNight * 1.25 //* Math.pow((AnnualGrowth.value * 0.01 + 1), HowLong.value)	}
	SystemRating = SystemRating * Math.pow((AnnualGrowth.value * 0.01 + 1), HowLong.value)		var ValueHasChanged = false	if (Math.round(SystemRating) != InitialValue) ValueHasChanged = true 			//alert("SystemRating = " + SystemRating)	if (ActualCalcLoadOverride) {		//alert("1")		var ActualCalcLoad = CalcLoad.value		var SystemRating = GetRating(ActualCalcLoad)	} else {		//alert("2")		var ActualCalcLoad = SystemRating			}	//alert("ActualCalcLoad="+ActualCalcLoad)		var IsTooGreat = ActualCalcLoad > 300	SystemRating = GetRating(ActualCalcLoad)		if (IsTooGreat) {		//alert("A")	} else {		//alert("B")		var MicroFlushRating = Math.round(SystemRating * MicroFlushFactor)		var NonFlushRating = Math.round(SystemRating * NonFlushFactor)		var MaxPeriodValue = ""				if (!isNaN(MaxPeriod.value) && MaxPeriod.value != "") {			MaxPeriodValue = Number(MaxPeriod.value)			MFLitres = GetHoldingTankSize(MaxPeriodValue * MicroFlushRating)			NFLitres = GetHoldingTankSize(MaxPeriodValue * NonFlushRating)		}	}			if ((NightUsers.value != "" || DayUsers.value != "" || CalcLoad.value != "" ) ) {		//alert("D")		if (ActualCalcLoadOverride && ValueHasChanged) {			NightUsers.value = ""			DayUsers.value = ""		} else {			CalcLoad.value = Math.round(ActualCalcLoad)		}					FinalSize.value = SystemRating		Microflush.value = MicroFlushRating		NonFlush.value = NonFlushRating					MinSizeMicroFlush.value = MFLitres		MinSizeNonFlush.value = NFLitres			} else {		//alert("E")		CalcLoad.value = "0"		FinalSize.value = "0"		Microflush.value = "0"		NonFlush.value = "0"		MinSizeMicroFlush.value = "0"		MinSizeNonFlush.value = "0"		//NightUsers.focus()	}//	alert ("SystemRating = " + SystemRating)//	alert("MicroFlushRating = " + MicroFlushRating)//	alert("NonFlushRating = " + NonFlushRating)	if (!isNaN(whichElement.value) && whichElement.value != "") whichElement.value = Number(whichElement.value)
		//HandleKeyPress()
	
	return false}function GetRating(v) {	var r	v = Number(v)	if (v == 0) {		r = 0	} else if (Math.max(v,6) == 6){		r = 6	} else if (Math.max(v,10)==10) {		r = 10	} else if (Math.max(v,25)==25) {		r = 25	} else if (Math.max(v,50)==50) {		r = 50	} else if (Math.max(v,75)==75) {		r = 75	} else if (Math.max(v,100)==100){		r = 100	} else if (Math.max(v,125)==125){		r = 125	} else if (Math.max(v,150)==150) {		r = 150	} else if (Math.max(v,175)==175){		r = 175	} else if (Math.max(v,200)==200){		r = 200	} else if (Math.max(v,225)==225){		r = 225	} else if (Math.max(v,250)==250){		r = 250	} else if (Math.max(v,275)==275){		r = 275	} else if (Math.max(v,300)==300){		r = 300	} else if (v > 300) {		r = "> 300"	}	return r}function GetHoldingTankSize(v) {	var r	v = Number(v)	if (Math.max(v,200) == 200){		r = 200	} else if (Math.max(v,600)== 600) {		r = 600	} else if (Math.max(v,1000)==1000) {		r = 1000	} else if (Math.max(v,2500)==2500) {		r = 2500	} else if (Math.max(v,5500)==5500) {		r = 5500	} else if (v > 5500) {		r = "See Note"	} 	return r}function PrintFriendly(b) {	if (b.name == "PrintFriendlyButton") {		var f = document.CalcForm		f.method = "POST"		f.action = "hts_calc_print.asp"		f.target = "_blank"		f.submit()	}	return false}function HandleKeyPress(){	if (document.activeElement) {		var AE = document.activeElement
				switch (event.keyCode) {			case 13 :				if (AE.type && AE.type.toUpperCase() != "TEXTAREA") {					event.returnValue=false;					var f = document.CalcForm					//var ElementFound = false					var nextAvailableField = ""
					for (var i = 0; i < f.elements.length; i++) {						
						if (f.elements[i] == AE) {							//move cursor to next available field							//alert("match : " + f.elements[i].name)							//break;
							for (var j = i; j < f.elements.length; j++ ) {								//search for the next selectable field
																//alert(f.elements[j].name)								
								if (!f.elements[j].disabled && f.elements[j].focus) {									
									nextAvailableField = f.elements[j]									alert(nextAvailableField.name)																		if (nextAvailableField != "" && !nextAvailableField.disabled && nextAvailableField.focus && nextAvailableField.select) {
										nextAvailableField.focus()										nextAvailableField.select()										
									}
																		break;
								}
								
								//if (nextAvailableField != "" ) break;							}							break;						}
						
						//if (nextAvailableField != "" ) break;					}					//DoSearch();					//alert()					//break				}			default:				break		}	}
	return false}
function DisableField (whichElement) {
	whichElement.disabled = true	whichElement.value = "Unused"	//if (whichElement.form.activeElement == whichElement) {			//}
}

function EnableField (whichElement) {
	whichElement.disabled = false	whichElement.value = ""
}
//document.onkeypress=HandleKeyPress;
