﻿function validate_option1()
{
    var alertText = "To calculate your household fuel emissions you must:\r\n";
    var option1IsValid = true;
    if (document.getElementById)
    {
        var numericExpression = /^[0-9]*$/;
        
        // validate electricity for numeric value
        if (!document.getElementById('txtElectricity').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter electricity usage in numeric format\r\n";
        }
        
        // validate green tarrif electricity for numeric value
        if (!document.getElementById('txtGreenTarrifElec').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter green taffic electricity usage in numeric format\r\n";
        }
        
        // validate gas for numeric value
        if (!document.getElementById('txtGas').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter gas usage in numeric format\r\n";
        }
        
        // validate bottled gas for numeric value
        if (!document.getElementById('txtBottledGas').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter bottled gas usage in numeric format\r\n";
        }
        
        // validate heating oil for numeric value
        if (!document.getElementById('txtHeatingOil').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter heating oil usage in numeric format\r\n";
        }
        
        // validate coal for numeric value
        if (!document.getElementById('txtCoal').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter coal usage in numeric format\r\n";
        }
        
        // validate wood for numeric value
        if (!document.getElementById('txtWood').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter wood usage in numeric format\r\n";
        }
        
        // validate at least one entry exists
        var enteredValues = parseInt(document.getElementById('txtElectricity').value.length + 
            document.getElementById('txtGreenTarrifElec').value.length + 
            document.getElementById('txtGas').value.length + 
            document.getElementById('txtBottledGas').value.length + 
            document.getElementById('txtHeatingOil').value.length + 
            document.getElementById('txtCoal').value.length + 
            document.getElementById('txtWood').value);
        if (enteredValues < 1) {
            option1IsValid = false;
            alertText += " - Enter a usage amount for at least 1 fuel type\r\n";
        }
        
        // validate number of years for required value
        if (document.getElementById('ddlOpt1Yrs').value == "") {
            option1IsValid = false;
            alertText += " - Select how many years to offset\r\n";
        }
        
        // return the option1IsValid, alert user if option1IsValid == false with alertText
        if (option1IsValid) {
            return true;
        } else {
            alert(alertText);
            return false;
        }
    }
}
function validate_option2()
{
    var alertText = "To calculate your household emissions by type and size you must:\r\n";
    var option2IsValid = true;
    if (document.getElementById)
    {
        var numericExpression = /^[0-9]+$/;
        
        // validate number of staff for required and numeric value
        if (!document.getElementById('txtOpt2NumStaff').value.match(numericExpression)) {
            option2IsValid = false;
            alertText = " - Enter number of staff\r\n";
        }
        
        // validate floor area for required and numeric value
        if (!document.getElementById('txtOpt2FloorArea').value.match(numericExpression)) {
            option2IsValid = false;
            alertText = " - Enter office floor area\r\n";
        }
        
        // validate central heating for required value
        if (document.getElementById('ddlOpt2CentralHeating').value == "") {
            option2IsValid = false;
            alertText += " - Indicate whether central heating is used in the office\r\n";
        }
        
        // validate energy saving for required value
        if (document.getElementById('ddlOpt2EnergySaving').value == "") {
            option2IsValid = false;
            alertText += " - Indicate whether energy saving measures are used in the office\r\n";
        }
        
        // validate energy supply for required value
        if (document.getElementById('ddlOpt2EnergySupply').value == "") {
            option2IsValid = false;
            alertText += " - Select the energy supply used in the office\r\n";
        }
        
        // validate years to offset for required value
        if (document.getElementById('ddlOpt2Yrs').value == "") {
            option2IsValid = false;
            alertText += " - Select how many years to offset\r\n";
        }
        
        
        // return the option1IsValid, alert user if option1IsValid == false with alertText
        if (option2IsValid) {
            return true;
        } else {
            alert(alertText);
            return false;
        }
    }
}
