/*
Last modified on 12/16/2010
Modified by R. Adams

- I have added removeAVTooltip() to remove the Articles and Videos tooltip with jQuery rather than Dojo...woot!

*/
$(function(){
	resultsBarFix();	
	shopDeptHover();
	chngShareLink();
	imgMagnifyRemove();
	contextHelpMsgTxt();
	dynSlide();
	gridViewPageBreak();
	/* terms and conditions link fix in checkout */
	termsAndConditionsLinkFix();
	/* Moved function into body.load() function so it would wait until all images were loaded. */
	railHeight(100);
	quickJumpMenu();
	orderConfMsg();  /*This banner will display on the Order Confirmation page above the page title */
	/*lowerLogin();  Change the login ID to lowercase */
	//removeCheckOtherStores();
	removeCreditCardInfo();
	removeStoreLocatorHeight(); /* removes iframe height from storelocator if store*/
	storeLocatorToNewWindow(); /* fix to help stores handle printing problems with store locator */
	/*adjustDeliveryVal();*/
	removeDollarSign(); /* removes extra $ the double dollar sign in the secure checkout - deleivery confirmation */
	giftCardCheck(); /* checks for valid ranges of giftCard*/
	//updateRebateLink(); /* quick fix for rebate links */
	removeAVTooltip();
	emailAFriendFix();	/* Defect 9642 */
	removeMaxQty(); /* request to remove max quantity from product price overrides on detail page */
	// Removed on IT request
	orderCheckFix(); /* hides customer name and address from anonymous order check */
	keywordSearchFix(); /* Defect 13234 */
	rePosMyStoreInfo(); /* Defect 13338 */
	showZipDevMsg(); /* Defect 13507 */
	/*fixMacFFDropDown(); Defect 13813 */
	hideCartEPPDropDown(); /* Hides Cart Protection Plan Selection Box While IT Fixes Redirect Issue  */
	hideAvailMsgBF(); /* Supress "x currently available" message on detail page */
	//blackFridayEndecaHack(); /* justin added on saturday after BF to simulate an endeca banner...thats right let that sink in */
	orderConfEmailFix();
	nurseryChk(); /* removes pickup in store for cetain nursery items*/
	//insertStormBanner();
	//updateShippingSelect(45);
	//parcelHolidayMsg();
	posRestriction();
	//percentOffHack(); /* issue with % sign being appended into a URL parameter */
	fixWinSafMastButton();  /* Defect 14552, 14414 */
	onlineOnlyAppliances(); /* to run from 12-31 thru 1-10 */
	//storeKiosk();
	addToMyProducts();
	taxRefundCardUpdates();
});

function onlineOnlyAppliances() {
	if($('#prod-stats').length > 0){
		var effectedItems = [274807,274821,274824];
		var applItem = itemNumber($('#item-info').text());
		$(effectedItems).each(function(i){
			if(effectedItems[i] == applItem){
				$('p.promo-text').empty().html('<b>Online Only Price </b>&nbsp;');
			}
		});
		
	}
}
function percentOffHack(){
	if($('#breadcrumbs').length > 0){
		var msg = '10% off Major Appliances';
		$('#breadcrumbs ul li').each(function(){
			var crumbTxt = $(this).text();
			if(crumbTxt.indexOf(msg) >= 0){
				if($('.prod-col-b').length > 0){
					$('.prod-col-b a').each(function(){
						var thisHref = $(this).attr('href');
						if(thisHref.indexOf(msg) >= 0){
							var newHref = thisHref.replace(msg,'10 off Major Appliances');
							$(this).attr('href',newHref);
						}
					});
				}
			}
		});
	}
}

function posRestriction(){
	if($('#ship-options').length > 0 && $('#posRestrictedAlerts').length > 0){
		var thisItemNum = itemNumber($('#item-info').text());
		$('#ship-options .delivery-options').replaceWith('<strong>The item '+thisItemNum+' is restricted for shipment</strong> in the area you are shopping due to <strong>ordering procedures that require assistance.<br />Please visit your local Lowe\'s store to place your order.</strong>');
		$('.purchase-options').remove();
	}
}


function updateShippingSelect(threashold) {
	
	/* This will auto select the free 2 day delivery option if a user selects Parcel Shipping */
	
	if ( $('#scGenericshipModeId').length > 0 )
	{
		var total = parseFloat($('input[name=currentTotal]').val());
		
		if ( total > threashold )
		{
			$('#scGenericshipModeId').find('option').each(function(i, item){

				var $this = $(this);
				
				// Remove default selected value and set the second option
				if ( $this.is(':selected') && i === 0 ) 
				{
					$this.attr('selected', '');
					$this.next().attr('selected', 'selected');
					refreshShpingChrg(document.ShopCartForm);
				}

			});
		}
	}
	
}

function insertStormBanner(){
	/* only on homepage */
	if($('#homepage-hero').length > 0){
		var stateArray = ['ND','SD','MN','IA','WI','IL','MO','TN','IN','KY','MI','OH','WV','VA','NY','NC','CT','RI','MA','ME','NH','VT','MD','NJ','DE'];
		if(getStateAndZip()){
			var userInfo = getStateAndZip().split(',');
			var userState = userInfo[0].toLowerCase();
			$(stateArray).each(function(i){
				if(stateArray[i].toLowerCase() == userState){
					$('<div><a title="Plan and Prepare For Snowstorms" href="/cd_Snow+span+classsearchtermStormspan_281748281_"><img src="/images/storm_20101203.jpg" alt="Be Ready When Snowstorms Strike" /></a></div>').insertBefore('#hero');
				}
			});
		}
	}
}
function nurseryChk(){
		var itemNum;
		/* detail page */
		if($('#ship-options').length > 0){
			itemNum = chkPlant(itemNumber($('#item-info').text()));
			if(itemNum){
				$('#ship-options label').each(function(){
					var $thisLabel = $(this);
					if($thisLabel.hasClass('ship-options-pickup') || $thisLabel.hasClass('ship-options-deliver')){
						$thisLabel.parent().remove();
					}
				});	
			}
		}
		/* cart page */
		if($('#my-cart-contents').length > 0){
			$('#my-cart-contents tbody tr').each(function(i){
				var $thisRow = $(this);
				itemNum = chkPlant(itemNumber($($thisRow).find('.prod-details p:first').text()));
				if(itemNum){
					$thisRow.find('.delivery-options li label').each(function(){
						var isPickup = $(this).text();
						if(isPickup.indexOf('Pick Up') >= 0 || isPickup.indexOf('Truck Delivery') >= 0){
							$(this).parent().remove();
						}												  
					});
				}
			});
		}
	}
//==============================
	function chkPlant(plantItem){
		var foundIt = false;
		var plantArray = [30513,31439,31506,33862,34547,36656,62543,161816,182031,182034,182038,182045,182056,182057,182065,271918,277036,277440,337036,337038,337039,337049,337213,337215,337218,337219,337221,337222,337230,337238,337240,337244,337245,337246,337247,337248,337249,337250,337251,337252,337253,337278,337279,337280,337284,337387,337389,337391,337392,337403,337404,337405,337406,337407,337435,337436,337437,337438,337439,337440,337441,337442,337443,337444,337445,337446,337448,337452,337453,337454,337455,337457,337498,337580,337787,337802,337804,337807,337815,337821,337822,337824,337825,337826,337938,337939,337940,337941,337948,337952,337953,337955,337957,337968,337969,337971,337973,337978,337980,337982,338011,338017];
		$(plantArray).each(function(i){
			if(plantArray[i] == plantItem){
				foundIt = true;
			}							
		});
		return foundIt;
	}
//==================================
	function itemNumber(str){
		var $thisItem = str.split('|');
			$thisItem = $thisItem[0].split('#:');
			if($thisItem.length > 1){
				return $thisItem[1].trim();
			} 
	}
//===============================
function orderConfEmailFix(){
	if($('#content-area-order-conf').length > 0){
		$('img').each(function(){
			var thisImg = $(this);
			var srcVal = $(thisImg).attr('src');
			if(srcVal.indexOf('email.lowes.com') >= 0){
				var newVal = srcVal.replace('email.lowes.com','p.chtah.com');
				$(thisImg).attr('src',newVal);
			}
		});
	}	
}
function blackFridayEndecaHack()
{
	if($('#breadcrumbs').length)
	{
		$('#breadcrumbs li').each(function(i,li){

			var $text = $(li).text().trim();
			
			if($text == "Whirlpool: Save up to 625 via Mail-in Rebate" || $text == "Whirlpool Save up to 625 via Mail-in Rebate")
			{
				$('#one-column h1').after('<div class="fake-endeca" style="margin-bottom: 10px;"><a href="http://www.lowespromos.com/PDFs/2639-1.pdf?cm_sp=Appliances-_-HP_Area_6c-_-Up_To_625_Rebate_Whirlpool_Kitchen_Appliances_Rebate" title="Get Rebate" target="_blank"><img src="/campaign/holiday/2010/espot/homepage/images/espot/bf_whirlpool_banner_740x130.jpg" alt="Get Rebate"/></a></div>');
			}

		});

	}
}

/* used to dynamically size iframe height for featured BF iframe on HP */
function bfIframeHeight(val){	
	var newframeHeight;
    if(val != undefined){
    		newframeHeight = val + 30;
    } else {
    		newframeHeight = 1500;		
    }		
    $('#product_frame').attr('height',newframeHeight);	
}

function hideAvailMsgBF(){
	if($('#buy-now').length > 0){
		$('#buy-now li').each(function(){
			var thisTxt = $(this).html();
			if(thisTxt.indexOf('on the shelf available for purchase') >= 0){
				$(this).remove();
			}
		});
	}
}

function orderCheckFix(){
	if($('table.order-info').length > 0){
		$('ul.address li').each(function(){
			var thisTxt = $(this).text();
			if (thisTxt.indexOf(',') == -1 && thisTxt.indexOf('(') == -1) {
				$(this).remove();
			}
		});
	}
}

function removeMaxQty(){
	if($('#qty-limit').length > 0){
		$('#qty-limit').remove();
	}	
}

function removeAVTooltip(){
	
	$av = $('#av-flag');
	
	if ( $av.length > 0 )
	{
		$av.find('.av-flag-end .close').click(function(){
			
			$av.fadeOut();
			
			return false;
			
		}).attr('onclick', '');
	}
	
}

function updateRebateLink(){
		if($('#content-area-prod-list').length > 0){
			$('#result-list li').each(function(){
				var $jsLink = $('.rebate a',this);
				if($jsLink.length >0){
					var $itemInfo = $('.item-info',this).text().split('|');
					/*$itemInfo = $itemInfo[0].split('#:');*/
					$itemInfo = $itemInfo[0].match(/[0-9]+/m);
					$itemInfo = $itemInfo[0];
					
					var $rebateLink = $($jsLink).attr('href').split("','");
					$($jsLink).attr('href',$rebateLink[0] + "&id2=" + $itemInfo + "','" + $rebateLink[1]);
				}
											   
			});
		}
}

function giftCardCheck()
{
/***
	$('.gift-card-block #giftCard').bind('blur focusout',function(){
		$this = $(this);
		var min = 6006491797150000000;
		var max = 6006491797309899999;		
		
		if($this.val().length > 0)
		{	
			cardNumber = parseFloat($this.val());
			if(cardNumber >= min && cardNumber <= max)
			{
				alert("We are currently unable to process your Lowe's(r) Visa(r) Rewards Certificate on Lowes.com at this time. Your Rewards Certificate will process successfully at any Lowe's store.");
				$this.val('')
			}
			return false;
		}
	});
	
	$('.gift-card-block #giftCard').trigger('blur');
	*/
	return true;

}

/*========== Temporary fix for delivery/shiping value ======*/
function adjustDeliveryVal(){
	if($('#ship-options .delivery-estimate').length > 0){
		var shipLink = $('#ship-options .delivery-estimate a.contextHelp');
		$(shipLink).bind('click',function(){
			if($('#ship_rates').length > 0){
				fixDecimalPlaces();
			} else {
				setTimeout(fixDecimalPlaces,1000);	
			}
		});
	}	
}
function fixDecimalPlaces(){
	if($('#ship_rates').length > 0){
		var shipValue = $('#ship_rates td:last').text();
		var newShipValue = shipValue.substring(0,shipValue.indexOf('.')+3);
		$('#ship_rates td:last').text(newShipValue);
		
	}
}
/*========== Remove iframe height if store ===========*/
function removeStoreLocatorHeight(){
	if($('#externalServiceIframe').length >0){
		/*if(isStore){
			$('#externalServiceIframe').css('min-height','1350px');
		}*/
		if($.browser.mozilla){
			$('#externalServiceIframe').removeAttr('height');
			var agent = navigator.userAgent.split(' ');
			$.makeArray(agent);
			$(agent).each(function(i){
				if(this.toLowerCase().indexOf('firefox') >=0){
					var agentVersion = agent[i];
					agentVersion = agentVersion.split('/');
					$.makeArray(agentVersion);
					if(parseInt($.trim(agentVersion[1])) == 1){
						$('#externalServiceIframe').css('min-height','1350px');
					}
				}
			});
		}
	}
}
/*====================================================*/

/*==========Check to see if in store, and if so change store locator link=========*/
function storeLocatorToNewWindow(){
	var storeLocatorLink = "http://lowes.know-where.com/lowes_nextgen/cgi/index?design=default&lang=eng&mapid=US&srcIframe=http%3a%2f%2fwww.lowes.com%2fwebapp%2fwcs%2fstores%2fservlet%2fLowesIframeTransport&srcJS=http%3a%2f%2fwww.lowes.com%2fwcsstore%2fB2BDirectStorefrontAssetStore%2fjavascript%2fiframeTransport.js";

	if($('#change-current-store').length){
		$.each($.browser, function(i, val) {
		   if(i=="mozilla" && $.browser.version.substr(0,3)=="1.8") {
		   		$('#my-store').append(' | <a id="print-directions" href="">Print Directions</a>');
				$('#print-directions').attr({target: '_blank', href: storeLocatorLink});
				$('#current-store-detail').attr({target: '_blank', href: storeLocatorLink});
		   }
		 });				
	}
	
	if($('#store-locator a').length)
	{
		$.each($.browser, function(i, val) {
		   if(i=="mozilla" && $.browser.version.substr(0,3)=="1.8") {
				$('#store-locator a').attr({target: '_blank', href: storeLocatorLink});
		   }
		 });
	}
}
/*============================================*/
/*==========Remove Check Other Stores Link on Detail Page =========*/
function removeCheckOtherStores(){
	if($('#bottomTabContainer').length > 0 || $('.goToPage').length > 0){
		return;
	} else {
		$('#content-block a').each(function(){
			if($(this).text().toLowerCase().indexOf('check other stores') >= 0 || $(this).text().toLowerCase().indexOf('check inventory') >= 0){
				$(this).remove();	
			}
		});	
	}
}
/*==========Make all Login Submissions Become Lowercase Text=======*/
function lowerLogin() {
	if($('form#Logon').length > 0){
		$('form#Logon .form-input-block a.button-green').attr('href','#login').bind('click',function(event){
			event.preventDefault();
			var lowerVal = $('#WC_AccountDisplay_FormInput_logonId_In_Logon_1').val().toLowerCase();
			$('#WC_AccountDisplay_FormInput_logonId_In_Logon_1').val(lowerVal);
		 	document.Logon.submit();
		});
	}
}
/*==========Order Confirmation Message=======*/

/* <a id="conf_banner" href="/pl_Outdoor+Power+Equipment_4294859121_4294937087_ "><img src="/images/prepare-your-yard_20100818.jpg" alt="" /></a> */

function orderConfMsg() {
	if( $('#content-area-order-conf').length > 0 ) {
		$("<p>For installation of dryers, dryer manufacturers recommend semi-rigid dryer ducts. For hook up, Lowe's delivery and installation services require a new duct or kit suitable for your dryer, supplied by you. See your owner's manual for more information.</p>").css({'display':'block', 'margin':'5px 0 20px'}).prependTo('#one-column');
	}
}

/*==========Quick Jump Menu - 1.0.5 - On Change update URL and reload=======*/
function quickJumpMenu() {
	if($('.quick-jump').length != 0) {
		$('.quick-jump').bind('change', function() {
			var val = $(this).val();
			if(val != ''){
				window.location = val;
			}
		});
	}
}
/*==========Right Rail - 1.0.5 - Check height and make sure it doesn't overlap the site...div is absolutely positioned=======*/
function railHeight(currHeight){
	if($('#one-column').length > 0){
		/* If it is not an Article General page */
		if($('#one-column .wcm-landing-main-content').length == 0) {
			var currentTallestHeight = currHeight, colHeight = 0, colPosition;
		
			/* get the greatest height of immediate child div of #one-column */	
			/* C. Stukes 09-02-2010 - Changed Selector from '#one-column > div' to '#one-column > div, #one-column .community-videos' for Availability Filters */
			$('#one-column > div, #one-column .community-videos').each(function(){	
				/* get child's offset from parent and add to height */
				colPosition = $(this).position();
				colHeight = ($(this).height() + colPosition.top);
				
				if(colHeight > currentTallestHeight){
					currentTallestHeight = colHeight;	
				}
			});
			
			if($('#one-column').height() < currentTallestHeight){
				if($.browser.msie && $.browser.version == '6.0'){
					$('#one-column').height(currentTallestHeight + 50);
				}else{
					$('#one-column').css('min-height',currentTallestHeight+50 + 'px');	
				}
			}
		}
	}
}


/*==========Grid View Pagination - Force Page Break for Print=======*/
function gridViewPageBreak(){
	if($('#product-list')){
		$('#product-list li:nth-child(6n)').addClass('pageBreakAfter');
	}
};
/*=======================================*/
function resultsBarFix(){
	var navControl = '#page-block #content-block #content-area-prod-list #one-column .catalog-utility-nav .bottomBar .right fieldset.nav-control';
	if($(navControl).length > 0){
		var totalPages = parseInt($(navControl + ' form input[type=hidden]:first').val());
		
		$(navControl + ' form div.form-input-block input.tiny').bind('blur',function(){
			if(isNaN(parseInt($(this).val()))){
				$(this).val('1');
			} else {
				if(parseInt($(this).val()) > totalPages){
					$(this).val(totalPages);
				}
			}
		});
	/*	$(navControl + ' form div.form-input-block .button-grey').attr('onclick','').bind('click',function(){
			callChangePageNumber($(navControl + ' form div.form-input-block input.tiny').val());
		});*/
	}
}
/*=======================================*/
/*delays shop by dept on mouseover*/
function shopDeptHover(){
	var shopDept;
	var shopRoom;
	var shopLCI;
	var LCIsub;
	$("#global-nav li.menu-1").bind('mouseenter',function(){
		clearTimeout(shopDept);
		shopDept = setTimeout(function(){
			$("#global-nav li.menu-1 ul.subnav").css({'left' : '-4px'});				  
					},150);
	}).bind('mouseleave',function(){
		clearTimeout(shopDept);
		$("#global-nav li.menu-1 ul.subnav").css({'left' : '-5000em'});
	});
	$("#global-nav li.menu-2").bind('mouseenter',function(){
		clearTimeout(shopRoom);
		shopRoom = setTimeout(function(){
			$("#global-nav li.menu-2 ul.subnav").css({'left' : '-4px'});				  
					},150);
	}).bind('mouseleave',function(){
		clearTimeout(shopRoom);
		$("#global-nav li.menu-2 ul.subnav").css({'left' : '-5000em'});
	});
	$("#global-nav li.menu-3").bind('mouseenter',function(){
		clearTimeout(shopLCI);
		shopLCI = setTimeout(function(){
			$("#global-nav li.menu-3 ul.subnav").css({'left' : '-4px'});				  
					},150);
	}).bind('mouseleave',function(){
		clearTimeout(shopLCI);
		$("#global-nav li.menu-3 ul.subnav").css({'left' : '-5000em'});
	});
	$("#email-sup input[type=text]:first").bind('mouseenter',function(){
		$("#global-nav li.menu-2 ul.subnav").css({'left':'-5000em'});
		$("#global-nav li.menu-3 ul.subnav").css({'left':'-5000em'});
	});
	$('#header-block ul li').each(function(i){
		$(this).bind('keyup',function(e){
			var key = e.keyCode;
			if(key == 9){
				var liClass = $(this).attr('class');
				switch(liClass){
					default:
						$("#global-nav li.menu-1 ul.subnav").css({'left' : '-5000px'});
						$("#global-nav li.menu-2 ul.subnav").css({'left' : '-5000px'});
						$("#global-nav li.menu-3 ul.subnav").css({'left' : '-5000px'});
						break;
					case 'menu-1':
						$("#global-nav li.menu-1 ul.subnav").css({'left' : '-4px'});
						$("#global-nav li.menu-2 ul.subnav").css({'left' : '-5000px'});
						$("#global-nav li.menu-3 ul.subnav").css({'left' : '-5000px'});
						break;
					case 'menu-2':
						$("#global-nav li.menu-1 ul.subnav").css({'left' : '-5000px'});
						$("#global-nav li.menu-2 ul.subnav").css({'left' : '-4px'});
						$("#global-nav li.menu-3 ul.subnav").css({'left' : '-5000px'});
						break;
					case 'menu-3':
						$("#global-nav li.menu-1 ul.subnav").css({'left' : '-5000px'});
						$("#global-nav li.menu-2 ul.subnav").css({'left' : '-5000px'});
						$("#global-nav li.menu-3 ul.subnav").css({'left' : '-4px'});
						break;
				}
			}
		});
	});
}
/*=====================================*/
function chngShareLink(){
	if($('.share-header .share .top a.contextHelp')){
		$('.share-header .share .top a.contextHelp').attr('href','/MContent/Structured/SuperCategoryLandingPage/social_networks.html');
	}
}
/*=====================================*/
function imgMagnifyRemove(){
	if($('#original-image')){
		var imgPath = $('#original-image').attr('src');
		if(imgPath != undefined){
			if(imgPath.indexOf('no_image_available_lg.gif') == -1 && imgPath.indexOf('imagenotavailable_276x276.jpg') == -1){
				if($('#expand-link')){
					$('#expand-link').show();
				}
			}
		}
	}
}
/*===================================*/
function contextHelpMsgTxt(){
	if($('a.contextHelp')){
		$('a.contextHelp').each(function(i){
			if($(this).attr('title') == 'Content TBD'){
				$(this).attr('title','Click for more information');
			}
		});
	}
}
/*===================================*/
function dynSlide(){
	
	getInstances();
	
	//find all sliders
	function getInstances(){
		var dynSliders = $(".dyn_slide");
		if(dynSliders.length > 0){
			createSliders(dynSliders);
		}
	}
	
	//create basic structure
	function createSliders(dynSliders){
		dynSliders.each(function (i){
			var mySlider = dynSliders[i];
			mySlider.wrap = $(mySlider).attr("id");
			mySlider.data = $(mySlider).attr("id")+".xml";
			mySlider.cur_slide = 0;
			$('<ul class="slide_holder"></ul>').appendTo("#"+mySlider.wrap);
			$('<a class="next" href="#next"><span></span></a>').appendTo("#"+mySlider.wrap);
			$('<a class="prev" href="#prev"><span></span></a>').appendTo("#"+mySlider.wrap);
			$('<a class="playPause pause" href="#pause"><span></span></a>').appendTo("#"+mySlider.wrap);
			$('<ul class="slide_indicator"></ul>').appendTo("#"+mySlider.wrap);
			$('<ul class="desc_holder"></ul>').appendTo("#"+mySlider.wrap);
			getData(mySlider)
		});
	
	}
	
	//get and insert xml data
	
	function getData(mySlider){	
	/* fixes path issues when logging in and out */
	 var myURL=(document.URL).toString();
	 var thisURL=(myURL).toString().split('/');
	 var xmlURL = thisURL[2];
	 var urlProtocol = window.location.protocol;
		$.ajax({
		
			type: "GET",
			url: urlProtocol+"//"+xmlURL+"/xml/"+mySlider.data,  //XML file path
			dataType: ($.browser.msie) ? "text" : "xml",   
			success: function(data) {
				var xml
				if (typeof data == "string") {       
					xml = new ActiveXObject("Microsoft.XMLDOM");      
					xml.async = false;       xml.loadXML(data);    
				} else {       
					xml = data;     
				}
				
				nextLabel = $(xml).find('slides').attr('next');
				mySlider.next = $("#"+mySlider.wrap+" .next");
				$(mySlider.next).html(nextLabel);
				
				
				prevLabel = $(xml).find('slides').attr('prev');
				mySlider.prev = $("#"+mySlider.wrap+" .prev");
				$(mySlider.prev).html(prevLabel);
				
				
				mySlider.playLabel = $(xml).find('slides').attr('play');
				mySlider.pauseLabel = $(xml).find('slides').attr('pause');
				mySlider.playPause = $("#"+mySlider.wrap+" .playPause");
				mySlider.playPause.span = $("#"+mySlider.wrap+" .playPause span");
				$(mySlider.playPause.span).html(mySlider.pauseLabel);
				
				mySlider.autoPlay = $(xml).find('slides').attr('autoPlay');
				mySlider.tranSpeed = $(xml).find('slides').attr('tranSpeed');
				mySlider.secBetween = $(xml).find('slides').attr('secBetween');
				mySlider.touchPause = $(xml).find('slides').attr('touchPause');
				mySlider.slides = $(xml).find('slide');
				mySlider.numSlides = $(xml).find('slide').length;
				$(mySlider.slides).each(function(i){
					content = $(this).find('content').text();
					label = $(this).find('label_text').text();
					desc = $(this).find('desc').text();
					
					
                    /* Updated by Chris Stukes (04/13/2010) */
                    /* If Slide's Date is Valid, Setup it Up */
                    /*if (validateDate($(this))){*/
						if(i == 0){
							$('<li class="active first slide"></li>').html(content).appendTo("#"+mySlider.wrap+" .slide_holder");
							$('<li class="active first indicator"></li>').html(label).appendTo("#"+mySlider.wrap+" .slide_indicator");
							$('<li class="active first desc"></li>').html(desc).appendTo("#"+mySlider.wrap+" .desc_holder");
						}else if(i+1 == mySlider.numSlides){
							$('<li class="last slide"></li>').html(content).appendTo("#"+mySlider.wrap+" .slide_holder");
							$('<li class="last indicator"></li>').html(label).appendTo("#"+mySlider.wrap+" .slide_indicator");
							$('<li class="last desc"></li>').html(desc).appendTo("#"+mySlider.wrap+" .desc_holder");
						}else{
							$('<li class="slide"></li>').html(content).appendTo("#"+mySlider.wrap+" .slide_holder");
							$('<li class="indicator"></li>').html(label).appendTo("#"+mySlider.wrap+" .slide_indicator");
							$('<li class="desc"></li>').html(desc).appendTo("#"+mySlider.wrap+" .desc_holder");
						}
					/*}*/
				});
				mySlider.slides = $("#"+mySlider.wrap+" .slide_holder li");
				
				mySlider.indicators = $("#"+mySlider.wrap+" .slide_indicator li");
				mySlider.descriptions = $("#"+mySlider.wrap+" .desc_holder li");
				assignIndicatorVars(mySlider);
				makeSlidesClick(mySlider);
				autoTransition(mySlider);
				
				
			}
		});
	}
	
	//give indicators needed reference attributes
	function assignIndicatorVars(mySlider){
		$(mySlider.indicators).each(function(i){
			mySlider.indicators[i].num = i;						  
		});
	}
	
	//set click events
	function makeSlidesClick(mySlider){
		
		if(mySlider.touchPause == "true"){
			$(mySlider.slides).hover(function(){
				$(mySlider).stopTime();
			},
			function () {
				autoTransition(mySlider);
			}
		);
		}
		
		$(mySlider.indicators).click(function(i){
			transition(mySlider,this.num);
			autoTransition(mySlider);
		});
		
		$(mySlider.next).click(function(i){
			transition(mySlider,-1);
			autoTransition(mySlider);
		});
		$(mySlider.prev).click(function(i){
			transition(mySlider,-2);
			autoTransition(mySlider);
		});	
		
		$(mySlider.playPause).click(function(i){
			playPauseToggle(mySlider);							  
		});
		
	}
	
	//toggles button for play and pause
	function playPauseToggle(mySlider){
		if($(mySlider.playPause).hasClass('pause')){
			$(mySlider.playPause).removeClass('pause');
			$(mySlider.playPause).addClass('play');
			$(mySlider.playPause.span).html(mySlider.playLabel);
			$(mySlider.playPause).attr('href','#play');
			$(mySlider).stopTime();
		}else{
			$(mySlider.playPause).removeClass('play');
			$(mySlider.playPause).addClass('pause');
			$(mySlider.playPause.span).html(mySlider.pauseLabel);	
			$(mySlider.playPause).attr('href','#pause');
			autoTransition(mySlider);
		}
	}
	
	//auto play...
	function autoTransition(mySlider){
		if(mySlider.autoPlay == "true"){
			$(mySlider).stopTime();
			$(mySlider).everyTime(mySlider.secBetween*1000, function(i) {
			  transition(mySlider,-1);
			}, 0);
		}
	}
	
	//transition between slides...
	function transition(mySlider,next){
	
		curr = mySlider.cur_slide;
		$(mySlider.descriptions).each(function(i){
		
				
				$(mySlider.descriptions[i]).css({'dispaly':'none'});							   
			
				
		});
		if(next == -1){
			next = whatsNext(mySlider);
		}else if(next == -2){
			next = whatsLast(mySlider);
		}else{
			mySlider.cur_slide = next;
		}
		if(mySlider.tranSpeed != "none"){
			$(mySlider.slides[curr]).fadeOut(mySlider.tranSpeed);
		}else{
			
			$(mySlider.slides[curr]).css({'opacity':0,'display':'none'});
		}			
		$(mySlider.slides[curr]).removeClass('active');
		$(mySlider.indicators[curr]).removeClass('active');
		$(mySlider.descriptions).each(function(i){
			if(i != curr){						    
				$(mySlider.descriptions[i]).css({'display':'none'});
			}
		});		
		if(mySlider.tranSpeed != "none"){
			$(mySlider.descriptions[curr]).fadeOut(mySlider.tranSpeed, function(i){
				$(mySlider.descriptions).each(function(i){
					if(i != next){						    
						$(mySlider.descriptions[i]).css({'display':'none'});
					}
				});
				$(mySlider.descriptions[next]).css({'dispaly':'block'});
		
				$(mySlider.descriptions[next]).fadeIn(mySlider.tranSpeed);	
			});
		}else{
			$(mySlider.descriptions[curr]).css({'opacity':0,'display':'none'});
			$(mySlider.descriptions[next]).css({'opacity':1,'display':'block'});
		}
		if(mySlider.tranSpeed != "none"){
			$(mySlider.slides[next]).fadeIn(mySlider.tranSpeed);
		}else{
			$(mySlider.slides[next]).css({'opacity':1,'display':'block'});
		}
		$(mySlider.slides[next]).addClass('active');
		$(mySlider.indicators[next]).addClass('active');
		
		
		
							$(mySlider.descriptions).each(function(i){
				if(i != mySlider.cur_slide){						    
					$(mySlider.descriptions[i]).css({'display':'none'});
				}
			});
		
	}
	
	//get next slide
	function whatsNext(mySlider,clicked){

		if(mySlider.cur_slide >= mySlider.slides.length-1){
			mySlider.cur_slide = 0;
		}else{
			mySlider.cur_slide = mySlider.cur_slide+ 1;
		}
		
		return mySlider.cur_slide;
	
	}
	
	//get last slide
	function whatsLast(mySlider,clicked){

		if(mySlider.cur_slide == 0){
			mySlider.cur_slide = mySlider.slides.length-1;
		}else{
			mySlider.cur_slide = mySlider.cur_slide- 1;
		}
		
		return mySlider.cur_slide;
	
	}	

	/* Created by Chris Stukes (04/13/2010) */
	/* Finds If Selected Slide is Valid for Current Date */
	function validateDate(objjqXMLSlideInfo)
	{
		var strSlideStartTime = objjqXMLSlideInfo.attr("start");
					/* Start Time for Slide */
		var strSlideEndTime = objjqXMLSlideInfo.attr("end");
					/* End Time for Slide */
		/*var aStartTimeInfo = null; */
					/* The Broken Apart Start Time */
		/*var aEndTimeInfo = null; */
        			/* The Broken Apart End Time */
		/*var objjqPageInfoLayer = $("div[name='PAGE_TIMESTAMP']"); */
					/* Jquery Object for Layer Containing Page Information*/
		/*var strPageInfo = objjqPageInfoLayer.text();*/
						/* Page Information */
		/*var aPageTimeInfo = strPageInfo.split("millis=");*/
						/* Page Time Information Separated from Page Information */
		/*var objDateCurrent = new Date();*/
					/* Current Date Information */
		/*var objDateSlideStart = new Date();*/
					/* Starting Time for Slide */
		/*var objDateSlideEnd = new Date();*/
					/* Ending Time for Slide */
        var boolSlideIsValid = true;
        			/* Indicator That Slide is Valid for Current Date, Slide Will Always Validate Unless Current Date is Outside of Set Range */

		if (strSlideStartTime != "" && strSlideEndTime != "")
		{
			var aStartTimeInfo = strSlideStartTime.split("/");
					/* The Broken Apart Start Time */
			var aEndTimeInfo = strSlideEndTime.split("/");
					/* The Broken Apart End Time */

			if (aStartTimeInfo.length == 3 && aEndTimeInfo.length == 3)
			{
				var objjqPageInfoLayer = $("div[name='PAGE_TIMESTAMP']"); 
					/* Jquery Object for Layer Containing Page Information */
					
				if (objjqPageInfoLayer.length > 0)
				{
					var strPageInfo = $(objjqPageInfoLayer.get(0)).text();
						/* Page Information */
					var aPageTimeInfo = strPageInfo.split("millis=");
						/* Page Time Information Separated from Page Information */
						
					if (aPageTimeInfo.length == 2)
					{
						var objDateCurrent = new Date(parseInt(aPageTimeInfo[1]));
							/* Current Date Information */
						var objDateSlideStart = new Date(parseInt(aStartTimeInfo[2]), (parseInt(aStartTimeInfo[0]) - 1), parseInt(aStartTimeInfo[1]), 12, 0, 0);
							/* Starting Time for Slide */
						var objDateSlideEnd = new Date(parseInt(aEndTimeInfo[2]), (parseInt(aEndTimeInfo[0]) - 1), parseInt(aEndTimeInfo[1]), 12, 0, 0);
							/* Ending Time for Slide */
							
						if (objDateSlideStart > objDateCurrent || objDateCurrent > objDateSlideEnd)
						{
							boolSlideIsValid = false;
						}
					}
				}
			}
		}
        
        /* Return False If Current Date is not Within the Selected Slide's Start and End Date, Else True */
        return boolSlideIsValid;
	}
}

/*===============================================*/
function termsAndConditionsLinkFix(){
	if($('#creditCardInputs #lccBlock .lowes-credit-card-promo p')){
		$('#creditCardInputs #lccBlock .lowes-credit-card-promo p a').each(function(){
			$(this).remove();			  
		});
		$('#creditCardInputs #lccBlock .lowes-credit-card-promo p').append('<a href="/cd_Special+Credit+Events_781778798_" target="_blank">Terms and conditions</a>')
	}
}

function getStateAndZip(){
	if (chkCookie("selectedStore1")){
		var cookieArray = chkStoreZIP("selectedStore1");
		$.makeArray(cookieArray);
		var userState = cookieArray[0].substring(cookieArray[0].length,cookieArray[0].lastIndexOf(' '));
		userState = $.trim(userState);
		return userState + ',' + cookieArray[3] + ',' + cookieArray[1];
	} else {
		return false;
	}
}

/*======== remove incorrect credit card promo in checkout reveiw and pay ====================*/
function removeCreditCardInfo(){
	if($('#lccBlock .lowes-credit-card-promo').length >0){
		$('#lccBlock').remove();
	}
}
/*====== check to see if the user is from the store ==========*/
function isStore(){
	if(chkCookie('isStore')){
		return true;
	} else {
		return false;	
	}
}

//$(window).load(railHeight(100));

/*======== remove the extra $ on the Secure Checkout - deleivery confirmation
(You must enter a P O box in the address field to test) ====================*/

function removeDollarSign() {
	if($('div.checkout-container').length > 0){
	v = $("div.checkout-container").html().replace(/\$\$/g,'$');
	$("div.checkout-container").html(v);
	}
}

/* 9642 - Fix for Missing Article Name Which are Pulled from the H1 Tag in "Article-Info" Div Tag. 
		  This Fixes the Issue Where the Div Has The Class "Article-Info" Instead of the ID */
function emailAFriendFix()
{
	var objjqArtInfoLayer = $("div [class='article-info']");
					 /* Layers with the "Article-Info" Class */
	
	if (objjqArtInfoLayer.length == 1)
	{
		objjqArtInfoLayer.attr("id", "article-info");
	}
}

/* 13234 - Fix for the Masthead Keyword Search Sending User to Product Details Page from Default Text 
		   or Empty Text Submission */
function keywordSearchFix()
{
	var $objSearchButton = $("form[name='frmQuickSearch'] input[type='image']");
	
	/* Keyword Search Form Submission Buttons */
	if ($objSearchButton.length == 1)
	{
		$objSearchButton.bind("click", function(e)
		{
			
			var $objSearchInput = $("#Ntt", this.form);
			/* Form Input for Keyword Search */
			/*var strSearchValue = "";
			Form Search Input Box Value */
				
			if ($objSearchInput.length == 1)
			{
				var strSearchValue = $objSearchInput.val().toLowerCase();
					strSearchValue = strSearchValue.replace('"', ''); /* Added to remove " from the string */
				
				if (strSearchValue == "keyword or item #" || strSearchValue == "")
				{
					location.href = "/pc_Appliances_4294937007_4294937087_";
					return false;
				}
			}
		});
	}
}

/* Defect 13338 - Positions Correctly Second My Store Popup */
function rePosMyStoreInfo()
{	 
	$(".current-store-link2").live("click", function()
	{
		/*var aLinkPos = $(this).position();*/
		var $objMyStorePopup = $("#my-store-more-info2");
	  
		if ($objMyStorePopup.length > 0)
		{
			var aLinkPos = $(this).offset();
		  
			$objMyStorePopup.each(function()
			{
				$(this).css({
					"display": "block",
					"left": aLinkPos.left + "px",
					"top": (aLinkPos.top + 10) + "px"
				});
			});
		}
	});
}

/* Defect 13507 - Shows Message That User Needs to Zip In or Select a Delivery Method */
function showZipDevMsg()
{
	/* If the Zip Error Information Exists, Setup to Show Error Message */
	if ($(".js-delivery-method-error").length > 0)
	{
		/* Setup Events for the "Continue Checkout" Button */
		$("#cart-Continue-Checkout, #cart-Continue-Checkout-Avail").bind("click", function(objEvent)
		{
			objEvent.preventDefault();
			
			$("input[value='Enter ZIP Code'], .delivery-options li label[for='pickup']").each(function()
			{
				var $objThis = $(this);
				/* var $objMsgLayer = $(document.createElement("div")).addClass("dijitTooltipDialogLeft delivery-conf");
									Main Error Message Layer 
				var $objMsgSecondLayer = $(document.createElement("div")).addClass("dijitTooltipContainer");
									Second Inner Layer for Formatting 
				var $objMsgThirdLayer = $(document.createElement("div")).addClass("dijitTooltipContents dijitTooltipFocusNode");
									Third Inner Layer for Formatting 
				var $objMsgCloseButton = $(document.createElement("button")).attr("name", "close");
									Close Button for Popup 
				var aInputPos = $objThis.offset();
									Get Position of Closest Zip Code Input After Putting Focus to it */
			    
				if ($objThis.css("visibility") != "hidden" && !$objThis.is(":hidden") && $("input:checked", $objThis.parents(".delivery-options")).length <= 0)
				{
					var $objMsgLayer = $(document.createElement("div")).addClass("dijitTooltipDialogLeft delivery-conf");
					var $objMsgSecondLayer = $(document.createElement("div")).addClass("dijitTooltipContainer");
					var $objMsgThirdLayer = $(document.createElement("div")).addClass("dijitTooltipContents dijitTooltipFocusNode");
					var $objMsgCloseButton = $(document.createElement("button")).attr("name", "close");
					var aInputPos = $objThis.offset();
					
					/* If in a Store */
					if ($("#store_number").val() == "true")
					{
						$objMsgThirdLayer.append("<p>You must select a delivery method for all products in your cart in order to continue checkout.</p>");
					}
					else
					{
						$objMsgThirdLayer.append("<p>You must enter your ZIP code to view delivery options for your area.</p>");
					}
					
					/* Setup Close Button */
					$objMsgCloseButton.bind("click", function()
					{
					 $(".dijitTooltipDialogLeft").css("display", "none").remove();
					 showZipDevMsg();
					});

					$objMsgThirdLayer.append($objMsgCloseButton);
					
					/* Setup Inner Layer's of Message, and Add to Body */
					$("body").append($objMsgLayer.append($objMsgSecondLayer.append($objMsgThirdLayer)));
					
					$objMsgLayer.css(
					{
						"position" : "absolute",
						"display" : "block",
						"left" : (aInputPos.left + ($objThis.outerWidth() - 1)) + "px",
						"top" : (aInputPos.top - 37) + "px",
						"z-index" : "1000"
					});
				}
			});
			
			/* Clear All of the Button's Current Events, and Stop from Using Default Behavior */
			$("#cart-Continue-Checkout, #cart-Continue-Checkout-Avail").unbind("click").bind("click", function(objEvent)
			{
				objEvent.preventDefault();
			});
		});
	}
}

/* Defect 13813 - Fixes Dropdowns in Firefox on a Mac Which Require Extra Padding */
function fixMacFFDropDown()
{
	if (navigator.appVersion.indexOf("Mac") != -1)
	{
		if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1)
		{
			$("select").css("padding", "3px");
		}
	}
}

/* Defect 14552, 14414 - Fixes Masthead Buttons in Safari on a PC Which Has Visual Breaks */
function fixWinSafMastButton()
{
	/*var $objMastBtns = $("#find_a_store_btn, #mainSearch").css("padding-right", "14px !important");
									 Masthead Buttons */
	/*var strBrowserInfo = navigator.userAgent.toLowerCase();
									 User's Browser Information */
									
	if (navigator.appVersion.indexOf("Win") != -1)
	{
		var strBrowserInfo = navigator.userAgent.toLowerCase();
		
		/* Safari and Chrome Have the Same User Agent Information, Minus "Chrome" in the Description for Safari */
		if (/webkit/.test(strBrowserInfo) && !/chrome/.test(strBrowserInfo))
		{
			var $objMastBtns = $("#find_a_store_btn, #mainSearch").css("padding-right", "14px !important");
			$("span", $objMastBtns).css("top", "-2px");
			$("#search .search_form").css("width", "250px");
		}
	}
}

/* Hides Cart Protection Plan Selection Box While IT Fixes Redirect Issue  */
function hideCartEPPDropDown()
{
	var $objEPPDropDown = $("select.protection-plan");
								/* Access to Cart EPP Dropdown  */
								
	if ($objEPPDropDown.length > 0)
	{
		$objEPPDropDown.css("display", "none");
	}
}

function storeKiosk(){
	if(chkCookie('storeKiosk')){
		var inAssignedStore;
		var kioskInfo = $.makeArray(chkCookie('storeKiosk').split('|'));
		var storeNumber = kioskInfo[0];
		var startURL = kioskInfo[1];
		/* insert banner to return to start screen */
		$('<div id="kioskHome"><a href="'+startURL+'">I\'m finished.</a><br /><img src="/kiosk/images/empButton.png"></div>').css({
			'height':'30px',
			'margin':'10px',
			'position':'fixed',
			'text-align':'center',
			'width':'150px'
		}).prependTo('#container');
		/* determine if zipped to kiosk store */
		var thisStoreInfo = getStateAndZip();
		thisStoreInfo = thisStoreInfo.split(',');
		$.makeArray(thisStoreInfo);
		var currentStore = thisStoreInfo[2];
		if(storeNumber == currentStore){
			/* modify pickup instore messaging */
			/* detail page */
			if($('#ship-options .ship-options-pickup').length > 0){
				$('.ship-options-pickup').empty().html('<strong>Pick Up</strong> At Customer Service<span class="promo-text"> - Free</span>');
			}
			/* cart page */
			if($('#my-cart-contents').length > 0){
				$('#my-cart-contents tbody tr').each(function(i){
					var $thisRow = $(this);
					$thisRow.find('.delivery-options li label').each(function(){
						var isPickup = $(this).text();
						if(isPickup.indexOf('Pick Up') >= 0){
							$(this).empty().html('<strong>Pick Up</strong> At Customer Service<span class="promo-text"> - Free</span>');
						}												  
					});
				});
			}
			/* checkout page */
			if($('table.order-info').length > 0){
				$('table.order-info td, table.order-info th').each(function(){
					var thisTxt = $(this).text();
					if(thisTxt.indexOf('Pick Up') >= 0){
						var newTxt = thisTxt.replace('Pick Up In Store','Pick Up At Customer Service');
						$(this).text(newTxt);
					}
				});
			}
			/* order confirmation page */
			if($('table.order-info').length > 0){
				var isPickUp = false;
				$('table.order-info tbody tr').each(function(){
					var $rowInfo = $(this).html();
					if($rowInfo.indexOf('Pick Up In Store') >= 0){
						var newInfo = $rowInfo.replace('Pick Up In Store','Pick Up At Customer Service');
						$rowInfo.html(newInfo);
						isPickUp = true;
					}
				});
				if(isPickUp){
					$('<div>You Have Items You Must Pick Up At Customer Service</div>').css({
						'margin':'10px 0',
						'background':'#ffcc00',
						'height':'50px',
						'line-height':'50px',
						'padding-left':'10px',
						'font-weight':'bold',
						'text-align':'center'
					}).insertAfter('#one-column h1');
				}
			}
		}
	}
}

jQuery.parseQuery = function(qs,options) {
	var q = (typeof qs === 'string'?qs:window.location.search), o = {'f':function(v){return unescape(v).replace(/\+/g,' ');}}, options = (typeof qs === 'object' && typeof options === 'undefined')?qs:options, o = jQuery.extend({}, o, options), params = {};
	jQuery.each(q.match(/^\??(.*)$/)[1].split('&'),function(i,p){
		p = p.split('=');
		p[1] = o.f(p[1]);
		params[p[0]] = params[p[0]]?((params[p[0]] instanceof Array)?(params[p[0]].push(p[1]),params[p[0]]):[params[p[0]],p[1]]):p[1];
	});
	return params;
}

function addToMyProducts()
{
	if($('.add_to_favorites_pdp').length)
	{
		$addLink = $('.add_to_favorites_pdp');
		$addLink.bind('click',function(){
			$this = $(this);
			productInfo = $.parseQuery($this.attr('href'));
			locationInfo = $.parseQuery();

			favoritesData = {
				//URL : window.location.href, 
				langId: locationInfo.langId, 
				storeId:productInfo.storeId, 
				catalogId:productInfo.catalogId, 
				catEntryId_1:productInfo.catEntryId_1, 
				partNumber_1:productInfo.partNumber_1 
			};

			//console.dir(favoritesData);

			$.ajax({
				type : 'POST',
				dataType : 'json',
				url : '/AjaxFavoritesAddCmd',
				data : favoritesData,
				success : function(data){
					//console.log('in success');
					switch(data.error)
					{
						case 'duplicate':
							//console.log('in duplicate');
							window.myProducts_showDuplicateModal();
						break;
										
						case 'true':
							//console.log('in true');
							window.myProducts_showErrorModal();
						break;
						
						case 'false':
							//console.log('in false');
							window.myProducts_showSuccessModal();
						break;
					}
				},
				error : function(){}
			});
			
			return false;
		});
		
	//contextual help

	$('.mylowes_functions .close').live('click',function(){
		$('.mylowes_functions .active_modal').fadeOut(function(){
			$(this).remove();
		})
		return false;
	});

	$('.mylowes_contexthelp').bind('click',function(){
		$this = $(this);
		
		if(!$('.mylowes_modal.active_modal').length){
			$this.parent().parent().append('<div class="mylowes_modal active_modal"><div class="headline"><a href="" class="close">Close</a></div><div class="modal_content"></div></div>');
			$('.active_modal .modal_content').append('<p>Favorites are a quick way to track items you have purchased or plan to buy in the future. You can set Reminders to help you remember to buy items you may need on a regular basis.</p><a href="/webapp/wcs/stores/servlet/ContactUsCategoryFAQPageView?storeId=10151&catalogId=10051&faqId=56" class="learn-more">Learn More</a><img src="/images/mylowes/right-pointer.png" class="right-pointer"/>');
		
			$modal = $('.active_modal');
			$modal.fadeIn();
		
			$('body').bind('click',function(){
				if($('.mylowes_modal.active_modal').length)
				{
					$('.mylowes_modal.active_modal').fadeOut(function(){$(this).remove();});
				}
			})
		}else{
			$modal = $('.active_modal');
			$modal.fadeOut(function(){
				$(this).remove();
			});			
		}
		return false;
	})	
		
	}
}

window.positionFavoritesModal = function()
{
	//console.log('positionFavoritesModal');
	var pageWidth = $(document).width();
	var pageHeight = $(document).height();
	var viewportWidth = $(window).width();
	var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
	var halfWidth = viewportWidth/2;
	var halfHeight = viewportHeight/2;

	$('body').append('<div class="modal_cover"></div>');
	$('.modal_cover').css({width: pageWidth, height: pageHeight, zIndex: 50, backgroundColor: '#000000', position: 'absolute', left: 0, top: 0 }).animate({opacity: .5},function(){
		$('.active_modal:last').fadeIn('fast');
	});
	
	$('.active_modal:last .close').live('click',function(){
		$('.modal_cover').trigger('click');
		return false;
	})
	
	$('.modal_cover').live('click',function(){
		$('.active_modal:last').fadeOut('fast',function(){
			$('.active_modal:last').remove();

			$('.modal_cover').fadeOut('fast',function(){
				$(this).remove();
			});						
		});
		return false;
	});	
	
	$('body').append('<div class="mylowes_modal active_modal"><div class="headline"><h2>Add to Favorites</h2><a href="" class="close">Close</a></div><div class="modal_content">Saving...</div></div>');

	var $modalContent = $('.active_modal');				
	
	var leftPosition = ($modalContent.width()/2) - halfWidth;
	var topPosition = ($modalContent.height()/2) - halfHeight;
	
	$modalContent.css({left: (-leftPosition), top: 234});
	

}

window.myProducts_showSuccessModal = function()
{
	//console.log('myProducts_showSuccessModal');
	window.positionFavoritesModal();
	
	$modal = $('.modal_content');
	
	$modal.html('<div class="added_message"><p>This product has been added to your Favorites.</p></div>');
	$modal.append('<table class="product_summary"><tr><td style="padding-right: 15px;"><img src="'+$('#original-image').attr('src')+'" width="70" height="70"></td><td class="info"><strong>'+$('#prod-stats h1').text()+'</strong><br/>'+$('#item-info').text()+'</td></tr></table>');
	$modal.append('<h6>Notes (optional):</h6><form action=""><textarea name="product_notes" class="elastic_text">Click to add notes.</textarea><div class="note_actions"><a href="" class="button"><span>Save and Continue</span></a></div></form></div><a href="'+$('#nav-favorites').attr('href')+'" class="view_favorites">View Your Favorites</a>');
}

window.myProducts_showDuplicateModal = function()
{
	//console.log('myProducts_showDuplicateModal');	
	window.positionFavoritesModal();	
	$('.modal_content').html('<div class="error_message"><p>This item already exists in your Favorite list</p><a href=""></a></div>');	
}

window.myProducts_showErrorModal = function()
{
	//console.log('myProducts_showErrorModal');
	window.positionFavoritesModal();
	$('.modal_content').html('<div class="error_message"><p>An error has occured</p></div>');	
}

function taxRefundCardUpdates(){
	var $taxRefundCardTitle = $.trim($("#prod-info #prod-stats h1").text()),
	 $bulletList = $("#prod-view #prod-tabs .tab-content ul"),		
	 $amountDropdown = $("#giftcard-order form fieldset ol li ul"),
	 $gifCardOtherAmt = $("#giftcard-order form fieldset ol li#giftcard-other-amount"),
	 $rtRailGiftCardImage = $("#giftcard-order #giftcard-order-collateral #giftcard-occasion-img");
	 $breadcrumb = $("#breadcrumbs ul li.last");
	
	if($taxRefundCardTitle.length > 0 || $bulletList.length > 0 || $amountDropdown.length > 0  || $gifCardOtherAmt > 0 || $rtRailGiftCardImage.length > 0 || $breadcrumb > 0){
		if($taxRefundCardTitle == "LowesTax Refund Card"){
			$bulletList.replaceWith('<ul><li>Amounts from $500 to $4,000.</li><li>Cards available for purchase February 8, 2011 ? March 14th, 2011.</li><li>10% of the original card amount added back on your card March 18, 2011.</li><li>Cards mailed directly to you, free standard shipping.  No expiration date, no service fees.</li><li>View card demo video for details or see store.</li></ul>');
			$($amountDropdown).each(function(index){
				if (index == 1) {
				   $(this).css("display", "none");
				   return false; 
				}
			  });
			$breadcrumb.replaceWith('<li class="last">Lowe\'s&nbsp;Tax Refund Card</li>');
			 $gifCardOtherAmt.replaceWith('<li id="giftcard-other-amount" style="display: block;"><ul><li><label>$:</label></li><li><input type="text" value="" onfocus="highlight(this);" maxlength="4" size="3" class="tiny" id="gcAmount" name="gcAmount" style="width:30px;">.00<br><span class="fineprint" id="reminder">Enter an amount between $500 and $4000</span><br></li></ul></li>');
			$('#gcAmount').blur(function() {
  				 if($(this).val() < 500){
					 $(this).animate({backgroundColor: 'red'}, 100).animate({backgroundColor: '#fff'}, 100).val('');
					 $("#reminder").animate( {color: 'red'}, 500).animate({color: '#909090'}, 500).val('');
				 }
				 if($(this).val() > 4000){
					 $(this).animate({backgroundColor: 'red'}, 100).animate({backgroundColor: '#fff'}, 100).val('');
					 $("#reminder").animate({color: 'red'}, 500).animate({color: '#909090'}, 500).val('');
				 }
			});
			 $rtRailGiftCardImage.replaceWith('<a name="View Tax Refund Card Demo" title="View Tax Refund Card Demo" href="http://www.youtube.com/watch?v=9Fx2fpGXxMA" target="_blank"><img style="margin-left:1px;" alt="View Tax Refund Card Demo" src="/wcsstore/B2BDirectStorefrontAssetStore/images/gift-card/TaxCard1.jpg"></a>');
		}
	}
}
