<!--
//-- Copyright David Thomas http://www.jewels.co.uk email dave@jewels.co.uk
//-- This file is only used in conjunction with price lists.

function writeTable() {
 document.write('<center><table cellspacing=5 cellpadding=10 border=5>');
 for (i=1; i<category.length; i++)
 
  writeTableRow(i);

 document.write('<tr bgcolor="' + ((category.length%2==0) ? color1 : color2) + '">' + '<input type="hidden" name="custom3" size=12 maxlength=12 value="0.00" ' + 'onFocus="document.form1.custom3.blur()"></td><td align=right>' + writecurrency() +  '<input type="text" ' + 'name="currencytext" size=15 maxlength=15 ' + 'onFocus="document.form1.currencytext.blur()"><br><input type="text" ' + 'name="grandtotal" size=15 maxlength=15 value="0.00" ' + 'onFocus="document.form1.grandtotal.blur()"></td><td align=left>&nbsp;UK Pounds<br><input type="text" ' + 'name="grandtotaluk" size=15 maxlength=12 value="0.00" ' + 'onFocus="document.form1.grandtotaluk.blur()"></td></tr>' + ' <tr bgcolor="' + ((category.length%2==0) ? color2 : color1) + '"><td align=center>This transaction will be in UK Pounds Sterling</td><td align="left"><a href="http://www.webweave.co.uk"><img src="webweaveicon.jpg" width=70 height=29 alt="WebWeave for WebDesign and JavaScript" border="0"></a><img src="secure.gif" width=88 height=31 border=0 alt="i-Stores.co.uk Secure Shopping Directory"></td><td align=right><input type="submit" onClick="return validate()" name="add" value=" - Purchase - "></td></tr></table></center>');
}


// The function below establishes the currency charge based upon a percentage
// of the total cost of the order. Adjust these factors as needed to vary the
// currency charges. These factors are applied based upon the selection in the
// currency select box.


var currency = 1
var currencytext = ""

function update(num) {
var note = ""
currencytext = ""
currency = 1


 if (document.form1.currency.options[0].selected) {
   currency = curate[34]; document.form1.state[0].checked="yes"; note = "";  document.form1.currencytext.value = "Pound [GBP]"} 
 if (document.form1.currency.options[1].selected) {
   currency = curate[33]; document.form1.state[0].checked="yes"; note = "";  document.form1.currencytext.value = "Dollar [USD]"}  
if (document.form1.currency.options[2].selected) {
   currency = curate[0]; document.form1.state[0].checked="yes"; note = "";  document.form1.currencytext.value = "Euro [EUR]"}
if (document.form1.currency.options[3].selected) {
   currency = -1; document.form1.state[0].checked="yes"; note = "";  document.form1.currencytext.value = "Rate Not Avail"}  



if (currency < 0 ) {currency = 0; document.form1.currencytext.value = "Currency not avail"};
if (curate == 0 ) {currency = 0; document.form1.currencytext.value = "Currency not avail"};
  
eval('selected = document.form1.menu' + num + '.selectedIndex;');             

var quant = 1
 

if (metal == 1)
{

if (category[num].product[selected].metaltype == 1) {
latestmetalprice = gold; metalbaseused = goldbaseused; peramountup = goldperamountup; peramountdown = goldperamountdown; percentperamountup = goldpercentperamountup; percentperamountdown = goldpercentperamountdown; profit = goldprofit }; 
if (category[num].product[selected].metaltype == 2) {
latestmetalprice = platinum; metalbaseused = platbaseused; peramountup = platperamountup; peramountdown = platperamountdown; percentperamountup = platpercentperamountup; percentperamountdown = platpercentperamountdown; profit = platprofit }; 
if (category[num].product[selected].metaltype == 3) {
latestmetalprice = silver; metalbaseused = silverbaseused; peramountup = silverperamountup; peramountdown = silverperamountdown; percentperamountup = silverpercentperamountup; percentperamountdown = silverpercentperamountdown; profit = silverprofit };


var metalcalc = metalbaseused - latestmetalprice;
var metalcalc2 = latestmetalprice - metalbaseused;

if (metalcalc > 0) {var percentup=0; var percentdown = percentperamountdown * (metalcalc / peramountup)};
if (metalcalc < 0) {var percentdown=0; var percentup = percentperamountup * (metalcalc2 / peramountdown)};
if (metalcalc == 0) {var percentup=0; var percentdown=0};

}  else {var percentup=0; var percentdown=0; 
if (category[num].product[selected].metaltype == 1) {profit = goldprofit}; 
if (category[num].product[selected].metaltype == 2) {profit = platprofit}; 
if (category[num].product[selected].metaltype == 3) {profit = silverprofit};
}


// Feed for item cost is exvat & retail below.
var pricecalc = fix(category[num].product[selected].price * profit)
var exvat = fix((pricecalc)-((pricecalc * percentdown)/100)+((pricecalc * percentup)/100))
var vatamount = fix(exvat * (vatrate/100)) 
var retail = fix((pricecalc-((pricecalc * percentdown)/100)+((pricecalc * percentup)/100))+(exvat * (vatrate/100))) 

cost = fix(exvat * quant);
 eval('document.form1.price' + num + '.value = cost;');
 var sub_total = 0;
 for (i=1; i<category.length; i++)
  eval('sub_total += parseFloat(document.form1.price' + i + '.value);');


 var taxes_with_currency = fix(vatamount * quant) * currency
 var with_currency = fix(exvat * quant) * currency
  var desc = category[num].product[selected].description

 // Use grand_total_uk & noTaxTotal_uk to pass item sales price to form

if (document.form1.state[0].checked) {var display_taxes = "0.00" ; document.form1.price.value = exvat; vatext = "View = "+document.form1.currencytext.value+" : Transaction currency = UK pounds : "+"Vat not chargeable"  
 } else {
  var display_taxes = (vatamount * quant); document.form1.price.value = exvat; vatext = "View = "+document.form1.currencytext.value+" : Transaction currency = UK pounds : "+"Vat is chargeable"    
  }
  
 document.form1.display_currency.value = fix(with_currency)

 grand_total = taxes_with_currency + with_currency
 noTaxTotal =  with_currency
 
 noTaxTotal_uk = fix(exvat * quant);
 grand_total_uk = fix(retail * quant);
 
if (document.form1.state[0].checked) {
  document.form1.grandtotaluk.value = " £"+fix(noTaxTotal_uk)+" no-vat"
 } else {
  document.form1.grandtotaluk.value = " £"+fix(grand_total_uk)+" inc-vat"
 }
 
 if (document.form1.state[0].checked) {
  document.form1.grandtotal.value = note+" "+fix(noTaxTotal)+" approx"
 } else {
  document.form1.grandtotal.value = note+" "+fix(grand_total)+" approx"
 }
 
 document.form1.quantity.value = quant
 document.form1.custom1.value = desc
 document.form1.custom2.value = vatext
 document.form1.custom3.value = note
  }


function fix(num) {
 string = "" + num;
 if (string.indexOf('.') == -1)
  return string + '.00';
 seperation = string.length - string.indexOf('.');
 if (seperation > 3)
  return string.substring(0,string.length-seperation+3);
 else if (seperation == 2)
  return string + '0';
 return string;
}

writeTable();   // writes all categories
document.write('<br><table cellspacing=0 cellpadding=5 '
 + 'bgcolor="' + color1 + '">');

  
//-->
















