$(document).ready(function() {
  
  var location = document.location.href;
  var isHttps = location.indexOf("https") != -1;
  var isTelus = location.indexOf("telus") != -1;
  
  if (isTelus && isHttps) {
    
    $("#cp_encrypt").css("display", "none");
    $("#rp_encrypt").css("display", "none");
    
  } else {

    $("#cp_encrypt").click(function() {
      triggerCpLinkChange();
    });
    
    $("#rp_encrypt").click(function() {

      triggerRpLinkChange();

    });
    
    $("#cp_encrypt").attr("checked", "checked");
    $("#rp_encrypt").attr("checked", "checked");
    
    triggerCpLinkChange(isTelus);
    triggerRpLinkChange(isTelus);
    
  }

});

function triggerCpLinkChange(isTelus) {
  
  var newUrl;

  if ($("#cp_encrypt").attr("checked")) {

    newUrl = $("#cp_go").attr("href").replace("http://", "https://");

  } else {

    if (!isTelus) {
      newUrl = $("#cp_go").attr("href").replace("https://", "http://");
    } else {
      $("#cp_encrypt").attr("checked", "checked");
    }
    
  }

  $("#cp_go").attr("href", newUrl);
  $("#cp_go2").attr("href", newUrl);
  
}

function triggerRpLinkChange(isTelus) {
  
  var newUrl;

  if ($("#rp_encrypt").attr("checked")) {

    newUrl = $("#rp_go").attr("href").replace("http://", "https://");

  } else {

    if (!isTelus) {
      newUrl = $("#rp_go").attr("href").replace("https://", "http://");
    } else {
      $("#rp_encrypt").attr("checked", "checked");
    }
    
  }

  $("#rp_go").attr("href", newUrl);
  $("#rp_go2").attr("href", newUrl);
  
}