// Disable badge printing on specified SKUs

//$(window).load(function() {
$(document).ready(function() {
  if($("#product_code").length>0) {
    SKU8 = $("#product_code").html(); 
    SKU8 = SKU8.substr(SKU8.length - 8);
    
    SKU2 = SKU8.substr(0,2);
    
    // Gift with purchase only products, redirect back to home page
    if(SKU8=='73110301') {
      window.location.replace("http://www.jjbsports.com/pws/ShippingOptions.ice");
    }
        
    // Remove Rangers / Celtic printing options / Brazil
     if(SKU8=='95402001'||SKU8=='95402091'||
       SKU8=='95402031'||SKU8=='61257991'||
       SKU8=='61257931'||SKU8=='59113601') {
      // Preselect no printing
      $("#printed_yes").attr('checked', false);
      $("#printed_no").attr('checked', true);
      $('#shirt_printed_cont').hide();
    }
     // Argentina and Spain remove bespokement. 
     if(SKU8=='59024001'||SKU8=='59024301'||SKU8=='59073001') {
        $("#personalisation_custom_name").html(
          'Why not have your shirt personalised with your favourite players name' 
          + ' and number printed on the back of your shirt?');
        $('#customisation_or').hide(); 
        $('#bespoke_selected_label').hide();
     }
     
     // Adjust England printing disclaimer.
     if(SKU2=='58') {
      if($("#personalisation_custom_name").length>0) {
         $("#personalisation_custom_name").html(
            'Why not have your shirt personalised with your own name and number? ' 
            + ' Alternatively, have your favourite players name and number ' + 
            'printed on the back of your shirt. NB: Numbers will be printed ' + 
            'on both the front and back of all England Shirts.');
        }
        
      // Hide personalisation options.  
      $("#printed_yes").attr('checked', false);
      $("#printed_no").attr('checked', true);
      $('#shirt_printed_cont').hide();
     } 
     
      
    if(SKU2=='60'||SKU2=='61'||SKU2=='95') {
      if($("#personalisation_custom_name").length>0) {
         $("#personalisation_custom_name").html(
            'Why not have your shirt personalised with your own name and number? ' 
            + ' Alternatively, have your favourite players name and number ' + 
            'printed on the back of your shirt. <br/><br />' + 
            'Please note individual players may change their squad number or ' + 
            'could be transferred before the new season.');
        }
     } 
     

     
     
    // Remove squad list options for rangers pre-order 
    if(SKU8=='95403001'||SKU8=='95403109'||
        SKU8=='95403501'||SKU8=='95403901'||
        SKU8=='95404009'||SKU8=='95404401') {
      $('#squad_selected_label').hide();    
      $('#player_name').hide();    
      $('#customisation_or').hide();
      $('#custom_name').show();
      // Swap selected graphic
      $('#bespoke_selected_label').find('img').attr("src", 
       "/pws/images/btn_type_own_name_1.png");
       // Select bespokement!!   
      $('#squad_selected').attr('checked', false); 
      $('#bespoke_selected').attr('checked', true);
    }
   
     var LegendsSKUList = ["58544501","58544502","58544503","58544504","58544505","59002201","59002701","59002501","59002502","59002301","59002401"]; 
        
    // Pre-select shirt printing for legends shirts 
    if(jQuery.inArray(SKU8,LegendsSKUList)>-1) {
      $('#bespoke_selected_label').hide(); 
      $("#select_player_name option:eq(1)").attr("selected", "selected");     
      $('#customisation_or').hide();
      $("#personalisation_custom_name").html('');
      $("#optional_shirt_printing").html('Legend Printed Shirt');      
      $("#printed_yes").attr('checked', true);
      $('#squad_selected').attr('checked', true);
      $('#shirt_printed_cont').hide();
      $('#personalisation').hide();            
    }
    
  }
});
 
    var promoDisplaySKU = false;

    // England Ringer / Football
    var promoEnglandRingerSKUList = ["58596051","58596151"]; 
    var promoEnglandBallSKUList = ["58782501","58782551"]; 
    var promoClaimedEnglandBall = false;
    var promoEnglandBallDisplay = false; 
    
    // Shinpads 
    var promoShinPadList = ["67005362","67268495","67005321"];
    var promoClaimedShinpad = false; 
    var promoDisplayShinpad = false;
    
    // Goggles
    var promoSpeedoGoogles = ["44261891", "44261991", "44261691", "23150391"];
    var promoClaimedGoogles = false; 
    var promoDisplayGoogles = false;
    
    // Golf promos 
    var promoTaylorMadeBallsSKUList = ["78464701","78464601"]; 
    var promoTaylorMadeBallsDisplay = false;
    var promoTaylorMadeClaimed = false;   
    var promoFootJoySKUList = ["21265905","21265991"]; 
    var promoFootJoyDisplay = false;
    var promoFootJoyClaimed = false;

// Checkout page banners
// On load rather than ready for FF.
$(window).load(function() {
  
  // Golf Promotions 
  if($("div#free-taylormade-balls").length>0) {
    $('#shopping_bag_table TR').each(function() {
      var tr = $(this);
        tr.find('TD.image_cont').each(function() {
          var td = $(this); 
          td.find('a img').each(function() {
            var SKUPathPrefix = "/pws/client/images/catalogue/products/";
            var SKUText = ''; 
            var SKUImagePath = $(this).attr("src");
            var SKUOffset = SKUImagePath.indexOf(SKUPathPrefix);
            if(SKUOffset>-1) {
              SKUText= SKUImagePath.substr(SKUPathPrefix.length,8);
              // Bought an Taylor made club 
              if(jQuery.inArray(SKUText,promoTaylorMadeBallsSKUList)>-1) {
                 promoTaylorMadeBallsDisplay = true;
              } 
              // Claimed free balls
              if(SKUText=='78102901') {
                promoTaylorMadeClaimed  = true;
              }
            }
          });
        });
     });
     // If set display the banner
     if(promoTaylorMadeBallsDisplay && !promoTaylorMadeClaimed) {
        $("div#free-taylormade-balls").show();
     }
  }
  // Footjoy glove
  if($("div#free-footjoy-glove").length>0) {
    $('#shopping_bag_table TR').each(function() {
      var tr = $(this);
        tr.find('TD.image_cont').each(function() {
          var td = $(this); 
          td.find('a img').each(function() {
            var SKUPathPrefix = "/pws/client/images/catalogue/products/";
            var SKUText = ''; 
            var SKUImagePath = $(this).attr("src");
            var SKUOffset = SKUImagePath.indexOf(SKUPathPrefix);
            if(SKUOffset>-1) {
              SKUText= SKUImagePath.substr(SKUPathPrefix.length,8);
              // Bought an Taylor made club 
              if(jQuery.inArray(SKUText, promoFootJoySKUList)>-1) {
                promoFootJoyDisplay = true;
              } 
              // Claimed free gift
              if(SKUText=='78763101') {
                promoFootJoyClaimed = true;             
              }
            }
          });
        });
     });
     // If set display the banner
     if(promoFootJoyDisplay && !promoFootJoyClaimed) {
        $("div#free-footjoy-glove").show();
     }
  }
  
  // England T-Shirt/Football
    if($("div#free-england-footall").length>0) {
    $('#shopping_bag_table TR').each(function() {
      var tr = $(this);
        tr.find('TD.image_cont').each(function() {
          var td = $(this); 
          td.find('a img').each(function() {
            var SKUPathPrefix = "/pws/client/images/catalogue/products/";
            var SKUText = ''; 
            var SKUImagePath = $(this).attr("src");
            var SKUOffset = SKUImagePath.indexOf(SKUPathPrefix);
            if(SKUOffset>-1) {
              SKUText= SKUImagePath.substr(SKUPathPrefix.length,8);
              // Bought a supports shirt
              if(jQuery.inArray(SKUText,promoEnglandRingerSKUList)>-1) {
                 promoEnglandBallDisplay = true;
              } 
              // Claimed ball
              if(jQuery.inArray(SKUText,promoEnglandBallSKUList)>-1) {
                 promoClaimedEnglandBall = true;
              } 
            }
          });
        });
     });
     // If set display the banner
     if(promoEnglandBallDisplay && !promoClaimedEnglandBall) {
        $("div#free-england-footall").show();
     }
  }
  
  // Half price shinpads 
  if($("div#half-price-shinpads").length>0) {
    $('#shopping_bag_table TR').each(function() {
      var tr = $(this);
        tr.find('TD.image_cont').each(function() {
          var td = $(this); 
          td.find('a img').each(function() {
            var SKUPathPrefix = "/pws/client/images/catalogue/products/";
            var SKUText = ''; 
            var SKUImagePath = $(this).attr("src");
            var SKUOffset = SKUImagePath.indexOf(SKUPathPrefix);
            if(SKUOffset>-1) {
              SKUText= SKUImagePath.substr(SKUPathPrefix.length,8);
              // Bought from junior football dept.
              
              if(SKUText.substr(0,2)=="07") {
                 promoDisplayShinpad = true;
              } 
              // Already bought shinpads
               if(jQuery.inArray(SKUText,promoShinPadList)>-1) {
                promoClaimedShinpad  = true;
              }
            }
          });
        });
     });
     // If set display the banner
     if(promoDisplayShinpad && !promoClaimedShinpad) {
        $("div#half-price-shinpads").show();
     }
  }

  // Speedo googles
  if($("div#free-swimming-goggles").length>0) {
    $('#shopping_bag_table TR').each(function() {
      var tr = $(this);
        tr.find('TD.image_cont').each(function() {
          var td = $(this); 
          td.find('a img').each(function() {
            var SKUPathPrefix = "/pws/client/images/catalogue/products/";
            var SKUText = ''; 
            var SKUImagePath = $(this).attr("src");
            var SKUOffset = SKUImagePath.indexOf(SKUPathPrefix);
            if(SKUOffset>-1) {
              SKUText= SKUImagePath.substr(SKUPathPrefix.length,8);
              // Bought one of the Goggles?      
              if(jQuery.inArray(SKUText,promoSpeedoGoogles)>-1) {
                 promoDisplayGoogles = true;
              } 
              // Already bought googles
              if(SKUText=='24711189') {
                promoClaimedGoogles = true;
              }
            }
          });
        });
     });
     // If set display the banner
     if(promoDisplayGoogles && !promoClaimedGoogles) {
        $("div#free-swimming-goggles").show();
     }
  }   

});