Initialiser.modules.aarp = function(){
  
  //If the aarp referral is present:
  
  if ($.cookie('referralcookie') == 'aarp') {
    
    //When the cart has been emptied, remove the aarpReminder:
    var basketEmpty = false;
    if ($('span.amount', '#minishopcart').text() == '$0.00') {
      basketEmpty = true;
      $.cookie('aarpReminder', null);
    }
    
    var message = '';
    
    if ($.cookie('aarpState') && !basketEmpty) {
      message = safeMessages['AARPDiscountApplied'];
    } else if ($('body').is('.basket') && !basketEmpty) {
      message = safeMessages['enterAARPMembershipNo'];
    } else if ($.cookie('aarpReminder') && !basketEmpty) {
      message = safeMessages['AARPReminder'];
    } else {
      message = safeMessages['welcomeAARPMember'];
    } 
      
      var bannerContents = '<strong class="logo">AARP</strong> <span class="messageText">' + message + '</span>';
      
      safe.showNotificationBar(bannerContents, {barId: 'AARPBanner'});
   
   //Capture the code when a valid ID is submitted
   $('#AARPCodeForm').submit(function(){
     if ($('#aarpMemberIdEntry').val().length) {
       $.cookie('aarpState', $('#aarpMemberIdEntry').val());
     }
   });

	//Record when user clicks 'Remove Offer' button. delete the cookie aarpState to remove the 'AARPDiscountApplied' message
	//Same when we log out.
    $('#WC_OrderSubmitForm_PromoCode_Link_2').add('a[href*=Logoff?]', '#header').click(function(){
   		$.cookie('aarpState', null);
   		$.cookie('aarpReminder', null);
    });
   
   //Record when the user has continued into the checkout stage (from the cart view)
   $('#WC_OrderItemDisplay_Link_5').click(function(){
     
     //The value of the cookie is the URL for the cart page, so we can return here
     if ($.cookie('aarpState')) {
       $.cookie('aarpReminder', null); //When they have entered their number, everything's cool, so delete the reminder cookie:
     } else {
       var date = new Date();
 	   date.setTime(date.getTime() + (20 * 60 * 1000));
       $.cookie('aarpReminder', safeMessages['viewCartURLForAARP'], { expires: date }); //If they haven't entered the number, set a reminder
     }
     
   });
  }
}

