/*
 * This is a javascript file used for working with promo codes
 */

$(document).ready(function() {
  function hasPromoCode() {
    return custCatName != 'Anonymous';
  }

  var promoCode = hasPromoCode() ? custCatName : '';

  if(hasPromoCode()) {
    $('.current-promo-code').each(function() {
      if($(this).attr('fmt') != '') {
        var html = $(this).attr('fmt').replace(/[%]/g, promoCode);
        $(this).html(html);
      } else {
        $(this).html(promoCode);
      }
    });
  }

  var mesg = hasPromoCode() ?
    "Your promo code is currently set to: <b>" + promoCode + "</b>." :
    "Set your promo code by entering it below.";

  $('.promo-box .message').html(mesg);

  $('#set-promo-code-form').submit(function() {
    if(this.elements["pricing"].value == '') {
      alert("You must enter a promo code to continue");
      return false;
    } else {
      return true;
    }
  }
    );
});

