// JavaScript Document

function calc_outletFriction( form )
	{
		flowUnits		= parseFloat( form.flowUnits.value );
		diameterUnits 	= parseFloat( form.diameterUnits.value );
		lengthUnits 	= parseFloat( form.lengthUnits.value );
		frictionUnits 	= parseFloat( form.frictionUnits.value );

		diameter 	= parseFloat( form.diameter.value ) / diameterUnits ;
		outlets		= parseFloat( form.outlets.value );
		length 		= parseFloat( form.length.value ) / lengthUnits;
		flow 		= parseFloat( form.flow.value ) * flowUnits;
		material 	= parseFloat( form.material.value );
		
		// intermediate calculations
		friction = 1 / 2.75;
		friction = friction + ( 1 / ( 2 * outlets ) );
		friction = friction + ( Math.pow( .75, .5 ) / ( 6 * Math.pow( outlets, 2 ) ) );
		friction = friction * ( length / 100 );
		friction = Math.pow( diameter, -4.8655 ) * friction;
		friction = Math.pow( flow / material , 1.852 ) * friction;
		friction = 1050 * friction;
		friction = friction * frictionUnits;

		 form.friction.value = friction; //Math.round( friction ) / 10000;           
	}
function calc_outletSize( form )
	{

		flowUnits 		= parseFloat( form.flowUnits.value );
		frictionUnits 	= parseFloat( form.frictionUnits.value );
		lengthUnits	= parseFloat( form.lengthUnits.value );
		diameterUnits 	= parseFloat( form.diameterUnits.value );

		friction	= parseFloat( form.friction.value ) / frictionUnits;
		outlets		= parseFloat( form.outlets.value );
		length		= parseFloat( form.length.value ) / lengthUnits;
		flow		= parseFloat( form.flow.value ) * flowUnits;
		material	= parseFloat( form.material.value );

		// calculate the power

		flowPow		= Math.pow( flow / material, 1.852 );

		// intermediate calculations
		diameter	= 1 / 2.75;
		diameter	= diameter + 1/( 2 * outlets );
		diameter	= diameter + ( Math.pow( .75, .5 ) / ( 6 * Math.pow( outlets, 2 ) ) );
		diameter 	= diameter *  length / 100 ;
		diameter 	= diameter * 1050 * flowPow;
		diameter 	= friction / diameter;
		diameter 	= Math.pow( diameter, ( -1 / 4.87 )  );
		diameter	= Math.round(diameter * diameterUnits * 10000 );

		form.diameter.value =  diameter / 10000;
   	}

function calc_reqFlowRate( form )
	{
		useRateUnits 		= parseFloat( form.useRateUnits.value );
		areaUnits 			= parseFloat( form.areaUnits.value );
		maxFlowRateUnits 	= parseFloat( form.maxFlowRateUnits.value );

		useRate 	= parseFloat( form.useRate.value ) * useRateUnits;
		area 		= parseFloat( form.area.value ) / areaUnits;
		efficiency 	= parseFloat( form.efficiency.value );


		maxFlowRate = ( area * useRate * 452.57 ) / 24;
		maxFlowRate = ( maxFlowRate  / efficiency ) * 100;
		maxFlowRate = Math.round( ( maxFlowRate / maxFlowRateUnits ) * 10000 );
		maxFlowRate = maxFlowRate / 10000;
		 form.maxFlowRate.value = maxFlowRate;
	}

function calc_waterDepth( form )
	{

		// get values from input form
		flowRateUnits	= parseFloat( form.flowRateUnits.value);
		areaUnits		= parseFloat( form.areaUnits.value);
		timeUnits 		= parseFloat( form.timeUnits.value);
		waterDepthUnits 	= parseFloat( form.waterDepthUnits.value);

		// convert input values
		flowRate	= parseFloat( form.flowRate.value) * flowRateUnits;
		area 		= parseFloat( form.area.value) / areaUnits;
		time 		= parseFloat( form.time.value) / timeUnits;
		efficiency 	= parseFloat( form.efficiency.value) / 100;
		
		// calculate result
		waterDepth = ( flowRate * time ) / ( 452.57 * area );
		waterDepth = Math.round( waterDepth * efficiency * waterDepthUnits * 10000 );
		waterDepth = waterDepth/10000;
		
		 form.waterDepth.value = waterDepth;		
	}

function calc_applicationRate( form )
	{
		flowRateUnits 			= parseFloat( form.flowRateUnits.value);
		areaUnits 				= parseFloat( form.areaUnits.value);
		applicationRateUnits 	= parseFloat( form.applicationRateUnits.value);

		flowRate 	= parseFloat( form.flowRate.value) * flowRateUnits;
		area 		= parseFloat( form.area.value) / areaUnits;
	
		applicationRate = flowRate / area;
		applicationRate = applicationRate / 452.57;
		applicationRate = applicationRate  * applicationRateUnits;
		applicationRate = Math.round( applicationRate * 10000 );
	
		 form.applicationRate.value = applicationRate/10000;
	}

function calc_pipefriction( form )
	{
		pfFlowUnits 		= parseFloat( form.flowUnits.value );
		pfDiameterUnits	= parseFloat( form.diameterUnits.value );
		pfLengthUnits 		= parseFloat( form.lengthUnits.value );
		pfPressLossUnits 	= parseFloat( form.pressureLossUnits.value );

		pfFlow 		= parseFloat( form.flow.value) * pfFlowUnits;
		pfDiameter 	= parseFloat( form.diameter.value) * pfDiameterUnits;
		pfLength  	= parseFloat( form.length.value) * pfLengthUnits;
		pfMaterial 	= parseFloat( form.material.value );
		
		pressureLoss = pfLength / 100;
		pressureLoss = pressureLoss * 455.2;
		pressureLoss = pressureLoss * Math.pow( ( pfFlow / pfMaterial ), 1.852 );
		pressureLoss = pressureLoss * Math.pow( ( pfDiameter/2.54 ), -4.8655 );
		pressureLoss = Math.round(  pressureLoss  * pfPressLossUnits * 10000 ) / 10000;

		 form.pressureLoss.value = pressureLoss;
	}

function calc_pipesize( form )
	{
		psMaxPressureUnits = parseFloat( form.maxPressureUnits.value );
		psFlowUnits 		= parseFloat( form.flowUnits.value );
		psLengthUnits 		= parseFloat( form.lengthUnits.value );
		psMinPipeSizeUnits = parseFloat( form.minPipeSizeUnits.value );

		psFlow 			= parseFloat( form.flow.value) * psFlowUnits;
		psLength 		= parseFloat( form.length.value) / psLengthUnits;
		psMaterial 		= parseFloat( form.material.value );
		psMaxPressure 	= parseFloat( form.maxPressure.value) / psMaxPressureUnits;
		
		minPipeSize = Math.pow( ( psFlow / psMaterial ), 1.852 );
		minPipeSize = 455.2 * ( psLength / 100 ) * minPipeSize;
		minPipeSize = psMaxPressure / minPipeSize;
		minPipeSize = Math.pow( minPipeSize, ( -1 / 4.8655 ) );
		minPipeSize = Math.round( ( minPipeSize / psMinPipeSizeUnits ) * 10000 );
		minPipeSize = minPipeSize / 10000;
		
		form.minPipeSize.value = minPipeSize;
	}
	
	function calc_horsepower( form )
{

		pressureUnits 	= parseFloat( form.pressureUnits.value );
		flowRateUnits 	= parseFloat( form.flowRateUnits.value );
		powerUnits		= parseFloat( form.powerUnits.value );
		brakeUnits		= parseFloat( form.brakeUnits.value );

		pressure 		= parseFloat( form.pressure.value ) / pressureUnits;
		flowRate 		= parseFloat( form.flowRate.value ) * flowRateUnits;
		pumpEffic 		= parseFloat( form.pumpEffic.value ) / 100;
		driveMotorEffic = parseFloat( form.driveMotorEffic.value ) / 100;

		tmpResult = ( flowRate * pressure ) / ( 1716.8 * pumpEffic );

		// find brake horsepower
		brakeHP = tmpResult / brakeUnits;
		brakeHP = Math.round( brakeHP * 10000 );
		 form.brakeHP.value = brakeHP / 10000;

		// total power requirements
		powerReq = parseFloat( tmpResult / driveMotorEffic );
		powerReq = powerReq / powerUnits;
		powerReq = Math.round( powerReq * 10000 );
		form.powerReq.value = powerReq / 10000;
}

// Water Velocity equation
// velocity = (0.408 * flowRate)/(diameter squared)
function calc_waterVelocity( form )
	{
		flowRateUnits	= parseFloat( form.flowRateUnits.value) ;
		diameterUnits	= parseFloat( form.diameterUnits.value);

		flowRate	= parseFloat( form.flowRate.value) * flowRateUnits;
		diameter	= parseFloat( form.diameter.value) / diameterUnits;

		waterVelocity = Math.pow( diameter, 2 );
		waterVelocity = ( 0.4085 * flowRate ) / waterVelocity;
		waterVelocity = Math.round( waterVelocity * 10000 );
		waterVelocity = waterVelocity / 10000;
		
		 form.waterVelocity.value = waterVelocity;
	
	}
function calc_pipeDiameter( form )
	{

		pipeFlowRateUnits	= parseFloat( form.pipeFlowRateUnits.value);
		pipeDiameterUnits	= parseFloat( form.pipeDiameterUnits.value);

		pipeFlowRate		= parseFloat( form.pipeFlowRate.value) * pipeFlowRateUnits;
		
		pipeDiameter = Math.sqrt( pipeFlowRate );
		pipeDiameter = Math.round(  0.28583 * pipeDiameter * pipeDiameterUnits * 10000 );
		pipeDiameter = pipeDiameter / 10000;
		
		 form.pipeDiameter.value = pipeDiameter;
	}

function calc_setTime( form )
{	
	flowUnits 		= parseFloat(form.flowUnits.value);
	areaUnits 		= parseFloat(form.areaUnits.value);
	appUnits 		= parseFloat(form.appUnits.value);
	setTimeUnits 	= parseFloat(form.setTimeUnits.value);

	app 		= parseFloat(form.app.value) * appUnits;
	area 		= parseFloat(form.area.value) / areaUnits;
	flow 		= parseFloat(form.flow.value) * flowUnits;
	efficiency 	= parseFloat(form.efficiency.value) / 100;
	
	setTime = app * area * 43560;
	setTime = setTime / ( 96.3 * flow * efficiency );
	setTime = setTime / setTimeUnits;
	setTime = Math.round( setTime * 1000 );
	
	form.setTime.value = setTime / 1000;
}




function calc_systemCapacity( form )
	{

		areaUnits 		= parseFloat( form.areaUnits.value);
		depthUnits 	= parseFloat( form.depthUnits.value);
		intervalUnits 	= parseFloat( form.intervalUnits.value);
		timeUnits 		= parseFloat( form.timeUnits.value);
		systemCapUnits = parseFloat( form.systemCapUnits.value);

		area 		= parseFloat( form.area.value) / areaUnits;
		depth 		= parseFloat( form.depth.value) / depthUnits;
		interval 	= parseFloat( form.interval.value) * intervalUnits;
		time 		= parseFloat( form.time.value) * timeUnits;
		efficiency 	= parseFloat( form.efficiency.value) / 100;
		
		result = 453 * area * depth;
		result = result/( interval * time * efficiency );
		result = parseFloat( result / systemCapUnits );
		result = Math.round( result * 10000 );
		
		 form.systemCapacity.value = result / 10000;		

	}

function clearText( thefield )
{
	if ( thefield.defaultValue == thefield.value )
		thefield.value = "";
} 

// area trapezoidal fields

function calc_trapezoidalArea( form )
{
widthUnits = parseFloat( form.widthUnits.value );
length1Units = parseFloat( form.length1Units.value );
length2Units = parseFloat( form.length2Units.value );
areaUnits = parseFloat( form.areaUnits.value );

width = parseFloat( form.width.value ) / widthUnits;
length1 = parseFloat( form.length1.value ) / length1Units;
length2 = parseFloat( form.length2.value ) / length2Units;

area = length2 + length1;
area = area / 2;
area = area * width;
area = area / 43560;
area = area * areaUnits;

// rounding
area = Math.round( area * 100 ) / 100;
form.area.value = area;
}

// area rectangular

function calc_rectangularArea( form )
{
widthUnits = parseFloat( form.widthUnits.value );
lengthUnits = parseFloat( form.lengthUnits.value );
areaUnits = parseFloat( form.areaUnits.value );

width = parseFloat( form.width.value ) / widthUnits;
length = parseFloat( form.length.value ) / lengthUnits;

area = length * width;
area = area / 43560;
area = area * areaUnits;

// rounding

area = Math.round( area * 100 ) / 100;
form.area.value = area;
}

// area triangular field
function calc_triangularArea( form )
{
baseUnits = parseFloat( form.baseUnits.value );
heightUnits = parseFloat( form.heightUnits.value );
areaUnits = parseFloat( form.areaUnits.value );

height = parseFloat( form.height.value ) / heightUnits;
base = parseFloat( form.base.value ) / baseUnits;

area = base * height;
area = area / 2;
area = area / 43560;

// rounding
area = Math.round( area * 100 ) / 100;

area = area * areaUnits;

form.area.value = area;
}

// area circular field
function calc_circularArea( form )
{
radiusUnits = parseFloat( form.radiusUnits.value );
circleUnits = parseFloat( form.circleUnits.value );
areaUnits = parseFloat( form.areaUnits.value );

radius = parseFloat( form.radius.value ) / radiusUnits;
circle = parseFloat( form.circle.value );

switch( circleUnits )
{
	// degree
	case 0:
		// do nothing
	break;
	// percentages
	case 1:
		circle = circle * 3.6;
	break;
	// decimal
	case 2:
		circle = circle * 360;
	break;
	default:
}

area = Math.PI * Math.pow( radius, 2 );
area = area * circle;
area = area / 360;
area = area / 43560;
area = area * areaUnits;

// rounding
area = Math.round( area * 100 ) / 100;

form.area.value = area;
}
// Total Dynamic Head

function calc_totalDynamicHead( form )
{
elevationUnits = parseFloat( form.elevationUnits.value );
headPressureUnits = parseFloat( form.headPressureUnits.value );
frictionUnits = parseFloat( form.frictionUnits.value );
existingPressureUnits = parseFloat( form.existingPressureUnits.value );

totalHeadPressureUnits = parseFloat( form.totalHeadPressureUnits.value );
totalDynamicHeadUnits = parseFloat( form.totalDynamicHeadUnits.value );


elevationChange = parseFloat( form.elevationChange.value ) / elevationUnits;
headPressure = parseFloat( form.headPressure.value ) * headPressureUnits;
frictionLoss = parseFloat( form.frictionLoss.value ) * frictionUnits;
existingPressure = parseFloat( form.existingPressure.value ) * existingPressureUnits;

totalHeadPressure = elevationChange / 2.31;
totalHeadPressure = totalHeadPressure + headPressure + frictionLoss;
form.totalHeadPressure.value = totalHeadPressure *totalHeadPressureUnits;



totalDynamicHead = totalHeadPressure - existingPressure;
totalDynamicHead = totalDynamicHead / totalDynamicHeadUnits;

form.totalDynamicHead.value = totalDynamicHead;

}

// Irrigatable Area
function calc_irrigatableArea( form )
{
supplyUnits = parseFloat( form.supplyUnits.value );
waterNeedsUnits = parseFloat( form.waterNeedsUnits.value );
timeUnits = parseFloat( form.timeUnits.value );
irrigatedAreaUnits = parseFloat( form.irrigatedAreaUnits.value );

supply = parseFloat( form.supply.value ) * supplyUnits;
waterNeeds = parseFloat( form.waterNeeds.value ) * waterNeedsUnits;
operationHours = parseFloat( form.operationHours.value ) * timeUnits;
sysEfficiency = parseFloat( form.sysEfficiency.value );

if( form.sysEfficiencyUnits.value == 0 )
{
	sysEfficiency = parseFloat( form.sysEfficiency.value ) / 100;
}


irrigatedArea = 96.25 * supply * operationHours * sysEfficiency;
irrigatedArea = irrigatedArea / waterNeeds;
irrigatedArea = irrigatedArea / 43560;
irrigatedArea = irrigatedArea * irrigatedAreaUnits;

form.irrigatedArea.value = irrigatedArea;
}

// Irrigation Run Time
function calc_irrigRunTime( form )
{
wateringFreqUnits = parseFloat( form.wateringFreqUnits.value );
refETUnits = parseFloat( form.refETUnits.value );
appRateUnits = parseFloat( form.appRateUnits.value );
runTimeUnits = parseFloat( form.runTimeUnits.value );

wateringFreq = parseFloat( form.wateringFreq.value ) / wateringFreqUnits;
refET = parseFloat( form.refET.value ) * refETUnits;
cropCoefficient = 1 ;
appRate = parseFloat( form.appRate.value ) / appRateUnits;

if ( form.efficiencyUnits.value == 0 )
{
	efficiency = parseFloat( form.efficiency.value ) / 100;
}
else
{
	efficiency = parseFloat( form.efficiency.value );
}

runTime = 60 * wateringFreq * refET * cropCoefficient;
runTime = runTime / ( appRate * efficiency );
runTime = runTime * runTimeUnits;

form.runTime.value = runTime;
}
// irrigation frequency
function calc_irrigFrequency( form )
{
AWHCUnits = parseFloat( form.AWHCUnits.value );
RZUnits = parseFloat( form.RZUnits.value );
EtoUnits = parseFloat( form.EtoUnits.value );
frequencyUnits = parseFloat( form.frequencyUnits.value );


AWHC = parseFloat( form.AWHC.value );
RZ = parseFloat( form.RZ.value ) / RZUnits;
MAD = parseFloat( form.MAD.value );
Eto = parseFloat( form.Eto.value ) * EtoUnits;
Kc = 1 ;

switch( AWHCUnits )
{
	case 0: // in/ft
		break;
	case 1: // %
		AWHC = AWHC / 100;
	break;
	case 2: // in/in
	case 3: //m/m
	case 4: // decimal
	default: AWHC = AWHC / 0.0833333333;
}
frequencyActual = AWHC * RZ * MAD;
frequencyActual = frequencyActual / ( Eto * Kc );
frequencyActual = frequencyActual * frequencyUnits;

frequency = frequencyActual;
form.frequency.value = frequency;
}
// Converting Nozzle sizes

function calc_convertNozzleSizes( form )
{
decimalofInch = parseFloat( form.decimalofInch.value );
convertSize = parseInt( form.convertSize.value );

	switch( convertSize )
	{
	
		case 0:	convertedValue = decimalOfInch * 25.4;
			break;
		case 1: convertedValue = Math.round( decimalOfInch * 128 );
			break;
		case 2: convertedValue = Math.round( decimalOfInch * 64 );
			break;
		case 3:	size_128 = Math.round( decimalOfInch * 128 );
			break;
		case 4: size_64 = Math.round( decimalOfInch * 64 );
			break;
		case 5: size_32 = Math.round( decimalOfInch * 32 );
			break;
		case 6: size_16 = Math.round( decimalOfInch * 16 );
			break;
		case 7: size_8 = Math.round( decimalOfInch * 8 );
			break;
		default:
			break;
		// convert to nearest 128th inch
		
		if( ( size_128 % 2 ) != 0 )
		{
			result = (size_128 % 2 ) + "/128";
		}
		else if( ( size_128 % 4 ) != 0 )
		{
			result = (size_128 % 4 ) / 2;
			result = result + "/64";
		}
		else if( ( size_128 % 8 ) != 0 )
		{
			result = ( size_128 % 8 ) / 4;
			result = result + "/32";
		}
		else if( ( size_128 % 16 ) != 0 )
		{
			result = ( size_128 % 16 ) / 8;
			result = result + "/16";
		}
		else if( ( size_128 % 32 ) != 0 )
		{
			result = ( size_128 % 32 ) / 16;	
			result = result + "/8";
		}
		else if( ( size_128 % 64 ) != 0 )
		{
			result = ( size_128 % 64 ) / 32;
			result = result + "/4";
		}
		else if( ( size_128 % 128 ) != 0 )
		{
			result = ( size_128 % 128 ) / 64;
			result = result + "/2";
		
		}
		else
		{
			result = size_128 / 128;
			
		}
	
	}
}

// NPSHA

function calc_NPSHA( form )
{
elevationUnits = parseFloat( form.elevationUnits.value );
frictionUnits = parseFloat( form.frictionUnits.value );
vHeightUnits = parseFloat( form.vHeightUnits.value );
NPSHAUnits = parseFloat( form.NPSHAUnits.value );

elevation = parseFloat( form.elevation.value ) * elevationUnits;
friction = parseFloat( form.friction.value ) * frictionUnits;
vHeight = parseFloat( form.vHeight.value ) * vHeightUnits;
pressure = elevation / 504.74;
pressure = 293 - pressure;
pressure = pressure / 293;
pressure = Math.pow( pressure, 5.26 );
pressure = 33.89 * pressure;

form.atPressure.value = pressure;
NPSHA = pressure - friction - vHeight;
NPSHA = NPSHA / NPSHAUnits;

form.NPSHA.value = NPSHA;
}

// Water Hammer
function calc_waterHammer( form )
{
opPressureUnits = parseFloat( form.opPressureUnits.value );
velocityUnits = parseFloat( form.velocityUnits.value );
lengthUnits = parseFloat( form.lengthUnits.value );
devPressureUnits = parseFloat( form.devPressureUnits.value );

opPressure = parseFloat( form.opPressure.value ) * opPressureUnits;
velocity = parseFloat( form.velocity.value ) / velocityUnits;
length = parseFloat( form.length.value ) / lengthUnits;
time = parseFloat( form.time.value );

devPressure = opPressure + velocity * length * 0.07 / time;
devPressure = devPressure / devPressureUnits;

form.devPressure.value = devPressure;
}
// water supply
function calc_waterSupply( form )
{
waterRateUnits = parseFloat( form.waterRateUnits.value );
timeUnits = parseFloat( form.timeUnits.value );

supplyUnits = parseFloat( form.supplyUnits.value );
areaUnits = parseFloat( form.areaUnits.value );
sysCapacityUnits = parseFloat( form.sysCapacityUnits.value );

waterRate = parseFloat( form.waterRate.value ) * waterRateUnits;
opTime = parseFloat( form.opTime.value ) * timeUnits;
efficiency = parseFloat( form.efficiency.value );

if( parseInt( form.efficiencyUnits.value ) == 0 )
{
	efficiency = efficiency / 100;
}

minSupplyReqs = waterRate * 15.08556;
minSupplyReqs = minSupplyReqs / opTime;
minSupplyReqs = minSupplyReqs / efficiency;

form.minSupplyReqs.value = minSupplyReqs / supplyUnits;

area = parseFloat( form.area.value ) / areaUnits;

sysCapacity = minSupplyReqs * area;
sysCapacity = sysCapacity / sysCapacityUnits;

form.sysCapacity.value = sysCapacity;
}

// Sprinkler Density
function calc_rectangleSprinklerDensity( form )
{
lateralSpacingUnits = parseFloat( form.lateralSpacingUnits.value );
lineSpacingUnits = parseFloat( form.lineSpacingUnits.value );
headDensityUnits = parseFloat( form.headDensityUnits.value );

lateralSpacing = parseFloat( form.lateralSpacing.value ) * lateralSpacingUnits;
lineSpacing = parseFloat( form.lineSpacing.value ) * lineSpacingUnits;

headDensity = 43560 / lineSpacing;
headDensity = headDensity / lateralSpacing;
headDensity = headDensity * headDensityUnits;

form.headDensity.value = headDensity;
}

function calc_triangleSprinklerDensity( form )
{
lineSpacingUnits = parseFloat( form.lineSpacingUnits.value );
headDensityUnits = parseFloat( form.headDensityUnits.value );

lineSpacing = parseFloat( form.lineSpacing.value );

headDensity = 0.866 * Math.pow( lineSpacing, 2 );
headDensity = 43560 / headDensity;
headDensity = headDensity * headDensityUnits;

form.headDensity.value = headDensity;
}



// Estimated Pipe Size

function show_id( form )
{
	pipeMaterial = parseInt( form.pipeMaterial.value );
	switch( pipeMaterial )
	{
		case 0:
		document.getElementById( "pvc" ).style.display = "block";
		document.getElementById( "steel" ).style.display = "none";
		document.getElementById( "castIron" ).style.display = "none";
		document.getElementById( "aluminum" ).style.display = "none";	

		break;
		case 1:
		document.getElementById( "pvc" ).style.display = "none";
		document.getElementById( "steel" ).style.display = "block";
		document.getElementById( "castIron" ).style.display = "none";
		document.getElementById( "aluminum" ).style.display = "none";			
		break;
		case 2:
		document.getElementById( "pvc" ).style.display = "none";			
		document.getElementById( "steel" ).style.display = "none";	
		document.getElementById( "castIron" ).style.display = "block";
		document.getElementById( "aluminum" ).style.display = "none";	
		break;
		case 3:
		document.getElementById( "pvc" ).style.display = "none";		
		document.getElementById( "steel" ).style.display = "none";
		document.getElementById( "castIron" ).style.display = "none";		
		document.getElementById( "aluminum" ).style.display = "block";	
		break;
		default:
		document.getElementById( "pvc" ).style.display = "none";		
		document.getElementById( "steel" ).style.display = "none";
		document.getElementById( "castIron" ).style.display = "none";		
		document.getElementById( "aluminum" ).style.display = "none";	
	}
}
function calc_pipeSize( form )
{
// user chooses a pipe Material from a dropdown list then chooses a nominal value.
pipeMaterial = parseInt( form.pipeMaterial.value );
circumferenceUnits = parseFloat( form.circumferenceUnits.value );

  switch( pipeMaterial )
{
	
	case 0: 
		circumference = parseFloat( form.pvcOD.value ) * Math.PI;
	break;
	case 1: 
		circumference = parseFloat( form.steelOD.value ) * Math.PI;
		break;
	case 2: 
		circumference = parseFloat( form.castIronOD.value ) * Math.PI;
		break;
	case 3: 
		circumference = parseFloat( form.aluminumOD.value ) * Math.PI;
		break;
	default: circumference = 0;


}

form.circumference.value = circumference / circumferenceUnits;

}

// pressure loss fittings

function calc_equivPipeSize( form )
{
// indices for lookup table
pipeType = parseInt(form.pipeType.value);
pipeSize = parseInt( form.pipeSize.value );

fittingNo = parseFloat( form.fittingNo.value );

// lookup tables

tbl_coupling = [ '1.5', '2.5', '3', '3', '4', '6', '7', '8', '11', '18','24'];
tbl_runStTee = [ '2.5', '3', '4', '5', '6', '8', '9', '11', '15', '21', '28'];
tbl_soTee = [ '7', '9', '12', '15', '18', '24', '30', '36', '45', '70', '90' ];
tbl_runReducedTee = [ '3.5', '4.5', '6', '8', '9', '11', '14', '17', '24', '34', '45'];
tbl_elbow90Degree = [ '3.5', '4.5', '6', '8', '9', '11', '14', '17', '24', '34', '45'];
tbl_elbow45Degree = [ '1.5', '2', '3', '3.5', '4', '5', '7', '8', '10', '16', '20'];

switch( pipeType )
{
	case 0:
		equivFeet = tbl_coupling[ pipeSize ];
		break;
	case 1:
		equivFeet = tbl_runStTee[ pipeSize ];
		break;
	case 2:
		equivFeet = tbl_soTee[ pipeSize ];
		break;
	case 3:
		equivFeet = tbl_runReducedTee[ pipeSize ];
		break;
	case 4:
		equivFeet = tbl_elbow90Degree[ pipeSize ];
		break;
	case 5:
		equivFeet = tbl_elbow45Degree[ pipeSize ];
		break;
	default: 
		equivFeet = 0;
		
}

totalEquivFeet = fittingNo * equivFeet;

form.totalEquivFeet.value = totalEquivFeet;

}

// max operating pressures for PVC and polyethelyne

function calc_maxOpPressureTable( form )
{

// indices for the lookup table 
nominalSize = parseInt( form.nominalSize.value );
pipeType = parseInt( form.pipeType.value );

// lookup tables

tbl_sch80PVC = [ '850', '690', '630', '520', '470', '400', '420', '370', '320', '280', '250', '230', '230'];
tbl_sch40PVC = [ '600', '480', '450', '370', '330', '280', '300', '260', '220', '180', '160', '140', '130']; 

tbl_CL315 = 	[ '315', '315', '315', '315', '315', '315', '315', '315', '315', '315', '315', '315', '315' ];
tbl_CL200 = [ '***', '200', '200', '200', '200', '200', '200', '200', '200', '200', '200', '200', '200', '200'];
tbl_CL160 =  [ '***', '***', '160', '160', '160', '160', '160', '160', '160', '160', '160', '160', '160'];
tbl_CL125 = [ '***', '***', '***', '***', '***', '***', '***','125', '125', '125', '125', '125', '125'];

tbl_sch40PE = [ '190', '150', '140', '120', '100', '90', '100', '80', '70', '60', '++', '++', '++' ];

tbl_annCopperM = [ '430', '350', '295', '295', '290', '300', '235', '220', '215', '190', '200', '205', '205'];
tbl_hdCopperM = [ '760', '610', '515', '515', '510', '450', '410', '385', '380', '335', '350', '355', '360'];

tbl_annCopperL = [ '625', '495', '440', '385', '355', '315', '295', '275', '255', '215', '240', '240', '225'];
tbl_hdCopperL = [ '1105', '875', '770', '680', '630', '555', '520', '490', '450', '385', '420', '425', '395'];

tbl_annCopperK = [ '780', '750', '575', '465', '435', '380', '355', '340', '315', '305', '325', '330', '330'];
tbl_hdCopperK =  [ '1375', '1315', '1010', '820', '765', '665', '520', '605', '555', '540', '580', '585', '585'];


switch( pipeType )
{
	case 0:
		maxOpPressure = tbl_sch80PVC[ nominalSize ];
		break;
	case 1:
		maxOpPressure = tbl_sch40PVC[ nominalSize ]; 
		break;

	case 2:
		maxOpPressure = tbl_CL315[ nominalSize ]; 
		break;

	case 3:
		maxOpPressure = tbl_CL200[ nominalSize ];
		break;
	
	case 4:
		maxOpPressure = tbl_CL160[ nominalSize ];
		break;

	case 5:
		maxOpPressure = tbl_CL125[ nominalSize ];
		break;

	case 6:
		maxOpPressure = tbl_sch40PE[ nominalSize ];
		break;
	
	case 7:
		maxOpPressure = tbl_annCopperM[ nominalSize ];
		break;

	case 8:
		maxOpPressure = tbl_hdCopperM[ nominalSize ];
		break;

	case 9:
		maxOpPressure = tbl_annCopperL[ nominalSize ];
		break;

	case 10:
		maxOpPressure = tbl_hdCopperL[ nominalSize ]; 
		break;

	case 11:
		maxOpPressure = tbl_annCopperK[ nominalSize ]; 
		break;

	case 12:
		maxOpPressure = tbl_hdCopperK[ nominalSize ];
		break;

	default:
		maxOpPressure = 0; 

}

form.maxOpPressure.value = maxOpPressure;
}