// Techgua, LLC An Ocean of Services

var URL = "";
var name = "";
var width = 0;
var height = 0;

//Open the Covrage Calculator Window
function OpenCoverageCalc(URL, name, features)
{	
	//Open Window
	window.open(URL, name, features);
}

function CalculateQty(frm)
{
	var errorString = "";
	var bValidForm  = true;
	if (frm.form_depth.value == "")
	{
		frm.form_depth.focus();
		errorString = "Please Enter Depth in Inches. \r" + errorString;		
		bValidForm = false;
	}
	else
	{
		if(!isInteger(frm.form_depth.value)) 
		{
			errorString = "Depth must be number! \r" + errorString;	
			frm.form_depth.focus();
			frm.form_depth.select();
			bValidForm = false;
		}
	}

	if (frm.form_width.value == "")
	{
		frm.form_width.focus();
		errorString = "Please Enter Width in Feet. \r" + errorString;		
		bValidForm = false;
	}
	else
	{
		if(!isInteger(frm.form_width.value)) 
		{
			errorString = "Width must be number! \r" + errorString;	
			frm.form_width.focus();
			frm.form_width.select();
			bValidForm = false;
		}
	}

	if (frm.form_length.value == "")
	{
		frm.form_length.focus();
		errorString = "Please Enter Length in Feet. \r" + errorString;		
		bValidForm = false;
	}
	else
	{
		if(!isInteger(frm.form_length.value)) 
		{
			errorString = "Length must be number! \r" + errorString;	
			frm.form_length.focus();
			frm.form_length.select();
			bValidForm = false;
		}
	}
	if (!bValidForm)
    	{
		alert(errorString);
    	}
    	else  //Do Calculation
    	{
		var intResult = 0;
		
		//1 cubic foot	= 1728 cubic inches
		//1 cubic yard	= 27 cubic feet
		//1 ton			= 40 cubic feet
		//There are 46,656 cubic inches in one cubic yard
		// calc = (L * W) / (324 / D)  
		intResult = ( frm.form_length.value * frm.form_width.value ) / (324 / frm.form_depth.value);
		if (parseFloat(intResult) > 0)
		{		
			//round "original" to two decimals
			var result = Math.round(intResult*100)/100 
			intResult = result;
		}
		frm.form_required.value = intResult;
	}
	return false;
}

function ResetQty(frm)
{
	frm.form_required.value = "";
	frm.form_length.value = "";
	frm.form_width.value = "";
	frm.form_depth.value = "";

	frm.form_length.focus();
	return false;
}

function CalculateFoot(frm)
{
	var errorString = "";
	var bValidForm  = true;

	if (frm.fDepthFoot.value == "")
	{
		frm.fDepthFoot.focus();
		errorString = "Please Enter Footing Depth is a Required field. \r" + errorString;		
		bValidForm = false;
	}

	else
	{
		if(!isInteger(frm.fDepthFoot.value)) 
		{
			errorString = "The Footing Depth Must be Numeric! \r" + errorString;	
			frm.fDepthFoot.focus();
			frm.fDepthFoot.select();
			bValidForm = false;
		}
	}

	if (frm.fWidthFoot.value == "")
	{
		frm.fWidthFoot.focus();
		errorString = "The Footing Width is a Required field. \r" + errorString;		
		bValidForm = false;
	}
	else
	{
		if(!isInteger(frm.fWidthFoot.value)) 
		{
			errorString = "The Footing Width Must be Numeric! \r" + errorString;	
			frm.fWidthFoot.focus();
			frm.fWidthFoot.select();
			bValidForm = false;
		}
	}
	
	if (frm.fLengthFoot.value == "")
	{
		frm.fLengthFoot.focus();
		errorString = "The Footing Length is a Required field. \r" + errorString;		
		bValidForm = false;
	}
	else
	{
		if(!isInteger(frm.fLengthFoot.value)) 
		{
			errorString = "The Footing Length Must be Numeric! \r" + errorString;	
			frm.fLengthFoot.focus();
			frm.fLengthFoot.select();
			bValidForm = false;
		}
	}

	if (!bValidForm)
    	{
		alert(errorString);
    	}
    	else  //Do Calculation
    	{
		var intResult = 0;
		//1 cubic foot	= 1728 cubic inches
		//1 cubic yard	= 27 cubic feet
		//1 ton			= 40 cubic feet
		//There are 46,656 cubic inches in one cubic yard
		// calc = (B11 * (B12/12) ) / (324/B13) 
		intResult = ( frm.fLengthFoot.value * (frm.fWidthFoot.value / 12) ) / (324 / frm.fDepthFoot.value);
		if (parseFloat(intResult) > 0)
		{		
			//round "original" to two decimals
			var result = Math.round(intResult*100)/100 
			intResult = result;
		}
		frm.fYardageFoot.value = intResult;
	}
	return false;
}

function ResetFoot(frm)
{
	frm.fYardageFoot.value = "";
	frm.fLengthFoot.value = "";
	frm.fWidthFoot.value = "";
	frm.fDepthFoot.value = "";
	
	frm.fLengthFoot.focus();
	return false;
}

function CalculateColumn(frm)
{
	var errorString = "";
	var bValidForm  = true;

	if (frm.fDepthColumn.value == "")
	{
		frm.fDepthColumn.focus();
		errorString = "The # of Columns is a Required field. \r" + errorString;		
		bValidForm = false;
	}
	
	else
	{
		if(!isInteger(frm.fDepthColumn.value)) 
		{
			errorString = "The # of Columns Must be Numeric! \r" + errorString;	
			frm.fDepthColumn.focus();
			frm.fDepthColumn.select();
			bValidForm = false;
		}

		else if(frm.fDepthColumn.value < 1)
		{
			errorString = "The # of Columns Must be greater than 1. \r" + errorString;	
			frm.fDepthColumn.focus();
			frm.fDepthColumn.select();
			bValidForm = false;
		}
	}

	if (frm.fWidthColumn.value == "")
	{
		frm.fWidthColumn.focus();
		errorString = "The Column Width is a Required field. \r" + errorString;		
		bValidForm = false;
	}

	else
	{
		if(!isInteger(frm.fWidthColumn.value)) 
		{
			errorString = "The Column Width Must be Numeric! \r" + errorString;	
			frm.fWidthColumn.focus();
			frm.fWidthColumn.select();
			bValidForm = false;
		}
	}

	if (frm.fLengthColumn.value == "")
	{
		frm.fLengthColumn.focus();
		errorString = "The Column Length is a Required field. \r" + errorString;		
		bValidForm = false;
	}
	else
	{
		if(!isInteger(frm.fLengthColumn.value)) 
		{
			errorString = "The Column Length Must be Numeric! \r" + errorString;	
			frm.fLengthColumn.focus();
			frm.fLengthColumn.select();
			bValidForm = false;
		}
	}

	if (!bValidForm)
    	{
		alert(errorString);
    	}
    	else  //Do Calculation
    	{
		var intResult = 0;
		//1 cubic foot	= 1728 cubic inches
		//1 cubic yard	= 27 cubic feet
		//1 ton			= 40 cubic feet
		//There are 46,656 cubic inches in one cubic yard
		// calc =  ( ( (3.14*(B18/2)*(B18/2)*(B17*12) ) / 1728 )  /27 ) * B19
		//17 - L
		//18 - Dia
		//19 - # of Col
		intResult = ( ( (3.14 * (frm.fWidthColumn.value/2) * (frm.fWidthColumn.value/2) * (frm.fLengthColumn.value * 12) ) / 1728 ) / 27) * frm.fDepthColumn.value;
		if (parseFloat(intResult) > 0)
		{		
			//round "original" to two decimals
			var result = Math.round(intResult*100)/100 
			intResult = result;
		}
		frm.fYardageColumn.value = intResult;
	}
	
	return false;
}

function ResetColumn(frm)

{
	frm.fYardageColumn.value = "";
	frm.fLengthColumn.value = "";
	frm.fWidthColumn.value = "";
	frm.fDepthColumn.value = "1";
	
	frm.fLengthColumn.focus();
	
	return false;
}


function isInteger (s)
{   
	var i;
	var c;
	var theDot = 0;
	var theComma = 0;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.


    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

		if (c != "." && c != ",")
		{
			if (!isDigit(c))
			{
			    return false;
			}
		}
		else
		{
			if (c == ".")
			{
				theDot = theDot + 1;
			}
			else
			{
				theComma = theComma + 1;
			}
		}
    }
    // All characters are numbers.
    return true;
}


function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}



// close layer when click-out
document.onclick = mclose; 

