	function createCounter()
	{
		if(document.getElementById && document.createTextNode)
		{
			var inputs,i,newa,cmax,cmin,c;
			var linkclass='counterlink';
			var addtext='+';
			var subtext='-';
			inputs=document.getElementsByTagName('input');
			for(i=0;i<inputs.length;i++)
			{
				if(/.*?_ctr_-{0,1}\d+_-{0,1}\d+/.test(inputs[i].id))
				{
					var cmax=inputs[i].id.match(/.*?_ctr_(-{0,1}\d+)_(-{0,1}\d+)/);
					var cmin=cmax[1];
					var cmax=cmax[2];
					var c=parseInt(inputs[i].value);
					if (isNaN(c) || c<cmin) {inputs[i].value=cmin;}
					if (c>cmax) {inputs[i].value=cmax;}
					inputs[i].value=parseInt(inputs[i].value)
					inputs[i].onchange=function()
					{
						var cmax,cmin,c;
						cmax=this.id.match(/.*?_ctr_(-{0,1}\d+)_(-{0,1}\d+)/)
						cmin=cmax[1];
						cmax=cmax[2];
						c=parseInt(this.value);
						if (isNaN(c) || c<cmin) {this.value=cmin;}
						if (c>cmax) {this.value=cmax;}
						this.value=parseInt(this.value);
					}
					
					newTable = document.createElement('table');
					newTable.className = "counterTable";
					newTable.style.cellspacing = "0";
					newTable.style.cellpadding = "0";
					tBody = document.createElement('tBody');
					newTable.appendChild(tBody);
					tRow = document.createElement('tr');
					tBody.appendChild(tRow);
					tColumn = document.createElement('td');
					tRow.appendChild(tColumn);
					
					newa=document.createElement('a')
					addImg = document.createElement('img');
					addImg.src = "js/upsimple.png";
					addImg.style.border = "0";
					newa.appendChild(addImg);
					newa.o=inputs[i];
					newa.cmax = cmax;
					newa.href='#';
					newa.className=linkclass;
					newa.onclick=function()
					{
						if(parseInt(this.o.value)<this.cmax)
						{
							this.o.value++;
						}
						return false;
					}
					tColumn.appendChild(newa);
					
					tRow = document.createElement('tr');
					tBody.appendChild(tRow);
					tColumn = document.createElement('td');
					tRow.appendChild(tColumn);
					
					newa=document.createElement('a')
					addImg = document.createElement('img');
					addImg.src = "js/downsimple.png";
					addImg.style.border = "0";
					newa.appendChild(addImg);
					newa.o=inputs[i];
					newa.cmin = cmin;
					newa.href='#';
					newa.className=linkclass;
					newa.onclick=function()
					{
						if(parseInt(this.o.value)>this.cmin)
						{
							this.o.value--;
						}
						return false;
					}
					tColumn.appendChild(newa);

					parentNode = inputs[i].parentNode;
					nextSibling = inputs[i].nextSibling;
										
					bigTable = document.createElement('table');
					tBody = document.createElement('tBody');
					bigTable.appendChild(tBody);
					tRow = document.createElement('tr');
					tBody.appendChild(tRow);
					tColumn = document.createElement('td');
					tRow.appendChild(tColumn);
					tColumn.appendChild(inputs[i]);
					tColumn = document.createElement('td');
					tRow.appendChild(tColumn);
					tColumn.appendChild(newTable);
					bigTable.className = "counterTable";
					
					parentNode.insertBefore(bigTable, nextSibling);
				}
			}	
		}
	}
	window.onload=createCounter;	
