function find_referrer_cookie()
//       --------------------
{
   var the_cookie = document.cookie;
   var the_cookie = unescape(the_cookie);
   var index = the_cookie.indexOf("LSJP_REFERRER");

   return index;
}

function set_referrer_cookie()
//       -------------------
{
   if (find_referrer_cookie() == -1)
   {
      var my_url = escape(window.location);
      var ref_cookie = "";
      var when = new Date();
      var src_index = my_url.indexOf("%3Fsrc%3D");

      if (src_index == -1)
      {
         src_index = my_url.indexOf("%3Fov_");

         if (src_index != -1)
            src_index = src_index - 6;
      }

      if (src_index == -1)
      {
         ref_cookie = escape(document.referrer);

         if (ref_cookie.length == 0)
         {
            ref_cookie = "No_Referrer";
         }
         else
         {
            var se_term = chk_all_ses(ref_cookie);

            if (se_term.length > 0)
               ref_cookie = se_term;
            else
            {
               if (ref_cookie.indexOf("http%3A//") == 0)
                  ref_cookie = ref_cookie.substring(9, ref_cookie.length);

               if (ref_cookie.indexOf("www.") == 0)
                  ref_cookie = ref_cookie.substring(4, ref_cookie.length);

               if (ref_cookie.length > 100)
                  ref_cookie = ref_cookie.substring(0, 100);
            }
         }
      }
      else
      {
         ref_cookie = my_url.substring(src_index + 9, my_url.length);
      }

      var day = when.getDate();
      var mon = when.getMonth() + 1;

      ref_cookie = ref_cookie + "_" + mon.toString() + "_" + day.toString();

      when.setMonth(when.getMonth() + 11);
      document.cookie = "LSJP_REFERRER=" + ref_cookie + ";expires=" + when.toGMTString();
   }
}

function read_referrer_cookie()
//       --------------------
{
   var cookie_index = find_referrer_cookie();

   if (cookie_index != -1)
   {
      var the_cookie = document.cookie;
      var first = cookie_index + 14;
      var last = the_cookie.indexOf(';', first);

      if (last == -1)
         last = the_cookie.length;

      the_cookie = the_cookie.substring(first, last);

      return the_cookie;
   }

   return "No_Cookie";
}

function chk_se(ref, se, strt_tag, fnsh_tag)
//       ------
{
   if (ref.indexOf(se) != -1)
   {
      var strt = ref.indexOf(strt_tag);

      if (strt != -1)
      {
         var fnsh = ref.indexOf(fnsh_tag, strt + 1);
         if (fnsh == -1) fnsh = 999;
         return se + "/" + ref.substring(strt + strt_tag.length, fnsh);
      }
   }

   return "";
}

function chk_all_ses(ref)
//       -----------
{
   var result = chk_se(ref, "google.", "%26q%3D", "%26");

   if (result.length != 0)
      return result;

   result = chk_se(ref, "search.yahoo", "p%3D", "%26");

   if (result.length != 0)
	return result;

   result = chk_se(ref, "search.msn", "%26q%3D", "%26");

   if (result.length != 0)
	return result;

   result = chk_se(ref, "altavista", "%3Fq%3D", "%26");
   return result;
}

function get_year()
//       --------
{
   return "2004";
}

function plimus_buy_link(contract)
//       ---------------
{
   var link = "https://www.plimus.com/jsp/buynow.jsp?contractId=";
   var referrer = read_referrer_cookie();

   link = link + contract;
   
   if (referrer.length != 0)
      link = link + "&referrer=" + referrer;

   location.href = link;
   return false;
}
