﻿function checkValues1() {}

function checkValues2() {
    var $this = $(".product-find .DDLQuestion2");
    var ddlVal = $this.val();
    var $wrp = $this.parents("ol");

    if (ddlVal != '' && !IsNumeric(ddlVal)) {
        //window.location.href = ddlVal;

        $wrp.siblings("input[type='submit']").show();
        setTimeout(function () { $wrp.find(".DDLQuestion3").attr('disabled', 'disabled') }, 120);
    }
    else {
        $wrp.siblings("input[type='submit']").hide();
        $wrp.find(".DDLQuestion3").removeAttr('disabled');
    }
}

function checkValues3() {
    var $this = $(".product-find .DDLQuestion3");
    var ddlVal = $this.val();
    var $wrp = $this.parents("ol");

    if (ddlVal != '' && !IsNumeric(ddlVal)) {
        //window.location.href = ddlVal;
        $wrp.siblings("input[type='submit']").show();
    }
}

$(document).ready(function () {

    $(".product-find .btn").bind("click",
        function (e) {
            e.preventDefault();
            var ddlVal1 = $(this).parents(".product-find").find(".DDLQuestion1").val();
            var ddlVal2 = $(this).parents(".product-find").find(".DDLQuestion2").val();
            var ddlVal3 = $(this).parents(".product-find").find(".DDLQuestion3").val();
            if (ddlVal2 != '' && !IsNumeric(ddlVal2)) {
                //Add previous selections for breadcrumb functionality

                //If url already has parameters, add onto the end
                if (ddlVal2.indexOf("?") < 0) {
                    ddlVal2 = ddlVal2 + "?";
                }
                //alert(ddlVal2);
                //alert(ddlVal2 + "&ddl1=" + ddlVal1);
                //window.location.href = ddlVal2 + "&ddl1=" + ddlVal1;

                var ddlVal2Text = $(this).parents(".product-find").find(".DDLQuestion2 option:selected").text();
                window.location.href = ddlVal3 + "&ddl1=" + ddlVal1 + "&resultName=" + escape(ddlVal2Text);

            }

            if (ddlVal3 != '' && !IsNumeric(ddlVal3)) {
                //Add previous selections for breadcrumb functionality

                //If url already has parameters, add onto the end
                if (ddlVal3.indexOf("?") < 0) {
                    ddlVal3 = ddlVal3 + "?";
                }
                //alert(ddlVal3);
                //alert(ddlVal3 + "&ddl1=" + ddlVal1 + "&ddl2=" + ddlVal2);
                var ddlVal3Text = $(this).parents(".product-find").find(".DDLQuestion3 option:selected").text();
                window.location.href = ddlVal3 + "&ddl1=" + ddlVal1 + "&ddl2=" + ddlVal2 + "&resultName=" + escape(ddlVal3Text);
            }

        }
    );
});

function IsNumeric(input) {
    return (input - 0) == input && input.length > 0;
}

