/*
 Function will check to see if the user has checked the 'No Preference' checkbox on step one.  If so
 the system will just make sure that the data in the measurement dropdowns is not used.  If not, then
 the system will grab the data from the width and height dropdowns
 */
function validateStepOneInput(){

    // figure out if the check box is selected
    if ($("#noPreference").attr('checked')){
        // just make sure that the input fields for width and height are set to ""
        $("#selectedValues00value").val("");
        $("#selectedValues01value").val("");
        return true;
    } else {
        var widthInch = $("#wInches").val();
        var widthPartial = $("#wPartial").val();

        var hInch = $("#hInches").val();
        var hPartial = $("#hPartial").val();

        // this code doesn't check to see if this is shower or bath doors, but it doesn't have to
        // since only bathtub can have a door with height less than 55.5
        if ((hInch + hPartial) < 55.5){
            alert ("The smallest size you can choose for bathtub shower doors opening height is 55 1/2 inches. Please choose a height greater than 55 1/2 inches.");
            return false;
        } else {

            $("#selectedValues00value").val(widthInch + widthPartial);
            $("#selectedValues01value").val(hInch + hPartial);
            return true;
        }
    }
}

function specifyStep4Value(attributeName, attributeVal){

    if (attributeName == 'GLASS_TEXTURE_GROUPING'){
        $("#selectedValues40value").val(attributeVal);
        $("#selectedValues50value").val("");
    }
    else if (attributeName == 'GLASS_CHOICE'){
        $("#selectedValues40value").val("");
        $("#selectedValues50value").val(attributeVal);
    } else {
        $("#selectedValues40value").val("");
        $("#selectedValues50value").val("");
    }

}

$(function() {
    $("#selectionForm").submit(function() {
        if ($("#_page").val() == '0') {
            // figure out if the check box is selected
            if ($("#noPreference").attr('checked')){
                // just make sure that the input fields for width and height are set to ""
                $("#selectedValues00value").val("");
                $("#selectedValues01value").val("");
                return true;
            } else {
                var widthInch = $("#wInches").val();
                var widthPartial = $("#wPartial").val();

                var hInch = $("#hInches").val();
                var hPartial = $("#hPartial").val();

                // this code doesn't check to see if this is shower or bath doors, but it doesn't have to
                // since only bathtub can have a door with height less than 55.5
                if ((hInch + hPartial) < 55.5){
                    alert ("The smallest size you can choose for bathtub shower doors opening height is 55 1/2 inches. Please choose a height greater than 55 1/2 inches.");
                    return false;
                } else {

                    $("#selectedValues00value").val(widthInch + widthPartial);
                    $("#selectedValues01value").val(hInch + hPartial);
                    return true;
                }
            }
        }
    });

    $("#sortBy").change(function() {
        $(this).parents("form").get(0).submit();
    });


    $("li.enlarge a").click(
            function() {
                var enlargedImg = $(this).parents("div.selectionGuide-selectionImg").children("img").attr("src").split("/");
                var enlargedImgName = enlargedImg[enlargedImg.length - 1];
                var enlargedImgTitle = $(this).parents("div.selectionGuide-selectionImg").children("img").attr("alt");

                $("#overlay-enlargeImg #enlargedPhoto").attr("src", "/common/images/enlarged/" + enlargedImgName);
                $("#overlay-enlargeImg #enlarge-title").text(enlargedImgTitle);

                var myScrollTop = $(document).scrollTop();
                if((myScrollTop > -1) && (!$.browser.safari)) {
                    $('#overlay-enlargeImg').css("top", (myScrollTop + ($(window).height() / 2) - 180) + "px");
                } else {
                    $('#overlay-enlargeImg').css("top", (self.pageYOffset + ($(window).height() / 2) - 180) + "px");
                }
                $("#overlay-enlargeImg-header img.close-enlargeImg").click(
                        function() {
                            $('#overlay-enlargeImg').hide();
                        }
                        );
                setTimeout(function() { $("#overlay-enlargeImg").show(); }, 300); // delay to prevent flicker
                $("#overlay-enlargeImg").jqDrag('#overlay-enlargeImg-header');
            }
            );

    $("#overlay-frameComparison-header img.close-frameComparison").click(
            function() {
                $('#overlay-frameComparison').hide();
            }
    );

    $("div#frameDesign-frameComparisonLink a").click(function() {
        var myScrollTop = $(document).scrollTop();
        if((myScrollTop > -1) && (!$.browser.safari)) {
            $('#overlay-frameComparison').css("top", (myScrollTop + ($(window).height() / 2) - 180) + "px");
        } else {
            $('#overlay-frameComparison').css("top", (self.pageYOffset + ($(window).height() / 2) - 180) + "px");
        }
        $("#overlay-frameComparison").jqDrag('#overlay-frameComparison-header');
        $("#overlay-frameComparison").show();
        return false;
    });
});
