// JavaScript Document

function gas_calc() {
	temperature_rise = document.getElementById('tbx_temp2').value;
	gasvalue = document.getElementById('gasType2').value;
	
	alert_msg = "";
	check = "ok";
	if (temperature_rise == null)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}
	if (temperature_rise < 20)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}
	if (temperature_rise > 70)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}

	if (gasvalue == null)
	{
		alert_msg = alert_msg+'\n'+"Please select a Gas Types for this water heater.";
		check = "bad";
	}

	if (check == "bad"){
		alert(alert_msg);
	}

		if (document.getElementById('ddl_units2').selectedIndex == 0) {
		parallel = "1";
		}
		if (document.getElementById('ddl_units2').selectedIndex == 1) {
		parallel = "2";
		}
		if (document.getElementById('ddl_units2').selectedIndex == 2) {
		parallel = 3;
		}
		if (document.getElementById('ddl_units2').selectedIndex == 3) {
		parallel = 4;
		}
		if (document.getElementById('ddl_units2').selectedIndex == 4) {
		parallel = 5;
		}
		if (document.getElementById('ddl_units2').selectedIndex == 5) {
		parallel = 6;
		}
		if (document.getElementById('ddl_units2').selectedIndex == 6) {
		parallel = 7;
		}
		if (document.getElementById('ddl_units2').selectedIndex == 7) {
		parallel = 8;
		}

	
	if (check == "ok") {
	storage_capacity = parallel * document.getElementById('cap2').value;

	hourly_thermal_input = gasvalue * parallel;

	efficiency = document.getElementById('eff2').value/100;

	max_hr_top = hourly_thermal_input * efficiency;
	max_hr_bottom = 0.004186 * temperature_rise;
	max_hourly_recovery1 = max_hr_top/max_hr_bottom;
	max_hourly_recovery = Math.round(max_hourly_recovery1*Math.pow(10,0))/Math.pow(10,0)

	first_hour1 = document.getElementById('del2').value * parallel;
	first_hour_delivery = max_hourly_recovery + first_hour1;

	document.getElementById('tbx_t2_2_1').value = storage_capacity;
	document.getElementById('tbx_t2_2_2').value = hourly_thermal_input;
	document.getElementById('tbx_t2_2_3').value = max_hourly_recovery;
	document.getElementById('tbx_t2_2_4').value = first_hour_delivery;
	}
}

function elec_calc() {

	temperature_rise = document.getElementById('tbx_temp').value;
	element_array = document.getElementById('element_array').value;

	alert_msg = "";
	check = "ok";
	if (temperature_rise == null)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}
	if (temperature_rise < 20)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}
	if (temperature_rise > 70)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}

	if (element_array == null)
	{
		alert_msg = alert_msg+'\n'+"Please select an Input for this water heater.";
		check = "bad";
	}

	if (check == "bad"){
		alert(alert_msg);
	}

		if (document.getElementById('ddl_units').selectedIndex == 0) {
		parallel = "1";
		}
		if (document.getElementById('ddl_units').selectedIndex == 1) {
		parallel = "2";
		}
		if (document.getElementById('ddl_units').selectedIndex == 2) {
		parallel = 3;
		}
		if (document.getElementById('ddl_units').selectedIndex == 3) {
		parallel = 4;
		}
		if (document.getElementById('ddl_units').selectedIndex == 4) {
		parallel = 5;
		}
		if (document.getElementById('ddl_units').selectedIndex == 5) {
		parallel = 6;
		}
		if (document.getElementById('ddl_units').selectedIndex == 6) {
		parallel = 7;
		}
		if (document.getElementById('ddl_units').selectedIndex == 7) {
		parallel = 8;
		}
	    if (document.getElementById('ddl_input').selectedIndex == 0) {
    	    input = 3.6;
	    }
	    if (document.getElementById('ddl_input').selectedIndex == 1) {
    	    input = 4.8;
	    }
	    if (document.getElementById('ddl_input').selectedIndex == 2) {
    	    input = 6.0;
	    }	    	    
	    
	delivery = parallel * document.getElementById('del').value;
	maximum_load = element_array * parallel;
	efficency = document.getElementById('eff').value/100;

	max_hour_top = maximum_load * 3.6 * efficency;
	max_hour_bottom = 0.004186 * temperature_rise;

	max_hour_recovery1 = max_hour_top/max_hour_bottom;
	max_hour_recovery = Math.round(max_hour_recovery1*Math.pow(10,0))/Math.pow(10,0);
	
	max_hour_recovery = parallel * element_array * 3.6;
    max_hour_recovery2 = Math.round(max_hour_recovery * input);
    max_hour_recovery1 = 0.004186 * document.getElementById('tbx_temp').value;
    
    max_hour_recovery = Math.round(max_hour_recovery2 / max_hour_recovery1);

	first_hour_delivery2 = max_hour_recovery + delivery;
	first_hour_delivery = Math.round(first_hour_delivery2*Math.pow(10,0))/Math.pow(10,0);

	
	if (check == "ok") {
	//output values to the form
	    document.getElementById('tbx_t2_1').value = delivery;
	    document.getElementById('tbx_t2_2').value = max_hour_recovery;
	    document.getElementById('tbx_t2_3').value = first_hour_delivery;
	}

}

function raypak_calc(){
	temperature_rise = eval(document.tech_table.temp_rise2.value);
	gasvalue = eval(document.tech_table.gas_type2.value);
	outputvalue = eval(document.tech_table.output2.value);
	minbuffervalue = eval(document.tech_table.min_buffer.value);
	
	alert_msg = "";
	check = "ok";
	if (temperature_rise == null)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}
	if (temperature_rise < 20)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}
	if (temperature_rise > 70)
	{
		alert_msg = "Sorry, your temperature rise is out of range."+'\n'+"Temperature rise must be a numeric value between 20 and 70.";
		check = "bad";

	}

	if (gasvalue == null)
	{
		alert_msg = alert_msg+'\n'+"Please select a Gas Types for this water heater.";
		check = "bad";
	}

	if (check == "bad"){
		alert(alert_msg);
	}

		if (document.tech_table.parallel.selectedIndex == 0) {
		parallel = "1";
		}
		if (document.tech_table.parallel.selectedIndex == 1) {
		parallel = "2";
		}
		if (document.tech_table.parallel.selectedIndex == 2) {
		parallel = 3;
		}
		if (document.tech_table.parallel.selectedIndex == 3) {
		parallel = 4;
		}
		if (document.tech_table.parallel.selectedIndex == 4) {
		parallel = 5;
		}
		if (document.tech_table.parallel.selectedIndex == 5) {
		parallel = 6;
		}
		if (document.tech_table.parallel.selectedIndex == 6) {
		parallel = 7;
		}
		if (document.tech_table.parallel.selectedIndex == 7) {
		parallel = 8;
		}

	
	if (check == "ok") {
	storage_capacity = parallel * eval(document.tech_table.capacity.value);

	hourly_thermal_input = gasvalue * parallel;

	efficiency = eval(document.tech_table.efficency.value)/100;

	max_hr_top = hourly_thermal_input * efficiency;
	max_hr_bottom = 0.004186 * temperature_rise;
	max_hourly_recovery1 = max_hr_top/max_hr_bottom;
	max_hourly_recovery = Math.round(max_hourly_recovery1*Math.pow(10,0))/Math.pow(10,0)

	first_hour1 = eval(document.tech_table.delivery.value) * parallel;
	first_hour_delivery = max_hourly_recovery + first_hour1;
	
	output_final = outputvalue * parallel;
	
	buffer_final = minbuffervalue * parallel;

	//output values to the form
	document.tech_table.buffer_storage.value = buffer_final;
	document.tech_table.output.value = output_final;
	document.tech_table.storage.value = storage_capacity;
	document.tech_table.hourly_input.value = hourly_thermal_input;
	document.tech_table.hourly_recovery.value = max_hourly_recovery;
	// document.tech_table.first_hr_delivery.value = first_hour_delivery;
	}
}
