// SHOPPING CART JAVASCRIPT //


function showBasketButton() {
	// CHECK TO SEE IF THE BASKET IS EMPTY //
	var basket=getCookie('TheBasket');
	if (basket == null) {

		var basket="";
	}else if (basket.length <= 1) {

	}else{
		document.writeln('<tr align="left"><td width="70"></td><td colspan="3"><a href="basket.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'baskety\',\'\',\'img/basket2.gif\',1)"><img src="img/basket1.gif" width="111" height="25" name="baskety" border="0"></a><a href="javascript:goBuy()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'orderformy\',\'\',\'img/orderform2.gif\',1)"><img src="img/orderform1.gif" width="86" height="25" name="orderformy" border="0"></a></td></tr>');
	}


// NEW PAYPAL BASKET //
//	document.writeln('<tr align="left"><td width="70"></td><td colspan="3"><a href="javascript:document.basket.submit();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'baskety\',\'\',\'img/basket2.gif\',1)"><img src="img/basket1.gif" width="111" height="25" name="baskety" border="0" alt="Show Basket"></a><a href="javascript:document.checkout.submit();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'orderformy\',\'\',\'img/orderform2.gif\',1)"><img src="img/orderform1.gif" width="86" height="25" name="orderformy" border="0" alt="Checkout"></a> <form name="basket" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_cart"><input type="hidden" name="business" value="sales@lizzy-b.co.uk"><input type="hidden" name="display" value="1"></form><form name="checkout" target="paypal" method="post" action="https://www.paypal.com/cart/checkout=1&amp;page_style=PayPal"><input name="form_charset" type="hidden" value="windows-1252"></form></td></tr>');
}

// POP-UP WINDOW //
function popup(url,winx,winy,scrollbaryn) {
	newwin=window.open(url, "popup", "width="+winx+",height="+winy+",toolbar=0,status=0,"+scrollbaryn);
	//e.g. <a href="javascript:popup('me.html','300','100','scrollbars');">Open with scroll</a> //
	//e.g. <a href="javascript:popup('me.html','300','100','');">Open without scroll</a> //
}

function dazzlingClubOffer(newItem,newPrice,newTaxable,newWeight,newAP,newQuantity) {

                 if (newAP!='none') {
                     newAP=checkAdvanced(newAP);
                 }
                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);
                 amended = false;
                 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;
                         thequantity=fulllist.substring(itemstart,itemend);
                         itemlist++;
                         if (theItem==newItem ) {
                             amended=true;
                             tempquantity=eval(thequantity)+eval(newQuantity);
                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+newAP+'|'+tempquantity+']';
                         } else {
                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+theAP+'|'+thequantity+']';
                         }
                     } 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;
                     }
                 }
                 if (amended==false) {
                     newItemList=newItemList+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newWeight+'|'+newAP+'|'+newQuantity+']'; }
                 index = document.cookie.indexOf('TheBasket');
                 document.cookie='TheBasket='+newItemList+'; expires=Friday, 31-Dec-2020 08:00:00 GMT';
				window.location.href="basket.htm";


}

function prepareItem(newItem,newPrice,newTaxable,newWeight,newAP,newQuantity) {
	quantity=prompt("Please enter the quantity of "+newItem+"s you require:",1);
	if (quantity != null) {
		while (!isNum (quantity)) {
			if (quantity != null) {
				quantity=prompt("WARNING: You entered more than just a number, or no number at all. Please enter the quantity of "+newItem+"s you require:",1)
			}else{
				break;
			}
		}
	}

	if (quantity != null && quantity != 0) {
		buyItem(newItem,newPrice,newTaxable,newWeight,newAP,quantity);
	}
}

function isNum (str)
{
	if (str != null) {
	    for (var i = 0; i < str.length; i++)
	    {
	     var ch = str.substring(i, i + 1);
	     if (ch < "0" || "9" < ch)
	        return false;
	    }
	    return true;
	}else{
		return false;
	}
}

function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie;             
    if (dc.length > 0) {              
	    begin = dc.indexOf(cname);       
        if (begin != -1) {           
	        begin += cname.length;       
	        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
	return null;
}


// SET EXP VALUE //
var exp = new Date();                                   
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31 * 6));


function setCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value) + "; path=/" +
	((expires == null) ? "" : "; expires=" + expires);
//	((expires == null) ? "" : "; expires=" + expires.toGMTString());
}


// Function to save form element's value.
function setValue(element) {
	setCookie(element.name, element.value, exp);
}


function completeFields() {
	var value = getCookie('surname');
	if (value != null) {
		doit=confirm("You have completed this form once before. Would you like to retrieve the name and address information that you used last time?");
		if (doit == 1) {
			if (value != null) d.f.surname.value = value;
			var value = getCookie('firstname');
			if (value != null) d.f.firstname.value = value;
			var value = getCookie('email');
			if (value != null) d.f.email.value = value;
			var value = getCookie('address1');
			if (value != null) d.f.address1.value = value;
			var value = getCookie('address2');
			if (value != null) d.f.address2.value = value;
			var value = getCookie('towncity');
			if (value != null) d.f.towncity.value = value;
			var value = getCookie('county');
			if (value != null) d.f.county.value = value;
			var value = getCookie('postcode');
			if (value != null) d.f.postcode.value = value;
			var value = getCookie('telephone');
			if (value != null) d.f.telephone.value = value;
			var value = getCookie('cardname');
		}	
	}
}


    function goBuy() {
        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='order_form.htm?items='+ilist;
    }

    function replaceSpaces(tstring) {
        nstring='';
        for(var i=0;i<=tstring.length;i++) {
            if (tstring.charAt(i)=='^') { nstring=nstring+' ';
            } else { nstring=nstring+tstring.charAt(i); }
        }
        return nstring;
    }

    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;
    }

function checkAdvanced(adv) {
     newAdv='';advlist=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) {
                newAdv = newAdv+ '{'+advFrom+'~'+advTo+'~'+advPrice+'~'+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;
        }
    }
    if (newAdv=='') newAdv='none';
    return newAdv;
}
    function buyItem(newItem,newPrice,newTaxable,newWeight,newAP,newQuantity) {
        if(newQuantity<=0) {
            rc = alert('The quantity entered is incorrect');
        } else {
            if (confirm('Add '+newQuantity+' x '+newItem+' to basket? ')) {
                 if (newAP!='none') {
                     newAP=checkAdvanced(newAP);
                 }
                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);
                 amended = false;
                 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;
                         thequantity=fulllist.substring(itemstart,itemend);
                         itemlist++;
                         if (theItem==newItem ) {
                             amended=true;
                             tempquantity=eval(thequantity)+eval(newQuantity);
                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+newAP+'|'+tempquantity+']';
                         } else {
                             newItemList=newItemList+'['+theItem+'|'+thePrice+'|'+theTaxable+'|'+theWeight+'|'+theAP+'|'+thequantity+']';
                         }
                     } 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;
                     }
                 }
                 if (amended==false) {
                     newItemList=newItemList+'['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newWeight+'|'+newAP+'|'+newQuantity+']'; }
                 index = document.cookie.indexOf('TheBasket');
                 document.cookie='TheBasket='+newItemList+'; expires=Friday, 31-Dec-2020 08:00:00 GMT';
				window.location.href="basket.htm";
            }
        }
    }


 taxfield='United Kingdom';
 function showBasket() {
     currency=1;
     index=document.cookie.indexOf('TheBasket');

	// CHECK TO SEE IF THE BASKET IS EMPTY //
	var basket=getCookie('TheBasket');
	if (basket == null) {
		document.writeln('<center><HR><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Your shopping basket is empty.</font></center><HR>');
		var basket="";
	}else if (basket.length <= 1) {
		document.writeln('<center><HR><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Your shopping basket is empty.</font></center><HR>');
	}else{
     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;
     document.writeln('<table border=1 cellpadding=2 cellspacing=0>');
     document.writeln('<tr>');
     document.writeln('<td bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Item</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Price</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Quantity</font></td><td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Total&nbsp;Cost</font></td><td bgcolor=#FFFFFF align=center><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Action</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));
             temptotal=itemtotal*100;
             totprice=totprice+itemtotal;
             itemlist=itemlist+1;
         document.writeln('<tr><td bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+theitem+'</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+presentValue(eval(theprice))+'</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><input type=text name="quant'+itemlist+'" value='+thequantity+' size=3 onChange="updateBasket();"></font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+presentValue(itemtotal)+'</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><input type=button name="remove'+itemlist+'" value="Remove" onClick="removeItem('+itemlist+');" style="font-family: Verdana; size: 2; font-weight:normal;"></font></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;
             }
         }

	// TOTAL GOODS //
     document.writeln('<tr><td colspan=3 bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>Total Goods</i></font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>'+presentValue(totprice)+'</i></font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>&nbsp;</i></font></td>');
     document.writeln('</tr>');


	// DELIVERY //
	delivery=getCookie('delivery');
//	alert(delivery);
	if (delivery == "Recorded") {
		deliv_title="Recorded Delivery";
		deliv_cost="0.64";
		deliv_cost_value=0.64;
//		other_deliv="standard";
		setCookie("delivery", "Recorded", null);
	}else if (delivery == "Special") {
		deliv_title="Special Delivery (Mon-Fri)";
		deliv_cost="5.20";
		deliv_cost_value=5.2;
//		other_deliv="Saturday";
		setCookie("delivery", "Special", null);
	}else{
		delivery == "Standard";
		deliv_title="Standard Delivery";
		deliv_cost="0.00";
		deliv_cost_value=0;
//		other_deliv="Saturday";
		setCookie("delivery", "Standard", null);
	}

     document.writeln('<tr><td colspan=3 bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>'+deliv_title+'</i></font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>£'+deliv_cost+'</i></font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=center><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><select name="changedelivery" onChange="changeDelivery(value)" style="font-family: Verdana; size: 2; font-weight:normal;"><option value="">Change...<option value="">-----------<option value="Standard">Standard<option value="Recorded">Recorded<option value="Special">Special</select></font></td>');
     document.writeln('</tr>');


	// GRAND TOTAL //
	price_total=presentValue(totprice).substring(1,10);
	price_total=parseFloat(price_total);
	new_price=price_total+deliv_cost_value;
	new_price=new_price+".0";
	parts=new_price.split('.');
	pounds=parts[0];
	pence=parts[1];
	pence=pence+"00";
	pence=pence.substring(0,2);
	price_total=pounds+"."+pence;

     document.writeln('<tr><td colspan=3 bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Total Goods</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>£'+price_total+'</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>&nbsp;</font></td>');
     document.writeln('</tr>');



     document.writeln('</table><br>');
     document.writeln('<center><input type=button name=clear value="Empty Basket" onClick="clearBasket();" style="font-family: Verdana; size: 2; font-weight:bold;">');
     document.writeln('<input type=button name=update value="Update Basket" onClick="updateBasket();" style="font-family: Verdana; size: 2; font-weight:bold;"><br><br><input type=button name=shop value="Continue Shopping" onClick="document.location.href=\'lizzy_online_shop.htm\';" style="font-family: Verdana; size: 2; font-weight:bold;color:#00804D;"> <input type=button name=orderfordm value="Order Form" onClick="goBuy();" style="font-family: Verdana; size: 2; font-weight:bold;color:#00804D;"></center>');

	} // THIS IS THE END OF CHECKING THE BASKET IS EMPTY BRACKET//
}



 taxfield='United Kingdom';
 function showOrderFormSummary() {
     currency=1;
     index=self.location.href.indexOf('items');
     countbegin=(self.location.href.indexOf('=',index)+1);
     countend=self.location.href.length;
     fulllist=self.location.href.substring(countbegin,countend);
     fulllist=replaceSpaces(fulllist);
     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;totalforshipping=0;
     document.writeln('<center><table border=1 cellspacing=0 cellpadding=2 width="100%">');
     document.writeln('<tr>');
     document.writeln('<td bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Product Name</b></font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Price</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Quantity</font></td><td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Total Cost</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 (currency==2) theprice=theprice2;
             if (theAP!='none') {
     tempprice=getAdvanced(theAP,currency,thequantity); if (tempprice>0) theprice=tempprice; }
             itemtotal=(eval(theprice*thequantity));
             temptotal=itemtotal*100;
             totprice=totprice+itemtotal;
             if (thetaxable == 0) taxablestandard = taxablestandard + itemtotal;
             if (thetaxable == 1) taxablesecond = taxablesecond + itemtotal;
             totalforshipping = totalforshipping + eval(thequantity);
             itemlist=itemlist+1;
         document.writeln('<tr><td bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+theitem+'</font></td>');
     document.writeln('<input type=hidden name="'+nextField()+'Name'+itemlist+'" value="'+theitem+'"><input type=hidden name="'+nextField()+'Quantity'+itemlist+'" value="'+thequantity+'">');

     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+presentValue(eval(theprice))+'</font></td><input type=hidden name="'+nextField()+'Price'+itemlist+'" value="'+presentValue(eval(theprice))+'">');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+thequantity+'</font></td>');
     document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2">'+presentValue(itemtotal)+'</font></td><input type=hidden name="'+nextField()+'Item Total'+itemlist+'" value="'+presentValue(eval(itemtotal))+'">');
     document.writeln('</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;
             }
         }


	// TOTAL GOODS //
     document.writeln('<tr><td colspan=3 bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>Total Goods <input type=hidden name="numberitems" value="'+itemlist+'"> </font></td>');
     if (currency==1) { document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i> '+presentValue(totprice)+'</font></td>');}
     if (currency==2) { document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i> '+presentValue2(totprice)+'</font></td>');}
     document.writeln('</tr>');


	// DELIVERY //
	delivery=getCookie('delivery');
//	alert(delivery);
	if (delivery == "Recorded") {
		deliv_title="Recorded Delivery";
		deliv_cost="0.64";
		deliv_cost_value=0.64;
//		other_deliv="standard";
		setCookie("delivery", "Recorded", null);
	}else if (delivery == "Special") {
		deliv_title="Special Delivery (Mon-Fri)";
		deliv_cost="5.20";
		deliv_cost_value=5.2;
//		other_deliv="Saturday";
		setCookie("delivery", "Special", null);
	}else{
		delivery == "Standard";
		deliv_title="Standard Delivery";
		deliv_cost="0.00";
		deliv_cost_value=0;
//		other_deliv="Saturday";
		setCookie("delivery", "Standard", null);
	}

	// DELIVERY COSTS //
     document.writeln('<tr><td colspan=3 bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i>'+deliv_title+'<input type="hidden" name="deliv_title" value="'+deliv_title+'"></font></td>');
     if (currency==1) { document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i><input type=hidden name="delivery_cost" value="'+deliv_cost+'">£'+deliv_cost+'</font></td>');}
     if (currency==2) { document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><i><input type=hidden name="delivery_cost" value="'+deliv_cost+'">'+deliv_cost+'</font></td>');}
     document.writeln('</tr>');

	price_total=presentValue(totprice).substring(1,10);
	price_total=parseFloat(price_total);
	new_price=price_total+deliv_cost_value;
	if (new_price == 0) { new_price="0.00";}
	new_price=new_price+".00";
	parts=new_price.split('.');
	pounds=parts[0];
	pence=parts[1];
	pence=pence.substring(0,2);
	price_total=pounds+"."+pence;

	// GRAND TOTAL //
     document.writeln('<tr><td colspan=3 bgcolor=#FFFFFF><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Order Total</font></td>');
     if (currency==1) { document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>£'+price_total+'</b><input type=hidden name="Goods_Total" value="'+price_total+'"></font></td>');}
     if (currency==2) { document.writeln('<td bgcolor=#FFFFFF align=right><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>'+price_total+'</b><input type=hidden name="Goods_Total" value="'+price_total+'"></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-2020 08:00:00 GMT';
		location.reload();
    }

    function clearBasket() {
        if (confirm('Are you sure you wish to clear the basket?')) {
            index=document.cookie.indexOf('TheBasket');
            document.cookie='TheBasket=.';
			setCookie('delivery', "standard", 'Friday, 31-Dec-2020 08:00:00 GMT');
			location.reload();
        }
    }
    function clearBasketNoCheck() {
        index=document.cookie.indexOf('TheBasket');
        document.cookie='TheBasket=.';
		setCookie('delivery', "standard", 'Friday, 31-Dec-2020 08:00:00 GMT');
    }

    function changeCurrency(num) {
         index=document.cookie.indexOf('TheCurrency');
         document.cookie='TheCurrency='+num+'; expires=Friday, 31-Dec-2020 08:00:00 GMT';
		location.reload();
    }

    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-2020 08:00:00 GMT';
		location.reload();
    }

function changeDelivery(type) {
	if (type != "") {
		setCookie('delivery', type, 'Friday, 31-Dec-2020 08:00:00 GMT');
		location.reload();
	}
}
		
    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);
    }

    numFields=0;
    function addFiller(curnum) {
        newnum=parseInt(curnum);
        if (newnum<10) return '00'+newnum;
        if (newnum<100) return '0'+newnum;
        return newnum;
    }

    function nextField() {
        numFields++;
        return addFiller(numFields)+'-';
    }


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;
}
