/*-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
  -- Web Site:  http://www7.ewebcity.com/cyanide7 --> 
  -- This script and many more are available free online at -->
  -- The JavaScript Source!! http://javascript.internet.com */

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
	num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
	cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function SetRegion(id){
  document.form.region.value=(id);
  CalcAll();
}

function GetGasCost(){
  if (eval("document.form.gasCost.value") ==''){
    alert("Please enter the cost of Natural Gas in Your Area");
  } else {  
    ce = document.form.gasCost.value;
  }	  
  return ce;
}

function GetPoolArea(){
  if (eval("document.form.poolArea.value") ==''){
//    alert("Please enter the size of your pool in square feet");
	poolArea = 0;
  } else {  
    poolArea = document.form.poolArea.value;
  }	  
  return poolArea;
}
function GetLaborType(){
    if(document.form.labor[0].checked == true){
	laborType = 0;
    } else {
	laborType = 1;
    }
    return laborType;
}
function GetLaborCost(){
    if (GetLaborType() == 0){
	// Union Labor
	cph = 19;	
    } else {
	// NonUnion Labor
	cph = 11;
    }
    return cph;
}
function GetCostInMBtu(){
	ce=GetGasCost();
	/* Multiplier for MBTU/THERM/FT^3 */
	/*  document.form.thermalUnits[1].checked == true ? ce = ce*10: ce=ce; */
  	if(document.form.thermalUnits[0].checked == true){
    	ce=ce;
  	} else if(document.form.thermalUnits[1].checked == true){
    	ce=ce*10;
  	} else {/*  document.form.thermalUnits[2].checked == true  */
    	ce=ce*1000;
  	}
	return ce;
 }
 function GetIndoorOrOutdoor(){
	/* Indoor or Outdoor */
  	if(document.form.inOutDoor[0].checked==true) {	
		 inOut = 0; 
		 } else {
		 inOut =1;
	}
	return inOut;
}

 function CalcInstallationCost(costPerHourLabor, costPerThermal){
 	return costPerThermal * costPerHourLabor;
 }

 function CalcEnergyToPool(energyCostInMBtu){
	cost = energyCostInMBtu / 0.75;
	//	document.form.energyToPoolTherms.value = formatCurrency(cost / 10.0);
	document.getElementById("energyToPoolTherms").innerHTML = formatCurrency(cost / 10.0);
	//	document.form.energyToPoolMBtu.value = formatCurrency(cost);
	document.getElementById("energyToPoolMBtu").innerHTML = formatCurrency(cost);
 }

 function CalcInstallationCost(){
 	price = GetLaborCost() * GetPoolArea() * 0.75;
	if(price == 0){
	    //	document.form.installationCost.value = "no pool area given";
	    document.getElementById("installationCost").innerHTML = "no pool area given";
	} else {
	    //		document.form.installationCost.value = formatCurrency(price);
		document.getElementById("installationCost").innerHTML = formatCurrency(price);
	}
 }
function CalcSBP() { 
	/*  indoor(poolcover, solarheater, both), outdoor(poolcover, solarheater, both) */
  var solarNum = new Array();
  solarNum[0] = new Array( 0);
  solarNum[1]  =  new Array(411, 126, 537, 145, 78, 223);
  solarNum[2]  =  new Array(419, 256, 673, 162, 101, 262);
  solarNum[3]  =  new Array(421, 188, 588, 166, 133, 276);
  solarNum[4]  =  new Array(433, 306, 693, 182, 172, 306);
  solarNum[5]  =  new Array(379, 439, 699, 158, 166, 195);
  solarNum[6]  =  new Array(397, 320, 692, 425, 301, 676);
  solarNum[7]  =  new Array(337, 469, 668, 319, 264, 532);
  solarNum[8]  =  new Array(524, 327, 266, 832, 1082, 570);
  solarNum[9]  =  new Array(388, 251, 600, 76, 74, 93);
  solarNum[10]  = new Array(268, 393, 587, 212, 203, 337);
  solarNum[11]  = new Array(385, 202, 629, 80, 73, 98);
  solarNum[12]  = new Array(387, 225, 587, 102, 97, 159);

  cp = GetLaborCost();
  ce = GetCostInMBtu();
  inout = GetIndoorOrOutdoor();
  
  /* Calculate three erspecs */
  /* Solar Pool Cover */
  ERspec_spc = solarNum[document.form.region.value][inOut*3+0];
  //document.form.solarCover.value =((900*2)/(ERspec_spc*ce)).toFixed(1); 
  document.getElementById("solarCover").innerHTML = ((900*2)/(ERspec_spc*ce)).toFixed(1); 
  //  alert(ERspec_spc*ce*20);
  /* Solar Collector */
  ERspec_sc = solarNum[document.form.region.value][inOut*3+1];
  //document.form.solarCollector.value =((cph * 750)/(ERspec_sc*ce)).toFixed(1); 
   document.getElementById("solarCollector").innerHTML = ((cph * 750)/(ERspec_sc*ce)).toFixed(1); 
  /* Solar Pool Cover and Collector */
  ERspec_cc = solarNum[document.form.region.value][inOut*3+2];
  //document.form.coverAndCollector.value =(((900*2) + (cph * 750))/(ERspec_cc*ce)).toFixed(1); 
  document.getElementById("coverAndCollector").innerHTML = (((900*2) + (cph * 750))/(ERspec_cc*ce)).toFixed(1); 
  //  alert(ERspec_cc*ce*20);
}/* end function */    

function CalcAll(){
	CalcSBP();
	CalcInstallationCost();
	CalcEnergyToPool(GetCostInMBtu());
	CalcIndependantEnergyProvidersMBtuCost();
}

function CalcIndependantEnergyProvidersMBtuCost() { 
    /* NonUnion(indoor, outdoor), Union(indoor, outdoor) */
    /* indoor(Union, NonUnion), outdoor(Union, NonUnion) */
    var bestOffer = new Array();
    bestOffer[0] =   new Array(0);
    bestOffer[1]  =  new Array(15.80, 9.80, 25.50, 15.80);
    bestOffer[2]  =  new Array(7.60, 4.80, 19.50, 12.10);
    bestOffer[3]  =  new Array(11.30, 7.10, 16.10, 10.10);
    bestOffer[4]  =  new Array(7.70, 4.80, 13.80, 8.60);
    bestOffer[5]  =  new Array(7.90, 4.90, 20.40, 12.70);
    bestOffer[6]  =  new Array(6.10, 3.80, 6.10, 3.85);
    bestOffer[7]  =  new Array(4.35, 2.70, 7.30, 4.45);
    bestOffer[8]  =  new Array(4.70, 2.95, 5.90, 3.70);
    bestOffer[9]  =  new Array(8.00, 5.00, 27.50, 17.10);
    bestOffer[10]  = new Array(5.00, 3.10, 9.60, 6.00);
    bestOffer[11]  = new Array(7.60, 4.80, 24.20, 15.00);
    bestOffer[12]  = new Array(10.40, 6.50, 16.800, 10.50);
    // indoor or outdoor pool?
    // union/nonUnion labor ?
    inOut = GetIndoorOrOutdoor();
    labor = GetLaborType();
    IEPCostInDollersPerMBtu_v = bestOffer[document.form.region.value][inOut*2+labor];
    document.getElementById("IEPCostInDollersPerMBtu").innerHTML = formatCurrency(IEPCostInDollersPerMBtu_v);
    document.getElementById("IEPCostInDollersPerTherm").innerHTML = formatCurrency(IEPCostInDollersPerMBtu_v / 10.0);
 //  document.form.IEPCostInDollersPerMBtu.value = formatCurrency(IEPCostInDollersPerMBtu);	     
//  document.form.IEPCostInDollersPerTherm.value = formatCurrency(IEPCostInDollersPerMBtu / 10.0);	
    
    
}

