

function GMTtime(a) {
  // alert = a ; // diagnostic
  if (a.substring(0,1) == "<") {return (document.lastModified) }
  GMTDate = new Date()
  milliSeconds = Date.parse(a)
  GMTDate.setTime(milliSeconds)
  return(GMTDate.toGMTString())
}

function updated() {
  document.writeln("Last Updated: ")
  // Get the date that the requested URL (not this document) was modified
  document.writeln(GMTtime('<!--#echo var="LAST_MODIFIED" -->') + "<BR>")
}

function webmaster() {
   var emailTo = location.hostname;
   if (emailTo.indexOf('www.') == 0) {
     emailTo = emailTo.substring(4,emailTo.length) ;
   }
   else if (emailTo.indexOf('dev.') == 0) {
     emailTo = emailTo.substring(4,emailTo.length) ;
   }
   emailTo = 'webmaster@' + emailTo ;
   document.writeln("Web Master: ")
   document.write(emailTo.link('mailto:'+emailTo) + "<BR>");
}

function fixed2(value) {
// copyright HCI Data ltd 1999,2000 - We scan the WWW regularly to check for violations
//                                    of copyright.  If you wish to license this code
//                                    email sales@hcidata.com
//                                    The costs are very low!
     if (value < 0.5) return '0.00' ;
     var newValue = parseInt((value * 100) + 0.49)  // change to pence/cents and round
     var pence = newValue % 100
     var pounds = (newValue - pence) / 100

     if   (pence < 10) pence = '0' + pence
     if   (pounds < 1) pounds = '0' + pounds

     return '' + pounds + '.' + pence
// copyright HCI Data Ltd 
     }

function AddItem(Item, Price, Quantity) {
// copyright HCI Data Ltd 
     var CookieName = "TheBasket"
     if (Quantity <= 0) {
          alert('The quantity entered (' + Quantity + ') is incorrect' + 
                ' - It must be a number 1 or more.');
          return false;
          }
     document.cookie   = CookieName + "=" + GetCookie(CookieName) + 
                         escape("["+Item+","+Price+"#"+Quantity+"]");
     itemsInBasket()
     return true;
// copyright HCI Data Ltd 
     }

function GetCookie(name) {
// copyright HCI Data Ltd 
     var myCookie = " " + document.cookie + ";" ;
     var searchName = " " + name + "=" ;
     var CookieStart = myCookie.indexOf(searchName) ;
     if   (CookieStart == -1 ) return null    // this cookie does not exist ! 
     CookieStart  += searchName.length // skip over name of cookie to address data // copyright HCI Data Ltd 
     var CookieEnd = myCookie.indexOf(";", CookieStart);
     return unescape(myCookie.substring(CookieStart,CookieEnd)) ;
// copyright HCI Data Ltd 
     }     

function resetShoppingBasket() {
// copyright HCI Data Ltd 
     document.cookie="TheBasket=";
// copyright HCI Data Ltd 
     }

function hiddenItem(name,value) {
// copyright HCI Data Ltd 
     document.writeln('<INPUT TYPE="hidden" NAME="' + name + '" VALUE="' + value + '"' +
                             'SIZE="40">');
     return
// copyright HCI Data Ltd 
     }

function itemsInBasket() {
// copyright HCI Data Ltd 
     var fulllist = "" + GetCookie("TheBasket")
     var itemStart ;
     var itemEnd = 0 ;
     for (var numberOfItems = 0; ; numberOfItems++) {
          itemStart = fulllist.indexOf("[",itemEnd) ;
          if   (itemStart == -1) break
          itemEnd = fulllist.indexOf("]",itemStart) ;
          }
     document.forms[0].ICOUNT.value = numberOfItems
     }
   
function showItems(currency,type,vatrate,itemsPage,itemsName) {
// copyright HCI Data Ltd 
     var checkout = false     //  assume its not yet checkout time unless proved otherwise // copyright HCI Data Ltd 
     var vatRate = 17.5;
     var itemsHTML = "items.htm";          // default for list of items
     var itemsLinkText = "View Services" ; // default text for link to items.htm 

     if   (typeof type != "undefined") {
        if   (type == "checkout") {
           checkout = true
        }
     }

     if (typeof vatrate != "undefined") {
        if (vatrate == "NO") {vatRate = 0}
        else                 {vatRate = vatrate}
     }

     if   (typeof itemsPage != "undefined") {itemsHTML = itemsPage}
     if   (typeof itemsName != "undefined") {itemsLinkText = itemsName}

     var returnToItemsLink = '<A HREF="'+itemsHTML+'">'+itemsLinkText+'</A>';

// copyright HCI Data Ltd 1999 
     var itemList = new Array ;
     var fulllist = "" + GetCookie("TheBasket")
     var itemStart ;
     var itemEnd = 0 ;
     for (var numberOfItems = 0; ; numberOfItems++) {
          itemStart = fulllist.indexOf("[",itemEnd) ;
          if   (itemStart == -1) break
          itemEnd = fulllist.indexOf("]",itemStart) ;
          itemList[numberOfItems] = fulllist.substring(itemStart+1,itemEnd) ;
          }
     if   (numberOfItems == 0) {
//          location = itemsHTML;              // load this page
          document.write('<B>The shopping basket is empty.</B>') ;
          document.write('<P>' + returnToItemsLink ) ;
          return false;
          }
//     document.write('<P><B>' + numberOfItems + '</B> items in your shopping basket') ;// copyright HCI Data Ltd 1999 

     var totprice = 0;
     document.write('<TABLE BORDER="2" CELLPADDING="4" CELLSPACING="2" bgcolor="#ffff66">');
     document.write('<TR><TH>#</TH><TH>Item</TH><TH>Quantity</TH>' +
                        '<TH>Unit Price<BR>'+ currency + '</TH>' +
                        '<TH BGCOLOR="#FFCCCC">Total Price<BR>'+ currency + '</TH>') ;
     document.write('</TR>');
     for (var i = 0; i < numberOfItems ; i++) {
          var comma = itemList[i].indexOf(",")
          var pound = itemList[i].indexOf("#")
          theitem     = itemList[i].substring(0, comma);
          theprice    = itemList[i].substring(comma+1, pound);
// if (typeof theprice != "number") theprice = 99.99;
          thequantity = itemList[i].substring(pound+1, itemList[i].length);
          itemtotal = fixed2(theprice*thequantity);
          totprice += eval(itemtotal);
          itemNumber = i + 1 ;
          document.write('<tr>' +
                             '<td>'+itemNumber+'</td>' + 
                             '<td>'+theitem+'</td>' + 
                             '<td align=right>'+ thequantity+'</td>' + 
                             '<td align=right>'+theprice+'</td>' + 
                             '<td align=right>'+itemtotal+'</td>') ;
          if   (checkout) {
               hiddenItem('item       ' + itemNumber,theitem);
               hiddenItem('quantity   ' + itemNumber,thequantity);
               hiddenItem('price each ' + itemNumber,theprice);
               hiddenItem('total cost ' + itemNumber,itemtotal);
               }
          else {
//             document.write('<TD><a href="javascript:removeItem('+i+')">Remove</a></TD>') ;
               document.write('<TD><INPUT TYPE="button" NAME="removeButton"' +
                                    ' VALUE="Remove from Shopping Basket"' +
                                    ' onclick="removeItem('+i+')"></TD>')
               }
          document.write('</tr>');
          }
     totprice = fixed2(totprice) ;

     if   (checkout) {
          var link2 = '<A HREF="basket.htm">Change Basket</A>'
          var clearALL = " "
          }
     else {
          var link2 = '<A HREF="checkout.htm">Place Order</A>'
          var onClickClearBasket = "clearBasket('"+itemsHTML+"')";
          var clearALL = '<TD ROWSPAN="3">' +
                          '<INPUT TYPE="button" name="clear"' +
                                ' VALUE="Clear Basket"' +
                                ' onClick="'+onClickClearBasket+'">' +
                         '</TD>' 
          }

     var vat = fixed2(eval(totprice) * vatRate/100);

     totpriceWithVAT = fixed2(eval(totprice) + eval(vat))
     if (vat > 0) {
          document.write('<tr><TD COLSPAN="2" ROWSPAN="3">' + returnToItemsLink + '<BR>' + link2 +'</TD>' +
                        '<th COLSPAN="2"><FONT SIZE="+1">TOTAL (ex VAT)</FONT></th>' +
                        '<td align=right><FONT SIZE="+1">'+ totprice +'</FONT></td>' +
                        clearALL) ;
          document.write('<tr>'+
                        '<th COLSPAN="2"><FONT SIZE="+1">VAT</FONT> ('+vatRate+'%)</th>' +
                        '<td align=right><FONT SIZE="+1">'+ vat +'</FONT></td>') ;
          document.write('<tr>' +
                        '<th COLSPAN="2"><FONT SIZE="+1">TOTAL (incl VAT)</FONT></th>' +
                        '<td align=right><FONT SIZE="+1">'+ totpriceWithVAT +'</FONT></td>') ;
          }
     else {
          document.write('<tr><TD COLSPAN="2">' + returnToItemsLink + '<BR>' + link2 +'</TD>' +
                        '<th COLSPAN="2"><FONT SIZE="+1">TOTAL</FONT></th>' +
                        '<td align=right><FONT SIZE="+1">'+ totprice +'</FONT></td>' +
                        clearALL) ;
          }
     if   (checkout) {
          hiddenItem('Goods Total ===========',totprice);
          }
     else {
          document.write('<TD></TD>') ;
          }
     document.write('</tr>');
     document.write('</TABLE>');
// copyright HCI Data Ltd 1999 
     return true
     }

function removeItem(itemno) {
// Remove an item based on its positsion within the shopping basket - ie itemno = 0,1,2,3, etc
     var itemList = new Array ;
     fulllist = " "+GetCookie("TheBasket")
     var itemStart ;
     var itemEnd = 0 ;
     for (var numberOfItems = 0; ; numberOfItems++) {
          itemStart = fulllist.indexOf("[",itemEnd) ;
          if   (itemStart == -1) break
          itemEnd = fulllist.indexOf("]",itemStart) ;
          itemList[numberOfItems] = fulllist.substring(itemStart+1,itemEnd) ;
          }

     var newItemList = null ;
     for (i = 0 ; i < numberOfItems ; i++) {
         if (i != itemno) newItemList += '[' + itemList[i] + ']';
          }
     document.cookie="TheBasket="+newItemList;
     if (location.pathname.indexOf("basket.htm") >= 0) {
        location = "basket.htm";                    // reload this page
     }
// copyright HCI Data Ltd 1999 
     }

function removeItemById(itemID) {
     var itemList = new Array ;
     fulllist = " "+GetCookie("TheBasket")
     var itemStart ;
     var itemEnd = 0 ;
     for (var numberOfItems = 0; ; numberOfItems++) {
          itemStart = fulllist.indexOf("[",itemEnd) ;
          if   (itemStart == -1) break
          itemEnd = fulllist.indexOf("]",itemStart) ;
          itemList[numberOfItems] = fulllist.substring(itemStart+1,itemEnd) ;
          }

     var newItemList = null ;
     for (i = 0 ; i < numberOfItems ; i++) {
        if (itemList[i].indexOf(""+itemID+",") == -1 ) newItemList += '[' + itemList[i] + ']';
        //else alert("Removed......"+itemList[i]);
     }
     document.cookie="TheBasket="+newItemList;
     if (location.pathname.indexOf("basket.htm") >= 0) {
        location = "basket.htm";                    // reload this page
     }
}


function clearBasket(nextPage) {
// copyright HCI Data Ltd 1999 
     if (confirm('Are you sure you wish to clear your basket')) {
          resetShoppingBasket() ;
          location = nextPage;              // load this page
          }
     }

function headings(currency) {
// Default has 4 columns - item-descriptione price quanity add-to-basket-button
     document.write("<TABLE BORDER=3><TR><TH>Item</TH>" +
                    '<TH>Price ' + currency +'</TH><TH>Quantity</TH>' +
                   "<TH> Items in Basket " +
                    '<INPUT TYPE=TEXT NAME="ICOUNT" SIZE="2">' + "</TH></TR>")
     itemsInBasket()
     }
function headingsPS(currency,photoType) {
// Photospencer has 5 columns - photo item-desc price quanity total-price
     document.write("<TABLE BORDER=2><TR><TH WIDTH=200>"+photoType+"</TH>" +
                    '<TH>Item</TH>' +
                    '<TH>Price ' + currency +'</TH><TH>Quantity</TH>' +
                    '<TH>Total Price '+ currency + "</TH></TR>");
     }

function UpdateItemQuantity(i,p,q,fld) {
//   alert('ITEM='+i+' Price='+p+' New Quantity='+q+' Field to place result='+fld);
//   alert(document.forms[0].fld.value) ;
   removeItemById(i);
   AddItem(i,p,q);
   document.forms[0].elements[fld].value = fixed2(q*p);
}

function entryPS(num,item,price,detailsURL,valueRange,image) {
     var QuantityName = "A" + num + "quantity"
     var ItemTotalCostName = "A" + num + "TotalCost"
     document.writeln('<TR>')
     document.writeln('<TD>' + details(detailsURL,image) + '</TD>')
     document.writeln('<TD>' + item + '</TD>')
     document.writeln ('<TD ALIGN=RIGHT>' + price + '</TD>')
     initialValue = getQuantityFromCookie(item);
     if   (typeof valueRange == "undefined") {
          var quantityValue = "document.forms[0]." + QuantityName + ".value"
          var onchange = "UpdateItemQuantity('" + item + "','" + price + "'," + quantityValue + ",'"+ItemTotalCostName+"')";
          document.writeln('<TD>' + 
               '<INPUT TYPE=TEXT' +
                     ' NAME="' + QuantityName + '" onChange="'+onchange+'"' +
                     ' VALUE="'+initialValue+'" SIZE="3" MAXLENGTH="3">' + 
               '</TD>')
          }
     else {
          var quantityValue = "document.forms[0]." + 
                                         QuantityName + ".options[document.forms[0]." + 
                                         QuantityName + ".selectedIndex].text"
          var onchange = "UpdateItemQuantity('" + item + "','" + price + "'," + quantityValue + ",'"+ItemTotalCostName+"')";
          document.writeln('<TD>' +
               '<SELECT NAME="'     + QuantityName + '"' +
                      ' VALUE="'    + initialValue + '"' +
                      ' onChange="' + onchange     + '">' + 
                range(valueRange,initialValue) +
               '</SELECT>' +
               '</TD>')
          }

     document.writeln('<TD>' + 
          '<INPUT TYPE=TEXT NAME="'+ItemTotalCostName+'" VALUE="'+fixed2(initialValue*price)+'" SIZE="3" MAXLENGTH="3">' + 
               '</TD>')
     document.write('</TR>')
     }

function getQuantityFromCookie(itemID) {
   var quantity = 0;
   var itemList = new Array ;
   fulllist = " "+GetCookie("TheBasket")
   var itemStart ;
   var itemEnd = 0 ;
   for (var numberOfItems = 0; ; numberOfItems++) {
      itemStart = fulllist.indexOf("[",itemEnd) ;
      if   (itemStart == -1) break
      itemEnd = fulllist.indexOf("]",itemStart) ;
      itemList[numberOfItems] = fulllist.substring(itemStart+1,itemEnd) ;
   }
   for (i = 0 ; i < numberOfItems ; i++) {
      if (itemList[i].indexOf(""+itemID+",") != -1 ) {
         var startOfQuantity = itemList[i].lastIndexOf("#")+1;
         quantity = itemList[i].substring(startOfQuantity); 
      }
   }
   return quantity;
}




function entry(num,item,price,detailsURL,valueRange,image) {
// alert(item)
// copyright HCI Data Ltd 1999 
// alert(detailsURL);alert(typeof detailsURL)
     var QuantityName = "A" + num + "quantity"
     document.writeln('<TR>')
     document.writeln('<TD>' + item + details(detailsURL,image) + '</TD>')
     document.writeln ('<TD ALIGN=RIGHT>' + price + '</TD>')
     if   (typeof valueRange == "undefined") {
          document.writeln('<TD>' + 
               '<INPUT TYPE=TEXT' +
                     ' NAME="' + QuantityName + '"' +
                     ' VALUE="1" SIZE="3" MAXLENGTH="3">' + 
               '</TD>')
          var quantityValue = "document.forms[0]." + QuantityName + ".value"
          }
     else {
          var onchange = "alert('changed')"
          document.writeln('<TD>' +
               '<SELECT NAME="' + QuantityName + '">' + 
                range(valueRange,"1") +
               '</SELECT>' +
               '</TD>')
          var quantityValue = "document.forms[0]." + 
                                         QuantityName + ".options[document.forms[0]." + 
                                         QuantityName + ".selectedIndex].text"
//          var quantityValue = "document.forms[0]." + 
//                                       QuantityName + ".selectedIndex"
          }
     var onclick = "AddItem('" + item + "','" + price + "'," + quantityValue + ")" 
//     var onclick = "alert('" + item + "<-->" + price + "<-->'+" + quantityValue + ")" 

     var ButtonAttributes = ' TYPE=BUTTON' +
//                     ' NAME="' + item + 'add"' +
                       ' VALUE="Add to Shopping Basket"'
     document.write('<TD><INPUT ' + ButtonAttributes + ' onclick="' + onclick + '"></TD>')
// copyright HCI Data Ltd 1999 
     document.write('</TR>')
     }


function endlist() {
     document.write("</TABLE>")
     }



function details(href,image) {
     var anchor;
     var pre= "";
     var URL = (typeof href) == "string";
     if   (URL) URL = href != "";
     var IMG = (typeof image) == "string";
     if   (IMG) IMG = image != " ";
     if (IMG) {
          anchor = image
     }
     else if (URL) {
          anchor = 'details';
          pre = "<BR>";
     }
     else {
          anchor = '';
     }
     if   (URL) {
        return('<FONT SIZE="-1">'+pre+anchor.link(href)+'</FONT>');
          }
     else {
        return('<FONT SIZE="-1">'+anchor+'</FONT>');
     }
}

// copyright HCI Data Ltd 1999 

function range(limits,initValue) {
// alert("--->"+limits + "<----->"+efault+"<---")
     searchString = limits + ","  // ensure it end in a comma to ease processing
     var options = ""
     for (var startPosition = 0 ; startPosition < searchString.length -1 ;){
          var nextParm = searchString.indexOf(",",startPosition)
// alert("Start=" + startPosition + "  Next=" +nextParm)
          options += checkRange(initValue,searchString.substring(startPosition,nextParm));
          startPosition = nextParm + 1
          }
// alert("--->"+limits + "<----->"+options+"<---")
     return options
     }

function checkRange(initValue,limits) {
     var options = ""
     var splitPoint = limits.indexOf("-")
     if  (splitPoint == -1) {
        if (initValue == limits) {
           options = '<OPTION VALUE="'+limits+'" SELECTED>'+limits;  // just a single number
        }
        else {
           options = '<OPTION VALUE="'+limits+'">'+limits;  // just a single number
        }
     }
     else {
        var loValue = eval(limits.substring(0,splitPoint))
        var hiValue = eval(limits.substring(splitPoint+1,limits.length))
        for (var i = loValue ; i < hiValue ; i++) {
           if (initValue == i) {
              options += '<OPTION VALUE="'+i+'" SELECTED>'+i; 
           }
           else {
              options += '<OPTION VALUE="'+i+'">'+i;
           }
        }
     }
// alert("--->"+options+"<---")
     return options
     }
//

