function order() {
    if (ordertotal==0) {
	    alert("Zero Order Value - Cannot Purchase!");
		goShopping();
		return
	}
    ilist='';
    ilist=ilist+retrieveCookie('TheBasketCode',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketName',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketWeight',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketTaxable',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketPrice',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketExtraFields',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketAdvanced',0,0)+'^';
    ilist=ilist+retrieveCookie('TheBasketQuantity',0,0)+'^';
    ilist=ilist+retrieveCookie('TheCurrency',0,0)+'^';
    ilist=changeUnwanted(ilist);
    ilist=escape(ilist);
    ilist=changePercent(ilist);
    top.name=ilist;
	top.location='secure/order.htm';//    top.location='https://www.secure-server-hosting.com/secutran/secureforms/SH205273/order.htm ';
}
function changeUnwanted(tstring) {
    nstring='';
    for (var i=0; i <= tstring.length; i++) {
        nchar=tstring.charAt(i);
        if (nchar=='*') { nchar='!&1'; }
        if (nchar=='+') { nchar='!&2'; }
        if (nchar=='@') { nchar='!&3'; }
        if (nchar=='.') { nchar='!&4'; }
        if (nchar=='/') { nchar='!&5'; }
        if (nchar=='-') { nchar='!&6'; }
        nstring=nstring+nchar;
    }
    return nstring;
}
function changePercent(tstring) {
    nstring='';
    for (var i=0; i <= tstring.length; i++) {
        nchar=tstring.charAt(i);
        if (nchar=='%') { nchar='_'; }
        nstring=nstring+nchar;
    }
    return nstring;
}
function removeFromCookie(thecookie,thenumber) {
    fulllist=retrieveCookie(thecookie,0,0);
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
            itemvalue=fulllist.substring(itemstart,i);
            if (thisitem!=thenumber) {
                newcookie=newcookie+itemvalue+'|';
            }
            itemstart=i+1;
        }
    }
    if (newcookie=='') { newcookie='.'; }
    document.cookie=thecookie+'='+newcookie+'; expires='+today;
}
function changeCookieValue(thecookie,thenumber,thevalue) {
    fulllist=retrieveCookie(thecookie,0,0);
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
            itemvalue=fulllist.substring(itemstart,i);
            if (thisitem==thenumber) {
                itemvalue=thevalue;
            }
            newcookie=newcookie+itemvalue+'|';
            itemstart=i+1;
        }
    }
    document.cookie=thecookie+'='+newcookie+'; expires='+today;
}
function removeItem(itemno) {        
	if (confirm('Are you sure you want to remove this item?')) {        
		removeFromCookie('TheBasketCode',itemno);        
		removeFromCookie('TheBasketName',itemno);        
		removeFromCookie('TheBasketWeight',itemno);        
		removeFromCookie('TheBasketTaxable',itemno);        
		removeFromCookie('TheBasketPrice',itemno);        
		removeFromCookie('TheBasketExtraFields',itemno);       
		removeFromCookie('TheBasketAdvanced',itemno);        
		removeFromCookie('TheBasketQuantity',itemno);        
		self.location = 'check_basket.htm';        
	}    
}    
function clearBasket() {        
	if (confirm('Are you sure you wish to clear the basket?')) {            
		index=document.cookie.indexOf('TheBasket');            
		document.cookie='TheBasketCode=.;  		expires='+today;            
		document.cookie='TheBasketName=.; 		expires='+today;            
		document.cookie='TheBasketWeight=.; 	expires='+today;            
		document.cookie='TheBasketTaxable=.; 	expires='+today;            
		document.cookie='TheBasketPrice=.; 		expires='+today;            
		document.cookie='TheBasketExtraFields=.; expires='+today;            
		document.cookie='TheBasketAdvanced=.; 	expires='+today;            
		document.cookie='TheBasketQuantity=.; expires='+today;            
		self.location='check_basket.htm';        
	}    
}    
function updateBasket() {        
	newItemList='';        
	itemlist=0;        
	for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {            
		if (!isNaN(document.basketform.elements['quant'+i].value)) {                
			changeCookieValue('TheBasketQuantity',i,eval(document.basketform.elements['quant'+i].value));            
		}        
	}        
	self.location='check_basket.htm';    
}
function showBasket() {   
    totprice=0;shippingtotal=0;taxtotalone=0;taxtotaltwo=0;ordertotal=0;taxablestandard=0;taxablesecond=0;taxable=0;totalforshipping=0;
	sepchar='"';   totprice=0;
	if (retrieveCookieCount('TheBasketCode')==0) {
		document.writeln('<p class="empty">... is empty !</p>');
	} else {
	document.writeln('<table class="basket" align="center" cellspacing="0" cellpadding="3" border="0" bordercolor="#000000">');   
	document.writeln('<tr class="bhdr">');
	document.writeln('<td class="bhdr">Code</td>');
	document.writeln('<td class="bhdr">Description</td>');
	document.writeln('<td class="bhdrr">Qty</td>');
	document.writeln('<td class="bhdrr">&nbsp;Item Cost</td>');
	document.writeln('<td class="bhdrr">&nbsp;Total Cost</td>');
	document.writeln('<td class="bhdrr">&nbsp;Action</td>');
	document.writeln('</tr>');   
	for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {
		theCode=retrieveCookie('TheBasketCode',i,0); 
		theName=retrieveCookie('TheBasketName',i,0); 
		theWeight=retrieveCookie('TheBasketWeight',i,0); 
		theTaxable=retrieveCookie('TheBasketTaxable',i,0); 
		thePrice=retrieveCookie('TheBasketPrice',i,0); 
		theAP=retrieveCookie('TheBasketAdvanced',i,0); 
		theQuantity=retrieveCookie('TheBasketQuantity',i,0);       
		itemtotal=eval(theQuantity)*eval(thePrice); 
		totprice=eval(totprice+itemtotal);      
		if (theTaxable==1) taxablestandard=taxablestandard+itemtotal;
        if (theTaxable==2) taxablesecond=taxablesecond+itemtotal;
        totalforshipping=totalforshipping+(eval(theQuantity)*eval(theWeight));
		document.writeln('<td class="bleft">'+theCode+'</td>');       
		document.writeln('<td class="bleft">'+theName+'</td>');       
		document.writeln('<td class="bright"><input class="formtxtr" type=text name="quant'+i+'" size="2" value="'+theQuantity+'" onChange="updateBasket();"></td>');      
		document.writeln('<td class="bright">'+showPrice(thePrice,"£")+'</td>');       
		document.writeln('<td class="bright">'+showPrice(itemtotal,"£")+'</td>'); 
		strCmd="MM_swapImage('Add"+i+"','','images/Remove_Over.gif',1)" 
		document.writeln('<td class="bright"><input type=image name="add'+i+'" onClick="removeItem('+i+');" value="Remove" onMouseOver="'+strCmd+'" onMouseOut="MM_swapImgRestore()"  src="images/Remove.gif" width="45" height="14" border="0"></td>');       
		document.writeln("</tr>");   
	} 
	document.writeln('<tr>');   
	document.writeln('<td height="1"><img src="images/spacer.gif" height="1" width="60"</td>');   
	document.writeln('<td height="1"><img src="images/spacer.gif" height="1" width="350"</td>');
	document.writeln('<td height="1"><img src="images/spacer.gif" height="1" width="15"</td>');
	document.writeln('<td height="1"><img src="images/spacer.gif" height="1" width="80"</td>');
	document.writeln('<td height="1"><img src="images/spacer.gif" height="1" width="80"</td>');
	document.writeln('<td height="1"><img src="images/spacer.gif" height="1" width="50"</td>');
	document.writeln('</tr>');   
	recalculateShipping(); 
	recalculateTax();
	document.writeln('<tr>');   
	document.writeln('<td class="btotal" colspan=4>Total Goods</td>');   
	document.writeln('<td class="btotal">'+showPrice(totprice,"£")+'</td>');   
	document.writeln('<td class="btotal">&nbsp;</td>');   
	document.writeln('</tr>');  
	document.writeln("<tr>");
    document.writeln('<td class="btotal" colspan=4>Delivery Charge</td>');
    document.writeln('<td class="btotal">'+showPrice(shippingtotal,"£")+'</td>');
	document.writeln('<td class="btotal">&nbsp;</td>');   
    document.writeln('</tr>');
    document.writeln('<tr>');
    document.writeln('<td class="btotal" colspan=4>Total VAT</td>');
    document.writeln('<td class="btotal">'+showPrice(ordertax,"£")+'</td>');
    document.writeln('<td class="btotal">&nbsp;</td>');   
    document.writeln('</tr>');
    document.writeln('<tr>');
    document.writeln('<td class="btotal" colspan=4>Order Total</td>');
    document.writeln('<td class="btotal">'+showPrice(ordertotal,"£")+'</td>');
	document.writeln('<td class="btotal">&nbsp;</td>');   
    document.writeln('</tr>');
 	document.writeln('</table><br>');  
	document.writeln('<center><br>'); 
	document.writeln("<input type=image name='clearbasket' onClick='clearBasket();' value='Empty Basket' src='images/empty_basket.gif' height='20' width='90'>&nbsp;");   
	document.writeln("<input type=image name='updatebasket' onClick='updateBasket();' value='Update Basket' src='images/update_basket.gif' height='20' width='90'>");
	document.writeln('</center>'); 
	}
}

