var email_address;
var target;

// pull a param from the page url
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function pan_post(){


    var party_id;
    var known_id;

    // set email address and target defaults if they are not set outside script
    if (email_address == null) { email_address = "null"}
    if (target == null) { target = "false"}

    // set know id to party id if one is passed int he URL
    party_id = gup('pid')
    if (party_id != "") {
        known_id = party_id;
        $.cookie('known_id', known_id, { expires: 365 });
    } else {
        known_id = $.cookie('pan_known_id')
    }

    //sent data
    $.get("http://backroadslogger.ddmweb.com/pan_track?" +
          "pan_id=" + $.cookie('pan_id') +
          "&known_id="+ known_id +
          "&referrer=" + String(document.referrer).replace(/&/g, "|038|") +
          "&page=" + String(document.location).replace(/&/g, "|038|") +
          "&email_address=" + email_address +
          "&target=" + target,
    {}, null, "script" )
}

// callback
function pan_success(data) {
    // set the pan id cookie to the pan id returned 
    $.cookie('pan_id', data.pan_id, { path: '/', expires: 365 });

}

pan_post();
