					
function goInStock(id) {
	var outOfStock = document.getElementById('outofstockline' + id);
	var inStock = document.getElementById('addtobasketline' + id);
	var outOfStockMessage = document.getElementById('outofstockmessage' + id);
	outOfStock.style.display = 'none';
	outOfStock.style.visibility = 'hidden';
	outOfStockMessage.style.display = 'none';
	outOfStockMessage.style.visibility = 'hidden';
	inStock.style.display = '';
	inStock.style.visibility = 'visible';
	
}

function goOutOfStock(id) {
	var outOfStock = document.getElementById('outofstockline' + id);
	var inStock = document.getElementById('addtobasketline' + id);
	var outOfStockMessage = document.getElementById('outofstockmessage' + id);
	inStock.style.display = 'none';
	inStock.style.visibility = 'hidden';
	outOfStockMessage.style.display = '';
	outOfStockMessage.style.visibility = 'visible';
	outOfStock.style.display = '';
	outOfStock.style.visibility = 'visible';
}
								
function ExtractNum(stringNo) 
{
	//Pindar - KW - Do we need to change the price? We only need to do this if there's a price break
	// The existing code will update anything that's numeric!
	if(stringNo.indexOf("+")==0 || stringNo.indexOf("+")>0)
	{
	//We're doing string functions to make sure that we're getting the price after "(+" of each option labels
	stringNo = stringNo.slice(stringNo.lastIndexOf("(+"),stringNo.length);
	
	var parsedNo = ""; 
	for(var n=0; n<stringNo.length; n++) 
	{
		var i = stringNo.substring(n,n+1); 
		if(i=="1"||i=="2"||i=="3"||i=="4"||i=="5"||i=="6"||i=="7"||i=="8"||i=="9"||i=="0"||i==".")
		parsedNo += i; 
	} 
	if (parsedNo.length > 0) { 
	return parsedNo;} else {return 0;}
	}
	else
	{return 0;}
	}
 	

function checkStock(id,outOfStockItems, CustomerPrices) {

	// Build up out options selections
	var txtPrice = document.getElementById('txtPrice' + id);
	var origPrice = document.getElementById('origPrice' + id);
	var txtPriceEx = document.getElementById('txtPriceEx' +id);
	var i = 0;
	
	//Pindar - KW - Variable for Option - default to select box
	var OptionDisplayType="select-one";
	
	var selections = new Array();
	var selectionCount = 0;
	var numOptionsTotal = 0;
	for (i=0;i<document.getElementById('options' + id).elements.length;i++) {
		var element = document.getElementById('options' + id).elements[i];
		if(element.name.substring(0,6)=='OPT_ID') {
			switch(element.type)
			{
				case 'checkbox':
					// is this checkbox selected?
					if(element.checked == true) {
						//Pindar - KW - Set the Option Type
						OptionDisplayType="checkbox";
						// use this ID
						selections[selectionCount]=element.value;
						selectionCount++;
						// find all labels
						
						var labels = document.getElementsByTagName('label');
						// loop through all label elements
							
						for (var m = 0; m < labels.length; m++) 
							{var label = labels[m];
							 var labelFor = label.htmlFor;
							 if (labelFor == element.id) 
							 			{
										numOptionsTotal = numOptionsTotal + parseFloat(ExtractNum(label.innerHTML));
								
										}							
							}
					} else {
						// otherwise we have to get out the nocheckvalue
						var nocheck = document.getElementById('options' + id).elements['NOCHECK_' + element.name]
						//Pindar - KW - Set the Option Type
						OptionDisplayType="checkbox";
						selections[selectionCount]=nocheck.value;
						selectionCount++;
					}
					break;
					
				case 'radio':
					if(element.checked == true) {
						selections[selectionCount]=element.value;
						//Pindar - KW - Set the Option Type
						OptionDisplayType="radio";
						selectionCount++;
						// find all labels
						var labels = document.getElementsByTagName('label');

						// loop through all label elements

						for (var m = 0; m < labels.length; m++) 
							{
								var label = labels[m];

								var labelFor = label.htmlFor;
								if (labelFor == element.id) 
								{
									numOptionsTotal = numOptionsTotal + parseFloat(ExtractNum(label.innerHTML));

								}							
							
							}
					}
					break;
					
				case 'select-one':
					var Index = element.selectedIndex;
					selections[selectionCount]=element.value;
					//Pindar - KW - Set the Option Type
						OptionDisplayType="select-one";
					selectionCount++;
					numOptionsTotal = numOptionsTotal + parseFloat(ExtractNum(element.options[Index].text));
					break;

				default:
					break;
					
			}
			
		}

	}
	txtPrice.value=( parseFloat(origPrice.value) +  parseFloat(numOptionsTotal)).toFixed(2);
	if (txtPriceEx != null){
		var numTax = document.getElementById('numTax' + id);
		txtPriceEx.value = (txtPrice.value * numTax.value).toFixed(2);
	}
	
		//Pindar KW - Check if we need to sort
	if(OptionDisplayType=='radio')
	{	
		
		//sort the options - if we do this on select boxes it breaks!
		selections = (selections.sort());
	}
	
	var selection = selections.join('-');
	var isOutOfStock = false;
	
	// Does this combination exist in out outofstock array?
	for(i=0; i<outOfStockItems.length; i++) {
		if(outOfStockItems[i]==selection) {
			isOutOfStock = true;
			break;
		}
	}
	
	if(isOutOfStock) {
		goOutOfStock(id);
	} else {
		goInStock(id);
	}
	
	// see if we need to update the pricing information for the customer group
	// Loop through the customer price array
		for(i=0; i<CustomerPrices.length; i++)
		{
		// Split the options [0] from the price [1]
		var OptionPriceArray = CustomerPrices[i].split('|');
		// Does the price option match the selected form fields?
		if(OptionPriceArray[0]==selection)
			{
			//The option matches so we update the price
			// Update Price INC. VAT
			txtPrice.value=OptionPriceArray[1]+" (SP)"
			// Do we need to update the EXC. Tax? This field won't
			// exist if the site isn't set to show prices exc. VAT so first
			// check it's there to update or we'll get a javascript error
				if (txtPriceEx != null)
					{
						// The exc. text field is there
						txtPriceEx.value = (txtPrice.value * numTax.value).toFixed(2);
					}
			}
		}
if(typeof(document.ProdLogoForm)!='undefined'){		
	  if(typeof(document.ProdLogoForm.ProductLogo)!='undefined')		
		  {
			  var frm = document.ProdLogoForm ;
			  var opt = frm.ProductLogo;
			  var SelectedItems = ""; 
	  
			  var numofoptions = opt.length
			  for (i=0; i<numofoptions; i++)
				  {
					  if (opt[i].selected === true)
					  {
						  SelectedItems = SelectedItems +"," + opt[i].value	 
					  }
				  }
		  document.ProductForm.LogoID.value = SelectedItems;
		}
	}
}
						