
Footprint = function()
{
	this.emissionFactors = 	[ 120.161, 1.37, 22.28];
	this.unitPrice = 		[13.83, 0.1,2.37];
}

Footprint.GAS=0;
Footprint.ELECTRIC=1;
Footprint.OIL=2;

Footprint.MAXEMISSIONS = 286103;
Footprint.MAXGREEN = 11425;

Footprint.GREENTARGET=50000;

Footprint.BARWIDTH=320;

Footprint.MAXREDUCTIONS = 17463;

Footprint.MULTIPLIER=12;

function nextStep()
{
	document.frm.action = "eco-calculator/home-upgrade-calculator.php";
	document.frm.submit();
	
	
}

Footprint.prototype.Update = function(text,index)
{
	if(index==undefined){
		
	}else{

	var combo = "hd_selection"+index;
	
	elem = document.getElementById(combo);
 	elem.value = text;
	
	}

	new Effect.Morph('costEl',{
        style:'width:'+parseInt(this.GetEmissions()/Footprint.MAXEMISSIONS * Footprint.BARWIDTH)+"px",
            duration:1
    });
    
    
    new Effect.Morph('ecoRebateEl',{
        style:'width:'+parseInt(this.GetReductions()/Footprint.MAXEMISSIONS * Footprint.BARWIDTH)+"px",
            duration:1
    });

    var newEmissions = this.GetEmissions()-this.GetReductions();
    
    new Effect.Morph('newCostEl',{
        style:'width:'+parseInt(newEmissions/Footprint.MAXEMISSIONS * Footprint.BARWIDTH)+"px",
            duration:1
    });
    
    $("newCostEl").innerHTML = parseInt(newEmissions) + "lbs";
    $("costEl").innerHTML = parseInt(this.GetEmissions()) + "lbs";
    $("ecoRebateEl").innerHTML = parseInt(this.GetReductions()) + "lbs";
    leafBrightness = this.GetReductions()/Footprint.MAXREDUCTIONS;
    
    new Effect.Opacity('leaf', {duration:0.5, to:leafBrightness});
    
    var skyBrightness = Math.abs(1 - (newEmissions - 40000) / 60000);
    //alert(skyBrightness);
    new Effect.Opacity('skydiv', {duration:0.5, to:Math.min(Math.max(leafBrightness,0.2),0.75)});
    
    
    
    var percent = parseInt(this.GetReductions()/this.GetEmissions()*100);
    if (percent > 0)
    {
    	$("ImprovementEl").innerHTML = "YOU'VE IMPROVED " + percent + "%";
	}
	else
	{
		$("ImprovementEl").innerHTML ="";
	}
	
}

Footprint.prototype.GetHeatType = function()
{
	return parseInt($("HeatTypeList").value);
}

Footprint.prototype.GetCost = function(heatType)
{
	return parseInt($("Costs"+heatType).value);
}

Footprint.prototype.GetPeopleInHome = function()
{
	return parseInt($("NumPeople").value);
}


Footprint.prototype.GetThermoDown = function()
{
	return parseInt($("ThermoDown").value);
}


/*Footprint.prototype.GetEmissions = function()
{
	var total=0;
	for (var i = 0;i < this.emissionFactors.length; i++)
	{
		total+=(this.GetCost(i)/this.unitPrice[i]) * this.emissionFactors[i] * Footprint.MULTIPLIER
	}
	return total;
}*/

Footprint.prototype.GetBaseEmissions = function()
{
	return this.GetPeopleInHome() * 1018;
}

Footprint.prototype.GetEmission = function(heatType)
{
	return (this.GetCost(heatType)/this.unitPrice[heatType]) * this.emissionFactors[heatType] * Footprint.MULTIPLIER
}

Footprint.prototype.GetEmissions = function()
{
	return this.GetEmission(Footprint.GAS) + this.GetEmission(Footprint.OIL) + this.GetEmission(Footprint.ELECTRIC)  + this.GetBaseEmissions();
}

Footprint.prototype.GetReductions = function()
{
	return this.GetThermoReduction() + this.GetLightsReduction() + this.GetFridgeReduction() + this.GetFurnaceReduction() + this.GetAirConReduction() + this.GetWindowsReduction();
}

Footprint.prototype.GetThermoReduction = function()
{
	var emissions = this.GetEmission(this.GetHeatType());
	
	switch(this.GetHeatType())
	{
		case Footprint.GAS:
		{
			return this.GetThermoDown() * 0.42 * 0.01 * this.GetEmissions();
			break;
		}
		case Footprint.ELECTRIC:
		{
			return this.GetThermoDown() * 0.33 * 0.01 * this.GetEmissions();
			break;
		}
		case Footprint.OIL:
		{
			return this.GetThermoDown() * 0.42 * 0.01 * this.GetEmissions();
			break;
		}
	}	
	throw "Please select how your home is heated."
}

Footprint.prototype.GetLightsReduction = function()
{
	return parseInt($("LightBulbs").value) * 73 * 1.37;
}

Footprint.prototype.GetFridgeReduction = function(cost)
{
	return ($("Fridge").checked ? 521 : 0);	
}

Footprint.prototype.GetFurnaceReduction = function(cost)
{
	var h = this.GetHeatType();
	var reduction = [3011,0,4154];
	return ($("Furnace").checked ?  reduction[h]  : 0);	
}

Footprint.prototype.GetAirConReduction = function(cost)
{
	return parseInt($("AirCon").value) *0.16*0.05*0.42*this.GetEmission(Footprint.ELECTRIC);
}

Footprint.prototype.GetWindowsReduction = function(cost)
{
	var h = this.GetHeatType();
	var reduction = [3320,3884,4577];
	return ($("Windows").checked ?  reduction[h]  : 0);	
}


