var categories = new Object();
var choices = new Array(3);
choices['item1'] = {title: 'Eminence FL154 + Crown XTi2000 amp', price: 100.000000};
choices['item2'] = {title: 'Dynacord PowerMax 5 set (2 x Dynacord F8 (sub) + 2 x Dynacord F150 (sat) + 4 x 700W RMS amp )', price: 250.000000};
choices['item3'] = {title: 'JBL MP225 + Crown XTi1000', price: 150.000000};
categories['Speakers'] = choices;
var choices = new Array(3);
choices['item1'] = {title: 'Allen&Heath XOne:62 + 2 x Pioneer CDJ 1000MK3', price: 150.000000};
choices['item2'] = {title: 'Allen&Heath XOne:62 + 2 x Technics 1210 MK5', price: 150.000000};
choices['item3'] = {title: 'Allen&Heath DB4 + 2 x Pioneer CDJ-2000', price: 250.000000};
categories['mix'] = choices;
var choices = new Array(3);
choices['item1'] = {title: 'Robe DJ Scan 250XT scanner', price: 40.000000};
choices['item2'] = {title: 'Boost 16 channels DMX controler', price: 20.000000};
choices['item3'] = {title: 'LED PAR 64 light', price: 30.000000};
categories['Lights'] = choices;
var choices = new Array(11);
choices['item1'] = {title: 'Allen & Heath DB4 DJ PRO Mixer', price: 150.000000};
choices['item2'] = {title: 'Allen & Heath XOne:62 DJ PRO Mixer', price: 50.000000};
choices['item3'] = {title: 'Technics 1210 MK5', price: 50.000000};
choices['item4'] = {title: 'Pioneer CDJ-2000 CD-player', price: 75.000000};
choices['item5'] = {title: 'Pioneer CDJ-1000mk3 CD-player', price: 60.000000};
choices['item6'] = {title: 'Denon DN-D4000 double CD-player', price: 35.000000};
choices['item7'] = {title: 'Mic StageLine wireless', price: 10.000000};
choices['item8'] = {title: 'Amplifier Crown XTi2000', price: 30.000000};
choices['item9'] = {title: 'Amplifier Crown XTi1000', price: 25.000000};
choices['item10'] = {title: 'Yamaha MX 12/4 Mixing Console', price: 20.000000};
choices['item11'] = {title: 'Soundandlights.eu team', price: 20.000000};
categories['Parts'] = choices;

//var images = new Object();
var selection = new Object();
var grand_total = 0.0;
var selection_display;

function refresh_selection_display() {
	if (selection_display.innerHTML === undefined)
		throw "HTML element expected as selection_display";
	
	var output = "";
	grand_total = 0.0;
	for (i in selection) {
		for (j in selection[i]) {
			if (selection[i][j] == 0)
				continue;
			var item_total =
				selection[i][j] * categories[i][j].price;
			output += (categories[i][j].title
				+ ": " + selection[i][j]
				+ " x &euro;" + categories[i][j].price
				+ " = &euro;" + item_total
				+ "<br/>\n");
			grand_total += item_total;
		}
	}
	output += ("Total: &euro;" + grand_total);
	
	selection_display.innerHTML = output;
}

function choice_handler(i, j) {
	return function() {
		selection[i][j] = parseFloat(categories[i][j].element.value);
		refresh_selection_display();
		//images[i].src = selection[i].url;
	}
}

function attach_to_form(form) {
	if (!form.elements)
		throw "Form element expected";
		
	for (var i in categories) {
		selection[i] = new Object();
		for (j in categories[i]) {
			var elem_name = 'item[' + i + '][' + j + ']';
			form.elements[elem_name].onchange =
				choice_handler(i, j);
			categories[i][j].element = form.elements[elem_name];
			selection[i][j] = 0;
		}
		
		/*var image = document.getElementById(i + "-img");
		if (image.src === undefined)
			throw "Img element expected";
		else
			images[i] = image;*/
	}
}

