// The author asserts copyright on this program and all of its components

function report_error(msg, url, line)
{  record('WEBPAGEERROR>>> msg='+msg+', url='+url+', line='+line);
    alert('Sorry, but an error has been detected.\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 you are not using Internet Explorer - then using it will probably avoid this error.\n' +
           'Alternatively, you are welcome to email or phone on 01234 306993 during UK office hours.\n\n'+
           'Once again, we apologise for any inconvenience this may have caused you.');
   return true;
};

// window.onerror = report_error;

var error_count=0;
var message="Right Clicking is disabled";

function click(e)
{if (document.all)
    {if (event.button == 2)
        {alert(message);
         record('Right Click');
         return false;
        }
    };

 if (document.layers)
    {if (e.which == 3)
        {alert(message);
         record('RightClick');
         return false;
        }
    }
};

if (document.layers)
   {document.captureEvents(Event.MOUSEDOWN);
   };

// document.onmousedown=click;

function bookmark(url){
  if (document.all)
  window.external.AddFavorite(url,"Sunflower Fabrics");
  record('Bookmarking ' + url);
};

function NewSearch(num, keyword)
{
 record('Search:: ' + num + ': '+ keyword);
 var newloc = "search2.php?&simple=true&colour=X&pattern=X&type=X&key=" + keyword;
 window.location.href = newloc;
};

function NewSearch2(num, keyword)
{
 record('Search:: ' + num + ': '+ keyword);
 var newloc = "search3.php?&simple=true&colour=X&pattern=X&type=X&key=" + keyword;
 window.location.href = newloc;
};

function get_items_total()
{var LinePrice, PriceTotal = 0, items, mycookie = GetCookie("order");
 if   (mycookie == "")
      {return 0;
	  }
 else {items = mycookie.split('|');
       count = items.length;
	   for (var i=0; i<count; i++)
           {parts = items[i].split("^");
            LinePrice = parts[10];
	        PriceTotal += LinePrice/1;
           }; 
     return PriceTotal;
	 };
};

function MoneyFormat(amount) {
	var val = parseFloat(amount);
	if (isNaN(val)) { return "0.00"; }
	else { val = Math.round(val*100)/100; }
	val = (val == Math.floor(val)) ? val + '.00' : ((val*10 == Math.floor(val*10)) ? val + '0' : val);
	return val;
	};

function dummy(msg, url, line)
{return true;
};

function go()
{
 document.myform.url.value = myurl;
 record('Emailing page: ' + document.myform.url.value     +
        ' to '            + document.myform.email.value   +
        ' with name '     + document.myform.name.value    +
        ' and message '   + document.myform.message.value
       );
};

function DoPic(i)
{// if (i != 0)
 //    {var temp = Math.round(i * Math.random());
 //     document.writeln("<A HREF='people.htm' BORDER='0'><IMG SRC='p" + temp + ".jpg' BORDER='0'></A>");
 //    };
};

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 doNaviBar(navicolour)
{document.writeln("<link rel='stylesheet' href='styles.css' type='text/css'>");
 custom_pre_navi();
 document.writeln("<div align='center'><center>");
 document.writeln("   <table width='100%' border='0' cellpadding='1'>");
 document.writeln("    <tr>");
 document.writeln("      <td bgcolor='Red' width='150'><div align='center'>");
 document.writeln("        <a class='white' href='help1.htm' title='Help using our online quilt store'>HELP!</a>");
 document.writeln("       </div></td>");
 document.writeln("      <td class='navibar' width='150'><div align='center'>");
 document.writeln("         <a class='white' href='talk.htm' title = 'Contact our quilt store staff'>Contact Us</a>");
 document.writeln("       </div></td>");
 document.writeln("      <td class='navibar' width='150'><div align='center'>");
 document.writeln("         <a class='white' href='index.htm' Title = 'Departments to visit: quilt fabrics, quilt patterns, habby, & more'>Departments</a>");
 document.writeln("       </div></td>");
 document.writeln("      <td class='navibar' width='150'><div align='center'>");
 document.writeln("         <a class='white' href='sform2.htm' Title = 'Search for quilting supplies'>Advanced Search</a>");
 document.writeln("      </div></td>");
 document.writeln("      <td class='navibar' width='32%'><div align='center'>");
 document.writeln("      <a class='white' href= 'basket.htm' title = 'Show/Change basket contents or go to checkout'>Your Basket Total is: &pound;");
 document.writeln("         <script language='JavaScript1.2' type='text/Javascript1.2'>document.write(MoneyFormat(get_items_total()))</script>");
 document.writeln("         </a>");
 document.writeln("         </div></td>");
 document.writeln("     </tr>");
 document.writeln("  </table>");
 document.writeln("</center></div>");

 if (GetCookie('CDROOT') !='')
    {var colour, label;
     if   (location.protocol == 'file:')
          {colour = 'Green'; label = 'CD-ROM'}
     else {colour = 'Red';   label = 'Online'};

     document.writeln("<td bgcolor='Green' width='14%'><div align='center'>");
     document.writeln("<font size='2' face='Arial' color='White'>",label,"</font>");  
    };
 document.writeln("</div></td></tr></table>");
};

function debug(msg)
{
 if (GetCookie('DEBUG')=="ON")
    {
     alert(msg)
    };
};

function gothere()
{
 var value = document.myform.selector[document.myform.selector.selectedIndex].value;

 if   (    (location.protocol == 'file:')
        && (value == 'newest1')
      ) 
      window.location.href = 'http://www.sunflowerfabrics.com/checkol.htm?'+GetCookie('order');
 else
      window.location.href = value + '.htm';
};

function record(info)
{
 if (document.URL.search(/file/i) != 0)
   {
    var LogVersion = '1';
    var CID;
    if   (GetCookie('CDROOT') !='')
         {CID ='CDROM'}
    else {CID ='ONLIN'};

    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');
       };

    var undefined;
    var NQ         = document.URL.split('?'); if (NQ[1] == undefined) NQ[1]='';
    var pagename   = NQ[0].split(/\\|\//);
        pagename   = pagename[pagename.length-1];

    if (info != '') pagename = pagename + '+' + info;
    if (NQ[1] !='') pagename = pagename + '?' + NQ[1];
    pagename = escape(pagename);

    if (pagename.length > 255)
       { pagename = pagename.slice(0,254)
       };

	 NQ 	    = document.referrer.split('?');
    var  temp1      = NQ[0].split('/');
         myreferrer = temp1[temp1.length-1];
    var  refdomain  = temp1[2]; if (refdomain == undefined) refdomain = '';

    if (refdomain != '' && refdomain != document.domain) myreferrer = document.referrer;
    if (myreferrer.length > 255)
       { myreferrer = myreferrer.slice(0,254)
       };

    var x = new Image();
    var logstring = '/cgi-bin/log.pl?' +
                     LogVersion        + '^'
                      + pagename       + '^'
                      + BID            + '^'
                      + CID            + '^'
                      + escape(myreferrer);
    x.src = logstring;
  };
};

record();

function amazon(ISBN)
{  record('Amazon click on: ' + ISBN);
   var myhref = "http://www.amazon.co.uk/exec/obidos/ASIN/" + ISBN + "/rebeccsadultshop";
   window.open(myhref);
};