if (Drupal.jsEnabled) {
  $(document).ready(function() {
    ss_affiliate_update_phone();
  });
}

function ss_affiliate_update_phone() {
  var phone = ss_affiliate_get_cookie('affiliate[phone]');
  var extension = ss_affiliate_get_cookie('affiliate[extension]');
  if (phone != null && extension != null) $('.ss-phone').empty().html(phone + ', Offer Code: ' + extension);
  else if (phone != null) $('.ss-phone').empty().html(phone);
}

function ss_affiliate_get_cookie(name) {
  var cookieValue = null;
  if (document.cookie && document.cookie != '') {
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
      var cookie = jQuery.trim(cookies[i]);
      // Does this cookie string begin with the name we want?
      cookie_match = cookie.substring(0, name.length + 1);
      if (cookie_match == (name + '=')) {
        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
        break;
      }
    }
  }
  return cookieValue;
}
