


	function onLinkSeries(id) {
	
		if (document.getElementById('sd'+id) != null)
		{
			document.getElementById('sd'+id).style.textDecoration='underline';
			document.getElementById('sd'+id).style.color='#9e088f';
		
		bgimg = document.getElementById('sbg'+id)
		if (bgimg!=null)
			{
				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';	
	
			bgimg = document.getElementById('sbg'+id)
			if (bgimg!=null)
			{
				bgimg.style.backgroundImage	 =  "url('/assets/img/shop/bg_section.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);
	}

	function setcolourAjax(pid, AttributeValueId, pos)
	{
	document.product.pavid[pos].value = AttributeValueId;
	//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);
	
	 updateOptions(pid, pos);
	}




	

	var clickmessage="Copyright Image"
	
	function disableclick(e) {
		if (document.all) {
		if (event.button==2||event.button==3) {
		if (event.srcElement.tagName=="IMG")
		{
		alert(clickmessage);
		return false;
		}
		}
		}
		else if (document.layers) 
		{
		if (e.which == 3) {
		alert(clickmessage);
		//return false;
		}
		}
		else if (document.getElementById)
		{
		if (e.which==3&&e.target.tagName=="IMG")
		{
		alert(clickmessage);
		return false;
		}
		}
	}
	
	
	
	function associateimages()
	{
		for(i=0;i<document.images.length;i++)
		document.images[i].onmousedown=disableclick;
	}






	$(function()
	 {	
		
			//Tabs
			$(".tab_content").hide();
			$("ul.tabs li:first, ul.tabs li:first").addClass("active").show();
			$(".tab_content:first, .tab_content:first").show();
			
			//On Click Event
			$("ul.tabs li").click(function () {
				$("ul.tabs li").removeClass("active"); //Remove any "active" class
				$(this).addClass("active"); //Add "active" class to selected tab
				$(".tab_content").hide(); //Hide all tab content
				var activeTab = $(this).find("a").attr("href"); //Find the href
				$(activeTab).fadeIn(100); //Fade in the active ID content
				return false;
			});
			
	
	
		});
	
	$.ajaxSetup ({
		// Disable caching of AJAX responses
		cache: false
	});


	function VideoTabPlay(ProductId, VideoId)
	{
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(".tabs-3").addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
			
			$("#videoplayer").load("/store/product/youtube.asp?pid=" + ProductId + "&mvid=" + VideoId);	
			$("#tabs-3").show(); //Fade in the active ID content
			
			return false;	
	}
	







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;
			var spc = itemObjToDisplay.spc;
			getObj('spc').innerHTML = itemObjToDisplay.spc;
			getObj('dv').innerHTML = itemObjToDisplay.dv;
			
			
			var price = itemObjToDisplay.pr;
			getObj('pr').innerHTML = '&pound;' + price;
			
			var previousPrice = itemObjToDisplay.pp;
			if (previousPrice> 0)
			{
				getObj('pp').innerHTML = '<span>&pound;' +  itemObjToDisplay.pp + '</span>  now ';	
			}
			else
			{
				getObj('pp').innerHTML = '';
			}
			
			
	
			
	
	
	
			var minqty = itemObjToDisplay.mq;
			//alert( minqty);
			if (minqty > 1) {	
			document.productbuy.spcqty.value = minqty;
			getObj('mq').innerHTML = " &nbsp; Minimum Order Quantity: "  + minqty;	
			}
			else
			{
			getObj('mq').innerHTML = "";
			}
	
	
			var packsize = itemObjToDisplay.ps;
			
	
			if (packsize > 1) {	
			getObj('ps').innerHTML = "(Pack Size: "  + packsize + ", &nbsp;&pound;" +  CurrencyFormat(price/packsize) + " each)";	
			}
			else
			{
			getObj('ps').innerHTML = "";
			}
	
	
			var tierpricecount = itemObjToDisplay.tp;
	
			if (tierpricecount > 0) 
			{	
				$("#tp").load("/store/product/get/tierprice.asp?spc=" + spc + "&rnd" + Math.random());
			}
			else
			{
			getObj('tp').innerHTML = "";
			}
	
			
			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);
					
					if (swatchImg!=null)
					{
					swatchImg.src = '/media/img/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 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 pausecomp(millis) 
	{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); } 
	while(curDate-date < millis);
	} 


	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)
	{
		
		var elem = document.getElementById("product_image");
		elem.width = width;
		elem.height = height;	
		document.getElementById('product_image').src = mediafile ; 
	
	
	
	
		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>";
		}
		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 watchVideo(productid) 
	{
		aWindow = window.open("/store/video.asp?wpid=" + productid,"video","location=no;menubar=no,scrollbars=yes,resizable=yes,width="+540+",height="+450+",top=100,left=100");
	}
	
	
	
	
	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");
	}
	
	
	
	function PlayVideo(productid, MediaVideoId) 
	{
		aWindow = window.open("/store/video.asp?wpid=" + productid + "&mvid=" + MediaVideoId,"video","location=no;menubar=no,scrollbars=yes,resizable=yes,width="+540+",height="+450+",top=100,left=100");
	}
	






	function submitAttriubtes()
    {

    
     var options = { 
        target:        '#optinfo',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
       // success:       showResponse,  // post-submit callback 
		clearForm: true  
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
       // dataType:  xml        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind to the form's submit event 
    $('#product-select').submit(function()
	 { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });    
       
    }



    // bind to the form's submit event 
    function submitAttriubteForm()
	 { 
	 
	var rand_no = Math.random();

	 
     var options = { 
        target:        '#optinfo',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
       // success:       showResponse,  // post-submit callback 
		clearForm: false ,
		type: "post",
		url:       "/store/product/get/options.asp?" + rand_no   
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
       // dataType:  xml        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 	 
	 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $('#product-select').ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
     
    }
	
	
	
	

	function updateOptions(productId, pos)
	{
		
		
		//alert(document.product.pavid.options[document.product.pavid.selectedIndex].value);
	 var pavids = "";
	 var attr = "";
	 ddcount = document.product.pavid.length;
	 for (i = 0; i < ddcount; i++)
		{
			//document.filter.authid[i].value + ",";
			//alert(document.product.pavid[i].options[document.product.pavid[i].selectedIndex].value);
			//alert(i);
			
			// (document.product.pavid[i].selected) 
			//{
			//var chosen = document.product.pavid[i].value	
			//}
			pavids = pavids +  document.product.pavid[i].value;
			attr = attr + document.product.attr[i].value;
			if (i < ddcount-1)
			{
				pavids = pavids	+ ","
				attr = attr	+ ","
			}
			
			if (i > pos)
			{
			//$("#atr"+ document.product.attr[i].value).val('0'); 
			}
			else
			{
				if ( (i+1) < ddcount )
				{

				$("#atr" + document.product.attr[i+1].value).removeAttr("disabled");	
				}
			}
		}
		
	
		
	 $.ajaxSetup ({   
        cache: false  
    });   
	 
	 
	 
    var ajax_load = "<img src='/assets/img/icons/loader.gif' width='16' height='16' alt='loading' />";   
	
	var rnd = Math.random();
       
//  load() functions   
    var loadUrl = "/store/product/get/options.asp?pid=" + productId + "&pavid=" + pavids + "&attr=" + attr + "&pos=" + pos + "&rnd=" + rnd;   
  $("#optinfo").html(ajax_load).load(loadUrl);   

	}




	function getSizeConverter()
	{
			window.open("/store/product/sizeconvert.asp","convert","menubar=yes,scrollbars=yes,resizable=1,width="+400+",height="+400+",top=40,left=60");
	}




	function getTierPrices(spc)
	{
		
	$("#tp").load("/store/product/get/tierprice.asp?spc=" + spc + "&rnd" + Math.random());	
		
	}











