﻿/****** REGION: Option 1 Methods ******/

function calculateOption1()
{
    if (document.getElementById)
    {
        var txtOpt1JrnyDist = document.getElementById('txtOpt1JrnyDistMileage');
        
        var blnUseKilometres = false;
        
        if(txtOpt1JrnyDist.value == '')
        {
            blnUseKilometres = true;
            
            txtOpt1JrnyDist = document.getElementById('txtOpt1JrnyDistKilometres');
        }
        
        // make the calculation based on the user's selections        
        var result = (txtOpt1JrnyDist.value * (blnUseKilometres ? 1 : KilometresToMilesConversionFactor)); // convert to journey distance to Kilometres
        result = result * taxiCommuterEmissionFactor; // multiply by emission factor
        
        // convert from kilo's to tonnes
        result = result / 1000;
        
        // round to two decimal places
        var roundedResult = Math.round(result*100)/100;
        // show the cost of this offset
        var roundedCost = (Math.round((roundedResult * costPerTonne)*100)/100).toFixed(2);
        document.getElementById('ctl00_cphPrimary_hfOpt1Result').value = roundedResult;
        
        if(document.all)
        {        
            document.getElementById('divOpt1Result').innerHTML = roundedResult.toString();
            document.getElementById('divOpt1Cost').innerText = roundedCost;
        }
        else
        {
            document.getElementById('divOpt1Result').textContent = roundedResult.toString();
            document.getElementById('divOpt1Cost').textContent = roundedCost;
        }
        
    }
}
/****** END REGION: Option 1 Methods ******/


/****** REGION: Option 2 Methods ******/

function calculateOption2()
{
    if (document.getElementById)
    {
        var txtOpt2JrnyDist = document.getElementById('txtOpt2JrnyDistMileage');
        
        var blnUseKilometres = false;
        
        if(txtOpt2JrnyDist.value == '')
        {
            blnUseKilometres = true;
            
            txtOpt2JrnyDist = document.getElementById('txtOpt2JrnyDistKilometres');
            
        }
        var txtOpt2JrnysPerMnth = document.getElementById('txtOpt2JrnysPerMnth');
        
        // make the calculation based on the user's selections
        var result = parseFloat(taxiCommuterEmissionFactor); // emission factor for taxi
        result = result * 12; // months per annum
        result = result * txtOpt2JrnysPerMnth.value; // number of journeys per month
        result = result * (txtOpt2JrnyDist.value * (blnUseKilometres ? 1 : KilometresToMilesConversionFactor)); // estimated average journey in kilometres (converted from miles)
        
        // convert from kilo's to tonnes
        result = result / 1000;
        
        // round to two decimal places
        var roundedResult = Math.round(result*100)/100;
        // show the cost of this offset
        var roundedCost = (Math.round((roundedResult * costPerTonne)*100)/100).toFixed(2);
        document.getElementById('ctl00_cphPrimary_hfOpt2Result').value = roundedResult;
        
        if(document.all)
        {        
            document.getElementById('divOpt2Result').innerHTML = roundedResult.toString();
            document.getElementById('divOpt2Cost').innerText = roundedCost;
        }
        else
        {
            document.getElementById('divOpt2Result').textContent = roundedResult.toString();
            document.getElementById('divOpt2Cost').textContent = roundedCost;
        }
    }
}
/****** END REGION: Option 2 Methods ******/
