function addItem() {
	var ni = document.getElementById('shipItems');
	var numi = document.getElementById('shipItemsCounter');
	var num = (document.getElementById('shipItemsCounter').value -1)+ 2;
	numi.value = num;

	var newLi = document.createElement('table');
	var liIdName = 'shipItemLi'+num;
	newLi.setAttribute('id',liIdName);
	newLi.setAttribute('class',"itemZebra" + (num%2) );
	newLi.setAttribute('className',"itemZebra" + (num%2) );
	newLi.setAttribute('cellSpacing',"0");
	newLi.setAttribute('cellPadding',"0");
	newLi.setAttribute('border',"0");
	newLi.setAttribute('width',"370");
	
	var stupidIE = document.createElement('tbody');
	
	// Labels
	var weightLabel = document.createElement('label');
	weightLabel.setAttribute('for', "origin_weight_" + num);
	var weightLabelText = document.createTextNode('Weight:');
	weightLabel.appendChild(weightLabelText);

	var lengthLabel = document.createElement('label');
	lengthLabel.setAttribute('for', "origin_length_" + num);
	var lengthLabelText = document.createTextNode('Length:');
	lengthLabel.appendChild(lengthLabelText);

	var widthLabel = document.createElement('label');
	widthLabel.setAttribute('for', "origin_width_" + num);
	var widthLabelText = document.createTextNode('Width:');
	widthLabel.appendChild(widthLabelText);

	var heightLabel = document.createElement('label');
	heightLabel.setAttribute('for', "origin_height_" + num);
	var heightLabelText = document.createTextNode('Height:');
	heightLabel.appendChild(heightLabelText);

	// Spans
	var requiredSpan = document.createElement('span');
	requiredSpan.setAttribute('style', "color: red");
	var requiredSpanText = document.createTextNode(' *');
	requiredSpan.appendChild(requiredSpanText);

	var itemNumSpan = document.createElement('td');
	itemNumSpan.setAttribute('class', "itemNumber");
	itemNumSpan.setAttribute('className', "itemNumber");
	itemNumSpan.setAttribute('id',"itemNumber" + num);
	itemNumSpan.setAttribute('width', "50");
	itemNumSpan.setAttribute('rowSpan', "4");
	itemNumSpan.setAttribute('align', "center");
	var itemNumSpanText = document.createTextNode((num+1));
	itemNumSpan.appendChild(itemNumSpanText);

	// Inputs
	var weightInput = document.createElement('input');
	weightInput.setAttribute('name',"origin_weight_" + num);
	weightInput.setAttribute('type',"text");
	weightInput.setAttribute('id',"origin_weight_" + num);
	weightInput.setAttribute('size', "22");
	weightInput.setAttribute('class', "styledBox");
	weightInput.setAttribute('className', "styledBox");
	weightInput.setAttribute('tabIndex', (num*4+22));

	var lengthInput = document.createElement('input');
	lengthInput.setAttribute('name',"origin_length_" + num);
	lengthInput.setAttribute('type',"text");
	lengthInput.setAttribute('id',"origin_length_" + num);
	lengthInput.setAttribute('size', "22");
	lengthInput.setAttribute('class', "styledBox");
	lengthInput.setAttribute('className', "styledBox");
	lengthInput.setAttribute('tabIndex', (num*4+23));

	var widthInput = document.createElement('input');
	widthInput.setAttribute('name',"origin_width_" + num);
	widthInput.setAttribute('type',"text");
	widthInput.setAttribute('id',"origin_width_" + num);
	widthInput.setAttribute('size', "22");
	widthInput.setAttribute('class', "styledBox");
	widthInput.setAttribute('className', "styledBox");
	widthInput.setAttribute('tabIndex', (num*4+24));

	var heightInput = document.createElement('input');
	heightInput.setAttribute('name',"origin_height_" + num);
	heightInput.setAttribute('type',"text");
	heightInput.setAttribute('id',"origin_height_" + num);
	heightInput.setAttribute('size', "22");
	heightInput.setAttribute('class', "styledBox");
	heightInput.setAttribute('className', "styledBox");
	heightInput.setAttribute('tabIndex', (num*4+25));

	// Anchor
	var removeLink = document.createElement('a');
	removeLink.setAttribute('href', "javascript:removeItem(\"shipItemLi" + num + "\", " + num + ")");
//	var removeLinkText = document.createTextNode('(X)');
	var removeLinkText = document.createElement('img');
	removeLinkText.setAttribute('src', "/images/subtract.gif");
	removeLinkText.setAttribute('border', "0");
	removeLinkText.setAttribute('width', "16");
	removeLinkText.setAttribute('height', "16");
	removeLinkText.setAttribute('style', "padding-left:7px;");	
	removeLink.appendChild(removeLinkText);

	var tr1 = document.createElement('tr');
	var tr2 = document.createElement('tr');
	var tr3 = document.createElement('tr');
	var tr4 = document.createElement('tr');
	var td1 = document.createElement('td');
	td1.setAttribute('width', "100");
	td1.setAttribute('height', "25");
	td1.setAttribute('align', "right");
	var td2 = document.createElement('td');
	td2.setAttribute('width', "175");
	
	tr1.appendChild(itemNumSpan);
	tmp = td1.cloneNode(true);
	tmp.appendChild(weightLabel);
	tr1.appendChild(tmp);
	tmp = td2.cloneNode(true);
	tmp.appendChild(weightInput);
	tmp.appendChild(requiredSpan);
	tr1.appendChild(tmp);

	tmp = td1.cloneNode(true);
	tmp.appendChild(lengthLabel);
	tr2.appendChild(tmp);
	tmp = td2.cloneNode(true);
	tmp.appendChild(lengthInput);
	tr2.appendChild(tmp);

	tmp = td1.cloneNode(true);
	tmp.appendChild(widthLabel);
	tr3.appendChild(tmp);
	tmp = td2.cloneNode(true);
	tmp.appendChild(widthInput);
	tr3.appendChild(tmp);

	tmp = td1.cloneNode(true);
	tmp.appendChild(heightLabel);
	tr4.appendChild(tmp);
	tmp = td2.cloneNode(true);
	tmp.appendChild(heightInput);
	tmp.appendChild(removeLink);
	tr4.appendChild(tmp);
	
	stupidIE.appendChild(tr1);
	stupidIE.appendChild(tr2);
	stupidIE.appendChild(tr3);
	stupidIE.appendChild(tr4);
	newLi.appendChild(stupidIE);

	ni.appendChild(newLi);
	renumberItems();
//	alert(ni.innerHTML);
}

function removeItem(liNum, num) {
	var d = document.getElementById('shipItems');
	var oldLi = document.getElementById(liNum);
	d.removeChild(oldLi);
	renumberItems();
}

function renumberItems() {
	renumber = 0
	for(i=0;i<=document.getElementById('shipItemsCounter').value;i++) {
		if(document.getElementById('itemNumber'+i)) {
			document.getElementById('itemNumber'+i).innerHTML = (renumber+1);
			document.getElementById('shipItemLi'+i).setAttribute('class',"itemZebra" + (renumber%2) );
			document.getElementById('shipItemLi'+i).setAttribute('className',"itemZebra" + (renumber%2) );
			renumber++;
//			alert(i+"='"+ document.getElementById('itemNumber'+i).innerHTML + "'");
		}
	}
}
