
/*<%-- 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';
//MSD: Added variables for site root
var gJsonSaveDoor = gSiteRoot + '/services/savedoor.aspx';

/*<%-- thickbox iframe pages --%>*/
var gDoorImagePreviewProvider = gSiteRoot + "/products/doordetail/fulldetailload.aspx";
//var gDoorImagePreviewProvider = gSiteRoot + "/products/patiodetail/fulldetailload.aspx";
//MSD: Added variable to augment building querystring from hash
/*<%-- MyThermaTru Doors page --%>*/
var gMyThermaTruDoors = gSiteRoot + "/MyThermaTru/index.aspx";
var gMyThermaTruCreateAcct = gSiteRoot + "/MyThermaTru/createaccount.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";
/*<%-- 20101028 - for door config (dbldoors) --%>*/
var gDoorConfigKey = "cfg";

/*<%-- 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;

/*<%-- Augmented querystring to be built from hash --%>*/
var qs = "";

/*<%-- 20101028-Double Door Image --%>*/
var gDblDoorImg = "";

/*<%-- call to initialize the page --%>*/
function initPage(quoteSessionId) {
	/*<%-- initialize the gQuoteSessionId --%>*/
	gQuoteSessionId = quoteSessionId;

	initAccordian();
	/*<%-- 20101028-Initialize the panels --%>*/
	initPanels();
	initClueTips();
	initSelectedItems();
	initFilters();
	doorAndGlassSelectionController(false);
	toggleDoorProperties();
	setZoomClickUrl(); /* note!  setZoomClickUrl() sets the qs var!  this could be refactored out at a later time */
	showHideZoomButton();
	showHideShareBar(); 	// this guy needs the qs var
	initSaveButtonClick();
	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();
	/*<%-- 20101028-Open the config options panel --%>*/
	$('#configHeader').addClass('down');
	$('#doorHeader').addClass('down');
	/*<%-- 20101028-Show door filters and styles --%>*/
	$('#doorfilters').show();
	$('#doorStyles').show();
	$('#glass h3').addClass('down');
	$('#glass ul').show();
	/*<%-- 20101028-Hide the Double Door disclaimer --%>*/
	$('#dblDisclaimer').addClass('hidden');

	/*<%-- 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
		/*<%-- 20101028-Add config header to 'not' so it does not trigger collapses --%>*/
		if (!$(this).is('#doorHeader, #glassHeader, #configHeader')) {
			//Adds Auto-Scroll functionality to the page
			$.scrollTo($('#selectionsHeader'), 500, { onAfter: function () {
				$('#doorStyles').slideUp(1000);
				$('#doorHeader').removeClass('down');
				$('#doorfilters').slideUp();
				/*<%-- 20101028-collapse configstyles and close config header arrow --%>*/
				$('#configStyles').slideUp(1000);
				$('#configHeader').removeClass('down');
				$('#glassOptions').slideUp(1000);
				$('#glassHeader').removeClass('down');
			}
			});
		} else {
			$('#sidelitesleft ul').slideUp(1000);
			$('#sidelitesleft h3').removeClass('down');
			$('#sidelitesright ul').slideUp(1000);
			$('#sidelitesright h3').removeClass('down');
			$('#transom ul').slideUp(1000);
			$('#transom h3').removeClass('down');
		}


		/*<%-- 20101028-Hide the filters when necessary --%>*/
		if (!$(this).hasClass('down') && $(this).is('#doorHeader')) {
			$('#doorfilters').slideUp();
		} else if ($(this).hasClass('down') && $(this).is('#doorHeader')) {
			$('#doorfilters').slideDown();
		}

		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;
	});
}

/*<%-- 20101028 - manage the panels based on door config selection --%>*/
function initPanels(){

	/*<%-- add a mouse pointer --%>*/
	$('.config').attr('style', 'cursor:pointer;');
	/*<%-- add a click handler to the config images --%>*/
	$('.config').click(function() {
		/*<%-- Remove all 'selections' --%>*/
		$('.config').removeClass('highlightItem');
		/*<%-- a 'selection' to 'this' --%>*/
		$(this).addClass('highlightItem');
		/*<%-- hide unneeded sections --%>*/
		var doorCfg = this.id;
		switch (doorCfg){
			case 'sd':
				// First, remove sidelites and transom options from hash
				setSelectedSideliteOptionLeft(null);
				setSelectedSideliteOptionRight(null);
				setSelectedTransomOption(null);
				// then remove any preview for the same
				setPreviewSidelite(getSelectedSideliteOptionRight(), gOrientationRight, getSelectedGlass());
				setPreviewSidelite(getSelectedSideliteOptionLeft(), gOrientationLeft, getSelectedGlass());
				setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
				//then hide the containers
				$('#sidelitesleft ul').slideUp(1000);
				$('#sidelitesleft h3').removeClass('down');
				$('#sidelitesleft').fadeOut(1000);
				$('#sidelitesright ul').slideUp(1000);
				$('#sidelitesright h3').removeClass('down');
				$('#sidelitesright').fadeOut('slow');
				$('#transom ul').slideUp(1000);
				$('#transom h3').removeClass('down');
				$('#transom').fadeOut('slow');
				//manage disclaimer
				$('#dblDisclaimer').addClass('hidden');
				break;
			case 'dd':

				// First, remove sidelites and transom options from hash
				setSelectedSideliteOptionLeft(null);
				setSelectedSideliteOptionRight(null);
				setSelectedTransomOption(null);
				// then remove any preview for the same
				setPreviewSidelite(getSelectedSideliteOptionRight(), gOrientationRight, getSelectedGlass());
				setPreviewSidelite(getSelectedSideliteOptionLeft(), gOrientationLeft, getSelectedGlass());
				setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
				//then hide the containers
				$('#sidelitesleft ul').slideUp(1000);
				$('#sidelitesleft h3').removeClass('down');
				$('#sidelitesleft').fadeOut(1000);
				$('#sidelitesright ul').slideUp(1000);
				$('#sidelitesright h3').removeClass('down');
				$('#sidelitesright').fadeOut('slow');
				$('#transom ul').slideUp(1000);
				$('#transom h3').removeClass('down');
				$('#transom').fadeOut('slow');
				//manage disclaimer
				$('#dblDisclaimer').removeClass('hidden');
				break;
			case 'dlsl':
				// First, remove right sidelite and transom options from hash
				setSelectedSideliteOptionRight(null);
				setSelectedTransomOption(null);
				// then remove any preview for the same
				setPreviewSidelite(getSelectedSideliteOptionRight(), gOrientationRight, getSelectedGlass());
				setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
				//then hide the containers, show the left sidelites
				$('#sidelitesleft').fadeIn('slow');
				$('#sidelitesright').fadeOut('slow');
				$('#transom').fadeOut('slow');
				//manage disclaimer
				$('#dblDisclaimer').addClass('hidden');
				break;
			case 'drsl':
				// First, remove right sidelite and transom options from hash
				setSelectedSideliteOptionLeft(null);
				setSelectedTransomOption(null);
				// then remove any preview for the same
				setPreviewSidelite(getSelectedSideliteOptionLeft(), gOrientationLeft, getSelectedGlass());
				setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
				//then hide the containers, show the right sidelites
				$('#sidelitesleft').fadeOut('slow');
				$('#sidelitesright').fadeIn('slow');
				$('#transom').fadeOut('slow');
				//manage disclaimer
				$('#dblDisclaimer').addClass('hidden');
				break;
			case 'dbsl':
				// First, remove transom options from hash
				setSelectedTransomOption(null);
				// then remove any preview for the same
				setPreviewTransom(getSelectedTransomOption(), getSelectedGlass());
				//then hide the containers, show left and rigth sidelites
				$('#sidelitesleft').fadeIn('slow');
				$('#sidelitesright').fadeIn('slow');
				$('#transom').fadeOut('slow');
				//manage disclaimer
				$('#dblDisclaimer').addClass('hidden');
				break;
			case 'dt':
				// First, remove sidelite options from hash
				setSelectedSideliteOptionLeft(null);
				setSelectedSideliteOptionRight(null);
				// then remove any preview for the same
				setPreviewSidelite(getSelectedSideliteOptionRight(), gOrientationRight, getSelectedGlass());
				setPreviewSidelite(getSelectedSideliteOptionLeft(), gOrientationLeft, getSelectedGlass());
				//then hide the containers, show the transoms
				$('#sidelitesleft').fadeOut('slow');
				$('#sidelitesright').fadeOut('slow');
				$('#transom').fadeIn('slow');
				//manage disclaimer
				$('#dblDisclaimer').addClass('hidden');
				break;
			case 'dbslt':
				//This is the previously normal state of affairs, lets not change it
				//show the containers
				$('#sidelitesleft').fadeIn('slow');
				$('#sidelitesright').fadeIn('slow');
				$('#transom').fadeIn('slow');
				//manage disclaimer
				$('#dblDisclaimer').addClass('hidden');
				break;
		}
		setSelectedDoorConfigOption(doorCfg);
		setZoomClickUrl();
		setPreviews(doorCfg);
		});
}
//sets up the door preview
function setPreviews(config){
    var doorConfig = config;
    var slWidth;
    var doorWidth;
    if (gDoorHeight == '8\'0\"') {
        slWidth = 39;
    } else {
        slWidth = 37;
    }
	switch (doorConfig){
	case 'sd':
		$('.dbldoor img').fadeOut(1000);
		$('#transomPreviewDiv img').fadeOut(1000, function(){
			$('.lsidelite img').fadeTo(1000, 0, function(){
			    $('.lsidelite').width(slWidth);
			    $('.lsidelite img').width(slWidth);
			});
			$('.rsidelite img').fadeTo(1000, 0, function(){
				$('.rsidelite').width(slWidth);
				$('.rsidelite img').width(slWidth);
				$('.doorconfig').width(179);
			});
		});
		setSelectedSideliteOptionLeft(null);
		setSelectedSideliteOptionRight(null);
		setSelectedTransomOption(null);
		break;
	case 'dd':
		$('#transomPreviewDiv img').fadeOut(1000, function () {
			$('.lsidelite img').fadeTo(1000, 0, function () {
				$('.lsidelite').width(7);
				$('.lsidelite img').width(0);
            });
			$('.rsidelite img').fadeTo(1000, 0, function () {
				$('.rsidelite').width(6);
				$('.rsidelite img').width(0);
				$('.doorconfig').width(215);
				var doorImgSrc = $('.door img').attr('src');
				$('.dbldoor img').attr('src', doorImgSrc);
				$('.dbldoor img').fadeIn(1000);
			});
		});
		setSelectedSideliteOptionLeft(null);
		setSelectedSideliteOptionRight(null);
		setSelectedTransomOption(null);
		break;
	case 'dlsl':
		$('.dbldoor img').fadeOut(1000, function(){
			$('#transomPreviewDiv img').fadeOut(1000, function(){
			    $('.lsidelite').width(slWidth);
			    $('.lsidelite img').width(slWidth);
			    $('.doorconfig').width(179);
				$('.lsidelite img').fadeTo(1000, 100, function(){
				});
				$('.rsidelite img').fadeTo(1000, 0, function(){
					$('.rsidelite').width(slWidth);
					$('.rsidelite img').width(slWidth);
				});
			});
		});
		setSelectedSideliteOptionRight(null);
		setSelectedTransomOption(null);
		break;
	case 'drsl':
		$('.dbldoor img').fadeOut(1000, function(){
			$('#transomPreviewDiv img').fadeOut(1000, function(){
				$('.rsidelite').width(slWidth);
				$('.rsidelite img').width(slWidth);
				$('.doorconfig').width(179);
				$('.rsidelite img').fadeTo(1000, 100, function(){
				});
				$('.lsidelite img').fadeTo(1000, 0, function(){
				    $('.lsidelite').width(slWidth);
				    $('.lsidelite img').width(slWidth);
				});
			});
		});
		setSelectedSideliteOptionLeft(null);
		setSelectedTransomOption(null);
		break;
	case 'dbsl':
		$('.dbldoor img').fadeOut(1000, function(){
			$('#transomPreviewDiv img').fadeOut(1000, function(){
				$('.lsidelite').width(slWidth);
				$('.doorconfig').width(179);
				$('.lsidelite img').fadeTo(1000, 100, function(){
				    $('.lsidelite img').width(slWidth);
				});
				$('.rsidelite img').fadeTo(1000, 100, function(){
					$('.rsidelite').width(slWidth);
					$('.rsidelite img').width(slWidth);
				});
			});
		});
		setSelectedTransomOption(null);
	   break;
	case 'dt':
		$('.dbldoor img').fadeOut(1000, function(){
				$('.lsidelite').width(slWidth);
				$('.doorconfig').width(179);
				$('.lsidelite img').fadeTo(1000, 0, function(){
				    $('.lsidelite img').width(slWidth);
				});
				$('.rsidelite img').fadeTo(1000, 0, function(){
					$('.rsidelite').width(slWidth);
					$('.rsidelite img').width(slWidth);
					$('#transomPreviewDiv img').fadeIn(1000);
				});
		});
	   break;
		setSelectedSideliteOptionLeft(null);
		setSelectedSideliteOptionRight(null);
	default:
		//sets it back to door with transom and both sidelites
		$('.dbldoor img').fadeOut(1000, function(){
			$('.doorconfig').width(179);
			$('.lsidelite').width(slWidth);
			$('.lsidelite img').fadeTo(1000, 100, function(){
			    $('.lsidelite img').width(slWidth);
			    $('.rsidelite').width(slWidth);
				$('.rsidelite img').width(slWidth);
				$('.rsidelite img').fadeTo(1000, 100, function () {
					$('#transomPreviewDiv img').fadeIn(1000);
				});
			});
		});
		break;
}
$('h3#configHeader').click();
}

/*<%-- 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());

	/*<%-- 20101028-update the selected config image --%>*/
	setPreviewDoorConfig(getSelectedDoorConfig());
}

/*<%-- registers a click event for the element doorStyleOptionLinkId and passes the doorStyleOption to the doorClickHandler --%>*/
function initDoorStyleOptionSelection(doorStyleOptionId, doorStyleOptionLinkId) {
	var doorLink = $('#' + doorStyleOptionLinkId);
	var doorStyleOption = gDoorStyleOptionHash[doorStyleOptionId];

	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);
	}
}

/*<%-- 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)) {
		setLoadedGlassLinkId(glassOptionLinkId);
	}
}

/*<%-- 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);
	}
}
/*<%-- 20101028-Handles a click on the door config  --%>*/
function initDoorConfigSelection(DoorConfigId) {
	var doorLink = $('#' + DoorConfigId);
	doorLink.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 (DoorConfigId == getDocumentHashValue(gDoorConfigKey)) {
		setLoadedDoorConfigId(DoorConfigId);
	}
}

function initFilters() {
/*<%-- 20101028-bind click event to noise reduction filter --%>*/
	$('#' + gCheckboxNoiseReduction).bind('click', {}, doorFilterClickHandler);
	$('#' + gCheckboxEnergyStar).bind('click', {}, doorFilterClickHandler);
	$('#' + gCheckboxImpactRated).bind('click', {}, doorFilterClickHandler);
	$('#' + gCheckboxFlushGlazed).bind('click', {}, doorFilterClickHandler);
}


function handleZoomClickUrl(event) {
	setZoomClickUrl();
	showHideZoomButton();
	//MSD: Added call to showHideShareBar
	showHideShareBar();

	/*<%-- 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());


		//20101028 - Add Door Config to args
		if (getSelectedDoorConfig() != null && getSelectedDoorConfig() == 'dd') {
			args['doorQty'] = 2;
			args['doorCfg'] = getSelectedDoorConfig();
		} else {
			args['doorQty'] = 1;
			args['doorCfg'] = getSelectedDoorConfig();
		}
		//20101028 - Solid door doorGlassOption=IsNoGlass
		if (getSelectedDoorStyleOption().IsNoGlass) {
			args['doorGlassOption'] = 'IsNoGlass';
		} else {
			args['doorGlassOption'] = 'HasGlass';
		}
		/* MSD: note that qs is now globally scoped */
		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");
		$('#' + gWhereToBuyContact).attr('href', gDoorImagePreviewProvider + "?wtb=true&" + qs);
	}
	else {
		$('#' + gZoomDetail).attr('href', '#');
	}
}

/*<%--MSD: enables share bar buttons when a door style is selected --%>*/
function showHideShareBar() {

	var shareUrl = escape(document.location);

	if ((getSelectedGlass() != null) && (getSelectedDoorStyleOption() != null)) {
		$('#' + gEmailDoorAlt).attr("href", "/email2/?" + qs + "&TB_iframe=true&height=500&width=800&modal=false");
		$('#' + gEmailDoor).attr("href", "javascript:goEmail();");
		$('#' + gEmailDoorImg).attr("src", "/images/btn-emailpage3_on.png");
		$('#' + gEmailDoorSpan).removeClass("linkItOff").addClass("linkIt");
		$('#' + gFacebookDoor).attr("href", "http://www.facebook.com/sharer.php?u=" + shareUrl + "&t=My+Saved+Doors");
		//$('#' + gFacebookDoor).attr("target", "_blank");
		$('#' + gFacebookDoorImg).attr("src", "/images/btn-facebook_on.png");
		$('#' + gFacebookDoorSpan).removeClass("linkItOff").addClass("linkIt");
		$('#' + gShareDoorImg).attr("src", "/images/btn-share3_on.png");
		$('#' + gShareDoorSpan).removeClass("linkItOff").addClass("linkIt");
		$('#' + gPrintDoor).attr("href", "javascript:window.print();");
		$('#' + gPrintDoorImg).attr("src", "/images/btn-print3_on.png");
		$('#' + gPrintDoorSpan).removeClass("linkItOff").addClass("linkIt");
	}
	else {
		$('#' + gEmailDoorAlt).attr("href", "javascript:void(0);");
		$('#' + gEmailDoor).attr("href", "javascript:void(0);");
		$('#' + gEmailDoorImg).attr("src", "/images/btn-emailpage3_off.png");
		$('#' + gEmailDoorSpan).removeClass("linkIt").addClass("linkItOff");
		$('#' + gFacebookDoor).attr("href", "javascript:void(0);");
		$('#' + gFacebookDoorImg).attr("src", "/images/btn-facebook_off.png");
		$('#' + gFacebookDoorSpan).removeClass("linkIt").addClass("linkItOff");
		$('#' + gShareDoorImg).attr("src", "/images/btn-share3_off.png");
		$('#' + gShareDoorSpan).removeClass("linkIt").addClass("linkItOff");
		$('#' + gPrintDoor).attr("href", "javascript:void(0);");
		$('#' + gPrintDoorImg).attr("src", "/images/btn-print3_off.png");
		$('#' + gPrintDoorSpan).removeClass("linkIt").addClass("linkItOff");
	}

}

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();
	//MSD
	setZoomClickUrl();
	showHideZoomButton();
	showHideShareBar();

	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'));
	var isNoiseReducedClick = (($('#' + gCheckboxNoiseReduction).attr('checked') == null) ? false : $('#' + gCheckboxNoiseReduction).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';
	}
	if (isNoiseReducedClick) {
		classes[classes.length] = 'IsNoiseReducedAvailable-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');
	$('#' + gCheckboxNoiseReduction).removeAttr('checked');
}

function doorClickHandler(event) {
	setSelectedDoorStyleOption(event.data.doorStyleOption);
	doorAndGlassSelectionController(true);

	/*<%-- cancel the click event --%>*/
	event.preventDefault();
}

function glassClickHandler(event) {
	setSelectedGlass(event.data.glassOption);
	doorAndGlassSelectionController(false);

	/*<%-- cancel the click event --%>*/
	event.preventDefault();
}

function doorAndGlassSelectionController(isDoorClick) {

	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();

	/*<%-- 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 --%>*/
		//20101028 - change shaded items - shadeItem($('#doorStyles').find(".IsNoGlass-False"));
		unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

		/*<%-- fade all the glass options except the no glass option --%>*/
		//20101028 - change shaded items - shadeItem($('#glassOptions').find(".IsNoGlass-False"));
		unshadeItem($('#glassOptions').find(".IsNoGlass-True"));

		/*<%-- set selected glass as "no glass" since it is the only possible choice --%>*/
		//20101028 - change the noglassoption
		setSelectedGlass(getNoGlassOption());
		//setSelectedGlass(getClearGlassOption());
	}
	else {
		/*<%-- a door with glass is selected --%>*/

		/*<%-- show all glass doors --%>*/
		//20101028 - change shaded items - 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 --%>*/
		//20101028 - change shaded items - 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"));
		//20101028 - change shaded items - unshadeItem($("#doorStyles li"));

		/*<%-- fade all the glass options except the no glass option --%>*/
		shadeItem($("#glassOptions li"));
		unshadeItem($('#glassOptions').find(".IsNoGlass-True"));
		//20101028 - change shaded items - unshadeItem($("#glassOptions li"));
	}
	else {
		/*<%-- display everything except solid doors and "no glass" --%>*/

		/*<%-- fade all doors --%>*/
		shadeItem($("#doorStyles li"));

		/*<%-- show normal glass options --%>*/
		//20101028 - change shaded items - unshadeItem($('#glassOptions').find(".IsNoGlass-False"));
				unshadeItem($("#glassOptions li"));

		/*<%-- unshade the available door options --%>*/
		unshadeAvailableDoors();

		/*<%-- fade all solid doors --%>*/
		//20101028 - change shaded items - shadeItem($('#doorStyles').find(".IsNoGlass-True"));
		unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

		/*<%-- fade "no glass" option --%>*/
		shadeItem($('#glassOptions').find(".IsNoGlass-True"));
		//20101028 - change shaded items - unshadeItem($('#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 --%>*/
//        20101028 - change shaded items - shadeItem($("#glassOptions li"));
//        20101028 - change shaded items - unshadeItem($('#glassOptions').find(".IsNoGlass-True"));
		unshadeItem($("#glassOptions li"));
		//20101028 - Set No Glass Option based on glass clicked
		if (getSelectedGlass().GlassFamily.IsNoGlass) {
			setSelectedGlass(getNoGlassOption());
		}else{
			if (getSelectedDoorStyleOption().IsGlassFamilyException) {
				/*<%-- set selected glass as the exception glass --%>*/
				setSelectedGlass(gGlassOptionHash[getSelectedDoorStyleOption().GlassFamilyException.Family.toLowerCase()]);
			}
			else {
				/*<%-- set selected glass as "clear" --%>*/
				//setSelectedGlass(getClearGlassOption());
				//alert("Not setting selected glass");
			}
		}
	}
		//END RFDII Set No Glass Option based on glass clicked
	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 --%>*/
			//20101028 - change shaded items - shadeItem($("#glassOptions li"));
			//20101028 - change shaded items - unshadeItem($('#glassOptions').find(".IsNoGlass-False"));
			unshadeItem($("#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 --%>*/
			unshadeAvailableDoors();
			//20101028 - change shaded items - 
			unshadeItem($('#doorStyles').find(".IsNoGlass-True"));
		}
		else {
			/*<%-- a door with no glass was selected and "no glass" was just clicked --%>*/
			/*<%-- fade all glass doors --%>*/
			//20101028 - change shaded items - shadeItem($('#doorStyles').find(".IsNoGlass-False"));
			//20101028 - change shaded items - unshadeItem($('#doorStyles').find(".IsNoGlass-True"));
			unshadeItem($('#doorStyles').find(".IsNoGlass-False"));

			/*<%-- fade normal glass options --%>*/
			//20101028 - change shaded items - shadeItem($('#glassOptions').find(".IsNoGlass-False"));
			//20101028 - change shaded items - unshadeItem($('#glassOptions').find(".IsNoGlass-True"));
			unshadeItem($('#glassOptions').find(".IsNoGlass-False"));

			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 --%>*/
			//20101028 - change shaded items - shadeItem($('#doorStyles').find(".IsNoGlass-False"));
			//20101028 - change shaded items - unshadeItem($('#doorStyles').find(".IsNoGlass-True"));
			unshadeItem($('#doorStyles').find(".IsNoGlass-False"));

			/*<%-- fade all the glass options except the no glass option --%>*/
			//20101028 - change shaded items - shadeItem($('#glassOptions').find(".IsNoGlass-False"));
			//20101028 - change shaded items - unshadeItem($('#glassOptions').find(".IsNoGlass-True"));
			unshadeItem($('#glassOptions').find(".IsNoGlass-False"));

			/*<%-- set selected glass as "no glass" since it is the only possible choice --%>*/
			//20101028 - do NOT set selected glass - 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 --%>*/
			//20101028 - change shaded items -  - shadeItem($("#doorStyles li"));
			unshadeItem($("#doorStyles li"));

			/*<%-- these selections are incompatible, reset the door --%>*/
			//20101028 - leave them as was, do not reset
//            setSelectedDoorStyleOption(null);
//            setSelectedSideliteOptionLeft(null);
//            setSelectedSideliteOptionRight(null);
//            setSelectedTransomOption(null);

			/*<%-- unshade the available door options --%>*/
			//20101028 - change shaded items -  - unshadeAvailableDoors();

			/*<%-- fade all solid doors --%>*/
			//20101028 - change shaded items -  - shadeItem($('#doorStyles').find(".IsNoGlass-True"));
			unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

			/*<%-- fade "no glass" option --%>*/
			//20101028 - change shaded items -  - shadeItem($('#glassOptions').find(".IsNoGlass-True"));
			unshadeItem($('#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 --%>*/
		//20101028 - change shaded items -  - not shading anything anymore
		shadeItem($("#doorStyles li"));
		shadeItem($("#glassOptions li"));
		//20101028 - change shaded items - unshadeItem($("#doorStyles li"));
		//20101028 - change shaded items - unshadeItem($("#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();
				//20101028 - change shaded items 
				unshadeItem($('#doorStyles').find(".IsNoGlass-True"));
			}
		}
		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 --%>*/
		//20101028 - change shaded items - shadeItem($('#doorStyles').find(".IsNoGlass-True"));
		unshadeItem($('#doorStyles').find(".IsNoGlass-True"));

		/*<%-- fade "no glass" option --%>*/
		//20101028 - change shaded items - shadeItem($('#glassOptions').find(".IsNoGlass-True"));
		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));
	//20101028 - hide or show noise reduced items
	showHide($('#noiseReduced'), (door.DoorConfigDetails.IsNoiseReduced));
	showHide($('#impactRated'), (door.DoorConfigDetails.IsImpactRated));
	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;
		//20101028 - if door is solid glass is NG, thus sub glass for NG to get door dimensions
		if (doorStyleOption.IsNoGlass) {
			jsonArgs['glassFamily'] = 'NG'
		} else {
			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
+ 20101028 - Included in the above exception, if it is a solid door, do not make AJAX call
+ 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 --%>*/
	updateDoorPreview(gDoorLoadingImg);

	if (doorStyleOption == null) {
		/*<%-- replace the door with the placeholder image --%>*/
		updateDoorPreview(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);
		}
		//20101028 - changed to include if door is solid do not call jSon - else if (glassOption.GlassFamily.IsClear || glassOption.GlassFamily.IsNoGlass) {
			else if (glassOption.GlassFamily.IsClear || glassOption.GlassFamily.IsNoGlass || doorStyleOption.IsNoGlass) {
			/*<%-- if the glass option is clear or solid no need to make an ajax call --%>*/
			styleDoorPreviewDetails(doorStyleOption.ExampleDoor, glassOption);
			updateDoorPreview(doorStyleOption.ExampleDoor.ImagePathMedium);
		}
		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);
				}
				else {
					updateDoorPreview(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());
					}
				}

			});
		}
	}
}

/*<%--
+ 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);
			});
		}
	}
}
//20101028 - set the preview when a door config is clicked
function setPreviewDoorConfig(DoorConfig){
	$('#'+ DoorConfig).click();

}
/*<%-- 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 (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 Styles');

	/*<%-- 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('~', ''));
	//20101028 - Make the dblDoor image same as door image
	$('.dbldoor img').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);
		var hash = document.location.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();
	}
}

/*<%-- 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;
var gSelectedSideliteOptionLeft = null;
var gSelectedTransomOption = null;
//20101028 - add the global door config option
var gDoorConfigOption = null;

var gLoadedDoorLinkId = null;
var gLoadedGlassLinkId = 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) {
		/*<%-- 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) {
		/*<%-- 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;
}
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);
	}
}
//20101028 - new fn to get the selected door configuration
function getSelectedDoorConfig() {
	if (gDoorConfigOption == null) {
		gDoorConfigOption = getDocumentHashValue(gDoorConfigKey);
	}
	return gDoorConfigOption;
}
function setSelectedDoorConfigOption(value) {
	gDoorConfigOption = value;

	if (value != null) {
		/*<%-- update the page hash with the selected transom --%>*/
		setDocumentHashValue(gDoorConfigKey, value);
	}
	else {
		removeDocumentHashValue(gDoorConfigKey);
	}
}

function getLoadedDoorConfigId() { return gDoorConfigId; }
function setLoadedDoorConfigId(value) { gDoorConfigId = value; }

function getLoadedDoorLinkId() { return gLoadedDoorLinkId; }
function setLoadedDoorLinkId(value) { gLoadedDoorLinkId = value; }

function getLoadedGlassLinkId() { return gLoadedGlassLinkId; }
function setLoadedGlassLinkId(value) { gLoadedGlassLinkId = 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;
}

function initSaveButtonClick() {
	/*<%-- add a click handler to the save button --%>*/
	$('#' + gSaveDoor).click(function() {

		/*<%-- do we have anything? we at least need a door --%>*/
		if ((getSelectedGlass() != null) && (getSelectedDoorStyleOption() != null)) {
			/*<%-- try and save --%>*/
			var url = gJsonSaveDoor + "?" + qs;

			$.getJSON(url, null, function(resp) {
				if (resp.WebUserDoorID > 0) {
					if (resp.WebUserID > 0) {
						top.location.href = gMyThermaTruDoors;
					}
					else {
						$('#' + gSaveDoorAlt).attr('href', gMyThermaTruCreateAcct + "?did=" + resp.WebUserDoorID + "&TB_iframe=true&height=500&width=700&modal=false");
						$('#' + gSaveDoorAlt).click();
					}
				}
				else {
					alert(resp.Message);
				}
			});
			//	            /* show the door configuration details */
			//	            if (document.URL.indexOf('showDoorConfig=true') > 0) {
			//	                $('#' + gZoomDetail).click();
			//	            }		    
		}
		else {
			alert("Please select a door style");
		}
		return false;
	});
}
	
