<!--

	function ifNumeric(val)

	{

		if(parseFloat(val,10) != (val*1))

		{

			return false;

		}	

		else

		{

			return true;

		}

	}

	

	function validate()

	{

		if (document.frmenquiry.txtNoMac.value == "")

		{

			alert("Please enter Number of machines");

			document.frmenquiry.txtNoMac.value = "";

			document.frmenquiry.txtNoMac.focus();

			return false;

		}

		else if (ifNumeric(document.frmenquiry.txtNoMac.value) == false)

		{

			alert("Number of machines should be whole number");

			document.frmenquiry.txtNoMac.select();

			return false;

		}

		else if(document.frmenquiry.txtNoMac.value.indexOf(".") != -1)

		{

			alert("Number of machines should be whole number");

			document.frmenquiry.txtNoMac.select();

		}

		else if(document.frmenquiry.txtNoMac.value < 0)

		{

			alert("Number of machines should not be less than zero");

			document.frmenquiry.txtNoMac.select();

		}

		else if (document.frmenquiry.txtOpHrPerYr.value == "")

		{

			alert("Please enter Operating hours per year");

			document.frmenquiry.txtOpHrPerYr.value = "";

			document.frmenquiry.txtOpHrPerYr.focus();

			return false;

		}

		else if (ifNumeric(document.frmenquiry.txtOpHrPerYr.value) == false)

		{

			alert("Operating hours per year should be numeric");

			document.frmenquiry.txtOpHrPerYr.select();

			return false;

		}

		else if(document.frmenquiry.txtOpHrPerYr.value < 0)

		{

			alert("Operating hours per year should not be less than zero");

			document.frmenquiry.txtOpHrPerYr.select();

		}

		else if (document.frmenquiry.txtCurAvailability.value == "")

		{

			alert("Please enter Current availability in %");

			document.frmenquiry.txtCurAvailability.value = "";

			document.frmenquiry.txtCurAvailability.focus();

			return false;

		}

		else if (ifNumeric(document.frmenquiry.txtCurAvailability.value) == false)

		{

			alert("Current availability in % should be numeric");

			document.frmenquiry.txtCurAvailability.select();

			return false;

		}

		else if(document.frmenquiry.txtCurAvailability.value < 0)

		{

			alert("Current availability in % should not be less than zero");

			document.frmenquiry.txtCurAvailability.select();

		}

		else if (document.frmenquiry.txtDwnTime.value == "")

		{

			alert("Please enter Down time cost per hour (£)");

			document.frmenquiry.txtDwnTime.value = "";

			document.frmenquiry.txtDwnTime.focus();

			return false;

		}

		else if (ifNumeric(document.frmenquiry.txtDwnTime.value) == false)

		{

			alert("Down time cost per hour (£) should be numeric");

			document.frmenquiry.txtDwnTime.select();

			return false;

		}

		else if(document.frmenquiry.txtDwnTime.value < 0)

		{

			alert("Down time cost per hour (£) should not be less than zero");

			document.frmenquiry.txtDwnTime.select();

		}

		else

		{

			return true;

		}

	}

	

	function Calculate()

	{

		Res = validate();

		if (Res == true)

		{

			var B2 = document.frmenquiry.txtNoMac.value;

			var B3 = document.frmenquiry.txtOpHrPerYr.value;

			var B4 = document.frmenquiry.txtCurAvailability.value;

			var B5 = document.frmenquiry.txtDwnTime.value;

			document.frmenquiry.txtTotDwnTime.value = round_decimals(((100-B4)/100)*B2*B3*B5, 2);

			var B6 = document.frmenquiry.txtTotDwnTime.value;

			document.frmenquiry.txtMechFailure.value = round_decimals(B6*0.65, 2);

			document.frmenquiry.txtHydFailure.value = round_decimals(B6*0.35, 2);

			var B11 = document.frmenquiry.txtHydFailure.value;

			document.frmenquiry.txtFluid.value = round_decimals(B11*0.7, 2);

			var B12 = document.frmenquiry.txtFluid.value;

			document.frmenquiry.txtOther.value = round_decimals(B11*0.3, 2);

			document.frmenquiry.txtRelated.value = round_decimals(B12*0.9, 2);

		}

	}

	

	function round_decimals(original_number, decimals)

	{

		var result1 = original_number * Math.pow(10, decimals)

		var result2 = Math.round(result1)

		var result3 = result2 / Math.pow(10, decimals)

		return pad_with_zeros(result3, decimals)

	}

	

	function pad_with_zeros(rounded_value, decimal_places) 

	{

		// Convert the number to a string

		var value_string = rounded_value.toString();

		// Locate the decimal point

		var decimal_location = value_string.indexOf(".");

		// Is there a decimal point?

		if (decimal_location == -1) 

		{  

			// If no, then all decimal places will be padded with 0s

			decimal_part_length = 0;

			// If decimal_places is greater than zero, tack on a decimal point

			value_string += decimal_places > 0 ? "." : "";

		}

		else 

		{

			// If yes, then only the extra decimal places will be padded with 0s

			decimal_part_length = value_string.length - decimal_location - 1;

		}

		// Calculate the number of decimal places that need to be padded with 0s

		var pad_total = decimal_places - decimal_part_length

	 

		if (pad_total > 0) 

		{  

			// Pad the string with 0s

			for (var counter = 1; counter <= pad_total; counter++) 

			 value_string += "0"

		}

		return value_string;

	}



	

//-->
