	var colors = 0;


	function newColor(){
		colors = colors + 1;
		if(addDiv("shirtSelectors","selector_" + colors)){
			document.getElementById("selector_" + colors).innerHTML = shirtSelector(colors);
		}
		if(document.getElementById("numberOfColors")){
			document.getElementById("numberOfColors").value = colors;
		}
	}


	function colorselector(number,sizer){
		var selector = '<select name="'+sizer+'_'+number+'">';
		for(var i = 0; i < 100; i++)
			selector += '<option value="'+i+'">'+i+'</option>';
		selector += '</select>';
		return selector;
	}


	function shirtSelector(num){
		var texter = '<img src="/shared/store/graphics/shirt-arrow.gif" id="swatch_'+num+'" class="swatch" /><select name="color_'+num+'" onchange="updateswatch(this.value,\'swatch_'+num+'\');" class="colors">';
		texter = texter + coloroptions
		texter = texter + "</select>"
		texter = texter + colorselector(num,"S");
		texter = texter + colorselector(num,"M");
		texter = texter + colorselector(num,"L");
		texter = texter + colorselector(num,"XL");
		texter = texter + colorselector(num,"XXL");
		return texter;
	}


	function updateswatch(newcolor,picid){
		document.getElementById(picid).src="/shared/store/graphics/shirt-"+newcolor.replace(" ","-")+".gif";
	}


	function addDiv(parentID,childID) {
		var returner = false;
		var container = document.getElementById(parentID);
		if(container!=null){
			var newdiv = document.createElement("div");
			if(newdiv){
				newdiv.setAttribute("id",childID);
				newdiv.setAttribute("class","auto");
				container.appendChild(newdiv);
				returner = true;
			}
		}
		return returner;
	}


	function updateQ(itemID,skuID,quantity,productID){
		//update the picture
		var skuStr = skuID + '';
		if(document.getElementById('mainPic'))
			document.getElementById('mainPic').src = '/shared/Store/product-images/' + productID + '-' + skuStr + '_lrg.jpg';

		//update the quantity holders
		var inputBox = document.getElementById('qContainer');
		if(inputBox){
			allInputs = inputBox.getElementsByTagName('input');
			for(var j = 0; j < allInputs.length; j++){
				allInputs[j].value = '0';
			}
		}

		//update the new one
		if(document.getElementById('Q_' + itemID + '_' + skuStr)){
			document.getElementById('Q_' + itemID + '_' + skuStr).value = quantity;
		}

	}


	function addToCart(productID,itemID,skuID,quantity){
		if(!document.getElementById("productID"))
			return false;
		document.getElementById("productID").value = productID;
		document.getElementById("itemID").value = itemID;

		var formObj = document.getElementById("addToCartForm");
		if(formObj != null){
			var skuInput = document.getElementById("skuInput");
			if (!skuInput)
			{
				skuInput = document.createElement("input");
				if(skuInput)
				{
					skuInput.setAttribute("type","hidden");
					skuInput.setAttribute("id","skuInput");
					formObj.appendChild(skuInput);
				}
			}
			skuInput = document.getElementById("skuInput");
			skuInput.setAttribute("name","SKUs_"+itemID);
			skuInput.setAttribute("value",skuID);
			
			var qInput = document.getElementById("qInput");
			if (!qInput)
			{
				qInput = document.createElement("input");
				if(qInput)
				{
					qInput.setAttribute("type","hidden");
					qInput.setAttribute("id","qInput");
					formObj.appendChild(qInput);
				}
			}
			
			qInput = document.getElementById ("qInput");
			qInput.setAttribute("name","Q_" + itemID + "_" + skuID);
			qInput.setAttribute("value",quantity);
			
			formObj.submit();
		}
	}
