	var NS4 = document.layers
	var NS6 = document.getElementById && !document.all
	var IE4 = document.all

	var arrExtraPrice = new Array();
	var arrExtraName  = new Array();

	/*
		Check that Date, Name, Delivery Address and Message have been filled in
	*/
	function CheckForm(strProduct)
	{
		objForm  = document.forms['BasketForm'].elements;
		strError = '';
		
		if(objForm.vchDate.value == 'dd/mm/yyyy - click to change')
		{
			strError += "\n + You must select a delivery date";
		}
		
		if(objForm.vchName.value == '')
		{
			strError += "\n + You must enter a delivery name";
		}
		
		if(objForm.vchAddress.value == '')
		{
			strError += "\n + You must enter a delivery House and Street";
		}
		
		if(strError != '')
		{
			alert("The following fields must be changed prior to adding\n"+strProduct+" to your basket\n"+strError);
			return false;
		}
		return true;
	}
	
	
	function BuildName()
	{	
		strProductName  = document.forms['BasketForm'].vchProductName_Original.value;
		strProductDate  = document.forms['BasketForm'].vchDate.value;
		strProductTo    = document.forms['BasketForm'].vchName.value;
		
		strProductName  += ' delivered to '+strProductTo+' on '+strProductDate;

		document.forms['BasketForm'].vchProductName.value = strProductName;
	}
	
	
	function BuildSize()
	{	
		strStreet  = document.forms['BasketForm'].vchAddress.value;
		strStreet  = strStreet.replace(/\r/, '');
		strStreet  = strStreet.replace(/\n/, ', ');
		
		strAddress = document.forms['BasketForm'].vchTown.value;
		arrAddress = strAddress.split(',');
		strTown    = arrAddress[0];
		
		strStreet  += ', '+strTown;

		document.forms['BasketForm'].vchSize.value = strStreet;
	}
	
	
	function BuildColour()
	{	
		strMessage      = document.forms['BasketForm'].vchMessage.value;
		strMessage      = strMessage.replace(/\r/, '');
		strMessage      = strMessage.replace(/\n/, ', ');
		
		document.forms['BasketForm'].vchColour.value = strMessage;
	}

	/*
		This function retrieves all selected extras for the current product and
	*/
	function UpdateTotalPrice()
	{
		arrElements     = document.forms['BasketForm'].elements;
		strProductCode  = document.forms['BasketForm'].vchProductCode_Original.value;
		floPrice        = format2dp(document.forms['BasketForm'].floBasePrice.value);
		floExtras       = 0;
		strExtraContent = '';

		for(intLoop=0; intLoop < arrElements.length; intLoop++)
		{
			if(arrElements[intLoop].name.substring(0, 6) == 'Extra_')
			{
				objCheckbox = arrElements[intLoop];
				if(objCheckbox.checked == true)
				{
					strExtraCode    = objCheckbox.value;
					strProductCode += '+' + strExtraCode;
					floExtras      += parseInt(arrExtraPrice[strExtraCode] * 100);
					strExtraContent += '<br>&nbsp; &nbsp; + &nbsp;'+arrExtraName[strExtraCode];
				}
			}
			//alert(arrElements[intLoop].name);
		}
		strAddress  = document.forms['BasketForm'].vchTown.value;
		arrAddress  = strAddress.split(',');
		strTown     = arrAddress[0];
		floDelivery = parseInt(arrAddress[1] * 100);
        
        /*
            Need to determine if we are on a sunday...
        */
        strDate = document.forms['BasketForm'].vchDate.value;
        if(strDate != 'dd/mm/yyyy - click to change')
        {
            arrDate = strDate.split('/');
            objDate =new Date();
            objDate.setDate(arrDate[0]);
            objDate.setMonth(arrDate[1]-1);
            objDate.setFullYear(arrDate[2]);
            
            if(objDate.getDay() == 0)
            {
                floExtras       += 300;
                strExtraContent += '<br>&nbsp; &nbsp; + &nbsp;Sunday Delivery (&pound;3 surcharge)';
            }
        }
        		
		floPrice = format2dp((parseInt(floPrice * 100) + floExtras + floDelivery)/100);
		document.forms['BasketForm'].vchProductCode.value = strProductCode;
		document.forms['BasketForm'].floPrice.value       = floPrice;
		
		SetDIVContent('PriceToPay', '&pound;'+floPrice);
		
		if(strExtraContent != '')
		{
			strExtraContent = '<br/><b>This price includes the following extras:</b>'+strExtraContent;
		}
		SetDIVContent('ExtraDisplay', strExtraContent);
	}

	function format2dp(value)
	{
		if(value == 0)
		{
			return '0.00';
		}

		var tmpValue  = String(parseInt(0.05 + value * 100));
		var intLength = tmpValue.length;
		return tmpValue.substring(0, intLength-2) + '.' + tmpValue.substr(intLength-2, 2);
	}

	function SetDIVContent(strDIVName, strContent)
	{
		if(NS4)
		{
			objContent = eval("document."+strDIVName);
			objContent.document.write(strContent);
			objContent.document.close();
		}
		if(NS6)
		{
			document.getElementById(strDIVName).innerHTML=strContent;
		}
		if(IE4)
		{
			document.all(strDIVName).innerHTML=strContent;
		}
	}



	function GetDIVContent(strDIVName)
	{
		if(NS6)
		{
			return document.getElementById(strDIVName).innerHTML;
		}
		if(IE4)
		{
			return document.all(strDIVName).innerHTML;
		}
	}

