﻿function validate_option1()
{
    var alertText = "To calculate commuter emissions you must:\r\n";
    var option1IsValid = true;
    if (document.getElementById)
    {
        var numericExpression = /^[0-9]*$/;
    
        // validate number of commuters for required numeric value
        if (!document.getElementById('txtOpt1NumCommuters').value.match(numericExpression)) {
            option1IsValid = false;
            alertText += " - Enter number of commuters to offset\r\n";
        }
        // validate journey length for required value
        if (document.getElementById('ddlOpt1JrnyLength').value == "") {
            option1IsValid = false;
            alertText += " - Select the average journey length\r\n";
        }
        
        // validate number of days per week for required value
        if (document.getElementById('ddlOpt1DaysPerWeek').value == "") {
            option1IsValid = false;
            alertText += " - Select the average number of days travelled per week\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 company taxi emissions you must:\r\n";
    var option2IsValid = true;
    if (document.getElementById)
    {
        var numericExpression = /^[0-9]+$/;
    
        // validate number of commuters for required numeric value
        if (!document.getElementById('txtOpt2Journeys').value.match(numericExpression)) {
            option2IsValid = false;
            alertText += " - Enter average number of journeys per month\r\n";
        }
        // validate journey length for required value
        if ((!document.getElementById('txtOpt2DistanceMileage').value.match(numericExpression)) && (!document.getElementById('txtOpt2DistanceKilometres').value.match(numericExpression))){
            option2IsValid = false;
            alertText += " - Select the average journey miles OR kilometres\r\n";
        } else  if ((document.getElementById('txtOpt2DistanceMileage').value.match(numericExpression)) && (document.getElementById('txtOpt2DistanceKilometres').value.match(numericExpression))){
            option2IsValid = false;
            alertText += " - Select the average journey miles OR kilometres\r\n";
        }
        
        // return the option1IsValid, alert user if option1IsValid == false with alertText
        if (option2IsValid) {
            return true;
        } else {
            alert(alertText);
            return false;
        }
    }
}
