var Item = new Class({
	'initialize': function(name, quantity, price) {
		this.quantity = quantity;
		this.name = name;
		this.price = price;
	},
	'cost': function() {
		return this.quantity*this.price;
	}
});

function getRates() {
	var list = [];
	var size = parseInt($("size").value) ;
	if ((size != size) || (size < 0)  ) {
		alert("Введено некорректное количество мест.");
		return false;
	};
	$("size").value = size;
	list.push(new Item("Модуль расширения Scobo GDb24",  Math.ceil(size/8), 7800));
	list.push(new Item("Контроллер Scobo",  Math.ceil(list[0].quantity/12), 24000));
	if (list[1].quantity > 1) {
		list.push(new Item("Маршрутизатор D-Link DIR-130 8 портов",  1, 2500));
		
	};
	list.push(new Item("Монитор 19\"",  1, 6000));
	list.push(new Item("Программное обеспечение на место",  size, 600));
	list.push(new Item("Пульт голосования",  size, 1300));
	if ($('card').checked) {
		list.push(new Item("Считыватель карт стандарта Mifare",  1, 8000));
	}
	var table_array = [];
	var total = 0;
	list.each(function(n) {
		table_array.push([{content: n.name, properties: { style: 'text-align: left'} }, n.quantity, n.price, n.cost()]);
		total +=  n.cost();
	});
	
	var myTable = new HtmlTable({
	    properties: {
	        border: 0,
	        cellspacing: 1,
	style: '1px solid blue'
	    },
	    headers: [{content: "Наименование", properties: { style: 'text-align: left'} }, 'Количество', 'Цена', 'Стоимость'],
	    rows: table_array
	});
	$('result').empty();
	myTable.push([{content: "Итого", properties: {colspan: 3}}, total]);
	myTable.push([{content: "Итого за место", properties: {colspan: 3}}, Math.round(total/size)]);
	myTable.inject($('result'));
};
