oMax=parent.header.eval("oMax");
oColours=parent.header.eval("oColours");
oNum=parent.header.eval("oNum");
mCurrentrate=parent.header.eval("mCurrentrate");
dCurrentsymbol=parent.header.eval("dCurrentsymbol");
mPnp=parent.header.eval("mPnp");

Order =new OrderSheet;
load();
if(oNum>0) { display(); } else { empty(); }

function deleteItem(itemnum) {
parent.header.eval("oNum--;");
if(itemnum<oNum) {
for (i=itemnum; i<oNum; i++ ) {
parent.header.eval('CurrentOrder.quantity['+(i+1)+']=CurrentOrder.quantity['+(i+2)+']');
parent.header.eval('CurrentOrder.name['+(i+1)+']=CurrentOrder.name['+(i+2)+']');
parent.header.eval('CurrentOrder.goldsilver['+(i+1)+']=CurrentOrder.goldsilver['+(i+2)+']');
parent.header.eval('CurrentOrder.description['+(i+1)+']=CurrentOrder.description['+(i+2)+']');
parent.header.eval('CurrentOrder.unitprice['+(i+1)+']=CurrentOrder.unitprice['+(i+2)+']');

} } }


function load() {
for (i=0; i<oNum; i++) {
Order.quantity[i]    = parent.header.eval("CurrentOrder.quantity["   +(i+1)+"]"); 
Order.name[i]        = parent.header.eval("CurrentOrder.name["       +(i+1)+"]"); 
Order.goldsilver[i]  = parent.header.eval("CurrentOrder.goldsilver[" +(i+1)+"]"); 
Order.description[i] = parent.header.eval("CurrentOrder.description["+(i+1)+"]"); 
Order.unitprice[i]   = parent.header.eval("CurrentOrder.unitprice["  +(i+1)+"]"); 
Order.link[i]        = parent.header.eval("CurrentOrder.link["       +(i+1)+"]"); 
}
}

function OrderSheet() {
this.quantity       =new Array(oMax);
this.name          =new Array(oMax);
this.goldsilver    =new Array(oMax);
this.description   =new Array(oMax);
this.unitprice     =new Array(oMax);
this.unittotal     =new Array(oMax);
this.colour        =new Array(oMax);  
this.colour[1]     =new Array(oColours);
this.colour[2]     =new Array(oColours);
this.colour[3]     =new Array(oColours);
this.colour[4]     =new Array(oColours);
this.link          =new Array(oMax);
}


function display() {
mSubTotal=0;
document.write('<body bgcolor="#F0EEFF" leftmargin="0" background="images/celtic.jpg" bgproperties="fixed">');
document.write('<div align="center"><center><table border="0" width="750" cellspacing="0" cellpadding="0"><tr><td width="100%"><p align="center"><strong>To change the number of items in your cart, type the number and click Change beside that item.<br>');
document.write('To delete an item, change the quantity to zero and click change beside that item.<br>When you are happy with your choice of Tiaras, click My Details to continue.</strong></td></tr></table></center></div>');
document.write('<div align="center"><center><form name="cart"><table border="1" bordercolorlight="#F6F5FF" bordercolordark="#D2CDFF" cellpadding="4">');
for (i=0; i<oNum; i++) {
mSubTotal=mSubTotal+(Order.unitprice[i]*Order.quantity[i]);
document.write('<tr><td width="100%"><table border="0" width="734"><tr>');
document.write('<td width="109" height="17" align="center"><strong>');
document.write('<input type="button" value="Change" onclick="change('+i+');"><input type="text" name="location'+i+'" size="2" value="'+Order.quantity[i]+'"></strong></td>');
document.write('<td width="464"><a href="tiaras/'+Order.link[i]+'">'+Order.name[i]+'</a> in '+Order.goldsilver[i]+" -- "+Order.description[i]+'</td>');
document.write('<td width="90" height="17" align="right"><font face="Arial">'+         CurrencyRound(Order.unitprice[i])+'</font></td>');
document.write('<td width="90" height="17" align="right"><font face="Arial">'+         CurrencyRound((Order.unitprice[i]*Order.quantity[i]))+'</font></td>');
document.write('</tr></table></td></tr>');
}

document.write('</table><table border="0" width="734"><tr><td width="644"><font face="Arial"><p align="right">');
document.write('subtotal:</p></td><td><p align="right"><font face="Arial">');
document.write('<b>'+CurrencyRound(mSubTotal)+'</b>');
document.write('</p></font></td></tr></form></table></center></div>');
document.write('</body>');
}


//                                                                                           CURRENCY ROUND
// Round any number to 2 dps
function CurrencyRound(CurrencyValue) {
RoundedValue=(CurrencyValue*100*mCurrentrate);
RoundedValue=Math.round(RoundedValue);
RoundedValue=(RoundedValue/100);
Round10=(RoundedValue*10);

//add 0s to end of number if missing
extraDP=""
if(parseInt(Round10) ==Round10)  { extraDP="0";  } 
if(parseInt(RoundedValue)==RoundedValue) { extraDP=".00"; }
RoundedValue=dCurrentsymbol+RoundedValue+extraDP;

return RoundedValue;
}

//                                                                                           CHANGE VALUE
function change(location) {
ErrorFound=false;
Product=Order.name[location];
quantity=eval("document.cart.location"+location+".value");
if (quantity=="") { quantity="0"; }

if(!ErrorFound) { if (quantity<0) { LowQuantityError(Product,quantity); } }
if(!ErrorFound) { if (quantity==parseInt(quantity)) { null; } else { LowQuantityError(Product,quantity); } }
if(!ErrorFound) { HighQuantityCheck(Product,quantity); }
if(!ErrorFound) { if (quantity==0) { deleteItem(location); } else { parent.header.eval("CurrentOrder.quantity["+(location+1)+"]="+quantity+";"); }
window.location.reload();
} }

function LowQuantityError(Product,num) {
alert("Sorry, you have chosen "+num+" "+Product+" Tiaras.\nPlease enter a valid number.");
ErrorFound=true;
}

function HighQuantityCheck(Product,num) {
if (quantity>8) {
if(!confirm("Are you SURE you wish to order "+num+" "+Product+" Tiaras?")) {ErrorFound=true; } } }



//                                                                                           SHOPPING CART EMPTY

function empty() {
document.write('<body bgcolor="#F0EEFF" background="images/celtic.jpg">');
document.write('<p align="center">&nbsp;</p>');
document.write('<p align="center">&nbsp;</p>');
document.write('<p align="center"><big><big><big>Your Shopping Cart is empty<br><br>');
document.write('</big><a href="cat.htm"><font face="Arial">START BY VISITING THE CATALOGUE</font></a></big></big></p>');
document.write('<p>&nbsp;</p>');
document.write('</body>'); }


