﻿function validate_option1()
{
    var alertText = "To calculate your non-regular journey's emissions you must:\r\n";
    var option1IsValid = true;
    if (document.getElementById)
    {
        // validate journey type for required value
        if (document.getElementById('ddlOpt1JnyTyp').value == "") {
            option1IsValid = false;
            alertText += " - Select the type of journey; one-way or return\r\n";
        }
        
        // validate travel method for required value
        if (document.getElementById('ddlOpt1TravelMethod').value == "") {
            option1IsValid = false;
            alertText += " - Select the method of rail transport used\r\n";
        }
        
        // validate the journey distance of required & numeric value
        var numericExpression = /^[0-9]+$/;
        if ((!document.getElementById('txtOpt1JrnyDistMileage').value.match(numericExpression)) && (!document.getElementById('txtOpt1JrnyDistKilometres').value.match(numericExpression))){
            option1IsValid = false;
            alertText += " - Enter the journey miles OR kilometres in numeric format\r\n";
        } else  if ((document.getElementById('txtOpt1JrnyDistMileage').value.match(numericExpression)) && (document.getElementById('txtOpt1JrnyDistKilometres').value.match(numericExpression))){
            option1IsValid = false;
            alertText += " - Enter the journey miles OR kilometres in numeric format\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 annual rail emissions you must:\r\n";
    var option2IsValid = true;
    if (document.getElementById)
    {
        // validate journey length for required value
        if (document.getElementById('ddlOpt2JrnyLength').value == "") {
            option2IsValid = false;
            alertText += " - Select the average journey length\r\n";
        }
        
        // validate number of days per week for required value
        if (document.getElementById('ddlOpt2DaysPerWeek').value == "") {
            option2IsValid = false;
            alertText += " - Select the average number of days travelled per week\r\n";
        }
        
        // return the option1IsValid, alert user if option1IsValid == false with alertText
        if (option2IsValid) {
            return true;
        } else {
            alert(alertText);
            return false;
        }
    }
}
