/**
 * Checkout
 */
function ckoutBreadCrumb() {
		if ($('ul.checkoutIndicator li').length == 8) {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_8step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '750px'
		 });
		}
		else if ($('ul.checkoutIndicator li').length == 7) {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_7step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '650px'
		 });
		}
		else if ($('ul.checkoutIndicator li').length == 6) {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_6step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '570px'
		 });
		}
		else if ($('ul.checkoutIndicator li').length == 5) {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_5step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '500px'
		 });
		}
		else if ($('ul.checkoutIndicator li').length == 4) {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_4step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '430px'
		 });
		}
		else if ($('ul.checkoutIndicator li').length == 3) {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_3step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '360px'
		 });
		}
		else {
		 $('ul.checkoutIndicator').css({
		  backgroundImage: 'url('+imagePath+'img/misc/checkout_indicator_status_2step.gif)',
		  backgroundPosition: '20px 0',
		  backgroundRepeat: 'no-repeat',
		  width: '280px'
		 });
		}
}

$.fn.dynamicPopup = function(settings) {
	var settings = $.extend({
		filename: 'default.html',
		contentname: '#popup',
		windowWidth: '300px',
		windowHeight: '100px',
		jsonFlag: false
	},settings);
	return this.each(function(){
		$(this).click(function(e){
			dynpop.ini(e, settings)
		});
	});
}

function pageDims(){
	var dims = {};
	if($.browser.msie){
		if($.boxmodel){
			dims.w = document.documentElement.clientWidth;
			dims.h = document.documentElement.clientHeight;
			dims.s = document.documentElement.scrollTop;
		}else{
			dims.w = document.body.clientWidth;
			dims.h = document.body.clientHeight;
			dims.s = document.body.scrollTop;
		}
	}else{
		dims.w = window.innerWidth;
		dims.h = window.innerHeight;
		dims.s = window.pageYOffset;
	}
	return dims;
}

var dynpop = { ini: 
	function(e, settings){
			$('#DHTMLwrap').add('#DHTMLcontent').remove();
			var w;
			var h;
			var dhtmlContent = '<div id="DHTMLwrap"></div><div id="DHTMLcontent"></div>';
			var dhtmlHeight = Number(settings.windowHeight.split('px')[0]);
			var dhtmlWidth = Number(settings.windowWidth.split('px')[0]);
		var pagesize = pageDims();
		var w = pagesize.w+20;
		var h = pagesize.h;
		var s = pagesize.s;
			if ($.browser.msie) {
				$("select").css("visibility", "hidden");
				$('body').append(dhtmlContent);
				$('#DHTMLwrap').bgiframe();
				$('#DHTMLwrap').css({
					position: 'absolute',
					top: (e.pageY+dhtmlHeight > (h+s)) ? (e.pageY - (((e.pageY+dhtmlHeight)-(h+s)))*1.3) : e.pageY,
				left: e.pageX,
				zIndex: '1000001',
					display: 'none'
				});
				$('#DHTMLcontent').css({
					position: 'absolute',				
					top:  (e.pageY) - 250,
				left: (e.pageX+dhtmlWidth>(w-50)) ? e.pageX - ((e.pageX+dhtmlWidth)-w) - 50 : e.pageX + 5,
					backgroundColor: '#fff',
				zIndex: '1000002',
					display: 'none'
				});
			}
			else {
				$('body').append(dhtmlContent);
				$('#DHTMLwrap').css({
					position: 'absolute',
					top: (e.pageY+dhtmlHeight > (h+s)) ? (e.pageY - (((e.pageY+dhtmlHeight)-(h+s)))*1.3) : e.pageY,
				left: e.pageX+dhtmlWidth>(w-75) ? (e.pageX - ((e.pageX + dhtmlWidth)-w)) - 75 : e.pageX,
				zIndex: '1000001',
					MozBorderRadius: '0px',
				  	WebkitBorderRadius: '0px',
					opacity: '0',
					filter: 'alpha(opacity=30)',
					display: 'none'
				});
				$('#DHTMLcontent').css({
					position: 'absolute',				
					top: (e.pageY+dhtmlHeight > (h+s)) ? (e.pageY - ((((e.pageY+dhtmlHeight)-(h+s)))*1.3)+5) : e.pageY+5,
				left: e.pageX+dhtmlWidth>(w-70) ? (e.pageX - ((e.pageX + dhtmlWidth)-w)) - 70 : e.pageX +5,
					backgroundColor: '#fff',
				zIndex: '1000002',
					display: 'none'
				});
			}
			if(settings.jsonFlag){
				$.getSearsCode = $.getJSON;
			}else{
				$.getSearsCode = $.ajax;
			}
			$.getSearsCode({
				url: settings.filename,
				cache: false,
				success: function(html){
					$('#DHTMLcontent').empty().append('<a href="javascript:;" title="Close Window" class="closeWin"></a>').append(html);
					if(typeof imagePath!='undefined' && imagePath!=null && imagePath!="") {
						$('.closeWin').css({height:'24px',width:'24px',position:'absolute',top:'15px',right:'15px',background:'url('+imagePath+'img/btn/close.gif) no-repeat'});
					} else {
						$('.closeWin').css({height:'24px',width:'24px',position:'absolute',top:'15px',right:'15px',background:'url(../img/btn/close.gif) no-repeat'});
					}
					$('#DHTMLcontent').find(settings.contentname).width(settings.windowWidth);
					$('#DHTMLcontent').find(settings.contentname).height(settings.windowHeight);
					if(!$.browser.msie){
					$('#DHTMLwrap').width($('#DHTMLcontent').width()+12);
					}
					else{
					$('#DHTMLwrap').width($('#DHTMLcontent').width()+12);
					}
					if(!$.browser.msie){
					$('#DHTMLwrap').height($('#DHTMLcontent').height()+12);
					}
					else{
					$('#DHTMLwrap').height($('#DHTMLcontent').height()+12);
					}		
					$('#DHTMLwrap').add('#DHTMLcontent').show('fast');
					$('.closeWin').click(function(){
						$('#DHTMLwrap').add('#DHTMLcontent').fadeOut('fast',function(){
							$(this).remove();
							if ($.browser.msie) {
								$("select").css("visibility", "");
							}
						});
					});
				}
			});
	}
}
$.fn.centerOnScreen = function(){
	var $this = this[0];
	var yScroll = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
	var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	var windowWidth  = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
	$($this).css({ top: +(yScroll+((windowHeight - $this.offsetHeight)/2)), left: +((windowWidth/2) - ($this.offsetWidth/2)) });
}

function changeThisPopUp(revSectionA, link){
	$(revSectionA).add(link).click(function(){
		curtainOverlay({trans:0.2,ajaxmodal:true,closeonclick:false,ajaxclass:'pa1Absolute'});
			if($('.pa1ModalRelative').length <= 0){
				var absolute = $('.pa1Absolute');
				$.ajax({
					url: 'popups/masterPopUp.html',
					cache: false,
					success: function(html){
						$(absolute).append(html).show().centerOnScreen();
						//Adjustments for WIDTH in IE
						if(!$.browser.msie){
							$('.pa1ModalAlpha2').width($('.pa1Modal').width()+25);
							$('.pa1Modal').height($('.pa1ModalAlpha2').height()-10);
						}
						else{
							$('.pa1ModalAlpha2').width($('.pa1Modal').width()+43);
							$('.pa1Modal').height($('.pa1ModalAlpha2').height()-10);
						}
					}
				});
			}
	});	
}

function displayPopUpContent(htmlPath){
	curtainOverlay({trans:0.2,ajaxmodal:true,closeonclick:false,ajaxclass:'pa1Absolute'});
	if($('.pa1ModalRelative').length <= 0){
		var absolute = $('.pa1Absolute');
		$.ajax({
			url: htmlPath,
			cache: false,
			success: function(html){
				$(absolute).append(html).show().centerOnScreen();
				//Adjustments for WIDTH in IE
				if(!$.browser.msie){
					$('.pa1ModalAlpha2').width($('.pa1Modal').width()+25);
					$('.pa1Modal').height($('.pa1ModalAlpha2').height()-10);
				}
				else{
					$('.pa1ModalAlpha2').width($('.pa1Modal').width()+43);
					$('.pa1Modal').height($('.pa1ModalAlpha2').height()-10);
				}
			}
		});
	}
}	

function changeThisWarning(revSectionA, link){
	$(revSectionA).add(link).click(function(){
		curtainOverlay({trans:0.2,ajaxmodal:true,closeonclick:false,ajaxclass:'pa1Absolute'});
			if($('.pa1ModalRelative').length <= 0){
				var absolute = $('.pa1Absolute');
				$.ajax({
					url: 'popups/pa1Warning.html',
					cache: false,
					success: function(html){
						$(absolute).append(html).show().centerOnScreen();
						//Adjustments for WIDTH in IE
						if(!$.browser.msie){
							$('.pa1ModalAlpha2').width($('.pa1Modal').width()+25);
							$('.pa1Modal').height($('.pa1ModalAlpha2').height()-10);
						}
						else{
							$('.pa1ModalAlpha2').width($('.pa1Modal').width()+43);
							$('.pa1Modal').height($('.pa1ModalAlpha2').height()-10);
						}
					}
				});
			}
	});
}

function curtainOverlay(params){
	if(!params.closing){										
		if(!params){
			var params = {};
			params.elm = 'body'; 
			params.trans = '0.8'; 
			params.color = '#2364AF'
			params.closing = false;
			params.ajaxclass = '';
			params.ajaxmodal = false;
			params.closeonclick = true;
			params.persistmodal = false;
			params.fade = true;
		};
		if(!params.elm){params.elm = 'body'};
		if(!params.trans){params.trans = '0.8'};
		if(!params.color){params.color = '#333'};
		if(!params.ajaxclass){params.ajaxclass = ''};
		if(params.ajaxmodal != false){params.ajaxmodal = true};
		if(params.closeonclick != false){params.closeonclick = true};
		if(params.persistmodal != false){params.persistmodal = true};
		if(params.fade != false){params.fade = true}
	};
	if(params.fade){
		$.fn.inmode = $.fn.fadeIn;
		$.fn.outmode = $.fn.fadeOut;
		var duration = 1000;
	}else{
		$.fn.inmode = $.fn.show;
		$.fn.outmode = $.fn.hide;
		var duration = 0;
	}
	$('#curtain').remove();
	if(params.persistmodal){
		$('#ajaxmodal').hide();
	}else{
		$('#ajaxmodal').remove();
	}
	if(params.closing){
		if($.browser.msie){
			$('body').css({overflow:''});
			//$('select').css({visibility:''});
		}else{
			$('html').css({overflow:''})
		}
	}
	var w = 0; var h = 0; var s = 0;
	if(!params.closing){
		if ($(params.elm).is('body')){
			if($.browser.msie){
				$('body').css({overflow:'hidden'});
				if($.boxmodel){
					w = document.documentElement.clientWidth;
					h = document.documentElement.clientHeight;
					s = document.documentElement.scrollTop;
				}else{
					w = document.body.clientWidth;
					h = document.body.clientHeight;
					s = document.body.scrollTop;
				}
			}else{
				$('html').css({overflow:'hidden'});
				w = window.innerWidth;
				h = window.innerHeight;
				s = window.pageYOffset;
			}
		}else{
			w = $(params.elm).width();
			h = $(params.elm).height();
			s = $(params.elm).offset().top
		}
		var curtain = $('<div id="curtain"/>').css({
			position:	'absolute',
			display:	'none',
			zIndex:		1000000,
			top:		s,
			left:		$(params.elm).offset().left,
			width:		"100%",
			height:		Sears.getWindowSize().pageHeight,
			background:	params.color,
			opacity:	params.trans
		}).appendTo('body');
		
		if($.browser.msie){ 
				//curtain.bgiframe()
				curtain.css({ filter:'alpha(opacity='+(params.trans * 100)+')'}).show();
		}else{
			curtain.show();
		}
		if(params.ajaxmodal){
			if(params.persistmodal){
				if($('#ajaxmodal').length > 0){
					$('#ajaxmodal').fadeIn(1000);	
				}else{
					$('#ajaxmodal').remove();
					$('<div id="ajaxmodal" class="'+params.ajaxclass+'"/>').css({display:'none'}).insertAfter('#curtain').inmode(duration);
					//$('#ajaxmodal').show().centerOnScreen();
				}	
			}else{
				$('#ajaxmodal').remove();
				$('<div id="ajaxmodal" class="'+params.ajaxclass+'"/>').css({display:'none'}).insertAfter('#curtain').outmode(duration);
				//$('#ajaxmodal').centerOnScreen();
			}
		}		
		if(params.closeonclick){
			curtain.unbind().click(function(){
				curtainOverlay({closing:true});
			});
		};
	};
};

$.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;
};

//G(02-18)
function addPaymentTypeEvents(){

	//$("#savedCardRadio").attr("checked", "checked");
	$("#assocDiscId").css("display", "none");
	
	$("#savedCardRadio").click(
		function(event){
			if($(this).attr("checked") == true){
				$("#tbl_paycard").css("display", "none");
				$("#tbl_savedcard").css("display", "");
									
			}					 
		}				
	);
	
	if(typeof document.getElementById("checkAssociate") != 'undefined' && document.getElementById("checkAssociate") != null && document.getElementById("checkAssociate").value=='Y'){
	if(document.getElementById("existingcCard")!= 'undefined' && document.getElementById("existingcCard") != null){
		//alert('a');
		if($("#savedCardRadio").attr("checked") == true){
			var savedCard=document.getElementById("existingcCard");
			var optionValue = $(savedCard).val();
			var valueArray = optionValue.split('|', 1);
			
			if(valueArray != "" && valueArray != "Sears Gold MC" && valueArray != "SearsPlus")
	{
  	$("#assocDiscId").css("display", "");
	}
	else
	{ 									
	$("#assocDiscId").css("display", "none");
	}
					  
								}
		$("#existingcCard").change(function(){
		//alert('b');
			var savedCard=document.getElementById("existingcCard");
			var optionValue = $(savedCard).val();
			var valueArray = optionValue.split('|', 1);
			if(valueArray != "" && valueArray != "Sears Gold MC" && valueArray != "SearsPlus")
			{ 									
  	$("#assocDiscId").css("display", "");
	}
	else
	{  
	$("#assocDiscId").css("display", "none");
	}
					  
								})	;
								}
			}					 
	
	
	
	$("#newCardRadio").click(
		function(event){
			if($(this).attr("checked") == true){
				$("#tbl_paycard").css("display", "");
				$("#tbl_savedcard").css("display", "none");
				$("#assocDiscId").css("display", "none");
				
				if(typeof document.getElementById("checkAssociate") != 'undefined' && document.getElementById("checkAssociate") != null && document.getElementById("checkAssociate").value=='Y')
					{
						$("#paymentType").change(function(){
						var pay=document.getElementById("paymentType").value;
						var payType=pay.split("|",1);
						if(payType != "" && payType != "Sears Gold MC" && payType != "SearsPlus")
						{ 									
					  		$("#assocDiscId").css("display", "");
			}
						else
						{  
							$("#assocDiscId").css("display", "none");
		}
									  
						});
					}
			}
		}
	);
}

function addEditExpirationDateEvents()
{	var hideFunc=function(){
			var style=$("#ccEditable").css("display");
			if (style == "none") {
				$("#ccEditable").css("display", "block");
				$("#editExpDateLink").css("display", "none");
			}else
			{	$("#ccEditable").css("display", "none");
				$("#editExpDateLink").css("display", "block");	
			}			
		}	
	
	$('#updateExpDate').click( function() {		
		var d = new Date();
		var curr_month = d.getMonth();
		curr_month++;
		var curr_year = d.getFullYear();		
		
		if ( ($('select#cYear').val() == curr_year) && ($('select#cMonth').val() < curr_month) ) {
			$('#editError').show();	
		}else if(($('select#cYear').val() == curr_year+10) && ($('select#cMonth').val()>curr_month)){
			$('#editError').show();	
		} else {
			$('#ccEditable').hide();
			$('#editError').hide();
			$('#editingExpDate').html('Expires ' + $('select#cMonth').val() + '/' + $('select#cYear').val() + '<a href="javascript:;">edit expiration date</a>' );
			$('#editingExpDate').show();
			$('#editingExpDate a').click( function() {
				$('#editingExpDate').hide();
				$('p#ccEditable').show();
			});
		}
	});
	$('#expCncl').click( function() {
		$('p#ccEditable').hide();
		$('#editingExpDate').show();
	});
	
	$('#editingExpDate a').click( function() {
		$('#editingExpDate').hide();
		$('p#ccEditable').show();
	});
	
}

function shipRadioBtnClassSwitcher() {
	var shipRadios = $('div.shippingMethodWrapper div.item div.addAndMethod div.method label input');
	$(shipRadios).click(function(){
		$(this).parent().parent().each(function(i){$(this).children().removeClass('selected');})
		$(this).parent().addClass('selected');
	});
}



function inp_btn__click(event){
	$("#tbl_addresses input[type=button]").attr("class","btn_unselected");
	$("#tbl_addresses input[type=button]").removeAttr("disabled");
	
	$(this).attr("class","btn_selected");
	$(this).attr("disabled","disabled");
	
	$("#tbl_addresses tr").attr("class", "unselected");
	$(this).parents("tr").removeAttr("class");
	
	$("#a_showSavedAddresses").click();
}

function htmlElement_slideFinish(event){
}

var isHide = false;
function a_showSavedAddresses_click(event){
	var STR_LABEL_POST = " My Saved Adresses";
	if(!isHide){
		$(this).html("Hide" + STR_LABEL_POST);
		$("#tbl_addresses tr").fadeIn("fast", htmlElement_slideFinish);
		isHide = true;
		$('p.expressCheckout').hide();
	}else{
		$(this).html("Show" + STR_LABEL_POST);
		$("#tbl_addresses tr[class='unselected']").fadeOut("fast");
		isHide = false;
		$('p.expressCheckout').show();
	}
}

function addAddAddressStyleEvents()
{	
	f = function(){
		if($(this).hasClass("address_collapse")){
			$(this).addClass("address_expanded");
			$(this).removeClass("address_collapse");
		}else{
			$(this).addClass("address_collapse");
			$(this).removeClass("address_expanded");
		}
	};

	$("#newAddressLink").click(f);
	$("#useGiftCard").click(f);
	$("#useCoupon").click(f);
	
	$("#a_showSavedAddresses").click(a_showSavedAddresses_click);
	$("#tbl_addresses input[type=button]").click(inp_btn__click);
	
	$("#img_editAddress").unbind('click').click(
		function(){
		   $("#newAddressLink").click();
		}
	);

	
	$("#newAddressLink").click(function(){
		if($("#newAddressForm").css("display") == "none") {
			$("#newAddressForm").fadeIn("slow");
			$("#pleaseNoteId").css("display", "block");
		} else {
			$("#newAddressForm").fadeOut("slow");
			$("#pleaseNoteId").css("display", "none");
		}
	 });
	
	$("#useCoupon").click(function(){
		if($("#div_cards").css("display") == "none")
			$("#div_cards").fadeIn("slow");
		else 
			$("#div_cards").fadeOut("slow");
	 });
	
	 $("#preferredNumber").click(function() {
        if ($("#div_preffered_number").css("display") == "none")
            $("#div_preffered_number").fadeIn("slow");
        else
            $("#div_preffered_number").fadeOut("slow");
     });
     
	$("#useGiftCard").click(function(){
		if($("#div_gifcards").css("display") == "none")
			$("#div_gifcards").fadeIn("slow");
		else 
			$("#div_gifcards").fadeOut("slow");
									 });
}

var isOutOfStock = false;
//var selectThisStore = function(exceptionWindowFlag){
function selectThisStore(exceptionWindowFlag){
	//void changeThisPopUp($('#a_link_1'), $('td.per a'));
	//void changeThisPopUp($('#a_link_2'), $('td.per a'));
	void changeThisPopUp($('#a_link_3'), $('td.per a'));
	
//	$(".select_this_store").click(function(){
		if(exceptionWindowFlag=="Y"){
			isOutOfStock = true;
			//Omniture tracking.
            if (typeof omPrefix != 'undefined') {
            	if (omPrefix != null && omPrefix != "") {
            		omPrefix = omPrefix + ' > ' + 'Out of Stock Modal';
            	}
            }
		}else {
			isOutOfStock = false;
			//Omniture tracking.
            if (typeof omPrefix != 'undefined') {
            	if (omPrefix != null && omPrefix != "") {
            		omPrefix = omPrefix + ' > ' + 'In Stock Modal';
            	}
            }
		}
		if (typeof s != 'undefined') {
			s.t();
		}
		if(isOutOfStock){
			$('.pop_up .outStock').show();
			$('.pop_up .inStock').hide();
		} else {
			$('.pop_up .outStock').hide();
			$('.pop_up .inStock').show();
		}
		$(".pop_up").show().centerOnScreen();
//	});
	$("a.goBackSelectAnother").click(function(){
		$(".pop_up").hide();
	});
	$(".pop_up > .close > a").click(function(){
		$(".pop_up").hide();
	});
	$('.pop_up .someone_else input.check').eq(0).click(function(){
		if($(this).is(':checked')){
			$('.someone_else .thirdPUForm').show();
		}else{
			$('.someone_else .thirdPUForm').hide();
		}
	});
	
	$('li.exceptionItem p.shipRemove input').click(function(){
		$(this).parent().find('label.strong').removeClass('strong');
		$(this).next().addClass('strong');
	});
}


function addEventsToChangeThis(){
$(".changethis").click(
	   function (){
		   displayPopUpContent("popups/pa1Warning.html");
   });
}

function continueCheckoutEvent(){
	$(".btn_continue_checkout").click(
	  function(event){
//			 displayPopUpContent("popups/continueCheckoutPopup.html");
		});
}

function countdown(){
	var textArea = $('div.instructions textarea');
	var text = 'Example: "S. of Main, E. of North Ave." or "Please leave at back door."';
	$(textArea).val(text);
	$(textArea).focus(function(){
		if($(this).val() == text){
			$(this).val('');
		}
	}).blur(function(){
		if ($(this).val() == '') {
			$(this).val(text).css({color:'#c1c1c1'});
		}
	});
	
	$(textArea).keyup(function(){
		var count = $('div.instructions div.characters span#count');
		var startNum = 110;
		var textAreaValue = $(textArea).val().length;
		$(this).css({color:'#000'});
		$(count).html(startNum - textAreaValue);
		if (textAreaValue >= 110){
			$(count).html('0');
			$(this).val($(this).val().substring(0, startNum));
		}
	});
}

function autoCalendar(){
	if (document.ScheduleForm) {
		var storeId = document.ScheduleForm.storeId.value;
		var calendarIcon = $('#a_calendaricon');
		var calendarInput = $('div.dateTime div.calendar input.ScheduledDate');

		//user clicks the calendar icon
		var pickUpStoreId = document.ScheduleForm.pickStoreId.value;

		if(pickStoreIdExist != pickUpStoreId)
		{
			ajaxCallForScheduleCalendar(pickUpStoreId);
		}
			$(calendarIcon).click(
				function(){
					if(startDate != ''){
						curtainOverlay({trans:0,color:'transparent',ajaxmodal:true,closeonclick:false,ajaxclass:'autoScheduleThingy'});
						$("select").css("visibility", "hidden");
						ajaxCalendar();
					}
				}
			);
			//user puts focus on the input field
			$(calendarInput).focus(
				function(){
					if(startDate != ''){
						document.getElementById("ScheduledTime").focus();
						curtainOverlay({trans:0,color:'transparent',ajaxmodal:true,closeonclick:false,ajaxclass:'autoScheduleThingy',persistmodal:true});
						var absolute = $('.autoScheduleThingy');
						$("select").css("visibility", "hidden");
						ajaxCalendar();
					}
				}
			);
			
			function ajaxCalendar(){
				var err = document.getElementById("errorBox");
				err.style.display='none';
				var selectedDate =document.getElementById('ScheduledDate').value;
				if("Date"==selectedDate)
				{
					selectedDate="";
				}
				
				//$('#ScheduledDate').val('');
				if($('.scheduleRelative').length <= 0){
					var absolute = $('.autoScheduleThingy');

					$.ajax({
						url: '/shc/s/AppointmentCalendarView?holidays='+storeHolidayList+'&firstDate='+startDate+'&storeId='+storeId+'&selectedDate='+selectedDate,						
						cache: false,
						success: function(data){							
							$(absolute).append(data).show().centerOnScreen();
						}
					});
				};
			};
	}
}

function loginSwitch() {
	var loginPage = $('div#content');
	var right1 = $('div#loginEnhancedRgt');
	var right2 = $('div#loginEnhancedRgt2');	
	var caseMsg = $('span.caseSensitive');
	var link = $('div#content p.acct a');
	$(link).click(function(){	
		if ($(loginPage) && $(this).text() == 'Register now') {
			$(right2).add(caseMsg).hide();
			$(right1).fadeIn('fast', function(){$(this).show();});
		}
		if ($(loginPage) && $(this).text() == 'Log in') {
			$(right2).fadeIn('fast', function(){$(this).add(caseMsg).show();});
			$(right1).hide();
		}
		else {return false;}
	});
}

function controlSendMeText(){
	$("#chk_sendme_sms").attr("checked",false);
	$("#chk_phncall").attr("checked",false);
	
	$("#chk_sendme_sms").click(function(){
	var textMessageFlag = document.getElementById('textMessageFlag');
		if($("#chk_sendme_sms").attr("checked")==true){
			$("#sendMeText").fadeIn("low");
			$("#carrier_and_coupon").show();
			if($("#chk_phncall").attr("checked")==true){
				$("#sendMeBoth").show();
				$("#sendMeTextMessage").hide();
				$("#sendMeCall").hide();
			}
			else{
				$("#sendMeTextMessage").show();
				$("#sendMeCall").hide();
				$("#sendMeBoth").hide();
			}
			textMessageFlag.setAttribute('value', true);
		}
		else{
			textMessageFlag.setAttribute('value', false); 
			if($("#chk_phncall").attr("checked")==true){
				$("#sendMeText").fadeIn("low");
				$("#sendMeTextMessage").hide();
				$("#sendMeCall").show();
				$("#carrier_and_coupon").hide();
				$("#sendMeBoth").hide();
			}
			else{
				$("#sendMeText").hide();
				$("#sendMeTextMessage").hide();
				$("#sendMeCall").hide();
				$("#sendMeBoth").hide();
			}
		}
	});
	$("#chk_phncall").click(function(){
	var phoneCallFlag = document.getElementById('phoneCallFlag');
		if($("#chk_phncall").attr("checked")==true){
			phoneCallFlag.setAttribute('value', true);
			$("#sendMeText").fadeIn("low");
			if($("#chk_sendme_sms").attr("checked")==true){
				$("#sendMeTextMessage").hide();
				$("#sendMeCall").hide();
				$("#sendMeBoth").show();
				$("#carrier_and_coupon").show();
			}
			else{
				$("#sendMeTextMessage").hide();
				$("#sendMeCall").show();
				$("#sendMeBoth").hide();
				$("#carrier_and_coupon").hide();
			}
		}
		else{
			phoneCallFlag.setAttribute('value', false);
			if($("#chk_sendme_sms").attr("checked")==true){
				$("#sendMeText").fadeIn("low");
				$("#sendMeTextMessage").show();
				$("#sendMeCall").hide();
				$("#sendMeBoth").hide();
				$("#carrier_and_coupon").show();
			}
			else{
				$("#sendMeText").hide();
				$("#sendMeBoth").hide();
				$("#sendMeTextMessage").hide();
				$("#sendMeCall").hide();
			}
		}
	});
}



//Password Help DHTML Layer occurs on focus of the "password" field 5/14/08 - JR
function passwordHelp(){
	var helpHTML = '<div id="passwordHelp">\n'
	helpHTML += '	<h1>Password Guidelines</h1>\n'
	helpHTML += '	<dl>\n'
	helpHTML += '		<dt>Your password must contain 6 different (case-sensitive) characters and meet the following requirements:</dt>\n'
	helpHTML += '		<dd>At least one letter</dd>\n'
	helpHTML += '		<dd>At least one number</dd>\n'
	helpHTML += '		<dd>No spaces</dd>\n'
	helpHTML += '		<dd>No ! or ?</dd>\n'
	helpHTML += '		<dd class="passDisclaimer">This pop-up window will disappear once you&rsquo;ve entered your password.</dd>\n'
	helpHTML += '	</dl>\n'
	helpHTML += '</div>\n'
	var passField = $('input#password');	
	

//Everything else
	if ($('div.col_left div.content_section' | 'div#col_right div#loginEnhancedRgt')) {
		$(passField).focus(function(){
			$(helpHTML).remove();
			$(helpHTML).css({
				top: $(this).offset().top - 55,
				left: $(this).offset().left - 270
			}).appendTo('body');
			$('#passwordHelp').show('fast');
		});
		
		$(passField).blur(function(){
			$('#passwordHelp').fadeOut('fast', function(){
				$(this).remove();
			});
		});
	}
}



/*
 Paymethods switcher -  wrap content in a div with a class titled payMethods.
So that the input & label show at all times wrap them in a span with a class titled payOption
6/16/09 KL
*/

function paymentMethod() {	
	/*Default state on page load*/
	$('div.payMethods').children().not($('.payOption')).hide();
	//$('input#creditMethod').attr("checked","checked");
	if ($('input#creditMethod').is(':checked')) {
		$('div#crdtPayOpts').show();
		if ($('input#savedCardRadio').is(':checked')) {
			$('p#creditIntro,p.radio_box_p,table#tbl_savedcard').show();
			$('div#expChkOpt').show();
		} 
		if ($('input#newCardRadio').is(':checked')) {
			$('p#creditIntro,p.radio_box_p,table#tbl_paycard').show();
		} 
	}
	$('span.payOption input').click( function() {
		$('div.payMethods').children().not($('.payOption')).hide();
		/*crdt card table not children node of the #creditMethod PayMethods, thus
		 wrapped in in div#crdtPayOpts and call hide and show on the div*/
		if ($('input#creditMethod').is(':checked')) {
			$(this).parents('div.payMethods').children().fadeIn();
			$('div#crdtPayOpts').fadeIn();
			if ($('input#savedCardRadio').is(':checked')) {
				$('table#tbl_paycard').hide();
				$('div#expChkOpt').show();
			} 
			if ($('input#newCardRadio').is(':checked')) {
				$('table#tbl_savedcard').hide();
				$('div#expChkOpt').hide();
			} 
		} else {
			$(this).parents('div.payMethods').children().fadeIn();
			$('div#crdtPayOpts').hide();
			$('div.checkout div#cCardWrapper #specialFinanceDIV').hide();
			document.getElementById("paymentType").value = "";
}
		
	});
}
$(paymentMethod);

function ebillWinPop() {
 $('p#ebillLearn a').click( function() {
		window.open('https://about.ebillme.com/index.php/about/sears','eBillMe','menubar=no,location=no,scrollbars=yes,status=no,width=540,height=800,resizable=yes');
	});
}
$(ebillWinPop);


$(function(){
	// IE6 image flicker caching problem, for sprite Arrows
	try {
    	document.execCommand("BackgroundImageCache", false, true);
	}catch(err){
	}

	void addEditExpirationDateEvents();
	void addAddAddressStyleEvents();
	void ckoutBreadCrumb();
	void countdown();
	void autoCalendar();
	void loginSwitch();
	void addPaymentTypeEvents();
	
	void shipRadioBtnClassSwitcher();
	
	//void continueCheckoutEvent();
	paymentMethod();
	void passwordHelp();
	/*
	$('#a_whatsthis').dynamicPopup({filename: 'popups/delivery_seeLocations.html',contentname: '.gcPleaseNote',windowWidth: '580px',windowHeight: '315px'}); //HTML
	$('#a_sendemail').dynamicPopup({filename: 'popups/delivery_whatsIncluded.html',contentname: '.gcPleaseNote',windowWidth: '300px',windowHeight: '315px'});
	$('#a_seeLocations').dynamicPopup({filename: 'popups/delivery_seeLocations.html',contentname: '.gcPleaseNote',windowWidth: '300px',windowHeight: '315px'});
	*/
	
	//Change Zip Code Functionality
	$('.zip a').click(function(){
		$(this).hide();
		$('span.newZip').show();
		$('.addStores').css('margin-top', '15px');
		$('.zip input.image').click(function(){
			$('span.newZip').hide();
			$('.zip a').show();
			$('.addStores').css('margin-top', '10px');
		});
	});
	
	
	
	//"Store Details" Modal Window Functionality
	$('a.storeDetails').each(function(){
		$(this).click(function(e){
			var i = $('a.storeDetails').index(this);
			var wrap = $('.modalWrap').eq(i);
			var content = $('.modalContent').eq(i);
			$('.modalWrap').hide();
			$('.modalContent').hide();
			$(content).show().css('top', e.pageY).css('left', (e.pageX - 70));
			var modalContentH = $(content).height();
			$(wrap).show().css({'top' : (e.pageY - 5),'left' : (e.pageX - 75), 'height' : (modalContentH + 10)});
			$('.modalContent a.closeWin').click(function(){
				$(wrap).hide();
				$(content).hide();
			});
			$(this).blur(function(){
				$(wrap).hide();
				$(content).hide();
			});
		});
	});
	//Reserve And Pay changes
	//"Store Details" Modal Window Functionality
	$('a.myStoreDetails').each(function(){
		$(this).click(function(e){
			var i = $('a.myStoreDetails').index(this);
			var wrap = $('.modalWrap').eq(i);
			var content = $('.modalContent').eq(i);
			$('.modalWrap').hide();
			$('.modalContent').hide();
			$(content).show().css('top', e.pageY).css('left', (e.pageX - 70));
			var modalContentH = $(content).height();
			$(wrap).show().css({'top' : (e.pageY - 5),'left' : (e.pageX - 75), 'height' : (modalContentH + 10)});
			$('.modalContent a.closeWin').click(function(){
				$(wrap).hide();
				$(content).hide();
			});
			$(this).blur(function(){
				$(wrap).hide();
				$(content).hide();
			});
		});
	});
	
	//"More Info" Modal Window Functionality
	$('table.pick_up td a.moreInfo').each(function(){
		$(this).click(function(e){
			var type = $(this).parent().attr('class');
			if(type == 'in'){
				var tempModal = '<div id="tempWrap" class="modalWrap"></div><div id="tempContent" class="modalContent"><a class="closeWin" title="Close Window" href="javascript:;" >close</a><p><strong>More Info - In Stock</strong>Generally, when an item is listed as "In Stock", it means that as of the last time the system was polled, the item was listed as being on the shelf.</p></div>';
			}else if(type == 'out'){
				var tempModal = '<div id="tempWrap" class="modalWrap"></div><div id="tempContent" class="modalContent"><a class="closeWin" title="Close Window" href="javascript:;" >close</a><p><strong>More Info - Out of Stock</strong>This item is not currently in stock at the above store; future availability cannot be determined at this time.</p></div>';
			}else if(type == 'soon'){
				var tempModal = '<div id="tempWrap" class="modalWrap"></div><div id="tempContent" class="modalContent"><a class="closeWin" title="Close Window" href="javascript:;" >close</a><p><strong>More Info - 3-5 days</strong>When this item arrives at your selected store, you\'ll recieve an e-mail message that it\'s ready to be picked up.</p></div>';
			}else if(type == 'dealer'){
				var tempModal = '<div id="tempWrap" class="modalWrap"></div><div id="tempContent" class="modalContent"><a class="closeWin" title="Close Window" href="javascript:;" >close</a><p><strong>More Info - Out of Stock</strong>Unfortunately, this item is unlikely to be restocked at this location.</p></div>';
			}else{
				var tempModal = '<div id="tempWrap" class="modalWrap"></div><div id="tempContent" class="modalContent"><a class="closeWin" title="Close Window" href="javascript:;" >close</a><p><strong>More Info - Out of Stock</strong>Unfortunately, this item is unlikely to be restocked at this location.</p></div>';
			}
			$('body').append(tempModal);
			var wrap = $('#tempWrap');
			var content = $('#tempContent');
			$('.modalWrap').hide();
			$('.modalContent').hide();
			$(content).show().css('top', e.pageY).css('left', (e.pageX - 70));
			var modalContentH = $(content).height();
			$(wrap).show().css({'top' : (e.pageY - 5),'left' : (e.pageX - 75), 'height' : (modalContentH + 10)});
			$('.modalContent a.closeWin').click(function(){
				$(wrap).remove();
				$(content).remove();
			});
			$(this).blur(function(){
				$(wrap).remove();
				$(content).remove();
			});
		});
	});
	
	
});
		
//Opens "Add a new address" on Delivery/Shipping pages
function newAddressOpen(){
	$(".content_section .button").click(function(){
		$("#editAddressForm").fadeIn("slow");
		$("#newAddressForm").attr("style", "display:none;");
	})
}

function newAdressClose(){
	$(".arrow_horz").click(function(){
		if($("#newAddressForm").attr('style').indexOf("none") != -1){						
			$("#newAddressForm").fadeIn("slow");
		} else {
			$("#newAddressForm").fadeOut("slow");
		}
		$('#editAddressForm').attr('style', 'display:none;');
	})
}



function selectUnselectRadiosOnAddresses(){
	function unselect(){
		$(".address_book .active").attr("class", "");	
	}
	unselect();
	$(".address_book input[type=radio][checked]").parents("tr").attr("class", "active");
	$(".address_book input[type=radio]").click(function(){
														unselect();
													   	$(this).parents("tr").attr("class", "active");
												   });
}

function viewHideAddresses(){
	void selectUnselectRadiosOnAddresses();
	$(".address_book a.fright").click(function(){
		var str_token = ( $(".address_book tr.hidden").length == 0)?"show":"hidden";
		var items = $(".address_book tr." + str_token);
		var str_class = (str_token == "hidden")?"show":"hidden";
		var str_title = (str_token == "hidden")?"View less addresses":"View all addresses";
		items[(str_token == "hidden")?"fadeIn":"fadeOut"]("slow");
		items.attr("class", str_class);
		$(this).attr("title", str_title);
		$(this).html(str_title);
	});
}

function shipMethodHilite(){
	var radios = $(".shoppingtable input");
	var totalShipping = $("#str_totalshipping");
	var tr_shipping = $("#tr_shipping");
	radios.click(function(){
		var item = $(this).parents(".shoppingtable").find(".note"), className= "noteheightlight";
		item.attr("class", className);
		totalShipping.css("display", "inline");
		totalShipping.attr("class", "fright noteheightlight");
		tr_shipping.attr("class", "total_item highlighted");
		function timeOut(){
			item.attr("class", "note");
			totalShipping.attr("class", "fright");
			tr_shipping.attr("class", "total_item");
		}
		setTimeout(timeOut, 4000);
	});
}
