	var cart_y_offset = 0;
	var fullSizeListVisible = true;
	var fullSizeListVisible_popup = true;

	function fn_Search(){
		var obj = document.getElementById("searchterm")
			if(obj.value == ""){alert("You must enter a keyword before a search can proceed.");return false;}
		return true;
	}

    function showxcart() {
	var oHttp = GetXmlHttpObject();
		try {
			oHttp.onreadystatechange = function() { displayxcartdata(oHttp); }	        
			var url = location.protocol + "//" + location.hostname + "/default" + "." + "a" + "spx?Z=C&action=bagx";
			oHttp.open("POST", url, true);
			oHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			oHttp.setRequestHeader("Content-length", url.length);
//			oHttp.setRequestHeader("Connection", "close");
			showCartLoadingBox();
			oHttp.send("");
			return false;
		}catch(e){
			return true;
		}
		return false;
    }

	function displayxcartdata(oHttp) {
		if (oHttp.readyState == 4) {	
			if (oHttp.status == 200) {	
				try{
					var rtn = oHttp.responseText;   			    
					var cartDiv = document.getElementById("CartSummaryPopUp");
					if (cartDiv != null) {
//			        cartDiv.style.visibility = "hidden";
					var targetDiv = document.getElementById('ajax_feedback');
					if (targetDiv != null) {
						InsertElementOnPage(targetDiv, rtn, 1);
						var cartContentDiv = document.getElementById('cartContent');
						if (cartContentDiv != null) {
							InsertElementOnPage(cartDiv, cartContentDiv.innerHTML, 1);
						}
						InsertElementOnPage(targetDiv, '&nbsp;', 1);

						switchResizing('cart');
						fnSetOpacity(cartDiv, 1);
//              cartDiv.style.visibility = "visible";	 
					}
				}
				}catch(e){}   			
			}		
		}
	}

	function hidexcartdata(){
		var cartDiv = document.getElementById("CartSummaryPopUp");
		if (cartDiv != null) {
			needsResizingBag = false;
			switchResizing('');
//			faderDirections["CartSummaryPopUp"] = -1;
//			fSmoothShow("CartSummaryPopUp", 25, 1, 0, 1, -0.1);
//        cartDiv.style.visibility = "hidden";
			cartDiv.style.display = "none";
		}
		return false;
	}

    var needsResizingBag = false;

    function handleWindowResize() {
      var wdth;
      if (document.all)
      {wdth = document.body.clientWidth;}
      else
      {wdth = window.innerWidth;}
      
      if (needsResizingBag) {
        document.getElementById("BagSummary").style.left = (wdth + 768) / 2 - 222 + 'px';
      }
    }

	function handleWindowYScroll() {
		var y;
		// scrolling offset calculation via www.quirksmode.org
		if (self.pageYOffset){
		y = self.pageYOffset;
		}else if (document.documentElement && document.documentElement.scrollTop) { 
			y = document.documentElement.scrollTop; 
		}else if (document.body) { 
			y = document.body.scrollTop; 
		}

		if (needsResizingBag) {
			if (y > cart_y_offset) {
				document.getElementById("BagSummary").style.top = y + 'px';}
			else {
			document.getElementById("BagSummary").style.top = cart_y_offset + 'px';}
		}
	}

	function switchResizing(obj) {
		switchFound = false;
		if (obj != null) {
			if (obj == 'cart') {
				needsResizingBag = true;
				switchFound = true;
			}
		}
		if (switchFound) {
			var popupObj = document.getElementById("CartSummary");
			offsetPair = findPos(popupObj);
			cart_y_offset = offsetPair[1] + 22;
			window.onresize = handleWindowResize;
			window.onscroll = handleWindowYScroll;
			handleWindowResize();
			handleWindowYScroll();
		}
		else {
			window.onresize = null;
			window.onscroll = null;
		}
	}


	function fHide(){
		needsResizingBag = false;
		switchResizing('');
//      document.getElementById("CartSummaryPopUp").style.visibility = "hidden";
//		if (document.getElementById("CartSummaryPopUp").style.display == '') {
//			fSmoothShow("CartSummaryPopUp", 25, 1, 0, 1, -0.1);
//		}
		document.getElementById("CartSummaryPopUp").style.display = "none";
	}

    
    function updateCartQty() {
      var cartCommentDiv = document.getElementById("qtyCartArea");
      var cartQtyDiv = document.getElementById("CX");
	  var cartShowLbl = document.getElementById("cartShowTextPlace");
      var qty = 0;

      if (cartQtyDiv != null)  {
        qty = cartQtyDiv.value;
      }
      if (cartCommentDiv != null) {
        cartCommentDiv.innerHTML =  qty;// + ' item(s) in shopping bag';
      }
	  
	  if (cartShowLbl != null) {
	    if (qty == 0) {
		  cartShowLbl.style.display = 'none';
		}
		else {
		  cartShowLbl.style.display = 'inline';
		}
	  }
    }
	
	function fireProductPopup(styleCode) {
		if (styleCode != '') {
			document.getElementById("styled_popup").style.display = "";
			document.getElementById("TB_overlay").style.display = "";
		  
			var oHttp = GetXmlHttpObject();
			try {
				oHttp.onreadystatechange = function() { displayxprodpopup(oHttp); }	        
				var url = location.protocol + "//" + location.hostname + "/support" + "." + "a" + "spx?iSAMS=axpop&cs=" + styleCode;
				oHttp.open("POST", url, true);
				oHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				oHttp.setRequestHeader("Content-length", url.length);
//				oHttp.setRequestHeader("Connection", "close");
				oHttp.send("");
				return false;
			}catch(e){
				return true;
			}
		}
		return false;
	}
  
      function fRenderCart(oHttp){    
	    if (oHttp.readyState == 4) {	
		    if (oHttp.status == 200) {		    
		      try{
			      var rtn = oHttp.responseText;   			    
            var cartDiv = document.getElementById("CartSummaryPopUp");
            if (cartDiv != null) {
//			        cartDiv.style.visibility = "hidden";
              var targetDiv = document.getElementById('ajax_feedback');
			  InsertElementOnPage(targetDiv, rtn, 1);
              var cartContentDiv = document.getElementById('cartContent');
              if (cartContentDiv != null) {
                InsertElementOnPage(cartDiv, cartContentDiv.innerHTML, 1);
              }
              InsertElementOnPage(targetDiv, '&nbsp;', 1);
              updateCartQty();
              switchResizing('cart');
//              cartDiv.style.visibility = "visible";	 
					faderDirections["CartSummaryPopUp"] = -1;
			        setTimeout("fHide()", 10000);
            }
			    }catch(e){}   			
		    }		
	    }
    }

	function fn_iSAMS_HotLink(_pdId, _pdTitle, _hsType, evt) {
		if(navigator.userAgent.indexOf('Safari') > 1) {
			return fn_iSAMS_HotLink_z(_pdId, _pdTitle, _hsType);
		}
		var o = fPosition(evt);
		var o2 = document.getElementById("oLoader");
		o2.style.display = "";
		o2.style.top = o.y + "px";
		o2.style.left = o.x + "px";
		return fn_iSAMS_HotLink_z(_pdId, _pdTitle, _hsType, '65'); // 65 - Online books
	}

	function fn_iSAMS_HotLink_Src(_pdId, _pdTitle, _hsType, evt, _src) {
		if(navigator.userAgent.indexOf('Safari') > 1) {
			return fn_iSAMS_HotLink_z(_pdId, _pdTitle, _hsType, _src);
		}
		var o = fPosition(evt);
		var o2 = document.getElementById("oLoader");
		o2.style.display = "";
		o2.style.top = o.y + "px";
		o2.style.left = o.x + "px";
		if ((_src == null) || (_src == '')) { _src = '65'; }
		return fn_iSAMS_HotLink_z(_pdId, _pdTitle, _hsType, _src);
	}

	function fn_iSAMS_HotLink_z(_pdId, _pdTitle, _hsType, _src) {
		var pdId = parseInt(_pdId);
		var hsType = parseInt(_hsType);
		var xurl = '';

		if ((_src == null) || (_src == '')) { _src = '65'; }

		if(navigator.userAgent.indexOf('Safari') > 1) {
			document.location = location.protocol + "//" + location.hostname + "/default.a" + 'spx?P=' + pdId + "&source=" + _src;
			return true;
		}

		switch(hsType) {
			case 1: // product redirect
				break;
			case 2: // product pop-up
				if (pdId > 0) {
					xurl = location.protocol + "//" + location.hostname + "/support" + "." + "a" + "spx?iSAMS=axpop&pid=" + pdId + "&pp_src=" + _src;
				}
				break;
			case 3: // link redirect
				break;
			case 4: // link pop-op by target = _blank
				break;
			default:
				break;
			return false;
		}

		if (xurl != '') {
			document.getElementById("styled_popup").style.display = "";
			document.getElementById("TB_overlay").style.display = "";

			var oHttp = GetXmlHttpObject();
			try {
				oHttp.onreadystatechange = function() { displayxprodpopup(oHttp); }	        
				oHttp.open("POST", xurl, true);
				oHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				oHttp.setRequestHeader("Content-length", xurl.length);
//				oHttp.setRequestHeader("Connection", "close");
				oHttp.send("");
				return false;
			}catch(e){
				return true;
			}
		}
		return true;
	}
	
	function displayxprodpopup(oHttp) {
		if (oHttp.readyState == 4) {	
			if (oHttp.status == 200) {	
				try{
					var rtn = oHttp.responseText;
					var o2 = document.getElementById("oLoader");
					if (o2 != null) {
						o2.style.display = "none";
					}
					var resDiv = document.getElementById("styled_popup");
					if (resDiv != null) {
						InsertElementOnPage(resDiv, rtn, 1);
					}
					try {
						document.location="#top";
					}
					catch(e) {
					}
				}catch(e){}
			}
		}
	}

	function hidexprodpopup() {
		var resDiv = document.getElementById("styled_popup");
		if (resDiv != null) {
			InsertElementOnPage(resDiv, '&nbsp;', 1);
			resDiv.style.display = "none";
			document.getElementById("TB_overlay").style.display = "none";
		}
	}
	
	function performxcall(targetName, popupMode, loaderName, xurl) {
		if (xurl != '') {
			if (targetName != null) {
				var targetObj = document.getElementById(targetName);	

				if (popupMode == true) {
					document.getElementById("styled_popup").style.display = "";
					document.getElementById("TB_overlay").style.display = "";
				}

				var oHttp = GetXmlHttpObject();
				try {
					oHttp.onreadystatechange = function() { displayxpopup(oHttp, loaderName, targetName); }
					oHttp.open("POST", xurl, true);
					oHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					oHttp.setRequestHeader("Content-length", xurl.length);
					oHttp.send("");
					return false;
				}catch(e){
					return true;
				}
			}
		}
		return true;
	}
	
	function displayxpopup(oHttp, loaderName, targetName) {
		if (oHttp.readyState == 4) {
			if (oHttp.status == 200) {
				try{
					var rtn = oHttp.responseText;
					if (loaderName != "") {
						var o2 = document.getElementById(loaderName);
						if (o2 != null) {
							o2.style.display = "none";
						}
					}
					if (targetName != "") {
						var resDiv = document.getElementById(targetName);
						if (resDiv != null) {
							InsertElementOnPage(resDiv, rtn, 1);
						}
					}
				}catch(e){}
			}
		}
	}

	function hidexpopup(targetName) {
		if (targetName != "") {
			var resDiv = document.getElementById(targetName);
			if (resDiv != null) {
				InsertElementOnPage(resDiv, '&nbsp;', 1);
				resDiv.style.display = "none";
				document.getElementById("TB_overlay").style.display = "none";
				document.getElementById("styled_popup").style.display = "none";
			}
		}
	}

	function showCartLoadingBox() {
		var cartDiv = document.getElementById("CartSummaryPopUp");
		var cartLoaingDiv = document.getElementById("cartLoadingContent");
		if ((cartDiv != null) && (cartLoaingDiv != null)) {
			InsertElementOnPage(cartDiv, cartLoaingDiv.innerHTML, 1);
			switchResizing('cart');
//			cartDiv.style.visibility = "visible";
			fnSetOpacity(cartDiv, 1);
			cartDiv.style.display = "";
		}
	}


	function fnInitZoomVariables(_photo_w, _photo_h, _photo2_w, _photo2_h, _zoom_w, _zoom_h, _border, _smallPhotoDivName, _smallPhotoShadowDivName, _bigPhotoDivName, _flyBoxDivName, _flyBoxPhotoDivName, _zoomBoxDivName, _popupDivName, _objName) {

		var SettingsObject = new Object; 

		SettingsObject.photo_w = _photo_w;
		SettingsObject.photo_h = _photo_h;
		SettingsObject.photo2_w = _photo2_w;
		SettingsObject.photo2_h = _photo2_h;
		SettingsObject.zoom_w = _zoom_w;
		SettingsObject.zoom_h = _zoom_h;
		SettingsObject.border = _border;

		SettingsObject.ratio_x = _photo2_w / _photo_w;
		SettingsObject.ratio_y = _photo2_h / _photo_h;

		SettingsObject.fly_w = _zoom_w / SettingsObject.ratio_x - 1;
		SettingsObject.fly_h = _zoom_h / SettingsObject.ratio_y - 1;
		
		SettingsObject.smallPhotoDivName = _smallPhotoDivName;
		SettingsObject.smallPhotoShadowDivName = _smallPhotoShadowDivName;
		SettingsObject.bigPhotoDivName = _bigPhotoDivName;
		SettingsObject.flyBoxDivName = _flyBoxDivName;
		SettingsObject.flyBoxPhotoDivName = _flyBoxPhotoDivName;
		SettingsObject.zoomBoxDivName = _zoomBoxDivName;
		SettingsObject.popupDivName = _popupDivName;
		SettingsObject.objName = _objName;

		SettingsObject.smallPhotoOffset = {x:0, y:0};
		SettingsObject.bigPhotoOffset = {x:0, y:0};

		SettingsObject.popupOffset = {x:0, y:0};

		if (_popupDivName != '') {
			var popupDiv = document.getElementById(_popupDivName);
			if (popupDiv != null) {
				offsetPair = findPos(document.getElementById(_popupDivName));
				SettingsObject.popupOffset.x = offsetPair[0];
				SettingsObject.popupOffset.y = offsetPair[1];
			}
		}

		return SettingsObject;
	}
	
	function fnTrackMouse(setObj, evt) {
		if (setObj == null) {return;}
		max_x = setObj.photo_w + setObj.border - setObj.fly_w - setObj.border*2;
		max_y = setObj.photo_h + setObj.border - setObj.fly_h - setObj.border*2;

		min_x = setObj.border;
		min_y = setObj.border;

		max_x2 = setObj.zoom_w/1 - setObj.photo2_w;
		max_y2 = setObj.zoom_h/1 - setObj.photo2_h;
		min_x2 = 0;
		min_y2 = 0;

		var bigPhoto = document.getElementById(setObj.bigPhotoDivName);
		var flyDiv = document.getElementById(setObj.flyBoxDivName);
		var flyPhotoDiv = document.getElementById(setObj.flyBoxPhotoDivName);
		if (flyPhotoDiv != null) {
			var o = fPosition(evt);
			
			var smallPhoto = document.getElementById(setObj.smallPhotoDivName);
			
			real_x = o.x - setObj.smallPhotoOffset.x - setObj.popupOffset.x;
			real_y = o.y - setObj.smallPhotoOffset.y - setObj.popupOffset.y;
			
			x = real_x - setObj.fly_w/2;
			y = real_y - setObj.fly_h/2;

			if (x > max_x) {x = max_x;}
			if (y > max_y) {y = max_y;}
			if (x < min_x) {x = min_x;}
			if (y < min_y) {y = min_y;}
			
			x2 = 0 - (real_x) * setObj.ratio_x + (setObj.zoom_w)/2;
			y2 = 0 - (real_y) * setObj.ratio_y + (setObj.zoom_h)/2;
			
			if (x2 > min_x2) {x2 = min_x2;}
			if (y2 > min_y2) {y2 = min_y2;}
			if (x2 < max_x2) {x2 = max_x2;}
			if (y2 < max_y2) {y2 = max_y2;}
			
			bigPhoto.style.left = x2 + 'px';
			bigPhoto.style.top = y2 + 'px';

			flyDiv.style.left = setObj.smallPhotoOffset.x - setObj.border + x + 'px';
			flyDiv.style.top = setObj.smallPhotoOffset.y - setObj.border + y + 'px';
			
			flyPhotoDiv.style.left = 0 - x + 'px';
			flyPhotoDiv.style.top = 0 - y + 'px';
		}
	}

	function fnStepOnOff(setObj, onoff) {
		if (setObj == null) {return;}
		var intObj = document.getElementById('globalBackGround');
		if (onoff == true) {
			document.getElementById(setObj.smallPhotoShadowDivName).style.display = '';
			document.getElementById(setObj.flyBoxDivName).style.display = '';
			faderDirections[setObj.zoomBoxDivName] = 1;
			fSmoothShow(setObj.zoomBoxDivName, 25, 0, 1, 0, 0.1);

			if (setObj.objName != '') {
				if (navigator.appName.indexOf("Microsoft") != -1) {
				  intObj.onmousemove = function() {return fDblCheckZoom(setObj, event);}
				}
				else { // Firefox, Opera, Safari etc.
				  intObj.setAttribute("onmousemove", "fDblCheckZoom(" + setObj.objName + ", event);");
				}
			}
		}
		else {
			document.getElementById(setObj.smallPhotoShadowDivName).style.display = 'none';
			document.getElementById(setObj.flyBoxDivName).style.display = 'none';
			faderDirections[setObj.zoomBoxDivName] = -1;
			fSmoothShow(setObj.zoomBoxDivName, 25, 1, 0, 1, -0.1);

			if (setObj.objName != '') {
				if (navigator.appName.indexOf("Microsoft") != -1) {
				  intObj.onmousemove = "";
				}
				else { // Firefox, Opera, Safari etc.
				  intObj.setAttribute("onmousemove", "");
				}
			}
		}
	}

	function fSetFlySize(setObj) {
		if (setObj == null) {return;}
		var targetDiv = document.getElementById(setObj.flyBoxDivName);
		if (targetDiv != null) {
			targetDiv.style.width = setObj.fly_w + 'px';
			targetDiv.style.height = setObj.fly_h + 'px';
		}
	}
	
	function fDblCheckZoom(setObj, evt) {
		if (setObj == null) {return;}
		var flyDiv = document.getElementById(setObj.flyBoxDivName);
		var o = fPosition(evt);
		if ((flyDiv.style.display == '') && ((o.x < (setObj.smallPhotoOffset.x + setObj.popupOffset.x)) || (o.x > ((setObj.smallPhotoOffset.x + setObj.popupOffset.x) + setObj.photo_w)) || (o.y < (setObj.smallPhotoOffset.y + setObj.popupOffset.y)) || (o.y > ((setObj.smallPhotoOffset.y + setObj.popupOffset.y) + setObj.photo_h )))) {
			fnStepOnOff(setObj, false);
		}
	}


	function fnCalculateZoomPos(setObj) {
		if (setObj == null) {return;}
		var imgplace = 	document.getElementById(setObj.smallPhotoDivName);
		var imgpos = findPos(imgplace);
		var detpos = findPos(imgplace);

		dx = parseInt(imgplace.style.width);
		detpos[0] = imgpos[0] + dx;


		var photoplace = document.getElementById(setObj.smallPhotoDivName);
		var photoplaceshadow = document.getElementById(setObj.smallPhotoShadowDivName);
		var zoombox = document.getElementById(setObj.zoomBoxDivName);

		photoplace.style.left = imgpos[0] - setObj.popupOffset.x + 'px';
		photoplace.style.top = imgpos[1] - setObj.popupOffset.y + 'px';
		photoplace.style.display = '';

		photoplaceshadow.style.left = imgpos[0] - setObj.popupOffset.x + 'px';
		photoplaceshadow.style.top = imgpos[1] - setObj.popupOffset.y + 'px';

		zoombox.style.left = detpos[0] - setObj.popupOffset.x + 'px';
		zoombox.style.top = detpos[1] - setObj.popupOffset.y + 'px';
		
		zoombox.style.width = setObj.zoom_w + 'px';
		zoombox.style.height = setObj.zoom_h + 'px';

		setObj.smallPhotoOffset.x = imgpos[0] - setObj.popupOffset.x;
		setObj.smallPhotoOffset.y = imgpos[1] - setObj.popupOffset.y;

		fSetFlySize(setObj);
	}

	function fnShowLargeColour(sender, colourImgSrc, rgbCode, colourCaption) {
		var colourDiv = document.getElementById("LgeColour");
		if (colourDiv != null) {
			var imgObj = document.getElementById("LgeImage");
			var clrBoxObj = document.getElementById("LgeColourBox");
			var captionObj = document.getElementById("LgeCaption");
			if ((imgObj != null) && (captionObj != null) && (clrBoxObj != null)) {
				clrBoxObj.style.display = 'none';
				imgObj.style.display = 'none';
				clrBoxObj.style.backgroundColor = colourDiv.style.backgroundColor;
				if (colourImgSrc != '') {
					if (imgObj.nodeName == 'IMG') {
						imgObj.src = colourImgSrc;
						imgObj.style.display = '';
					}
				}
				else if (rgbCode != '') {
					if (clrBoxObj.nodeName == 'DIV') {
						clrBoxObj.style.display = '';
						clrBoxObj.style.backgroundColor = rgbCode;
					}
				}
				if (captionObj.nodeName == 'SPAN') {
					captionObj.innerHTML = colourCaption;
				}
				var imgpos = findPos(sender);
				colourDiv.style.left = imgpos[0] - 2 + 'px';
				colourDiv.style.top = imgpos[1] - 5 - parseInt(colourDiv.style.height) + 'px';
				colourDiv.style.display = '';
			}
		}
	}
	
	function fnHideLargeColour() {
		var colourDiv = document.getElementById("LgeColour");
		if (colourDiv != null) {
			colourDiv.style.display = 'none';
		}
		else {
		}
	}

	function showBorder(swatch) {		
		if(document.getElementById(swatch).className != 'SwatchBorderOn') {
			document.getElementById(swatch).className = 'SwatchBorderOver';
		}
	}

	function showBorder_popup(swatch) {
		if(document.getElementById(swatch).className != 'SwatchBorderOn') {
			document.getElementById(swatch).className = 'SwatchBorderOver';
		}
	}

	function hideBorder(swatch) {
		if(document.getElementById(swatch).className != 'SwatchBorderOn') {
			document.getElementById(swatch).className = 'SwatchBorder';
		}
	}
    
	function hideBorder_popup(swatch) {
		if(document.getElementById(swatch).className != 'SwatchBorderOn') {
			document.getElementById(swatch).className = 'SwatchBorder';
		}
	}

	function fHideFullSizeList() {
	    if (fullSizeListVisible) {
	        var obj = document.getElementById('swatch_allsizes');
	        if (obj != null) {
	            obj.style.display = "none";
	            fullSizeListVisible = false;
	        }
	    }
	}

	function fHideFullSizeList_popup() {
	    if (fullSizeListVisible_popup) {
	        var obj = document.getElementById('swatch_allsizes_popup');
	        if (obj != null) {
	            obj.style.display = "none";
	            fullSizeListVisible_popup = false;
	        }
	    }
	}

	function fSelectFromFullSizeList(objectid, selection, szID, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2) {
	    fHideFullSizeList();

	    fSelectColour(objectid, selection, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2);
	    fSelectSize(objectid, selection, szID, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2);
	}

	function fSelectFromFullSizeList_popup(objectid, selection, szID, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2) {
	    fHideFullSizeList_popup();

	    fSelectColour_popup(objectid, selection, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2);
	    fSelectSize_popup(objectid, selection, szID, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2);
	}
    

	function fSelectColour(objectid, selection, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2) {
      fHideFullSizeList();

      // Show selected colour swatch
      var obj = document.getElementById(objectid);
      for(i=0;i < oColourArr.length; i++) {
        var sel = document.getElementById(oColourArr[i]);
        if(sel.id == obj.id) {
          if(sel.className == "SwatchBorder" || sel.className == "SwatchBorderOver") { sel.className = "SwatchBorderOn"; }
        }
        else {
          sel.className = "SwatchBorder";
        }
      }
      
      // De-select ALL size cells
      for(i=0;i < oCellArr.length; i++) {
        var sel = document.getElementById(oCellArr[i]);
        if(sel) {
          if(sel.className == "SizeBorderOn") { sel.className = "SizeBorder"; }
          if(sel.className == "DelayedDeliveryOn") { sel.className = "DelayedDelivery"; }
          if(sel.className == "SoldOutOn") { sel.className = "SoldOut"; }
        }
      }
      
      // Only show size table for selected colour swatch, and try and match size from other colours size tables, if can't match then select first for that particular table
      var currentszid = document.getElementById(hiddensizeid).value;
      var trymatchsize = document.getElementById(selection + "sizeswatch" + currentszid + "_" + clID);
      var oColourTable = null;
      for(i=0;i < oTableArr.length; i++) {
        if(oTableArr[i] == (selection + "sctable" + clID)) {
          oColourTable = document.getElementById(oTableArr[i]);
          var oSizeCellsArr = oColourTable.getElementsByTagName("td");
          if(!trymatchsize) {
            trymatchsize = oSizeCellsArr[0];
          }
          if(trymatchsize) {
            currentszid = trymatchsize.attributes["szID"].value;
          }
          document.getElementById(oTableArr[i]).style.display = "";
        }
        else {
          document.getElementById(oTableArr[i]).style.display = "none";
        }
      }

      // Select size cell (everything else already de-selected above)
      if(trymatchsize) {
        if(trymatchsize.className == "SizeBorder") { trymatchsize.className = "SizeBorderOn"; }
        if(trymatchsize.className == "DelayedDelivery") { trymatchsize.className = "DelayedDeliveryOn"; }
        if(trymatchsize.className == "SoldOut") { trymatchsize.className = "SoldOutOn"; }
      }
      
      // Set labels
      if(trymatchsize) {
        fSetAvailabilityLabel(trymatchsize, availabilityspanid, availabilityspanid2);
        fSetSelectionLabel(trymatchsize, selectspanid);
      }
      else {
        fSetAvailabilityLabel(obj, availabilityspanid, availabilityspanid2);
        fSetSelectionLabel(obj, selectspanid);
      }
  
      // Set hidden inputs for cart submission
      document.getElementById(hiddensizeid).value = currentszid;
      document.getElementById(hiddencolourid).value = clID;
      TrackItemPriceLabel(currentszid, clID, 'dynamic_price', 1);
    }

    function fSelectColour_popup(objectid, selection, clID, hiddencolourid, hiddensizeid, selectspanid, availabilityspanid, availabilityspanid2) {
        fHideFullSizeList_popup();

        // Show selected colour swatch
		var obj = document.getElementById(objectid);
		for(i=0;i < oColourArr_popup.length; i++) {
			var sel = document.getElementById(oColourArr_popup[i]);
			if(sel.id == obj.id) {
				if(sel.className == "SwatchBorder" || sel.className == "SwatchBorderOver") { sel.className = "SwatchBorderOn"; }
			}
			else {
				sel.className = "SwatchBorder";
			}
		}

		// De-select ALL size cells
		for(i=0;i < oCellArr_popup.length; i++) {
			var sel = document.getElementById(oCellArr_popup[i]);
			if(sel) {
				if(sel.className == "SizeBorderOn") { sel.className = "SizeBorder"; }
				if(sel.className == "DelayedDeliveryOn") { sel.className = "DelayedDelivery"; }
				if(sel.className == "SoldOut") { sel.className = "SoldOutOn"; }
			}
		}
	
		// Only show size table for selected colour swatch, and try and match size from other colours size tables, if can't match then select first for that particular table
		var currentszid = document.getElementById(hiddensizeid).value;
		var trymatchsize = document.getElementById(selection + "sizeswatch" + currentszid + "_" + clID);
		var oColourTable = null;
		for(i=0;i<oTableArr_popup.length; i++) {
			if(oTableArr_popup[i] == (selection + "sctable" + clID)) {
				oColourTable = document.getElementById(oTableArr_popup[i]);
				var oSizeCellsArr = oColourTable.getElementsByTagName("td");
				if(!trymatchsize) {
					trymatchsize = oSizeCellsArr[0];
				}
				if(trymatchsize) {
					currentszid = trymatchsize.attributes["szID"].value;
				}
				document.getElementById(oTableArr_popup[i]).style.display = "";
			}
			else {
				document.getElementById(oTableArr_popup[i]).style.display = "none";
			}
		}

		// Select size cell (everything else already de-selected above)
		if(trymatchsize) {
			if(trymatchsize.className == "SizeBorder") { trymatchsize.className = "SizeBorderOn"; }
			if(trymatchsize.className == "DelayedDelivery") { trymatchsize.className = "DelayedDeliveryOn"; }
			if(trymatchsize.className == "SoldOut") { trymatchsize.className = "SoldOutOn"; }
		}

		// Set labels
		if(trymatchsize) {
		    fSetAvailabilityLabel_popup(trymatchsize, availabilityspanid, availabilityspanid2);
			fSetSelectionLabel_popup(trymatchsize, selectspanid);
		}
		else {
		    fSetAvailabilityLabel_popup(obj, availabilityspanid, availabilityspanid2);
			fSetSelectionLabel_popup(obj, selectspanid);
		}

		// Set hidden inputs for cart submission
		document.getElementById(hiddensizeid).value = currentszid;
		document.getElementById(hiddencolourid).value = clID;
		TrackItemPriceLabel(currentszid, clID, 'dynamic_price_popup', 2);
	}

	function fSelectSize(objectid, selection, szID, clID, hiddensizeid, hiddencolourid, selectspanid, availabilityspanid, availabilityspanid2) {
		// Make sure this colour is selected
		var obj = document.getElementById(selection + "colourswatch" + clID);
		for(i=0; i < oColourArr.length; i++) {
			var sel = document.getElementById(oColourArr[i]);
			if(sel.id == obj.id) {
				if(sel.className == "SwatchBorder" || sel.className == "SwatchBorderOver") { sel.className = "SwatchBorderOn"; }
			}
			else {
				sel.className = "SwatchBorder";
			}
		}

		// Go through list and select size, while looking for this de-select anything else
		var obj = document.getElementById(objectid);
		for(i=0;i < oCellArr.length; i++) {
			var sel = document.getElementById(oCellArr[i]);
			if(sel.id == obj.id) {
				if(sel.className == "SizeBorder") { sel.className = "SizeBorderOn"; }
				if(sel.className == "DelayedDelivery") { sel.className = "DelayedDeliveryOn"; }
				if(sel.className == "SoldOut") { sel.className = "SoldOutOn"; }
			}
			else {
				if(sel.className == "SizeBorderOn") { sel.className = "SizeBorder"; }
				if(sel.className == "DelayedDeliveryOn") { sel.className = "DelayedDelivery"; }
				if(sel.className == "SoldOut") { sel.className = "SoldOutOn"; }
			}
		}

		// Set labels
		fSetAvailabilityLabel(obj, availabilityspanid, availabilityspanid2);
		fSetSelectionLabel(obj, selectspanid);

		// Set hidden inputs for cart submission
		document.getElementById(hiddensizeid).value = szID;
		document.getElementById(hiddencolourid).value = clID;
		TrackItemPriceLabel(szID, clID, 'dynamic_price', 1);
	}

	function fSelectSize_popup(objectid, selection, szID, clID, hiddensizeid, hiddencolourid, selectspanid, availabilityspanid, availabilityspanid2) {
		// Make sure this colour is selected
		var obj = document.getElementById(selection + "colourswatch" + clID);
		for(i=0;i<oColourArr_popup.length; i++) {
			var sel = document.getElementById(oColourArr_popup[i]);
			if(sel.id == obj.id) {
			if(sel.className == "SwatchBorder" || sel.className == "SwatchBorderOver") { sel.className = "SwatchBorderOn"; }
			}
			else {
				sel.className = "SwatchBorder";
			}
		}

		// Go through list and select size, while looking for this de-select anything else
		var obj = document.getElementById(objectid);
		for(i=0;i<oCellArr_popup.length; i++) {
			var sel = document.getElementById(oCellArr_popup[i]);
			if(sel.id == obj.id) {
				if(sel.className == "SizeBorder") { sel.className = "SizeBorderOn"; }
				if(sel.className == "DelayedDelivery") { sel.className = "DelayedDeliveryOn"; }
				if(sel.className == "SoldOut") { sel.className = "SoldOutOn"; }
			}
			else {
				if(sel.className == "SizeBorderOn") { sel.className = "SizeBorder"; }
				if(sel.className == "DelayedDeliveryOn") { sel.className = "DelayedDelivery"; }
				if(sel.className == "SoldOut") { sel.className = "SoldOutOn"; }
			}
		}

		// Set labels
		fSetAvailabilityLabel_popup(obj, availabilityspanid, availabilityspanid2);
		fSetSelectionLabel_popup(obj, selectspanid);

		// Set hidden inputs for cart submission
		document.getElementById(hiddensizeid).value = szID;
		document.getElementById(hiddencolourid).value = clID;
		TrackItemPriceLabel(szID, clID, 'dynamic_price_popup', 2);
	}

	function fSetAvailabilityLabel(obj, availabilityspanid, availabilityspanid2) {
		var availobj = document.getElementById(availabilityspanid);
		availobj.innerHTML = obj.attributes["avail"].value;

		var availobj2 = document.getElementById(availabilityspanid2);
		if (availobj2 != null) {
		    availobj2.innerHTML = obj.attributes["avail"].value;
		}

		var avail_block = document.getElementById(availabilityspanid2 + '_area');
		var sold_block = document.getElementById(availabilityspanid2 + '_soldarea');
		var purch_ctr = document.getElementById('purchase_controls');

		if (avail_block != null) {
		    if (obj.attributes["avail"].value.indexOf("Estimated") > -1) {
		        avail_block.style.display = '';
		    }
		    else {
		        avail_block.style.display = 'none';
		    }
		}
		if (sold_block != null) {
		    if (obj.attributes["avail"].value.indexOf("Sold") > -1) {
		        sold_block.style.display = '';
		    }
		    else {
		        sold_block.style.display = 'none';
		    }
		}

		if (obj.attributes["avail"].value.indexOf("Sold") > -1) {
		    purch_ctr.style.display = 'none';
		}
		else {
		    if (purch_ctr.style.display != '') {
		        purch_ctr.style.display = '';
		    }
		}
    }

	function fSetAvailabilityLabel_popup(obj, availabilityspanid, availabilityspanid2) {
		var availobj = document.getElementById(availabilityspanid);
		availobj.innerHTML = obj.attributes["avail"].value;

		var availobj2 = document.getElementById(availabilityspanid2);
		if (availobj2 != null) {

		    availobj2.innerHTML = obj.attributes["avail"].value;
		}

		var avail_block = document.getElementById(availabilityspanid2 + '_area');
		var sold_block = document.getElementById(availabilityspanid2 + '_soldarea');
		var purch_ctr = document.getElementById('purchase_controls_popup');
		if (avail_block != null) {
		    if (obj.attributes["avail"].value.indexOf("Estimated") > -1) {
		        avail_block.style.display = '';
		    }
		    else {
		        avail_block.style.display = 'none';
		    }
		}
		if (sold_block != null) {
		    if (obj.attributes["avail"].value.indexOf("Sold") > -1) {
		        sold_block.style.display = '';
		    }
		    else {
		        sold_block.style.display = 'none';
		    }
		}

		if (obj.attributes["avail"].value.indexOf("Sold") > -1) {
		    purch_ctr.style.display = 'none';
		}
		else {
		    if (purch_ctr.style.display != '') {
		        purch_ctr.style.display = '';
		    }
		}
    }


	function fSetSelectionLabel(obj, selectspanid) {
		var selectobj = document.getElementById(selectspanid);
		selectobj.innerHTML = obj.attributes["name"].value;
	}

	function fSetSelectionLabel_popup(obj, selectspanid) {
		var selectobj = document.getElementById(selectspanid);
		selectobj.innerHTML = obj.attributes["name"].value;
	}

	function WinOpen(page,width,height){
		window.open(page, "", "width="+width+",height="+height+",toolbar=no,header=no,location=no,resizable=1,scrollbars=1");
	}

	function isReviewFormValid(frm) {
		if (frm != null) {
			var validationResult = false;
			var email = frm.r_email.value;
			var cust = frm.r_custno.value;
			var notify = frm.r_notify.checked;

			if (email != '' && validateEmail(email) == false) {
				alert("Invalid E-mail")
				return false;
			}

			if (cust != '' && validateNumber(cust) == false) {
				alert("Invalid Customer number")
				return false;
			}

			validationResult = ((notify == false) || ((notify == true) && (email != '' || cust != '')));

			if (validationResult == false) {
				alert('Please let us know your email address or customer number\r\notherwise we will not be able to contact you.');
			}
			return validationResult;
		}
		return false;
	}

	function Popup(url){
		window.open(url, "Zoomify", "width=525,height=584,toolbar=no,header=no,location=no,resizable=0,scrollbars=0");
	}

	function fSelectColourSize(clID, szID) {
		fSelectColour('1colourswatch' + clID, '1', clID, 'hiddenclid1', 'hiddenszid1', 'selectiondesc1', 'availabilitydesc1');
		fSelectSize('1sizeswatch' + szID + '_' + clID, '1', szID, clID, 'hiddenszid1', 'hiddenclid1', 'selectiondesc1', 'availabilitydesc1');
		closeColourSizePopup();
		return true;
	}

	function fSelectColourSize_popup(clID, szID) {
		fSelectColour_popup('1colourswatch' + clID, '1', clID, 'hiddenclid1', 'hiddenszid1', 'selectiondesc1', 'availabilitydesc1');
		fSelectSize_popup('1sizeswatch' + szID + '_' + clID, '1', szID, clID, 'hiddenszid1', 'hiddenclid1', 'selectiondesc1', 'availabilitydesc1');
		closeColourSizePopup_popup();
		return true;
	}

	function TrackItemPriceLabel(sz, cl, target, mode) {
		if ((sz > 0) && (cl > 0) && (target != '')) {

			msgArea = document.getElementById(target);
			if (msgArea != null) {
				var msg = "";
				if (mode == 1) {
					msg = oItemsPriceWasNow[cl + '_' + sz];
				}
				else if (mode == 2) {
					msg = oItemsPriceWasNow_popup[cl + '_' + sz];
				}
				if (msg == null) {msg = '';}

				msgArea.innerHTML = msg;
			}
		}
		return;
	}

	function closeColourSizePopup_popup() {
		document.getElementById("Matrix_popup").style.display = "none";
	}

	function fireColourSizePopup_popup() {
		var _obj = document.getElementById("Matrix_popup");
		_obj.style.marginLeft = "-400px";
		_obj.style.display = "";
		_obj.style.marginLeft = 0 - parseInt(_obj.clientWidth) / 2 + "px";
	}
