function writeProduct(type, colour)
{
	var stock = '0';
	var index = (type-1)*20 + colour - 1;
	stock = stockOrderLevels[index];
	var cost = prices[index];
	var cost2 = prices2[index];
	var sale = false;
	var original = '0.00';
	if (type < 4)
	{
		if ( cost != '180.00' && cost != '160.00' )
		{
			sale = true;
			if ( colour == 14 || colour == 15 || colour == 16 )
				original = '180.00';
			else
				original = '160.00';
		}
	}
	if (sale)
		writeSaleProduct(typeNames[type-1], colourNames[colour-1], cost, stock, original, index, cost2);
	else
		writeTheProduct(typeNames[type-1], colourNames[colour-1], cost, stock, index, cost2);
}

function writeTheProduct(type, colour, cost, stock, index, cost2)
{
	var text = '<tr><td height="75" colspan="2" valign="top" style="background-color: '+getColor(index)+';">';
	text += '</td><td colspan="2" valign="top"><span class="heading">';
	text += colour;
	text += '</span><span class="body_text"><br />';
	text += '&pound;'+cost+' per box (inc VAT)';
	text += '<br /></span>';
	text += '<span class="small_print">&pound;'+cost2+' per tile </span>';
	text += '</td>';
	text += '<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td valign="top"><span class="body_text">';
	if (stock.indexOf('hone') == -1) {
		text += getQuantitySelector(type, colour, 'quantity_box') + ' boxes<br>';
		text += getQuantitySelector(type, colour, 'quantity_tile') + ' tiles<br>';
		document.write(text);
		text = '';
		writeCart(type, colour, cost, cost2);
	}
	text += '<br /></span></td><td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td colspan="2" valign="top"><span class="small_print">';
	if (stockLevels[index].indexOf('hone') == -1 && stockLevels[index] > 2)
		text += '<b>';
	text += 'Stock: '+stock;
	if (stock.indexOf('hone') == -1)
		text += ' boxes';
	if (stockLevels[index].indexOf('hone') == -1 && stockLevels[index] > 2)
		text += '</b>';
	text += '<br /><br /></span><span class="body_text"><a onclick="addToRequest(\''+type+'\', \''+colour+'\');">Get a sample</a><br />';
	text += '<a onclick="getMoreInfo(\''+type+'\', \''+colour+'\');">More Info</a></span></td>';
	text += '<td></td><td></td></tr>';
	document.write(text);
}

function writeSaleProduct(type, colour, cost, stock, original, index, cost2)
{
	var text = '<tr><td height="75" colspan="2" valign="top" style="background-color: '+getColor(index)+';">';
	text += '</td><td colspan="2" valign="top"><span class="heading">';
	text += colour;
	text += '</span><span class="body_text"><br />';
	text += '&pound;'+cost+' per box (inc VAT)';
	text += '<br /></span>';
	text += '<span class="small_print">&pound;'+cost2+' per tile </span>';
	text += '<br /></span><span class="sale">(was &pound;'+original+' per box)</span>';
	text += '</td>';
	text += '<td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td valign="top"><span class="body_text">';
	if (stock.indexOf('hone') == -1) {
		text += getQuantitySelector(type, colour, 'quantity_box') + ' boxes<br>';
		text += getQuantitySelector(type, colour, 'quantity_tile') + ' tiles<br>';
		document.write(text);
		text = '';
		writeCart(type, colour, cost, cost2);
	}
	text += '<br /></span></td><td valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td colspan="2" valign="top"><span class="small_print">';
	if (stockLevels[index].indexOf('hone') == -1 && stockLevels[index] > 2)
		text += '<b>';
	text += 'Stock: '+stock;
	if (stock.indexOf('hone') == -1)
		text += ' boxes';
	if (stockLevels[index].indexOf('hone') == -1 && stockLevels[index] > 2)
		text += '</b>';
	text += '<br /><br /></span><span class="body_text"><a onclick="addToRequest(\''+type+'\', \''+colour+'\');">Get a sample</a><br />';
	text += '<a onclick="getMoreInfo(\''+type+'\', \''+colour+'\');">More Info</a></span></td>';
	text += '<td></td><td></td></tr>';
	document.write(text);	

}

function getQuantitySelector(type, colour, text)
{
	var text = '<select id="'+type+'_'+colour+'_'+text+'">';
	for (i = 0; i < 13; i++)
		text += '<option value="'+i+'">'+i+'</option>';
	text += '</select>';
	return text;
}

function getMoreInfo(type, colour)
{
	var shortType = type.replace(' ', '');
	shortType = shortType.toLowerCase();
	var shortColour = colour.replace(' ', '');
	window.location.href= 'http://www.rubberflooringonline.co.uk/products/'+shortType+'/'+shortColour+'.htm';
}

function writeCart(type, colour, cost1, cost2)
{
	var text = '<a onclick="addToBasket(\''+type+'\', \''+colour+'\', '+cost1+', '+cost2+');">Add to Basket</a>';
	document.write(text);
}

function writeLargeProduct(type, colour)
{
	var stock = '0';
	var index = (type-1)*20 + colour - 1;
	var cost = prices[index];
	var cost2 = prices2[index];
	stock = stockOrderLevels[index];
	var sale = false;
	var original = '0.00';
	if (type < 4)
	{
		if ( cost != '180.00' && cost != '160.00' )
		{
			sale = true;
			if ( colour == 14 || colour == 15 || colour == 16 )
				original = '180.00';
			else
				original = '160.00';
		}
	}
	if (sale)
		writeTheLargeSaleProduct(typeNames[type-1], colourNames[colour-1], cost, stock, index, original, cost2);
	else
		writeTheLargeProduct(typeNames[type-1], colourNames[colour-1], cost, stock, index, cost2);
}

function writeTheLargeProduct(type, colour, cost, stock, index, cost2)
{
	var shortColour = colour.replace(' ', '');
	var text = '<td height="230" colspan="2" valign="top"><img src="'+shortColour+'_life_style_shot.jpg" alt="Product Image" name="Image3" width="149" height="220" border="0" id="Image3" /></td>';
	text += '<td colspan="2" rowspan="2" valign="top"><span class="heading">'+colour+'</span><span class="body_text"><br />';
	text += '&pound;'+cost;
	if (type.indexOf('Apex') != -1) {
		text += ' per box (15 tiles/5.36m²)';
		text += '<br /></span><span class="small_print">&pound;'+cost2;
		text += ' per tile';
	}
	text += ' </span><span class="body_text"><br /><br />Stock: ';
	text += stock + '<br />';
	document.write(text);
	if (stock.indexOf('hone') == -1) {
		document.write( getQuantitySelector(type, colour, 'quantity_box') + ' boxes<br />' );
		document.write( getQuantitySelector(type, colour, 'quantity_tile') + ' tiles<br />' );
		writeCart(type, colour, cost, cost2);
	}
	text = '<br />';
	text += '<a onclick="addToRequest(\''+type+'\', \''+colour+'\');">Get a sample</a><br />';
	text += '<br /><br />&lt;&lt;&lt;<a href="../../index.htm">Back</a></span></td>';
	text += '<td width="8" rowspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td colspan="2" rowspan="3" valign="top"><img src="'+shortColour+'_product_shot_close_up.jpg" alt="Lifestyle Shot" width="306" height="420" /></td>';
	text += '<td rowspan="6" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td></td></tr><tr>';
	text += '<td height="155" colspan="2" valign="top"><table height="100" width="149" style="background-color: '+getColor(index)+';"><tr><td>&nbsp;</td></tr></table></td>';
	text += '<td></td>';
	document.write(text);
}

function writeTheLargeSaleProduct(type, colour, cost, stock, index, original, cost2)
{
	var shortColour = colour.replace(' ', '');
	var text = '<td height="230" colspan="2" valign="top"><img src="'+shortColour+'_life_style_shot.jpg" alt="Product Image" name="Image3" width="149" height="220" border="0" id="Image3" /></td>';
	text += '<td colspan="2" rowspan="2" valign="top"><span class="heading">'+colour+'</span><span class="body_text"><br />';
	text += '&pound;'+cost;
	if (type.indexOf('Apex') != -1) {
		text += ' per box (15 tiles/5.36m²)';
		text += '<br /></span><span class="small_print">&pound;'+cost2;
		text += ' per tile';
	}
	text += ' </span><span class="body_text"><br /><br />Stock: ';
	text += stock + '<br />';
	document.write(text);
	if (stock.indexOf('hone') == -1) {
		document.write( getQuantitySelector(type, colour, 'quantity_box') + ' boxes<br />' );
		document.write( getQuantitySelector(type, colour, 'quantity_tile') + ' tiles<br />' );
		writeCart(type, colour, cost, cost2);
	}
	text = '<br />';
	text += '<a onclick="addToRequest(\''+type+'\', \''+colour+'\');">Get a sample</a><br />';
	text += '<br /><br />&lt;&lt;&lt;<a href="../../index.htm">Back</a></span><br><br><span class="sale">SALE! SALE! SALE!<br>Was &pound;'+original;
	if (type.indexOf('Apex') != -1)
		text += ' per box';
	text += '<br>SALE! SALE! SALE!</span></td>';
	text += '<td width="8" rowspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td colspan="2" rowspan="3" valign="top"><img src="'+shortColour+'_product_shot_close_up.jpg" alt="Lifestyle Shot" width="306" height="420" /></td>';
	text += '<td rowspan="6" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>';
	text += '<td></td></tr><tr>';
	text += '<td height="155" colspan="2" valign="top"><table height="100" width="149" style="background-color: '+getColor(index)+';"><tr><td>&nbsp;</td></tr></table></td>';
	text += '<td></td>';
	document.write(text);
}

function addToBasket(type, colour, cost1, cost2)
{
	var quantity1 = 1;
	var quantity2 = 0;
	if (document.getElementById(type+'_'+colour+'_quantity_box'))
		quantity1 = document.getElementById(type+'_'+colour+'_quantity_box').value;
	if (document.getElementById(type+'_'+colour+'_quantity_tile'))
	quantity2 = document.getElementById(type+'_'+colour+'_quantity_tile').value;	
	var cookiestring = getCookie("basket");
	var basketstring = getBasketString(type, colour, cost1, quantity1);
	var searchstring = type+'#'+colour;
	if (cookiestring == null || cookiestring == '' || cookiestring.indexOf(searchstring) < 0)
	{
		if (quantity1 > 0 && checkStock(type, colour, quantity1) == 0)
			cookiestring += basketstring;
		setCookie("basket", cookiestring);
		writeBasket();
	}
	else if (quantity1 > 0)
	{		
		addSome(type, colour, cost1, quantity1);
	}
	if ( quantity2 > 0 ) {
		basketstring = getBasketString(type + ' (tile)', colour, cost2, quantity2);
		searchstring = type+' (tile)#'+colour;
		if (cookiestring == null || cookiestring == '' || cookiestring.indexOf(searchstring) < 0)
		{
			cookiestring += basketstring;
			setCookie("basket", cookiestring);
			writeBasket();
		}
		else
		{
			addSome(type + ' (tile)', colour, cost2, quantity2);
		}
	}
}

function addSome(type, colour, price, quantity)
{
	var cookiestring = getCookie("basket");
	var basketstring = "##"+type+"#"+colour+"#"+price+"#";
	var index = cookiestring.indexOf(basketstring) + basketstring.length;
	var index2 = cookiestring.indexOf("#", index);
	var newquantity = parseInt(cookiestring.substring(index, index2));
	newquantity += quantity;
	
	if (type.indexOf('tile') > 0 || checkStock(type, colour, newquantity) == 0)
	{
		if (newquantity == 0)
			cookiestring = cookiestring.substring(0, cookiestring.indexOf(basketstring))+cookiestring.substring(index2+1);
		else
			cookiestring = cookiestring.substring(0, index)+newquantity+cookiestring.substring(index2);
		setCookie("basket", cookiestring);
	}
	writeBasket();
}

function deleteFromBasket(type, colour, price, quantity)
{
	var cookiestring = getCookie("basket");
	cookiestring = cookiestring.replace(getBasketString(type, colour, price, quantity), '');
	setCookie("basket", cookiestring);
	writeBasket();
}

function getBasketText(isbasket)
{
	var cookiestring = getCookie("basket");
	var basketstring = '';
	if (cookiestring == null)
		return '<tr><td height=20 class=bb4 colspan=7>No items in basket</td></tr>';
	var type = '';
	var colour = '';
	var quantity = 0;
	var price = 0.00;
	var numitems = 1;
	while (cookiestring.indexOf('##') != -1)
	{
		cookiestring = cookiestring.substring(cookiestring.indexOf('##')+2);
		var index = cookiestring.indexOf('#');
		type = cookiestring.substring(0, index);
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		colour = cookiestring.substring(0, index);
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		price = parseFloat(cookiestring.substring(0, index));
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		quantity = parseInt(cookiestring.substring(0, index));
		cookiestring = cookiestring.substring(index+1);
		basketstring += '<tr><td class=bb4 height=20>'+type+'</td><td class=bb4>'+colour+'</td>';
		if (isbasket.indexOf("true") < 0)
			basketstring += '<td class=bb4 colspan=2>'+quantity;
		else
			basketstring += '<td class=bb4>'+quantity+'</td><td class=bb4>';
		if (isbasket.indexOf("true") > -1)
		{
			basketstring += '<button onclick="addSome(\''+type+'\', \''+colour+'\', '+price+', 1);">+</button>';
			basketstring += '<button onclick="addSome(\''+type+'\', \''+colour+'\', '+price+', -1);">-</button>';
		}
		basketstring += '</td><td class=bb4 align=right>£'+price.toFixed(2)+'</td><td class=bb4 align=right>£'+(price*quantity).toFixed(2)+'</td>';
		if (isbasket.indexOf("true") > -1)
			basketstring += '<td class=noborder><button onclick="deleteFromBasket(\''+type+'\', \''+colour+'\', '+price+', '+quantity+');">Delete</button></td>';
		basketstring += '</tr>';
		basketstring += '<input type="hidden" name="item_name_'+numitems+'" value="'+type+' - '+colour+'">';
		basketstring += '<input type="hidden" name="amount_'+numitems+'" value="'+price.toFixed(2)+'">';
		basketstring += '<input type="hidden" name="quantity_'+numitems+'" value="'+quantity+'">';
		numitems += 1;
	}
	if (numitems == 1)
		return '<tr><td height=20 class=bb4 colspan=7>No items in basket</td></tr>';
	var subtotal = getBasketSubtotal();
	var postage = getPostage(subtotal);
	var total = getBasketTotal(subtotal, postage);
	basketstring += '<tr><td height=20 class=noborder colspan=4></td><td class=bb4>Subtotal</td><td class=bb4 align=right>£'+subtotal.toFixed(2)+'</td>';
	if (isbasket.indexOf("true") > -1)
		basketstring += '<td class=noborder></td>';
	basketstring += '</tr><tr><td height=20 class=noborder colspan=4></td><td class=bb4>Postage</td><td class=bb4 align=right>£'+postage.toFixed(2)+'</td>';
	if (isbasket.indexOf("true") > -1)
		basketstring += '<td class=noborder></td>';
	basketstring += '<input type="hidden" name="item_name_'+numitems+'" value="Delivery">';
	basketstring += '<input type="hidden" id="shipping" name="amount_'+numitems+'" value="'+postage.toFixed(2)+'">';
	basketstring += '<input type="hidden" name="quantity_'+numitems+'" value="1">';
	basketstring += '</tr><tr><td height=20 class=noborder colspan=4></td><td class=bb4>TOTAL</td><td class=bb4 align=right>£'+total.toFixed(2)+'</td>';
	if (isbasket.indexOf("true") > -1)
		basketstring += '<td class=noborder></td>';
	basketstring += '</tr>';
	return basketstring;
}

function getSubmitBasketString()
{
	var cookiestring = getCookie("basket");
	var basketstring = '';
	var type = '';
	var colour = '';
	var quantity = 0;
	var price = 0.00;
	var numitems = 1;
	while (cookiestring.indexOf('##') != -1)
	{
		cookiestring = cookiestring.substring(cookiestring.indexOf('##')+2);
		var index = cookiestring.indexOf('#');
		type = cookiestring.substring(0, index);
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		colour = cookiestring.substring(0, index);
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		price = parseFloat(cookiestring.substring(0, index));
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		quantity = parseInt(cookiestring.substring(0, index));
		cookiestring = cookiestring.substring(index+1);
		basketstring += ':'+type+' - '+colour+':'+quantity+':£'+price.toFixed(2);
		basketstring += ':£0.00:£'+price.toFixed(2)+':'+(price*quantity).toFixed(2);
		numitems += 1;		
	}
	basketstring = ''+numitems+basketstring+':Delivery:::::£'+getPostage(getBasketSubtotal()).toFixed(2);
	return basketstring;
}

function simpleXor(text, key)
{
	var result=[];
	
	for(var i = 0; i < text.length; i++)
    	{
      		result[i] = (text.charCodeAt(i) ^ key.charCodeAt(i % key.length));
    	}
    	return result;
}

function encode(data) 
{
    	var encoding = [
	    "A", "B", "C", "D", "E", "F", "G", "H",
	    "I", "J", "K", "L", "M", "N", "O", "P",
	    "Q", "R", "S", "T", "U", "V", "W", "X",
	    "Y", "Z", "a", "b", "c", "d", "e", "f",
	    "g", "h", "i", "j", "k", "l", "m", "n",
	    "o", "p", "q", "r", "s", "t", "u", "v",
	    "w", "x", "y", "z", "0", "1", "2", "3",
	    "4", "5", "6", "7", "8", "9", "+", "/"
	];
    	var result = [];
    	var ip57   = Math.floor(data.length / 57);
    	var fp57   = data.length % 57;
    	var ip3    = Math.floor(fp57 / 3);
    	var fp3    = fp57 % 3;
    	var index  = 0;
    	var num;
    
    	for ( var i = 0; i < ip57; i++ ) 
    	{
        	for ( j = 0; j < 19; j++, index += 3 ) 
        	{
            		num = data[index] << 16 | data[index+1] << 8 | data[index+2];
            		result.push(encoding[ ( num & 0xFC0000 ) >> 18 ]);
            		result.push(encoding[ ( num & 0x03F000 ) >> 12 ]);
            		result.push(encoding[ ( num & 0x0FC0   ) >>  6 ]);
            		result.push(encoding[ ( num & 0x3F     )       ]);
        	}
        	result.push("\n");
    	}

    	for ( i = 0; i < ip3; i++, index += 3 ) 
    	{
        	num = data[index] << 16 | data[index+1] << 8 | data[index+2];
        	result.push(encoding[ ( num & 0xFC0000 ) >> 18 ]);
        	result.push(encoding[ ( num & 0x03F000 ) >> 12 ]);
        	result.push(encoding[ ( num & 0x0FC0   ) >>  6 ]);
        	result.push(encoding[ ( num & 0x3F     )       ]);
    	}

    	if ( fp3 == 1 ) 
    	{
        	num = data[index] << 16;
        	result.push(encoding[ ( num & 0xFC0000 ) >> 18 ]);
        	result.push(encoding[ ( num & 0x03F000 ) >> 12 ]);
        	result.push("==");
    	} 
    	else if ( fp3 == 2 ) 
    	{
        	num = data[index] << 16 | data[index+1] << 8;
        	result.push(encoding[ ( num & 0xFC0000 ) >> 18 ]);
        	result.push(encoding[ ( num & 0x03F000 ) >> 12 ]);
        	result.push(encoding[ ( num & 0x0FC0   ) >>  6 ]);
        	result.push("=");
    	}
   	return result.join("");
}
   
function getTransCode()
{
	var d = new Date();
	return "RFO" + (Math.random()*1000000) + "." + d.getTime();
}

function getCrypt()
{
	var vendorTxCode = getTransCode();
	var subtotal = getBasketSubtotal();
	var postage = getPostage(subtotal);
	if ((subtotal < 100 && postage > 10) || (subtotal >= 100 && postage > 0))
		if (!confirm('A surcharge of £'+getSurcharge(postage)+' has been added to your delivery costs due to the postcode entered. Please see our delivery policy for details.'))
			return false;
	var amount = getBasketTotal(subtotal, postage);
	var currency = "GBP";
	var description = "Goods from Rubber Flooring Online";
	var customerEmail= document.getElementById('email').value;
	var customerName= document.getElementById('Name').value;
	var vendorEmail= "administrator@rubberflooringonline.co.uk";
	var deliveryAddress= document.getElementById('Address1').value;
	deliveryAddress += ", " + document.getElementById('Address2').value;
	deliveryAddress += ", " + document.getElementById('Town').value;
	deliveryAddress += ", " + document.getElementById('County').value;
	var deliveryPostCode= document.getElementById('Postcode').value;
	var billingAddress= deliveryAddress;
	var billingPostCode= deliveryPostCode;
	var contactNumber = document.getElementById('Phone').value;
	var shoppingBasket = getSubmitBasketString();

	var stuff = "VendorTxCode=" + vendorTxCode + "&Amount=" + amount;
	stuff += "&Currency=" + currency + "&Description=" + description;
	stuff += "&SuccessURL=http://www.rubberflooringonline.co.uk/success.htm&FailureURL=http://www.rubberflooringonline.co.uk/failure.htm";

	if ( customerEmail != "" ) 
	{
	  stuff += "&CustomerEmail=" + customerEmail;
	}
	if ( vendorEmail != "" ) 
	{
	  stuff += "&VendorEmail=" + vendorEmail;
	}
	if ( customerName != "" ) 
	{
	  stuff += "&CustomerName=" + customerName;
	}
	if (deliveryAddress != "" ) 
	{
	  stuff += "&DeliveryAddress=" + deliveryAddress;
	}
	if (deliveryPostCode != "" ) 
	{
	  stuff += "&DeliveryPostCode=" + deliveryPostCode;
	}
	if (billingAddress != "" ) 
	{
	  stuff += "&BillingAddress=" + billingAddress;
	}
	if (billingPostCode != "" ) 
	{
	  stuff += "&BillingPostCode=" + billingPostCode;
	}
	if (contactNumber != "" ) 
	{
	  stuff += "&ContactNumber=" + contactNumber;
	}
	if (shoppingBasket != "")
	{
		stuff += "&Basket="+shoppingBasket;
	}
	return stuff;
}

function setCrypt()
{
	var stuff = getCrypt();
	var crypt = encode(simpleXor(stuff,'wsNDakQCYzfnyQSd'));
	crypt = crypt.replace(/[\n\r]/g, "" );
	document.getElementById('Crypt').value = crypt;
	document.theForm.action = "https://ukvps.protx.com/vps2Form/submit.asp";
	return checkStockLevels();
}

function submitPayPal()
{
	var subtotal = getBasketSubtotal();
	var postage = getPostage(subtotal);
	if ((subtotal < 100 && postage > 10) || (subtotal >= 100 && postage > 0))
		if (!confirm('A surcharge of £'+getSurcharge()+' has been added to your delivery costs due to the postcode entered. Please see our delivery policy for details.'))
			return false;
	document.getElementById('shipping').value = postage.toFixed(2);
	document.getElementById('cmd').value = "_cart";
	document.getElementById('upload').value = "1";
	document.getElementById('business').value = "administrator@rubberflooringonline.co.uk";
	document.getElementById('currency_code').value = "GBP";
	document.getElementById('return').value = "http://www.rubberflooringonline.co.uk/success.htm";
	document.theForm.action = "https://www.paypal.com/cgi-bin/webscr";
	return checkStockLevels();
}

function checkStockLevels()
{
	var cookiestring = getCookie("basket");
	if (cookiestring == null)
		return true;
	var quantity = 0;
	var stock = 0;
	var stock2 = 0;
	var type = '';
	var colour = '';
	var typeNum = 0;
	var colourNum = 0;
	while (cookiestring.indexOf('##') != -1)
	{
		cookiestring = cookiestring.substring(cookiestring.indexOf('##')+2);
		var index = cookiestring.indexOf('#');
		type = cookiestring.substring(0, index);
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		colour = cookiestring.substring(0, index);
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		cookiestring = cookiestring.substring(index+1);
		index = cookiestring.indexOf('#');
		quantity = parseInt(cookiestring.substring(0, index));
		cookiestring = cookiestring.substring(index+1);
		typeNum = getTypeNum(type);
		colourNum = getColourNum(colour);
		if (typeNum != -1 && colourNum != -1 && type.indexOf('tile') == -1)
		{
			index = typeNum*20 + colourNum;
			stock = parseInt(stockLevels[index]);
			if ( isNaN(stock) )
				stock = 0;
			stock2 = parseInt(stockOrderLevels[index]);
			if ( isNaN(stock2) )
				stock2 = 0;
			if (quantity > stock && quantity <= stock2)
				return confirm('At least one of the items you have in your basket is only available on 7 working day delivery. If you wish to continue, please click OK. If not, please click Cancel to go back and amend your order. Thank you!');
			else if (quantity > stock2)
				return confirm('At least one of the items you have in your basket is out of stock with an 6-8 week lead time. If you wish to continue, please click OK. If not, please click Cancel to go back and amend your order. Thank you!');
		}
	}
	return true;
}