
/*<%-- JSON service calls --%>*/
var gJsonDoorForOptions = gSiteRoot + '/services/ConfiguratorService.svc/GetDoorsForOptions';
var gJsonGlassForSidelite = gSiteRoot + '/services/ConfiguratorService.svc/GetSideliteForOptions';
var gJsonGlassForTransom = gSiteRoot + '/services/ConfiguratorService.svc/GetTransomForOptions';
var gJsonDoorDimensionsForOptions = gSiteRoot + '/services/ConfiguratorService.svc/GetDoorDimensions';
var gJsonGenerateLeadRequest = gSiteRoot + '/services/ConfiguratorService.svc/GenerateLeadRequest';

/*<%-- thickbox iframe pages --%>*/
var gDoorImagePreviewProvider = gSiteRoot + "/products/patiodetail/fulldetailload.aspx";

/*<%-- loading image paths --%>*/
var gDoorLoadingImg = gSiteRoot + "/i/products/door/loader.gif";
var gSideliteLoadingImg = gSiteRoot + "/i/products/sidelite/loader.gif";
var gTransomLoadingImg = gSiteRoot + "/i/products/transom/loader.gif";

/*<%-- hash keys --%>*/
var gDoorStyleOptionKey = "dso";
var gGlassOptionKey = "go";
var gSideliteStyleOptionLeftKey = "ssol";
var gSideliteStyleOptionRightKey = "ssor";
var gTransomStyleOptionKey = "tso";

/*<%-- Added by Hamid - hash keys --%>*/
var gDoorLeftOptionKey = "dl";

/*<%-- Added by Hamid - hash keys --%>*/
var gDoorRightOptionKey = "dr";

/*<%-- sidelite orientations --%>*/
var gOrientationLeft = "left";
var gOrientationRight = "right";

/*<%-- no glass and clear glass door style options --%>*/
var gNoGlassOption = null;
var gClearGlassOption = null;

/*<%-- quote session id --%>*/
var gQuoteSessionId = null;

//added by Hamid - can be removed
//function selectRightDoor(clickme) {
//    //alert(clickme.value);
//    //alert(clickme.checked);
//    if (clickme.getAttribute("wasChecked") == "true") {
//        clickme.checked = false;
//        alert("was Checked");
//        clickme.setAttribute("wasChecked", "false");
//    } else {
//    clickme.setAttribute("wasChecked", "true");
//    alert("was not Checked");
//    }
//    //clickme.addClass('highlightItem');
//    //    if (clickme.checked == true) {
//    //        clickme.checked = false;
//    //    } else if (clickme.checked == false) {
//    //        clickme.checked = true;
//    //    }
//    updateDoorRightPreview(getImageInstructionsPlaceHolderImg());
//}

/*<%-- call to initialize the page --%>*/
function initPage(quoteSessionId) {
    /*<%-- initialize the gQuoteSessionId --%>*/
    gQuoteSessionId = quoteSessionId;

    initAccordian();
    initClueTips();
    initSelectedItems();
    initFilters();
    doorAndGlassSelectionController(false);
    toggleDoorProperties();
    showHideZoomButton();
    setZoomClickUrl();
    setGlassDetailLink(getSelectedGlass(), 'doorpropertiesminiglassmoreinfo');
    if (getSelectedDoorStyleOption() == null) {
        updateDoorPreview(getImageInstructionsPlaceHolderImg());
    }
    initDoorPreviewMouseClick();
    /* show the door configuration details */
    if (document.URL.indexOf('showDoorConfig=true') > 0) {
        $('#' + gZoomDetail).click();
    }
}

function initDoorPreviewMouseClick() {
    /*<%-- add a click handler to the door preview image --%>*/
    $('#' + gZoomImgDetail).click(function() {
        /*<%-- clicking the door image is the same as clicking the zoom button --%>*/
        if ($('#' + gZoomDetail).attr('href') != '#') {
            $('#' + gZoomDetail).click();
        }
    });
    /*<%-- add a mouse hover to the door preview image --%>*/
    $('#' + gZoomImgDetail).mouseover(function() {
        if ($('#' + gZoomDetail).attr('href') != '#') {
            $('#' + gZoomImgDetail).attr('style', 'cursor:pointer;');
        }
        else {
            $('#' + gZoomImgDetail).attr('style', 'cursor:default;');
        }
    });
}

/*<%-- initialize the accordian animation --%>*/
function initAccordian() {
    /*<%-- sets inital state of options --%>*/
    $('.option ul:not(:first)').hide();
    $('#doorHeader').addClass('down');
    $('#glass h3').addClass('down');
    $('#glass ul').show();

    /*<%-- toggles option containers on click --%>*/
    $('.option h3:not(:first)').click(function() {
        $(this).toggleClass('down');
        $(this).parent().find('ul').slideToggle("slow");


        //Adds Auto-Collapse functionality to the page
        if (!$(this).is('#doorHeader, #glassHeader')) {
            //Adds Auto-Scroll functionality to the page
            $.scrollTo($('#selectionsHeader'), 500, { onAfter: function() {
                $('#doorStyles').slideUp(1000);
                $('#doorHeader').removeClass('down');
                $('#doorfilters').slideUp();
                $('#glassOptions').slideUp(1000);
                $('#glassHeader').removeClass('down');
            }
            });
        } else {
            $('#sidelitesleft ul').slideUp(1000);
            $('#sidelitesleft h3').removeClass('down');
            $('#sidelitesright ul').slideUp(1000);
            $('#sidelitesright h3').removeClass('down');
            //added by Hamid
            $('#doorleft ul').slideUp(1000);
            $('#doorleft h3').removeClass('down');
            $('#doorright ul').slideUp(1000);
            $('#doorright h3').removeClass('down');

            $('#transom ul').slideUp(1000);
            $('#transom h3').removeClass('down');
        }
        if (!$(this).hasClass('down') && $(this).is('#doorHeader')) { $('#doorfilters').slideUp(); }
        return false;
    });

    $('.option .filter').click(function() {
        $('#doorfilters').slideToggle("slow");
        //ensures if the filters are shown, the doors are shown
        if (!$('#doorHeader').hasClass('down')) {
            $('#doorStyles').slideDown();
            $('#doorHeader').addClass('down');
        }
        return false;
    });
}

/*<%-- initialize the clue tips --%>*/
function initClueTips() {
    $('.houdini').cluetip({
        splitTitle: '|', // use the invoking element's title attribute to populate the clueTip...
        // ...and split the contents into separate divs where there is a "|"
        showTitle: false, // hide the clueTip's heading
        fx: {
            open: 'fadeIn',
            openSpeed: ''
        },
        activation: 'click',
        sticky: true,
        closePosition: 'bottom',
        closeText: 'close',
        arrows: true,
        dropShadowSteps: 3

    });
}

/*<%-- if the page was bookmarked, the selected selected door configuration options can be reloaded --%>*/
function initSelectedItems() {
    /*<%-- update the selected door image --%>*/
    setPreviewDoor(getSelectedDoorStyleOption(), getSelectedGlass());

    /*<%-- update the selected sidelite image --%>*/
    setPreviewSidelite(getSelectedSideliteOptionRight(), gOrientationRight, getSelectedGlass());

    /*<%-- update the selected sidelite image --%>*/
    setPreviewSidelite(getSelectedSideliteOptionLeft(), gOrientationLeft, getSelectedGlass());

    /*<%-- update the selected transom image --%>*/
    setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
}

/*<%-- registers a click event for the element doorStyleOptionLinkId and passes the doorStyleOption to the doorClickHandler --%>*/
function initDoorStyleOptionSelection(doorStyleOptionId, doorStyleOptionLinkId) {
    //doorStyleOptionLInkId = hDoorStyleOption - asp:Hyperlink for Door
    var doorLink = $('#' + doorStyleOptionLinkId);
    var doorStyleOption = gDoorStyleOptionHash[doorStyleOptionId];
    //alert(doorStyleOptionId + ' - - - - ' + doorStyleOptionLinkId);
    doorLink.bind('click', { doorStyleOption: doorStyleOption }, doorClickHandler);
    doorLink.attr('href', '#');

    doorLink.bind('click', {}, handleZoomClickUrl);
    doorLink.bind('click', {}, handleGlassDetailClickUrl);

    /*<%-- the hash for this option is indicated in the url, remember it to click on that link once the page loads --%>*/
    if (doorStyleOptionId == getDocumentHashValue(gDoorStyleOptionKey)) {
        setLoadedDoorLinkId(doorStyleOptionLinkId);
        
        //added by Hamid - can be removed
        //alert('hellO');
        //alert(doorStyleOptionLinkId);
    }
}

/*<%-- registers a click event for the element glassOptionLinkId and passes the glassOption to the glassClickHandler --%>*/
function initGlassOptionSelection(glassOptionId, glassOptionLinkId, glassOptionDescriptionLinkId, glassOptionInfoImgLinkId) {
    var glassLink = $('#' + glassOptionLinkId);
    var glassDetail = $('#' + glassOptionDescriptionLinkId);
    var glassOption = gGlassOptionHash[glassOptionId];

    if (glassOption.GlassFamily.IsNoGlass) {
        gNoGlassOption = glassOption;
    }
    if (glassOption.GlassFamily.IsClear) {
        gClearGlassOption = glassOption;
    }

    glassLink.bind('click', { glassOption: glassOption }, glassClickHandler);
    glassLink.attr('href', '#');

    /*<%-- set the thickbox url's for this glass option --%>*/
    setGlassDetailLink(glassOption, glassOptionDescriptionLinkId);
    setGlassDetailLink(glassOption, glassOptionInfoImgLinkId);

    glassLink.bind('click', {}, handleZoomClickUrl);
    glassLink.bind('click', {}, handleGlassDetailClickUrl);

    /*<%-- the hash for this option is indicated in the url, remember it to click on that link once the page loads --%>*/
    if (glassOptionId == getDocumentHashValue(gGlassOptionKey)) {
        //alert(glassOptionId);
        setLoadedGlassLinkId(glassOptionLinkId);
    }
}
/*<%-- Added by Hamid - registers a click event for the element glassOptionLinkId and passes the glassOption to the glassClickHandler --%>*/
function initDoorLeftOptionSelection(doorLeftOptionId, doorLeftOptionLinkId) {
    var doorLeftLink = $('#' + doorLeftOptionLinkId);
    //var glassDetail = $('#' + glassOptionDescriptionLinkId);
    var doorLeftOption = gDoorLeftOptionHash[doorLeftOptionId];

    //added by Hamid - can be removed
    //alert('doorLeftOption ' + doorLeftOption); //DoorLeft
    //    if (glassOption.GlassFamily.IsNoGlass) {
    //        gNoGlassOption = glassOption;
    //    }
    //    if (glassOption.GlassFamily.IsClear) {
    //        gClearGlassOption = glassOption;
    //    }
    //alert(doorLeftOption);
    //alert(doorLeftOptionId + ' - - - - ' + doorLeftOptionLinkId);

    doorLeftLink.bind('click', { doorLeftOption: doorLeftOption }, doorLeftClickHandler);
    //glassLink.bind('click', { glassOption: glassOption }, doorLeftOptionClickHandler); 
    doorLeftLink.attr('href', '#');

    //can be removed - Hamid
    /*<%-- set the thickbox url's for this glass option --%>*/
    //    setGlassDetailLink(glassOption, glassOptionDescriptionLinkId);
    //    setGlassDetailLink(glassOption, glassOptionInfoImgLinkId);
    //glassLink.bind('click', {}, handleZoomClickUrl);
    //glassLink.bind('click', {}, handleGlassDetailClickUrl);
    //alert(glassOptionId);
    //alert(getDocumentHashValue(gDoorLeftOptionKey));
    /*<%-- the hash for this option is indicated in the url, remember it to click on that link once the page loads --%>*/
    //alert('doorLeftOptionID - ' + doorLeftOptionId);
    //alert('getDocumentHashValue(gDoorLeftOptionKey)) - ' + getDocumentHashValue(gDoorLeftOptionKey));
    if (doorLeftOptionId == getDocumentHashValue(gDoorLeftOptionKey)) {
        //commented out by Hamid for testing
        //setLoadedDoorLeftLinkId(doorLeftOptionLinkId);
        //alert('setLoadedDoorLeftLinkId - ' + setLoadedDoorLeftLinkId(doorLeftOptionLinkId));
    }
}
function initDoorRightOptionSelection(doorRightOptionId, doorRightOptionLinkId) {
    var doorRightLink = $('#' + doorRightOptionLinkId);
    //var glassDetail = $('#' + glassOptionDescriptionLinkId);
    var doorRightOption = gDoorRightOptionHash[doorRightOptionId];

    doorRightLink.bind('click', { doorRightOption: doorRightOption }, doorRightClickHandler);
    doorRightLink.attr('href', '#');

    if (doorRightOptionId == getDocumentHashValue(gDoorRightOptionKey)) {
        //commented out by Hamid for testing
        //setLoadedDoorLeftLinkId(doorLeftOptionLinkId);
        //alert('setLoadedDoorLeftLinkId - ' + setLoadedDoorLeftLinkId(doorLeftOptionLinkId));
    }
}
/*<%-- registers click events for the left sidelite options --%>*/
function initSideliteStyleOptionSelectionLeft(sideliteStyleOptionId, sideliteStyleOptionLinkId) {
    var sideliteLink = $('#' + sideliteStyleOptionLinkId);
    var sideliteStyleOption = gSideliteStyleOptionHash[sideliteStyleOptionId];

    sideliteLink.bind('click', { sideliteStyleOption: sideliteStyleOption, orientation: gOrientationLeft }, sideliteStyleOptionClickHandlerLeft);
    sideliteLink.attr('href', '#');

    sideliteLink.bind('click', {}, handleZoomClickUrl);

    /*<%-- the hash for this option is indicated in the url, remember it to click on that link once the page loads --%>*/
    if (sideliteStyleOptionId == getDocumentHashValue(gSideliteStyleOptionLeftKey)) {
        setLoadedSideliteLeftLinkId(sideliteStyleOptionLinkId);
    }
}

/*<%-- registers click events for the right sidelite options --%>*/
function initSideliteStyleOptionSelectionRight(sideliteStyleOptionId, sideliteStyleOptionLinkId) {
    var sideliteLink = $('#' + sideliteStyleOptionLinkId);
    var sideliteStyleOption = gSideliteStyleOptionHash[sideliteStyleOptionId];

    sideliteLink.bind('click', { sideliteStyleOption: sideliteStyleOption, orientation: gOrientationRight }, sideliteStyleOptionClickHandlerRight);
    sideliteLink.attr('href', '#');

    sideliteLink.bind('click', {}, handleZoomClickUrl);

    /*<%-- the hash for this option is indicated in the url, remember it to click on that link once the page loads --%>*/
    if (sideliteStyleOptionId == getDocumentHashValue(gSideliteStyleOptionRightKey)) {
        setLoadedSideliteRightLinkId(sideliteStyleOptionLinkId);
    }
}

function initTransomStyleOptionSelection(transomStyleOptionId, transomStyleOptionLinkId) {
    var transomLink = $('#' + transomStyleOptionLinkId);
    var transomStyleOption = gTransomStyleOptionHash[transomStyleOptionId];

    transomLink.bind('click', { transomStyleOption: transomStyleOption }, transomStyleOptionClickHandler);
    transomLink.attr('href', '#');

    transomLink.bind('click', {}, handleZoomClickUrl);

    /*<%-- the hash for this option is indicated in the url, remember it to click on that link once the page loads --%>*/
    if (transomStyleOptionId == getDocumentHashValue(gTransomStyleOptionKey)) {
        setLoadedTransomLinkId(transomStyleOptionLinkId);
    }
}

function initFilters() {
    $('#' + gCheckboxEnergyStar).bind('click', {}, doorFilterClickHandler);
    $('#' + gCheckboxImpactRated).bind('click', {}, doorFilterClickHandler);
    $('#' + gCheckboxFlushGlazed).bind('click', {}, doorFilterClickHandler);
}


function handleZoomClickUrl(event) {
    setZoomClickUrl();
    showHideZoomButton();

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}

function setZoomClickUrl() {
    var args = {};
    args['doorSubLine'] = gDoorSubLine;
    if ((getSelectedGlass() != null) && (getSelectedDoorStyleOption() != null)) {
        args['glassFamily'] = getSelectedGlass().GlassFamily.Family;
        if (getSelectedDoorStyleOption() != null) {
            args['doorStyleShape'] = getSelectedDoorStyleOption().DoorStyle.StyleShape;
        }
        if (getSelectedSideliteOptionRight() != null) {
            args['sideliteRightStyleShape'] = getSelectedSideliteOptionRight().DoorStyle.StyleShape;
            args['sideliteRightStyleIsNoGlass'] = getSelectedSideliteOptionRight().IsNoGlass;

        }
        if (getSelectedSideliteOptionLeft() != null) {
            args['sideliteLeftStyleShape'] = getSelectedSideliteOptionLeft().DoorStyle.StyleShape;
            args['sideliteLeftStyleIsNoGlass'] = getSelectedSideliteOptionLeft().IsNoGlass;

        }
        if (getSelectedTransomOption() != null) {
            args['transomStyleShape'] = getSelectedTransomOption().DoorStyle.StyleShape;
            args['transomStyleIsNoGlass'] = getSelectedTransomOption().IsNoGlass;
        }
        args['doorHeight'] = escape(getDoorHeight());


        var qs = "quotesessionid=" + gQuoteSessionId;

        /*<%-- append existing query string parameters --%>*/
        for (var key in args) {
            qs += ('&' + key + '=' + args[key]);
        }
        /*<%-- add the current url to appear in any quote requests --%>*/
        qs += '&detailPath=' + escape(escape(document.location));

        /*<%-- set the thickbox url parameters --%>*/
        /*<%-- indicates this is an iframe, so printing works, querystring params need to be before 'TB_iframe=' --%>*/
        $('#' + gZoomDetail).attr('href', gDoorImagePreviewProvider + "?" + qs + "&TB_iframe=true&height=500&width=800&modal=false");
        $('#wheretobuycontact').attr('href', gDoorImagePreviewProvider + "?wtb=true&" + qs);
    }
    else {
        $('#' + gZoomDetail).attr('href', '#');
    }
}

function showHideZoomButton() {
    if ((getSelectedGlass() != null) && (getSelectedDoorStyleOption() != null)) {
        $('#' + gZoomDetail).show();
        //$('#' + gAvailableStyles).show();
    }
    else {
        $('#' + gZoomDetail).hide();
        //$('#' + gAvailableStyles).hide();
    }
}

/*<%-- handle door filtration actions --%>*/
function doorFilterClickHandler(event) {
    setSelectedDoorStyleOption(null);
    setSelectedGlass(null);
    setSelectedSideliteOptionLeft(null);
    setSelectedSideliteOptionRight(null);
    setSelectedTransomOption(null);

    unshadeItem($('#glassOptions li'));
    setPreviewDoor(null, null);

    styleDoorPreviewDimensions(null, null);
    toggleDoorProperties();
    showHideZoomButton();
    setZoomClickUrl();

    highlightItems();
    filterDoorOptions();
    refreshStyleCounts();
}

function filterDoorOptions() {
    var isEnergyStarClick = (($('#' + gCheckboxEnergyStar).attr('checked') == null) ? false : $('#' + gCheckboxEnergyStar).attr('checked'));
    var isImpactRatedClick = (($('#' + gCheckboxImpactRated).attr('checked') == null) ? false : $('#' + gCheckboxImpactRated).attr('checked'));
    var isFlushGlazedClick = (($('#' + gCheckboxFlushGlazed).attr('checked') == null) ? false : $('#' + gCheckboxFlushGlazed).attr('checked'));

    /*<%-- build an array of classes matching the filter --%>*/
    var classes = new Array();
    if (isEnergyStarClick) {
        classes[classes.length] = 'IsEnergyStarAvailable-True';
    }
    if (isImpactRatedClick) {
        classes[classes.length] = 'IsImpactRatedDoorAvailable-True';
    }
    if (isFlushGlazedClick) {
        classes[classes.length] = 'IsFlushGlazedAvailable-True';
    }

    /*<%-- highlight the matching doors styles --%>*/
    $('#doorStyles li').each(function() {
        var matchCount = 0;
        /*<%-- count the number of classes this doorStyle matches --%>*/
        for (var i = 0; i < classes.length; i++) {
            if ($(this).hasClass(classes[i])) {
                matchCount++;
            }
        }
        /*<%-- if the match count equals the number of classes, then all classes match this door style, highlight it --%>*/
        if (matchCount == classes.length) {
            unshadeItem($(this));
        }
        else {
            shadeItem($(this));
        }
    });
}

function clearFilters() {
    $('#' + gCheckboxEnergyStar).removeAttr('checked');
    $('#' + gCheckboxImpactRated).removeAttr('checked');
    $('#' + gCheckboxFlushGlazed).removeAttr('checked');
}

function doorClickHandler(event) {
    setSelectedDoorStyleOption(event.data.doorStyleOption);
    //commented out by Hamid for testing ONLY
    doorAndGlassSelectionController(true);

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}

function glassClickHandler(event) {
    setSelectedGlass(event.data.glassOption);
    doorAndGlassSelectionController(false);

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}

//Added by Hamid
function doorLeftClickHandler(event) {
    if (this.getAttribute("wasChecked") == "true") {
        this.checked = false;
        //alert("was Checked");
        this.setAttribute("wasChecked", "false");
        setSelectedDoorLeftOption(null);
        //highlightItems();
    } else {
        this.setAttribute("wasChecked", "true");
        //alert("was not Checked");
        setSelectedDoorLeftOption(event.data.doorLeftOption);
        //highlightItems();
    }
//        var doorLeftOption = event.data.doorLeftOption;
//        alert('doorLeftOption ' + doorLeftOption); //value = DoorLeft
//        alert('doorLeftOptionId ' + doorLeftOption.doorLeftOptionId); //value=undefined
//            var deselect = false;
//            if (getSelectedDoorLeftOption() != null) {
//                if (doorLeftOption.doorLeftOptionId == getSelectedDoorLeftOption().doorLeftOptionId) {
//                //if (doorLeftOption == getSelectedDoorLeftOption().doorLeftOptionId) {
//                    deselect = true;
//                    alert('deselect ' + deselect);
//                }
//            alert('dsfdseselect');
//            if (deselect) {
//                /*<%-- this sidelite is already selected, deselect it --%>*/
//                setSelectedDoorLeftOption(null);
//            }
//            else {
//                //if (isSideliteValidForGlassSelection(sideliteOption, getSelectedGlass())) {
//                    /*<%-- select this sidelite --%>*/
//                    setSelectedDoorLeftOption(doorLeftOption);
//                }
//            }
           // alert('deselect value - ' + deselect);
   // alert('doorLeftClickHandler(event)  - ' + event.data.doorLeftOption);

    //setSelectedDoorLeftOption(event.data.doorLeftOption);
    //setSelectedDoorLeftOption(null);
    doorAndGlassSelectionController(false);

    //    if (getSelectedDoorLeftOption() != null) {
    //        alert('doorleftoption is not null');
    //    } else {
    //        alert('doorleftoption is null');
    //    }
    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}
function doorRightClickHandler(event) {
    if (this.getAttribute("wasChecked") == "true") {
        this.checked = false;
        //alert("was Checked");
        this.setAttribute("wasChecked", "false");
        setSelectedDoorRightOption(null);
    } else {
        this.setAttribute("wasChecked", "true");
        //alert("was not Checked");
        setSelectedDoorRightOption(event.data.doorRightOption);
    }
    doorAndGlassSelectionController(false);

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}


function doorAndGlassSelectionController(isDoorClick) {
    //var gselecteddoorstyleoption = getSelectedDoorStyleOption();
    //alert('doorAndGlassSelectionController - ' + gselecteddoorstyleoption);
    //alert('doorAndGlassSelectionController - ' + getSelectedDoorStyleOption);
    //alert('doorAndGlassSelectionController - ' + gSelectedDoorStyleOption);
//    if (getSelectedDoorStyleOption() != null) {
//        alert('doorstyleoption is not null');
//    } else {
//        alert('doorstyleoption is null');
//    }
//    if (getSelectedDoorLeftOption() != null) {
//        alert('doorleftoption is not null');
//    } else {
//        alert('doorleftoption is null');
//    }
    if ((getSelectedDoorStyleOption() != null) && (getSelectedGlass() == null)) {
        /*<%-- door is selected, but glass is not --%>*/
        handleDoorOnly();

    }
    else if ((getSelectedGlass() != null) && (getSelectedDoorStyleOption() == null)) {
        /*<%-- glass is selected, but door is not --%>*/
        handleGlassOnly();
    }
    else if ((getSelectedDoorStyleOption() != null) && (getSelectedGlass() != null)) {
        /*<%-- door and glass are selected --%>*/
        handleDoorAndGlass(isDoorClick);
    }
    else {
        /*<%-- neither door nor glass are selected --%>*/
    }

    /*<%-- clear selected sidelites and transoms if they are not valid for the glass or door selections --%>*/
    if (!isSideliteValidForGlassSelection(getSelectedSideliteOptionLeft(), getSelectedGlass())) {
        setSelectedSideliteOptionLeft(null);
    }
    if (!isSideliteValidForGlassSelection(getSelectedSideliteOptionRight(), getSelectedGlass())) {
        setSelectedSideliteOptionRight(null);
    }
    if (!isTransomValidForGlassSelection(getSelectedTransomOption(), getSelectedGlass())) {
        setSelectedTransomOption(null);
    }

    /*<%-- style the transoms --%>*/
    styleLeftSidelitesForGlass();
    styleRightSidelitesForGlass();

    //Added by Hamid
    //styleRightDoorForGlass();

    /*<%-- style the transoms --%>*/
    styleTransomsForGlass();

    /*<%-- a door selection has been made, clear the filters --%>*/
    clearFilters();

    /*<%-- refresh style counts --%>*/
    refreshStyleCounts();

    /*<%-- highlight selected options --%>*/
    highlightItems();

    toggleDoorProperties();
}

function handleDoorOnly() {
    /*<%-- door selected, but no glass selected yet --%>*/

    if (getSelectedDoorStyleOption().IsNoGlass) {
        /*<%-- a solid door is selected --%>*/

        /*<%-- no door is selected, so only display solid doors and "no glass" --%>*/
        /*<%-- fade all the door options except the solid doors --%>*/
        shadeItem($('#doorStyles').find(".IsNoGlass-False"));
        unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

        /*<%-- fade all the glass options except the no glass option --%>*/
        shadeItem($('#glassOptions').find(".IsNoGlass-False"));
        unshadeItem($('#glassOptions').find(".IsNoGlass-True"));

        /*<%-- set selected glass as "no glass" since it is the only possible choice --%>*/
        setSelectedGlass(getNoGlassOption());
    }
    else {
        /*<%-- a door with glass is selected --%>*/

        /*<%-- show all glass doors --%>*/
        shadeItem($('#doorStyles').find(".IsNoGlass-True"));
        unshadeItem($('#doorStyles').find(".IsNoGlass-False"));

        /*<%-- shade all glass options --%>*/
        shadeItem($("#glassOptions li"));

        if (getSelectedDoorStyleOption().IsGlassFamilyException) {
            /*<%-- set selected glass as the exception glass --%>*/
            setSelectedGlass(gGlassOptionHash[getSelectedDoorStyleOption().GlassFamilyException.Family.toLowerCase()]);
        }
        else {
            /*<%-- set selected glass as "clear" --%>*/
            setSelectedGlass(getClearGlassOption());
        }

        /*<%-- unshade the available glass options --%>*/
        unshadeAvailableGlass();

        /*<%-- fade all the solid door options --%>*/
        shadeItem($('#doorStyles').find(".IsNoGlass-True"));

        /*<%-- fade "no glass" glass options --%>*/
        shadeItem($('#glassOptions').find(".IsNoGlass-True"));
    }

    /*<%-- update the preview image --%>*/
    setPreviewDoor(getSelectedDoorStyleOption(), getSelectedGlass());

}


function handleGlassOnly() {
    /*<%-- glass is selected, but door is not --%>*/

    if (getSelectedGlass().GlassFamily.IsNoGlass) {
        /*<%-- "no glass" glass selected --%>*/

        /*<%-- only display solid doors and "no glass" --%>*/
        /*<%-- fade all the door options except the solid doors --%>*/
        shadeItem($("#doorStyles li"));
        unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

        /*<%-- fade all the glass options except the no glass option --%>*/
        shadeItem($("#glassOptions li"));
        unshadeItem($('#glassOptions').find(".IsNoGlass-True"));
    }
    else {
        /*<%-- display everything except solid doors and "no glass" --%>*/

        /*<%-- fade all doors --%>*/
        shadeItem($("#doorStyles li"));

        /*<%-- show normal glass options --%>*/
        unshadeItem($('#glassOptions').find(".IsNoGlass-False"));

        /*<%-- unshade the available door options --%>*/
        unshadeAvailableDoors();

        /*<%-- fade all solid doors --%>*/
        shadeItem($('#doorStyles').find(".IsNoGlass-True"));

        /*<%-- fade "no glass" option --%>*/
        shadeItem($('#glassOptions').find(".IsNoGlass-True"));
    }

}

function handleDoorAndGlass(isDoorClick) {
    /*<%-- door and glass are selected --%>*/
    if ((getSelectedDoorStyleOption().IsNoGlass) || (getSelectedGlass().GlassFamily.IsNoGlass)) {
        /*<%-- door or glass are "no glass" options --%>*/

        /*<%-- fade all the door options except the solid doors --%>*/
        shadeItem($("#doorStyles li"));
        unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

        /*<%-- fade all the glass options except the no glass option --%>*/
        shadeItem($("#glassOptions li"));
        unshadeItem($('#glassOptions').find(".IsNoGlass-True"));
    }

    if ((getSelectedGlass().GlassFamily.IsNoGlass) && (getSelectedDoorStyleOption().IsNoGlass == false)) {
        /*<%-- glass is "no glass", door has glass --%>*/

        if (isDoorClick) {
            /*<%-- "no glass" is selected and a door with glass was just clicked --%>*/

            /*<%-- display everything except solid doors and "no glass" --%>*/
            /*<%-- fade all solid doors --%>*/
            shadeItem($("#doorStyles li"));
            //unshadeItem($('#doorStyles').find(".IsNoGlass-False"));

            /*<%-- fade "no glass" option --%>*/
            shadeItem($("#glassOptions li"));
            unshadeItem($('#glassOptions').find(".IsNoGlass-False"));

            if (getSelectedDoorStyleOption().IsGlassFamilyException) {
                /*<%-- set selected glass as the exception glass --%>*/
                setSelectedGlass(gGlassOptionHash[getSelectedDoorStyleOption().GlassFamilyException.Family.toLowerCase()]);
            }
            else {
                /*<%-- set selected glass as "clear" --%>*/
                setSelectedGlass(getClearGlassOption());
            }

            /*<%-- unshade the available glass options --%>*/
            unshadeAvailableDoors();
        }
        else {
            /*<%-- a door with no glass was selected and "no glass" was just clicked --%>*/

            /*<%-- fade all glass doors --%>*/
            shadeItem($('#doorStyles').find(".IsNoGlass-False"));
            unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

            /*<%-- fade normal glass options --%>*/
            shadeItem($('#glassOptions').find(".IsNoGlass-False"));
            unshadeItem($('#glassOptions').find(".IsNoGlass-True"));

            setSelectedDoorStyleOption(null);
        }
    }
    else if ((getSelectedDoorStyleOption().IsNoGlass) && (getSelectedGlass().GlassFamily.IsNoGlass == false)) {
        /*<%-- door is solid, glass is normal --%>*/

        if (isDoorClick) {
            /*<%-- a normal glass option was selected and a solid door was just clicked --%>*/

            /*<%-- only display solid doors and "no glass" --%>*/
            /*<%-- fade all the door options except the solid doors --%>*/
            shadeItem($('#doorStyles').find(".IsNoGlass-False"));
            unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

            /*<%-- fade all the glass options except the no glass option --%>*/
            shadeItem($('#glassOptions').find(".IsNoGlass-False"));
            unshadeItem($('#glassOptions').find(".IsNoGlass-True"));

            /*<%-- set selected glass as "no glass" since it is the only possible choice --%>*/
            setSelectedGlass(getNoGlassOption());
        }
        else {
            /*<%-- a solid door was selected and a normal glass option was just clicked --%>*/

            /*<%-- display everything except solid doors and "no glass" --%>*/
            /*<%-- fade all doors --%>*/
            shadeItem($("#doorStyles li"));

            /*<%-- these selections are incompatible, reset the door --%>*/
            setSelectedDoorStyleOption(null);
            setSelectedSideliteOptionLeft(null);
            setSelectedSideliteOptionRight(null);
            setSelectedTransomOption(null);

            /*<%-- unshade the available door options --%>*/
            unshadeAvailableDoors();

            /*<%-- fade all solid doors --%>*/
            shadeItem($('#doorStyles').find(".IsNoGlass-True"));

            /*<%-- fade "no glass" option --%>*/
            shadeItem($('#glassOptions').find(".IsNoGlass-True"));

            /*<%-- show glass options --%>*/
            unshadeItem($('#glassOptions').find(".IsNoGlass-False"));

        }
    }
    else if ((getSelectedDoorStyleOption().IsNoGlass == false) && (getSelectedGlass().GlassFamily.IsNoGlass == false)) {
        /*<%-- door has glass, glass is normal --%>*/

        /*<%-- shade all door and glass options --%>*/
        shadeItem($("#doorStyles li"));
        shadeItem($("#glassOptions li"));

        if (isDoorClick) {
            /*<%-- a normal glass option was selected and a door with glass was just clicked --%>*/

            /*<%-- make sure the selected door is valid for the clicked glass --%>*/
            if (!isSelectedGlassValidForDoorSelection(getSelectedGlass(), getSelectedDoorStyleOption())) {
                if (getSelectedDoorStyleOption().IsGlassFamilyException) {
                    /*<%-- set selected glass as the exception glass --%>*/
                    setSelectedGlass(gGlassOptionHash[getSelectedDoorStyleOption().GlassFamilyException.Family.toLowerCase()]);
                }
                else {
                    /*<%-- set selected glass as "clear" --%>*/
                    setSelectedGlass(getClearGlassOption());
                }
                setSelectedSideliteOptionLeft(null);
                setSelectedSideliteOptionRight(null);
                setSelectedTransomOption(null);

                /*<%-- unshade the available glass options --%>*/
                unshadeAvailableDoors();
            }
        }
        else {
            /*<%-- a door with glass was selected and a normal glass option was just clicked --%>*/

            /*<%-- make sure the selected door is valid for the clicked glass --%>*/
            if (!isSelectedGlassValidForDoorSelection(getSelectedGlass(), getSelectedDoorStyleOption())) {
                setSelectedDoorStyleOption(null);
                setSelectedSideliteOptionLeft(null);
                setSelectedSideliteOptionRight(null);
                setSelectedTransomOption(null);

                /*<%-- unshade all normal glass options --%>*/
                unshadeItem($('#glassOptions').find(".IsNoGlass-False"));
            }

        }

        /*<%-- unshade the available door options --%>*/
        unshadeAvailableDoors();

        /*<%-- unshade the available glass options --%>*/
        unshadeAvailableGlass();

        /*<%-- fade all solid doors --%>*/
        shadeItem($('#doorStyles').find(".IsNoGlass-True"));

        /*<%-- fade "no glass" option --%>*/
        shadeItem($('#glassOptions').find(".IsNoGlass-True"));
    }

    /*<%-- update the preview image --%>*/
    setPreviewDoor(getSelectedDoorStyleOption(), getSelectedGlass());
}

function sideliteStyleOptionClickHandlerLeft(event) {
    var sideliteOption = event.data.sideliteStyleOption;

    if (getSelectedGlass() != null) {
        var deselect = false;
        if (getSelectedSideliteOptionLeft() != null) {
            if (sideliteOption.SideliteStyleOptionId == getSelectedSideliteOptionLeft().SideliteStyleOptionId) {
                deselect = true;
            }
        }

        if (deselect) {
            /*<%-- this sidelite is already selected, deselect it --%>*/
            setSelectedSideliteOptionLeft(null);
        }
        else {
            if (isSideliteValidForGlassSelection(sideliteOption, getSelectedGlass())) {
                /*<%-- select this sidelite --%>*/
                setSelectedSideliteOptionLeft(sideliteOption);
            }
        }

        /*<%-- refresh style counts --%>*/
        refreshStyleCounts();

        /*<%-- style the sidelites --%>*/
        styleLeftSidelitesForGlass();

        /*<%-- highlight selected options --%>*/
        highlightItems();
    }
    else {
        alert('Please select a Glass Style.');
    }

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}

function sideliteStyleOptionClickHandlerRight(event) {
    var sideliteOption = event.data.sideliteStyleOption;

    if (getSelectedGlass() != null) {
        var deselect = false;
        if (getSelectedSideliteOptionRight() != null) {
            if (sideliteOption.SideliteStyleOptionId == getSelectedSideliteOptionRight().SideliteStyleOptionId) {
                deselect = true;
            }
        }

        if (deselect) {
            /*<%-- this sidelite is already selected, deselect it --%>*/
            setSelectedSideliteOptionRight(null);
        }
        else {
            if (isSideliteValidForGlassSelection(sideliteOption, getSelectedGlass())) {
                /*<%-- select this sidelite --%>*/
                setSelectedSideliteOptionRight(sideliteOption);
            }
        }

        /*<%-- refresh style counts --%>*/
        refreshStyleCounts();

        /*<%-- style the sidelites --%>*/
        styleRightSidelitesForGlass();

        /*<%-- highlight selected options --%>*/
        highlightItems();
    }
    else {
        alert('Please select a Glass Style.');
    }

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}


function transomStyleOptionClickHandler(event) {
    var transomOption = event.data.transomStyleOption;

    if (getSelectedGlass() != null) {
        var deselect = false;
        if (getSelectedTransomOption() != null) {
            if (transomOption.TransomStyleOptionId == getSelectedTransomOption().TransomStyleOptionId) {
                deselect = true;
            }
        }

        if (deselect) {
            /*<%-- this transom is already selected, deselect it --%>*/
            setSelectedTransomOption(null);
        }
        else {
            if (isTransomValidForGlassSelection(transomOption, getSelectedGlass())) {
                /*<%-- select this transom --%>*/
                setSelectedTransomOption(transomOption);
            }
        }

        /*<%-- refresh style counts --%>*/
        refreshStyleCounts();

        /*<%-- style the transoms --%>*/
        styleTransomsForGlass();

        /*<%-- highlight selected options --%>*/
        highlightItems();
    }
    else {
        alert('Please select a Glass Style');
    }

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}

function unshadeAvailableDoors() {
    if (getSelectedGlass() != null) {
        /*<%-- unshade the available door style options --%>*/
        unshadeItem($('#doorStyles').find(".AvailableGlass-" + getSelectedGlass().GlassFamily.Family));
    }
}

function unshadeAvailableGlass() {
    if (getSelectedDoorStyleOption() != null) {
        /*<%-- unshade the available glass options --%>*/
        var availableGlassStyles = getSelectedDoorStyleOption().AvailableGlassOptions;
        for (var i = 0; i < availableGlassStyles.length; i++) {
            unshadeItem($('#glassOptions').find(".GlassFamily-" + availableGlassStyles[i].Family));
        }
    }
}

/*<%-- style the left sidelites for the selected door --%>*/
function styleLeftSidelitesForGlass() {
    styleSidelitesForGlass(getSelectedGlass(), 'sideliteStylesLeft', 'sideliteStyleLeft');
    setPreviewSidelite(getSelectedSideliteOptionLeft(), gOrientationLeft, getSelectedGlass());
}

/*<%-- style the right sidelites for the selected door --%>*/
function styleRightSidelitesForGlass() {
    styleSidelitesForGlass(getSelectedGlass(), 'sideliteStylesRight', 'sideliteStyleRight');
    setPreviewSidelite(getSelectedSideliteOptionRight(), gOrientationRight, getSelectedGlass());
}

/*<%-- style the sidelites based on the glass --%>*/
function styleSidelitesForGlass(glassOption, sideliteStylesId, sideliteStyleLiId) {
    var sideliteOptionId = null;
    var sideliteOption = null;

    /*<%-- shade sidelite options --%>*/
    shadeItem($('#' + sideliteStylesId + ' li'));

    if (glassOption != null) {
        /*<%-- if the selected glass is "no glass", treat the sidelites as if clear glass was selected --%>*/
        if (glassOption.GlassFamily.IsNoGlass) {
            glassOption = getClearGlassOption();
        }

        $("#" + sideliteStylesId).find("li[@id^='" + sideliteStyleLiId + "-']").each(function() {
            /*<%-- get the sidelite --%>*/
            sideliteOptionId = $(this).attr('id').replace(sideliteStyleLiId + '-', '');
            sideliteOption = gSideliteStyleOptionHash[sideliteOptionId];

            if (isSideliteValidForGlassSelection(sideliteOption, glassOption)) {
                unshadeItem($(this));
            }
        });
    }
    else {
        /*<%-- no glass selected and/or no door selected --%>*/
        shadeItem($('#' + sideliteStylesId + ' li'));
    }
}

function styleTransomsForGlass() {
    var transomOptionId = null;
    var transomOption = null;

    var glassOption = getSelectedGlass();

    /*<%-- shade all transom options --%>*/
    shadeItem($('#transomStyles li'));

    if (glassOption != null) {
        /*<%-- glass and door are selected --%>*/

        /*<%-- if the selected glass is "no glass", treat the transoms as if clear glass was selected --%>*/
        if (glassOption.GlassFamily.IsNoGlass) {
            glassOption = getClearGlassOption();
        }

        $("#transomStyles").find("li[@id^='transomStyle-']").each(function() {
            /*<%-- get the transom --%>*/
            transomOptionId = $(this).attr('id').replace('transomStyle-', '');
            transomOption = gTransomStyleOptionHash[transomOptionId];

            if (isTransomValidForGlassSelection(transomOption, glassOption)) {
                unshadeItem($(this));
            }
        });
    }
    else {
        /*<%-- no glass selected and/or no door selected --%>*/
        shadeItem($('#transomStyles li'));
    }

    setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
}

function styleDoorPreviewDetails(door, glassOption) {
    if (glassOption != null) {
        $('#selectedGlass').html(glassOption.GlassFamily.FamilyDescription);
    }
    else {
        $('#selectedGlass').html('');
    }

    showHide($('#features'), (glassOption.GlassFamily.IsGrille));

    showHide($('#availableoptions'), (door.DoorConfigDetails.IsFlushGlazed || door.DoorConfigDetails.IsImpactRated));
    showHide($('#flushGlazed'), (door.DoorConfigDetails.IsFlushGlazed));
    showHide($('#impactRated'), (door.DoorConfigDetails.IsImpactRated));
    //hiding EnergyStart for the Patio
    //showHide($('#energyStar'), (door.DoorConfigDetails.IsEnergyStar));
    showHide($('#lowEGlass'), (door.DoorConfigDetails.IsLowE));

    return;
}

function showHide(obj, val) {
    if (val) {
        obj.show();
    } else {
        obj.hide();
    }
}

function styleDoorPreviewDimensions(doorStyleOption, glassOption) {
    $('#miniDimensions').hide();
    $('#sizeList').html('');

    if ((doorStyleOption != null) && (glassOption != null)) {
        var jsonArgs = {};
        jsonArgs['doorStyleShape'] = doorStyleOption.DoorStyle.StyleShape;
        jsonArgs['doorSubLine'] = gDoorSubLine;
        jsonArgs['glassFamily'] = glassOption.GlassFamily.Family;
        jsonArgs['doorHeight'] = getDoorHeight();

        $.getJSON(gJsonDoorDimensionsForOptions, jsonArgs, function data(dimensions) {
            var sizeList = '';
            for (var i = 0; i < dimensions.length; i++) {
                sizeList += "<li>" + dimensions[i].WidthDescription + " x " + dimensions[i].HeightDescription + "</li>\n";
            }
            $('#sizeList').html(sizeList);

            $('#miniDimensions').show();
        });
    }
}

/*<%--
+ update the door image to display the loading image
+ if the door is null, set the image to the placeholder image
+ if the glass is null, set the image to the selected clear glass
door image - no need to make a JSON call since it is stored in the
selected door option
+ if selected glass is clear, "no glass" or "exception glass" display
the selected door option image - no need to make a JSON call since
it is stored in the selected door option
+ if none of the above are true, make a JSON call to find the selected door
+ display the door preview details and door dimensions
--%>*/
function setPreviewDoor(doorStyleOption, glassOption) {
    /*<%-- display loading animation until JSON call completes --%>*/
    //alert(document.getElementById('rdbDoorStyleRight').attr('checked'));
    if ($('#rdbDoorStyleRight').attr('checked')) {
        //the box is checked
        //alert('it is checked')
    } else {
        //the box is not checked
        //alert('it is not checked')
    }
    updateDoorPreview(gDoorLoadingImg);
    //Added by Hamid for displaying Left Door
    if (getSelectedDoorLeftOption() != null) {
        updateDoorLeftPreview(gDoorLoadingImg);
    } else {
         updateDoorLeftPreview(getDoorPlaceHolderImg());
     }
     //Added by Hamid for displaying Right Door
     if (getSelectedDoorRightOption() != null) {
         updateDoorRightPreview(gDoorLoadingImg);
     } else {
        updateDoorRightPreview(getDoorPlaceHolderImg());
     }
    //alert(getSelectedDoorStyleOption);
    //alert(doorStyleOption.value);
    if (doorStyleOption == null) {
        /*<%-- replace the door with the placeholder image --%>*/
        updateDoorPreview(getDoorPlaceHolderImg());
        //Added by Hamid for displaying Left Door
        if (getSelectedDoorLeftOption() != null) {
            updateDoorLeftPreview(getDoorPlaceHolderImg());
        } else {
            updateDoorLeftPreview(getDoorPlaceHolderImg());
        }
        //Added by Hamid for displaying Right Door
        if (getSelectedDoorRightOption() != null) {
            updateDoorRightPreview(getDoorPlaceHolderImg);
        } else {
            updateDoorRightPreview(getDoorPlaceHolderImg());
        }
    }
    else {
        if (glassOption == null) {
            /*<%-- if the glass option hasn't been selected no need to make an ajax call --%>*/
            styleDoorPreviewDetails(doorStyleOption.ExampleDoor, glassOption);
            updateDoorPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
            //Added by Hamid for displaying Left Door
            if (getSelectedDoorLeftOption() != null) {
                updateDoorLeftPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
            } else {
                updateDoorLeftPreview(getDoorPlaceHolderImg());
            }
            //Added by Hamid for displaying Right Door
            if (getSelectedDoorRightOption() != null) {
                updateDoorRightPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
            } else {
                updateDoorRightPreview(getDoorPlaceHolderImg());
            }            
        }
        else if (glassOption.GlassFamily.IsClear || glassOption.GlassFamily.IsNoGlass) {
            /*<%-- if the glass option is clear or solid no need to make an ajax call --%>*/
            styleDoorPreviewDetails(doorStyleOption.ExampleDoor, glassOption);
            updateDoorPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
            //Added by Hamid for displaying Left Door
            if (getSelectedDoorLeftOption() != null) {
                updateDoorLeftPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
            } else {
                updateDoorLeftPreview(getDoorPlaceHolderImg());
            }
            //Added by Hamid for displaying Right Door
            if (getSelectedDoorRightOption() != null) {
                updateDoorRightPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
            } else {
                updateDoorRightPreview(getDoorPlaceHolderImg());
            }              
        }
        else {
            var jsonArgs = {};
            jsonArgs['doorStyleShape'] = doorStyleOption.DoorStyle.StyleShape;
            //jsonArgs['topCut'] = doorStyleOption.DoorStyle.TopCut.TopCut;
            jsonArgs['doorSubLine'] = gDoorSubLine;
            jsonArgs['glassFamily'] = glassOption.GlassFamily.Family;
            jsonArgs['doorHeight'] = getDoorHeight();
            /*<%-- JSON call --%>*/
            $.getJSON(gJsonDoorForOptions, jsonArgs, function data(door) {

                if (door != null) {
                    styleDoorPreviewDetails(door, glassOption);
                    updateDoorPreview(door.ImagePathMedium);
                    //Added by Hamid for displaying Left Door
                    if (getSelectedDoorLeftOption() != null) {
                        updateDoorLeftPreview(door.ImagePathMedium);
                    } else {
                        updateDoorLeftPreview(getDoorPlaceHolderImg());
                    }
                    //Added by Hamid for displaying Right Door
                    if (getSelectedDoorRightOption() != null) {
                        updateDoorRightPreview(door.ImagePathMedium);
                    } else {
                        updateDoorRightPreview(getDoorPlaceHolderImg());
                    }                      
                }
                else {
                    updateDoorPreview(getDoorPlaceHolderImg());
                    //Added by Hamid for displaying Left Door
                    if (getSelectedDoorLeftOption() != null) {
                        updateDoorLeftPreview(getDoorPlaceHolderImg);
                    } else {
                        updateDoorLeftPreview(getDoorPlaceHolderImg());
                    }
                    //Added by Hamid for displaying Right Door
                    if (getSelectedDoorRightOption() != null) {
                        updateDoorRightPreview(getDoorPlaceHolderImg);
                    } else {
                        updateDoorRightPreview(getDoorPlaceHolderImg());
                    }                      
                }
            });
        }
        styleDoorPreviewDimensions(doorStyleOption, glassOption);
    }
}

/*<%--
+ update the sidelite image to display the loading image
+ if the sidelite is null or the glass is null, set the image to the placeholder image
+ if selected glass is "no glass" or sidelite does not contain glass display
the clear glass sidelite - no need to make a JSON call since it is stored in the
selected sidelite option
+ if none of the above are true, make a JSON call to find the sidelite image path
--%>*/
function setPreviewSidelite(sideliteStyleOption, orientation, glassOption) {

    /*<%-- display loading animation until JSON call completes --%>*/
    if (orientation == gOrientationLeft) {
        updateSideliteLeftPreview(gSideliteLoadingImg);
    }
    else {
        updateSideliteRightPreview(gSideliteLoadingImg);
    }

    if (sideliteStyleOption == null) {
        if (orientation == gOrientationLeft) {
            updateSideliteLeftPreview(getSidelitePlaceHolderImg());
        }
        else if (orientation == gOrientationRight) {
            updateSideliteRightPreview(getSidelitePlaceHolderImg());
        }
    }
    else {
        if (glassOption == null) {
            if (orientation == gOrientationLeft) {
                updateSideliteLeftPreview(getSidelitePlaceHolderImg());
            }
            else if (orientation == gOrientationRight) {
                updateSideliteRightPreview(getSidelitePlaceHolderImg());
            }
        }
        else if ((glassOption.GlassFamily.IsNoGlass) || (sideliteStyleOption.IsNoGlass)) {
            /*<%-- if the no glass is selected OR the sidelite is solid, display the clear glass option --%>*/
            if (orientation == gOrientationLeft) {
                updateSideliteLeftPreview(sideliteStyleOption.ExampleSidelite.ImagePathMedium);
            }
            else if (orientation == gOrientationRight) {
                updateSideliteRightPreview(sideliteStyleOption.ExampleSidelite.ImagePathMedium);
            }
        }
        else {
            var jsonArgs = {};
            jsonArgs['doorStyleShape'] = sideliteStyleOption.DoorStyle.StyleShape;
            //jsonArgs['topCut'] = sideliteStyleOption.DoorStyle.TopCut.TopCut;
            jsonArgs['doorSubLine'] = gDoorSubLine;
            jsonArgs['glassFamily'] = glassOption.GlassFamily.Family;
            jsonArgs['doorHeight'] = getDoorHeight();

            /*<%-- JSON call --%>*/
            $.getJSON(gJsonGlassForSidelite, jsonArgs, function data(sidelite) {
                if (orientation == gOrientationLeft) {
                    if (sidelite != null) {
                        updateSideliteLeftPreview(sidelite);
                    }
                    else {
                        updateSideliteLeftPreview(getSidelitePlaceHolderImg());
                    }
                }
                else if (orientation == gOrientationRight) {
                    if (sidelite != null) {
                        updateSideliteRightPreview(sidelite);
                    }
                    else {
                        updateSideliteRightPreview(getSidelitePlaceHolderImg());
                    }
                }

            });
        }
    }
}
///*<%--Added by Hamid
//+ update the sidelite image to display the loading image
//+ if the sidelite is null or the glass is null, set the image to the placeholder image
//+ if selected glass is "no glass" or sidelite does not contain glass display
//the clear glass sidelite - no need to make a JSON call since it is stored in the
//selected sidelite option
//+ if none of the above are true, make a JSON call to find the sidelite image path
//--%>*/
//function setPreviewDoorLeftnRight(sideliteStyleOption, orientation, glassOption) {
//    /*<%-- display loading animation until JSON call completes --%>*/
//    if (orientation == gOrientationLeft) {
//        updateSideliteLeftPreview(gSideliteLoadingImg);
//    }
//    else {
//        updateSideliteRightPreview(gSideliteLoadingImg);
//    }

//    if (sideliteStyleOption == null) {
//        if (orientation == gOrientationLeft) {
//            updateSideliteLeftPreview(getSidelitePlaceHolderImg());
//        }
//        else if (orientation == gOrientationRight) {
//            updateSideliteRightPreview(getSidelitePlaceHolderImg());
//        }
//    }
//    else {
//        if (glassOption == null) {
//            if (orientation == gOrientationLeft) {
//                updateSideliteLeftPreview(getSidelitePlaceHolderImg());
//            }
//            else if (orientation == gOrientationRight) {
//                updateSideliteRightPreview(getSidelitePlaceHolderImg());
//            }
//        }
//        else if ((glassOption.GlassFamily.IsNoGlass) || (sideliteStyleOption.IsNoGlass)) {
//            /*<%-- if the no glass is selected OR the sidelite is solid, display the clear glass option --%>*/
//            if (orientation == gOrientationLeft) {
//                updateSideliteLeftPreview(sideliteStyleOption.ExampleSidelite.ImagePathMedium);
//            }
//            else if (orientation == gOrientationRight) {
//                updateSideliteRightPreview(sideliteStyleOption.ExampleSidelite.ImagePathMedium);
//            }
//        }
//        else {
//            var jsonArgs = {};
//            jsonArgs['doorStyleShape'] = sideliteStyleOption.DoorStyle.StyleShape;
//            //jsonArgs['topCut'] = sideliteStyleOption.DoorStyle.TopCut.TopCut;
//            jsonArgs['doorSubLine'] = gDoorSubLine;
//            jsonArgs['glassFamily'] = glassOption.GlassFamily.Family;
//            jsonArgs['doorHeight'] = getDoorHeight();

//            /*<%-- JSON call --%>*/
//            $.getJSON(gJsonGlassForSidelite, jsonArgs, function data(sidelite) {
//                if (orientation == gOrientationLeft) {
//                    if (sidelite != null) {
//                        updateSideliteLeftPreview(sidelite);
//                    }
//                    else {
//                        updateSideliteLeftPreview(getSidelitePlaceHolderImg());
//                    }
//                }
//                else if (orientation == gOrientationRight) {
//                    if (sidelite != null) {
//                        updateSideliteRightPreview(sidelite);
//                    }
//                    else {
//                        updateSideliteRightPreview(getSidelitePlaceHolderImg());
//                    }
//                }

//            });
//        }
//    }
//}

/*<%--
+ update the transom image to display the loading image
+ if the transom is null or the glass is null, set the image to the placeholder image
+ if selected glass is "no glass" or transom does not contain glass display
the clear glass transom - no need to make a JSON call since it is stored in the
selected transom option
+ if none of the above are true, make a JSON call to find the transom image path
--%>*/
function setPreviewTransom(transomOption, glassOption) {
    /*<%-- display loading animation until JSON call completes --%>*/
    updateTransomPreview(gTransomLoadingImg);

    if (transomOption == null) {
        updateTransomPreview(getTransomPlaceHolderImg());
        $('#transomPreviewDiv').removeAttr('class');
    }
    else {
        if (glassOption == null) {
            updateTransomPreview(getTransomPlaceHolderImg());
            /*<%-- clear classes on transom preview div --%>*/
            $('#transomPreviewDiv').removeAttr('class');
        }
        else if ((glassOption.GlassFamily.IsNoGlass) || (transomOption.IsNoGlass)) {
            /*<%-- if the no glass is selected OR transom is solid, display the clear glass option --%>*/
            updateTransomPreview(transomOption.ExampleTransom.ImagePathMedium);
            /*<%-- clear classes on transom preview div --%>*/
            $('#transomPreviewDiv').removeAttr('class');
            /*<%-- add style shape class to transom preview div --%>*/
            $('#transomPreviewDiv').addClass('transomStyle-' + transomOption.ExampleTransom.DoorStyle.StyleShape);
        }
        else {
            var jsonArgs = {};
            jsonArgs['doorStyleShape'] = transomOption.DoorStyle.StyleShape;
            jsonArgs['doorSubLine'] = gDoorSubLine;
            jsonArgs['glassFamily'] = glassOption.GlassFamily.Family;

            /*<%-- JSON call  --%>*/
            $.getJSON(gJsonGlassForTransom, jsonArgs, function data(transom) {
                var transomImgPath = null;

                if (transom != null) {
                    transomImgPath = transom;
                }
                else {
                    transomImgPath = getTransomPlaceHolderImg();
                }
                updateTransomPreview(transomImgPath);
                /*<%-- clear classes on transom preview div --%>*/
                $('#transomPreviewDiv').removeAttr('class');
                /*<%-- add style shape class to transom preview div --%>*/
                $('#transomPreviewDiv').addClass('transomStyle-' + transomOption.ExampleTransom.DoorStyle.StyleShape);
            });
        }
    }
}

/*<%-- determine if the selected glass and door options are compatible --%>*/
function isSelectedGlassValidForDoorSelection(glassOption, doorStyleOption) {
    var isValidGlass = true;

    /*<%-- the door has just been selected (or changed) make sure the selected glass is available --%>*/
    if (glassOption != null) {
        if (glassOption.GlassFamily.IsNoGlass != doorStyleOption.IsNoGlass) {
            /*<%-- a solid door must not have glass --%>*/
            isValidGlass = false;
        }
        else {
            isValidGlass = false;
            for (var i = 0; i < doorStyleOption.AvailableGlassOptions.length; i++) {
                var glassFamily = doorStyleOption.AvailableGlassOptions[i];
                if (glassOption.GlassFamily.Family == glassFamily.Family) {
                    isValidGlass = true;
                    break;
                }
            }
        }
    }

    return isValidGlass;
}

/*<%-- determine if the selected glass and sidelite options are compatible --%>*/
function isSideliteValidForGlassSelection(sidelite, glassOption) {
    var isValid = false;

    if ((glassOption != null) && (sidelite != null)) {
        if (sidelite.IsNoGlass) {
            /*<%-- a solid sidelite should be available for all glass options --%>*/
            isValid = true;
        }
        else {
            /*<%-- if the selected glass is "no glass", treat the sidelite as if clear glass was selected --%>*/
            if (glassOption.GlassFamily.IsNoGlass) {
                glassOption = getClearGlassOption();
            }

            for (var i = 0; i < sidelite.AvailableGlassOptions.length; i++) {
                if (sidelite.AvailableGlassOptions[i].Family == glassOption.GlassFamily.Family) {
                    isValid = true;
                    break;
                }
            }
        }
    }

    return isValid;
}

/*<%-- determine if the selected glass and transom options are compatible --%>*/
function isTransomValidForGlassSelection(transom, glassOption) {
    var isValid = false;

    if ((glassOption != null) && (transom != null)) {
        if (transom.IsNoGlass) {
            /*<%-- a solid transom should be available for all glass options --%>*/
            isValid = true;
        }
        else {
            /*<%-- if the selected glass is "no glass", treat the transoms as if clear glass was selected --%>*/
            if (glassOption.GlassFamily.IsNoGlass) {
                glassOption = getClearGlassOption();
            }

            for (var i = 0; i < transom.AvailableGlassOptions.length; i++) {
                if (transom.AvailableGlassOptions[i].Family == glassOption.GlassFamily.Family) {
                    isValid = true;
                    break;
                }
            }
        }
    }

    return isValid;
}

/*<%-- highlight all the selected items --%>*/
function highlightItems() {
    if (getSelectedDoorStyleOption() != null) {
        highlightItem($('#doorStyle-' + getSelectedDoorStyleOption().DoorStyleOptionId));
    }
    if (getSelectedGlass() != null) {
        highlightItem($('#glassOption-' + getSelectedGlass().GlassOptionId));
    }
    if (getSelectedSideliteOptionLeft() != null) {
        highlightItem($('#sideliteStyleLeft-' + getSelectedSideliteOptionLeft().SideliteStyleOptionId));
    }
    if (getSelectedSideliteOptionRight() != null) {
        highlightItem($('#sideliteStyleRight-' + getSelectedSideliteOptionRight().SideliteStyleOptionId));
    }

    if (getSelectedDoorLeftOption() != null) {
        highlightItem($('#doorLeftOption'));
    } else {
        unhighlightItem($('#doorLeftOption'));
    }

    if (getSelectedDoorRightOption() != null) {
        highlightItem($('#doorRightOption'));
    } else {
        unhighlightItem($('#doorRightOption'));
    }    

    if (getSelectedTransomOption() != null) {
        highlightItem($('#transomStyle-' + getSelectedTransomOption().TransomStyleOptionId));
    }
}

/*<%-- set the thickbox url for the "more info" on the currently selected glass option --%>*/
function handleGlassDetailClickUrl(event) {
    /*<%-- set the thickbox url for the "more info" on the currently selected glass option --%>*/
    setGlassDetailLink(getSelectedGlass(), 'doorpropertiesminiglassmoreinfo');

    /*<%-- cancel the click event --%>*/
    event.preventDefault();
}

/*<%-- set the url for the specified anchor and glass option --%>*/
function setGlassDetailLink(glassOption, anchorId) {
    if (glassOption != null) {
        if (glassOption.GlassFamily.IsNoGlass) {
            if (anchorId == 'doorpropertiesminiglassmoreinfo') {
                $('#doorpropertiesminiglassmoreinfowrapper').hide();
            }
        }
        else {
            /*<%-- set the thickbox url parameters for the currently selected glass option --%>*/
            /*<%-- thickbox=true tells the glass detail page this is a thickbox request and not to display navigation --%>*/
            $('#' + anchorId).attr('href', glassOption.GlassFamily.ProductDetailPath + "?height=400&width=800&inlineId=glassdetail&thickbox=true");
            $('#doorpropertiesminiglassmoreinfowrapper').show();
        }
    }
    else {
        $('#' + anchorId).attr('href', '#');
    }
}

function refreshStyleCounts() {
    /*<%-- refresh number of available doors --%>*/
    $('#availabledoorstylescount').html(countedDisplayedItems($("#doorStyles li")) + ' Available Styles');

    /*<%-- refresh number of available glass families --%>*/
    $('#availableglassstylescount').html(countedDisplayedItems($("#glassOptions li")) + ' Available Designs');

    /*<%-- refresh number of available sidelites --%>*/
    $('#availablesideliteleftstylescount').html(countedDisplayedItems($("#sideliteStylesLeft li")) + ' Available Styles');
    $('#availablesideliterightstylescount').html(countedDisplayedItems($("#sideliteStylesRight li")) + ' Available Styles');

    /*<%-- refresh number of available transoms --%>*/
    $('#availabletransomstylescount').html(countedDisplayedItems($("#transomStyles li")) + ' Available Styles');
}

/*<%-- set the image src attribute for the door preview image --%>*/
function updateDoorPreview(path) {
    $('#' + gDoorPreview).attr('src', gSiteRoot + path.replace('~', ''));
}

/*<%-- Added by Hamidset the image src attribute for the door preview image --%>*/
function updateDoorLeftPreview(path) {
    $('#' + gDoorLeftPreview).attr('src', gSiteRoot + path.replace('~', ''));
}
/*<%--function added by Hamid --%>*/
/*<%-- set the image src attribute for the door preview image --%>*/
function updateDoorRightPreview(path) {
    $('#' + gDoorRightPreview).attr('src', gSiteRoot + path.replace('~', ''));
}

/*<%-- set the image src attribute for the left sidelite preview image --%>*/
function updateSideliteLeftPreview(path) {
    $('#' + gSideliteLeftPreview).attr('src', gSiteRoot + path.replace('~', ''));
}

/*<%-- set the image src attribute for the right sidelite preview image --%>*/
function updateSideliteRightPreview(path) {
    $('#' + gSideliteRightPreview).attr('src', gSiteRoot + path.replace('~', ''));
}

/*<%-- set the image src attribute for the transom preview image --%>*/
function updateTransomPreview(path) {
    $('#' + gTransomPreview).attr('src', gSiteRoot + path.replace('~', ''));
}

/*<%--
Hash consists of key value pairs, keys and values separated by colon ":"
and key/value pairs separated by forward slashes "/".  The hash begins and
ends with a forward slash "/"

Example:
http://server/path/document?query=value#<hash>

where #<hash> format:
#/key1:value1/key2:value2/key(n):value(n)/
--%>*/
function setDocumentHashValue(key, value) {
    var hash = document.location.hash;

    /*<%-- the hash is empty, add the key and value pairs --%>*/
    if ((hash == '') || (hash == null)) {
        hash = "/" + key + ":" + value + "/";
    }
    else {
        /*<%-- check to see if this hash value already exists --%>*/
        if (hash.indexOf('/' + key + ':') > -1) {
            /*<%-- replace the key's value with the new value --%>*/
            var regex = new RegExp('/' + key + ':[^/]*/', 'g');
            var replaceValue = '/' + key + ':' + value + '/';
            hash = hash.replace(regex, replaceValue);
        }
        else {
            /*<%-- append this key value pair to the hash --%>*/
            hash += key + ':' + value + '/';
        }
    }

    /*<%-- reset the hash --%>*/
    document.location.hash = hash;
    return;
}

/*<%-- removes the value from the document hash, see setDocumentHashValue --%>*/
function removeDocumentHashValue(key) {
    if (document.location.hash.indexOf(key) > -1) {
        var value = getDocumentHashValue(key);
        //alert('removeDocumentHashValue(key) - ' + value);
        var hash = document.location.hash;
        //alert('hash - ' +  hash);
        if (hash == ('#/' + key + ':' + value + '/')) {
            hash = '';
        }
        else {
            var regex = new RegExp('/' + key + ':' + value, 'g');
            hash = hash.replace(regex, '');
        }
        if ((hash == null) || (hash == '')) {
            hash = '#/';  /*<%-- without the slash "/" the page jumps --%>*/
        }
        document.location.hash = hash;
    }
}

/*<%-- retrieves the value from the document hash, see setDocumentHashValue --%>*/
function getDocumentHashValue(key) {
    var hash = document.location.hash;
    var value = null;

    /*<%-- the hash is empty, add the key and value pairs --%>*/
    if ((hash != '') && (hash != null)) {
        /*<%-- check to see if this hash value already exists --%>*/
        if (hash.indexOf('/' + key + ':') > -1) {
            var regex = new RegExp('/' + key + ':[^/]*/', 'g');
            value = hash.match(regex);

            if (value.length > 0) {
                value = value[0];
                value = value.substring((value.indexOf(':') + 1), (value.length - 1));
            }
        }
    }

    return value;
}

/*<%-- returns the number of items in the list that contain the class 'fadedItem' --%>*/
function countedDisplayedItems(items) {
    var total = items.length;
    items.each(function() {
        if ($(this).hasClass('fadedItem')) {
            total--;
        }
    });

    return total;
}

/*<%-- applies the class fadedItem to the selected item(s) --%>*/
function shadeItem(item) {
    item.addClass('fadedItem');
    item.removeClass('highlightItem');
}

/*<%-- applies the class normalItem to the selected item(s)  --%>*/
function unshadeItem(item) {
    item.removeClass('fadedItem');
    item.removeClass('highlightItem');
}

/*<%-- applies the class highlightItem to the selected item(s)  --%>*/
function highlightItem(item) {
    item.addClass('highlightItem');
    item.removeClass('fadedItem');
}

/*<%-- display the door properties if a door and glass are selected --%>*/
function toggleDoorProperties() {
    if ((getSelectedGlass() == null) || (getSelectedDoorStyleOption() == null)) {
        $('#doorpropertiesmini').hide();
        $('#energyStar').hide();
        $('#features').hide();
    }
    else {
        $('#doorpropertiesmini').show();
        //energyStar should always stay invisible for Patio
        $('#energyStar').hide();
    }
}

/*<%-- remove the highlightItem class from the selected item(s) --%>*/
function unhighlightItem(item) {
    item.removeClass('highlightItem');
}

/*<%-- the configured no glass option for this doorsubline --%>*/
function getNoGlassOption() {
    return gNoGlassOption;
}

/*<%-- the configured clear glass option for this doorsubline --%>*/
function getClearGlassOption() {
    return gClearGlassOption;
}

/*<%-- checks to see if the glass is a configured exception glass (such as Camino/Augustine for Rustic) --%>*/
function isExceptionGlass(glassFamily) {
    var isMatch = false;
    for (var i = 0; i < gConfiguratorExceptions.length; i++) {
        if ((gDoorSubLine == gConfiguratorExceptions[i].DoorSubLine.Abbreviation) && (glassFamily.Family == gConfiguratorExceptions[i].GlassFamily.Family)) {
            isMatch = true;
            break;
        }
    }
    return isMatch;
}


var gSelectedDoorStyleOption = null;
var gSelectedGlass = null;
var gSelectedSideliteOptionRight = null;

//Added by Hamid
var gSelectedDoorLeftOption = null;
var gSelectedDoorRightOption = null;


var gSelectedSideliteOptionLeft = null;
var gSelectedTransomOption = null;

var gLoadedDoorLinkId = null;
var gLoadedGlassLinkId = null;

//Added by Hamid
var gLoadedDoorLeftLinkId = null;
var gLoadedDoorRightLinkId = null;

var gLoadedTransomLinkId = null;
var gLoadedSideliteLeftLinkId = null;
var gLoadedSideliteRightLinkId = null;

function getSelectedDoorStyleOption() {

    if (gSelectedDoorStyleOption == null) {
        gSelectedDoorStyleOption = gDoorStyleOptionHash[getDocumentHashValue(gDoorStyleOptionKey)];
    }
    return gSelectedDoorStyleOption;
}
function setSelectedDoorStyleOption(value) {
    gSelectedDoorStyleOption = value;

    if (value != null) {
        //alert('setSectedDoorStyleOption(value) - ' + value.DoorStyleOptionId);
        /*<%-- update the page hash with the selected door style option --%>*/
        setDocumentHashValue(gDoorStyleOptionKey, value.DoorStyleOptionId);
    }
    else {
        removeDocumentHashValue(gDoorStyleOptionKey);
    }
}

function getSelectedGlass() {
    if (gSelectedGlass == null) {
        gSelectedGlass = gGlassOptionHash[getDocumentHashValue(gGlassOptionKey)];
    }
    return gSelectedGlass;
}
function setSelectedGlass(value) {
    gSelectedGlass = value;

    if (value != null) {
        //alert('setSectedGlass(value) - ' + value.GlassOptionId);
        /*<%-- update the page hash with the selected glass option --%>*/
        setDocumentHashValue(gGlassOptionKey, value.GlassOptionId);
    }
    else {
        removeDocumentHashValue(gGlassOptionKey);
    }
}

function getSelectedSideliteOptionRight() {
    if (gSelectedSideliteOptionRight == null) {
        gSelectedSideliteOptionRight = gSideliteStyleOptionHash[getDocumentHashValue(gSideliteStyleOptionRightKey)];
    }
    return gSelectedSideliteOptionRight;
}
//Added by Hamid
function getSelectedDoorLeftOption() {
    if (gSelectedDoorLeftOption == null) {
        gSelectedDoorLeftOption = gDoorLeftOptionHash[getDocumentHashValue(gDoorLeftOptionKey)];
        //gSelectedDoorLeftOption = 'DoorLeft';
    }
    return gSelectedDoorLeftOption;
}
//Added by Hamid
function setSelectedDoorLeftOption(value) {
    gSelectedDoorLeftOption = value;
    //gSelectedDoorLeftOption = 'DoorLeft';
    //alert('setSelectedDoorLeftOption(value) - ' + gSelectedDoorLeftOption );
    if (value != null) {
        /*<%-- update the page hash with the selected door style option --%>*/
        //setDocumentHashValue(gDoorLeftOptionKey, value.DoorLeftOptionId);
        setDocumentHashValue(gDoorLeftOptionKey, gSelectedDoorLeftOption);
        //setDocumentHashValue(gDoorLeftOptionKey, 'DoorLeft');
    }
    else {
        removeDocumentHashValue(gDoorLeftOptionKey);
        //removeDocumentHashValue('dl');
    }
}

//Added by Hamid
function getSelectedDoorRightOption() {
    if (gSelectedDoorRightOption == null) {
        gSelectedDoorRightOption = gDoorRightOptionHash[getDocumentHashValue(gDoorRightOptionKey)];
        //gSelectedDoorRightOption = 'DoorRight';
    }
    return gSelectedDoorRightOption;
}
//Added by Hamid
function setSelectedDoorRightOption(value) {
    gSelectedDoorRightOption = value;
    if (value != null) {
        /*<%-- update the page hash with the selected door style option --%>*/
        //setDocumentHashValue(gDoorRightOptionKey, value.DoorRightOptionId);
        setDocumentHashValue(gDoorRightOptionKey, gSelectedDoorRightOption);
        //setDocumentHashValue(gDoorRightOptionKey, 'DoorRight');
    }
    else {
        removeDocumentHashValue(gDoorRightOptionKey);
        //removeDocumentHashValue('dr');
    }
}


function setSelectedSideliteOptionRight(value) {
    gSelectedSideliteOptionRight = value;

    if (value != null) {
        /*<%-- update the page hash with the selected sidelite --%>*/
        setDocumentHashValue(gSideliteStyleOptionRightKey, value.SideliteStyleOptionId);
    }
    else {
        removeDocumentHashValue(gSideliteStyleOptionRightKey);
    }
}

function getSelectedSideliteOptionLeft() {
    if (gSelectedSideliteOptionLeft == null) {
        gSelectedSideliteOptionLeft = gSideliteStyleOptionHash[getDocumentHashValue(gSideliteStyleOptionLeftKey)];
    }
    return gSelectedSideliteOptionLeft;
}
function setSelectedSideliteOptionLeft(value) {
    gSelectedSideliteOptionLeft = value;

    if (value != null) {
        /*<%-- update the page hash with the selected sidelite --%>*/
        setDocumentHashValue(gSideliteStyleOptionLeftKey, value.SideliteStyleOptionId);
    }
    else {
        removeDocumentHashValue(gSideliteStyleOptionLeftKey);
    }
}

function getSelectedTransomOption() {
    if (gSelectedTransomOption == null) {
        gSelectedTransomOption = gTransomStyleOptionHash[getDocumentHashValue(gTransomStyleOptionKey)];
    }
    return gSelectedTransomOption;
}
function setSelectedTransomOption(value) {
    gSelectedTransomOption = value;

    if (value != null) {
        /*<%-- update the page hash with the selected transom --%>*/
        setDocumentHashValue(gTransomStyleOptionKey, value.TransomStyleOptionId);
    }
    else {
        removeDocumentHashValue(gTransomStyleOptionKey);
    }
}

function getLoadedDoorLinkId() { return gLoadedDoorLinkId; }
function setLoadedDoorLinkId(value) { gLoadedDoorLinkId = value; }

function getLoadedGlassLinkId() { return gLoadedGlassLinkId; }
function setLoadedGlassLinkId(value) { gLoadedGlassLinkId = value; }

//Added by Hamid
function getLoadedDoorLeftLinkId() { return gLoadedDoorLeftLinkId; }
function setLoadedDoorLeftLinkId(value) { gLoadedDoorLeftLinkId = value; }

//Added by Hamid
function getLoadedDoorRightLinkId() { return gLoadedDoorRightLinkId; }
function setLoadedDoorRightLinkId(value) { gLoadedDoorRightLinkId = value; }


function getLoadedTransomLinkId() { return gLoadedTransomLinkId; }
function setLoadedTransomLinkId(value) { gLoadedTransomLinkId = value; }

function getLoadedSideliteLeftLinkId() { return gLoadedSideliteLeftLinkId; }
function setLoadedSideliteLeftLinkId(value) { gLoadedSideliteLeftLinkId = value; }

function getLoadedSideliteRightLinkId() { return gLoadedSideliteRightLinkId; }
function setLoadedSideliteRightLinkId(value) { gLoadedSideliteRightLinkId = value; }

function getDoorHeight() { return gDoorHeight; }
function isEightFootPage() {
    return (getDoorHeight() == '8\'0\"');
}

function getDoorPlaceHolderImg() {
    if (isEightFootPage()) {
        return gPlaceholderImageDoor8Foot;
    }
    return gPlaceholderImageDoor;
}

function getTransomPlaceHolderImg() {
    if (isEightFootPage()) {
        return gPlaceholderImageTransom8Foot;
    }
    return gPlaceholderImageTransom;
}

function getSidelitePlaceHolderImg() {
    if (isEightFootPage()) {
        return gPlaceholderImageSidelite8Foot;
    }
    return gPlaceholderImageSidelite;
}

function getImageInstructionsPlaceHolderImg() {
    if (isEightFootPage()) {
        return gPlaceholderImageInstructions8Foot;
    }
    return gPlaceholderImageInstructions;
}

