var caurl = "http://contextad.janes.com/contextad/json?contextAdAcro=news&user=0&jsoncallback=?";

$(document).ready(function(){
    var k2dockey = location.pathname;
    caurl = caurl + "&K2DocKey=" + k2dockey;
    $.getJSON(caurl, processData);
})

function processData(json) {
    $("#tools > dl").after("<span id='ad_here'></span>");
    $("#url").html(caurl);

    if (json.json_key.length != 0) {
      $("#ad_here").html("<dl id='contextads'><dt>Industry Links</dt><dd id='test'></dl>");

      $.each (json.json_key, function(i, item) {
            $("#test").append("<p><a href='#' onclick='sponsorLink(\""+ item.adUrl + "\");'>" + item.linkText + "</a></p>");
      });

      $("#test").append("<p class='disclaimer'>Jane's is not responsible for the content within or linking from Industry Links pages.</p></dd></dl>");
/*    } else {
      $("#ad_here").html("No JSON Returned!");*/
    }
}

function sponsorLink(URL) {
 day = new Date();
 id = day.getTime();
 eval("page" + id +
      " = window.open(URL, '" + id +
      "','toolbar=1,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=800,height=400,left = 240,top = 200');");
}
