
(function($){
 /*
 * @name bgiframe
 * @type jQuery
 * @cat Plugins/bgiframe
 * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 */
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};

})(jQuery);

/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
//		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);

$(function(){

    var openToolboxHandle = $('#openToolbox');
    openToolboxHandle.click(function () {
    	if(hover == 1){
			hover = 0;
			toggleToolbar($('#mmlToolbox p.info'));
		}else{
			toggleToolbar($('#mmlToolbox p.info'));
		}
		//MCP-3390
		//updateMMLCookie('info');
		trackToolbarClicks(this, 'o', 'Toolbox > Open');
		return false;
    });
    openToolboxHandle.mouseover(function () {
    	clearTimeout(t);
		if(hover == 1){
			clearTimeout(t2);
			clearTimeout(t3);
			link = $('#mmlToolbox p.info');
			if(toolbox.find('ul li.active').find('p').attr('class') != link.attr('class')){
				t = setTimeout('toggleToolbar(link);', 500);
				hover = 1;
			}
		}
		return false;
    });
    openToolboxHandle.mouseout(function () {
    	clearTimeout(t);
		clearTimeout(t2);
		clearTimeout(t3);
		if(hover == 1){
			if(toolboxWrap.hasClass('open')){
				link = $('#mmlToolbox p.info');
				t2 = setTimeout('toggleToolbar(link);', 500);
			}
		}
		return false;
    });
	
	$('#mmlToolbox').find('li p').click(function(){
		if(hover == 1){
			hover = 0;
		}else{
			toggleToolbar($(this));
		}
		//MCP-3390
		//updateMMLCookie($(this).attr('class'));
		//Code for Omniture tracking - Starts
		var linkName = $(this).attr('class');
		//Get the proper 
		//Switch statements are much faster than long if/else
		switch(linkName){
			case 'shopping':
			  linkName = 'Toolbox > Shopping Cart';
			  break;
			case 'profile':
			  linkName = 'Toolbox > Profile';
			  break;
			case 'lists':
			  linkName = 'Toolbox > Lists';
			  break;
			case 'search':
			  linkName = 'Toolbox > Search/Browse History';
			  break;
			case 'personal':
			  linkName = 'Toolbox > Personal Shopper';
			  break;
			case 'info':
			  inkName = 'Toolbox > Info';
			  break;
		}
		trackToolbarClicks(this, 'o', linkName);
		//Code for Omniture tracking - Ends

		return false;
	});
	
	$('#mmlToolboxPanel .panelContent .info div a').click(function(){
		var target = $(this).attr('class').substring(5);
		hover = 0;
		switch(target){
			case 'cart':
			  linkName = 'Toolbox > Cart';
			  toggleToolbar($('#mmlToolbox p.shopping'));
			  trackToolbarClicks(this, 'o', linkName);
			  break;
			case 'profile':
			  linkName = 'Toolbox > Profile';
			  toggleToolbar($('#mmlToolbox p.profile'));
			  trackToolbarClicks(this, 'o', linkName);
			  break;
			case 'lists':
			  linkName = 'Toolbox > Lists';
			  toggleToolbar($('#mmlToolbox p.lists'));
			  trackToolbarClicks(this, 'o', linkName);
			  break;
			case 'recent':
			  linkName = 'Toolbox > Search/Browse History';
			  toggleToolbar($('#mmlToolbox p.search'));
			  trackToolbarClicks(this, 'o', linkName);
			  break;
			case 'ps':
			  linkName = 'Toolbox > Personal Shopper';
			  toggleToolbar($('#mmlToolbox p.personal'));
			  trackToolbarClicks(this, 'o', linkName);
			  break;
		}
		return false;
	});

	
	$('#mmlToolbox').click(function(){
		return true;
	});

	$('#mmlToolbox').find('li p').mouseover(function(){
		clearTimeout(t);
		if(hover == 1){
			clearTimeout(t2);
			clearTimeout(t3);
			link = $(this);
			if($('#mmlToolbox').find('ul li.active').find('p').attr('class') != link.attr('class')){
				t = setTimeout('toggleToolbar(link);', 500);
				hover = 1;
			}
		}
		return false;
	});
	$('#mmlToolbox').find('li p').mouseout(function(){
		clearTimeout(t);
		clearTimeout(t2);
		clearTimeout(t3);
		if(hover == 1){
			if($('#mmlToolboxWrap').hasClass('open')){
				link = $(this);
				t2 = setTimeout('toggleToolbar(link);', 500);
			}
		}
		return false;
	});
	$('#mmlToolboxPanel').mouseover(function(){
		if(hover == 1){
			clearTimeout(t2);
			clearTimeout(t3);
		}
	});
	$('#mmlToolboxPanel').mouseout(function(){
		if($('#mmlToolboxWrap').hasClass('open')){
			if(hover == 1){
				link = $('#mmlToolbox').find('ul li.active').find('p');
				clearTimeout(t2);
				t3 = setTimeout('toggleToolbar(link);', 500);
			}
		}
	});
});

var hover = 1;
var t;
var t2;
var t3;
var link;
var inMotion = 0;
var shoppingPulled = 0;
var searchPulled = 0;
//MML Universal List Changes
var listsPulled = 0;
var toolbar = $('#mmlToolbar');
var toolboxWrap = $('#mmlToolboxWrap');
var borderWrap = $('#borderBottomWrap');
var toolbox = $('#mmlToolbox');
var toolboxLink = toolbox.find('li p');
var toolboxPanel = $('#mmlToolboxPanel');
var wrap = $('#wrap');

if($.browser.msie && $.browser.version < 7){
	var sillyIE6 = true;			
}else{
	var sillyIE6 = false;
}

function toggleToolbar(link){
		if(sillyIE6){
			if(!inMotion){
				if(!$('#mmlToolboxWrap').hasClass('open')){
					inMotion = 1;
					$('#mmlToolbox').css('width', '41px');
					$('#wrap').css('margin-left', '210px');
					$('#mmlToolbar').css('width', '210px');
					link.parent().addClass('active');
					var active = link.attr('class');
					$('#mmlToolboxPanel').find('.panel').hide();
					$('#mmlToolboxPanel').find('.'+active).show();
					if(active == 'shopping' && shoppingPulled == 0){
						$.ajax({
							type: "GET",
							url: recentlyViewedURL+'&ajaxOrigin=shopping',
							cache: false,
							success: function(data){
								$('#mmlToolboxPanel .panelContent .shopping').html('').html(data);
								shoppingPulled = 1;
								$('#mmlToolboxPanel .shopping .miniCart ul li .remove').click(function(){
									var parent = $(this).parent();
									if(parent.hasClass('last')){
										parent.prev().addClass('last');
									}
									parent.fadeOut();
									return false;
								});
								$('#mmlToolboxPanel .shopping .toolbox_saveForLater').click(function(){
								if(mmlSaveFlag ==0){
									$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
									return false;
									}
								});
								$('#mmlToolboxPanel .shopping .detailsLink').toggle(function(){
									$(this).parent().next().show();
									correctPanels('shopping');
									$(this).html('Hide details');
									return false;
								}, function(){
									$(this).parent().next().hide();
									correctPanels('shopping');
									$(this).html('Details');
									return false;
								});
								correctPanels('shopping');
								if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
									//fnConvertPriceRecentlyViewed();
									var tempMiniCart = fnConSSfly($('div.miniCart').html());
									$('div.miniCart').html('').html(tempMiniCart);
									var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
									$('div.recentlyViewed').html('').html(tempRecentView);
									
							}
							}
						});
					}
					if(active == 'search' && searchPulled == 0){
						$.ajax({
							type: "GET",
							url: recentlyViewedURL,
							cache: false,
							success: function(data){
								$('#mmlToolboxPanel .panelContent .search').html('').html(data);
								searchPulled = 1;
								$('#mmlToolboxPanel .search .recentlyViewed .toolbox_saveForLater').click(function(){
								if(mmlSaveFlag ==0){
									$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
									return false;
									}
								});
								correctPanels('search');
								if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
								var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
								$('div.recentlyViewed').html('').html(tempRecentView);
							}
							}
						});
					}
					//MML Universal List Changes -Starts Here
					if(active == 'lists' && listsPulled == 0){
					
						$.ajax({
								type: "GET",
								url: UniversalListCenterView,
								cache: false,
								success: function(data){
								listsPulled = 1;
								
									var jsonListDetails = eval('('+data+')');
									var size=jsonListDetails.ItemList.ItemListArray.length;			
									var regsearssize=jsonListDetails.RegistryList.RegistryListsearsArray.length;
									var regkmartsize=jsonListDetails.RegistryList.RegistryListkmartArray.length;
									var regtgisize=jsonListDetails.RegistryList.RegistryListTGIArray.length;
									var giveTGsearssize=jsonListDetails.RegistryList.GivetogetherssearsListArray.length;
									var giveTGkmartsize=jsonListDetails.RegistryList.GivetogetherskmartListArray.length;
									if(size>0){
										var listDD = '<h5>My Lists</h5>';
										listDD += '<ul class="list_names">';
										for(i=0; i < size; i++){
										var listname = jsonListDetails.ItemList.ItemListArray[i];
										if(listname.length > 25){
											listname = listname.substring(0, 25);
										}
									
											listDD += '<li><a href="/shc/s/InterestItemDisplayCmd?storeId='+toolbarStoreid+'&catalogId='+toolbarcatalogid+'&langId=-1&listname='+jsonListDetails.ItemList.ItemListArray[i]+'">'+listname+'</a></li>';
										}
										listDD += '</ul>';
										$('div#listDD').html('').html(listDD);
									}
									if((regsearssize+regkmartsize+regtgisize+giveTGsearssize+giveTGkmartsize)>0)
									{
									var registryDD = '<h5>Registries &amp; Give Togethers</h5>';
									registryDD += '<ul class="list_names">';
									}
									for(i=0; i < (regsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)+1]+'</a></li>';
									}
									for(i=0; i < (regtgisize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)+1]+'</a></li>';
									}
									for(i=0; i < (giveTGsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)+1]+'</a></li>';
									}
									
									
									for(i=0; i < (giveTGkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)+1]+'</a></li>';
									}
									$('div#registriesDD').html('').html(registryDD);
							}
						});
					}
					//MML Universal List Changes -Ends Here 
					$('#mmlToolboxPanel').show().css('width', '167px').find('.close').unbind('click').click(function(){
						inMotion = 1;
						hover = 0;
						$('#mmlToolboxPanel').hide();
						$('#borderBottomWrap').removeClass('open');
						$('#mmlToolbar').css('width', '49px');
						$('#mmlToolbox').css('width', '49px').find('ul li.active').removeClass('active');
						$('#wrap').css('margin-left', '49px');
						$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
						$('#mmlToolboxWrap').removeClass('open');
						inMotion = 0;
						$('#mmlToolboxWrap').animate({color: '#000'}, 300, function(){ hover = 1; });
						//MCP-3390
						//updateMMLCookie();
						return false;
					});
					$('#mmlToolboxWrap').animate({color: '#000'}, 200, function(){
						applyJScrollBar(active);
						scrollfix();
						if($('#rightRail').length){
							widthSetResize();
						}
						$(window).resize();
					});
					$('#borderBottomWrap').addClass('open');
					inMotion = 0;
					$('#mmlToolboxWrap').addClass('open');
				}else{
					if($('#mmlToolbox').find('ul li.active').find('p').attr('class') == link.attr('class')){
						inMotion = 1;
						$('#mmlToolboxPanel').hide();
						$('#mmlToolbar').css('width', '49px');
						$('#mmlToolbox').css('width', '49px').find('ul li.active').removeClass('active');
						$('#wrap').css('margin-left', '49px');
						$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
						$('#mmlToolboxPanel .panelContent').css('padding', '20px 5px 20px');
						$('#borderBottomWrap').removeClass('open');
						$('#mmlToolboxWrap').removeClass('open');
						scrollfix();
						if($('#rightRail').length){
							widthSetResize();
						}
						$(window).resize();
						inMotion = 0;
						hover = 1;
					}else{
						$('#mmlToolbox').find('ul li.active').removeClass('active');
						link.parent().addClass('active');
						var active = link.attr('class');
						$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
						$('#mmlToolboxPanel .panelContent').css('padding', '20px 5px 20px 5px');
						$('#mmlToolboxPanel').find('.panel').hide();
						$('#mmlToolboxPanel').find('.'+active).show();
						if(active == 'shopping' && shoppingPulled == 0){
							$.ajax({
								type: "GET",
								url: recentlyViewedURL+'&ajaxOrigin=shopping',
								cache: false,
								success: function(data){
									$('#mmlToolboxPanel .panelContent .shopping').html('').html(data);
									shoppingPulled = 1;
									$('#mmlToolboxPanel .shopping .miniCart ul li .remove').click(function(){
										var parent = $(this).parent();
										if(parent.hasClass('last')){
											parent.prev().addClass('last');
										}
										parent.fadeOut();
										return false;
									});
									$('#mmlToolboxPanel .shopping .toolbox_saveForLater').click(function(){
									if(mmlSaveFlag ==0){
										$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
										return false;
										}
									});
									$('#mmlToolboxPanel .shopping .detailsLink').toggle(function(){
										$(this).parent().next().show();
										correctPanels('shopping');
										$(this).html('Hide details');
										return false;
									}, function(){
										$(this).parent().next().hide();
										correctPanels('shopping');
										$(this).html('Details');
										return false;
									});
									correctPanels('shopping');
									if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
										//fnConvertPriceRecentlyViewed();
										var tempMiniCart = fnConSSfly($('div.miniCart').html());
										$('div.miniCart').html('').html(tempMiniCart);
										var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
										$('div.recentlyViewed').html('').html(tempRecentView);
									
								}
								}
							});
						};
						if(active == 'search' && searchPulled == 0){
							$.ajax({
								type: "GET",
								url: recentlyViewedURL,
								cache: false,
								success: function(data){
									$('#mmlToolboxPanel .panelContent .search').html('').html(data);
									searchPulled = 1;
									$('#mmlToolboxPanel .search .recentlyViewed .toolbox_saveForLater').click(function(){
									if(mmlSaveFlag ==0){
										$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
										return false;
										}
									});
									correctPanels('search');
									if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
										//fnConvertPriceRecentlyViewed();
										var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
										$('div.recentlyViewed').html('').html(tempRecentView);
									
								}
								}
							});
						};
					//MML Universal List Changes -Starts Here
					if(active == 'lists' && listsPulled == 0){
					
						$.ajax({
								type: "GET",
								url: UniversalListCenterView,
								cache: false,
								success: function(data){
								listsPulled = 1;
								
									var jsonListDetails = eval('('+data+')');
									var size=jsonListDetails.ItemList.ItemListArray.length;
									var regsearssize=jsonListDetails.RegistryList.RegistryListsearsArray.length;
									var regkmartsize=jsonListDetails.RegistryList.RegistryListkmartArray.length;
									var regtgisize=jsonListDetails.RegistryList.RegistryListTGIArray.length;
									var giveTGsearssize=jsonListDetails.RegistryList.GivetogetherssearsListArray.length;
									var giveTGkmartsize=jsonListDetails.RegistryList.GivetogetherskmartListArray.length;
									if(size>0){
										var listDD = '<h5>My Lists</h5>';
										listDD += '<ul class="list_names">';
										for(i=0; i < size; i++){
										var listname = jsonListDetails.ItemList.ItemListArray[i];
										if(listname.length > 25){
											listname = listname.substring(0, 25);
										}
									
											listDD += '<li><a href="/shc/s/InterestItemDisplayCmd?storeId='+toolbarStoreid+'&catalogId='+toolbarcatalogid+'&langId=-1&listname='+jsonListDetails.ItemList.ItemListArray[i]+'">'+listname+'</a></li>';
										}
										listDD += '</ul>';
										$('div#listDD').html('').html(listDD);
									}
									if((regsearssize+regkmartsize+regtgisize+giveTGsearssize+giveTGkmartsize)>0){
									var registryDD = '<h5>Registries &amp; Give Togethers</h5>';
									registryDD += '<ul class="list_names">';
									}
									for(i=0; i < (regsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regtgisize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)+1]+'</a></li>';
									}
									for(i=0; i < (giveTGsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)+1]+'</a></li>';
									}
									
									
									for(i=0; i < (giveTGkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)+1]+'</a></li>';
									}
									$('div#registriesDD').html('').html(registryDD);
							}
						});
					}
					//MML Universal List Changes -Ends Here 
						applyJScrollBar(active);
					}
					return false;
				}
			}else{
				return false;
			}
		}else{
			if(!inMotion){
				if(!$('#mmlToolboxWrap').hasClass('open')){
					inMotion = 1;
					$('#mmlToolbox').css('width', '41px');
					$('#wrap').animate({marginLeft: '210px'}, 500);
					$('#mmlToolbar').animate({width: '210px'}, 500, function(){
						$('#borderBottomWrap').addClass('open');
					});
					link.parent().addClass('active');
					var active = link.attr('class');
					$('#mmlToolboxPanel').find('.panel').hide();
					$('#mmlToolboxPanel').find('.'+active).show();
					if(active == 'shopping' && shoppingPulled == 0){
						$.ajax({
							type: "GET",
							url: recentlyViewedURL+'&ajaxOrigin=shopping',
							cache: false,
							success: function(data){
								$('#mmlToolboxPanel .panelContent .shopping').html('').html(data);
								shoppingPulled = 1;
								$('#mmlToolboxPanel .shopping .miniCart ul li .remove').click(function(){
									var parent = $(this).parent();
									if(parent.hasClass('last')){
										parent.prev().addClass('last');
									}
									parent.fadeOut();
									return false;
								});
								$('#mmlToolboxPanel .shopping .toolbox_saveForLater').click(function(){
									if(mmlSaveFlag ==0){
										$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
									return false;
									}
								});
								$('#mmlToolboxPanel .shopping .detailsLink').toggle(function(){
									$(this).parent().next().show();
									correctPanels('shopping');
									$(this).html('Hide details');
									return false;
								}, function(){
									$(this).parent().next().hide();
									correctPanels('shopping');
									$(this).html('Details');
									return false;
								});
								correctPanels('shopping');
								if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
										//fnConvertPriceRecentlyViewed();
										var tempMiniCart = fnConSSfly($('div.miniCart').html());
										$('div.miniCart').html('').html(tempMiniCart);
										var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
										$('div.recentlyViewed').html('').html(tempRecentView);
							}
							}
						});
					}
					if(active == 'search' && searchPulled == 0){
						$.ajax({
							type: "GET",
							url: recentlyViewedURL,
							cache: false,
							success: function(data){
								$('#mmlToolboxPanel .panelContent .search').html('').html(data);
								searchPulled = 1;
								$('#mmlToolboxPanel .search .recentlyViewed .toolbox_saveForLater').click(function(){
								if(mmlSaveFlag ==0){
									$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
									return false;
									}
								});
								correctPanels('search');
								if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
										//fnConvertPriceRecentlyViewed();
										var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
										$('div.recentlyViewed').html('').html(tempRecentView);
							}
							}
						});
					}
					//MML Universal List Changes -Starts Here
					if(active == 'lists' && listsPulled == 0){
					
						$.ajax({
								type: "GET",
								url: UniversalListCenterView,
								cache: false,
								success: function(data){
								listsPulled = 1;
								
									var jsonListDetails = eval('('+data+')');
									var size=jsonListDetails.ItemList.ItemListArray.length;
									var regsearssize=jsonListDetails.RegistryList.RegistryListsearsArray.length;
									var regkmartsize=jsonListDetails.RegistryList.RegistryListkmartArray.length;
									var regtgisize=jsonListDetails.RegistryList.RegistryListTGIArray.length;
									var giveTGsearssize=jsonListDetails.RegistryList.GivetogetherssearsListArray.length;
									var giveTGkmartsize=jsonListDetails.RegistryList.GivetogetherskmartListArray.length;
									if(size>0){
										var listDD = '<h5>My Lists</h5>';
										listDD += '<ul class="list_names">';
										for(i=0; i < size; i++){
										var listname = jsonListDetails.ItemList.ItemListArray[i];
										if(listname.length > 25){
											listname = listname.substring(0, 25);
										}
									
											listDD += '<li><a href="/shc/s/InterestItemDisplayCmd?storeId='+toolbarStoreid+'&catalogId='+toolbarcatalogid+'&langId=-1&listname='+jsonListDetails.ItemList.ItemListArray[i]+'">'+listname+'</a></li>';
										}
										listDD += '</ul>';
										$('div#listDD').html('').html(listDD);
									}
									if((regsearssize+regkmartsize+regtgisize+giveTGsearssize+giveTGkmartsize)>0){
									var registryDD = '<h5>Registries &amp; Give Togethers</h5>';
									registryDD += '<ul class="list_names">';
									}
									for(i=0; i < (regsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regtgisize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)+1]+'</a></li>';
									}
									for(i=0; i < (giveTGsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)+1]+'</a></li>';
									}
									
									
									for(i=0; i < (giveTGkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)+1]+'</a></li>';
									}
									$('div#registriesDD').html('').html(registryDD);
							}
						});
					}
					//MML Universal List Changes -Ends Here 
					$('#mmlToolboxPanel').show().animate({width: '168px'}, 500, function(){
						$(this).find('.close').unbind('click').click(function(){
							inMotion = 1;
							hover = 0;
							$('#mmlToolboxPanel').animate({width: '0px'}, 500, function(){
								$(this).hide();
								$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
							});
							$('#borderBottomWrap').removeClass('open');
							$('#mmlToolbar').animate({width: '49px'}, 500, function(){
								
							});
							$('#wrap').animate({marginLeft: '49px'}, 500, function(){
								$('#mmlToolbox').css('width', '49px');
								$('#mmlToolboxWrap').removeClass('open');
								inMotion = 0;
								hover = 1;
							});
							$('#mmlToolbox').find('ul li.active').removeClass('active');
							//MCP-3390
							//updateMMLCookie();	
							return false;
						});
						if(typeof scrollfixFF == 'function') scrollfixFF();
						if($('#rightRail').length){
							widthSetResize();
						}
						$(window).resize();
						inMotion = 0;
					});
					$('#mmlToolboxWrap').animate({color: '#000'}, 200, function(){
						applyJScrollBar(active);
					});
					$('#mmlToolboxWrap').addClass('open');
					
				}else{
					if($('#mmlToolbox').find('ul li.active').find('p').attr('class') == link.attr('class')){
						inMotion = 1;
						$('#mmlToolboxPanel').animate({width: '0px'}, 500, function(){
							$(this).hide();
							$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
						});
						$('#mmlToolbar').animate({width: '49px'}, 500);
						$('#wrap').animate({marginLeft: '49px'}, 500, function(){
							$('#mmlToolbox').css('width', '49px');
							$('#mmlToolboxWrap').removeClass('open');
							$('#borderBottomWrap').removeClass('open');
							inMotion = 0;
							hover = 1;
							if(typeof scrollfixFF == 'function') scrollfixFF();
							if($('#rightRail').length){
								widthSetResize();
							}  
							$(window).resize();
						});
						$('#mmlToolbox').find('ul li.active').removeClass('active');
					}else{
						$('#mmlToolbox').find('ul li.active').removeClass('active');
						link.parent().addClass('active');
						var active = link.attr('class');
						$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
						$('#mmlToolboxPanel').find('.panel').hide();
						$('#mmlToolboxPanel').find('.'+active).show();
						if(active == 'shopping' && shoppingPulled == 0){
							$.ajax({
								type: "GET",
								url: recentlyViewedURL+'&ajaxOrigin=shopping',
								cache: false,
								success: function(data){
									$('#mmlToolboxPanel .panelContent .shopping').html('').html(data);
									shoppingPulled = 1;
									$('#mmlToolboxPanel .shopping .miniCart ul li .remove').click(function(){
										var parent = $(this).parent();
										if(parent.hasClass('last')){
											parent.prev().addClass('last');
										}
										parent.fadeOut();
										return false;
									});
									$('#mmlToolboxPanel .shopping .toolbox_saveForLater').click(function(){
									if(mmlSaveFlag ==0){
										$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
										return false;
										}
									});
									$('#mmlToolboxPanel .shopping .detailsLink').toggle(function(){
										$(this).parent().next().show();
										correctPanels('shopping');
										$(this).html('Hide details');
										return false;
									}, function(){
										$(this).parent().next().hide();
										correctPanels('shopping');
										$(this).html('Details');
										return false;
									});
									correctPanels('shopping');
									if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
										//fnConvertPriceRecentlyViewed();
										var tempMiniCart = fnConSSfly($('div.miniCart').html());
										$('div.miniCart').html('').html(tempMiniCart);
										var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
										$('div.recentlyViewed').html('').html(tempRecentView);
									
								}
								}
							});
						}
						if(active == 'search' && searchPulled == 0){
							$.ajax({
								type: "GET",
								url: recentlyViewedURL,
								cache: false,
								success: function(data){
									$('#mmlToolboxPanel .panelContent .search').html('').html(data);
									searchPulled = 1;
									$('#mmlToolboxPanel .search .recentlyViewed .toolbox_saveForLater').click(function(){
									if(mmlSaveFlag ==0){
										$(this).after('<span style="color: #666; display:block; float:left; font-size: .9em; margin-left: 12px; margin-top:5px">Saved successfully</span>').remove();
										return false;
										}
									});
									correctPanels('search');
									if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
										//fnConvertPriceRecentlyViewed();
										var tempRecentView = fnConSSfly($('div.recentlyViewed').html());
										$('div.recentlyViewed').html('').html(tempRecentView);
									
								}
								}
							});
						}
					//MML Universal List Changes -Starts Here
					if(active == 'lists' && listsPulled == 0){
					
						$.ajax({
								type: "GET",
								url: UniversalListCenterView,
								cache: false,
								success: function(data){
								listsPulled= 1;
						 		
									var jsonListDetails = eval('('+data+')');
									var size=jsonListDetails.ItemList.ItemListArray.length;
									var regsearssize=jsonListDetails.RegistryList.RegistryListsearsArray.length;
									var regkmartsize=jsonListDetails.RegistryList.RegistryListkmartArray.length;
									var regtgisize=jsonListDetails.RegistryList.RegistryListTGIArray.length;
									var giveTGsearssize=jsonListDetails.RegistryList.GivetogetherssearsListArray.length;
									var giveTGkmartsize=jsonListDetails.RegistryList.GivetogetherskmartListArray.length;
									if(size>0){
										var listDD = '<h5>My Lists</h5>';
										listDD += '<ul class="list_names">';
										for(i=0; i < size; i++){
										var listname = jsonListDetails.ItemList.ItemListArray[i];
										if(listname.length > 25){
											listname = listname.substring(0, 25);
										}
									
											listDD += '<li><a href="/shc/s/InterestItemDisplayCmd?storeId='+toolbarStoreid+'&catalogId='+toolbarcatalogid+'&langId=-1&listname='+jsonListDetails.ItemList.ItemListArray[i]+'">'+listname+'</a></li>';
										}
										listDD += '</ul>';
										$('div#listDD').html('').html(listDD);
									}
									if((regsearssize+regkmartsize+regtgisize+giveTGsearssize+giveTGkmartsize)>0)
									{
									var registryDD = '<h5>Registries &amp; Give Togethers</h5>';
									registryDD += '<ul class="list_names">';
									}
									for(i=0; i < (regsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListsearsArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListkmartArray[(i*2)+1]+'</a></li>';
									}
									
									for(i=0; i < (regtgisize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)]+'">'+jsonListDetails.RegistryList.RegistryListTGIArray[(i*2)+1]+'</a></li>';
									}
									for(i=0; i < (giveTGsearssize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherssearsListArray[(i*2)+1]+'</a></li>';
									}
									
									
									for(i=0; i < (giveTGkmartsize/2); i++)
									{
									registryDD +='<li><a target="_blank" href="/shc/s/'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)]+'">'+jsonListDetails.RegistryList.GivetogetherskmartListArray[(i*2)+1]+'</a></li>';
									}
									$('div#registriesDD').html('').html(registryDD);
							}
						});
					}
					//MML Universal List Changes -Ends Here 
						$('#mmlToolboxWrap').animate({opacity: 1}, 300, function(){
							applyJScrollBar(active);
						});
					}
					return false;
				}
			}else{
				return false;
			}
		}
}

function correctPanels(activePanel) {
	if(typeof userLoginType != 'undefined' && userLoginType == 'R' 
		&& typeof recsURLForMML != 'undefined' && recsURLForMML != '') {
		$('div#mmlToolboxPanel div.recommendations').css({display: "block"});
		$('div#mmlToolboxPanel div.recommendations a').attr('href', recsURLForMML);
	}
	applyJScrollBar(activePanel);
}

$(function() {
	//If Akamai is enabled, then Akamai AJAX will take care of following functionalities.
	if(typeof isAkamaiEnabled != 'undefined' && isAkamaiEnabled == 'true') return;
	
	//Block to update quantity of Cart
	var cartMsgForMML = $('div#links span#items').html();
	var cartPriceForMML = $('div#links span#miniCartTotal').html();	
	if(cartMsgForMML == '') cartMsgForMML = '0 items';
	$('div#mmlToolbox p.shopping').find('a').html(cartMsgForMML);

	//To correct the extra space in Info section
	if(typeof userLoginType != 'undefined' && userLoginType == 'G') $('div.info div:eq(0)').addClass('first');
});

/* trackToolbarClicks() is moved to global_wide.js */

//Function to hide toolbox and focus the search box - Start Shopping link changes
function fnStartShopping() {
	inMotion = 1;
	hover = 0;
	$('#mmlToolboxPanel').animate({width: '0px'}, 500, function(){
		$(this).hide();
		$('#mmlToolboxPanel .panelContent .panel').jScrollPaneRemove();
	});
	$('#mmlToolbar').animate({width: '49px'}, 500);
	$('#wrap').animate({marginLeft: '49px'}, 500, function(){
		$('#mmlToolbox').css('width', '49px');
		$('#mmlToolboxWrap').removeClass('open');
		$('#borderBottomWrap').removeClass('open');
		inMotion = 0;
		hover = 1;
		if(typeof scrollfixFF == 'function') scrollfixFF();
		if($('#rightRail').length){
			widthSetResize();
		}
		$(window).resize();
	});
	$('#mmlToolbox').find('ul li.active').removeClass('active');
	$('#keyword').focus();
}
/*Code for Save for later starts*/

var popupheight;
var popupwidth;

	function addToWishListForMML(urlparam,catEntryId,count) {	
	urlparam = urlparam+'_'+count;	
	var	url=document.getElementById(urlparam).value;
    //var	url= urlparam;
		saveLaterId="saveLater_"+(count);
		object = document.getElementById(saveLaterId);	 
		var oy = findPosYForMML(object);
		var ox = findPosXForMML(object);		
		//popupH(ox);
		//popupW(oy);			
		var catEntryIds = getCatEntryIdURLForMML(catEntryId);		
		ajaxCallForMML(url + catEntryIds,'getAddToWishlistStatusForMML','','');		
	}
	
	function getCatEntryIdURLForMML(catentryId) {	
		var url = "";
		url = '&catEntryId_1=' + catentryId + '&quantity_1=1';
		return url;
	}	
	
	function findPosXForMML(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}

function findPosYForMML(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}
var mmlSaveFlag = 0;
function showLogonPageForMML(url,catentryId,modalOffUrl) {
		var catEntryIds = getCatEntryIdURLForMML(catentryId);
		if(catEntryIds.length > 0) {
			mmlSaveFlag = 1;
			var modalUrl = url + catEntryIds;
			var catIdsModalOff = enCodeUrlForMML(catEntryIds);
			var redirectURL = modalOffUrl + catIdsModalOff;
			fnShowLoginModal('SaveForLaterMML',redirectURL,modalUrl);
		}
	}	

	/*This function replaces character = and & with "%3d" and "%26" respectively for urls that are getting encrypted*/
	function enCodeUrlForMML(url){		
		var strValue = "";		
		for(i=0;i<url.length;i++){			
			var char = url.charAt(i);
			if(char == '=')
			{
				strValue = strValue + "%3d";
			}
			else if(char == '&')
			{
				strValue = strValue + "%26";
			}else{
				
				strValue =  strValue + char;
			}
		}
		return strValue;
	}


function ajaxCallForMML(url,callbackFunction,returnData,linkId) 
{ 
    var httpRequest = false; 	
    // Exit if this function is not supported
    if (!httpRequestSupported) {
        return;  
    }  
    
    // check if supported
    httpRequest = isHttpRequestSupported();   
    if (!httpRequest) { 
        httpRequestSupported = false;
        return false; 
    } 

    // Map the response to the callback function
    httpRequest.onreadystatechange = function() { 

        if (httpRequest.readyState == 4) {  
            if (httpRequest.status == 200) {
                if (returnData) { 
                    eval(callbackFunction + '(httpRequest.responseXML,linkId)'); 
                } else { 
                    eval(callbackFunction + '(httpRequest.responseText,linkId)'); 
                }  
            } else { 
                // TODO:  Keep this line commented in production.  The user will have no idea what this means.
                //('The AJAX request was made to our backend server and the following error occurred: ' + httpRequest.status); 
                eval(callbackFunction + '("")'); 
            } 
        }
        else{
            if(callbackFunction == 'displayTabContent'){
                
                htmlValue = "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                document.getElementById(linkId).innerHTML = htmlValue;
            }
            if(callbackFunction == 'browseSpecialOffer'){   
                htmlValue = "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                linkId.innerHTML = htmlValue;           
            }
            if(callbackFunction == 'loadingProductOptions'){   
				htmlValue = "<h4>Options and Services</h4>"
					+ "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                document.getElementById(linkId).innerHTML = htmlValue;
            }
        } 
    } 
    
    httpRequest.open('GET', url, true); 
    httpRequest.send(null); 
}
	
	function getAddToWishlistStatusForMML(value){	
	object = document.getElementById(saveLaterId);
	flag = '';
	if(value == "Success")
	{		
		return false;
	}
	else
	{		
		return false;
	}
}

    
var deleteStatus = 'false';
var deleteStatusUE = 'false';
      

function deleteItems(itemId) {
   if(deleteStatus == 'false' && deleteStatusUE == 'false'){
	    deleteStatus='true';
	    deleteStatusUE='true';
	    var smartCartDeleteURL="smartCartDeleteURL_"+itemId;
	    var smartCartDelete=document.getElementById(smartCartDeleteURL).value;
	    ajaxCallForMML(smartCartDelete,'testDelete');
	}
}

function formatCurrency(num) {
	
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

	return (num + '.' + cents);
}
function testDelete(value)
{    
	// Split the response according to delimiter
	var value_array=value.split('####');
	var totalQuantity = value_array[1]+" items";
	var totalPrice = value_array[2];
	document.getElementById("items").innerHTML = totalQuantity;
	document.getElementById("miniCartTotal").innerHTML = "$"+formatCurrency(totalPrice);
	if(document.getElementById("miniCartURL")!=null){
		document.getElementById("miniCartLink").href = document.getElementById("miniCartURL").value;
	}
	if(typeof isI18NConvReq == 'function' && isI18NConvReq()){
  		//fnConvertMiniCart();
  		var tempMiniCart = fnConSSfly($('div.miniCart').html());
  		$('div.miniCart').html('').html(tempMiniCart);
	}
	$('#mmlToolboxPanel .shopping .miniCart').html('').html(value_array[0]); 
	$('div#mmlToolbox p.shopping').find('a').html(value_array[1]+" items");
	deleteStatus = 'false';
	deleteStatusUE = 'false';	
	// Reload page if its shopping cart
	if(document.body.id=="shoppingcart") {
		window.location.reload();
	}
	if(document.body.id=="productOptions" || document.body.id=="StorePickUp"){
		window.location = "OrderItemDisplay?storeId=10153&catalogId=12605&orderId=.";
	}	
}    

/*Code for Save for later ends*/

/* Changes for Recent Searches - Starts */
var recentSearchesCookieName = 'RecentSearches';
$(function() {
	//If keyword present in the URL, update the cookie
	if(recentKwd != '' || recentKwdRdt != '') {
		var newCookieValue = '';
		var currCookieValue = getCookie(recentSearchesCookieName);
		var newCookieValue = getNewCookieValue(currCookieValue);
		if(newCookieValue != null && newCookieValue != '') {
			//Setting the RecentSearches cookie with new value and expiry as 10 YRS
			var date = new Date();
        	date.setTime(date.getTime() + (365 * 10 * 24 * 60 * 60 * 1000));
        	var expiry = ' expires=' + date.toUTCString();
			document.cookie = recentSearchesCookieName+'='+newCookieValue+';'+expiry;
		}
	}
	
	//Function to get the new cookie value
	function getNewCookieValue(currCookieValue) {
		var maxKwds = 15;
		var delim = '~';
		var currKwd = '';
		if(recentKwd != '') currKwd = recentKwd;
		else if (recentKwdRdt != '') currKwd = recentKwdRdt;
		var newCookieValue = currKwd+delim;		
		if(currCookieValue != null && currCookieValue != '') {
			var cookieVals = currCookieValue.split(delim);
			var cookieKwd = '';
			var counter = 1; //Coz, we have already added the current keyword to newCookieValue
			for(i=0; i < cookieVals.length; i++) {
				cookieKwd = cookieVals[i];
				if(cookieKwd != '' && cookieKwd != currKwd && counter < maxKwds) {
					newCookieValue += cookieKwd+delim;
					counter++;
				}
			}
		}
		return newCookieValue;
	}
});

//Function to remove the RecentSearches cookie - i.e. for Clear All button
function removeRecentSearches() {
	document.cookie = recentSearchesCookieName+'= ;';
	$('div.recentlySearched').html('<h4>Recent Searches</h4><p>Ready to start a new search? The items you seek will be saved here for you. </p>');
}
function removeRecentlyViewed() {
                /*document.cookie = 'RecentViewPartNum= ;';
                var currentTime = new Date();
                var month = currentTime.getMonth();
                var day = currentTime.getDate();
                var year = currentTime.getFullYear();
                year = year-1;
                var date = day+'/'+month+'/'+year;
                document.cookie = "RecentViewPartNum=;expires="+date;*/
                $.cookie("RecentViewPartNum",null);
	$('div.recentlyViewed').html('<h4>Recently Viewed</h4><p>' + norecentitemsmsg + '</p>');
}
/* Changes for Recent Searches - Ends */

/* Code to track the state of Toolbox - Starts */

var mmlStatusCookieName = 'MMLToolboxStatus';

//Function to update the Toolbox status in the cookie
function updateMMLCookie(activeTab) {
	var cookieValue = 'activeTab|';
	if(activeTab != null && activeTab != '') {
		cookieValue = 'activeTab|'+activeTab;
	}
	var date = new Date();
	date.setTime(date.getTime() + (365 * 10 * 24 * 60 * 60 * 1000));
	var expiry = ' expires=' + date.toUTCString();
	document.cookie = mmlStatusCookieName+'='+cookieValue+';'+expiry;
}

//MCP-3390
/*$(function() {
	var cookieValue = getCookie(mmlStatusCookieName);
	if(cookieValue != null && cookieValue != '') {
		var activeTab = cookieValue.split('|')[1];
		if(activeTab != '') {
			hover = 0;
			if(activeTab == 'search') 
				//In keyword pages, give enough time for updating MMLRecentSearches cookie
				setTimeout("$('#mmlToolbox').find('li p.search').trigger('click');", 100);
			else 
				$('#mmlToolbox').find('li p.'+activeTab).trigger('click');
		}
	}	
});*/
/* Code to track the state of Toolbox - Ends */

/* Function to apply customized scroll bar */
function applyJScrollBar(active) {
	if(sillyIE6) {
		switch(active){
			case 'shopping':
				$('#mmlToolboxPanel .panelContent .shopping').jScrollPane({showArrows:true});
				$('#mmlToolboxPanel .panelContent').css('padding', '20px 0px 20px 5px');
			  break;
			case 'lists':
				$('#mmlToolboxPanel .panelContent .lists').jScrollPane({showArrows:true});
				$('#mmlToolboxPanel .panelContent').css('padding', '20px 0px 20px 5px');
			  break;
			case 'search':
				$('#mmlToolboxPanel .panelContent .search').jScrollPane({showArrows:true});
				$('#mmlToolboxPanel .panelContent').css('padding', '20px 0px 20px 5px');
			  break;
			case 'info':
				$('#mmlToolboxPanel .panelContent .info').jScrollPane({showArrows:true});
				$('#mmlToolboxPanel .panelContent').css('padding', '20px 0px 20px 5px');
			  break;
		}
	} else {
		switch(active){
			case 'shopping':
				$('#mmlToolboxPanel .panelContent .shopping').jScrollPane({showArrows:true});
			  break;
			case 'lists':
				$('#mmlToolboxPanel .panelContent .lists').jScrollPane({showArrows:true});
			  break;
			case 'search':
				$('#mmlToolboxPanel .panelContent .search').jScrollPane({showArrows:true});
			  break;
			case 'info':
				$('#mmlToolboxPanel .panelContent .info').jScrollPane({showArrows:true});
			  break;
		}
	}
}
