window.onerror = report_error;

var error_count=0;

function dummy(msg, url, line)
{return true;
};

function report_error(msg, url, line)
{record('WEBPAGEERROR>>> msg='+msg+'url='+url+'line='+line);
 alert('Sorry, but an error in our website has been detected.\n'+
       'This is our fault - not yours, and you cannot fix it.\n'+
	   'The fault has been logged & we will fix it soon.\n\n' +
	   'In the meantime, this page may not work correctly for you.\n\n' +
	   'If so, you can try again later, or email us, or phone on 01234 306993.\n\n'+
	   'Once again, we apologise for any inconvenience this may have caused you.');
 return true;
};

function GetCookie(name)
{  var allcookies = unescape(document.cookie);
   var pos = allcookies.indexOf(name+"=", start);
   if (pos != -1)
      {var start = pos + name.length + 1
       var end   = allcookies.indexOf(";", start)
       if (end == -1) end = allcookies.length;
       return unescape(allcookies.substring(start, end))
      }
   else return "";
};

function debug(msg)
{
 if (GetCookie('DEBUG')=="ON")
    {
     alert(msg)
    };
};

function gothere()
{
 var value = document.myform.selector[document.myform.selector.selectedIndex].value;
 window.location.href = value + '.html?Sel';
};

function record(info)
{
 if (document.URL.search(/file/i) != 0)
   {var LogVersion = '1';
    var CID        = GetCookie('keepid');
    var BID        = GetCookie('BID'   );
    if (BID == '')
       {
        var now = new Date();
        BID = Date.parse(now.toUTCString())/1000;
        document.cookie = "BID=" + BID + '; expires=Tue, 31-Dec-2012 00:00:00 GMT';
        BID = GetCookie('BID');
        if (BID == '') {BID = '999999'};
       };
    // NQ[0] gets URL without query string, NQ[1] gets the query string
    var  NQ         = document.URL.split("\?");
    var  pagename   = NQ[0].split(/\\|\//);        // pagename array gets URL /-split elements
    var  pagename   = pagename[pagename.length-1]; // pagename gets last element = filename
	var  myreferrer = document.referrer;
    if (info != '') pagename = pagename + '+' + info;  // add any "info" to pagename field
    if (pagename.length > 255)
       { pagename = pagename.slice(0,254)
       };
    var x = new Image();
    var src_string =  'http://www.i-shops.org/log.pl?'
                      + LogVersion         + '^'
                      + pagename + '?' + escape(NQ[1]) + '^'
                      + BID                + '^'
                      + CID                + '^'
                      + escape(myreferrer);
   x.src = src_string;
   };
};

function log_amazon(ISBN)
{  record('Amazon click on: ' + ISBN);
   var myhref = "http://www.amazon.co.uk/exec/obidos/ASIN/" + ISBN + "/rebeccasadultshop";
   window.location = myhref;
};