var items=0;
itemValue = new Array;
var ordValChk=1;
var paytotal=0;
var allItems ="";
var dev='RM';

function setCookie(name, value) {
document.cookie = name + "=" + escape(value) + ";path=/;";
}

function royalmail()
{
dev='RM';
alert("Delivery will be by Royal Mail (or ParcelForce48 for larger orders).");
totalise(line);
}

function parcelforce()
{
dev='PF';
alert("Delivery by ParcelForce24 is recommended, though we have to make an additional charge of £3.85 to cover the extra cost. Your order, once in stock, will also receive priority handling.");
totalise(line);
} 

function goforit()
{
if(confirm("Submit this order for processing?"))
	{
	var check=totalise(1);
	if(check==-1)
		{return false;}
	else
		{
		if(ordValChk==0)
			{
			alert("No items have been ordered.");
			return false;
			}
		if(document.Order_Form.email.value=="" || document.Order_Form.realname.value=="")
			{
			alert("We need to have both your name and email address so that we can contact you!");
			return false;
			}
		else
			{
			setCookie("concession",document.Order_Form.Concession.value);
			setCookie("full",document.Order_Form.Full.value);
			setCookie("total",document.Order_Form.Order_Value.value);
			setCookie("reference",document.Order_Form.orderref.value);
			setCookie("email",document.Order_Form.email.value);
			setCookie("name",document.Order_Form.realname.value);
			setCookie("firstline",document.Order_Form.Address1.value);
			setCookie("secondline",document.Order_Form.Address2.value);
			setCookie("posttown",document.Order_Form.PostTown.value);
			setCookie("postcode",document.Order_Form.PostCode.value);
			setCookie("country",document.Order_Form.Country.value);
			setCookie("phone",document.Order_Form.Phone.value);
			waitforit();
			}
		}
	}
	else	{return false};
}

function waitforit()
{document.Order_Form.SendForm.value="Processing..";}

function totalise(items)
{

document.Order_Form.Concession_Total.value = document.Order_Form.Concession.value*5;

document.Order_Form.Full_Total.value = document.Order_Form.Full.value*7.5;

document.Order_Form.Order_Value.value = parseFloat(document.Order_Form.Concession_Total.value) + parseFloat(document.Order_Form.Full_Total.value);

}



function old()
{
var i=0;
var tot=0;
items += i;
var ltot=0;
var tline=1;
var ordVal=0;
var del=0;

allItems = "";
while (i<items)
	{
	if(document.Order_Form.elements[i].value)
		{
		if (isNaN(document.Order_Form.elements[i].value))
			{
			alert("An item quantity contains a character that is not a number (indicated by '>').  Please insert a number and then click the 'Recalculate' button.  Thank you.");
			tmp=document.Order_Form.elements[i].value;
			document.Order_Form.elements[i].value = '>' + tmp
			i=items;
			tot=0;
			}
		else
			{
			ltot = document.Order_Form.elements[i].value;
	allItems += (document.Order_Form.elements[i].name + document.Order_Form.elements[i].value + ':');
			ordVal += (itemValue[tline]*ltot);
			tot += ltot;
			i++;
			tline++;
			}
		}
	}

if (ordVal==0)
	{
	ordValChk=0;
	alert("Your Basket is Empty!");
	}
else	{
	ordValChk=1;
	}



document.Order_Form.order.value=parseFloat(ordVal/100);

if (ordVal>0)
	{
	if (dev!="PF")
		{
		ext = 0;
		document.Order_Form.ParcelForce.value='0.00';
		}
	else
		{
		ext = 385;
		document.Order_Form.ParcelForce.value='3.85';
		}
	del = 795;
	document.Order_Form.PandP.value='7.95';
	ordVal += del;
	ordVal += ext;
	ordVal += 100000;
	strOrdVal = String(ordVal);
	poundVal = strOrdVal.slice(1,4);
	penceVal = strOrdVal.slice(4,6)
	OrdVal = poundVal + '.' + penceVal;;
	document.Order_Form.total.value=OrdVal;
	paytotal= (parseInt(((OrdVal - (parseInt(document.Order_Form.credit.value*100)/100))+0.00005)*100))/100;
	document.Order_Form.amount.value=paytotal;
	}
}
