function bookmarksite(){
if (document.all)
window.external.AddFavorite(location.href, document.title);
else if (window.sidebar)
window.sidebar.addPanel(document.title, location.href, "")
}


tip=0;
function showtip()
{
	tip++; 
	if(tip < 8)
	{
		document.getElementById('tip_' + tip).style.display = 'block';
		if(tip == 7)
			document.getElementById('tip_8').style.display = 'none';
	}
	
}

function clickclear(thisfield, defaulttext) 
{
	if (thisfield.value == defaulttext) 
		thisfield.value = "";

}

function clickrecall(thisfield, defaulttext) 
{
	if (thisfield.value == "") 
	{
		thisfield.value = defaulttext;
	}
}

function cardimage(source) 
{
	if(document.images) 
		document.images['mycardimage'].src = 'images/cards/' + source + '.gif';
	else
  	document.images['mycardimage'].src = 'images/cards/invpxl.gif';
}

function showimage(source,id,text) 
{
	if(document.images) 
	{
		document.images['productimage'].src = 'images/products/' + source;
		document.getElementById('imgTitle').innerHTML=text;
	}
	else
  	document.images['productimage'].src = 'images/products/' + id + '.jpg';
  
  
}

function swapImg(source)
{
	document.images[source].src = 'images/' + source + '_on.gif';
}

function fillSub()
{
	box = document.forms[0].lhscategory;
	val = box.options[box.selectedIndex].value;
}

function popitup(url) {
	newwindow=window.open(url,null,'height=650,width=500,status=yes,toolbar=no,menubar=no');
	if (window.focus) {newwindow.focus()}
	return false;
}

function showDenier(id,str)
{
	
	if(id.value=="")
	{
		document.forms["search"].lhsdenier.options[0] = new Option('denier','');
		document.forms["search"].lhsdenier.options[1] = new Option('Any Denier','');
		document.forms["search"].lhsdenier.options[2] = new Option('Nets/Laces','Nets/Laces');
		document.forms["search"].lhsdenier.options[3] = new Option('Fishnets','Fishnets');
		document.forms["search"].lhsdenier.options[4] = new Option('< 10 denier','< 10 denier');
		document.forms["search"].lhsdenier.options[5] = new Option('10-20 denier','10-20 denier');
		document.forms["search"].lhsdenier.options[6] = new Option('20-40 denier','20-40 denier');
		document.forms["search"].lhsdenier.options[7] = new Option('40+ denier','40+ denier');
		document.forms["search"].lhsdenier.options[8] = new Option('Wool/Cotton','Wool/Cotton');
	}
	else
	{	
		var tmpArray = new Array();
		var tmpArray = str.split('#');
		var found=0;
		for(i=0; i<tmpArray.length;i++)
		{
			var tmpA = new Array();
			var tmpA = tmpArray[i].split('|');
			
			if(tmpA[0]==id.value)
			{
				var tmpB = new Array();
				var tmpB = tmpA[1].split('~');
				document.forms["search"].lhsdenier.length=0;
				document.forms["search"].lhsdenier.options[0] = new Option('denier','');
				document.forms["search"].lhsdenier.options[1] = new Option('Any Denier','');
				for(x=0; x<tmpB.length; x++)
				{
					var y=x+2;
					document.forms["search"].lhsdenier.options[y] = new Option(tmpB[x],tmpB[x]);
				}
				found = 1;
			}
			if(found==0)
			{
				document.forms["search"].lhsdenier.length=0;
				document.forms["search"].lhsdenier.options[0] = new Option('denier','');
				document.forms["search"].lhsdenier.options[1] = new Option('Any Denier','');
				
			}
			
		}
	}
}



var POID = 0;
var STOCK = 1;
var AVAILABILITY = 2;
var DELIVERY = 3;


function showStock(productId, productSet)
{
	var coloursElm = document.getElementById('colours');
	var accsElm = document.getElementById('accs');
	var chooseElm = document.getElementById('chooseSize');
	
	var sizeElm = document.getElementById('size_' + productId);
	if(sizeElm.options.length == 2)
		sizeElm.selectedIndex = 1;
	var size = sizeElm.options[sizeElm.selectedIndex].value;
	
	var tmp = new Array();
	var allColours = new Array();
	for(var s in stock[productId])
	{
		for(var c in stock[productId][s])
			tmp[c] = true;
	}
	
	for(var c in tmp)
		allColours[allColours.length] = c;
	
	var anyBuyable = false;
	
	if(!size)
	{
		if(coloursElm)
			;//coloursElm.style.display = 'none';
		
		if(accsElm)
			;//accsElm.style.display = 'none';
		
		if(chooseElm)
			chooseElm.className = chooseElm.className.replace(/ ?chooseSize/, '') + ' chooseSize';
		
		for(var i=0; i<allColours.length; i++)
		{
			var sel = document.getElementById('quantity_' + productId + '_' + allColours[i]);
			if(sel)
				sel.disabled = true;
			
			var addButton = document.getElementById('add_' + productId + '_' + allColours[i]);
			if(addButton)
				addButton.style.display = 'none';
		}
		
		var e = document.getElementById('addButton');
		if (e)
			e.style.display = 'none';
		
		return;
	}
		
	if(coloursElm)
		coloursElm.style.display = '';
	
	if(accsElm)
		accsElm.style.display = '';	
	
	if(chooseElm)
			chooseElm.className = chooseElm.className.replace(/ ?chooseSize/, '');
	
	for(var i=0; i<allColours.length; i++)
	{
		var sel = document.getElementById('quantity_' + productId + '_' + allColours[i]);
		if(sel)
			sel.disabled = false;
		
		var addButton = document.getElementById('add_' + productId + '_' + allColours[i]);
		if(addButton)
			addButton.style.display = 'inline';
	}
	
	var colours = stock[productId][size];
	
	//See if we have a colour select or a list of colours
	var colourSelect = document.getElementById('colour_' + productId);
	if(colourSelect)
	{
		var selected = 0;
		var selectedValue = '';
		if(colourSelect.selectedIndex != -1)
			selectedValue = colourSelect.options[colourSelect.selectedIndex].value;
		
		colourSelect.options.length = 1;
		var numColours = 0;
		for(var colour in colours)
		{
			if(!stock[productId][size][colour][STOCK] && !stock[productId][size][colour][AVAILABILITY])
				continue;
			
			colourSelect.options[colourSelect.options.length] = new Option(colour, colour);
			if(colour == selectedValue)
				selected = numColours+1;
			
			numColours++
		}
		
		selected = Math.max(0, Math.min(selected, colourSelect.options.length-1));
		
		if((numColours == 1) && !selected)
			selected = 1;
		
		colourSelect.selectedIndex = selected;
		
		var addButton = true;
		
		var colour = colourSelect.options[selected].value;
		if(colour)
		{
			var quantitySelect = document.getElementById('quantity_' + productId);
			
			/*
			Turn off request system
			if(productSet != 2)
				var inStock = 25;
			else
				var inStock = Math.max(stock[productId][size][colour][STOCK], 1);
			*/
			var inStock = 25;
			
			
			var selected = Math.max(0, Math.min(quantitySelect.selectedIndex, inStock));
			quantitySelect.options.length = 0;
			
			for(var i=1; i<=inStock; i++)
				quantitySelect.options[quantitySelect.options.length] = new Option(i, i);
			
			var e = document.getElementById('stock_' + productId);
			if(e)
				e.innerHTML = getStockStr(stock[productId][size][colour]);
			
			//Turn off request system
			//if(!stock[productId][size][colour][STOCK] && (productSet == 2))
				//addButton = false;
		}
		
		var e = document.getElementById('add_' + productId)
		if(e)
			e.style.display = addButton ? 'inline' : 'none';
		
		var e = document.getElementById('request_' + productId)
		if(e)
		{
			e.href = e.href.replace(/colour=.*?&/, 'colour=' + colour + '&').replace(/size=.*?$/, 'size=' + size);
			e.style.display = addButton ? 'none' : 'inline';
		}
		
	}
	else
	{
		var e = document.getElementById('addButton');
		if (e)
			e.style.display = 'inline';
		
		for(var colour in allColours)
		{
			colour = allColours[colour];
			
			var e = document.getElementById('stock_' + productId + '_' + colour);
			if (!e)
				continue;
			var s = colours[colour];
			
			while(e.tagName.toLowerCase() != 'tr')
				e = e.parentNode;
			
			if(typeof s == 'undefined')
			{
				toggleTableRow(e, false);
				continue;
			}
			
			toggleTableRow(e, true);
			
			var e = document.getElementById('stock_' + productId + '_' + colour);
			if(e)
				e.innerHTML = getStockStr(s);
			
			if(true) //Turn off request system productSet == 1)
			{
				anyBuyable = true;
				var e = document.getElementById('add_' + productId + '_' + colour);
				if(e)
					e.style.display = 'inline';
			
				var e = document.getElementById('request_' + productId + '_' + colour);	
				if(e)
					e.style.display = 'none';
			}
			else if(productSet == 2)
			{
				if(s[STOCK])
					anyBuyable = true;
				
				var e = document.getElementById('add_' + productId + '_' + colour);
				if(e)
					e.style.display = s[STOCK]?'inline':'none';
				
				var e = document.getElementById('request_' + productId + '_' + colour);
				if(e)
				{
					e.style.display = s[STOCK]?'none':'inline';
					e.href = e.href.replace(/size=.*/, 'size=' + size);
				}
			}
			else
			{
				alert('Unknown product set: ' + productSet);
			}
			
			while(e.tagName.toLowerCase() != 'tr')
				e = e.parentNode;
			
			var discontinued = !s[AVAILABILITY] && !s[DELIVERY] && !s[STOCK];
			toggleTableRow(e, !discontinued);
			
			var quantitySelect = document.getElementById('quantity_' + productId + '_' + colour);
			
			/*
			Turn off request system
			if(productSet != 2)
				var inStock = 25;
			else
				var inStock = Math.max(stock[productId][size][colour][STOCK], 0);
			*/
			var inStock = 25;
			
			var selected = Math.max(0, Math.min(quantitySelect.selectedIndex, inStock));
			quantitySelect.options.length = 0;
			
			for(var i=0; i<=inStock; i++)
				quantitySelect.options[quantitySelect.options.length] = new Option(i, i);
		}
		
		var e = document.getElementById('buyRow');
		
		toggleTableRow(e, anyBuyable && size);
	}
}


function toggleTableRow(e, on)
{
	try
	{
		e.style.display = on ? 'table-row' : 'none';
	}
	catch(ex)
	{
		e.style.display = on ? 'block' : 'none';
	}
}


function getStockStr(s)
{
	if(!s[AVAILABILITY] && !s[DELIVERY])
	{
		if(s[STOCK])
			return '(' + s[STOCK] + ' in stock) Limited Stock';
		else
			return '(0 in stock) Discontinued';
	}
	else
	{
		if(s[DELIVERY] && !s[STOCK])
			return '(Will send ' + s[DELIVERY] + ')';
		else
			return '(' + s[STOCK] + ' in stock)';
	}
}

function changeCardType(elm)
{
	var v = elm.options[elm.selectedIndex].value;

	document.getElementById('tbody_card_issue_number').style.display = (v == 'SOLO' || v == 'MAESTRO') ? '' : 'none';
	document.getElementById('tbody_card_details').style.display = '';
}

var doneFeedback = false;
function showFeedback()
{
	if (doneFeedback)
		return;
	
	doneFeedback = true;
	
	var win = window.open('/feedbackForm.php?quick=1&page=' + encodeURIComponent(location.pathname) + '&qs=' + encodeURIComponent(location.search), 'feedbackWindow', 'height=450,width=400,status=yes,toolbar=no,menubar=no');
	
	if (win && win.blur)
		win.blur();
	
	if (window.focus)
		window.focus();
}





var menu = new function()
{
	this.closeTimer = false;
	this.openTimer = false;
	this.openA = false;
	this.openDiv = false;
	this.overlappers = [];
	this.showOverlappersTimer = false;
	
	this.open = function(a)
	{
		this.clearOpenTimer();
		if (this.showOverlappersTimer)
		{
			clearTimeout(this.showOverlappersTimer);
			this.showOverlappersTimer = false;
		}
		
		if (this.openA == a)
		{
			this.clearCloseTimer();
			return;
		}
		
		if (this.openA)
		{
			var self = this;
			this.openTimer = setTimeout(function() { self.close(); self.open(a); }, 300);
			return;
		}
		
		this.openA = a;
		this.openA.className += ' lhnavhover';
		var offset = this.getOffset(a);
		
		
		var elm = a;
		while ((elm.nodeType != 1) || (elm.tagName.toLowerCase() != 'div'))
			elm = elm.nextSibling;
		
		this.openDiv = elm;
		this.openDiv.style.display = 'block';
		var maxTop = 0;
		
		if (document.body && document.body.clientHeight)
			maxTop = document.body.clientHeight;
		else if (document.body && document.body.offsetHeight)
			maxTop = document.body.offsetHeight;
		else if (document.documentElement && document.documentElement.clientHeight)
			maxTop = document.documentElement.clientHeight;
		else if (document.documentElement && document.documentElement.offsetHeight)
			maxTop = document.documentElement.offsetHeight;
		else if (window.innerHeight)
			maxTop = window.innerHeight;
		
		if (document.body && document.body.scrollTop)
			maxTop += document.body.scrollTop;
		else if (document.documentElement && document.documentElement.scrollTop)
			maxTop += document.documentElement.scrollTop;
		
		maxTop -= this.openDiv.offsetHeight;
		this.openDiv.style.top = Math.min(offset.y, maxTop) + 'px';
		
		this.hideOverlappers();
	}
	
	this.startCloseTimer = function()
	{
		this.clearCloseTimer();
		var self = this;
		this.closeTimer = setTimeout(function() { self.close(); }, 300);
	}
	
	this.close = function()
	{
		if (this.openDiv)
			this.openDiv.style.display = 'none';
		
		this.openDiv = false;
		
		if (this.openA)
		{
			this.openA.className = this.openA.className.replace(/ lhnavhover/g, '');
		}
		
		this.openA = false;
		
		var self = this;
		this.showOverlappersTimer = setTimeout(function() { self.showOverlappers(); }, 1000);
	}
	
	this.clearCloseTimer = function()
	{
		if (this.closeTimer)
			clearTimeout(this.closeTimer);
		
		this.closeTimer = false;
	}
	
	this.clearOpenTimer = function()
	{
		if (this.openTimer)
			clearTimeout(this.openTimer);
		
		this.openTimer = false;
	}
	
	this.clearTimers = function()
	{
		this.clearCloseTimer();
		this.clearOpenTimer();
	}
	
	this.hideOverlappers = function()
	{
		if (!this.openDiv)
			return;
		
		var elms = new Array();
		
		var tmp = document.getElementsByTagName('select');
		var len = tmp.length;
		for (var i = 0; i < len; i++)
			elms.push(tmp[i]);
		
		var tmp = document.getElementsByTagName('object');
		var len = tmp.length;
		for (var i = 0; i < len; i++)
			elms.push(tmp[i]);
		
		var tmp = document.getElementsByTagName('embed');
		var len = tmp.length;
		for (var i = 0; i < len; i++)
			elms.push(tmp[i]);
		
		
		var minX = this.openDiv.offsetLeft;
		var maxX = minX + this.openDiv.offsetWidth;
		var minY = this.openDiv.offsetTop;
		var maxY = minY + this.openDiv.offsetHeight;
		
		
		var len = elms.length;
		for (var i =0; i < elms.length; i++)
		{
			var elm = elms[i];
			var offset = this.getOffset(elm);
			if (((offset.x <= maxX) && (offset.x + elm.offsetWidth >= minX)) && ((offset.y <= maxY) && (offset.y + elm.offsetHeight >= minY)))
			{
				elm.style.visibility = 'hidden';
				this.overlappers.push(elm);
			}
		}
	}
	
	this.showOverlappers = function()
	{
		if (this.openA)
			return;
		
		for (var i = 0; i < this.overlappers.length; i++)
			this.overlappers[i].style.visibility = '';
		
		this.overlappers = new Array();
	}
	
	this.getOffset = function(elm)
	{
		var offset = {x:0,y:0};
		
		while (elm)
		{
			offset.x += elm.offsetLeft;
			offset.y += elm.offsetTop;
			elm = elm.offsetParent;
		}
		
		return offset;
	}
}();

