/*
	Last Modified Date: 03/12/2010
	Modified By: R. Adams
	1.0 Release
*/

var guestReg;
var thisStoreID;
var thisLangID;
var thisCatID;
var thisRedirectURLAfterLogon;
//=============================================
$(document).ready(function(){
						   
	if(mastConfig){
		guestReg = mastConfig.registerType;
		thisStoreID = mastConfig.storeId;
		thisLangID = mastConfig.langId;
		thisCatID = mastConfig.catalogId;
	} else {
		guestReg = 'G';
		thisStoreID = '10151';
		thisLangID = '-1';
		thisCatID = '10051';
	}
    if(typeof(URLAfterLogon) == "undefined") {
		thisRedirectURLAfterLogon = 'TopCategoriesDisplayView';
	} else {
		thisRedirectURLAfterLogon = encodeURL(URLAfterLogon);
	}
	
	/* set date/time for print view */
	if($('#header-block #print-masthead #stamps')){
		var curTime;
		var curDate;
		var todaysDateTime = new Date();
		var curHour = todaysDateTime.getHours();
		var curMin = todaysDateTime.getMinutes();
		var month = todaysDateTime.getMonth()+1;
		var year = todaysDateTime.getYear();
		var day = todaysDateTime.getDate();
		var curAMPM;
		
		if (curHour >= 12){
			curHour -= 12;
			curAMPM = " PM";
		} else {
			curAMPM = " AM";
		}
		if (curHour == 0) {
			curHour = 12;
		}
		curTime = curHour + ":"+ ((curMin < 10) ? "0" : "") + curMin + curAMPM;
		if(day<10) {
			day = "0" + day;
		}
		if(month<10) {
			month= "0" + month;
		}
		if(year<1000) {
			year+=1900;
		}
		curDate = month+'/'+day+'/'+year;
		$('#header-block #print-masthead #stamps p:first').empty().append('Printed on  '+ curDate + ' at ' + curTime);
	}
	
	getWelcomeInfo();
	if($.browser.msie){
		setTimeout(chkStoreCookies,500);
		setTimeout(getCartInfo,500);
	} else {
		chkStoreCookies();
		getCartInfo();
	}
	setMyAccountLinks();
	clearMastInputs();
	//weeklyAdLink();
	emailSignUpFooter();
	/*removeClick(); */ 
	
	/* Global For Spring */
	if($('#spring-global-trigger').length > 0){
		$('#spring-global-trigger').attr('href','/pc_Lawn+Garden_4294936085_4294937087_');
	}
	/*if($.browser.mozilla){
		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){
					if($('.rotating_banner').length > 0){
						$('.rotating_banner').scrollable({size:1,clickable:false,speed:0,loop:true}).autoscroll({autoplay:true,interval:5000,autopause:true});
					}
				}
			}
		});
	}*
	
	var spring_timer;
	
	if($('#spring-global-trigger').length > 0){
		$('#spring-global-trigger').bind('mouseover', function() {
			if($('#spring-global-pop').hasClass('flag_set')) {
				clearTimeout(spring_timer);
			} else {
				spring_timer = setTimeout("toggle_spring_pop()",1000);
			}
		}).bind('mouseleave', function() {
			clearTimeout(spring_timer);
			if($('#spring-global-pop').hasClass('flag_set')) {
				spring_timer = setTimeout("toggle_spring_pop()",300);
			}
		}).bind('click', function(event) {
			clearTimeout(spring_timer);
			toggle_spring_pop();
			event.preventDefault();
		});
	}
	
	if($('#spring-global-pop').length > 0){
		$('#spring-global-pop').bind('mouseover', function(){
			clearTimeout(spring_timer);
		}).bind('mouseleave', function(){
			clearTimeout(spring_timer);
			if($('#spring-global-pop').hasClass('flag_set')) {
				spring_timer = setTimeout("toggle_spring_pop()",300);
			}
		});
	}
	* End: Global for Spring */
	
	check_screen_size();
});

/* Global For Spring */
function toggle_spring_pop() {
	if($('#spring-global-pop').hasClass('flag_set')) {
		$('#spring-global-pop').removeClass('flag_set').fadeOut();
	} else {
		$('#spring-global-pop').addClass('flag_set').fadeIn();
	}
}
/* End: Global For Spring */

function check_screen_size() {
	var win = $(window).width();
	
	if(win > 990 && win < 1020) {
		$('#container').width(win+'px');
	}
}

function encodeURL(strURL){
	// enconde the char '?'
	var result = strURL.replace('?', '%3F');
	// enconde all chars '&'
	result = result.replace(/&/g, '%26');
	// enconde all chars '='
	result = result.replace(/=/g, '%3D');	
	return result;
}
//=============================================
function setMyAccountLinks(){
	var linkBool;
	if(guestReg == 'G'){
		linkBool = 'true';
	} else {
		linkBool = 'false';
	}
	if($('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul').length > 0){
		$('#masthead #top-nav ul#cart-account li a#nav-my-account').attr('href','javascript:displayURL(\'UserAccountView?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'&state=P\',\'false\')');
		$('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul li a#nav-my-profile').attr('href','javascript:displayURL(\'UserAccountView?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'&state=P\',\''+linkBool+'\')');
		$('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul li a#nav-my-order').attr('href','javascript:displayURL(\'OrderStatusDisplay?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'\',\''+linkBool+'\')');
		$('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul li a#nav-my-rebates').attr('href','javascript:displayURL(\'MyRebatesDisplayView?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'\',\''+linkBool+'\')');
		$('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul li a#nav-my-credit-center').attr('href','javascript:displayURL(\'MyCreditCenterDisplayView?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'\',\''+linkBool+'\')');
		$('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul li a#nav-my-projects').attr('href','javascript:displayURL(\'MyProjectsDisplayView?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'\',\''+linkBool+'\')');
		$('#masthead #top-nav ul#cart-account ul.accountmenu li.subContainer ul li a#nav-my-subscriptions').attr('href','javascript:displayURL(\'UserSubscriptionView?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'\',\''+linkBool+'\')');
	}
}
//=============================================
function getCartInfo(){
	if($('#masthead #top-nav ul#cart-account li.my-cart span.cart-total').length > 0){
		if(chkCookie('SHOPPINGCART')){
			var cartInfo = chkCookie('SHOPPINGCART').split('|');
			var items = cartInfo[0];
			var total = cartInfo[1];
			$('#masthead #top-nav ul#cart-account li.my-cart span.cart-total').text(total +' ('+items+' items)');
		} else {
			$('#masthead #top-nav ul#cart-account li.my-cart span.cart-total').text('$0.00 (0 items)');
		}
		$('#masthead #top-nav ul#cart-account li.my-orders a').attr('href','OrderStatusDisplay?storeId='+thisStoreID+'&catalogId='+thisCatID);
		$('#masthead #top-nav ul#cart-account li.my-cart a').attr('href','OrderItemDisplay?storeId='+thisStoreID+'&catalogId='+thisCatID);
		$('#masthead #top-nav ul#cart-account li.checkout a').attr('href','CheckoutLinkRouting?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID);
	}
}
//=============================================
function getWelcomeInfo(){
	if($('#masthead #top-nav #salutation')){
		var welcomeMsg;
		var userStatus;
		var userURL;
		var acctStatus;
		var acctURL;
		// Variable that is added to end of URL
		var catDisplayURL;
		// Variable set by IT
		//if(typeof(redirectURLAfterLogon) == "undefined") {
		//	var redirectURLAfterLogon;
		//}
		if(!thisRedirectURLAfterLogon) {
			//catDisplayURL = 'StoreCatalogDisplay';
			catDisplayURL = 'TopCategoriesDisplayView';
		} else {
			catDisplayURL = thisRedirectURLAfterLogon;
		}
		//check to see if the firstName cookie exists
		if(chkCookie('firstName')){
			var custName;
			var custFirstName = chkCookie('firstName');
			// if the user's name is greater than 40 characters, truncate the name
			if(custFirstName.length >= 40){
				custName = custFirstName.substring(0,24)+'...';
			} else {
				custName = custFirstName;
			}
			acctStatus = 'Not You?';
			acctURL = '/webapp/wcs/stores/servlet/Logoff?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'&rememberMe=false&URL=TopCategoriesDisplayView';
			//check to see if the employee cookie is set
			if(chkCookie('userSegment') == 'Employee'){
				if (chkCookie('invalidUserSegment') != 'true') {
					welcomeMsg = 'Welcome ' + custName + ' <span class="user-type">- Employee</span>';
				} else {
					// this is an invalid user segment cookie, remove the 2 cookies
					document.cookie = 'invalidUserSegment=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
					document.cookie = 'userSegment=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';								
				}
			} else if(chkCookie('userSegment') == 'Realtor'){
				if (chkCookie('invalidUserSegment') != 'true') {				
					welcomeMsg = 'Welcome ' + custName + ' <span class="user-type">- Realtor</span>';
				} else {
					// this is an invalid user segment cookie, remove the 2 cookies
					document.cookie = 'invalidUserSegment=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
					document.cookie = 'userSegment=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
				}
			} else {
					welcomeMsg = 'Welcome ' + custName;
			}
		} else {
			welcomeMsg = 'Welcome to Lowe\'s';
			acctStatus = 'Register';
			acctURL = '/webapp/wcs/stores/servlet/UserRegistrationForm?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'&new=Y&URL='+catDisplayURL;
		}
		// determine if the user is logged in
		if(guestReg == 'R'){
			userStatus = 'Log Out';
			userURL = '/webapp/wcs/stores/servlet/Logoff?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'&URL=TopCategoriesDisplayView';
		} else {
			userStatus = 'Log In';
			userURL = '/webapp/wcs/stores/servlet/LogonForm?langId='+thisLangID+'&storeId='+thisStoreID+'&catalogId='+thisCatID+'&URL='+catDisplayURL;
		}
		$('#masthead #top-nav #salutation span.welcome').append(welcomeMsg);
		$('#masthead #top-nav #salutation #account-status').append(acctStatus).attr('href',acctURL);
		$('#masthead #top-nav #salutation #user-status').append(userStatus).attr('href',userURL);
		$('#masthead #top-nav #salutation').show();
	}
}
//=============================================
function chkCookie(name) {
	var labelName = name + '=';
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(labelName) == 0){
			return c.substring(labelName.length,c.length);
		}
	}
	return null;
}

//=============================================
function chkStoreZIP(cookie) {
	if(chkCookie(cookie)) {
		
		var cookie_info = chkCookie(cookie);
		var cookie_array = cookie_info.split('|');
		cookie_array[8].replace('\##', ',');
		
		store_name = cookie_array[0];
		store_number = cookie_array[1];
		distance_to_store = cookie_array[2]; // in miles
		store_zip = cookie_array[3];
		remote_store = cookie_array[4];
		local_delivery = cookie_array[5];
		store_address = cookie_array[6];
		store_city = cookie_array[7];
		store_hours = cookie_array[8].replace('\##', ',');
		store_phone = cookie_array[9];
		store_fax = cookie_array[10];
		
		return cookie_array;
	} 
}
//=======         Begin Updated Changes =============
//=============================================
/*var populateStoreListInfo = {
	populateStoreListInfoFunc:function(){

		chkStoreZIP("selectedStore1");
	
		if (mustRefreshStoreList() == false || $("#change-current-store").attr("class") == "GotZipInfo") {
			 return;
		}
	
		$("#change-current-store").attr("class", "GotZipInfo");
	
		dojo.require("wc.service.common");
		document.searchNearestStoresForm.zipCode.value = store_zip;
		wc.service.declare({
			id: "MHAjaxStoreSearch",
			actionId: "storeSearch",
			url: "AjaxStoreSearch",
			formId: "searchNearestStoresForm",
			successHandler: function(serviceResponse) {
				var storeList = serviceResponse.selectedLocalStoreBeanArray;
				setStoreListInfo(storeList);
			},
			failureHandler: function(serviceResponse) {
			}
		});                                         
		wc.service.invoke("MHAjaxStoreSearch");
	}
}*/
function mustRefreshStoreList(){
	var vStoreName = $('#masthead #my-store a.current-location').attr('title');
	var storeHasChanged = (vStoreName != store_name.replace("##", ","));

	var count=0;
	$('#masthead #my-store-change-store .content ul#additional-stores li').each(function(i){
		count++; 
	});
	var storeListIsEmpty = (count <= 1);

	return (storeHasChanged || storeListIsEmpty);
}
	
//=============================================
function setStoreListInfo(aStoreList) {
	var i = 2;
	var lastItem;
	/* Clear the actual additional stores info */
	$('#masthead #my-store-change-store .content ul#additional-stores li').each(function(i){
		if ($(this).attr('class') == "last") {
			lastItem = $(this).html();
		}
		//$(this).empty();
	});
	//	$('#masthead #my-store-change-store .content ul#additional-stores').empty();
	
	dojo.forEach(aStoreList, function(store){
		if (selectedStoreNumber != store['storeNumber']) {
			setStoreInfo(store, i);
			i++;
		}
	});	
	i = 0;

	

	$('#masthead #my-store-change-store .content ul#additional-stores').append('<li><a href="StoreLocatorDisplayView?storeId=10151&catalogId=10051">Enter A New Zip Code</a></li>');
	/* added to remove the first store */
	$('#masthead #my-store-change-store .content ul#additional-stores li:first').remove();
	/* end remove first store*/
	$('#masthead #my-store-change-store .content ul#additional-stores li:last').addClass('last');
	
	$('#masthead #my-store-change-store .content ul#additional-stores').append(lastItem);
	$('#masthead #my-store-change-store .content ul#additional-stores').append('</li>');

	
	$('#masthead #my-store-change-store .content a.more-info-link').each(function(i){
		$(this).bind('click',function(){
			var storeInfoUL = $(this).attr('id') + 'Info';
			if (storeInfoUL != 'selectedStore1Info') {
				if($('#masthead #my-store-change-store .content ul#'+storeInfoUL).hasClass('hidden')){
					$('#masthead #my-store-change-store .content ul#'+storeInfoUL).removeClass('hidden');
					$(this).text('Hide');
				} else {
					$('#masthead #my-store-change-store .content ul#'+storeInfoUL).addClass('hidden');
					$(this).text('More Info');
				}
			}
		});
	});

}
function setStoreInfo(aStore, aIndex) {
	var more_info_link = ''; /*'MastHeadStoreInfoView?storeId='+thisStoreID+'&catalogId='+thisCatID+'&selectedStoreNumber='+chkStoreZIP(this)[1];*/
	var thisStoreInfo = 
		'<li>Store Number: '+aStore['storeNumber']+'</li>'+
		'<li>'+aStore['addressLine1']+'</li>'+
		'<li>'+getStoreCityAndState(aStore['storeName'], aStore['city'])+' '+aStore['zipCode']+'</li>'+
		'<li>Phone: '+aStore['phoneNumber']+'</li>'+
		'<li>Fax: '+aStore['faxNumber']+'</li>'
		'<li>Hours: '+aStore['storeHours'].replace(/##/g, ',')+'</li>';
		
	$('#masthead #my-store-change-store .content ul#additional-stores').append(
		'<li><div class="col-a">'+aStore['storeName'].replace('\##', ',') + 
		'<br />('+aStore['distance']+' miles) <a id="selectedStore'+aIndex+'" class="more-info-link" href="#'+more_info_link+'">More Info</a><div>'+
		'<ul id="selectedStore'+aIndex+'Info" class="hidden">'+thisStoreInfo+'</ul></div></div>'+
		'<div class="col-b">'+
		'<a href="javascript:storeUpdate(document.storeUpdateForm,\''+
		    aStore['storeNumber']+'\',\''+aStore['addressLine1']+'\',\'\',\''+
		    aStore['city']+'\',\'\',\''+aStore['zipCode']+'\');" class="button-grey"><span>Shop This Store</span></a></div></li>');	
}
//=============================================
var selectedStoreNumber;
//=======	End Updated Change ================
//=============================================
function chkStoreCookies() {
	//----------------------------
	var cookies = ['selectedStore1', 'selectedStore2', 'selectedStore3', 'selectedStore4', 'selectedStore5'];
	var storeChangeTimeOut;
	var storeInfoTimeOut;
	//---------------------------
	$(cookies).each(function(i){
		if(chkCookie(this)){
			var arr_storeInfo = chkStoreZIP(this);
			var thisStoreInfo = '<li>Store Number: '+arr_storeInfo[1]+'</li><li>'+arr_storeInfo[6]+'</li><li>'+getStoreCityAndState(arr_storeInfo[0], arr_storeInfo[7])+' '+arr_storeInfo[3]+'</li><li>Phone: '+arr_storeInfo[9]+'</li><li>Fax: '+arr_storeInfo[10]+'</li><li>Hours: '+arr_storeInfo[8].replace(/##/g, ',')+'</li>';
			var more_info_link = ''; /*'MastHeadStoreInfoView?storeId='+thisStoreID+'&catalogId='+thisCatID+'&selectedStoreNumber='+chkStoreZIP(this)[1];*/
			// if the first store, populate the my-store link
			if(i == 0){
				//add store id to weekly ad link
				if($('.weekly-ad').length > 0){
					$('.weekly-ad').attr('href','http://lowes.shoplocal.com/lowes/default.aspx?action=entryflash&storeref='+arr_storeInfo[1]);
				}
				//store info for print mast
				if($('#header-block #print-masthead #my-store-info')){
					$('#header-block #print-masthead #my-store-info').empty().append(arr_storeInfo[0].replace('\##', ',')+'<br />Store Number: '+arr_storeInfo[1]+'<br />'+arr_storeInfo[6]+'<br />'+arr_storeInfo[7].replace('\##', ',')+' '+arr_storeInfo[3]+'<br />Phone: '+arr_storeInfo[9]+'<br />Hours: '+arr_storeInfo[8].replace(/##/g, ','));
				} 
				//
				$('#masthead #my-store-more-info .current-store').append(arr_storeInfo[0].replace('\##', ','));
				$('#masthead #my-store-more-info .content:first ul#current-store-info').append(thisStoreInfo);
				$('#masthead #my-store-more-info .content:last p a').attr('href','StoreLocatorDisplayView?storeId='+thisStoreID+'&catalogId='+thisCatID+'&site='+arr_storeInfo[1]+'');
				$('#masthead #my-store-change-store .content .current-store .col-a').append(arr_storeInfo[0].replace('\##', ',') + '<br />('+arr_storeInfo[2]+' miles) <a id="'+this+'" class="more-info-link" href="#'+more_info_link+'">More Info</a><div><ul id="'+this+'Info" class="hidden">'+thisStoreInfo+'</ul></div>');
				$('#masthead #my-store a.current-location').append(arr_storeInfo[0].replace('\##', ',')).attr('title',arr_storeInfo[0].replace('\##', ',')).bind('click',function(){
					storeInfoTimeOut  = setTimeout(function(){
						$('#masthead #my-store-more-info').hide();
					},5000);
					$('#masthead #my-store-more-info').show();	
					$('#masthead #my-store-change-store').hide();
				});
			} else {
				$('#masthead #my-store-change-store .content ul#additional-stores').append('<li><div class="col-a">'+arr_storeInfo[0].replace('\##', ',') + '<br />('+arr_storeInfo[2]+' miles) <a id="'+this+'" class="more-info-link" href="#'+more_info_link+'">More Info</a><div><ul id="'+this+'Info" class="hidden">'+thisStoreInfo+'</ul></div></div><div class="col-b"><a href="javascript:storeUpdate(document.storeUpdateForm,\''+arr_storeInfo[1]+'\',\''+arr_storeInfo[6]+'\',\'\',\''+arr_storeInfo[7]+'\',\'\',\''+arr_storeInfo[3]+'\');" class="button-grey"><span>Shop This Store</span></a></div></li>');
				
			}
			
		}
	});
	
	/*=== added as interim fix to change 'change store' link to go to store locator ====*/
	$('#change-current-store').attr('href','/StoreLocatorDisplayView?storeId=10151&catalogId=10051');
	/*=== end added code ====*/
	
	//-------------------------
	$('#masthead #my-store-change-store .content a.more-info-link').each(function(i){
		$(this).bind('click',function(){
			var storeInfoUL = $(this).attr('id') + 'Info';
			if($('#masthead #my-store-change-store .content ul#'+storeInfoUL).hasClass('hidden')){
				$('#masthead #my-store-change-store .content ul#'+storeInfoUL).removeClass('hidden');
				$(this).text('Hide');
			} else {
				$('#masthead #my-store-change-store .content ul#'+storeInfoUL).addClass('hidden');
				$(this).text('More Info');
			}
		});
	});
	//--------------------------
	$('#masthead #my-store a#change-store-options').bind('click',function(){
			storeChangeTimeOut = setTimeout(function(){
				$('#masthead #my-store-change-store').hide();
			},5000);
			console.log(($(this).position().left - 328)+'px');
			$('#masthead #my-store-change-store').show();
			$('#masthead #my-store-more-info').hide();
	});
	//--------------------------
	$('#masthead #my-store-change-store .topper a.close').bind('click',function(){
			$('#masthead #my-store-change-store').hide();			  
	});
	//--------------------------
	$('#masthead #my-store-more-info .topper a.close').bind('click',function(){
			$('#masthead #my-store-more-info').hide();			  
	});
	//--------------------------
	$('#masthead #my-store-more-info').bind('mouseenter',function(){
			clearTimeout(storeInfoTimeOut);					   
	}).bind('mouseleave',function(){
			storeInfoTimeOut  = setTimeout(function(){
			$('#masthead #my-store-more-info').hide();
		},1000);
	});
	//---------------------------
	$('#masthead #my-store-change-store').bind('mouseenter',function(){
			clearTimeout(storeChangeTimeOut);					   
	}).bind('mouseleave',function(){
			storeChangeTimeOut = setTimeout(function(){
			$('#masthead #my-store-change-store').hide();
		},1000);
	});
	//----------------------------
	
	if(chkCookie('selectedStore1')){

		$('#my-store').show();			 
	} else {

		$('#store-locator').show();
		$('#store-locator form#storeSearchForm #findMyStore').bind('click',function(){
			document.storeSearchForm.submit();						  
		});
	}

	//-----------------------------
}
//================================================
function clearMastInputs(){
	$('#header-block input[type=text]').each(function(i){
		var defaultInput = $(this).val();
		$(this).bind('focus',function(){
			if($(this).val() == defaultInput) {
				$(this).val('');
			}
		});
		$(this).bind('blur',function(){
			if($(this).val() == ''){
				$(this).val(defaultInput);
			}
		});
	});
$('#utility-content input[type=text]').each(function(i){
                var defaultInput = $(this).val();
                $(this).bind('focus',function(){
                        if($(this).val() == defaultInput) {
                                $(this).val('');
                        }
                });
                $(this).bind('blur',function(){
                        if($(this).val() == ''){
                                $(this).val(defaultInput);
                        }
                });
        });
}

//================================================
function weeklyAdLink(){
 /* var weekly = $('.weekly-ad');
	var href = weekly.attr('href');
	var curr_href = href.substring(href.length-4, href.length);
	
	
	var new_href = href.replace(curr_href, thisStoreID);
	weekly.attr('href', new_href);
	*/
}

//================================================
function emailSignUpFooter() {
	$('#email-sub-submit a.button-grey').bind('click', function(i) {
		i.preventDefault();
	});
}
//================================================
function refreshMHStoreInfo() {
      $('#masthead #my-store-change-store .content ul#additional-stores').empty();
      $('#masthead #my-store-more-info .current-store').empty();
      $('#masthead #my-store-more-info .content:first ul#current-store-info').empty();
      $('#masthead #my-store-change-store .content .current-store .col-a').empty();
      $('#masthead #my-store a.current-location').empty();
      chkStoreCookies();
}
//================================================
function getStoreCityAndState(storeName, storeCity) {
	if(storeName.indexOf('\##') > -1) {
		vResult = storeCity + ', ' + storeName.split('\##')[1];
	} else {
		vResult = storeCity;
	}		
	return vResult;
}
/*===================*/
function check_neg() {
 var obj = $('#giftcard-value');    /* Sets the 'obj' variable to the ID 'giftcard-value' */
 var value = parseInt($(obj).val());   /* Checks the value of the input field and turns it into a number */
 if(value<0) {        /* If that value is less than zero */
  value = value * -1;      /* Make that negative number positive number */
  $(obj).val(value);      /* Replace the value of the form field so the user will see it */
 }
}

function submit_gc_form() {
 var gc_msg = $('#gift-msg-txtarea').val(); /* Get the value of the textarea */
 var len = gc_msg.length;     /* Find that textareas text length */
 g_msg = gc_msg.replace(/[\n\r]+/g,'');  /* Regular Expression to find all spaces on a new line ... not functioning */
 if(len > 255) {        /* If greater than 255, shorten the message to 255 characters */
  gc_msg = gc_msg.substring(0,255);
 }
 check_neg();        /* Run the check_neg function */
 document.giftCardForm.submit();    /* Submit the form */
}

function removeClick() {
 var obj = $('#giftCardForm img');   /* Find the submit button image */
 var curr_btn = {
  width : obj.attr('width'),    /* Then find it's properties */
  height : obj.attr('height'),
  alt : obj.attr('alt'),
  src: obj.attr('src')
 }
 
 var new_btn = $('img')     /* Create a new button */
  .attr('src', 'http://www.lowes.com'+curr_btn.src)    /* Set the attributes to match the old button minus the onclick event */
  .attr('alt', curr_btn.alt)
  .bind('click', submit_gc_form);   /* Bind our own click event to run the submit_gc_form function */
 obj.replaceWith($(new_btn));    /* Replace the old object with the new object */
}