﻿function Calculate1()
{
	var no_fixtures1, hrs_yr1, cost_kwh1, watts1_1, watts2_1, invst1;
	var s_perfix$1, s_sitecost1_1, s_sitecost2_1, s_sav_yr1, s_recoup1, s_res1, s_res2_1;

  			no_fixtures1 = document.getElementById('rahmform1').no_fixtures1.value;
  			hrs_yr1 = document.getElementById('rahmform1').hrs_yr1.value;
			cost_kwh1 = document.getElementById('rahmform1').cost_kwh1.value;
			watts1_1 = document.getElementById('rahmform1').watts1_1.value;
			watts2_1 = document.getElementById('rahmform1').watts2_1.value;
			invst1 = document.getElementById('rahmform1').invst1.value;

			if ( watts1_1 == "" )
   				{alert("Please enter the wattage of the existing fixture");
					return;}
       		
			//if ( watts2_1 == "" )
          //		{alert("Please enter the wattage of the proposed fixture");
					//return;}
 			else if ( no_fixtures1 == "" )
          		{alert("Please enter the number of fixtures at the site");
            		return;	}
             else{
				s_perfix$1 = Math.round((watts1_1 - watts2_1)*(hrs_yr1)*(cost_kwh1)/10)/100;
				s_sitecost1_1 = Math.round((watts1_1)*(hrs_yr1)*(no_fixtures1)*(cost_kwh1)/10)/100;
				s_sitecost2_1 = Math.round((watts2_1)*(hrs_yr1)*(no_fixtures1)*(cost_kwh1)/10)/100;
				s_sav_yr1 = Math.round((s_sitecost1_1-s_sitecost2_1)*100)/100;

				s_res1 =(invst1/s_perfix$1)


					document.getElementById('rahmform1').s_perfix$1.value   = "£"+ s_perfix$1;
					document.getElementById('rahmform1').s_sitecost1_1.value = "£"+ s_sitecost1_1;
					document.getElementById('rahmform1').s_sitecost2_1.value = "£"+ s_sitecost2_1;
					document.getElementById('rahmform1').s_sav_yr1.value = "£"+ s_sav_yr1;


					if(invst1 !=="")
					{document.getElementById('rahmform1').s_recoup1.value = Math.round(s_res1*12) + " months ("+ Math.round(s_res1*100)/100 + " yr.)";
					}

				}

}

function Calculate2()
{
	var no_fixt1, no_fixt2, watts_per1, watts_per2;
	var s_kw1, s_kw2, s_per_ft1, s_per_ft2;


			if(document.getElementById('rahmform2').area.value == "")
				{alert("Please enter the area being evaluated");
					return;}
			area = document.getElementById('rahmform2').area.value;
			no_fixt1 = document.getElementById('rahmform2').no_fixt1.value;
			no_fixt2 = document.getElementById('rahmform2').no_fixt2.value;
			watts_per1 = document.getElementById('rahmform2').watts_per1.value;
			watts_per2 = document.getElementById('rahmform2').watts_per2.value;

			if ( no_fixt1 == "" )
   				{alert("Please enter the number of fixtures");
					return;}
       		if ( watts_per1 == "" )
          		{alert("Please enter fixture watts");
					return;}
 			else
				{s_kw1 = Math.round((no_fixt1*watts_per1)/10)/100 +" kW";
				s_kw2 = Math.round((no_fixt2*watts_per2)/10)/100 +" kW";
				s_per_ft1 = Math.round((no_fixt1*watts_per1/area)*100)/100;
				s_per_ft2 = Math.round((no_fixt2*watts_per2/area)*100)/100;

					document.getElementById('rahmform2').s_kw1.value = s_kw1;
					document.getElementById('rahmform2').s_kw2.value = s_kw2;
					document.getElementById('rahmform2').s_per_ft1.value = s_per_ft1;
					document.getElementById('rahmform2').s_per_ft2.value = s_per_ft2;



		}
}

function Calculate3(){
var area, foot_c, fixtw, per_fix, lumens, bf, hrs_yr, cost_kwh, cu;
var s_fixt, s_lamps, s_spacing, s_kw, s_energy, s_wattsper;
  			area = document.getElementById('rahmform3').area.value;
  			foot_c = document.getElementById('rahmform3').foot_c.value;
			fixtw = document.getElementById('rahmform3').lampw.value;
			per_fix = document.getElementById('rahmform3').per_fix.value;
			lumens = document.getElementById('rahmform3').lumens.value;
			bf = document.getElementById('rahmform3').bf.value;
			hrs_yr = document.getElementById('rahmform3').hrs_yr.value;
			cost_kwh = document.getElementById('rahmform3').cost_kwh.value;
			lumens = document.getElementById('rahmform3').lumens.value;
			cu = document.getElementById('rahmform3').cu.value;

			if ( foot_c == "" )
   				{alert("Please enter the desired foot-candles; typical indoors ~ 50 foot-candles");
					return;}
       		if ( fixtw == "" )
          		{alert("Please enter the watts associated with each fixture (including ballast losses)")
					return;}
 			else if ( lumens == "" )
          		{alert("Please enter the rated mean lumens per lamp");
            		return;	}
             else{
				s_fixt = Math.round((area*foot_c)/(lumens*bf*cu*per_fix));
				s_lamps = Math.round(s_fixt*per_fix);
				s_spacing = Math.round((Math.sqrt(area/s_fixt))*10)/10;
				s_kw = Math.round(fixtw*s_fixt*100)/100000;
				s_energy = Math.round(s_kw*hrs_yr*cost_kwh*100)/100;
				s_wattsper = Math.round((fixtw*s_fixt/area)*100)/100;

					document.getElementById('rahmform3').s_fixt.value   = s_fixt;
					document.getElementById('rahmform3').s_lamps.value = s_lamps;
					document.getElementById('rahmform3').s_spacing.value = s_spacing + " ft.";
					document.getElementById('rahmform3').s_kw.value = s_kw;
					document.getElementById('rahmform3').s_energy.value = "£"+ s_energy;
					document.getElementById('rahmform3').s_wattsper.value = s_wattsper;



		}
}

function Calculate4()
{
	var lamps1, lamps2, lumens1, lumens2, bf1, bf2, cu1, cu2, no_fixt1;
	var s_fixtlum1, s_fixtlum2, s_usablelum1, s_usablelum2, s_no_fixt2, s_change;

			lamps1 = document.getElementById('rahmform4').lamps1.value;
			lamps2 = document.getElementById('rahmform4').lamps2.value;
			lumens1 = document.getElementById('rahmform4').lumens1.value;
			lumens2 = document.getElementById('rahmform4').lumens2.value;
			bf1 = document.getElementById('rahmform4').bf1.value;
			bf2 = document.getElementById('rahmform4').bf2.value;
			cu1 = document.getElementById('rahmform4').cu1.value;
			cu2 = document.getElementById('rahmform4').cu2.value;
			no_fixt1 = document.getElementById('rahmform4').no_fixt1.value;
			if ( lamps1 == "" )
   				{alert("Please enter the no. of lamps per fixture (existing.");
					return;}
       		if ( lamps2 == "" )
          		{alert("Please enter the no. of lamps per fixture (proposed).");
					return;}
 			else if ( lumens1 == "" )
          		{alert("Please enter the rated mean lumens per lamp");
            		return;	}
             else{
				s_fixtlum1 = Math.round(lamps1*lumens1*bf1);
				s_fixtlum2 = Math.round(lamps2*lumens2*bf2);
				s_usablelum1 = Math.round(s_fixtlum1*cu1);
				s_usablelum2 = Math.round(s_fixtlum2*cu2);
				s_no_fixt2 = Math.round(no_fixt1*s_usablelum1/s_usablelum2);
				s_change = Math.round(s_usablelum2*100/s_usablelum1);

					document.getElementById('rahmform4').s_fixtlum1.value   = s_fixtlum1;
					document.getElementById('rahmform4').s_fixtlum2.value = s_fixtlum2;
					document.getElementById('rahmform4').s_usablelum1.value = s_usablelum1;
					document.getElementById('rahmform4').s_usablelum2.value = s_usablelum2;
					document.getElementById('rahmform4').s_no_fixt2.value = s_no_fixt2;
					document.getElementById('rahmform4').s_change.value = s_change+ "%";
				}
}

function Calculate5(){
var cost_kwh, full_watts, no_fixt, percent1, percent2, time_full, time1, time2;
var s_fraction, s_percent_dim, s_watts_full, s_watts_dim, s_load_full, s_load_dim, s_load_sav;

			cost_kwh = document.getElementById('rahmform5').cost_kwh.value;
			full_watts = document.getElementById('rahmform5').full_watts.value;
  			no_fixt = document.getElementById('rahmform5').no_fixt.value;
			percent1 = document.getElementById('rahmform5').percent1.value;
			percent2 = document.getElementById('rahmform5').percent2.value;
			time_full = document.getElementById('rahmform5').time_full.value;
			time1 = document.getElementById('rahmform5').time1.value;
			time2 = document.getElementById('rahmform5').time2.value;


			if( cost_kwh == "" )
				{alert("Please enter the energy rate (cost per kwh).");
					return;}
			if ( full_watts == "" )
   				{alert("Please enter the Fixture Watts at Full Power.");
					return;}
       		if ( no_fixt == "" )
          		{alert("Please enter the number of fixtures being considered.");
					return;}
 			if ( time_full == "" )
          		{alert("Please enter the percent of time lamps are operated at full power.");
            		return;	}
			if (( time_full*1 + time1*1 + time2*1)!= 100)
          		{alert("The totals of the times at different settings does not add up to 100%.");
            		return;	}
             else{
				s_fraction = (100*(time_full) + (percent1)*(time1) + (percent2)*(time2))/100
				s_percent_dim = Math.round(s_fraction) + "%";
				s_watts_full = Math.round(full_watts);
				s_watts_dim = Math.round(full_watts*s_fraction/100);
				s_load_full = Math.round(full_watts*no_fixt/10)/100;
				s_load_dim = Math.round(s_watts_dim*no_fixt/10)/100;
				s_load_sav = Math.round((s_load_full - s_load_dim)*100)/100;
				//s_save_dollars = Math.round(s_load_sav*cost_kwh);
				s_save_dollars = s_load_sav*cost_kwh;

					document.getElementById('rahmform5').s_percent_dim.value   = s_percent_dim;
					document.getElementById('rahmform5').s_watts_full.value = s_watts_full;
					document.getElementById('rahmform5').s_watts_dim.value = s_watts_dim;
					document.getElementById('rahmform5').s_load_full.value = s_load_full + " kW";
					document.getElementById('rahmform5').s_load_dim.value = s_load_dim + " kW";
					document.getElementById('rahmform5').s_load_sav.value = s_load_sav + " kW";
					document.getElementById('rahmform5').s_save_dollars.value = "£" + s_save_dollars + "/hr";


		}
}

function Calculate6()
{
	var no_fixtures6, hrs_yr6, cost_kwh6, watts1_6, watts2_6;
	var s_sitecost1_6, s_sitecost2_6, s_cost_yr6, s_cost_mo6;

  			no_fixtures6 = document.getElementById('rahmform6').no_fixtures6.value;
  			hrs_yr6 = document.getElementById('rahmform6').hrs_yr6.value;
			cost_kwh6 = document.getElementById('rahmform6').cost_kwh6.value;
			watts1_6 = document.getElementById('rahmform6').watts1_6.value;
			watts2_6 = document.getElementById('rahmform6').watts2_6.value;

			if ( watts1_6 == "" )
   				{alert("Please enter the wattage of the existing fixture");
					return;}
       	//	if ( watts2_6 == "" )
          //		{alert("Please enter the wattage of the proposed fixture");
				//	return;}
 			else if ( no_fixtures6 == "" )
          		{alert("Please enter the number of fixtures at the site");
            		return;	}
             else{
				s_sitecost1_6 = Math.round((watts1_6)*(hrs_yr6)*(no_fixtures6)*(cost_kwh6)/10)/100;
				s_sitecost2_6 = Math.round((watts2_6)*(hrs_yr6)*(no_fixtures6)*(cost_kwh6)/10)/100;
				s_cost_yr6 = Math.round((s_sitecost1_6-s_sitecost2_6)*100)/100;
				s_cost_mo6 = Math.round((s_cost_yr6/12)*100)/100

					document.getElementById('rahmform6').s_sitecost1_6.value = "£"+ s_sitecost1_6;
					document.getElementById('rahmform6').s_sitecost2_6.value = "£"+ s_sitecost2_6;
					document.getElementById('rahmform6').s_cost_yr6.value = "£"+ s_cost_yr6;
					document.getElementById('rahmform6').s_cost_mo6.value = "£"+ s_cost_mo6;



				}
}

function Calculate7()
{
	var hrs_yr_7, cost_kwh_7, wattsA_7, wattsB_7, costA_7, costB_7, lifeA_7, lifeB_7, laborA_7, laborB_7, lumensA_7, lumensB_7;
	var s_costA1_7, s_costB1_7, s_costA2_7, s_costB2_7,s_costA3_7,s_costB3_7, s_sav_7;
	var name_A_7, name_B_7;

			if(document.getElementById('rahmform7').cost_kwh_7.value == "")
				{alert("Please enter the energy rate (cost per kwh).");
					return;}
			if(document.getElementById('rahmform7').lifeA_7.value == "")
				{alert("Please enter the rated life of lamp A.");
					return;}
			hrs_yr_7 = document.getElementById('rahmform7').hrs_yr_7.value;
			cost_kwh_7 = document.getElementById('rahmform7').cost_kwh_7.value;
			wattsA_7 = document.getElementById('rahmform7').wattsA_7.value;
			wattsB_7 = document.getElementById('rahmform7').wattsB_7.value;
			costA_7 = document.getElementById('rahmform7').costA_7.value;
			costB_7 = document.getElementById('rahmform7').costB_7.value;
			lifeA_7 = document.getElementById('rahmform7').lifeA_7.value;
			lifeB_7 = document.getElementById('rahmform7').lifeB_7.value;
			laborA_7 = document.getElementById('rahmform7').laborA_7.value;
			laborB_7 = document.getElementById('rahmform7').laborB_7.value;
			lumensA_7 = document.getElementById('rahmform7').lumensA_7.value;
			lumensB_7 = document.getElementById('rahmform7').lumensB_7.value;

			name_A_7 = document.getElementById('rahmform7').name_A_7.value;
			name_B_7 = document.getElementById('rahmform7').name_B_7.value;

				s_costA1_7 = costA_7*1 + laborA_7*1 + (wattsA_7*lifeA_7*cost_kwh_7/1000);
				s_costB1_7 = costB_7*1 + laborB_7*1 + (wattsB_7*lifeB_7*cost_kwh_7/1000);
				s_costA2_7 = s_costA1_7*1000/lifeA_7
				s_costB2_7 = s_costB1_7*1000/lifeB_7
				s_costA3_7 = s_costA2_7*hrs_yr_7/1000
				s_costB3_7 = s_costB2_7*hrs_yr_7/1000
				s_costA4_7 = s_costA2_7*1000/lumensA_7
				s_costB4_7 = s_costB2_7*1000/lumensB_7
				s_sav_7 = s_costA3_7 - s_costB3_7

				if(name_A_7 !="") document.getElementById('rahmform7').name_A2_7.value = name_A_7;
				if(name_B_7 !="")document.getElementById('rahmform7').name_B2_7.value = name_B_7;

				if(lifeA_7 != "")
					{document.getElementById('rahmform7').s_costA1_7.value = "£" + Math.round(s_costA1_7*100)/100 ;
					document.getElementById('rahmform7').s_costA2_7.value = "£" + Math.round(s_costA2_7*100)/100;
					document.getElementById('rahmform7').s_costA3_7.value = "£" + Math.round(s_costA3_7*100)/100;
					}

				if(lifeB_7 != "")
					{document.getElementById('rahmform7').s_costB1_7.value = "£" + Math.round(s_costB1_7*100)/100;
					document.getElementById('rahmform7').s_costB2_7.value = "£" + Math.round(s_costB2_7*100)/100;
					document.getElementById('rahmform7').s_costB3_7.value = "£" + Math.round(s_costB3_7*100)/100;
					document.getElementById('rahmform7').s_sav_7.value = "£" + Math.round(s_sav_7*100)/100;
						if(lumensB_7 != "")
							{document.getElementById('rahmform7').s_costB4_7.value = "£" + Math.round(s_costB4_7*100)/100;}
					}
				if(lumensA_7 != "")
					{document.getElementById('rahmform7').s_costA4_7.value = "£" + Math.round(s_costA4_7*100)/100;
					}





}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='Please use only numbers.';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert(errors);
  document.MM_returnValue = (errors == '');
}