// [1.0] - Original Build
// [1.1] - 

	jQuery(document).ready(function() {
		// ---- INI
		// Display "first" the "select input" that has "options"
		jQuery("select.variantSelection:has(option):first").show();

		//Ensure the qty input can only accept numeric values
		jQuery("#qty").numeric();

		// ---- EVENTS
		//Display the zoom image when the relevant button is selected
		jQuery('#zoom-image-link').click(function() {
			//Retrieve the "main image" img src value
			var sImgSrc = jQuery('#mainImage img').attr('src');

			//Substitute the "zoom" folder with the "standard" the folder to display the new relevant image
			rExp = /standard/;
			var sSubstitute = 'zoom';
			var newImgSrc = sImgSrc.replace(rExp, sSubstitute);
			jQuery('#zoom-image').attr({src: newImgSrc});

			//Display the zoom Image container
			//jQuery('#zoom-image-group').css("display", "inline");
			jQuery('#zoom-image-group').fadeIn(1500);
			jQuery('#zoom-image-group').focus();
			return false;
		});


		//Display the zoom image when the relevant button is selected
		jQuery('#zoom-image-close').click(function() {
			jQuery('#zoom-image-group').fadeOut(1500);
			return false;
		});


		// catch the additional image being "hovered" across
		jQuery('#AdditionalImages img').mouseover(function() {
			//Retrieve the "hovered over" img src value
			var sImgSrc = jQuery(this).attr('src');

			//Substitute the "additonal" folder with the "standard" the folder to display the new relevant image
			rExp = /additional/;
			var sSubstitute = 'standard';
			var newImgSrc = sImgSrc.replace(rExp, sSubstitute);
			jQuery('#mainImage img').attr({src: newImgSrc});

		});

		// When selecting the qty input for single variant products - enable the buy button
		if(jQuery('#singleVarProd').val() == '1') {
			jQuery('#qty').click(function() {
				jQuery(this).val("");
				//var sProdID = jQuery('#prod').val();
				//jQuery('#form_' + sProdID + 'link').attr({href: "javascript:ValidateAndSubmit('form_" + sProdID + "','" + sProdID + "');"});
				//jQuery('#form_' + sProdID + 'link img').attr({src: "/public/images/buttons/addtotrolley.png"});
			});


		}

		jQuery('#qty').keyup(function(e) {
			if(jQuery('#singleVarProd').val() == '1') {
				var sProdID = jQuery('#prod').val();
				if(jQuery(this).val() > 0 && jQuery(this).val() != '') {
					jQuery('#form_' + sProdID + 'link').attr({href: "javascript:ValidateAndSubmit('form_" + sProdID + "','" + sProdID + "');"});
					jQuery('#form_' + sProdID + 'link img').attr({src: "/public/images/buttons/addtotrolley.png"});
				} else {
					jQuery('#form_' + sProdID + 'link').attr({href: "javascript:alert('Please select your option before adding to the basket.')"});
					jQuery('#form_' + sProdID + 'link img').attr({src: "/public/images/buttons/addtotrolley02.png"});
				}
			}
		});


	});



//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	//
//  OAJAXBASKET 								//
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	//

function oAJAXBasket() {

	this.initialise 				= _initialise;

	this.AJAX_AddtoBasket 			= _AJAX_AddtoBasket;
	this.AJAX_ConfirmAddToBasket 	= _AJAX_ConfirmAddToBasket;

	this.isValidQty					= _isValidQty;
	this.setBasketProdImg			= _setBasketProdImg
	this.hideBasket					= _hideBasket;
	this.hideDiv					= _hideDiv;
	this.positionBasket				= _positionBasket;
	this.returnFormFieldsExclude	= _returnFormFieldsExclude;
	this.setURL						= _setURL;

	var p_sSiteURL					= '';
	//var oBasketBck 					= null;
	var oForm						= null;

	var sBasketProdImg				= '';
	var timerComfirmation			= null;
	var oBasketContainer 			= null;
	var p_sProdCode ='';


	// ----------------------------------------------------------------------------- _initialise()
	function _initialise() {
		//oBasketBck = getObject("oBasketBck")
		//oBasketBck.style.backgroundImage = "url(/public/images/basket_box.gif)";

		oBasketContainer = getObject('oBasketContainer');
	}

	// ----------------------------------------------------------------------------- _setBasketProdImg()
	function _setBasketProdImg(sPath_p) {
		sBasketProdImg = sPath_p;
	}

	// ----------------------------------------------------------------------------- _setURL()
	function _setURL(sSiteURL_p) {
		p_sSiteURL = sSiteURL_p;
	}
	// START OF [1.1]
	function _setCBL(bCompletethelook_p){
			p_bCompletethelook=bCompletethelook_p;
	}
	//END OF [1.1]

	// ----------------------------------------------------------------------------- _AJAX_AddtoBasket()
	function _AJAX_AddtoBasket(sFormName, sProdCode)
	{
		oForm = document.forms[sFormName];
		var iQty = oForm.elements['qty'].value;

		var sFormParams = _returnFormFieldsExclude(oForm, 'serial|prodname|timestamp');

		if (_isValidQty(iQty))
		{
			//var sURL = p_sSiteURL + '/core_2/core_ajax/EventListener.asp?' + sFormParams + '&inc_price=true&rQty=' + iQty;
			var sURL = p_sSiteURL + '/core_2/core_ajax/EventListener.asp?' + sFormParams;
			var oAJAXAddToBasket = new AjaxXMLDelegate(sURL, _AJAX_ConfirmAddToBasket);
			oAJAXAddToBasket.Fetch();

		}

	}

	// ----------------------------------------------------------------------------- _AJAX_ConfirmAddToBasket()
	function _AJAX_ConfirmAddToBasket(url, oXML)
	{
		// Update the basket total in the page header (via updateBasketTotal in layout.xsl)
		updateBasketTotal();

		//Retrieve new basket values
		var iBasketItemCount = oXML.getElementsByTagName('basket_totalitem_count')[0].firstChild.data;
		var iBasketTotal = oXML.getElementsByTagName('basket_price_total')[0].firstChild.data;

		//Retrieve option

		//Set new ProductCode global variable
		p_sProdCode = oForm.elements['prod'].value;

		//determine the correct currency symbol
		var sCurrencySymbol = '&#163;';

		// Populate the popup basket success message
		var sProductDetails =	'';
		sProductDetails = sProductDetails +	'<div id="ajax_basket_left_container" class="floatLeft"><img src="/public/pictures/products/small/' + oForm.elements['item_image_filename'].value + '" border="0" onerror="this.src=&#39;/public/pictures/products/small/noimage.gif&#39;"/> </div>';
		sProductDetails = sProductDetails +	'<div id="ajax_basket_right_container" class="floatLeft">';
		sProductDetails = sProductDetails +	'<div class="ajax_basket_name">' + oForm.elements['prodname'].value + '</div>';

		sProductDetails = sProductDetails +	'<div class="ajax_basket_details">' + oForm.elements['item_variant_option'].value.replace(',','<br>') + '</div>';
		sProductDetails = sProductDetails +	'</div';
		sProductDetails = sProductDetails +	'<div class="clear"><img src="/public/images/spacer.gif" /></div>';
		sProductDetails = sProductDetails +	'<div class="productDivider"><img src="/public/images/spacer.gif" /></div>';

		sProductDetails = sProductDetails +	'<div><div class="ajax_basket_qty">Qty: ' + oForm.elements['qty'].value + '</div>';
		var productCost = parseFloat(oForm.elements['item_varPrice'].value * parseInt(oForm.elements['qty'].value,10));		// Case ID: 09-10690 - Use variant price instead of product price
		sProductDetails = sProductDetails +	'<div class="ajax_basket_cost">Line total: ' + sCurrencySymbol + productCost.toFixed(2) + '</div>';
		sProductDetails = sProductDetails +	'<div class="clear"><img src="/public/images/spacer.gif" /></div></div>';
		sProductDetails = sProductDetails +	'<div class="productDivider"><img src="/public/images/spacer.gif" /></div>';
		var oVariantInfo = getObject("oVariantInfo");
		oVariantInfo.innerHTML = sProductDetails;

		_positionBasket();

		//Display the basket success message
		oBasketContainer.style.display = "block";
		var nClientHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			nClientHeight = parseFloat(self.innerHeight + self.pageYOffset);
		} else {
			nClientHeight = parseFloat(document.documentElement.clientHeight + document.documentElement.scrollTop);
		}
		var iYPosition = nClientHeight - ((parseFloat(oBasketContainer.style.height.replace('px',''))-48) * 2);

		jQuery('#oBasketContainer').animate( {top: iYPosition}, {duration: 500}, 'linear' );

		timerComfirmation = self.setTimeout(function() {_hideBasket()}, 5000)


	}

	// ----------------------------------------------------------------------------- _isValidQty()
	function _isValidQty(iVal) {
		var rIsNotNumeric = /[^0-9]/
		var rIsNotZero = /[1-9]+/
		var bValid = true;

		if ( rIsNotNumeric.test(iVal) || !rIsNotZero.test(iVal) ) {
			bValid = false
			alert("Quantity must be valid number greater than 0");
		}

		return bValid;
	}

	// ----------------------------------------------------------------------------- _hideBasket()
	function _hideBasket() {
		self.clearTimeout(timerComfirmation);
		if (oBasketContainer.style.display == "block") {

			// [1.6] - moving the AJAX basket confirmation
			var iYPosition = parseFloat(document.documentElement.clientHeight + document.documentElement.scrollTop);
			jQuery('#oBasketContainer').animate( {top: iYPosition}, {duration: 500, complete: function() {_hideDiv();}}, 'linear' );
		}

	}


	// ----------------------------------------------------------------------------- _hideDiv()
	function _hideDiv() {
		oBasketContainer.style.display = "none";
		// start [1.7] Reset "Add To Basket" button
		var oAddToBasketButtonTop = getObject('btnAdd' + p_sProdCode + '_top');
		if(oAddToBasketButtonTop) {
			oAddToBasketButtonTop.src = '/public/images/buttons/addtotrolley.png';
		}
		var oAddToBasketButton = getObject('btnAdd' + p_sProdCode);
		oAddToBasketButton.src = '/public/images/buttons/addtotrolley.png';
		var oAddToBasketLinkTop =  getObject('form_' + p_sProdCode + 'link_top');
		if(oAddToBasketLinkTop) {
			oAddToBasketLinkTop.href = "javascript:void(ValidateAndSubmit('form_" + p_sProdCode + "','" + p_sProdCode + "'))";
		}
		var oAddToBasketLink =  getObject('form_' + p_sProdCode + 'link');
		oAddToBasketLink.href = "javascript:void(ValidateAndSubmit('form_" + p_sProdCode + "','" + p_sProdCode + "'))";
		//END [1.7]

	}

	// ----------------------------------------------------------------------------- _positionBasket()
	function _positionBasket() {

		// Position the basket confirmation msg
		var iCenterHeight = (self.pageYOffset) ? parseFloat(self.innerHeight + self.pageYOffset) - (parseFloat(oBasketContainer.style.height.replace('px',''))) : parseFloat(document.documentElement.clientHeight + document.documentElement.scrollTop) - (parseFloat(oBasketContainer.style.height.replace('px','')));
		//Adding 30px to the width - to handle the padding
		var iCenterWidth = 960 - (parseFloat(oBasketContainer.style.width.replace('px','')) + 30);

		oBasketContainer.style.left = iCenterWidth + "px";
		oBasketContainer.style.top = iCenterHeight + "px";
		oBasketContainer.style.display = "none";
	}

	// ----------------------------------------------------------------------------- _returnFormFieldsExclude()
	function _returnFormFieldsExclude(oForm, sExclude) {
	/* Used to gather all the form fields in the incoming form object */
		sExcludesArray = new Array
		sExcludesArray = sExclude.split("|");

		var sMsg = '';
		var sFormParams = '';
		var bAdd = false;

		for(i=0; i<oForm.elements.length; i++) {

			bAdd = ( (oForm.elements[i].value=='') || (oForm.elements[i].type=="radio" && !(oForm.elements[i].checked)) ||  (oForm.elements[i].type=="checkbox" && !(oForm.elements[i].checked)  && (oForm.elements[i].disabled==false)) ) ? false : true;

			if (bAdd) {
				for (s in sExcludesArray) {
					if (oForm.elements[i].name.indexOf(sExcludesArray[s]) == 0){
						bAdd = false;
					}
				}
				if (bAdd == true) {
					sMsg = sMsg + (oForm.elements[i].name + " = " + oForm.elements[i].value + "\n");
					sFormParams = sFormParams + ("&" + oForm.elements[i].name + "=" + oForm.elements[i].value);
				}
			}
		}

		if (leftStr(sFormParams,1) == "&")  sFormParams = rightStr(sFormParams, sFormParams.length - 1)

		return sFormParams
	}


	// ----------------------------------------------------------------------------- Get positions
	function getYPosition( oElement ) {
		var iReturnValue = 0;
		while( oElement != null ) {
			iReturnValue += oElement.offsetTop;
			oElement = oElement.offsetParent;
		}
		return iReturnValue;
	}


	function getXPosition( oElement ) {
		var iReturnValue = 0;
		while( oElement != null ) {
			iReturnValue += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
		return iReturnValue;
	}
}


//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	//
//  PRODUCT PAGE FUNCTIONS						//
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	//


	function changeButton(oButtona, oButtonb)
	{
		if (oButtona)
		{
			oButtona.disabled=false;
			oButtona.src='/public/images/buttons/addtotrolley02.png';
		}
		if (oButtonb)
		{
			oButtonb.src='/public/images/buttons/addtotrolley.png';
		}
	}

	function EnableBuyButton(prodcode)
	{
		var oElementbtop = getObject('btnAdd' + prodcode + '_top');
		var oElementctop = getObject('form_' + prodcode + 'link_top');
		var oElementb = getObject('btnAdd' + prodcode);
		var oElementc = getObject('form_' + prodcode + 'link');

		if(document.forms['form_' + prodcode].elements['varPrice'].value != '')
		{
			oElementc.href = 'javascript:ValidateAndSubmit(\'form_' + prodcode + '\',\'' + prodcode + '\' )';
			changeButton('', oElementb);
			if(oElementctop) {
				oElementctop.href = 'javascript:ValidateAndSubmit(\'form_' + prodcode + '\',\'' + prodcode + '\' )';
				changeButton('', oElementbtop);
			}
		}
	}


	function DisableBuyButton(prodcode)
	{
		var oElementbtop = getObject('btnAdd' + prodcode + '_top');
		var oElementctop = getObject('form_' + prodcode + 'link_top');
		var oElementb = getObject('btnAdd' + prodcode);
		var oElementc = getObject('form_' + prodcode + 'link');

		if(document.forms['form_' + prodcode].elements['varPrice'].value != '')
		{
			oElementc.href = "javascript:alert('Please select your option before adding to the basket.')";
			oElementb.src='/public/images/buttons/addtotrolley02.png';
			if(oElementctop) {
				oElementctop.href = "javascript:alert('Please select your option before adding to the basket.')";
				oElementbtop.src='/public/images/buttons/addtotrolley02.png';
			}
		}
	}


	function ValidateAndSubmit(frm, sProdCode) {
		var oForm=document.forms[frm];
		var rIsNotNumeric=/[^0-9]/
		var rIsNotZero=/[1-9]+/
		var bValid=true

		if (bValid) {
			if (rIsNotNumeric.test(oForm.qty.value)) {
				bValid=false
				alert("Quantity must be valid number greater than 0");
				oForm.qty.focus()
			}
			else if (!rIsNotZero.test(oForm.qty.value)) {
				bValid=false
				alert("Quantity must be valid number greater than 0");
				oForm.qty.focus()
			}
		}

		if (bValid) {
			if (parseInt(oForm.qty.value)>parseInt(oForm.item_stock.value)) {
				bValid=false;
				alert("Please select a different quantity, only " + oForm.item_stock.value + " available.");
				oForm.qty.focus();
			}
		}

		if (bValid) {
			oAJAXBasket.hideBasket();
			var oAddToBasketButtonTop = getObject('btnAdd' + sProdCode + '_top');
			if(oAddToBasketButtonTop) {
				oAddToBasketButtonTop.src = '/public/images/buttons/addtotrolley02.png';
			}
			var oAddToBasketButton = getObject('btnAdd' + sProdCode);
			oAddToBasketButton.src = '/public/images/buttons/addtotrolley02.png';
			var oAddToBasketLinkTop =  getObject('form_' + sProdCode + 'link_top');
			if(oAddToBasketLinkTop) {
				oAddToBasketLinkTop.href='javascript:alert(\'Please wait whilst your item is added to your basket.\')';
			}
			var oAddToBasketLink =  getObject('form_' + sProdCode + 'link');
			oAddToBasketLink.href='javascript:alert(\'Please wait whilst your item is added to your basket.\')';
			oAJAXBasket.AJAX_AddtoBasket(frm, sProdCode);

		}
	}

	function CheckValidQty(iVal) {
		var rIsNotNumeric = /[^0-9]/
		var rIsNotZero = /[1-9]+/
		var bValid = true;

		if ( rIsNotNumeric.test(iVal) || !rIsNotZero.test(iVal) ) {
			bValid = false

		}

		return bValid;
	}


//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	//
//  HTML MENU FUNCTIONS							//
//	(Up to 4 variant options can be used)		//
//  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 	//

	// setVarSelections - Process the selection from the current dropdown box and display the next if applicable
	function setVarSelections(varObj, oForm, iPosition, sProdID, stock_behavior) {
		//iPosition is the number associated to each dropdown box

		//Set the number of variant options
		// [1.1] - varLimit should count all selections - not just populated
		//var varLimit = jQuery("select.variantSelection:has(option)").length;
		var varLimit = 4; //jQuery("select.variantSelection").length;


		DisableBuyButton(sProdID,"");
		var selectedValue = varObj.options[varObj.selectedIndex].value;

		//Hide all unrequired dropdown boxes
		for(i=iPosition+1;i<=varLimit;i++) {
			jQuery("#select_variant_option"+i).hide();
		}

		//Reset all variant lists
		if(iPosition==1) {
			arrVariantsFiltered = arrVariants;
			arrVariants2 = arrVariantsFiltered;
			arrVariants3 = arrVariants;
			arrVariants4 = arrVariants;

		} else if(iPosition==2) {
			arrVariantsFiltered = arrVariants2;
			arrVariants3 = arrVariants2;
			arrVariants4 = arrVariants2;

		} else if(iPosition==3) {
			arrVariantsFiltered = arrVariants3;
			arrVariants4 = arrVariants3;
		} else if(iPosition==4) {
			arrVariantsFiltered = arrVariants4;
		}

		//The search term could span multiple variant option fields and therefore only the specific value should be checked
		//use "iPosition-1" to reference the correct value in the + delimited string
		var arrSearchTerms = new Array();
		for(i=0;i<arrVariantsFiltered.length;i++) {
			sSearchString = arrVariantsFiltered[i].split("+")[iPosition-1];
			arrSearchTerms.push(sSearchString);
		}

		//Search for dropdown list value returning the found position indexes
		var arrResult = arrSearchTerms.find(selectedValue);


		//Filter the results found and create a new temporary array containing the matched values
		var arrTemp = new Array();
		for(var i=0; i<arrResult.length; i++) {
			arrTemp.push(arrVariantsFiltered[arrResult[i]]);
		}

		//Set the arrVariantsFiltered array to contain only the latest matched values
		arrVariantsFiltered = arrTemp;

		//Process selection made from the dropdown box
		if (selectedValue ==0) {
			//The dropdown value selected is either out of stock or not a valid product variant option
			DisableBuyButton(sProdID,"");
		} else {
			//The dropdown value selected is a valid product variant option
			var nextSelectionObj;
			var bFound = false;

			//For each subsequent dropdown box
			//Find the next populated dropdown box and process.  Each dropdown box is populated with data on the page load if possible.

			for(var i=iPosition+1; i<=varLimit; i++) {
				nextSelectionObj = getObject('select_variant_option' + i);
				if(nextSelectionObj.options.length > 0) {
					currentIndex = i;

					//Set a found flag
					var bFound = true;

					//Display the next dropdown list and exit loop
					nextSelectionObj.style.display = 'block';
					break;
				}
			}

			//If not found, there are no further selection boxes to populate
			//Enable the buy button and populate the form product/variant data
			if(!bFound) {

				EnableBuyButton(sProdID)
				var selectedVarValue = arrVariantsFiltered[0];
				var arrVarVal = selectedVarValue.split("+");
				var sVar1 = arrVarVal[0];
				var sVar2 = arrVarVal[1];
				var sVar3 = arrVarVal[2];
				var sVar4 = arrVarVal[3];
				var sVarId = arrVarVal[4];
				var sPrice = arrVarVal[5];
				var sStock = arrVarVal[6];
				var sIsObsolete = arrVarVal[7];

				jQuery('#item_variant_option1').val(sVar1);
				jQuery('#item_variant_option2').val(sVar2);
				jQuery('#item_variant_option3').val(sVar3);
				jQuery('#item_variant_option4').val(sVar4);
				jQuery('#variantid').val(sVarId);
				jQuery('#item_varPrice').val(sPrice);		// Case ID: 09-10690 - Use variant price instead of product price
				jQuery('#item_stock').val(sStock);

				//Populate the variant_option field
				var sOptionVariant = '';
				for(i=1;i<=varLimit;i++) {
					sOptionVariant = sOptionVariant + jQuery('#item_variant_option'+i).val() + '-';
				}
				sOptionVariant = sOptionVariant.substring(0, sOptionVariant.length-1);
				jQuery('#item_variant_option').val(sOptionVariant);

				return;
			}

			//Process the new values for the latest dropdown box to be display
			//Remove all current selection options
			for(var i=nextSelectionObj.options.length-1;i>=0;i--) {
				nextSelectionObj.remove(i);
			}

			//Create a new "Please Select..." initial option
			var optn = document.createElement("OPTION");
			optn.text = "Please Select... ";
			optn.value = "0";
			nextSelectionObj.options.add(optn);

			//Only distinct option values are displayed. The array is sorted so checking the previous value against the current should be sufficient.
			//Set variable to hold the previous option value
			var sPreviousValue = '';

			//Process each of the matched values held within the filtered array
			for(var i = 0;i<arrResult.length;i++) {

				//Each filtered array value contains a string of '+' delimited values.  (all required values for individual variant options eg, option1..optionN, variantID, price, stock)
				var tmpStr = new String(arrVariantsFiltered[i]);
				var arrStr = tmpStr.split("+");

				//PLEASE NOTE:  The value position within each array element is constant.
				//Therefore the dropdown value can be determined by subtracting 1 from the currentIndex variable set above
				var dropDownVar = arrStr[(currentIndex-1)];

				//If the dropdown value doesn't match the previous value - ie, valid new value to display
				if(sPreviousValue != dropDownVar) {
					var sVar1 = arrStr[0];
					var sVar2 = arrStr[1];
					var sVar3 = arrStr[2];
					var sVar4 = arrStr[3];
					var sVarId = arrStr[4];
					var sPrice = arrStr[5];
					var sStock = arrStr[6];
					var sIsObsolete = arrStr[7];
					var sAction = "NOSHOW" //DONT SHOW IN DROPDOWN

					optn = document.createElement("OPTION");

					//Determine whether there are further selections lists to choose from.  Determine the number and store in a variable
					var xCounter = 0;
					for(var x=iPosition; x<varLimit; x++) {
						if(arrStr[x].length > 0) {
							xCounter++;
						}
					}

					//xCounter = 1 :  This will be the last selection box to be show.
					if(xCounter == 1) {
						//Display any stock information
						if(stock_behavior == "0") { // <!--stock behaviour Remove -->
							if (sStock > parseInt(outofstockvalue)  && sIsObsolete != 1) {
								sAction = "I"; // SHOW AS INSTOCK
							}
						} else if(stock_behavior == "1") { // <!-- stock behaviour display out of stock -->
							if (sStock < parseInt(outofstockvalue)   && sIsObsolete != 1) {
								sAction = "O"; // SHOW AS OUT OF STOCK
							} else if (sStock > parseInt(outofstockvalue)   && sIsObsolete != 1) {
								sAction = "I"; // SHOW AS INSTOCK
							}
						} else if(stock_behavior == "2" && sIsObsolete != 1) { // <!-- stock behaviour Allow back orders -->
							if(sIsObsolete != 1) {
								sAction = "I"; // SHOW AS INSTOCK
							}
						} else if(stock_behavior == "3" && sIsObsolete != 1) { // <!-- stock behaviour Allow as normal order -->
							if(sIsObsolete != 1) {
								sAction = "I"; // SHOW AS INSTOCK
							}
						}

						if(sAction != "NOSHOW") {

							if (sStock <= parseInt(lowstockvalue) ) {
								if (sStock > outofstockvalue) {

									optn.text = dropDownVar + ' - ' + lowstockmessage ; // + (sAction == "" ? "" : (" => " + sAction));
								} else {
									optn.text = dropDownVar + ' - ' + outofstockmessage ;
								}
							} else {
								optn.text = dropDownVar ;
							}
							optn.value = sAction == "O" ? "0" : dropDownVar;
							nextSelectionObj.options.add(optn);
						} else {
							//Variant is set to hide from displaying
							//optn.text = dropDownVar + ' - ' + outofstockmessage ; // + (sAction == "" ? "" : (" => " + sAction));
							//optn.value = sAction == "O" ? "0" : dropDownVar;
							//nextSelectionObj.options.add(optn);
						}
					} else {
						//Display no stock information
						optn.text = dropDownVar;
						optn.value = dropDownVar;
						nextSelectionObj.options.add(optn);
					}
				}

				sPreviousValue = dropDownVar;

				//Set all variant lists
				if(iPosition==1) {
					arrVariants2 = arrVariantsFiltered;
					arrVariants3 = arrVariants2;
					arrVariants4 = arrVariants2;

				} else if(iPosition==2) {
					arrVariants3 = arrVariantsFiltered;
					arrVariants4 = arrVariants3;

				} else if(iPosition==3) {
					arrVariants4 = arrVariantsFiltered;
				} else if(iPosition==4) {
				}


			}
		}
	}


	//Search array function
	Array.prototype.find = function(searchStr)
	{

		var returnArray = false;

		 for (i=0; i<this.length; i++)
		 {

		 	if (typeof(searchStr) == 'function')
		 	{

		 		if (searchStr.test(this[i]))
		 		{
		 			if (!returnArray)
		 			{
		 				returnArray = []
		 			}

		 			returnArray.push(i);
		 		}
		 	}
		 	else
		 	{
				var objStr = new String(this[i])

				if (objStr.indexOf(searchStr) != -1)
		 	      	{
		 	      		if (!returnArray)
		 	      		{
		 	      			returnArray = []
		 	      		}

		 	      		returnArray.push(i);
		 	      	}
			}
		}

		return returnArray;
	}


