﻿  debugger;
  
  //Script for top menu
  var drdNumberOfPeopleValue;
  function ShowSection(id)
    {
        if (id!=1)
        {
            if(document.getElementById("drdHousehold").value==0)
            {
               alert("Please select the number of people in your household.");
               return false;
            }
        }
            
        if (id == 4)
        {
            var drdPayMonthly = document.getElementById("ctl00_MainContent_drdPayMonthly");
            if(drdPayMonthly.selectedIndex == drdPayMonthly.options.length - 1)
            {
                   alert("Please select the state in energy use.");
                   return false;
            }
        }
      
        document.getElementById('Cell1').className ="tab_table";
        document.getElementById('Cell2').className ="tab_table";
        document.getElementById('Cell3').className ="tab_table";
        document.getElementById('Cell4').className ="tab_table";
        document.getElementById("Cell"+id).className ="";
        document.getElementById('left1').className ="tab_border";
        document.getElementById('left2').className ="tab_border";
        document.getElementById('left3').className ="tab_border";
        document.getElementById('left4').className ="tab_border";
        document.getElementById("left"+id).className ="tab_sides_border";
        document.getElementById('right1').className ="tab_border";
        document.getElementById('right2').className ="tab_border";
        document.getElementById('right3').className ="tab_border";
        document.getElementById('right4').className ="tab_border";
        document.getElementById("right"+id).className ="tab_sides_border";
        document.getElementById('Table1').style.display ="none";
        document.getElementById('Table2').style.display ="none";
        document.getElementById('Table3').style.display ="none";
        document.getElementById('Table4').style.display ="none";
        document.getElementById("Table" + id).style.display = "block";

        ChangeTabDescriptorDiv(id);
        
        return false;
    }
    function ChangeTabDescriptorDiv(id) {
        if (id == 1) {
            document.getElementById('tabDescriptorDiv').innerHTML = "<b>How green are you?</b> Use Sterling Planet's fast and easy online calculator to measure your carbon footprint, see how your lifestyle compares to national averages, and begin the shift to carbon neutral status today.<br /><br />Once you've determined your carbon footprint, you will be able to purchase clean, renewable energy to offset your electricity use.  In addition, you will have the opportunity to purchase carbon offsets to offset the environmental impact of your driving, flying, natural gas and fuel oil use.";
        }
        else if (id == 2) {
            document.getElementById('tabDescriptorDiv').innerHTML = "How much driving and flying do you do in a week, in a month or in a year?  Provide your estimates below.";
        }
        else if (id == 3) {
            document.getElementById('tabDescriptorDiv').innerHTML = "What does it take to heat, cool and run your living space?  Enter in your estimated consumption of electricity, gas and fuel oil below.";
        }
        else if (id == 4) {
            document.getElementById('tabDescriptorDiv').innerHTML = "View your estimated emissions and then choose an offset option below to reduce your environmental footprint";
        }
    }
//Script for Get Started
    function Next_Click(id) {
        var drdHousehold = document.getElementById('drdHousehold');
        if(drdHousehold.value==0)
        {
            ShowSection(0);
            alert("Please select the number of people in your household.");
            return false;
        }  
        else {
            if (id == 1) {
                var tdCarbonTab = document.getElementById("ctl00_MainContent_tdCarbonTab");
                if (tdCarbonTab != null) {
                    if (tdCarbonTab.style.display == "none") {
                        id++;
                    }
                }
            }

            if (id == 2) {
                var tdEnergyTab = document.getElementById("ctl00_MainContent_tdEnergyTab");
                if (tdEnergyTab != null) {
                    if (tdEnergyTab.style.display == "none") {
                        id++;
                    }
                }
            }
            
            ShowSection(id+1);
        }
    }
//Script for Driving And Flying   
    function CalcCOEmission(id)
    {
        var drdDriving = document.getElementById('drdDriving['+id+']');
        var txbDrivingMiles = document.getElementById('txbDrivingMiles['+id+']');
        var drdDrivingTimeType = document.getElementById('drdDrivingTimeType['+id+']');
        var txbDrivingCO = document.getElementById('txbDrivingCO['+id+']');
        
        if (EmptyConvert(drdDriving.value)!=0)
        {
            var value = 19.4*EmptyConvert(txbDrivingMiles.value)*EmptyConvert(drdDrivingTimeType.value)/EmptyConvert(drdDriving.value)*0.000453592;
            txbDrivingCO.innerHTML = Math.round(value*100)/100;
        }
        else
        {
            txbDrivingCO.innerHTML  = 0;
            
        }
        CalcResultCOEmission();
    } 
    
    function CalcResultCOEmission()
    {
        var txbFuelOilCO = document.getElementById("txbFuelOilCO");
        var txbNaturalGasCO = document.getElementById("txbNaturalGasCO");
        var spResultDriving = document.getElementById('spResultDriving');
       
        var txbDrivingCO;
        var i;
        var value=0;
        for(i=1;i<6;i++)
        {
            txbDrivingCO = document.getElementById('txbDrivingCO['+i+']');
            value=value+(EmptyConvert(txbDrivingCO.innerHTML)-0);
        }
        spResultDriving.innerHTML = Math.round(value*100)/100;
        ShowCOSumLine();
    }
        
    function CalcCoFlying()
    {
        var txbFlyingMiles = document.getElementById('txbFlyingMiles');
        var drdFlyingTimeType = document.getElementById('drdFlyingTimeType');
        var txbFlyingCO = document.getElementById('txbFlyingCO');
        var cbxFlying = document.getElementById('cbxFlying');
        var spResultFlying = document.getElementById('spResultFlying');
        if (cbxFlying.checked)
        {
            txbFlyingCO.innerHTML = 0;
            spResultFlying.innerHTML = 0;
        }
        else
        {
            var value = EmptyConvert(txbFlyingMiles.value)*EmptyConvert(drdFlyingTimeType.value)*1.61*0.18*0.001;
            txbFlyingCO.innerHTML = Math.round(value*100)/100;
            spResultFlying.innerHTML = Math.round(value*100)/100;
        }
        ShowCOSumLine();
    }
    
    
    
    
    function AddVichle_Click()
    {
        var i = 1;
        
        var trDriving;
        for(i=1;i<6;i++)
        {
            trDriving = document.getElementById('trDriving['+i+']');
            if(trDriving.style.display=='none')
            {
                trDriving.style.display='block';
                CountVehicle=CountVehicle+1;
                if(CountVehicle==5)
                {
                    document.getElementById('AddVichle').style.display='none';      
                }
                return true;
            }
        }
    }
    
    function DeleteVichle(id)
    {
        document.getElementById('txbDrivingMiles['+id+']').value = 0;
        document.getElementById('txbDrivingCO['+id+']').innerHTML = 0;
        document.getElementById('trDriving['+id+']').style.display = 'none';
        document.getElementById('AddVichle').style.display='inline'; 
        var drdDriving = document.getElementById('drdDriving['+id+']');
        SetSelectedIndexes(drdDriving,0);
        drdDriving = document.getElementById('drdDrivingTimeType['+id+']');
        SetSelectedIndexes(drdDriving,drdDriving.options.length-1);
        CountVehicle=CountVehicle-1;
        CalcResultCOEmission();
    }
    
// Script for Energy Use Section
    
    
    function CalcCONaturalGasPay()
    {   
        var txbNaturalGasPay = document.getElementById("txbNaturalGasPay");
        var txbNaturalGasCO = document.getElementById("txbNaturalGasCO");
        var drdHousehold = document.getElementById('drdHousehold');
        var value = (12*EmptyConvert(txbNaturalGasPay.value)/12.46)*120.61*0.000453592;
        //value = Math.round(100*(value/drdHousehold.value))/100;
        value = Math.round(100*value)/100;
        txbNaturalGasCO.innerHTML = value;
        spResultNeutralGas.innerHTML = value;
        ShowCOSumLine();
    }
    
    function CalcCOFuelOil()
    {   
        var txbFuelOilPay = document.getElementById("txbFuelOilPay");
        var txbFuelOilCO = document.getElementById("txbFuelOilCO");
        var drdHousehold = document.getElementById('drdHousehold');
        var value = (12*EmptyConvert(txbFuelOilPay.value)/3.85)*22.28*0.000453592;
        //value =  Math.round(100*(value/drdHousehold.value))/100;
        value =  Math.round(100*value)/100;
        txbFuelOilCO.innerHTML= value;
        spResultFuelOil.innerHTML = value;
        ShowCOSumLine();
    }
    
  

    function CalcResultCOEnergy()
    {
        var txbElectricityCO = document.getElementById("txbElectricityCO");
        var spResultEnergy = document.getElementById("spResultEnergy");
        var value = (EmptyConvert(txbElectricityCO.innerHTML)-0);
        spResultEnergy.innerHTML = Math.round(value*100)/100;
        ShowCOSumLine();
    }
    
    
    
    function drdHousehold_Change()
    {
        var drdHousehold = document.getElementById('drdHousehold');
        drdNumberOfPeopleValue = drdHousehold.value;
        if(drdHousehold.value>0)
        {
            if(document.getElementById("txbElectricityPay").value == "")
            {
                CalcCOElectricity(2);
            }
            else if(document.getElementById("txbKWhUse").value == "")
            {
                CalcCOElectricity(1);
            }
            CalcCONaturalGasPay();
            CalcCOFuelOil();
            CalcResultCOEnergy();
        }
    }
    
    function EmptyConvert(value)
    {
        if(value!="")
            return value;
        else
            return 0;
    }


