function setSelectTextSize(aImage, aSize){
	document.getElementById("textSizing").className = aSize;
	                  
	if(window._selectedImage){
		window._selectedImage.src = window._selectedImage.src.replace("_on", "_off");
	}
	window._selectedImage = aImage;
	window._selectedTextSize = aSize;
}

function toggleRecipeList(aCheckbox){
	var vRecipeList = document.getElementById("RecipeList");
	if(vRecipeList){
	    var vClassName = "";
	    var vChecked = false;
	    var vRow = null;
    	
	    var vChildNodes = vRecipeList.getElementsByTagName("input");
    	
	    if(aCheckbox){
		    var vCheckIndex = aCheckbox.id.split("_")[1];
    		
		    var vRecipe = document.getElementById("recipe_" + vCheckIndex);
		    if(aCheckbox.checked){
			    vRecipe.className = "DisplayNone PrintDisplayBlock";
			    vRecipe.getElementsByTagName("div")[0].className = "PageBreakBefore";
		    }
		    else{
			    vRecipe.className = "DisplayNone";
			    vRecipe.getElementsByTagName("div")[0].className = "DisplayNone";
		    }

		    vRow = aCheckbox.parentNode;
		    while(vRow.nodeName.toLowerCase() != "tr"){
			    vRow = vRow.parentNode;
		    }
    		
    		
		    vClassName = aCheckbox.checked?"":"PrintDisplayNone";
		    vRow.className = vClassName;

		    for(var n=0;n<vChildNodes.length;n++){
			    if(vChildNodes[n].type.toLowerCase() == "checkbox" && vChildNodes[n].checked){
				    vChecked = true;
				    break;
			    }
		    }
    		
		    while(vRow.nextSibling != null){
			    vRow = vRow.nextSibling;
			    if(vRow.nodeName.toLowerCase() == "tr"){
				    if(vRow.className.toLowerCase().indexOf("divider") > -1){
					    vRow.className = "divider " + vClassName;
				    }
				    break;
			    }
		    }
	    }
	    else{
		    var vCheckIndex;
		    var vRecipe;
		    for(var n=0;n<vChildNodes.length;n++){
			    if(vChildNodes[n].type.toLowerCase() == "checkbox"){
				    vCheckIndex = vChildNodes[n].id.split("_")[1];
				    vRecipe = document.getElementById("recipe_" + vCheckIndex);
				    if(vChildNodes[n].checked){
					    vRecipe.className = "DisplayNone PrintDisplayBlock";
					    vRecipe.getElementsByTagName("div")[0].className = "PageBreakBefore";
				    }
				    else{
					    vRecipe.className = "DisplayNone";
					    vRecipe.getElementsByTagName("div")[0].className = "DisplayNone";
				    }
    		
				    vChecked = vChildNodes[n].checked;
				    vClassName = vChecked?"":"PrintDisplayNone";
				    vRow = vChildNodes[n].parentNode.parentNode;
				    while(vRow.nextSibling != null){
					    vRow = vRow.nextSibling;
					    if(vRow.nodeName.toLowerCase() == "tr"){
						    if(vRow.className.toLowerCase().indexOf("divider") > -1){
							    vRow.className = "divider " + vClassName;
						    }
						    break;
					    }
				    }
			    }
		    }
	    }

	    if(!vChecked){
		    vRecipeList.className = "ContentWidth PrintDisplayNone";
	    }
	    else{
		    vRecipeList.className = "ContentWidth";
	    }
	}
}

function toggleProductColumn(aCheckbox){
	var vTable = document.getElementById("ProductList");
	if(vTable){
	    var vVisibility;
	    var vClassName;
	    var vTableRows = vTable.getElementsByTagName("tr");
	    var vTableCell;
	    var vDivs;
	    var vIndex;
    	
	    if(aCheckbox){
		    vIndex = aCheckbox.parentNode.cellIndex;
		    vVisibility = aCheckbox.checked?"visible":"hidden";
		    vClassName = aCheckbox.checked?"":"PrintDisplayNone";

		    for(var n=0;n<vTableRows.length;n++){
			    if(vTableRows[n].parentNode.parentNode == vTable){
				    vChildNodes = vTableRows[n].getElementsByTagName("td");
				    if(vChildNodes.length > 2){
					    for(var z = 0;z<vChildNodes.length;z++){
						    vTableCell = vChildNodes[z];
						    if(vTableCell.parentNode == vTableRows[n]){
							    if(vTableCell.cellIndex == vIndex){
								    vTableCell.className = vClassName;

								    if(n > 0){
									    vDivs = vTableCell.getElementsByTagName("div");
									    if(vDivs.length > 0){
										    if(vDivs[0].className.toLowerCase() == "listcontent"){
											    vDivs[0].style.visibility = vVisibility;
										    }
									    }
								    }
								    break;
							    }
						    }
					    }
				    }
			    }
		    }
	    }
	    else{
		    var vHeaderNodes = vTable.getElementsByTagName("th");
		    var vCheckbox;
		    for(var n=0;n<vTableRows.length;n++){
			    if(vTableRows[n].parentNode.parentNode == vTable){
				    vChildNodes = vTableRows[n].getElementsByTagName("td");
				    if(vChildNodes.length > 2){
					    for(var z = 0;z<vChildNodes.length;z++){
						    vTableCell = vChildNodes[z];
						    if(vTableCell.parentNode == vTableRows[n]){
							    //need to find the correct header node
							    for(var k=0;k<vHeaderNodes.length;k++){
								    if(vHeaderNodes[k].cellIndex == vTableCell.cellIndex){
									    vCheckbox = vHeaderNodes[k].getElementsByTagName("input")[0];

									    if(vCheckbox){
										    vVisibility = vCheckbox.checked?"visible":"hidden";
										    vClassName = vCheckbox.checked?"":"PrintDisplayNone";
										    vTableCell.className = vClassName;

										    if(n > 0){
											    vDivs = vTableCell.getElementsByTagName("div");
											    if(vDivs.length > 0){
												    if(vDivs[0].className.toLowerCase() == "listcontent"){
													    vDivs[0].style.visibility = vVisibility;
												    }
											    }
										    }
										    break;
									    }
								    }
							    }
						    }
					    }
				    }
			    }
		    }
	    }
	}
}

function toggleStorelayout(aCheckbox){ 
	aCheckbox = aCheckbox?aCheckbox:document.getElementById("addToList1");

    if(aCheckbox){
	    var vCheckbox1 = document.getElementById("addToList1");
	    var vCheckbox2 = document.getElementById("addToList2");
    	
	    var vStoreMapLayoutBreak = document.getElementById("StoreMapLayoutHeaderBreak");
	    var vStoreMapLayoutHeader = document.getElementById("StoreMapLayoutHeader");
	    var vStoreMapLayout = document.getElementById("StoreMapLayout");
    		
	    if(aCheckbox.checked){
		    vStoreMapLayoutBreak.className = "PageBreakBefore";
		    vStoreMapLayoutHeader.className = "DisplayNone PrintDisplayTable";
		    vStoreMapLayout.className = "DisplayBlock PrintDisplayBlock";
	    }
	    else{
		    vStoreMapLayoutBreak.className = "DisplayNone";
		    vStoreMapLayoutHeader.className = "DisplayNone";
		    vStoreMapLayout.className = "DisplayNone";
	    }

	    vCheckbox1.checked = aCheckbox.checked;
	    vCheckbox2.checked = aCheckbox.checked;
	}
}

function initProductList(){
	toggleRecipeList();
	toggleProductColumn();
	toggleStorelayout();
}

 function toggleStoreChecked(evt, aCheck, aSetChecked){
    evt = evt ? evt : window.event;
    
    var aCheck;

    if(!aCheck.disabled){
        if(aSetChecked){
            aCheck.checked = aSetChecked;
        }
        
        var vChecks = document.getElementById("tableStores").getElementsByTagName("input");
        if(aCheck.name.toLowerCase().indexOf("showall") > -1){
            for(var n=0;n<vChecks.length;n++){
                if(vChecks[n] != aCheck){
                    if(aCheck.checked || aSetChecked){
                        vChecks[n].checked = true;
                    }
                    else{
                        vChecks[n].checked = false;
                    }
                }
            }
        }
        else if(!aCheck.checked){
            vChecks[0].checked = false;
        }
    }
}

function toggleStoreHover(aDiv, aHover){
    var vCheck = aDiv.getElementsByTagName("input")[0];
    if(!vCheck.disabled){
        if(aHover){
            aDiv.style.backgroundColor = "#ECECEC";
        }
        else{
            aDiv.style.backgroundColor = "";
        }
    }
}

/*
function toggleCustomDateRange(aSelect){
    var vDiv = document.getElementById("customDateRange");
    if(aSelect.selectedIndex == aSelect.options.length - 1){
        vDiv.style.display = "";
    }
    else{
        vDiv.style.display = "none";
    }
}
*/
function getCalendarKeydown(evt){
    evt = evt ? evt : window.event;
    
    var vAllowKeyDown = true;

    if(evt){
        if((evt.keyCode >= 48 && evt.keyCode <= 90) || (evt.keyCode >= 96 && evt.keyCode <= 222)){
            vAllowKeyDown = false;
        }
    }

    return vAllowKeyDown;
}

function showDiscounts(aTableId) 
{
    aTableId = aTableId ? aTableId : "tableReceiptDetails";
    
    var vShowTotals = true;
    var checkbox = jQuery("#ctl00_rptReceipts_ctl00_chkShowDiscounts");
    if( checkbox.is(":checked") )
    {
        vShowTotals = false
    }
    
    jQuery("#" + aTableId + " tr.showHide" ).each( function() {
        var upc = this.id.replace("showHideDiscount_", "");
        if(vShowTotals)
        {
            this.style.display = "none";
            jQuery("#totalWithDiscount_" + upc).css( "display", "block" );
            jQuery("#totalWithoutDiscount_" + upc).css( "display", "none" );
        }
        else
        {
            this.style.display = "";
            jQuery("#totalWithDiscount_" + upc).css( "display", "none" );
            jQuery("#totalWithoutDiscount_" + upc).css( "display", "block" );
        }
    } );
}

function toggleStores(aShow, aInputId){
    var vDisplay;
    var vDivStoreContainer = document.getElementById("divStoreContainer");
    var vDivStores = document.getElementById("divStores");
    var vToggleStores = document.getElementById("aToggleStores");
    
    if(!(aShow != null)){
        if(vDivStores.style.display == "none"){
            aShow = true;
        }
        else{
            aShow = false;
        }
    }

    if(aShow && aShow != "false"){
        vDisplay = "";
        //vDivStoreContainer.className = "tabarea";
        vLabel = "Hide Stores";
    }
    else{
        vDisplay = "none";
        //vDivStoreContainer.className = "tabarea_hide";
        vLabel = "Show Stores";
    }

    vDivStores.style.display = vDisplay;
    vToggleStores.firstChild.nodeValue = vLabel;

    if(aInputId){
        var vInput = document.getElementById(aInputId);
        vInput.value = aShow.toString();
    }
}

var product_hover_contents = new Array();

function showProductHover(location){
    clearHideProductHoverTimeout();

    hideProductHover(location);
    
    if(window._productHover){
    	/*
        var vImage = document.getElementById("imgProductThumb");
        if(window._upc){
            vImage.style.backgroundImage = "url('" + getImagePathFromUpc(window._upc) + "')";
            vImage.style.display = "";
        }
        else{
            vImage.style.display = "none";
        }
        */
        if(window._contentURL){
		var url = window._contentURL;
		jQuery(window._productHover).html('<img style="padding-top:80px;padding-left:120px;" src="/webapp/wcs/stores/B2BDirectStorefrontAssetStore/images/wegmans/ajax-loader-regular.gif"/>');
		if( !product_hover_contents[url] )
		{
			jQuery.get(url,null,function(_data,_textStatus){
				jQuery(window._productHover).html( _data );
				mrkfltwd20a.replace();
				product_hover_contents[url] = { data: _data, height: jQuery(window._productHover).children("#productDetailsMini")[0].clientHeight };
				jQuery(window._productHover).css("height", product_hover_contents[url].height);
			});
        	}
        	else
		{
			jQuery(window._productHover).html( product_hover_contents[url].data );
			jQuery(window._productHover).css("height", product_hover_contents[url].height);
		}
        }
            
        /*
        var vPosition = getNodePosition(vTarget);
        
        window._productHover.style.left = vPosition.left + "px";
        window._productHover.style.top = vPosition.top - parseInt(window._productHover.style.height, 10) + "px";
        */

        var vOffsetX = 0;
        var vOffsetY = 0;
        if(document.documentElement.scrollTop != null){
            vOffsetX = document.documentElement.scrollLeft;
            vOffsetY = document.documentElement.scrollTop;
        }
        else{
            vOffsetX = window.pageXOffset;
            vOffsetY = window.pageYOffset;
        }

        window._productHover.style.left = (window._hoverClientX + 50 + vOffsetX) + "px";
        window._productHover.style.top = (window._hoverClientY - 80 + vOffsetY) + "px";
        
        window._productHover.style.display = "block";
    }
}

function cleanHoverHTML( _input )
{
	var output = _input;
	output.replace(/<[^>]*s_code[^>]*><[^>]*>/,"");
	
	return output;
}

function setShowProductHoverTimeout(evt, aAnchor, location){
    clearHideProductHoverTimeout();
    
    evt = evt ? evt : window.event;
	if (navigator.vendor!=null && navigator.vendor.indexOf('Apple') != -1) 	{
		window._hoverClientX = evt.pageX;
		window._hoverClientY = evt.pageY;
	}else{
		window._hoverClientX = evt.clientX;
		window._hoverClientY = evt.clientY;
	}
    window._contentURL = aAnchor.getAttribute("contentURL");
    
    var vProductHover;

    if(aAnchor.className.toLowerCase().indexOf("notavailable") > -1){
        vProductHover = document.getElementById(location + "_product_hover");
        if(vProductHover){
            vProductHover.style.display = "none";
        }
        
        window._productHover = document.getElementById(location + "_product_hover_na");
    }
    else{
        vProductHover = document.getElementById(location + "_product_hover_na");
        if(vProductHover){
            vProductHover.style.display = "none";
        }
        
        window._productHover = document.getElementById(location + "_product_hover");
    }
      
    window._showProductHoverTimeoutId = setTimeout(function() { showProductHover(location); }, 500);
}

function clearShowProductHoverTimeout(){
    clearTimeout(window._showProductHoverTimeoutId);
}

function setHideProductHoverTimeout(location){
    clearShowProductHoverTimeout();
     window._hideProductHoverTimeoutId = setTimeout(function() { hideProductHover(location); }, 500);
}

function clearHideProductHoverTimeout(){
    clearTimeout(window._hideProductHoverTimeoutId);
}

function hideProductHover(location){
    vProductHover = document.getElementById(location + "_product_hover_na");
    if(vProductHover){
        vProductHover.style.display = "none";
    }
    vProductHover = document.getElementById(location + "_product_hover");
    if(vProductHover){
        vProductHover.style.display = "none";
    }
}

function getNodePosition(aNode){
    var vPosition = {top:0, left:0};
    while(aNode.parentNode != document){
        vPosition.left += aNode.offsetLeft;
        vPosition.top += aNode.offsetTop;
        
        aNode = aNode.parentNode;
    }
    return vPosition;
}

function setCalendarDates(aSelect, aInputId1, aInputId2)
{
    var vInput1 = document.getElementById(aInputId1);
    var vInput2 = document.getElementById(aInputId2);
    
    if(aSelect.selectedIndex >= aSelect.options.length - 2){
        vInput1.value = window._scpp_firstTransactionDate;
        vInput2.value = window._scpp_lastTransactionDate;
    }
    else{
        vInput1.value = window._scpp_timeFrame[aSelect.selectedIndex];
        vInput2.value = window._scpp_timeFrame[aSelect.options.length - 1];
        
    }
    
    hideCalendarControl();
}

function getImagePathFromUpc(aUpc){
    aUpc = aUpc ? aUpc : "";

    switch(aUpc.length){
	    case 4:
		    aUpc = "20" + aUpc + "00000";
		    break;
	    default:
		    aUpc = "00000000000" + aUpc;
		    aUpc = aUpc.substr(aUpc.length - 11);
		    break;
    }


    var vReverseUpc = aUpc.split("").reverse().join("");

    var vNumber = (
	    3 * (
			    parseInt(vReverseUpc.charAt(0), 10)
			    + parseInt(vReverseUpc.charAt(2), 10)
			    + parseInt(vReverseUpc.charAt(4), 10)
			    + parseInt(vReverseUpc.charAt(6), 10)
			    + parseInt(vReverseUpc.charAt(8), 10)
			    + parseInt(vReverseUpc.charAt(10), 10)
		    )
		    + (
			    parseInt(vReverseUpc.charAt(1), 10)
			    + parseInt(vReverseUpc.charAt(3), 10)
			    + parseInt(vReverseUpc.charAt(5), 10)
			    + parseInt(vReverseUpc.charAt(7), 10)
			    + parseInt(vReverseUpc.charAt(9), 10)
		    )
	    );

    if(10 - (vNumber % 10) == 10){
	    vNumber = 0;
    }
    else{
	    vNumber = 10 - (vNumber % 10);
    }                                                

    var vTemp = "00000000000000" + aUpc + vNumber;

    var vImagePath = "http://www.wegmans.com/prodimg/" + aUpc.substr(aUpc.length - 2) + vNumber + "/90/" + vTemp.substr(vTemp.length - 12) + ".jpg";

    return vImagePath;
}
	
function alertNotImplemented(){
    alert("This function has not been implemented for the prototype.");
}