var n=1;
function delRow(n) {
	document.getElementById('SUMMA').value = (document.getElementById('SUMMA').value - document.getElementById('sum'+n).value).toFixed(2);
	tr = document.getElementById('myTR'+n);
	document.getElementById('OrderTable').removeChild(tr);
}

function sumRow(n) {
//	sumR = document.getElementById('sum'+n).value;
//	document.getElementById('sum'+n).value = (document.getElementById('quantity'+n).value * document.getElementById('price'+n).value).toFixed(2);
//	document.getElementById('SUMMA').value = (document.getElementById('SUMMA').value - sumR + document.getElementById('sum'+n).value).toFixed(2);
	sumR = document.getElementById('sum'+n).value * 100;
	sumN = document.getElementById('quantity'+n).value * (100 * document.getElementById('price'+n).value); // иначе дробные копейки
	document.getElementById('sum'+n).value = (sumN / 100).toFixed(2);
	sumAll = document.getElementById('SUMMA').value * 100 - sumR + sumN;
	document.getElementById('SUMMA').value = (sumAll / 100).toFixed(2);
}

function addRow(product,price_1) {
	var tr = document.createElement('tr');
	tr.setAttribute('id','myTR'+n);
	document.getElementById('OrderTable').appendChild(tr);

	var td = document.createElement('td');
	document.getElementById('myTR'+n).appendChild(td);
	text = document.createTextNode(product);
	td.appendChild(text);
	field = document.createElement('input');
	field.setAttribute('name','product[]');
	field.setAttribute('id','product'+n);
	field.setAttribute('type','hidden');
	field.setAttribute('value',product);
	td.appendChild(field);

	var td = document.createElement('td');
	td.setAttribute('align','center');
	td.setAttribute('width','90px');
	document.getElementById('myTR'+n).appendChild(td);
	field = document.createElement('input');
	field.setAttribute('name','quantity[]');
	field.setAttribute('id','quantity'+n);
	field.setAttribute('type','text');
	field.setAttribute('size','7');
	field.onkeyup = new Function( 'return sumRow('+n+');' );// for IE
	td.appendChild(field);
	if (document.getElementById('equipment').style.display == 'block')
	{
		text = document.createTextNode(' шт');
	}else{
		text = document.createTextNode(' кг');
	}
	td.appendChild(text);

	var td = document.createElement('td');
	td.setAttribute('align','center');
	td.setAttribute('width','80px');
	document.getElementById('myTR'+n).appendChild(td);
	field = document.createElement('input');
	field.setAttribute('name','price[]');
	field.setAttribute('value',price_1);
	field.setAttribute('id','price'+n);
	field.setAttribute('type','hidden');
	field.setAttribute('size','10');
	td.appendChild(field);
	text = document.createTextNode(price_1+' грн');
	td.appendChild(text);

	var td = document.createElement('td');
	td.setAttribute('align','center');
	td.setAttribute('width','90px');
	document.getElementById('myTR'+n).appendChild(td);
	field = document.createElement('input');
	field.setAttribute('name','sum[]');
	field.setAttribute('id','sum'+n);
	field.setAttribute('type','text');
	field.setAttribute('size','7');
	field.setAttribute('disabled',"true");
	td.appendChild(field);

	var td = document.createElement('td');
	td.setAttribute('align','center');
	document.getElementById('myTR'+n).appendChild(td);
	field = document.createElement('input');
	field.setAttribute('name','delete');
	field.setAttribute('id','delete'+n);
	field.setAttribute('type','button');
	field.setAttribute('value','delete');
	field.onclick = new Function( "return delRow("+n+");" ); // for IE
	td.appendChild(field);

	n++;
}
