<!--Canoldir version 1.0 -->

function checkChoice(whichbox) {

with (whichbox.form) {
//Identify the previous quantity option choice (and associated price) for the selected item
//TO ADD A PRODUCT..copy and paste an 'if' statement, amend "quantitynn"(two instances) and price
if (whichbox.name == "quantity01") {
whichbox.price = 10.20;
whichbox.priorval = quantity01.priorval;
};
if (whichbox.name == "quantity02") {
whichbox.price = 10.20;
whichbox.priorval = quantity02.priorval;
};
if (whichbox.name == "quantity03") {
whichbox.price = 10.20;
whichbox.priorval = quantity03.priorval;
};
if (whichbox.name == "quantity04") {
whichbox.price = 10.20;
whichbox.priorval = quantity04.priorval;
};
if (whichbox.name == "quantity05") {
whichbox.price = 10.20;
whichbox.priorval = quantity05.priorval;
};
if (whichbox.name == "quantity06") {
whichbox.price = 10.20;
whichbox.priorval = quantity06.priorval;
};

//subtract the amount associated with the previous quantity option choice for the selected item
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);

//add the amount associated with the current quantity option choice for the selected item
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);

//Re-set the previous quantity option choice for the selected item (in preparation for the next quantity option choice)TO ADD A PRODUCT..copy and paste an 'if' statement, amend "quantitynn"(two instances) 
if (whichbox.name == "quantity01") {
quantity01.priorval = whichbox.value;
};
if (whichbox.name == "quantity02") {
quantity02.priorval=whichbox.value;
};
if (whichbox.name == "quantity03") {
quantity03.priorval = whichbox.value;
};
if (whichbox.name == "quantity04") {
quantity04.priorval=whichbox.value;
};
if (whichbox.name == "quantity05") {
quantity05.priorval=whichbox.value;
};
if (whichbox.name == "quantity06") {
quantity06.priorval=whichbox.value;
};

return(formatCurrency(hiddentotal.value));
}
}


function formatCurrency(num) {
//<!-- Function courtesy of: Cyanide_7 (leo7278@hotmail.com) -->
//<!-- Web Site: http://www7.ewebcity.com/cyanide7 -->
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
pence = Math.floor((num * 100 + 0.5) % 100);
num = Math.floor((num * 100 + 0.5) / 100).toString();
if(pence < 10) pence = "0" + pence;
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
num = num.substring(0,num.length - (4 * i + 3))+','+num.substring(num.length-(4 * i + 3));
return ("£" + num + "." + pence);
}


function InitForm() {
document.myform.total.value = '£0.00';
document.myform.hiddentotal.value = 0.00;
document.myform.price=0.0;
document.myform.quantity01.priorval=0.0;
document.myform.quantity02.priorval=0.0;
document.myform.quantity03.priorval=0.0;
document.myform.quantity04.priorval=0.0;
document.myform.value=0.0;

//initialise selection option boxes - one for each item eg 0 to 1 for 2 items, 0 to 2 for 3 items TO ADD A PRODUCT...increment the <n value by 1
for (xx = 0; xx < 5; xx++) {
if (document.myform.elements[xx].type == 'text') {
document.myform.elements[xx].value = "0";
}
}
}
