//Version 3.1.1
var butcatrequest = createRequest();
var contentrequest = createRequest();
var itemdetailrequest = createRequest();
var cartrequest = createRequest();
var popuprequest = createRequest();
var searchinterfacerequest = createRequest();
var sessionrequest = createRequest();
var actionrequest = createRequest();
var autorequest = createRequest();
var detailallowed = true;
var popupactive = false;
var ajaxurl = "index.php?option=com_outpostajax&format=raw";
var context = "none";
var currentdetailid = null;
var filters = new Array();
var buttonfilters;
var persistenterror = false;
var sortbuffer = null;
var activemagiccolorfilter = null;
var currentlistparameters = "";
var useremail = "";
var defaultquality = 1;
var sortattribute = "";
var autocompletecurrent = null;
var autocompleteamount = 0;

function createRequest()
{
	var req = false;
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}
	
	return req;
}

function initializeLayout(defqual,specificitemid,searchstring)
{
	cleanup();
	
	defaultquality = defqual;
	
	showPane("init");
	
	document.getElementById("searchheadcaption").innerHTML = "Search";
	document.getElementById("collectionsheadcaption").innerHTML = "Sets";
	document.getElementById("listsheadcaption").innerHTML = "Product list";
	document.getElementById("cartheadcaption").innerHTML = "Shopping cart";
	
	modifyCart(0,"none");
	
	if (specificitemid != 0)
	{
		persistenterror = true;
		getSpecificItem(specificitemid);
	}
	else if (searchstring != "")
	{
		currentlistparameters = "ajaxmode=search&context=none&keyword=" + searchstring;
		
		contentrequest.open("POST",ajaxurl,true);
		contentrequest.onreadystatechange = processContentResponse;
		contentrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		contentrequest.send(currentlistparameters + "&quality=0");
		
		showPane("lists");
	}
	
	searchinterfacerequest.open("POST",ajaxurl,true);
	searchinterfacerequest.onreadystatechange = processSearchInterface;
	searchinterfacerequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	searchinterfacerequest.send("ajaxmode=searchinterface&contextid=0");
}

function clearList()
{
	clearInnerList();
	clearOuterList();
}

function clearInnerList()
{
	var innerlist = document.getElementById("innerlist");
	if (innerlist)
	{
		innerlist.innerHTML = "";
	}
}

function clearOuterList()
{
	var outerlist = document.getElementById("outerlist");
	if (outerlist)
	{
		outerlist.innerHTML = "";
	}
}

function getSpecificItem(specificitemid)
{
	clearList();
	document.getElementById("filterbody").innerHTML = "";
	changeQuality(defaultquality)
	
	currentlistparameters = "ajaxmode=specificitem&itemid=" + specificitemid;
	
	contentrequest.open("POST",ajaxurl,true);
	contentrequest.onreadystatechange = processContentResponse;
	contentrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	contentrequest.send(currentlistparameters + "&quality=" + defaultquality);
	
	showPane("lists");
}

function findSomething()
{
	cleanup();
	
	document.getElementById("listsheadinfo").innerHTML = " - Loading...";
	
	var searchword = document.getElementById("cardsearchfield").value;
	
	var searchparameters = "";
	
	var searchcontext = context;
	var fullsearchnode = document.getElementById("limitsearchbox");
	if (fullsearchnode)
	{
		if (fullsearchnode.checked)
		{
			searchcontext = "none";
		}
	}
	
	switch (context)
	{
		case "magic":
			searchparameters = getMagicSearchParameters();
			clearMagicSearch();
			break;
		case "wow":
			searchparameters = getWowSearchParameters();
			clearWowSearch();
			break;
		case "ygo":
			searchparameters = getYgoSearchParameters();
			clearYgoSearch();
			break;
		case "boardgames":
			searchparameters = getBoardgameSearchParameters();
			clearBoardgameSearch();
			break;
		default:
			searchparameters = getDefaultSearchParameters();
			clearDefaultSearch();
			break;
	}
	
	if ((searchword.length < 2) && (searchparameters == ""))
	{
		return
	}
	
	clearList();
	document.getElementById("filterbody").innerHTML = "";
	changeQualityTag(defaultquality);
	
	currentlistparameters = "ajaxmode=search&context=" + searchcontext + "&keyword=" + searchword + "&" + searchparameters;
	
	contentrequest.open("POST",ajaxurl,true);
	contentrequest.onreadystatechange = processContentResponse;
	contentrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	contentrequest.send(currentlistparameters + "&quality=0"); // + defaultquality);
	
	showPane("lists");
}

function getDefaultSearchParameters()
{
	var parameterstring = "";
	
	return parameterstring;
}

function clearDefaultSearch()
{
	document.getElementById("cardsearchfield").value = "";
	
	opCheck("limitsearchbox");
}

function getBoardgameSearchParameters()
{
	var parameterstring = "";
	
	return parameterstring;
}

function clearBoardgameSearch()
{
	document.getElementById("cardsearchfield").value = "";
	
	opUncheck("limitsearchbox");
}

function getYgoSearchParameters()
{
	var parameterstring = "";
	
	return parameterstring;
}

function clearYgoSearch()
{
	document.getElementById("cardsearchfield").value = "";
	
	opUncheck("limitsearchbox");
}

function getWowSearchParameters()
{
	var parameterstring = "";
	
	return parameterstring;
}

function clearWowSearch()
{
	document.getElementById("cardsearchfield").value = "";
	
	opUncheck("limitsearchbox");
}

function getMagicSearchParameters()
{
	var common = (document.getElementById("commonbox").checked) ? "1" : "0";
	var uncommon = (document.getElementById("uncommonbox").checked) ? "1" : "0";
	var rare = (document.getElementById("rarebox").checked) ? "1" : "0";
	var mythic = (document.getElementById("mythicbox").checked) ? "1" : "0";
	
	var iswhite = (document.getElementById("orangebox").checked) ? "1" : "0";
	var isblue = (document.getElementById("bluebox").checked) ? "1" : "0";
	var isblack = (document.getElementById("blackbox").checked) ? "1" : "0";
	var isred = (document.getElementById("redbox").checked) ? "1" : "0";
	var isgreen = (document.getElementById("greenbox").checked) ? "1" : "0";
	var isnocol = (document.getElementById("nocolbox").checked) ? "1" : "0";
	
	var island = (document.getElementById("landbox").checked) ? "1" : "0";
	var iscreature = (document.getElementById("creaturebox").checked) ? "1" : "0";
	var issorcery = (document.getElementById("sorcerybox").checked) ? "1" : "0";
	var isinstant = (document.getElementById("instantbox").checked) ? "1" : "0";
	var isenchantment = (document.getElementById("enchantbox").checked) ? "1" : "0";
	var isartifact = (document.getElementById("artifactbox").checked) ? "1" : "0";
	var isplaneswalker = (document.getElementById("planeswalkerbox").checked) ? "1" : "0";
	
	var iswithfoils = (document.getElementById("foilonbox").checked) ? "1" : "0";
	var iswithnonfoils = (document.getElementById("nonfoilonbox").checked) ? "1" : "0";
	
	var setselector = document.getElementById("setselection");
	var setid = setselector.options[setselector.selectedIndex].value;
	
	var cmcselector = document.getElementById("relationsign");
	var cmcrel = cmcselector.options[cmcselector.selectedIndex].value;
	
	var supertype = document.getElementById("cardsupertype").value;
	
	var subtype = document.getElementById("cardsubtype").value;
	
	var artist = document.getElementById("cardartist").value;
	
	var cmcval = document.getElementById("relationnumber").value;
	if (!cmcval)
	{
		cmcval = 0;
	}
	
	var parameterstring = "cw=" + iswhite + "&cu=" + isblue + "&cg=" + isgreen + "&cr=" + isred + "&cb=" + isblack + "&cnocol=" + isnocol + "&tland=" + island + "&tcreature=" + iscreature + "&tsorcery=";
	parameterstring += issorcery + "&tinstant=" + isinstant + "&tenchantment=" + isenchantment + "&tartifact=" + isartifact + "&tplaneswalker=" + isplaneswalker + "&common=" + common + "&uncommon=" + uncommon;
	parameterstring += "&rare=" + rare + "&mythic=" + mythic + "&setid=" + setid + "&cmcrel=" + cmcrel + "&cmcval=" + cmcval + "&supertype=" + supertype + "&subtype=" + subtype + "&artist=" + artist;
	parameterstring += "&foilon=" + iswithfoils + "&nonfoilon=" + iswithnonfoils;
	
	return parameterstring;
}

function resetRarities()
{
	opCheck("commonbox");
	opCheck("uncommonbox");
	opCheck("rarebox");
	opCheck("mythicbox");
}

function disableRarities()
{
	opUncheck("commonbox");
	opUncheck("uncommonbox");
	opUncheck("rarebox");
	opUncheck("mythicbox");
}

function resetColors()
{
	opCheck("orangebox");
	opCheck("bluebox");
	opCheck("blackbox");
	opCheck("redbox");
	opCheck("greenbox");
	opCheck("nocolbox");
}

function disableColors()
{
	opUncheck("orangebox");
	opUncheck("bluebox");
	opUncheck("blackbox");
	opUncheck("redbox");
	opUncheck("greenbox");
	opUncheck("nocolbox");
}

function resetTypes()
{
	opCheck("landbox");
	opCheck("creaturebox");
	opCheck("sorcerybox");
	opCheck("instantbox");
	opCheck("enchantbox");
	opCheck("artifactbox");
	opCheck("planeswalkerbox");
}

function disableTypes()
{
	opUncheck("landbox");
	opUncheck("creaturebox");
	opUncheck("sorcerybox");
	opUncheck("instantbox");
	opUncheck("enchantbox");
	opUncheck("artifactbox");
	opUncheck("planeswalkerbox");
}

function clearMagicSearch()
{
	document.getElementById("cardsearchfield").value = "";
	document.getElementById("cardsupertype").value = "";
	document.getElementById("cardsubtype").value = "";
	document.getElementById("cardartist").value = "";
	document.getElementById("relationnumber").value = "";
	
	document.getElementById("foilonbox").checked = true;
	document.getElementById("nonfoilonbox").checked = true;
	
	resetRarities();
	resetColors();
	resetTypes();
	
	opUncheck("limitsearchbox");
	opCheck("foilonbox");
	opCheck("nonfoilonbox");
	
	var setselector = document.getElementById("setselection");
	setselector.selectedIndex = 0;
	
	var cmcselector = document.getElementById("relationsign");
	cmcselector.selectedIndex = 0;
}

function exclusiveColors(color)
{
	disableColors();
	opCheck(color);
}

function exclusiveTypes(type)
{
	disableTypes();
	opCheck(type);
}

function exclusiveRarities(rarity)
{
	disableRarities();
	opCheck(rarity);
}

function checkSearchEnter(e)
{
	/*if (e && e.which)
	{
		var code = e.which;
	}
	else
	{
		e = event;
		var code = e.keyCode;
	}
	
	if (code == 13)
	{
		findSomething();
	}
	if (code == 38)
	{
		focusonedown();
	}
	if (code == 40)
	{
		focusoneup();
	}*/
}

function focusonedown()
{
	if (autocompletecurrent)
	{
		unfocustrate(autocompletecurrent);
		if (autocompletecurrent >= autocompleteamount)
		{
			autocompletecurrent = 1;
		}
		else
		{
			autocompletecurrent++;
		}
		focustrate(autocompletecurrent);
	}
	else
	{
		autocompletecurrent = 1;
		focustrate(autocompletecurrent);
	}
}

function focusoneup()
{
	if (autocompletecurrent)
	{
		unfocustrate(autocompletecurrent);
		if (autocompletecurrent <= 1)
		{
			autocompletecurrent = autocompleteamount;
		}
		else
		{
			autocompletecurrent--;
		}
		focustrate(autocompletecurrent);
	}
	else
	{
		autocompletecurrent = autocompleteamount;
		focustrate(autocompletecurrent);
	}
}

function checkAutocomplete(e)
{
	if (e && e.which)
	{
		var code = e.which;
	}
	else
	{
		e = event;
		var code = e.keyCode;
	}
	
	switch (code)
	{
		case 13:
			if (autocompletecurrent)
			{
				autofill(autocompletecurrent);
			}
			else
			{
				findSomething();
			}
			break;
		case 38:
			focusoneup();
			break;
		case 40:
			focusonedown();
			break;
		default:
			autocomplete();
			break;
	}
}

function autocomplete()
{
	var keyword = document.getElementById("cardsearchfield").value;

	autorequest.open("POST",ajaxurl,true);
	autorequest.onreadystatechange = showAutocomplete;
	autorequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	autorequest.send("ajaxmode=autocomplete&keyword=" + keyword + "&context=" + context);
}

function showAutocomplete()
{
	if (autorequest.readyState == 4)
	{
		if (autorequest.status == 200)
		{
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(autorequest.responseText);
			}
			catch (error)
			{
				var xmlobj = autorequest.responseXML;
			}
			
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					var answerbodynode = xmlobj.getElementsByTagName("ajaxanswerbody")[0];
					var targetnode = document.getElementById("autocompletedetails");
					if (answerbodynode && targetnode)
					{
						autocompletecurrent = null;
						targetnode.innerHTML = answerbodynode.firstChild.nodeValue;
					}
					var amountnode = xmlobj.getElementsByTagName("ajaxansweramount")[0];
					if (amountnode)
					{
						autocompleteamount = parseInt(amountnode.firstChild.nodeValue);
					}
				}
			}
		}
	}
}

function focustrate(rank)
{
	unfocustrate(autocompletecurrent);
	
	autocompletecurrent = rank;
	var curnode = document.getElementById("autopt" + rank);
	if (curnode)
	{
		curnode.setAttribute("Class","autopthighlight");
	}
}

function unfocustrate(rank)
{
	var curnode = document.getElementById("autopt" + rank);
	if (curnode)
	{
		curnode.setAttribute("Class","autopt");
	}
}

function clearauto()
{
	autorequest.abort();
	autocompletecurrent = null;
	autocompleteamount = 0;
	var autonode = document.getElementById("autocompletedetails");
	if (autonode)
	{
		autonode.innerHTML = "";
	}
}

function autofill(rank)
{
	var sourcenode = document.getElementById("autopt" + rank);
	var targetnode = document.getElementById("cardsearchfield");
	if (sourcenode && targetnode)
	{
		targetnode.value = sourcenode.innerHTML;
	}
	
	var length = targetnode.value.length + 1;
	
	if (targetnode.setSelectionRange)
	{
		targetnode.focus();
		targetnode.setSelectionRange(length,length);
	}
	else if (targetnode.createTextRange)
	{
		var range = targetnode.createTextRange();
		range.collapse(true);
		range.moveEnd("character",length);
		range.moveStart("character",length);
		range.select();
	}
	
	clearauto();
}

function opCheckUncheck(elementid)
{
	var element = document.getElementById(elementid);
	element.checked = !element.checked;
	(element.checked) ? document.getElementById(elementid + "span").style.backgroundPosition = "0px -12px" : document.getElementById(elementid + "span").style.backgroundPosition = "0px 0px";
}

function opCheck(elementid)
{
	document.getElementById(elementid).checked = true;
	document.getElementById(elementid + "span").style.backgroundPosition = "0px -12px";
}

function opUncheck(elementid)
{
	document.getElementById(elementid).checked = false;
	document.getElementById(elementid + "span").style.backgroundPosition = "0px 0px";
}

function getList(collectionid)
{
	cleanup();
	
	clearList();
	document.getElementById("listsheadinfo").innerHTML = " - Loading...";
	document.getElementById("filterbody").innerHTML = "";
	changeQualityTag(defaultquality);
	
	currentlistparameters = "ajaxmode=getlist&collectionid=" + collectionid;
	
	contentrequest.open("POST",ajaxurl,true);
	contentrequest.onreadystatechange = processContentResponse;
	contentrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	contentrequest.send(currentlistparameters + "&quality=" + defaultquality);
	
	showPane("lists");
}

function changeQualityTag(qualityid)
{
	var qualityfilternode = document.getElementById("filterqualitybody");
	if (qualityfilternode)
	{
		for (k=0;k<qualityfilternode.childNodes.length;k++)
		{
			qualityfilternode.childNodes[k].style.fontWeight = "normal";
		}
	}
	
	var currentqualitynode = document.getElementById("filterquality" + qualityid);
	if (currentqualitynode)
	{
		currentqualitynode.style.fontWeight = "bold";
	}
}

function changeQuality(qualityid)
{
	if (currentlistparameters == "")
	{
		return;
	}
	
	cleanup();
	
	clearList();
	document.getElementById("listsheadinfo").innerHTML = " - Loading...";
	document.getElementById("filterbody").innerHTML = "";
	changeQualityTag(qualityid);
	
	contentrequest.open("POST",ajaxurl,true);
	contentrequest.onreadystatechange = processContentResponse;
	contentrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	contentrequest.send(currentlistparameters + "&quality=" + qualityid);
	
	showPane("lists");
}

function processContentResponse()
{
	if (contentrequest.readyState == 4)
	{
		var displayerror = "";
		document.getElementById("listsheadinfo").innerHTML = "";
		
		if (contentrequest.status == 200)
		{
			//alert(contentrequest.responseText);
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(contentrequest.responseText);
			}
			catch (error)
			{
				var xmlobj = contentrequest.responseXML;
			}
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					var answerheadinfo = xmlobj.getElementsByTagName("ajaxanswerbreadcrumb")[0];
					if (answerheadinfo)
					{
						var htmlheadinfo = answerheadinfo.firstChild.nodeValue;
						document.getElementById("listsheadinfo").innerHTML = htmlheadinfo;
					}
					var answerbody = xmlobj.getElementsByTagName("ajaxanswercontentlist")[0];
					if (answerbody)
					{
						var htmlbody = answerbody.firstChild.nodeValue;
						document.getElementById("innerlist").innerHTML = htmlbody;
						filters = null;
						filters = new Array();
						sortName(true);
					}
					var filtertext = "";
					var filterresetnode = xmlobj.getElementsByTagName("ajaxanswerfilterreset")[0];
					if (filterresetnode)
					{
						filtertext += filterresetnode.firstChild.nodeValue;
					}
					var namesindex = 0;
					var filternamenode = xmlobj.getElementsByTagName("ajaxanswerfilternames")[namesindex];
					while (filternamenode)
					{
						var filtername = filternamenode.firstChild.nodeValue;
						var filternode = xmlobj.getElementsByTagName("ajaxanswerfilters" + filtername)[0];
						if (filternode)
						{
							var filterstring = filternode.firstChild.nodeValue;
							if (filtername == "alphabet")
							{
								document.getElementById("listsheadfilter").innerHTML = filterstring;
							}
							else
							{
								filtertext += filterstring;
							}
						}
						namesindex++;
						filternamenode = xmlobj.getElementsByTagName("ajaxanswerfilternames")[namesindex];
					}
					
					if (filtertext != "")
					{
						document.getElementById("filterbody").innerHTML = filtertext;
					}
					var defaultfilternode = xmlobj.getElementsByTagName("ajaxanswerdefaultfilter")[0];
					if (defaultfilternode)
					{
						try
						{
							var func = new Function(defaultfilternode.firstChild.nodeValue);
							func();
						}
						catch (error)
						{
						}
					}
				}
				else
				{
					var errortextnode = xmlobj.getElementsByTagName("errormessage")[0];
					if (errortextnode)
					{
						displayerror = errortextnode.firstChild.nodeValue;
					}
					else
					{
						displayerror = "An error has occurred";
					}
				}
			}
		}
		
		if (displayerror != "")
		{
			errorDisplay(displayerror);
		}
	}
}

function getCats(butid,newcontext)
{
	context = newcontext;
	
	var magiclegal = "Magic the Gathering is TM and copyright Wizards of the Coast, Inc, a subsidiary of Hasbro, Inc. All rights reserved.";
	var wowlegal = "Warcraft, World of Warcraft and Blizzard Entertainment are trademarks and/or registered trademarks of Blizzard Entertainment, Inc.";
	var yugiohlegal = "Yu-Gi-Oh! is a trademark of Kazuki Takahashi, Shueisha, Konami Japan, etc. ©1996-2010. All rights reserved. ";
	var boardlegal = "Welcome to Outpost";
	
	document.getElementById("collectionsbody").innerHTML = "";
	document.getElementById("searchbody").innerHTML = "";
	
	switch (context)
	{
		case "magic":
			legaltekst = magiclegal;
			break;
		case "wow":
			legaltekst = wowlegal;
			break;
		case "ygo":
			legaltekst = yugiohlegal;
			break;
		case "boardgames":
			legaltekst = boardlegal;
			break;
		default:
			legaltekst = "";
			break;
	}
	
	document.getElementById("legal").innerHTML = legaltekst;
	
	butcatrequest.open("POST",ajaxurl,true);
	butcatrequest.onreadystatechange = processCatalog;
	butcatrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	butcatrequest.send("ajaxmode=settable&buttonid=" + butid + "&context=" + context);
	
	searchinterfacerequest.open("POST",ajaxurl,true);
	searchinterfacerequest.onreadystatechange = processSearchInterface;
	searchinterfacerequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	searchinterfacerequest.send("ajaxmode=searchinterface&context=" + context);
	
	showPane("collections");
}

function processCatalog()
{
	if (butcatrequest.readyState == 4)
	{
		var displayerror = "";
		
		if (butcatrequest.status == 200)
		{
			//alert(butcatrequest.responseText);
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(butcatrequest.responseText);
			}
			catch (error)
			{
				var xmlobj = butcatrequest.responseXML;
				
			}
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					var answerheadinfo = xmlobj.getElementsByTagName("ajaxanswerbreadcrumb")[0];
					if (answerheadinfo)
					{
						var headhtmlinfo = answerheadinfo.firstChild.nodeValue;
						document.getElementById("collectionsheadinfo").innerHTML = headhtmlinfo;
					}
					var answerbody = xmlobj.getElementsByTagName("ajaxanswerlistbody")[0];
					if (answerbody)
					{
						var bodyhtml = answerbody.firstChild.nodeValue;
						document.getElementById("collectionsbody").innerHTML = bodyhtml;
					}
					var answerfilternode = xmlobj.getElementsByTagName("ajaxanswerfilter")[0];
					if (answerfilternode)
					{
						var filtertext = answerfilternode.firstChild.nodeValue;
						document.getElementById("collectionsheadfilter").innerHTML = filtertext;
						buttonfilters = null;
						buttonfilters = new Array();
					}
				}
				else
				{
					var errortextnode = xmlobj.getElementsByTagName("errormessage")[0];
					if (errortextnode)
					{
						displayerror = errortextnode.firstChild.nodeValue;
					}
					else
					{
						displayerror = "An error has occurred";
					}
				}
			}
		}
		
		if (displayerror != "")
		{
			errorDisplay(displayerror);
		}
	}
}

function processSearchInterface()
{
	if (searchinterfacerequest.readyState == 4)
	{
		var displayerror = "";
		
		if (searchinterfacerequest.status == 200)
		{
			//alert(searchinterfacerequest.responseText);
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(searchinterfacerequest.responseText);
			}
			catch (error)
			{
				var xmlobj = searchinterfacerequest.responseXML;
			}
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					var answerheadcaption = xmlobj.getElementsByTagName("ajaxanswerheadcaption")[0];
					if (answerheadcaption)
					{
						var headhtml =  answerheadcaption.firstChild.nodeValue;
						document.getElementById("searchheadcaption").innerHTML = headhtml;
					}
					var answerheadinfo = xmlobj.getElementsByTagName("ajaxanswerheadinfo")[0];
					if (answerheadinfo)
					{
						var headinfohtml = answerheadinfo.firstChild.nodeValue;
						document.getElementById("searchheadinfo").innerHTML = headinfohtml;
					}
					var answerbody = xmlobj.getElementsByTagName("ajaxanswerbody")[0];
					if (answerbody)
					{
						var bodyhtml = answerbody.firstChild.nodeValue;
						document.getElementById("searchbody").innerHTML = bodyhtml;
					}
				}
				else
				{
					var errortextnode = xmlobj.getElementsByTagName("errormessage")[0];
					if (errortextnode)
					{
						displayerror = errortextnode.firstChild.nodeValue;
					}
					else
					{
						displayerror = "An error has occurred";
					}
				}
			}
		}
		
		if (displayerror != "")
		{
			errorDisplay(displayerror);
		}
	}
}

function cartImageChange(element,baseimage)
{
	element.src = "images/outpostimages/" + baseimage + ".png";
}

function addToCart(itemid)
{
	modifyCart(itemid,"create");
}
function deleteItem(itemid)
{
	modifyCart(itemid,"delete");
}

//modifiers
//"plus" = increment number of items
//"min" = decrement number of items
//"create" = add item to card
//"delete" = delete item from cart
//"none" = no modifications, only reloads cart
function modifyCart(itemid,modifier)
{
	if (modifier == "create")
	{
		var aantal = document.getElementById("productamount" + itemid).value;
		if (!aantal)
		{
			aantal = 0;
		}
	}
	else
	{
		var aantal = 1;
	}
	
	cartrequest.open("POST",ajaxurl,true);
	cartrequest.onreadystatechange = processCart;
	cartrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	cartrequest.send("ajaxmode=cart&itemid=" + itemid + "&modifier=" + modifier + "&aantal=" + aantal);
}

function processCart()
{
	if (cartrequest.readyState == 4)
	{
		var displayerror = "";
		
		if (cartrequest.status == 200)
		{
		//	alert(cartrequest.responseText);
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(cartrequest.responseText);
			}
			catch (error)
			{
				var xmlobj = cartrequest.responseXML;
				
			}
			
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					/*var answertab = xmlobj.getElementsByTagName("ajaxanswertabinfo")[0];
					if (answertab)
					{
						var tabinfotext = answertab.firstChild.nodeValue;
						document.getElementById("tabcart").innerHTML = tabinfotext;
					}*/
					//totalitems totalprice
					var aitnode = xmlobj.getElementsByTagName("ajaxanswertotalitems")[0];
					if (aitnode)
					{
						var cinode = document.getElementById("cartitemnr");
						if (cinode)
						{
							cinode.innerHTML = aitnode.firstChild.nodeValue;
						}
					}
					var atpnode = xmlobj.getElementsByTagName("ajaxanswertotalprice")[0];
					if (atpnode)
					{
						var ctpnode = document.getElementById("carttabtotal");
						if (ctpnode)
						{
							ctpnode.innerHTML = atpnode.firstChild.nodeValue + " &#8364;";
						}
					}
					var answerheadcaption = xmlobj.getElementsByTagName("ajaxanswerheadcaption")[0];
					if (answerheadcaption)
					{
						var htmlhead =  answerheadcaption.firstChild.nodeValue;
						document.getElementById("cartheadcaption").innerHTML = htmlhead;
					}
					var answerheadinfo = xmlobj.getElementsByTagName("ajaxanswerheadinfo")[0];
					if (answerheadinfo)
					{
						var htmlheadinfo = answerheadinfo.firstChild.nodeValue;
						document.getElementById("cartheadinfo").innerHTML = htmlheadinfo;
					}
					var answerbody = xmlobj.getElementsByTagName("ajaxanswerbody")[0];
					if (answerbody)
					{
						var htmlbody = answerbody.firstChild.nodeValue;
						document.getElementById("cartbody").innerHTML = htmlbody;
					}
					var subjectbody = xmlobj.getElementsByTagName("ajaxanswersubjectid")[0];
					if (subjectbody)
					{
						var subjectid = subjectbody.firstChild.nodeValue;
						var newstocknode = xmlobj.getElementsByTagName("ajaxanswernewstock")[0];
						if (newstocknode)
						{
							var newstock = newstocknode.firstChild.nodeValue;
							var subxnode = document.getElementById("stock" + subjectid);
							if (subxnode)
							{
								subxnode.innerHTML = newstock;
							}
							var mainxnode = document.getElementById(subjectid);
							if (mainxnode)
							{
								mainxnode.setAttribute("stock",newstock);
							}
						}
					}
				}
				else
				{
					var errortextnode = xmlobj.getElementsByTagName("errormessage")[0];
					if (errortextnode)
					{
						displayerror = errortextnode.firstChild.nodeValue;
					}
					else
					{
						displayerror = "An error has occurred";
					}
				}
			}
			else
			{
				displayerror = "The server response was inappropriate";
			}
			
			var notificationnode = xmlobj.getElementsByTagName("notification")[0];
			if (notificationnode)
			{
				notification = notificationnode.firstChild.nodeValue;
			}
		}
		
		if (displayerror != "")
		{
			errorDisplay(displayerror);
		}
	}
}

function showPopUp(pictureid)
{
	overlib("<img src=\"index.php?option=com_pictures&pictureid="+pictureid+"&width=0&height=0&angle=0&format=raw\" />",FGCOLOR,'#D6D4AE',HAUTO,VAUTO,BGCOLOR,'#000000');
	/*if (currentdetailid == itemid)
	{
		return;
	}
	popupactive = true;
	
	popuprequest.open("POST",ajaxurl,true);
	popuprequest.onreadystatechange = displayPopUp;
	popuprequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	popuprequest.send("ajaxmode=popup&itemid=" + itemid);*/
}

function displayPopUp()
{
	if (popuprequest.readyState == 4)
	{
		if (popuprequest.status == 200)
		{
			if (popupactive)
			{
				try
				{
					var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
					xmlobj.async = false;
					xmlobj.loadXML(popuprequest.responseText);
				}
				catch (error)
				{
					var xmlobj = popuprequest.responseXML;
					
				}
				
				var errornode = xmlobj.getElementsByTagName("errorcode")[0];
				if (errornode)
				{
					var err = errornode.firstChild.nodeValue;
					if (err == 0)
					{
						var answerbody =  xmlobj.getElementsByTagName("ajaxanswerbody")[0];
						if (answerbody)
						{
							var htmlbody = answerbody.firstChild.nodeValue;
							overlib(htmlbody,FGCOLOR,'#D6D4AE',HAUTO,VAUTO,BGCOLOR,'#000000');
						}
					}
				}
			}
		}
	}
}

function removePopUp()
{
	popupactive = false;
	nd();
}

function findPosX(element)
{
	var curleft = 0;
	while (element.offsetParent)
	{
		curleft += element.offsetLeft;
		element = element.offsetParent;
	}
	if (curleft == 0)
	{
		curleft += element.x;
	}
	
	return curleft;
}

function findPosY(element)
{
	var curtop = 0;
	while (element.offsetParent)
	{
		curtop += element.offsetTop;
		element = element.offsetParent;
	}
	if (curtop == 0)
	{
		curtop += element.y
	}
	
	return curtop;
}

function errorDisplay(errortext)
{
	var attachpoint = document.getElementById("carttop");
	var x = 28;
	var y = attachpoint.offsetTop + attachpoint.offsetHeight;
	var errordetails = document.getElementById("errordetails");
	document.getElementById("errordetailview").innerHTML = errortext;
	errordetails.style.position = "absolute";
	errordetails.style.width = "668px";
	errordetails.style.left = x + "px";
	errordetails.style.top = y + "px";
	errordetails.style.display = "block";
}

function actionDisplay(actionhtml)
{
	var attachpoint = document.getElementById("carttop");
	var x = 28;
	var y = attachpoint.offsetTop + attachpoint.offsetHeight;
	var actiondetails = document.getElementById("actiondetails");
	document.getElementById("actiondetailview").innerHTML = actionhtml;
	actiondetails.style.position = "absolute";
	actiondetails.style.width = "668px";
	actiondetails.style.left = x + "px";
	actiondetails.style.top = y + "px";
	actiondetails.style.display = "block";
}

function removeItemDetails()
{
	currentdetailid = null;
	document.getElementById("itemdetails").style.display = "none";
	document.getElementById("itemdetailview").innerHTML = "";
}

function removeErrorDetails()
{
	document.getElementById("errordetails").style.display = "none";
	document.getElementById("errordetailview").innerHTML = "";
}

function removeActionDetails()
{
	document.getElementById("actiondetails").style.display = "none";
	document.getElementById("actiondetailview").innerHTML = "";
}

function cleanup()
{
	clearauto();
	removeItemDetails();
	removeActionDetails();
	if (!persistenterror)
	{
		removeErrorDetails();
	}
	else
	{
		persistenterror = true;
	}
}

function notLoggedIn()
{
	toggleLoginOn();
	errorDisplay("You are not logged in, you must be logged in to checkout. Please feel free to register.");
}

function lookingForProduct(productid)
{
	var namenode = document.getElementById("detailhyperlink" + productid);
	var name = "";
	if (namenode)
	{
		name = namenode.firstChild.nodeValue;
	}
	var htmlstring = "<div id=\"actionpoptext\">Do you wish to inquire about the item " + name + " ?</div>";
	htmlstring += "<div id=\"actionpopinput\"><input type=\"text\" value=\"" + useremail + "\" id=\"lfpmail\" /><input type=\"hidden\" id=\"lfpid\" value=\"" + productid + "\" /></div>";
	htmlstring += "<div id=\"actionpopokbutton\"><input type=\"button\" onclick=\"javascript:registerLFP();\" value=\"OK\" /></div>";
	
	actionDisplay(htmlstring);
}

function registerLFP()
{
	var productnode = document.getElementById("lfpid");
	var mailnode = document.getElementById("lfpmail");
	
	if (productnode && mailnode)
	{
		var productid = productnode.value;
		var mail = mailnode.value;
		
		if (mail != "" && productid != "")
		{
			useremail = mail;
			
			actionrequest.open("POST",ajaxurl,true);
			actionrequest.onreadystatechange = processLFP;
			actionrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			actionrequest.send("ajaxmode=registerlfp&email=" + mail + "&productid=" + productid);
		}
	}
}

function processLFP()
{
	if (actionrequest.readyState == 4)
	{
		if (actionrequest.status == 200)
		{
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(actionrequest.responseText);
			}
			catch (error)
			{
				var xmlobj = actionrequest.responseXML;
			}
			
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					removeActionDetails();
				}
				else
				{
					actionDisplay("An error has occurred");
				}
			}
		}
	}
}

/*Display detail from cart item in proper position*/
function getCartItemDetails(cardid)
{
	cleanup();
	
	if (!detailallowed)
	{
		return;
	}
	
	currentdetailid = cardid;
	
	removePopUp();
	
	itemdetailrequest.open("POST",ajaxurl,true);
	itemdetailrequest.onreadystatechange = processCartItemDetails;
	itemdetailrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	itemdetailrequest.send("ajaxmode=itemdetail&cardid=" + cardid);
}

function processCartItemDetails()
{
	if (itemdetailrequest.readyState == 4)
	{
		if (itemdetailrequest.status == 200)
		{
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(itemdetailrequest.responseText);
			}
			catch (error)
			{
				var xmlobj = itemdetailrequest.responseXML;
			}
			
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					var cardinformationbuffer = null;
					var cardid = null;
					var answerbody = xmlobj.getElementsByTagName("ajaxanswerbody")[0];
					if (answerbody)
					{
						cardinformationbuffer =  answerbody.firstChild.nodeValue;
					}
					var answercardid = xmlobj.getElementsByTagName("ajaxanswercardid")[0];
					if (answercardid)
					{
						cardid = answercardid.firstChild.nodeValue;
					}
					if (cardid && cardinformationbuffer)
					{
						cartDilate(cardid,cardinformationbuffer);
					}
				}
			}
		}
	}
}

function cartDilate(cardid,cardinformationbuffer)
{
	//var attachpoint = document.getElementById("cartdetailhyperlink" + cardid);
	var attachpoint = document.getElementById("cartbody");
	var x = 28;
	var y = attachpoint.offsetTop + 10;
	var itemdetails = document.getElementById("itemdetails");
	document.getElementById("itemdetailview").innerHTML = cardinformationbuffer;
	itemdetails.style.position = "absolute";
	itemdetails.style.width = "668px";
	itemdetails.style.left = x + "px";
	itemdetails.style.top = y + "px";
	itemdetails.style.display = "block";
}

function getItemDetails(cardid)
{
	cleanup();
	
	if (!detailallowed)
	{
		return;
	}
	
	currentdetailid = cardid;
	
	removePopUp();
		
	itemdetailrequest.open("POST",ajaxurl,true);
	itemdetailrequest.onreadystatechange = processItemDetails;
	itemdetailrequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	itemdetailrequest.send("ajaxmode=itemdetail&cardid=" + cardid);
}

function processItemDetails()
{
	if (itemdetailrequest.readyState == 4)
	{
		if (itemdetailrequest.status == 200)
		{
			try
			{
				var xmlobj = new ActiveXObject("Microsoft.XMLDOM");
				xmlobj.async = false;
				xmlobj.loadXML(itemdetailrequest.responseText);
			}
			catch (error)
			{
				var xmlobj = itemdetailrequest.responseXML;
			}
			
			var errornode = xmlobj.getElementsByTagName("errorcode")[0];
			if (errornode)
			{
				var err = errornode.firstChild.nodeValue;
				if (err == 0)
				{
					var cardinformationbuffer = null;
					var cardid = null;
					var answerbody = xmlobj.getElementsByTagName("ajaxanswerbody")[0];
					if (answerbody)
					{
						cardinformationbuffer = answerbody.firstChild.nodeValue;
					}
					var answercardid = xmlobj.getElementsByTagName("ajaxanswercardid")[0];
					if (answercardid)
					{
						cardid = answercardid.firstChild.nodeValue;
					}
					if (cardid && cardinformationbuffer)
					{
						dilate(cardid,cardinformationbuffer);
					}
				}
			}
		}
	}
}

function dilate(cardid,cardinformationbuffer)
{
	//var attachpoint = document.getElementById(cardid);
	var attachpoint = document.getElementById("listsbody");
	var x = 28;
	var y = attachpoint.offsetTop + 10;
	var itemdetails = document.getElementById("itemdetails");
	document.getElementById("itemdetailview").innerHTML = cardinformationbuffer;
	itemdetails.style.position = "absolute";
	itemdetails.style.width = "668px";
	itemdetails.style.left = x + "px";
	itemdetails.style.top = y + "px";
	itemdetails.style.display = "block";
}

function fillbody(oddrow)
{
	var maxheight = parseInt(document.getElementById("listsbody").offsetHeight);
	var innerheight = parseInt(document.getElementById("innerlist").offsetHeight);
	var extraheight = maxheight - innerheight;
	
	var filling = document.getElementById("outerlist");
	filling.innerHTML = "";
	
	if (extraheight > 0)
	{
		var lineheight = 23;
		var quotient = parseInt(extraheight/lineheight);
		
		for (i=0;i<=quotient;i++)
		{
			var emptynode = document.createElement("div");
			if (oddrow)
			{
				emptynode.setAttribute("class","oddrow");
				oddrow = false;
			}
			else
			{
				emptynode.setAttribute("class","evenrow");
				oddrow = true;
			}
			emptynode.style.height = "19px";
			filling.appendChild(emptynode);
		}
	}
}

function increaseItem(itemid)
{
	var plusbut = document.getElementById("plusbut" + itemid);
	if (plusbut)
	{
		plusbut.disabled = true;
		plusbut.style.backgroundImage = "url('images/outpostimages/plusimagehover.png')";
	}
	var minbut = document.getElementById("minbut" + itemid);
	if (minbut)
	{
		minbut.disabled = true;
	}
	modifyCart(itemid,"plus");
}

function reduceItem(itemid)
{
	var plusbut = document.getElementById("plusbut" + itemid);
	if (plusbut)
	{
		plusbut.disabled = true;
	}
	var minbut = document.getElementById("minbut" + itemid);
	if (minbut)
	{
		minbut.disabled = true;
		minbut.style.backgroundImage = "url('images/outpostimages/minimagehover.png')";
	}
	modifyCart(itemid,"min");
}

function buttonpop(text)
{
	overlib(text,WIDTH,80,FGCOLOR,"#FFFFAA",BGCOLOR,"#000000");
} 

function resetFilters()
{
	for (var j in filters)
	{
		var filterline = document.getElementById(j + "filter");
		if (filterline)
		{
			for (k=0;k<filterline.childNodes.length;k++)
			{
				filterline.childNodes[k].style.fontWeight = "normal";
			}
		}
	}
	
	filters = null;
	filters = new Array();
	
	var mainlist = document.getElementById("innerlist");
	if (mainlist)
	{
		var oddrow = true;
		for (i=0;i<mainlist.childNodes.length;i++)
		{
			var currentline = mainlist.childNodes[i];
			currentline.style.display = "block";
			if (oddrow)
			{
				currentline.className = "oddrow";
				oddrow = false;
			}
			else
			{
				currentline.className = "evenrow";
				oddrow = true;
			}
		}
	}
	
	filterResults();
}

function filterColor(color)
{
	delete filters["cu"];
	delete filters["cw"];
	delete filters["cr"];
	delete filters["cb"];
	delete filters["cg"];
	delete filters["cnocol"];
	
	switch (color)
	{
		case "blue":
			filters["cu"] = 1;
			break;
		case "white":
			filters["cw"] = 1;
			break;
		case "red":
			filters["cr"] = 1;
			break;
		case "black":
			filters["cb"] = 1;
			break;
		case "green":
			filters["cg"] = 1;
			break;
		case "nocol":
			filters["cnocol"] = 1;
			break;
	}
	
	var filterline = document.getElementById("color" + "filter");
	if (filterline)
	{
		for (j=0;j<filterline.childNodes.length;j++)
		{
			filterline.childNodes[j].style.fontWeight = "normal";
		}
		var mememe = document.getElementById("filter" + "color" + color);
		if (mememe)
		{
			mememe.style.fontWeight = "bold";
		}
	}
	
	filterResults();
}

function resetColorFilter()
{
	delete filters["cu"];
	delete filters["cw"];
	delete filters["cr"];
	delete filters["cb"];
	delete filters["cg"];
	delete filters["cnocol"];
	
	var filterline = document.getElementById("color" + "filter");
	if (filterline)
	{
		for (j=0;j<filterline.childNodes.length;j++)
		{
			filterline.childNodes[j].style.fontWeight = "normal";
		}
	}
	
	filterResults();
}

function resetFilter(selector)
{
	delete filters[selector];
	
	filterSelectionDisplay(selector,"all");
	
	filterResults();
}

function narrowSearchAbit(selector,choice)
{
	filters[selector] = choice;
	
	filterSelectionDisplay(selector,choice);
	
	filterResults();
}

function filterSelectionDisplay(selector,choice)
{
	var filterline = document.getElementById(selector + "filter");
	if (filterline)
	{
		for (j=0;j<filterline.childNodes.length;j++)
		{
			filterline.childNodes[j].style.fontWeight = "normal";
		}
		var mememe = document.getElementById("filter" + selector + choice);
		if (mememe)
		{
			mememe.style.fontWeight = "bold";
		}
	}
}

function filterResults()
{
	var mainthing = document.getElementById("innerlist");
	if (mainthing)
	{
		for (i=0;i<mainthing.childNodes.length;i++)
		{
			var currentthing = mainthing.childNodes[i];
			currentthing.style.display = "block";
			for (attribute in filters)
			{
				var choice = filters[attribute];
				if (choice != "all")
				{
					if (currentthing.getAttribute(attribute) != choice)
					{
						currentthing.style.display = "none";
					}
				}
			}
		}
	}
	
	setListClass();
}

function resetButtonFilter(selector)
{
	delete buttonfilters[selector];
	
	filterSelectionDisplay(selector,"all");
	
	filterButtonResults();
}

function narrowButtonsAbit(selector,choice)
{
	buttonfilters[selector] = choice;
	
	filterButtonSelectionDisplay(selector,choice);
	
	filterButtonResults();
}

function filterButtonSelectionDisplay(selector,choice)
{
	var filterline = document.getElementById(selector + "filter");
	if (filterline)
	{
		for (j=0;j<filterline.childNodes.length;j++)
		{
			filterline.childNodes[j].style.fontWeight = "normal";
		}
		var mememe = document.getElementById("filter" + selector + choice);
		if (mememe)
		{
			mememe.style.fontWeight = "bold";
		}
	}
}

function filterButtonResults()
{
	var mainthing = document.getElementById("collectionsbody");
	if (mainthing)
	{
		for (i=0;i<mainthing.childNodes.length;i++)
		{
			var childthing = mainthing.childNodes[i];
			for (k=0;k<childthing.childNodes.length;k++)
			{
				var currentthing = childthing.childNodes[k].firstChild;
				if (currentthing)
				{
					if (currentthing.getAttribute)
					{
						var display = true;
						for (attribute in buttonfilters)
						{
							var choice = buttonfilters[attribute];
							if (choice != "all")
							{
								if (currentthing.getAttribute(attribute) != choice)
								{
									display = false;
								}
							}
						}
						
						if (display)
						{
							currentthing.parentNode.setAttribute("class","setbutton");
						}
						else
						{
							currentthing.parentNode.setAttribute("class","greyedoutbutton");
						}
					}
				}
			}
		}
	}
}

function showPane(paneid)
{
	cleanup();
	
	if (paneid == "catalog")
	{
		document.getElementById("legal").innerHTML = "";
	}
	
	if (paneid == "init")
	{
		paneid = "catalog";
	}
	
	document.getElementById("tabcatalog").style.fontWeight = "";
	document.getElementById("tabcollections").style.fontWeight = "";
	document.getElementById("tablists").style.fontWeight = "";
	document.getElementById("tabsearch").style.fontWeight = "";
	document.getElementById("tabcart").style.fontWeight = "";
	
	var activetab = document.getElementById("tab" + paneid);
	if (activetab)
	{
		activetab.style.fontWeight = "bold";
	}
	
	document.getElementById("catalog").style.display = "none";
	document.getElementById("collections").style.display = "none";
	document.getElementById("lists").style.display = "none";
	document.getElementById("search").style.display = "none";
	document.getElementById("cart").style.display = "none";
	
	var activepane = document.getElementById(paneid);
	if (activepane)
	{
		activepane.style.display = "block";
	}
	
	if (paneid == "search")
	{
		var searchstart = document.getElementById("cardsearchfield");
		if (searchstart)
		{
			searchstart.focus();
		}
	}
}

function setListClass()
{
	var oddrow = true;
	var rootelement = document.getElementById("innerlist");
	if (rootelement)
	{
		for (i=0;i<rootelement.childNodes.length;i++)
		{
			var child = rootelement.childNodes[i];
			if (child.style.display != "none")
			{
				if (oddrow)
				{
					child.setAttribute("class","oddrow");
					oddrow = false;
				}
				else
				{
					child.setAttribute("class","evenrow");
					oddrow = true;
				}
			}
		}
	}
	fillbody(oddrow);
}

function sortContent(a,b)
{
	var propa;
	var propb;

	if (sortattribute == "elname")
	{
		propa = a.getAttribute(sortattribute);
		propb = b.getAttribute(sortattribute);
	}
	else
	{
		propa = parseFloat(a.getAttribute(sortattribute));
		propb = parseFloat(b.getAttribute(sortattribute));
	}
	
	var returnvalue = 0;
	
	if (propa < propb)
	{
		returnvalue = -1;
	}
	else if (propa > propb)
	{
		returnvalue = 1;
	}
	
	return returnvalue;
}

function sortContentDown(a,b)
{
	var propa;
	var propb;
	
	if (sortattribute == "elname")
	{
		propa = a.getAttribute(sortattribute);
		propb = b.getAttribute(sortattribute);
	}
	else
	{
		propa = parseFloat(a.getAttribute(sortattribute));
		propb = parseFloat(b.getAttribute(sortattribute));
	}
	
	var returnvalue = 0;
	
	if (propa < propb)
	{
		returnvalue = 1;
	}
	else if (propa > propb)
	{
		returnvalue = -1;
	}
	
	return returnvalue;
}

function sortName(up)
{
	sortList(up,"elname");
}

function sortStock(up)
{
	sortList(up,"stock");
}

function sortPrice(up)
{
	sortList(up,"price");
}

function sortList(up,keyword)
{
	sortbuffer = new Array();
	
	sortattribute = keyword;
	
	var rootelement = document.getElementById("innerlist");
	if (rootelement)
	{
		for (i=0;i<rootelement.childNodes.length;i++)
		{
			var element = rootelement.childNodes[i];
			sortbuffer[i] = element;
		}
		
		if (up)
		{
			sortbuffer.sort(sortContent);
		}
		else
		{
			sortbuffer.sort(sortContentDown);
		}
		
		for (x in sortbuffer)
		{
			rootelement.appendChild(sortbuffer[x]);
		}
		
		setListClass();
	}
}

function getCartShippingDetails()
{
	//Coming Soon
}

function getCartCouponDetails()
{
	//Coming Soon
}
