function cartVisualization ()
{
}

cartVisualization.prototype.addRequestRow = function (values, setfocus) {
	var tbody = document.getElementById ('rows2Order').firstChild;
	var last_tr = tbody.childNodes[tbody.childNodes.length - 1];

	//клонируем
	var b = last_tr.cloneNode (true);
	
	//проставляем значения
	if (!values) {
		values = new Array ('', '', '', '', '');
	}

	this.fillRequestRow (b, values);

	//меняем картинку и ссылку бывшей последней строки
	last_tr.childNodes[5].firstChild.src = 'images/remove_row.gif';
	last_tr.childNodes[5].firstChild.onclick = new Function ('abo_cart_visualization.removeRequestRow (this)');

	//добавляем
	tbody.appendChild (b);

	//ставим флкус
	if (setfocus)
		b.childNodes[0].firstChild.focus ();
}

//удалить строку
cartVisualization.prototype.removeRequestRow = function (img) {
	var tr = img.parentNode.parentNode;
	var tbody = img.parentNode.parentNode.parentNode;
	tbody.removeChild (tr);
}

//удалить все доп. строки полей ввода, первую очистить
cartVisualization.prototype.clearRequestRows = function () {
	var tbody = document.getElementById ('rows2Order').firstChild;
	var a = tbody.childNodes.length - 2;
	for (var i = 0; i < a; i ++)
		tbody.removeChild (tbody.childNodes[1]);

	//очистить оставшуюся строку
	this.fillRequestRow (tbody.childNodes[1], Array ('', '', '', '', ''));
}

//заполнить строку по ссылке на tr и массиу значений
cartVisualization.prototype.fillRequestRow = function (tr, values) {
	tr.childNodes[0].firstChild.value = values[0];
	tr.childNodes[1].firstChild.value = values[1];
	tr.childNodes[2].firstChild.value = values[2];
	tr.childNodes[3].firstChild.value = values[3];
	tr.childNodes[4].firstChild.value = values[4];
}

//заполнить нулевую строку
cartVisualization.prototype.fillZeroRequestRow = function (values) {
	this.fillRequestRow (document.getElementById ('rows2Order').firstChild.childNodes[1], values);
}

//заполнить строки данным
cartVisualization.prototype.fillRequestRows = function (id) {
	var pos = abo_cart.getPosition (id)
	if (pos) {
		for (var a in pos.rows)
		{
			if (a == 0)
				this.fillZeroRequestRow (pos.rows[0]);
			else
				this.addRequestRow (pos.rows[a]);
		}
		//добавить пустую строку
		this.addRequestRow ();
	}
}

/* отрисовка корзины */
cartVisualization.prototype.drawCart = function (current_position_id) {
	this.current_position_id = current_position_id;
	//нарисовать корзину и запихать туда текущие позиции
	document.write ('			<table border="0" width="100%" cellpadding="0" cellspacing="4" class="cart" id="cart">');
	document.write ('				<tr style="display:none">');
	document.write ('					<td nowrap></td>');
	document.write ('					<th><img src="images/position_remove.gif" class="remove" width="9" height="9" border="0" alt="L&ouml;schen"></th>');
	document.write ('				</tr>');
	document.write ('				<tr style="display:none">');
	document.write ('					<td colspan="2" bgcolor="#C9CFD7"><img src="images/spacer.gif" width="1" height="1"></td>');
	document.write ('				</tr>');
	document.write ('			</table>');

	if (abo_cart.getPositionsCount () > 0) {
		var a = abo_cart.getPositions ();
		for (id in a) {
			this.addPositionToCart (id,a[id].mark);
		}
	}
}

//добавить позицию - визуализация
cartVisualization.prototype.addPositionToCart = function (id, mark) {
	//добавляем строку
	var cart_tbl_tbody = document.getElementById ('cart').firstChild;
	var new_row = cart_tbl_tbody.childNodes[cart_tbl_tbody.childNodes.length - 2].cloneNode (true);
	var new_row_div = cart_tbl_tbody.childNodes[cart_tbl_tbody.childNodes.length - 1].cloneNode (true);

	//ячейка с mark
	new_row.style.display = '';
	if (id == this.current_position_id)
		new_row.childNodes[1].firstChild.onclick = new Function ('removeCurrentPosition()');//не-текущая позиция
	else
		new_row.childNodes[1].firstChild.onclick = new Function ('removeFromCart(' + id + ')');//текущая позиция
	//разделитель
	new_row.firstChild.innerHTML = mark;
	new_row_div.style.display = '';

	new_row.id = 'cart_position_' + id;
	new_row_div.id = 'cart_position_divider' + id;

	cart_tbl_tbody.appendChild (new_row);
	cart_tbl_tbody.appendChild (new_row_div);

	//визуализация корзины
	if (abo_cart.getPositionsCount () >= 0)
		this.visualizeCart (true);
}

//удалить из корзины - визуализация + удаление данных
cartVisualization.prototype.removePositionFromCart = function (id) {
	var cart_tbl_tbody = document.getElementById ('cart').firstChild;
	cart_tbl_tbody.removeChild (document.getElementById ('cart_position_' + id));
	cart_tbl_tbody.removeChild (document.getElementById ('cart_position_divider' + id));

	//если корзина пуста - скрываем
	if (abo_cart.getPositionsCount () == 0)
		this.visualizeCart (false);
}

//показать/скрыть корзину
cartVisualization.prototype.visualizeCart = function (visible) {
	if (visible == true)
	{
		document.getElementById ('cart_cell_0').style.display = '';
		document.getElementById ('cart_cell_1').style.display = '';
		document.getElementById ('cart_cell_2').style.display = '';
	}
	else
	{
		document.getElementById ('cart_cell_0').style.display = 'none';
		document.getElementById ('cart_cell_1').style.display = 'none';
		document.getElementById ('cart_cell_2').style.display = 'none';
	}
}
