nq_url = '';
natune_date = new Date();
natune_org_error_handler = window.onerror;

function quoted(str)
{
  return (str != null) ? '"' + str + '"' : '""';
}

function natune_encodeURIComponent(str)
{
  if (typeof(encodeURIComponent) == 'function')
  {
    return encodeURIComponent(str);
  }
  else
  {
    return escape(str);
  }
}

function natune_append_url(param, value)
{
  if (value)
  {
    window.nq_url += '&' + param + '=' + value;
  }
}

function natune_append_url_esc(param, value)
{
  if (value)
  {
    natune_append_url(param, natune_encodeURIComponent(value));
  }
}

function natune_show_quote()
{
  var w = window;
  w.onerror = w.natune_org_error_handler;

  w.nq_url = 'http://quotes.natune.net/quoteservice/js1.0/getRandomQuote.js?';

  w.nq_url += 'client=' + escape(w.nq_subscriber) +
              '&dt=' + w.natune_date.getTime();

  natune_append_url_esc('refr_time', w.nq_first_refresh);
  natune_append_url('refr_intv', w.nq_refresh_interval);
  natune_append_url('syncid', w.nq_sync_id);
  
  natune_append_url_esc('url', w.natune_page_url);

  natune_append_url_esc('ref', w.natune_referrer_url);
  natune_append_url_esc('loc', w.natune_page_location);

  w.nq_url = w.nq_url.substring(0, 1000);
  w.nq_url = w.nq_url.replace(/%\w?$/, '');


  if (nq_output == 'js')
  {
    document.write('<scr' + 'ipt language="JavaScript1.1"' +
                   ' src=' + quoted(nq_url) +
                   '></scr' + 'ipt>');
  }

  w.nq_frameborder = null;
  w.natune_page_url = null;
  w.natune_page_location = null;
  w.natune_referrer_url = null;
}

function natune_error_handler(message, url, line)
{
  natune_show_quote();
  return true;
}

window.onerror = natune_error_handler;

if (window.nq_frameborder == null)
{
  nq_frameborder = 0;
}

if (window.nq_output == null)
{
  nq_output = 'js';
}

if (window.natune_page_url == null)
{
  natune_page_url = document.referrer;
  if (window.top.location == document.location)
  {
    natune_page_url = document.location;
    natune_last_modified_time = Date.parse(document.lastModified) / 1000;
    natune_referrer_url = document.referrer;
  }
}
else
{
  natune_page_location = document.referrer;
  if (window.top.location == document.location)
  {
    natune_page_location = document.location;
  }
}

natune_show_quote();