function MakeTen(expr,decimal){
	var str="" + Math.round(eval(expr) * Math.pow(10,decimal))
	while (str.length <= decimal){
	   str = "0" + str
	}
	var decpoint = str.length - decimal
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function MakeTwo(expr){
	return "£" + MakeTen(expr,2)
}
function GetScrew(vname,vvalue){
         var str = vname;
         if (str.substring(0,1) == '.') 
             {return vvalue;}
         else {return 0;}
}


function Getpipe(vname,vvalue){
         var str = vname;
         if (str.substring(0,1) == '-') 
             {return vvalue;}
         else {return 0;}
}

function getrefno(loc) {
var today = new Date();
var vsec1 = today.getMilliseconds();var vmin = today.getMinutes();var vsec = today.getSeconds(); var vday = today.getDay();
loc.cartId.value = (vday+'-'+vsec+vmin+vsec1);
                    }

function GetSeaCock(vname,vvalue){
         var str = vname;
         if (str.substring(0,8) == 'Sea Cock') 
             {return vvalue;}
         else {return 0;}
}

       function checkout(loc) {
                totline  = '';
                index = document.cookie.indexOf("MyCart");
                countbegin = (document.cookie.indexOf("=", index) + 1);
                countend = document.cookie.indexOf(";", index);
                if (countend == -1) {
                        countend = document.cookie.length;
                }
               fulllist = document.cookie.substring(countbegin, countend);
                wpdesc ='';
	 totprice = 0;
                totval = 0;
                itemlist = 0;
                pipeval = 0;
                seaval = 0;
                screwval = 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;
                                descline = 0;
                                totpay =0;
                                thequantity = fulllist.substring(itemstart, itemend);
                                itemtotal = 0;
                                itemtotal = (eval(theprice*thequantity));
                                pipeval = (eval(Getpipe(theitem,itemtotal)))+pipeval;
                                seaval =(eval(GetSeaCock(theitem,itemtotal)))+seaval;
                                screwval =(eval(GetScrew(theitem,itemtotal)))+screwval;

                                temptotal = itemtotal * 100;
                                totprice = totprice + itemtotal;
                                itemlist=itemlist+1;
wpdesc = wpdesc + thequantity+'->'+theitem+' '+theoption+' \n';
descline =+thequantity+'  of  '+theitem+' - '+theoption+' \t'+MakeTwo(itemtotal)+ '\n';
totline = totline + descline;                           
                        } else if (fulllist.substring(i,i+1) == ',') {
                                theitem = fulllist.substring(itemstart, i);
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == '^') {
                                theprice = fulllist.substring(itemstart, i);
                                itemstart = i+1;
                        } else if (fulllist.substring(i,i+1) == '~') {
                                theoption = fulllist.substring(itemstart, i);
                                itemstart = i+1;
                        }
                }
		if (screwval >'0' )
		    {if (screwval <'10') {
                 descline = ' Postage for fasteners '+'\t'+                   '£1.50'+'\n';
                 totline = totline + descline
                 totprice = totprice + 1.5;
		                        }
      }
		if (screwval >'10' )
		    {if (screwval <'30') {
		   descline = ' Postage for fasteners  '+'\t'+                '£3.00'+'\n';
                 totline = totline + descline
                 totprice = totprice + 3;
		                        }
      }
		if (screwval >'30' )
		    {if (screwval <'60') {
		   descline = ' Postage for fasteners   '+'\t'+                 '£6.00'+'\n';
                 totline = totline + descline
                 totprice = totprice + 6;
		                        }
      }
		if (screwval >'60' )
		    {if (screwval <'120') {
		 descline = ' Postage for fasteners '+'\t'+                   '£9.00'+'\n';
                 totline = totline + descline
                 totprice = totprice + 9;

		                        }
      }
		if (screwval >'120' )
		    {
	   descline = ' Free Postage for fasteners                '+'\n';
                 totline = totline + descline;
		     }

 	if (pipeval >'0' )
		    {if (pipeval <'10') {
		     totprice = totprice + 3;
                  descline = ' Postage for fittings  '+'\t'+                  '£3.00'+'\n';
                 totline = totline + descline;
		                        }
      }
       	if (pipeval >'10' )
		    {if (pipeval <'50') {
		    
		     totprice = totprice + 8;
                  descline = ' Postage for fittings '+'\t'+                   '£8.00'+'\n';
                  totline = totline + descline;
                                }
      }
      	if (pipeval >'50' )
		     {
                  descline = ' Free Postage for fittings '+'\n';
                  totline = totline + descline;
      }
       	if (seaval >'0' )
		    {if (seaval <'50') {
		     totprice = totprice + 5;
                descline = ' Postage for Sea Cocks  '+'\t'+                  '£5.00'+'\n';
                totline = totline + descline;
		                        }
      }
       	if (seaval >'50' )
		    {if (seaval <'100') {
		     totprice = totprice + 10;
                  descline = ' Postage for Sea Cocks   '+'\t'+            '£10.00'+'\n';
		   totline = totline + descline;
                                 }
      }
      	if (seaval >'100' )
		     {
                   descline = ' Free Postage for Sea Cocks  '+'\n';
                   totline = totline + descline;
      }

var today = new Date();
var vsec1 = today.getMilliseconds();var vmin = today.getMinutes();var vsec = today.getSeconds(); var vday = today.getDay();


document.orderForm.MC_order_line.value = totline;
document.orderForm.cartId.value = (vday+'-'+vsec+vmin+vsec1);
document.orderForm.M_cartId.value = (vday+'-'+vsec+vmin+vsec1);
document.orderForm.amount.value = MakeTen(totprice,2);
document.orderForm.M_amount.value = MakeTen(totprice,2);
document.orderForm.desc.value = wpdesc; 

 }


//document.write('<table BORDER=0 CELLSPACING=0 CELLPADDING=0 NOF=LY><tr VALIGN=TOP ALIGN=LEFT>');
//document.write('<td WIDTH=29 HEIGHT=33><img SRC="./clearpixel.gif" WIDTH=29 HEIGHT=1 BORDER=0 ALT=""></td>');
//document.write('<td></td></tr><tr VALIGN=TOP ALIGN=LEFT><td></td><td WIDTH=559><table ID="Table2" ');
//document.write('BORDER=0 CELLSPACING=3 CELLPADDING=1 WIDTH=559><tr><td COLSPAN=4><p><table WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=0 NOF=TE><tr><td ALIGN="CENTER"><textarea WRAP=PHYSICAL ID="Forms Multi-Line1" NAME="MC_order_details" ROWS=6 COLS=60>'+ totline +' </textarea> </td> </tr> </table>');



 

