/*
      This script runs on the Footer and creates Shopper Mode Change Notification Modal window
*/
$(document).ready(function() {

//Style applying to the Modal
var getModalStyle = function() 
	{
		$("div#ShopperModeNotificationDialog").dialog({
			autoOpen: false,
			bgiframe: true,
			width: 600,
			modal: true,
			closeOnEscape: false,
			resizable: false,
			draggable: false,
			overlay: {
				opacity: 0.70,
				background: "black"
			}
		});	
	};	
		
	

	// Execute the anchor tag click event if the custom attribute 'ShopperModeChangePromptEnabled' is set to 'Y'
	$("a[ShopperModeChangePromptEnabled=Y]").click (function(event){
	      
			 var ItemsInCartAjaxURL = $('#hdnItemsInCartAjaxURL').val();
			 if (ItemsInCartAjaxURL != "")
			 {
			 getModalStyle();
			   
			//Get the hidden field values                             
				var IsBDPage = $('#hdnIsBD').val();
				 
	            
				//Get the target URL
				var TargetURL = this.href;
				var TargetWindow = this.target;
				
				$("a[id='lnkContinue']").attr('href',TargetURL);
							
				//Check whether the shopper is in BD warehouse
				if( IsBDPage == "True")
					{					
						if( TargetURL.indexOf("/Home.aspx") > 0)					        
							{
								event.preventDefault();	
																
								// Call the AJAX function to get whether any items exsting in the BD cart
								$.get(ItemsInCartAjaxURL,function(ResponseData)
									{            
										if(ResponseData == "True")
										{											
											$('#ShopperModeNotificationDialog').css('display','block');
											$('#ShopperModeNotificationDialog_LeavingBD').css('display','block');
											$('#ShopperModeNotificationDialog_MovingtoBD').css('display','none');
											$("div#ShopperModeNotificationDialog").dialog("open");
											$(".ui-dialog-titlebar").hide();
											$(".ui-dialog").width("").height("250");
											$(".ui-dialog").css("center", "80px");
											$("div.dialogContent").corners("10px");	
										} 
										else
										{
											window.open(TargetURL,TargetWindow);
										} 
										            
									});
							} 					        
					}
				else
					{					
						if( TargetURL.indexOf("/BDLanding.aspx") > 0 && window.location.pathname.indexOf("/BDLanding.aspx") < 0)					        
							{
								event.preventDefault();								
								
								// Call the AJAX function to get whether any items exsting in the BC/BC Tire cart
								$.get(ItemsInCartAjaxURL,function(ResponseData)
									{  
										if(ResponseData == "True")
										{											
											$('#ShopperModeNotificationDialog').css('display','block');
											$('#ShopperModeNotificationDialog_LeavingBD').css('display','none');
											$('#ShopperModeNotificationDialog_MovingtoBD').css('display','block');
											$("div#ShopperModeNotificationDialog").dialog("open");
											$(".ui-dialog-titlebar").hide();
											$(".ui-dialog").width("").height("250");
											
											$("div.dialogContent").corners("10px");												
										} 
										else
										{
											window.open(TargetURL,TargetWindow);
										} 								        
									});								 
							} 					
					    } 
					}           
				}); //End anchor tag click event  
				
				//JQuery method to close the popup while clicking the 'Return' link.
				$("#lnkReturn").click(function(event) {
						$("div#ShopperModeNotificationDialog").dialog("close");
						event.preventDefault();
				});		               

	}); //End Function

	      
	            
	      
	            
	            




