function presentValue(value)
{if(value<=0.9999)
{newPounds='0';}
else
{newPounds=parseInt(value);}
dec='1';
for (var i=1; i<=2;i++)
{dec=dec+'0';}
if (value>0)
{newPence=Math.round((value+.000008 - newPounds)*(eval(dec)));}
else
{newPence=0;}
compstring='9';
for (var i=1; i <=2-1;i++)
{if (eval(newPence) <= eval(compstring))
newPence='0'+newPence;
compstring=compstring+'9';}
if (2>0)
{newString='$' + newPounds + '.' + newPence + '';}
else
{newString='$' + newPounds + '';}
return (newString);}

function getAdvanced(adv,curr,qty)
{newAdv='';advlist=0;applicable=true;advnewprice=0;
for (var j=0;j<=adv.length;j++)
{if (adv.substring(j,j+1) == '{')
{thisadv=1;
advstart=j+1;}
else
if (adv.substring(j,j+1) == '}')
{advend=j;
advPrice2=adv.substring(advstart,advend);
advlist++; applicable=true;
if (applicable==true)
{if (eval(advFrom) > 0 && eval(advFrom) > eval(qty))
applicable=false;
if (eval(advTo) > 0 && eval(advTo) < eval(qty))
applicable=false;
if (curr==1 && applicable==true)
advnewprice=advPrice;
if (curr==2 && applicable==true)
advnewprice=advPrice2;}}
else
if (adv.substring(j,j+1)=='~')
{if (thisadv== 1)
advFrom=adv.substring(advstart,j);
if (thisadv== 2)
advTo=adv.substring(advstart,j);
if (thisadv== 3)
advPrice=adv.substring(advstart,j);
if (thisadv== 4)
advPrice2=adv.substring(advstart,j);
thisadv++;advstart=j+1;}}
return advnewprice;}

function goBuy()
{state=document.gobuy.state[document.gobuy.state.selectedIndex].value;
zip=document.gobuy.zip.value;
country=escape(document.gobuy.country[document.gobuy.country.selectedIndex].value);
ilist='';
index=document.cookie.indexOf('TheBasket');
countbegin=(document.cookie.indexOf('=', index)+1);
countend=document.cookie.indexOf(';',index);
if(countend==-1)
{countend=document.cookie.length;}
fulllist=document.cookie.substring(countbegin,countend);
for(var i=0; i<= fulllist.length;i++)
{if(fulllist.substring(i,i+1)=='[')
{itemstart=i;}
else
if (fulllist.substring(i,i+1)==']')
{itemend=i+1;
ilist=ilist+fulllist.substring(itemstart,itemend);}}
ilist=changeSpaces(ilist);
top.location='https://www.microexpress.net/buy.asp?totalprice='+totprice+'&totalweight='+totweight+'&state='+state+'&zip='+zip+'&country='+country;}

function goShopping()
{top.location='proddisp.asp';}

function changeSpaces(tstring)
{nstring='';
for (var i=0; i <= tstring.length; i++)
{if (tstring.charAt(i)==' ')
{nstring=nstring+'^';}
else
{nstring=nstring+tstring.charAt(i);}}
return nstring;}

taxfield='United Kingdom';

function showBasket()
{currency=1;
index=document.cookie.indexOf('TheBasket');
countbegin=(document.cookie.indexOf('=',index)+1);
countend=document.cookie.indexOf(';',index);
if (countend==-1)
{countend=document.cookie.length;}
fulllist=document.cookie.substring(countbegin,countend);
totprice=0;totprice2=0;shippingtotal=0;shippingtotal2=0;taxtotalone=0;taxtotalone2=0;taxtotaltwo=0;taxtotaltwo2=0;ordertotal=0;ordertotal2=0;
taxablestandard=0;taxablesecond=0;taxable=0;totweight=0;
document.writeln('<table border=1 width="90%">');
document.writeln('<tr>');
document.writeln('<td bgcolor=fffce8><font face="Arial" size=2><b>Product Name</b></font></td>');
document.writeln('<td bgcolor=fffce8 align=right><font face="Arial" size=2><b>Price</b></font></td>');
document.writeln('<td bgcolor=fffce8 align=right><font face="Arial" size=2><b>Quantity</b></font></td><td bgcolor=fffce8 align=right><font face="Arial" size=2><b>Total Cost</b></font></td><td bgcolor=fffce8 align=right><font face="Arial" size=2><b>Action</b></font></td>');
document.writeln('</tr>');
itemlist=0;
for (var i=0; i<=fulllist.length;i++)
{if (fulllist.substring(i,i+1)=='[')
{itemstart=i+1;
thisitem=1;}
else
if (fulllist.substring(i,i+1)==']')
{itemend=i;
thequantity=fulllist.substring(itemstart,itemend);
itemtotal=0;itemtotal2=0;
if (theAP!='none')
{if (currency==1)
{tempprice=getAdvanced(theAP,1,thequantity);
if (tempprice>0)
theprice=tempprice;}
if (currency==2)
{tempprice=getAdvanced(theAP,2,thequantity);
if (tempprice>0)
theprice2=tempprice;}}
itemtotal=(eval(theprice*thequantity));
weighttotal=(eval(theweight*thequantity));
temptotal=itemtotal*100;
totprice=totprice+itemtotal;
totweight=totweight+weighttotal;
itemlist=itemlist+1;
document.writeln('<tr><td><font face="Arial" size=2>'+theitem+'</font></td>');
document.writeln('<td align=right><font face="Arial" size=2>'+presentValue(eval(theprice))+'</font></td>');
document.writeln('<td align=right><font face="Arial" size=2><input type=text name="quant'+itemlist+'" value='+thequantity+' size=3></font></td>');
document.writeln('<td align=right><font face="Arial" size=2>'+presentValue(itemtotal)+'</font></td>');
document.writeln('<td align=right><a href="javascript:removeItem('+itemlist+')"><font face="Arial" size=2>Remove</font></a></td></tr>');}
else if (fulllist.substring(i,i+1)=='|')
{if (thisitem== 1)
theitem=fulllist.substring(itemstart,i);
if (thisitem== 2)
theprice=fulllist.substring(itemstart,i);
if (thisitem== 3)
thetaxable=fulllist.substring(itemstart,i);
if (thisitem== 4)
theweight=fulllist.substring(itemstart,i);
if (thisitem== 5)
theAP=fulllist.substring(itemstart,i);
thisitem++; itemstart=i+1;}}
document.writeln('<tr><td colspan=3><font face="Arial" size=2><b>Total Goods</b></font></td>');
document.writeln('<td align=right><font face="Arial" size=2><b>'+presentValue(totprice)+'</b></font></td>');
document.writeln('<td align=right><font face="Arial" size=2><b>&nbsp;</b></font></td>');
document.writeln('</tr>');
document.writeln('</table><br>');}

function removeItem(itemno)
{newItemList=null;
itemlist=0;
for(var i=0;i<=fulllist.length;i++)
{if (fulllist.substring(i,i+1)=='[')
{itemstart=i+1;}
else
if (fulllist.substring(i,i+1)==']')
{itemend=i;
theitem = fulllist.substring(itemstart,itemend);
itemlist=itemlist+1;
if(itemlist != itemno)
{newItemList = newItemList+'['+fulllist.substring(itemstart,itemend)+']';}}}
index = document.cookie.indexOf('TheBasket');
document.cookie='TheBasket='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
self.location = 'https://www.microexpress.net/basket.asp';}

function clearBasket()
{if (confirm('Are you sure you wish to clear the basket?'))
{index=document.cookie.indexOf('TheBasket');
document.cookie='TheBasket=.';
self.location='https://www.microexpress.net/basket.asp';}}

function changeCurrency(num)
{index=document.cookie.indexOf('TheCurrency');
document.cookie='TheCurrency='+num+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
self.location='https://www.microexpress.net/basket.asp';}

function updateBasket()
{newItemList='';
itemlist=0;
for(var i=0;i<=fulllist.length; i++)
{if(fulllist.substring(i,i+1)=='[')
{thisitem=1;
itemstart=i+1;
fullstart=i+1;}
else
if (fulllist.substring(i,i+1)==']')
{itemend=i;itemlist++;
thiselement=document.basketform.elements['quant'+itemlist].value;
newItemList=newItemList+'['+partList+'|'+thiselement+']'}
else
if (fulllist.substring(i,i+1)=='|')
{partList=fulllist.substring(itemstart,i);}}
index=document.cookie.indexOf('TheBasket');
document.cookie='TheBasket='+newItemList+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
self.location='https://www.microexpress.net/basket.asp';}