//This Script is copyright 2003 www.starsnsites.com
	
	function displayVal(n) {
		var x = Math.round(n * 10.0);
		return x / 10.0;
	}

	function isNumeric(sText) {
		//Determine whether a string is numeric copyright 2003 www.starsnsites.com
		
	   var ValidChars = "0123456789.";
   	var IsNumber=true;
   	var Char;
	
 		if(sText.length == 0) {
 			return false;
 		}
 		
   	for (i = 0; i < sText.length && IsNumber == true; i++) 
   	   { 
   	   Char = sText.charAt(i); 
   	   if (ValidChars.indexOf(Char) == -1) 
   	      {
   	      IsNumber = false;
   	      }
   	   }
   	return IsNumber;
   
   }
	

	function typeVisible() {
		var calcType;
		var e;
		
		with(document.pondCalculator) {
			//Determine type of pond requested copyright 2003 www.starsnsites.com
			if(pondType[0].checked) {
				calcType = "Rectangular";
			} else {
				calcType = "Oval";
			}
			//Retrieve span element for radius copyright 2004 www.starsnsites.com
			
			e = document.getElementById('radius');
			
			//Set visibility according to type of pond copyright 2003 www.starsnsites.com
			if(calcType == "Oval") {
				e.style.visibility = "visible";
			} else {
				e.style.visibility = "hidden";
			}
		}
	}
	
	function calculatePond() {
		//Perform the pond calculations copyright 2003.5 www.starsnsites.com
		
		var calcType = '';
		var nLength = 0.0;
		var nWidth = 0.0;
		var nAvgDepth = 0.0;
		var nMaxDepth = 0.0;
		var nRadius = 0.0;
		var nVolumeUS = 0.0;
		var nVolumeUK = 0.0;
		var nArea = 0.0;
		var nLinerWidth = 0.0;
		var nLinerLength = 0.0;
		var nUSPumpSize = 0.0;
		var nUKPumpSize = 0.0;
		var nTurnover = 0.0;
		var nMarginalStock = 0.0;
		var nIdealStock = 0.0;
		
		with(document.pondCalculator) {
			//Determine type of pond requested copyright 2003 www.starsnsites.com
			if(pondType[0].checked) {
				calcType = "Rectangular";
			} else {
				calcType = "Oval";
			}

			if(isNumeric(pondLength.value) == false) {
				alert("Please enter numeric value.");
				pondLength.focus();
				return;
			}
			if(isNumeric(pondWidth.value) == false) {
				alert("Please enter numeric value.");
				pondWidth.focus();
				return;
			}
			if(calcType == 'Oval' && isNumeric(pondRadius.value) == false) {
				alert("Please enter numeric value.");
				pondRadius.focus();
				return;
			}
			if(isNumeric(pondMaxDepth.value) == false) {
				alert("Please enter numeric value.");
				pondMaxDepth.focus();
				return;
			}
			if(isNumeric(pondAvgDepth.value) == false) {
				alert("Please enter numeric value.");
				pondAvgDepth.focus();
				return;
			}
			if(isNumeric(turnover.value) == false) {
				turnover.value = "1.5";
			}
			
			//Retrieve the values copyright 2003 www.starsnsites.com
			nWidth = parseFloat(pondWidth.value);
			nLength = parseFloat(pondLength.value);
			nMaxDepth = parseFloat(pondMaxDepth.value);
			nAvgDepth = parseFloat(pondAvgDepth.value);
			if(calcType == 'Oval') {
				nRadius = parseFloat(pondRadius.value);
			}
			nTurnover = parseFloat(turnover.value);
			
			nArea = (nWidth * nLength) + (nRadius * nRadius * Math.PI);
			surfaceArea.value = displayVal(nArea);
			nVolumeUK = nArea * nAvgDepth * 6.23;
			nVolumeUS = nVolumeUK * 1.201;
			ukVolume.value = displayVal(nVolumeUK);
			usVolume.value = displayVal(nVolumeUS);
			
			//Liner size copyright 2003 www.starsnsites.com
			nLinerLength = (nLength + nRadius) + (2 * nMaxDepth + 4);
			nLinerWidth = (nWidth + nRadius) + (2 * nMaxDepth + 4);
			linerHeight.value = displayVal(nLinerLength);
			linerWidth.value = displayVal(nLinerWidth);
			
			//Pump size copyright 2003 www.starsnsites.com
			nUSPumpSize = (nVolumeUS / nTurnover);
			nUKPumpSize = (nVolumeUK / nTurnover);
			usPump.value = displayVal(nUSPumpSize);
			ukPump.value = displayVal(nUKPumpSize);
			
			//Stock size copyright 2003 www.starsnsites.com
			nIdealStock = Math.sqrt(((nVolumeUS / 20.0) * 231.0) / 2.0);
			nMarginalStock = Math.sqrt(((nVolumeUK / 10.0) * 231.0) / 2.0);
			idealStock.value = Math.round(nIdealStock);
			marginalStock.value = Math.round(nMarginalStock);
		}
	}
//Aquarium Calculations copyright 2003 www.starsnsites.com

function gallons(f) {
    f.USgallons.value = f.Length.value * f.Width.value * f.Height.value / 2.31;
    f.USgallons.value = Math.round(f.USgallons.value) / 100.0;
    f.UKgallons.value = f.Length.value * f.Width.value * f.Height.value / 2.7742;
    f.UKgallons.value = Math.round(f.UKgallons.value) / 100.0;
    
    f.Length1.value = f.Length.value * 254;
    f.Length1.value = Math.round(f.Length1.value) / 100;
    f.Width1.value = f.Width.value * 254;
    f.Width1.value = Math.round(f.Width1.value) / 100;
    f.Height1.value = f.Height.value * 254;
    f.Height1.value = Math.round(f.Height1.value) / 100;
    f.Liters.value = f.Length1.value * f.Width1.value * f.Height1.value / 10;
    f.Liters.value = Math.round(f.Liters.value) / 100;
}
function liter_volume(f) {
    f.Length.value = f.Length1.value / .0254;
    f.Length.value = Math.round(f.Length.value) / 100;
    f.Width.value = f.Width1.value / .0254;
    f.Width.value = Math.round(f.Width.value) / 100;
    f.Height.value = f.Height1.value / .0254;
    f.Height.value = Math.round(f.Height.value) / 100;
    f.Liters.value = f.Length1.value * f.Width1.value * f.Height1.value / 10;
    f.Liters.value = Math.round(f.Liters.value) / 100;
    f.USgallons.value = f.Length.value * f.Width.value * f.Height.value / 2.31;
    f.USgallons.value = Math.round(f.USgallons.value) / 100.0;
    f.UKgallons.value = f.Length.value * f.Width.value * f.Height.value / 2.7742;
    f.UKgallons.value = Math.round(f.UKgallons.value) / 100.0;
}    
function circular_gallons(f) {
    f.USgallons.value = (f.Diameter.value/2)* (f.Diameter.value/2) * Math.PI * f.Height.value / 2.31;
    f.USgallons.value = Math.round(f.USgallons.value) / 100;
    f.UKgallons.value = f.USgallons.value * 83.3;
    f.UKgallons.value = Math.round(f.UKgallons.value) / 100;

    f.Diameter1.value = f.Diameter.value * 254.0;
    f.Height1.value = f.Height.value * 254.0;
    f.Liters.value = (f.Diameter1.value/2) * (f.Diameter1.value/2) * Math.PI * f.Height1.value / 10000000;
    f.Liters.value = Math.round(f.Liters.value) / 100;
    
    f.Diameter1.value = Math.round(f.Diameter1.value) / 100;
    f.Height1.value = Math.round(f.Height1.value) / 100;
}
function circular_liters(f) {
    f.Liters.value = (f.Diameter1.value/2) * (f.Diameter1.value/2) * Math.PI * f.Height1.value / 10;
    f.Liters.value = Math.round(f.Liters.value) / 100;
    
    f.Diameter.value = f.Diameter1.value / .0254;
    f.Height.value = f.Height1.value / .0254;

    f.USgallons.value = (f.Diameter.value/2) * (f.Diameter.value/2) * Math.PI * f.Height.value / 2310000;
    f.USgallons.value = Math.round(f.USgallons.value) / 100.0;
    f.UKgallons.value = (f.Diameter.value/2) * (f.Diameter.value/2) * Math.PI * f.Height.value / 2774200;
    f.UKgallons.value = Math.round(f.UKgallons.value) / 100.0;
    
    f.Diameter.value = Math.round(f.Diameter.value) / 100;
    f.Height.value = Math.round(f.Height.value) / 100;

}    
function hex_gallons(f) {
    f.USgallons.value = (f.Width.value)* (f.Width.value/2) * (f.NumSides.value) * f.Height.value / 2.31;
    f.UKgallons.value = f.USgallons.value * .833;
    f.USgallons.value = Math.round(f.USgallons.value) / 100;
    f.UKgallons.value = Math.round(f.UKgallons.value) / 100;

    f.Width1.value = f.Width.value * 254.0;
    f.Height1.value = f.Height.value * 254.0;
    f.NumSides1.value = f.NumSides.value;
    f.Liters.value = (f.Width1.value) * (f.Width1.value/2) * f.NumSides1.value * f.Height1.value / 10000000;
    f.Liters.value = Math.round(f.Liters.value) / 100;
    
    f.Width1.value = Math.round(f.Width1.value) / 100;
    f.Height1.value = Math.round(f.Height1.value) / 100;
}
function hex_liters(f) {
    f.Liters.value = (f.Width1.value) * (f.Width1.value/2) * f.NumSides1.value * f.Height1.value / 10;
    f.Liters.value = Math.round(f.Liters.value) / 100;
    
    f.Width.value = f.Width1.value / .0254;
    f.Height.value = f.Height1.value / .0254;
    f.NumSides1.value = f.NumSides.value;

    f.USgallons.value = (f.Width.value) * (f.Width.value/2) * f.NumSides.value * f.Height.value / 2310000;
    f.USgallons.value = Math.round(f.USgallons.value) / 100.0;
    f.UKgallons.value = (f.Width.value) * (f.Width.value/2) * f.NumSides.value * f.Height.value / 2774200;
    f.UKgallons.value = Math.round(f.UKgallons.value) / 100.0;
    
    f.Width.value = Math.round(f.Width.value) / 100;
    f.Height.value = Math.round(f.Height.value) / 100;
}


function round(value) {
    value = Math.round(value * 100) / 100;
    return value;
}

