// JavaScript Document
/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getLocation(m){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'location_request.php?id=' + m);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	http.onreadystatechange = locationGet; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function locationGet(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('map_info').innerHTML = response;
	}
}


// JavaScript Document

$(document).ready(function() {
	getLocation("4");
	$("#odessa").css("background","url(images/locationball.png) no-repeat 0 -12px");
	
	$("#ipad_giveaway").click(function() {
		window.location = 'ipad_giveaway.php';
	});
	
	$("#submit_search").click(function() {
		document.getElementById("searchform").submit();
		$("#submit_search").css("background","url(images/searchbutton.png)");
	});
	$("#submit_search").mouseover(function() {
		$("#submit_search").css("background","url(images/searchbutton.png) 0 -20px");
	});
	$("#submit_search").mouseout(function() {
		$("#submit_search").css("background","url(images/searchbutton.png)");
	});
	$("#contact_submit").click(function() {
		document.getElementById("contactform").submit();
	});
	
	//map controls
	
	function customMouseOver () {
		$(this).css("background","url(images/locationball.png) no-repeat 0 -12px");
	}
	function customMouseOut () {
		$(this).css("background","url(images/locationball.png) no-repeat 0 0");
	}

	
	var clickedLocation=$('#odessa');
	$("#flora_vista").mouseover(function() {
		$("#flora_vista").css("background","url(images/locationball.png) no-repeat 0 -12px");
	});
	$("#flora_vista").mouseout(function() {
		$("#flora_vista").css("background","url(images/locationball.png) no-repeat 0 0");
	});
	$("#flora_vista").click(function() {
		$("#flora_vista").css("background","url(images/locationball.png) no-repeat 0 -12px");
		$("#flora_vista").unbind('mouseout');
		$("#flora_vista").unbind('mouseover');
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("1");
		clickedLocation =$('#flora_vista');
	});
	$("#amarillo").click(function() {
		$("#amarillo").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#amarillo").unbind('mouseout');
		$("#amarillo").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("2");
		clickedLocation =$('#amarillo');
	});
	$("#hobbs").click(function() {
		$("#hobbs").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#hobbs").unbind('mouseout');
		$("#hobbs").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("3");
		clickedLocation =$('#hobbs');
	});
	$("#odessa").click(function() {
		$("#odessa").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#odessa").unbind('mouseout');
		$("#odessa").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("4");
		clickedLocation =$('#odessa');
	});
	$("#boerne").click(function() {
		$("#boerne").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#boerne").unbind('mouseout');
		$("#boerne").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("5");
		clickedLocation =$('#boerne');
	});
	$("#corpuschristi").click(function() {
		$("#corpuschristi").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#corpuschristi").unbind('mouseout');
		$("#corpuschristi").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("6");
		clickedLocation =$('#corpuschristi');
	});
	$("#pharr").click(function() {
		$("#pharr").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#pharr").unbind('mouseout');
		$("#pharr").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("7");
		clickedLocation =$('#pharr');
	});
	$("#houston").click(function() {
		$("#houston").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#houston").unbind('mouseout');
		$("#houston").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("8");
		clickedLocation =$('#houston');
	});
	$("#palestine").click(function() {
		$("#palestine").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#palestine").unbind('mouseout');
		$("#palestine").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("9");
		clickedLocation =$('#palestine');
	});
	$("#grandprarie").click(function() {
		$("#grandprarie").css("background","url(images/locationball.png) no-repeat 0 -12px");
		clickedLocation.css("background","url(images/locationball.png) no-repeat 0 0");
		$("#grandprarie").unbind('mouseout');
		$("#grandprarie").unbind('mouseover');
		clickedLocation.bind('mouseout',customMouseOut);
		clickedLocation.bind('mouseover',customMouseOver);
		getLocation("10");
		clickedLocation =$('#grandprarie');
	});
	
  //Scroller events 
 	var scroller_width = ($('.scrollbox').length) * 160;
  
  
	$('.scrollbox:last').insertBefore($('.scrollbox:first'));
	$("#scroller").css({left: '-160px'});
	$("#scroller").css({width: scroller_width});
	

  
  function animateScroller() {
	  
	$("#scroller").animate({left: '+=160px'}, 3000,function() {
		$("#scroller").css('left', '-160px');
		$('.scrollbox:last').insertBefore($('.scrollbox:first'));
	 });
  }
	
	setInterval(animateScroller, 3500);
	
	animateScroller();
	
	/* ELECTRIC CALCULATORS */
	
	//calculators: AMPS when HP are known (AC 3-phase)
	$("#amps_hp").click(function() {
		
		var hp = $("#hp").val();
		var e_volts = $("#e_volts_hp").val();
		var eff_dec = $("#eff_dec_hp").val();
		var power_dec = $("#power_dec_hp").val();
		var result = (hp*746)/(1.73*e_volts*eff_dec*power_dec);
		
		$("#solution_amps_hp").val(result.toFixed(2));
	
	});
	
	$("#clear_amps_hp").click(function() {
		$("#hp").val("");
		$("#e_volts_hp").val("");
		$("#eff_dec_hp").val("");
		$("#power_dec_hp").val("");
		$("#solution_amps_hp").val("");
		
	});
	
	//calculators: AMPS when Kilowatts are known (AC 3-phase)
	$("#amps_kilowatts").click(function() {
		
		var kw = $("#kw").val();
		var e_volts = $("#e_volts_kw").val();
		var eff_dec = $("#eff_dec_kw").val();
		var result = (kw*1000)/(1.73*e_volts*eff_dec);
		
		$("#solution_amps_kilowatts").val(result.toFixed(2));
	
	});
	
	$("#clear_amps_kilowatts").click(function() {
		$("#kw").val("");
		$("#e_volts_kw").val("");
		$("#eff_dec_kw").val("");
		$("#solution_amps_kilowatts").val("");
		
	});
	
	//calculators: Kva (AC 3-phase)
	$("#amps_kva").click(function() {
		
		var amperes = $("#amperes_kva").val();
		var volts = $("#volts_kva").val();
		var result = (1.73*amperes*volts)/1000;
		
		$("#solution_kva").val(result.toFixed(2));
	
	});
	
	$("#clear_kva").click(function() {
		$("#amperes_kva").val("");
		$("#volts_kva").val("");
		$("#solution_kva").val("");
		
	});
	
	//calculators: Power Factor
	$("#power_factor").click(function() {
		
		var kw_pf = $("#kw_pf").val();
		var kva_pf = $("#kva_pf").val();
		var result = kw_pf/kva_pf;
		
		$("#power_pf").val(result.toFixed(2));
	
	});
	
	$("#clear_power_factor").click(function() {
		$("#kw_pf").val("");
		$("#kva_pf").val("");
		$("#power_pf").val("");
		
	});
	
	
	//calculators: HP Output (AC 3-phase)
	$("#hp_output").click(function() {
		
		var amperes_hp_output = $("#amperes_hp_output").val();
		var e_voltshp_output = $("#e_voltshp_output").val();
		var e_voltshp_output = $("#eff_dec_hp_output").val();
		var result = amperes_hp_output*e_voltshp_output*e_voltshp_output/746;
		
		$("#solution_hp_output").val(result.toFixed(2));
	
	});
	
	$("#clear_hp_output").click(function() {
		$("#amperes_hp_output").val("");
		$("#e_voltshp_output").val("");
		$("#eff_dec_hp_output").val("");
		$("#solution_hp_output").val("");
		
	});
	
	//calculators: Amperes when Resistance and Current is known
	$("#amperes_arc").click(function() {
		
		var volts_arc = $("#volts_arc").val();
		var resistance_arc = $("#resistance_arc").val();
		var result = volts_arc/resistance_arc;
		
		$("#solution_amperes_arc").val(result.toFixed(2));
	
	});
	
	$("#clear_amperes_arc").click(function() {
		$("#volts_arc").val("");
		$("#resistance_arc").val("");
		$("#solution_amperes_arc").val("");
		
	});
	
	
	//calculators: Voltage when Resistance and Current is known
	$("#voltatge_rc").click(function() {
		
		var amperes_rc = $("#amperes_rc").val();
		var resistance_rc = $("#resistance_rc").val();
		var result = amperes_rc/resistance_rc;
		
		$("#solution_voltatge_rc").val(result.toFixed(2));
	
	});
	
	$("#clear_voltatge_rc").click(function() {
		$("#amperes_rc").val("");
		$("#resistance_rc").val("");
		$("#solution_voltatge_rc").val("");
		
	});
	
	
	//calculators: Resistance when Voltage and Current are known
	$("#resistance_vc").click(function() {
		
		var volts_vc = $("#volts_vc").val();
		var amperes_vc = $("#amperes_vc").val();
		var result = volts_vc/amperes_vc;
		
		$("#solution_resistance_vc").val(result.toFixed(2));
	
	});
	
	$("#clear_resistance_vc").click(function() {
		$("#volts_vc").val("");
		$("#amperes_vc").val("");
		$("#solution_resistance_vc").val("");
		
	});
	
	/* MECHANICAL CALCULATORS */
	
	//calculators: PSI to Head-Feet
	$("#calculate_head_feet").click(function() {
		
		var psi_head_feet = $("#psi_head_feet").val();
		var spgr_head_feet = $("#spgr_head_feet").val();
		var result = (psi_head_feet*2.31)/spgr_head_feet;
		
		$("#head_feet").val(result.toFixed(2));
	
	});
	
	$("#clear_head_feet").click(function() {
		$("#psi_head_feet").val("");
		$("#spgr_head_feet").val("");
		$("#head_feet").val("");
		
	});
	
	//calculators: Head-Feet to PSI
	$("#calculate_hf2psi").click(function() {
		
		var head_feet_hf2psi = $("#head_feet_hf2psi").val();
		var spgr_hf2psi = $("#spgr_hf2psi").val();
		var result = (head_feet_hf2psi*spgr_hf2psi)/2.31;
		
		$("#psi_hf2psi").val(result.toFixed(2));
	
	});
	
	$("#clear_hf2psi").click(function() {
		
		$("#head_feet_hf2psi").val("");
		$("#spgr_hf2psi").val("");
		$("#psi_hf2psi").val("");
		
	});

	//calculators: Specific Gravity
	$("#calculate_spgr").click(function() {
		
		var liquid_spgr = $("#liquid_spgr").val();
		var water_spgr = $("#water_spgr").val();
		var result = liquid_spgr/water_spgr;
		
		$("#spgr_spgr").val(result.toFixed(2));
	
	});
	
	$("#clear_spgr").click(function() {
		
		$("#liquid_spgr").val("");
		$("#water_spgr").val("");
		$("#spgr_spgr").val("");
		
	});
	
	//calculators: BHP - Centrifugal
	$("#calculate_centrifugal").click(function() {
		
		var gpm_centrifugal = $("#gpm_centrifugal").val();
		var head_feet_centrifugal = $("#head_feet_centrifugal").val();
		var SpGr_centrifugal = $("#SpGr_centrifugal").val();
		var eff_centrifugal = $("#eff_centrifugal").val();
		var result = (gpm_centrifugal*head_feet_centrifugal*SpGr_centrifugal)/(3960*eff_centrifugal);
		
		$("#solution_bhp_centrifugal").val(result.toFixed(2));
	
	});
	
	$("#clear_centrifugal").click(function() {
		
		$("#gpm_centrifugal").val("");
		$("#head_feet_centrifugal").val("");
		$("#SpGr_centrifugal").val("");
		$("#eff_centrifugal").val("");
		$("#solution_bhp_centrifugal").val("");
		
	});
	
	//calculators: BHP - Plunger
	$("#calculate_plunger").click(function() {
		
		var gpm_plunger = $("#gpm_plunger").val();
		var psi_plunger = $("#psi_plunger").val();
		var mech_eff_plunger = $("#mech_eff_plunger").val();
		var result = (gpm_plunger*psi_plunger)/(1715*mech_eff_plunger);
		
		$("#bhp_plunger").val(result.toFixed(3));
	
	});
	
	$("#clear_plunger").click(function() {
		
		$("#gpm_plunger").val("");
		$("#psi_plunger").val("");
		$("#mech_eff_plunger").val("");
		$("#bhp_plunger").val("");
		
	});
	
	//calculators: Velocity (ft/sec)
	$("#calculate_velocity").click(function() {
		
		var gpm_velocity = $("#gpm_velocity").val();
		var psi_plunger = $("#in_velocity").val();
		var result = (0.4085*gpm_velocity)/(psi_plunger*psi_plunger);
		
		$("#solution_velocity").val(result.toFixed(3));
	
	});
	
	$("#clear_velocity").click(function() {
		
		$("#gpm_velocity").val("");
		$("#in_velocity").val("");
		$("#solution_velocity").val("");
		
	});
	
	
	//calculators: NPSHa (suction lift)
	$("#calculate_npsha").click(function() {
		
		var pb_npsha = +$("#pb_npsha").val();
		var vb_npsha = +$("#vb_npsha").val();
		var ls_npsha = +$("#ls_npsha").val();
		var hf_npsha = +$("#hf_npsha").val();
		var result = pb_npsha-(vb_npsha+ls_npsha+hf_npsha);
		
		$("#npsha").val(result.toFixed(2));
	
	});
	
	$("#clear_npsha").click(function() {
		
		$("#pb_npsha").val("");
		$("#vb_npsha").val("");
		$("#ls_npsha").val("");
		$("#hf_npsha").val("");
		$("#npsha").val("");
		
	});
	
	//calculators: NPSHa (suction head)
	$("#calculate_npsha2").click(function() {
		
		var pb_npsha = +$("#pb_npsha2").val();
		var vb_npsha = +$("#vb_npsha2").val();
		var ls_npsha = +$("#ls_npsha2").val();
		var hf_npsha = +$("#hf_npsha2").val();
		var result = pb_npsha+ls_npsha-(vb_npsha+hf_npsha);
		
		$("#npsha2").val(result.toFixed(2));
	
	});
	
	$("#clear_npsha2").click(function() {
		
		$("#pb_npsha2").val("");
		$("#vb_npsha2").val("");
		$("#ls_npsha2").val("");
		$("#hf_npsha2").val("");
		$("#npsha2").val("");
		
	});
	
	$('#email_attachment2').click( function() {
		$('#email_attachment').click();
	});
		
	//function to fill
	$('#email_attachment').change( function () {
		$('#email_attachment2').val($('#email_attachment').val());

	});
	
	
	/* This starts the functions for the Affinity Table */
	
	var combined_ratio;
	var c_value 
	
	function checkDependentFields() {
		
		var i;
		
		combined_ratio = $('#rpm_ratio').val()*$('#dia_ratio').val();
		if ($('#rpm_ratio').val() != '' && $('#dia_ratio').val() != '')
		{
			
			combined_ratio = $('#rpm_ratio').val()*$('#dia_ratio').val();
			$('#combined_ratio').val(combined_ratio.toPrecision(3));
			
			//These are the values for the lower tables
			c_value = $('#combined_ratio').val(); //c value
			
			for ( i = 1; i <= 16; i++ ) {
				$('#c' + i).val(c_value);
		
				if ($('#gpm1_' + i).val() != '')
				{
					var gpm2_val = c_value*$('#gpm1_' + i).val();
					$('#gpm2_' + i).val(gpm2_val.toFixed(1));
				}
				
				if ($('#tdh1_' + i).val() != '')
				{
					var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_' + i).val();
					$('#tdh2_' + i).val(tdh2_val.toFixed(1));
				}
				if ($('#bhp1_' + i).val() != '')
				{
					var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_' + i).val();
					$('#bhp2_' + i).val(bhp2_val.toFixed(1));
				}
			}
		}
		else
		{
			$('#combined_ratio').val('');
			for ( i = 1; i <= 16; i++ ) {
				$('#c' + i).val('');
				$('#gpm2_' + i).val('');
				$('#tdh2_' + i).val('');
				$('#bhp2_' + i).val('');
			}
		}
		
	}
	
	//These are the top RPM calculations
	$('#old_rpm').blur( function () {
		
		var rpm_ratio = $('#new_rpm').val()/$('#old_rpm').val();
		
		if ( rpm_ratio > 0 && isFinite(rpm_ratio)) 
		{
			$('#rpm_ratio').val(rpm_ratio.toPrecision(3));
		}
		else
		{
			$('#rpm_ratio').val('');
		}
		
		checkDependentFields();
	});
	
	$('#new_rpm').blur( function () {
		
		var rpm_ratio = $('#new_rpm').val()/$('#old_rpm').val();
		
		if ( rpm_ratio > 0 && isFinite(rpm_ratio)) 
		{
			$('#rpm_ratio').val(rpm_ratio.toPrecision(3));
		}
		else
		{
			$('#rpm_ratio').val('');
		}
		
		checkDependentFields();
	});
	
	//These are the top DIA calculations
	$('#old_dia').blur( function () {
		
		var dia_ratio = $('#new_dia').val()/$('#old_dia').val();
		
		if ( dia_ratio > 0 && isFinite(dia_ratio))
		{
			$('#dia_ratio').val(dia_ratio.toPrecision(3));
		}
		else
		{
			$('#dia_ratio').val('');
		}
		
		checkDependentFields();
		
		
	});
	
	$('#new_dia').blur( function () {
		
		var dia_ratio = $('#new_dia').val()/$('#old_dia').val();
		
		if ( dia_ratio > 0 && isFinite(dia_ratio))
		{
			$('#dia_ratio').val(dia_ratio.toPrecision(3));
		}
		else
		{
			$('#dia_ratio').val('');
		}
		
		checkDependentFields();

	});
	
	
	//This starts the table below the top table 
	
		//GPM1 Input
		$('#gpm1_1').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_1').val() != '')
			{				var gpm2_val = c_value*$('#gpm1_1').val();
				$('#gpm2_1').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_1').val('');
			}
	
		});
		
		//TDH1 Input
		$('#tdh1_1').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_1').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_1').val();
				$('#tdh2_1').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_1').val('');
			}
			
			
	
		});
		
		//BHP1 Input
		$('#bhp1_1').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_1').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_1').val();
				$('#bhp2_1').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_1').val('');
			}
			
			
	
		});
		
		//GPM2 Input
		$('#gpm1_2').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_2').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_2').val();
				$('#gpm2_2').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_2').val('');
			}
			
			
	
		});
		
		//TDH2 Input
		$('#tdh1_2').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_2').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_2').val();
				$('#tdh2_2').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_2').val('');
			}
			
			
	
		});
		
		//BHP2 Input
		$('#bhp1_2').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_2').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_2').val();
				$('#bhp2_2').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_2').val('');
			}
			
			
	
		});
		
		
		//GPM3 Input
		$('#gpm1_3').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value)  && $('#gpm1_3').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_3').val();
				$('#gpm2_3').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_3').val('');
			}
			
			
	
		});
		
		//TDH3 Input
		$('#tdh1_3').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value)  && $('#tdh1_3').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_3').val();
				$('#tdh2_3').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_3').val('');
			}
			
			
	
		});
		
		//BHP3 Input
		$('#bhp1_3').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value)  && $('#bhp1_3').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_3').val();
				$('#bhp2_3').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_3').val('');
			}
			
			
	
		});
		
		//GPM4 Input
		$('#gpm1_4').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value)  && $('#gpm1_4').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_4').val();
				$('#gpm2_4').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_4').val('');
			}
			
			
	
		});
		
		//TDH4 Input
		$('#tdh1_4').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_4').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_4').val();
				$('#tdh2_4').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_4').val('');
			}
			
			
	
		});
		
		//BHP4 Input
		$('#bhp1_4').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_4').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_4').val();
				$('#bhp2_4').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_4').val('');
			}
			
			
	
		});
		
		//GPM5 Input
		$('#gpm1_5').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_5').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_5').val();
				$('#gpm2_5').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_5').val('');
			}
			
			
	
		});
		
		//TDH5 Input
		$('#tdh1_5').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_5').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_5').val();
				$('#tdh2_5').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_5').val('');
			}
			
			
	
		});
		
		//BHP5 Input
		$('#bhp1_5').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_5').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_5').val();
				$('#bhp2_5').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_5').val('');
			}
			
			
	
		});
		
		//GPM6 Input
		$('#gpm1_6').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_6').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_6').val();
				$('#gpm2_6').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_6').val('');
			}
			
			
	
		});
		
		//TDH6 Input
		$('#tdh1_6').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_6').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_6').val();
				$('#tdh2_6').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_6').val('');
			}
			
			
	
		});
		
		//BHP6 Input
		$('#bhp1_6').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_6').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_6').val();
				$('#bhp2_6').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_6').val('');
			}
			
			
	
		});
		
		//GPM7 Input
		$('#gpm1_7').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_7').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_7').val();
				$('#gpm2_7').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_7').val('');
			}
			
			
	
		});
		
		//TDH7 Input
		$('#tdh1_7').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_7').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_7').val();
				$('#tdh2_7').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_7').val('');
			}
			
			
	
		});
		
		//BHP7 Input
		$('#bhp1_7').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_7').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_7').val();
				$('#bhp2_7').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_7').val('');
			}
			
			
	
		});
		
		//GPM8 Input
		$('#gpm1_8').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_8').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_8').val();
				$('#gpm2_8').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_8').val('');
			}
			
			
	
		});
		
		//TDH8 Input
		$('#tdh1_8').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_8').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_8').val();
				$('#tdh2_8').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_8').val('');
			}
			
			
	
		});
		
		//BHP8 Input
		$('#bhp1_8').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_8').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_8').val();
				$('#bhp2_8').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_8').val('');
			}
			
			
	
		});
		
		//GPM9 Input
		$('#gpm1_9').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_9').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_9').val();
				$('#gpm2_9').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_9').val('');
			}
			
			
	
		});
		
		//TDH9 Input
		$('#tdh1_9').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_9').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_9').val();
				$('#tdh2_9').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_9').val('');
			}
			
			
	
		});
		
		//BHP9 Input
		$('#bhp1_9').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_9').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_9').val();
				$('#bhp2_9').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_9').val('');
			}
			
			
	
		});
		
		//GPM10 Input
		$('#gpm1_10').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_10').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_10').val();
				$('#gpm2_10').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_10').val('');
			}
			
			
	
		});
		
		//TDH10 Input
		$('#tdh1_10').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_10').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_10').val();
				$('#tdh2_10').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_10').val('');
			}
			
			
	
		});
		
		//BHP10 Input
		$('#bhp1_10').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_10').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_10').val();
				$('#bhp2_10').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_10').val('');
			}
			
			
	
		});
		
		//GPM11 Input
		$('#gpm1_11').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_11').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_11').val();
				$('#gpm2_11').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_11').val('');
			}
			
			
	
		});
		
		//TDH11 Input
		$('#tdh1_11').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_11').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_11').val();
				$('#tdh2_11').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_11').val('');
			}
			
			
	
		});
		
		//BHP11 Input
		$('#bhp1_11').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_11').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_11').val();
				$('#bhp2_11').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_11').val('');
			}
			
			
	
		});
		
		//GPM12 Input
		$('#gpm1_12').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_12').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_12').val();
				$('#gpm2_12').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_12').val('');
			}
			
			
	
		});
		
		//TDH12 Input
		$('#tdh1_12').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_12').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_12').val();
				$('#tdh2_12').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_12').val('');
			}
			
			
	
		});
		
		//BHP12 Input
		$('#bhp1_12').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_12').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_12').val();
				$('#bhp2_12').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_12').val('');
			}
			
			
	
		});
		
		//GPM13 Input
		$('#gpm1_13').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_13').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_13').val();
				$('#gpm2_13').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_13').val('');
			}
			
			
	
		});
		
		//TDH13 Input
		$('#tdh1_13').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_13').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_13').val();
				$('#tdh2_13').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_13').val('');
			}
			
			
	
		});
		
		//BHP13 Input
		$('#bhp1_13').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_13').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_13').val();
				$('#bhp2_13').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_13').val('');
			}
			
			
	
		});
		
		//GPM14 Input
		$('#gpm1_14').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_14').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_14').val();
				$('#gpm2_14').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_14').val('');
			}
			
			
	
		});
		
		//TDH14 Input
		$('#tdh1_14').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_14').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_14').val();
				$('#tdh2_14').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_14').val('');
			}
			
			
	
		});
		
		//BHP14 Input
		$('#bhp1_14').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_14').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_14').val();
				$('#bhp2_14').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_14').val('');
			}
			
			
	
		});
		
		//GPM15 Input
		$('#gpm1_15').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_15').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_15').val();
				$('#gpm2_15').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_15').val('');
			}
			
			
	
		});
		
		//TDH15 Input
		$('#tdh1_15').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_15').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_15').val();
				$('#tdh2_15').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_15').val('');
			}
			
			
	
		});
		
		//BHP15 Input
		$('#bhp1_15').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_15').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_15').val();
				$('#bhp2_15').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_15').val('');
			}
			
			
	
		});
		
		//GPM16 Input
		$('#gpm1_16').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#gpm1_16').val() != '')
			{
				var gpm2_val = c_value*$('#gpm1_16').val();
				$('#gpm2_16').val(gpm2_val.toFixed(1));
			}
			else
			{
				$('#gpm2_16').val('');
			}
			
			
	
		});
		
		//TDH16 Input
		$('#tdh1_16').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#tdh1_16').val() != '')
			{
				var tdh2_val = Math.pow(c_value, 2)*$('#tdh1_16').val();
				$('#tdh2_16').val(tdh2_val.toFixed(1));
			}
			else
			{
				$('#tdh2_16').val('');
			}
			
			
	
		});
		
		//BHP16 Input
		$('#bhp1_16').blur( function () {
						
			if ( c_value > 0 && isFinite(c_value) && $('#bhp1_16').val() != '')
			{
				var bhp2_val = Math.pow(c_value, 3)*$('#bhp1_16').val();
				$('#bhp2_16').val(bhp2_val.toFixed(1));
			}
			else
			{
				$('#bhp2_16').val('');
			}
			
			
	
		});


});
