﻿function validate_option1()
{
    var alertText = "To calculate your average living emissions you must:\r\n";
    var option1IsValid = true;
    if (document.getElementById)
    {
        var numericExpression = /^[0-9]+$/;
        
        // validate age for numeric value
        if (!document.getElementById('txtOpt1Age').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter your age in numeric format\r\n";
        }
        
        // validate transport and household for required value
        if (document.getElementById('ddlOpt1TnptHhld').value == "") {
            option1IsValid = false;
            alertText += " - Indicate whether to include transport and household estimation\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 age for numeric value
        if (!document.getElementById('txtOpt2Age').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your age in numeric format\r\n";
        }
        
        // validate food for numeric value
        if (!document.getElementById('txtOpt2Food').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly food expenditure in numeric format\r\n";
        }
        
        // validate eating out for numeric value
        if (!document.getElementById('txtOpt2EatingOut').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly eating out expenditure in numeric format\r\n";
        }
        
        // validate entertainment for numeric value
        if (!document.getElementById('txtOpt2Entertainment').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly entertainment expenditure in numeric format\r\n";
        }
        
        // validate clothing for numeric value
        if (!document.getElementById('txtOpt2Clothing').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly clothing expenditure in numeric format\r\n";
        }
        
        // validate magazines / newspapers for numeric value
        if (!document.getElementById('txtOpt2MagsNews').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly newspaper and magazine expenditure in numeric format\r\n";
        }
        
        // validate gym membership for numeric value
        if (!document.getElementById('txtOpt2Gym').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly gym membership expenditure in numeric format\r\n";
        }
        
        // validate furniture for numeric value
        if (!document.getElementById('txtOpt2FurnApp').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your monthly furniture and appliance expenditure in numeric format\r\n";
        }
        
        // validate other goods and services for numeric value
        if (!document.getElementById('txtOpt2OthGdSvc').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter your any other goods and services monthly expenditure in numeric format\r\n";
        }
        
        // validate driving for required value
        if (document.getElementById('ddlOpt2Drive').value == "") {
            option2IsValid = false;
            alertText += " - Select how often you drive\r\n";
        }
        
        // validate public transport for required value
        if (document.getElementById('ddlOpt2PubTrans').value == "") {
            option2IsValid = false;
            alertText += " - Select how often you use public transport\r\n";
        }
        
        
        // return the option1IsValid, alert user if option1IsValid == false with alertText
        if (option2IsValid) {
            return true;
        } else {
            alert(alertText);
            return false;
        }
    }
}
