// JavaScript Document

function calculateSinkFlow(){
	/* First determine which variables we currently have on tap, if we have A) Length B) Depth C) Number of Compartments, than compute in^3 */
	formObj = document.forms.lengthForm;
	
	if( formObj ){
		/* Retrieve our length */
		length_computed = ( formObj.length_input.value.length > 0 ) ? formObj.length_input.value : 0;
		width_computed = ( formObj.width_input.value.length > 0 ) ? formObj.width_input.value : 0;
		depth_computed = ( formObj.depth_input.value.length > 0 ) ? formObj.depth_input.value : 0;
		
		/* Validate date before processing */
		if( !isNaN(length_computed) && !isNaN(width_computed) && !isNaN(depth_computed) && length_computed > 0 && width_computed > 0 && depth_computed > 0 ){
			/* Compute our total */
			inches = Math.round(length_computed * width_computed * depth_computed);
			formObj.textfield.value = inches;
			/* Process our next result */
			calculateCapacity();
		}
	}
}

function calculateCapacity(){
	/* First we need to make sure that we have our cubic inches calculated, if so, continue */
	formObj = document.forms.capacityForm;
	
	if( formObj ){
		/* Retrieve our in^3 */
		inches = ( document.getElementById('cub_inches').value.length > 0 ) ? document.getElementById('cub_inches').value : 0;
		comp_computed = ( formObj.comp.value > 0 ) ? formObj.comp.value : 0;
		
		if( !isNaN(inches) && !isNaN(comp_computed) && inches > 0 && comp_computed > 0 ){
			/* Process our result */
			gpm = Math.round(comp_computed * (inches/231));
			formObj.gpm.value = gpm;
			/* Forward our result to our next form */
			document.getElementById('gpm_2_id').value = gpm;
			/* Process our next result */
			calculateDisplacement();
		}
	}
}
function calculateDisplacement(){
	/* First we need to make sure that we have the gpm on calculated, if so continue */
	formObj = document.forms.gpmForm;
	
	if( gpmForm ){
		/* Retrieve our GPM */
		gpm = ( formObj.gpm_2.value > 0 ) ? formObj.gpm_2.value : 0;
		
		if( !isNaN(gpm) && gpm > 0 ){
			/* Process our result */
			displacement = Math.round(gpm * 0.75);
			formObj.gpm_3.value = displacement;
		}
	}
}