$(document).ready(function(e) {
            try {

                if($("#order-no-slip-grip-clips").length > 0 ) {

                    var noSlipGripClips = $("#order-no-slip-grip-clips").val().split(',');

                    if ($.inArray($("#Clips").val(), noSlipGripClips) == -1) {
                        // $("#noSlipGrip").hide();
                        $(".order-no-slip-grip").hide();

                    }
                    else {
                        // $("#noSlipGrip").show();
                        $(".order-no-slip-grip").show();
                    }
                    
                    
                    $(".columnsContainer select").msDropDown();
                
                }
                
                //$(".columnsContainer select").msDropDown();

                $("#order-submit").click(function(e) {

                    // Clip
                    if ($("#Clips").length > 0) {

                        $("input[name='os0']").remove();
                        $("input[name='on0']").remove();

                        if ($("#NoSlipGrip").get(0).selectedIndex == 0 && $("#NoSlipGrip:hidden").length == 0) {
                            //yes, please
                            $("#add-cart").prepend("<input type=\"hidden\" name=\"os0\" value=\"" + $("#Clips option[value='" + $("#Clips").val() + "']").text() + " with No-Slip Grip" + "\" />");
                        }
                        else {
                            //no, thanks
                            $("#add-cart").prepend("<input type=\"hidden\" name=\"os0\" value=\"" + $("#Clips option[value='" + $("#Clips").val() + "']").text() + "\" />");
                        }
                        $("#add-cart").prepend("<input type=\"hidden\" name=\"on0\" value=\"Clip\" />");
                    }


                    //Colors
                    var colors = "";
                    var firstAdded = false;
                    var colorElements = ["Colors1", "Colors2", "Colors3", "Colors4", "Colors5"];
                    $.each(colorElements, function(index, id) {
                        if ($("#" + id).length == 1) {
                            var colorSection = $("#" + id);
                            var id = colorSection.attr("id");
                            var name = colorSection.attr("name");
                            if (firstAdded) {
                                colors = colors + ", " + name + " - " + $("#" + id + " option[value='" + $("#" + id).val() + "']").text().replace(/^\s+/, "");
                            }
                            else {
                                colors = colors + name + " - " + $("#" + id + " option[value='" + $("#" + id).val() + "']").text().replace(/^\s+/, "");
                                firstAdded = true;
                            }
                        }
                    });

                    if (colors.length > 0) {
                        $("input[name='os1']").remove();
                        $("input[name='on1']").remove();
                    
                        $("#add-cart").prepend("<input type=\"hidden\" name=\"os1\" value=\"" + colors + "\" />");
                        $("#add-cart").prepend("<input type=\"hidden\" name=\"on1\" value=\"Color(s)\" />");
                    }
                    
                    //CenterChoice
                    if ($("#CenterChoice").length > 0) {

                        $("input[name='os2']").remove();
                        $("input[name='on2']").remove();

                        $("#add-cart").prepend("<input type=\"hidden\" name=\"os2\" value=\"" + $("#CenterChoice").val() + "\" />");
                        $("#add-cart").prepend("<input type=\"hidden\" name=\"on2\" value=\"Center Choice\" />");
                    }

                    //OrderLetter
                    if ($("#OrderLetter").length > 0) {

                        $("input[name='os3']").remove();
                        $("input[name='on3']").remove();

                        $("#add-cart").prepend("<input type=\"hidden\" name=\"os3\" value=\"" + $("#OrderLetter").val() + "\" />");
                        $("#add-cart").prepend("<input type=\"hidden\" name=\"on3\" value=\"Letter Choice\" />");
                    }
                    
                    //ButtonType
                    if ($("#ButtonType").length > 0) {

                        $("input[name='os4']").remove();
                        $("input[name='on4']").remove();

                        $("#add-cart").prepend("<input type=\"hidden\" name=\"os4\" value=\"" + $("#ButtonType").val() + "\" />");
                        $("#add-cart").prepend("<input type=\"hidden\" name=\"on4\" value=\"Button Type\" />");
                    }
                    
                    //SiliconeAdaptor
                    if ($("#SiliconeAdaptor").length > 0) {
                    
                        $("input[name='os5']").remove();
                        $("input[name='on5']").remove();
                        
                        if ($("#SiliconeAdaptor").get(0).selectedIndex == 1) {
                            $("#add-cart").prepend("<input type=\"hidden\" name=\"os5\" value=\"Included\" />");
                            $("#add-cart").prepend("<input type=\"hidden\" name=\"on5\" value=\"Silicone Adaptor\" />");
                        }
                    }
                    
                    var qty = parseInt($("#order-quantity").val());
                    if( qty > 0 )
                    {
                        $("input[name=quantity]").val(qty);
                    }
                    else {
                        alert("Please enter a valid number for the Quantity you'd like to order. Thanks!");
                        e.preventDefault();
                    }
            

                });


            } catch (e) {
                alert(e);
            }
        }
				      )

        function clipChanged(noSlipGripClips) {
            if ($.inArray($("#Clips").val(), noSlipGripClips) == -1) {
                $(".order-no-slip-grip").hide();
            }
            else {
                $(".order-no-slip-grip").show();
            }
        }
        
        function siliconeAdaptorChanged() {    
            
            if ($("#SiliconeAdaptor").get(0).selectedIndex == 1) {
                var price = parseFloat($("#item-price").text()) + .75;
            }
            else {
                var price = parseFloat($("#item-price").text());
            }
            $("input[name=amount]").val(price);
        
         }
