/* this script parses the page url for the pattern ref=someSource
  if we find that the user came from commission junction or bing search
  allow a 3rd party cookie to be set from the yahoo cart domain
  therefore allowing the yahoo order confirmation page to
  render conversion tracking script if this cookie exists
*/

var referrer = new RegExp('[\\?&]' + "ref" + '=?([^&#]*)').exec(window.document.location);

if (referrer != null && referrer.length > 1) {
  referrer = referrer[1]; 
}

// 3rd party cookie is set by appending a 1x1 pixel image from corresponding
// yahoo cart domain
// image and cookie are dynamically creating using PHP on the yahoo cart side

//note, this script only runs after full page load
//so it's possible for cookie to not be set if user browses away too quickly
//recommend moving this pixel tracking code within the body -hc

function generate_cookie_code(channel) {
  var old_onload = window.onload;
  window.onload = function(){
    _url = 'https://p10.secure.hostingprod.com/@cpodeltatruckboxes.com/ssl/'+channel+'_cookie.php'
    var e = document.createElement("img");
    e.src = _url;
    document.getElementsByTagName("body")[0].appendChild(e);
    if(old_onload) old_onload();

  }
}

//index of returns the char number where pattern is found in string
//as long as the referrer value contains src code, drop cookie
if (referrer.indexOf('bing') != -1) {generate_cookie_code('bing');}
if (referrer.indexOf('cj') != -1) {generate_cookie_code('cj');}
