



	function onLinkSeries(id) {
	
		if (document.getElementById('sd'+id) != null)
		{
			document.getElementById('sd'+id).style.textDecoration='underline';
			document.getElementById('sd'+id).style.color='#034da6';
		
		img = document.getElementById('svb'+id)
		if (img!=null)
			{
				img.src='/assets/img/buttons/view-o.gif';
				//bgimg.style.backgroundImage	 =  "url('/assets/img/shop/bg_section_on.gif')";
			}
		}
	
	}

	function offLinkSeries(id) {
		if (document.getElementById('sd'+id) != null)
		{	
			document.getElementById('sd'+id).style.textDecoration='none';
			document.getElementById('sd'+id).style.color='#000000';	
	
		img = document.getElementById('svb'+id)
		if (img!=null)
			{
				img.src='/assets/img/buttons/view.gif';
				//bgimg.style.backgroundImage	 =  "url('/assets/img/shop/bg_section_on.gif')";
			}
		}
	
	}




	function loadSectionBg()
	{
	image1 = new Image();
	image1.src = '/assets/img/shop/bg_section_on.gif'
	}
	
	loadSectionBg();
	
	//window.onload = loadSectionBg();



	function setcolour(AttributeValueId, pos)
	{
	document.getElementById('swatch_select'+pos).value= AttributeValueId;
	//document.getElementById('swatch-link').innerHTML= "<a href=\"Javascript:void(0)\" onClick=\"enlargeMedia(" + mediafileid + ")\">Enlarge</a>";			
	checkValidCombination(document.product, pos);
	}









var INVALID_BROWSER = "Sorry your browser does not work with this website"

// variable declarations
var allowSubmit = true;
var activeItemObject = null;

var ArrayP = new Array();
var selectedValidatedArray = new Array();
var selectedValidatedArrayIndexes = new Array();


var is = new Object()
is.ie = (document.all) ? 1:0
is.ns4 = (document.layers) ? 1:0
is.w3c = (document.getElementById) ? 1:0
is.win = (navigator.userAgent.toLowerCase().indexOf("win") > 0) ? 1:0
is.mac = (navigator.userAgent.toLowerCase().indexOf("mac") > 0) ? 1:0

var notAvailable = new String(" (Not available)");
var displayedProperties = new Array("spc","pr","pp","dv","mq","ps");



function initialiseArrayP(formArg) {

	var w = 0;

	for (var i = 0; i < formArg.elements.length;i++) {
		
		if (formArg.elements[i].name == "attributeValuesSelect") {
			ArrayP[w++] = formArg.elements[i];
		}
		else if(formArg.elements[i].name == "attributeValuesInput") {
			ArrayP[w++] = formArg.elements[i];
		}
	}


	for (var i = 0; i < ArrayP.length;i++) {
		if (ArrayP[i].name == "attributeValuesSelect")
	makeAttributesInvalid(0);
	loadItem(formArg);
	}
}


function getSelectedValuesAsArray(pBeforeIndex) {

	var selectedValuesArray = new Array();
	var selectedValuesArrayCounter = 0;
	
	for (var k = 0; k < pBeforeIndex;k++) {
		tmpObj = getObj(ArrayP[k].id+'alert');
		
		if (ArrayP[k].name == "attributeValuesSelect") {
			selectedValuesArray[selectedValuesArrayCounter++] = ArrayP[k].options[ArrayP[k].options.selectedIndex].value;
		}	
		if (ArrayP[k].name == "attributeValuesInput") {
			selectedValuesArray[selectedValuesArrayCounter++] = ArrayP[k].value;
		}
	}		
	return selectedValuesArray;
}	

function getAttributeValueIndex(pId)
{
	for (var k = 0; k < ArrayP.length;k++) {
		if (ArrayP[k].id==pId) return k;
	}	
}		



function makeAttributesInvalid(whichChanged) {

	var tmpObj;
	
	selectedValuesArray = getSelectedValuesAsArray(ArrayP.length);
		

	var tmpArray;
	for (var k = 0; k < ArrayP.length;k++) {
		tmpArray = new Array();
		for (var m=0;m<k;m++) {
			tmpArray[m] = selectedValuesArray[m];
		}
			
		if (ArrayP[k].name == "attributeValuesSelect") 
		{
			for (var l=0;l < ArrayP[k].length; l++) {
				tmpArray[k] = ArrayP[k][l].value;
				selectSelectedIndex = ArrayP[k].options.selectedIndex;

				if (findItemsByAttributes(tmpArray).length>0) 
				{
					enableOption(ArrayP[k][l]);		
				}
				else {
					disableOption(ArrayP[k][l]);					
				}
			}
		}
	
	
	}
	makeAttributesValid(whichChanged);
}



function makeAttributesValid(whichChanged) {

		var found = false;
		var selectedValuesArray = new Array();

		var vAlert = false;
		var vTmpObj;

		for (var i=0;i<ArrayP.length;i++) {

			if (ArrayP[i].name == "attributeValuesSelect") 
			{
				//alert(ArrayP[i].name );	
				if (ArrayP[i].options[ArrayP[i].options.selectedIndex].disabled==false) 
				{
					selectedValuesArray[i] =    ArrayP[i].options[ArrayP[i].options.selectedIndex].value;					
					selectedValidatedArray[i] = ArrayP[i].options[ArrayP[i].options.selectedIndex].value;					
					selectedValidatedArrayIndexes[i] = ArrayP[i].options.selectedIndex;
					
				//	alert('swatch_' + ArrayP[i].options[ArrayP[i].options.selectedIndex].value);
					
				}
				else {

					selectedValuesArray[i] = selectedValidatedArray[i];
					if (findItemsByAttributes(selectedValuesArray).length>0) {
								enableOption(ArrayP[i][selectedValidatedArrayIndexes[i]]);
								ArrayP[i].options.selectedIndex = selectedValidatedArrayIndexes[i];					
					}			
					else {

						vAlert = true;										
						found = false;
						var selectedValue;
						for (var j=0;j<ArrayP[i].length;j++) {
							selectedValuesArray[i] = ArrayP[i][j].value;
							if (findItemsByAttributes(selectedValuesArray).length>0)
							{
								enableOption(ArrayP[i][j]);
								if (!found) {
									selectedValue = ArrayP[i][j].value;
									ArrayP[i].options.selectedIndex = j;
									found = true;
								}		
							}
							else {
								disableOption(ArrayP[i][j]);
							}
						}
						selectedValuesArray[i] = selectedValue;	
						selectedValidatedArray[i] = selectedValue;	
					}
				}						
			}
		}	
			
			
}		

function enableOption(theOption) {
	if (theOption.disabled == true) {
		theOption.text = theOption.text.substring(0,theOption.text.length - (notAvailable.length+1));
		theOption.style.color = "#000000";
		theOption.disabled = false;	
	}	
}

function disableOption(theOption) {
	if (theOption.disabled == false) {
		theOption.text += ' ' + notAvailable;
		theOption.style.color = "#828282";
		theOption.disabled = true;	
	}	
}






function checkValidCombination(formArg,whichChanged) {

	if (!allowSubmit) { return; } 

	// bug fix for IE
	if ((typeof whichChanged != "undefined") && whichChanged != null && ArrayP[whichChanged].name == "attributeValuesSelect")
	{
		if (ArrayP[whichChanged].options[ArrayP[whichChanged].options.selectedIndex].disabled == true)
		 {
			if (selectedValidatedArray.length>0) {
				for (var i=0;i<ArrayP[whichChanged].options.length;i++) 
				{
					if (ArrayP[whichChanged][i].value == selectedValidatedArray[whichChanged])
					 ArrayP[whichChanged].options.selectedIndex = i;
				}
			}	
			return;
		}	
	}
	
	if ((typeof whichChanged != "undefined") && whichChanged != null)
	{ 
		makeAttributesInvalid(whichChanged);
		//alert("makeAttributesInvalid(whichChanged)");
	}
	
	loadItem(formArg, whichChanged);
	
}






function loadItem(formArg, whichChanged)
{

	var a = new Array();
	var ai = 0;

	for (var i = 0; i < formArg.elements.length;i++)
	{

		if (formArg.elements[i].name == "attributeValuesSelect") {
			a[ai++] = formArg.elements[i].options[formArg.elements[i].options.selectedIndex].value;
		}
		else if(formArg.elements[i].name == "attributeValuesInput") {
			a[ai++] = formArg.elements[i].value;
		}
		
	}


	var arrPos = findProdIdForItem(a);
		
	changeItem(arrPos, whichChanged); 
		

}	





function changeItem(arrPos, whichChanged) {

itemObjToDisplay = prodOptArray[arrPos];

	
	if (document.getElementById || document.all){

		if (itemObjToDisplay == null) {
			itemObjToDisplay = activeItemObject;
		}

//		var objectInPage = null;
//		for (var d = 0; d < (displayedProperties.length-2); d++)
//		{
//			
//			objectInPage = getObj(displayedProperties[d]);
//			alert(displayedProperties[d]);
//
//			if (objectInPage!=null)
//			{
//				objectInPage.innerHTML = eval("itemObjToDisplay." + displayedProperties[d]);
//			}
//		}



		var spc = itemObjToDisplay.spc;
		getObj('spc').innerHTML = spc;
		//getObj('dv').innerHTML = itemObjToDisplay.dv;
		
		
		
		var varOptionInfo = itemObjToDisplay.pa;
		
		getObj('opt-info').innerHTML = varOptionInfo;
	
		
		
		var price = itemObjToDisplay.pr;
		getObj('pr').innerHTML = '&pound;' + price;
		
		var previousPrice = itemObjToDisplay.pp;
		if (previousPrice> 0)
		{
			getObj('pp').innerHTML = '&pound;' +  itemObjToDisplay.pp;	
		}
		else
		{
			getObj('pp').innerHTML = '';
		}
		
		

		



		var minqty = itemObjToDisplay.mq;
		//alert( minqty);
		if (minqty > 1) {	
		document.productbuy.spcqty.value = minqty;
		getObj('mq').innerHTML = "<div class='\pa'\>Minimum Qty </div><div class='\pav'\>"  + minqty + "</div>";	
		}
		else
		{
		getObj('mq').innerHTML = "";
		}


		var packsize = itemObjToDisplay.ps;
		var productpriceqty = itemObjToDisplay.pq;
		var productpriceqtytypeid = itemObjToDisplay.pt;
		var packSizeType = "";
		var boxContents = "Box Contents";
		
		
		switch (productpriceqtytypeid)
		{
		case "2":
			if (productpriceqty > 1)
			{
			var pricePer = "Price per " + productpriceqty + " pairs";
			}
			else
			{
			var pricePer = "Price for 1 pair";
			}		
			packSizeType = " pairs";
			break;
		default:
			
			if (productpriceqty > 1)
			{
			var pricePer = "Price per " + productpriceqty;
			}
			else
			{
			var pricePer = "Price for 1 ";	
		
			}
			break;
		}
		
		
		
		
		document.productbuy.boxqty.value = packsize;	
		
		if (packsize > 1) {
		
		getObj('ps').innerHTML = "<div class='\pa'\>" + boxContents + "</div><div class='\pav'\>"  +  packsize + packSizeType + "</div><div class='\pa'\>" + pricePer +  "</div><div class='\pav'\>&pound;" +  CurrencyFormat((price/packsize) * productpriceqty)   + " </div>";	
		
		}
		else
		{
		getObj('ps').innerHTML = "";
		}
		
		
		


		var tierpricecount = itemObjToDisplay.tp;
		if (tierpricecount > 0) 
		{	
			$("#tp").load("/store/fetch/tierprice.asp?spc=" + spc + "&rnd" + Math.random());
		}
		else
		{
		getObj('tp').innerHTML = "";
		}
		



		var mediafile = itemObjToDisplay.mf;
		if (mediafile != '000000')
		{
		//document.getElementById('product_image').src = "/assets/shop/pd/" + mediafile + ".jpg"; 
		
				strMedia = prodMediaArray[0]['media_' + mediafile];
				strMediaTile =  prodMediaArray[1]['media_' + mediafile] ;
				document.getElementById('product_image').src  = strMedia;
				document.getElementById('product_title').innerHTML   = strMediaTile;

		}
		
		



		
		document.productbuy.spc.value = itemObjToDisplay.spc;	

		swatch = getObj('swatch_current');
			if (swatch!=null)
			{
			//	swatch.src = '/store/assets/media/sc/' + itemObjToDisplay.swatch + '.jpg';	
			}		
			
			

			
			
	     for (var i = 0; i < prodOptAttValArray[arrPos].length; i++)
		{
          optionValue = prodOptAttValArray[arrPos][i]
	
				
		 try
			{
	
				strImg = prodSwatchArray[0]['swatch_' + optionValue] + '.jpg';
				swatch_name =  prodSwatchArray[1]['swatch_' + optionValue] ;
				swatch_current =   prodSwatchArray[2]['swatch_' + optionValue] ;
				
				swatchImg = getObj('swatch_current' + swatch_current);
				//alert(swatchImg + " " + optionValue);
				
				if (swatchImg!=null)
				{
				swatchImg.src = '/assets/shop/sc/' + strImg;	
				}
				
				swatchName = getObj('colour_name'+ swatch_current);
	
				if (swatchName!=null)
				{
					swatchName.innerHTML = swatch_name;
				}			
					
			}	
			catch(e)
			{
				
				// not set
				
			}
				
        }		
			

	
	
	}
	else {
		alert (INVALID_BROWSER);
		return;
	}
}





	function updateBuyQty(orderQty)
	{
	 var boxqty = document.productbuy.boxqty.value;

		 var orderItemQty = (orderQty * boxqty ) 
		 var boxText = "";
		 if (boxqty>1)
		 {
				boxText = orderQty + " Boxes";
				getObj('orderitemqty').innerHTML = "Total Qty: " + orderItemQty + "  (" + boxText +  ")";				
		 }
		 else
		 {
			 getObj('orderitemqty').innerHTML = "";
		 }

	
	}





function CurrencyFormat(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}






function findProdIdForItem(attributeValues)
{
		var joinedAttr = attributeValues.join(",").toLowerCase();
        for (var i = 0; i < prodOptAttValArray.length; i++)
		{
           if ( joinedAttr == prodOptAttValArray[i].join(",").toLowerCase())
		   {
			    return i;
				break;
                }

        }
        return null;
}



function getObj(name)
{
        if (document.getElementById) {
                if (document.getElementById(name)) {
                        return document.getElementById(name);
                }
        }
        else if (document.all) {
                if (document.all[name]) {
                        return document.all[name];
                } 
        }
        else {
                alert (INVALID_BROWSER);
                return;
        }
}




function findItemsByAttributes(attributeList) {
	var itemsFound = new Array();
	var itemsFoundIndex = 0;
	var found = true;
	for (var i = 0; i < prodOptAttValArray.length;i++) {
		
		var itemAttrValue = prodOptAttValArray[i];
		var itemAttrValueJoined = itemAttrValue.join('##');
		found = true;
		for (var j=0; j < attributeList.length;j++) 
		{
			for (var x=0;x<itemAttrValue.length;x++)
			{
				if (itemAttrValueJoined.search(attributeList[j])==-1)
				found = false;
			}
		}
		
		if (found) itemsFound[itemsFoundIndex++] = i;
		
	}
	return itemsFound;
}



//function swapimage(mediafile, width, height, enlarge, productid)


function swapimage(mediafileid, enlarge)
{
	
  	//var elem = document.getElementById("product_image");
 	//elem.width = width;
	//elem.height = height;	
	//document.getElementById('product_image').src = mediafile ; 

		if (mediafileid != '000000')
		{
		//document.getElementById('product_image').src = "/assets/shop/pd/" + mediafile + ".jpg"; 
		
				strMedia = prodMediaArray[0]['media_' + mediafileid];
				strMediaTile =  prodMediaArray[1]['media_' + mediafileid] ;
				document.getElementById('product_image').src  = strMedia;
				document.getElementById('product_title').innerHTML   = strMediaTile;

		}
		
		


	if (enlarge ==1)
	{
	//document.getElementById('product_enlarge').innerHTML="<img src=\"/assets/img/enlarge_image.gif\" alt=\"Enlarge Image\"><a href=\"Javascript:void(0)\" onClick=\"enlargeImage(" + productid + ")\">See larger image</a>";
	document.getElementById('product_enlarge').innerHTML="<img src=\"/assets/img/icons/enlarge_image.gif\" alt=\"Enlarge Image\"><a href='#' class='ex2trigger' onclick=\"$('#imgpu').jqmShow();\">See larger image</a>";

}
	else
	{
		if (document.getElementById('product_enlarge') != null)
		{
			document.getElementById('product_enlarge').innerHTML="";	
		}
	}
}









function enlargeImage(productid) 
{
	aWindow = window.open("/store/enlarge.asp?wpid=" + productid,"enlarge","location=no;menubar=no,scrollbars=yes,resizable=yes,width="+640+",height="+650+",top=28,left=40");
}

function enlargeMedia(paid) 
{
	aWindow = window.open("/store/swatch.asp?paid=" + paid,"enlarge","menubar=yes,scrollbars=yes,resizable=1,width="+500+",height="+500+",top=40,left=40");
}





