﻿function PopUp(ref, w, h) {
        var strFeatures = "toolbar=no,status=no,menubar=no,location=no"
        strFeatures = strFeatures + ",scrollbars=no,resizable=no"
        if (w == null)
            strFeatures += ",width=550";
        else
            strFeatures += ",width=" + w;
        if (h == null)
            strFeatures += ",height=550";
        else
            strFeatures += ",height=" + h;

        newWin = window.open(ref, "TellObj", strFeatures);

        newWin.opener = top;
    }

    $(function() {
        var configurator = $("#configurator");
        var content = $("#centerColumn");

        content.ajaxStart(function() {
            $(this).addClass("ajaxLoading");
        }).ajaxStop(function() {
            $(this).removeClass("ajaxLoading");

            //$("#contentcolumn").height($("#contentcolumn div.innertube").height());
            setHeights();
        });

        function serializeFields() {
            return $("#centerColumn input[type='hidden']").fieldSerialize(); ;
        }

        function updateCart() {
            var tempCart = $("#tempCart");
            tempCart.fadeOut(80);
            var qs = serializeFields();
            tempCart.load("/configureCart.aspx #tempCart > *", qs, function() {
                tempCart.fadeIn(250);
            });
        }

        function incrementStep() {
            $("#currentStep").attr("value", parseInt($("#currentStep").attr("value")) + 1);
        }
        function setHeights() { }


        // vehicle selection
        var loading = $("#loading");
        var vehicleDiv = $("#vehicleSelector");
        // see if the vehicle has already been selected
        if (vehicleDiv.children().size() > 0 && $("select", vehicleDiv).size() == 0) {
            // if so then load the next step
            $("#carMake").attr("value", $("#vehicle_make").attr("rel"));
            $("#carModel").attr("value", $("#vehicle_model").attr("rel"));
            $("#carYear").attr("value", $("#vehicle_year").attr("rel"));
            $("#carSubmodel").attr("value", $("#vehicle_submodel").attr("rel"));
            var qs = serializeFields();
            $.post("/Configure_Steps.aspx", qs, function(data) {
                configurator.append($("div:eq(1)", data));
                $("div:last", configurator).hide().slideDown(500, setHeights);
                incrementStep();
            });
        }

        $("#vehicleSelector a").livequery("click", function(event) {
            event.preventDefault();
            if (configurator.children().size() > 0) {
                $("#currentStep").attr("value", 0);
                //$("#carMake").attr("value","");  
                //  $("#carModel").attr("value","");
                // $("#carYear").attr("value","");
                $("#carSubmodel").attr("value", "");
                configurator.children().slideUp();
                configurator.empty();
            }
            var linkUrl = $(this).attr("href");
            vehicleDiv.load("/vehicleSelectorContent.aspx?div=vehicle&url=" + linkUrl + "&subcatID=" + $("#subcatId").attr("value"));
        });
        $("#vehicleSelector select").livequery("change", function() {
            var selectUrl = this.value;
            vehicleDiv.load("/vehicleSelectorContent.aspx?div=vehicle&url=" + selectUrl + "&subcatID=" + $("#subcatId").attr("value"), "", function() {
                if ($("select", vehicleDiv).size() == 0) {
                    $("#carMake").attr("value", $("#vehicle_make").attr("rel"));
                    $("#carModel").attr("value", $("#vehicle_model").attr("rel"));
                    $("#carYear").attr("value", $("#vehicle_year").attr("rel"));
                    if ($("#vehicle_submodel").size() > 0) $("#carSubmodel").attr("value", $("#vehicle_submodel").attr("rel"));
                    var qs = serializeFields();
                    $.post("/Configure_Steps.aspx", qs, function(data) {
                        configurator.append($("div:eq(1)", data));
                        $("div:last", configurator).hide().slideDown(500, setHeights);
                        incrementStep();
                    });
                }
            });
        });

        // mat set selection
        $("#matSetList input").livequery("click", function() {
            if ($("#currentStep").attr("value") == 0) $("#currentStep").attr("value", 1);
            var sets = "";
            $("#matSetList input:checked").each(function() {
                sets += this.value + "|";
            });
            $("#selectedSets").attr("value", sets);
            var numChecked = $("#matSetList input:checked").size();
            var numsiblings = $("#matSetsDiv ~ *").size();
            if (numChecked > 0) {
                if ($("#tempCart").size() > 0) {
                    updateCart();
                }
                else if (numsiblings == 0) {
                    var qs = serializeFields();
                    $.post("/Configure_Steps.aspx", qs, function(data) {
                        configurator.append($("div:eq(1)", data));
                        $("#configurator > div:last").hide().slideDown(300, setHeights);
                        incrementStep();
                    });
                }
            }
            else {
                $("#matSetsDiv ~ *").slideUp().remove();
                $("#currentStep").attr("value", "1");
            }
        });

        // fix for ie so images in labels fire click event
        if (document.all && navigator.appVersion.indexOf("MSIE") > -1 && navigator.appVersion.indexOf("Windows") > -1) {
            $("#matSetList label img").livequery("click", function() {
                $("#" + $(this).parent().attr("for")).attr("checked", !$("#" + $(this).parent().attr("for")).attr("checked"));
                if ($("#currentStep").attr("value") == 0) $("#currentStep").attr("value", 1);
                var sets = "";
                $("#matSetList input:checked").each(function() {
                    sets += this.value + "|";
                });
                $("#selectedSets").attr("value", sets);
                var numChecked = $("#matSetList input:checked").size();
                var numsiblings = $("#matSetsDiv ~ *").size();
                var qs = serializeFields();
                if (numChecked > 0) {
                    if ($("#tempCart").size() > 0) {
                        updateCart();
                    }
                    else if (numsiblings == 0) {
                        // get the next step
                        $.post("/Configure_Steps.aspx", qs, function(data) {
                            configurator.append($("div:eq(1)", data));
                            $("#configurator > div:last").hide().slideDown(300, setHeights);
                            //$.scrollTo($("#configurator > div:last"),600);
                            incrementStep();
                        });
                    }
                }
                else {
                    $("#matSetsDiv ~ *").slideUp().remove();
                    $("#currentStep").attr("value", "1");
                }
            });
        }

        function logoClicked() {
            $("#selectedLogo").attr("value", $("input[name='logo']:checked").attr("value"));
            // since we don't know if the newly selected logo has custom thread colors available or not
            // we'll just roll up all the other steps
            $("#selectLogoDiv ~ *", configurator).slideUp().remove();
            $("#currentStep").attr("value", $("#configurator > div[id!='selectLogoDiv']").size() + 1);
            var qs = serializeFields();
            $.post("/Configure_Steps.aspx", qs, function(data) {
                configurator.append($("div:eq(1)", data));
                $("#configurator > div:last").hide().slideDown(300, setHeights);
                $.scrollTo($("#configurator > div:last"), 600);
                incrementStep();
            });
        }

        function chooseMatTypeChanged() {
            var mt = $("input[name='chooseMatType']:checked").attr("value");
            //console.log("mat type changed to " + mt);
            $("#floorMatType").attr("value", mt);
            if (mt == 0) {
                if ($("#tempCart").length) {
                    console.log("removing chooseMatType siblings except tempCart...");
                    $("#chooseMatType ~ div[id!='tempCart']").slideUp(250).remove();
                    updateCart();
                }
                else {
                    $.scrollTo($("#chooseMatType"), 400);
                    $("div#chooseMatType ~ *").slideUp(500).remove();
                    var cs = $("#configurator > div[id!='chooseMatType']").size() + 1;
                    $("#currentStep").attr("value", cs);
                    var qs = serializeFields();
                    $.post("/Configure_Steps.aspx", qs, function(data) {
                        configurator.append($("div:eq(1)", data));
                        $("#configurator > div:last").hide().slideDown(300, setHeights);
                        $.scrollTo($("#configurator > div:last"), 600);
                        incrementStep();
                    });
                }
            }
            else if (mt == 1 || mt == 2) {
                $("#chooseMatType ~ *", configurator).slideUp().remove();
                $("#currentStep").attr("value", $("#configurator > div[id!='chooseMatType']").size() + 1);
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div", data).eq(1));
                    $("#configurator > div:last").hide().slideDown(300);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                    // see if the next step is logo, and if a logo is selected set selected logo
                    if ($("#configurator > div:last").attr("id") == "selectLogoDiv" && $("#selectedLogo").attr("value") != "0"
                    && $("#selectedLogo").attr("value") != "") {
                        $("input[name='logo'][value='" + $("#selectedLogo").attr("value") + "']").attr("checked", "checked");
                        logoClicked();
                    }
                });
            }
        }

        $("#colorsDiv input").livequery("click", function() {
            $("#colorsDiv select").val(this.value);
            $("#selectedColor").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) {
                updateCart();
            }
            else if ($("#colorsDiv ~ *").size() == 0) {
                // get the next step
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                    // see if the next step is mat type, and if a logo is selected set mat type to with logo
                    if ($("#configurator > div:last").attr("id") == "chooseMatType" && $("#selectedLogo").attr("value") != "0"
                        && $("#selectedLogo").attr("value") != "") {
                        $("input[name='chooseMatType'][value=1]").attr("checked", "checked");
                        chooseMatTypeChanged();
                    }
                });
            }
        });

        $("#colorsDiv select").livequery("change", function() {
            $("input[id=color_" + this.value + "]").attr("checked", true);
            $("#selectedColor").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) {
                updateCart();
            }
            else if ($("#colorsDiv ~ *").size() == 0) {
                // get the next step
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                    // see if the next step is mat type, and if a logo is selected set mat type to with logo
                    if ($("#configurator > div:last").attr("id") == "chooseMatType" && $("#selectedLogo").attr("value") != "0"
                        && $("#selectedLogo").attr("value") != "") {
                        $("input[name='chooseMatType'][value=1]").attr("checked", "checked");
                        chooseMatTypeChanged();
                    }
                });
            }
        });

        $("img.jt").livequery(function() {
            $(this).cluetip({
                cluetipClass: 'jtip',
                width: 365,
                dropShadow: true,
                titleAttribute: "alt"
            });
        });

        $(".configureLogoItem img").livequery(function() {
            var logoID = $(this).attr("id").split("_")[1];
            $(this).attr("rel", "/logoDetails.aspx").attr("title", "Logo Details").cluetip({
                cluetipClass: 'jtip',
                width: 225,
                dropShadow: true,
                titleAttribute: "title",
                ajaxCache: false,
                ajaxSettings: {
                    type: "POST",
                    data: "id=" + logoID
                }
            });
        });

        $("#selectBindingDiv input[name='binding']").livequery("click", function() {
            // set the hidden input
            var binding = this.value;
            $("#selectedBinding").attr("value", binding);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#selectBindingDiv ~ *").size() == 0 && binding == 0) {
                // get the next step only if there are no siblings and no binding option selected
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                    // see if the next step is mat type, and if a logo is selected set mat type to with logo
                    if ($("#configurator > div:last").attr("id") == "chooseMatType" && $("#selectedLogo").attr("value") != "0"
                    && $("#selectedLogo").attr("value") != "") {
                        $("input[name='chooseMatType'][value=1]").attr("checked", "checked");
                        chooseMatTypeChanged();
                    }
                });
            }
        });

        $("#selectBindingDiv input[name='binding_color']").livequery("click", function() {
            $("#selectBindingDiv select").val(this.value);
            $("#selectedBindingColor").attr("value", this.value);
            $("#selectedBinding").attr("value", "1");
            $("#selectBindingDiv input[name='binding'][value='1']").attr("checked", true);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#selectBindingDiv ~ *").size() == 0) {
                // get the next step only if there are no siblings
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                    // see if the next step is mat type, and if a logo is selected set mat type to with logo
                    if ($("#configurator > div:last").attr("id") == "chooseMatType" && $("#selectedLogo").attr("value") != "0"
                    && $("#selectedLogo").attr("value") != "") {
                        $("input[name='chooseMatType'][value=1]").attr("checked", "checked");
                        chooseMatTypeChanged();
                    }
                });
            }
        });

        $("#selectBindingDiv select").livequery("change", function() {
            $("input[id=color_" + this.value + "]").attr("checked", true);
            $("#selectedBindingColor").attr("value", this.value);
            $("#selectedBinding").attr("value", "1");
            $("#selectBindingDiv input[name='binding'][value='1']").attr("checked", true);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#selectBindingDiv ~ *").size() == 0) {
                // get the next step only if there are no siblings
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                    // see if the next step is mat type, and if a logo is selected set mat type to with logo
                    if ($("#configurator > div:last").attr("id") == "chooseMatType" && $("#selectedLogo").attr("value") != "0"
                    && $("#selectedLogo").attr("value") != "") {
                        $("input[name='chooseMatType'][value=1]").attr("checked", "checked");
                        chooseMatTypeChanged();
                    }
                });
            }
        });

        // mat options
        $("input[name='chooseMatType']").livequery("click", chooseMatTypeChanged);

        // logos
        $("input[name='logo']").livequery("click", logoClicked);

        $("#logoApplicationsDiv input").livequery("click", function() {
            // set hidden input value
            var logoApplications = "";

            $("#logoApplicationsDiv input:checked").each(function() {
                if ($("#logo_placement_" + this.value).size() > 0) {
                    logoApplications += this.value + "-" + $("#logo_placement_" + this.value).attr("value") + "|";
                }
                else logoApplications += this.value + "|";
            });
            $("#selectedLogoApplications").attr("value", logoApplications);
            // if the cart is visible, just update it
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else {
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });
        $("#logoApplicationsDiv select").livequery("change", function() {
            // set hidden input value
            var logoApplications = "";
            $("#logoApplicationsDiv input:checked").each(function() {
                if ($("#logo_placement_" + this.value).size() > 0) {
                    logoApplications += this.value + "-" + $("#logo_placement_" + this.value).attr("value") + "|";
                }
                else logoApplications += this.value + "|";
            });
            $("#selectedLogoApplications").attr("value", logoApplications);
            // if the cart is visible, just update it
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else {
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });
        $("#logoColorDiv input[name='logo_color']").livequery("click", function() {
            $("#logoColorDiv select").val(this.value);
            $("#selectedLogoColor").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#logoColorDiv ~ *").size() == 0) {
                // get the next step only if there are no siblings
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });
        $("#logoColorDiv select").livequery("change", function() {
            $("input[id=color_" + this.value + "]").attr("checked", true);
            $("#selectedLogoColor").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#logoColorDiv ~ *").size() == 0) {
                // get the next step only if there are no siblings
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });

        // embroidery 
        $("#embroideryColorDiv input[name='embroidery_color']").livequery("click", function() {
            $("#embroideryColorDiv select").val(this.value);
            $("#embroideryColor").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#embroideryColorDiv ~ *").size() == 0) {
                // get the next step only if there are no siblings
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });
        $("#embroideryColorDiv select").livequery("change", function() {
            $("input[id=color_" + this.value + "]").attr("checked", true);
            $("#embroideryColor").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else if ($("#embroideryColorDiv ~ *").size() == 0) {
                // get the next step only if there are no siblings
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });
        $("input[name='embroidery_font']").livequery("click", function() {
            $("#embroideryFont").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
        });
        $("#txtEmbroidery1").livequery("change", function() {
            $("#embroideryText1").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
        });
        $("#txtEmbroidery2").livequery("change", function() {
            $("#embroideryText2").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
        });
        $("input[name='embroidery_orientation']").livequery("click", function() {
            $("#embroideryOrientation").attr("value", this.value);
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
        });

        var validateEmbroidery = function() {
            result = true;
            subcat = $("#subcatId").attr("value");
            if (subcat == "2" || subcat == "6" || subcat == "26") {
                txt1 = $("#txtEmbroidery1").attr("value");
                if (txt1.length > 0) {
                    $.ajax({
                        url: "/ConfigureFloorMats.aspx/checkText",
                        async: false,
                        type: "POST",
                        data: '{"txt" : "' + txt1 + '"}',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        cache: false,
                        success: function(msg) {
                            //alert("msg=["+msg+"],msg.d=["+msg.d+"]");
                            if (msg == false) {
                                $("#embroideryError1").text("Invalid text");
                                result = false;
                            }
                            else $("#embroideryError1").text("");
                        }
                    });
                }
                else {
                    $("#embroideryError1").text("Please enter the text for your embroidery");
                    result = false;
                }
                txt2 = $("#txtEmbroidery2").attr("value");
                if (txt2.length > 0) {
                    $.ajax({
                        url: "/ConfigureFloorMats.aspx/checkText",
                        async: false,
                        type: "POST",
                        data: '{"txt" : "' + txt2 + '"}',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        cache: false,
                        success: function(msg) {
                            //alert("msg=["+msg+"],msg.d=["+msg.d+"]");
                            if (msg == false) {
                                $("#embroideryError2").text("Invalid text");
                                result = false;
                            }
                            else $("#embroideryError2").text("");
                        }
                    });
                }
                if ($("input[name='embroidery_font']:checked").size() == 0) {
                    $("#embroideryError1").text("Please select your embroidery font");
                    result = false;
                }
            }
            return result;
        }
        $("#embroideryApplicationsDiv input").livequery("click", function() {
            if (!validateEmbroidery()) {
                event.preventDefault();
                return;
            }
            // set hidden input value
            var embApplications = "";
            $("#embroideryApplicationsDiv input:checked").each(function() {
                if ($("#embroidery_placement_" + this.value).size() > 0) {
                    embApplications += this.value + "-" + $("#embroidery_placement_" + this.value).attr("value") + "|";
                }
                else embApplications += this.value + "|";
            });
            $("#embroideryApplications").attr("value", embApplications);
            // if the cart is visible, just update it
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else {
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });
        $("#embroideryApplicationsDiv select").livequery("change", function(event) {
            if (!validateEmbroidery()) {
                event.preventDefault();
                return;
            }
            // set hidden input value
            var embApplications = "";
            $("#embroideryApplicationsDiv input:checked").each(function() {
                if ($("#embroidery_placement_" + this.value).size() > 0) {
                    embApplications += this.value + "-" + $("#embroidery_placement_" + this.value).attr("value") + "|";
                }
                else embApplications += this.value + "|";
            });
            $("#embroideryApplications").attr("value", embApplications);
            // if the cart is visible, just update it
            var tempCart = $("#tempCart");
            if (tempCart.size() > 0) updateCart();
            else {
                var qs = serializeFields();
                $.post("/Configure_Steps.aspx", qs, function(data) {
                    configurator.append($("div:eq(1)", data));
                    $("#configurator > div:last").hide().slideDown(300, setHeights);
                    $.scrollTo($("#configurator > div:last"), 600);
                    incrementStep();
                });
            }
        });

        $("a.toggle").livequery("click", function(event) {
            event.preventDefault();
            var divID = this.id + "Div";
            var theLink = this;
            //alert(theLink.id+"[href="+theLink.href+"] toggling div[id="+divID+"]");
            // see if we need to load the content
            if ($("#" + divID + " ol").size() == 0 && theLink.href.indexOf("#") < 0) {
                $.get(theLink.href, function(data) {
                    $(theLink).html("Hide More...");
                    $('#' + divID).prepend($("ol.logoList", data));
                    $('#' + divID).slideToggle("normal", setHeights);
                });
            }
            else {
                if ($('#' + divID).is(':visible'))
                    $(this).html("Show More...");
                else
                    $(this).html("Hide More...");
                $('#' + divID).slideToggle("normal", setHeights);
            }
        });

        $("a.toggleShow").livequery("click", function(event) {
            event.preventDefault();
            var divID = this.id + "Div";
            var theLink = this;
            // see if we need to load the content
            if ($("#" + divID + " ol").size() == 0) {
                $.get(theLink.href, function(data) {
                    $(theLink).html("Hide");
                    $('#' + divID).prepend($("ol.logoList", data));
                    $('#' + divID).slideToggle("normal", setHeights);
                });
            }
            else {
                if ($('#' + divID).is(':visible'))
                    $(this).html("Show");
                else
                    $(this).html("Hide");
                $('#' + divID).slideToggle("normal", setHeights);
            }
        });
        
        // handle clicking addGrommets
        $("input[name=chkGrommets]").livequery("click", function() {
            var val = $(this).is(":checked") ? 1 : 0;
            $("#addGrommetHoles").val(val);
        });

    });