﻿function validate_option1()
{
    var alertText = "To calculate your holiday offset you must:\r\n";
    var option1IsValid = true;
    if (document.getElementById)
    {
        var numericExpressionRequired = /^[0-9]+$/;
        var numericExpress = /^[0-9]*$/;
        
        // validate number of people
        if (document.getElementById('ddlOpt1NumPpl').value == "") {
            option1IsValid = false;
            alertText += " - Select the number of people to calculate for\r\n";
        }
        
        // validate the number of days
        if (!document.getElementById('txtOpt1Days').value.match(numericExpressionRequired)) {
            option1IsValid = false;
            alertText += " - Enter the length of the holiday in numeric format\r\n";
        }
        
        // validate at least 1 method of transport to destination
//    	        var ddlOpt1Flight = document.getElementById('ddlOpt1Flight');
//    	        var ddlOpt1Car = document.getElementById('ddlOpt1Car');
//    	        var ddlOpt1Rail = document.getElementById('ddlOpt1Rail');
//    	        var ddlOpt1Coach = document.getElementById('ddlOpt1Coach');
//    	        var ddlOpt1Motorcycle = document.getElementById('ddlOpt1Motorcycle');
//    	        var valueLength = parseInt(ddlOpt1Flight.value.length) + parseInt(ddlOpt1Car.value.length)
//    	            + parseInt(ddlOpt1Rail.value.length) + parseInt(ddlOpt1Coach.value.length) + parseInt(ddlOpt1Motorcycle.value.length);
//    	        if (valueLength == 0) {
//    	            option1IsValid = false;
//    	            alertText += " - Specify at least one method of transport to and from your holiday destination\r\n";
//    	        }

        var ddlOpt1Flight = document.forms[0].optFlight;
        var ddlOpt1Car = document.forms[0].optDrive;
        var ddlOpt1Rail = document.forms[0].optRail;
        var ddlOpt1Coach = document.forms[0].optCoach;
        var ddlOpt1Motorcycle = document.forms[0].optMotorcycle;
        // validate flight method
        if (ddlOpt1Flight[0].checked) {
            // validate departure airport
            if (document.getElementById('ddlOpt1FlightDpt').value == "") {
                option1IsValid = false;
                alertText += " - Select a departure airport\r\n";
            }
            // validate departure airport
            if (document.getElementById('ddlOpt1FlightDst').value == "") {
                option1IsValid = false;
                alertText += " - Select a destination airport\r\n";
            }
        }
      
        
        // validate car method
        if (ddlOpt1Car[0].checked) {
            // validate fuel type
            if (document.getElementById('ddlOpt1CarFuelType').value == "") {
                option1IsValid = false;
                alertText += " - Select the type of fuel of your car\r\n";
            }
            // validate engine size
            if (document.getElementById('ddlOpt1CarEngineSize').value == "") {
                option1IsValid = false;
                alertText += " - Select the engine size of your car\r\n";
            }
            // validate journey distance for numeric value
            if ((!document.getElementById('txtOpt1CarMiles').value.match(numericExpressionRequired)) && (!document.getElementById('txtOpt1CarKilometres').value.match(numericExpressionRequired))) {
                option1IsValid = false;
                alertText += " - Enter car journey miles OR kilometres in numeric format\r\n";
            } 
            else if ((document.getElementById('txtOpt1CarMiles').value.match(numericExpressionRequired)) && (document.getElementById('txtOpt1CarKilometres').value.match(numericExpressionRequired)) && (parseInt(document.getElementById('txtOpt1CarMiles').value) > 0) && (parseInt(document.getElementById('txtOpt1CarKilometres').value) > 0)) {
                option1IsValid = false;
                alertText += " - Enter car journey miles OR kilometres in numeric format\r\n";
            }
            
//	                // validate city driving
//	                if (document.getElementById('ddlOpt1CarCityDriving').value == "") {
//	                    option1IsValid = false;
//	                    alertText += " - Select how much city driving you did in your car\r\n";
//	                }
        }
        
        // validate rail method
        if (ddlOpt1Rail[0].checked) {
            // validate rail miles for numeric value
            if ((!document.getElementById('txtOpt1RailMiles').value.match(numericExpressionRequired)) && (!document.getElementById('txtOpt1RailKilometres').value.match(numericExpressionRequired))) {
                option1IsValid = false;
                alertText += " - Enter your rail journey miles OR kilometres in numeric format\r\n";
            }
            else  if ((document.getElementById('txtOpt1RailMiles').value.match(numericExpressionRequired)) && (document.getElementById('txtOpt1RailKilometres').value.match(numericExpressionRequired)) && (parseInt(document.getElementById('txtOpt1RailMiles').value) > 0) && (parseInt(document.getElementById('txtOpt1RailKilometres').value) > 0)) {
                option1IsValid = false;
                alertText += " - Enter your rail journey miles OR kilometres in numeric format\r\n";
            }
            
            // validate rail method
            if (document.getElementById('ddlOpt1RailMethod').value == "") {
                option1IsValid = false;
                alertText += " - Select the rail service used\r\n";
            }
        }
        
        // validate coach method
        if (ddlOpt1Coach[0].checked) {
            // validate coach miles for numeric value
            if ((!document.getElementById('txtOpt1CoachMiles').value.match(numericExpressionRequired)) && (!document.getElementById('txtOpt1CoachKilometres').value.match(numericExpressionRequired))) {
                option1IsValid = false;
                alertText += " - Enter your caoch journey distance in numeric format\r\n";
            }
            else if ((document.getElementById('txtOpt1CoachMiles').value.match(numericExpressionRequired)) && (document.getElementById('txtOpt1CoachKilometres').value.match(numericExpressionRequired)) && (parseInt(document.getElementById('txtOpt1CoachMiles').value) > 0) && ( parseInt(document.getElementById('txtOpt1CoachKilometres').value) > 0)) {
                option1IsValid = false;
                alertText += " - Enter your caoch journey miles OR kilometres in numeric format\r\n";
            }
        }
        
        // validate motorcycle method
        if (ddlOpt1Motorcycle[0].checked) {
            // validate engine size
            if (document.getElementById('ddlOp1MotorcycleEngineSize').value == "") {
                option1IsValid = false;
                alertText += " - Select the motorcycle engine size\r\n";
            }
            // validate journey distance
            if ((!document.getElementById('txtOpt1MotorcycleMiles').value.match(numericExpressionRequired)) && (!document.getElementById('txtOpt1MotorcycleKilometres').value.match(numericExpressionRequired))) {
                option1IsValid = false;
                alertText += " - Enter the estimated miles OR kilometres travelled by motorcycle in numeric format\r\n";
            }
            else if ((document.getElementById('txtOpt1MotorcycleMiles').value.match(numericExpressionRequired)) && (document.getElementById('txtOpt1MotorcycleKilometres').value.match(numericExpressionRequired)) && (parseInt(document.getElementById('txtOpt1MotorcycleMiles').value) > 0) && (parseInt(document.getElementById('txtOpt1MotorcycleKilometres').value) > 0)) {
                option1IsValid = false;
                alertText += " - Enter the estimated miles OR kilometres travelled by motorcycle in numeric format\r\n";
            }
//    	            // validate city driving
//    	            if (document.getElementById('ddlOpt1MotorcycleCityDriving').value == "") {
//    	                option1IsValid = false;
//    	                alertText += " - Indicate how much city driving for you motorcycle journey\r\n";
//    	            }
        }
        
        if((ddlOpt1Motorcycle[1].checked)&&(ddlOpt1Coach[1].checked)&&(ddlOpt1Rail[1].checked)&&(ddlOpt1Car[1].checked)&&(ddlOpt1Flight[1].checked))
        {
            option1IsValid = false;
            alertText += " - Please choose at least 1 mode of transport\r\n";
        }
            	        
        // validate private transport for required value
        if (document.getElementById('ddlOpt1PrivateTrans').value == "") {
            option1IsValid = false;
            alertText += " - Indicate whether you used private transport\r\n";
        }
        
        // validate public transport for required value
        if (document.getElementById('ddlOpt1PublicTrans').value == "") {
            option1IsValid = false;
            alertText += " - Indicate whether you used public transport\r\n";
        }
        
        // return the option1IsValid, alert user if option1IsValid == false with alertText
        if (option1IsValid) {
            return true;
        } else {
            alert(alertText);
            return false;
        }
    }
}
