var items = new Array();

function show(id)
{
        if(document.getElementById("d"+id).style.display=="none")
        {
                document.getElementById("d"+id).style.display="block";
				updateSet(id);
        }
        else
        {
                document.getElementById("d"+id).style.display="none";
        }
}

function hide(id)
{
   document.getElementById(id).style.display="none";
}


function importElements() {
  var j=0;

  for(i=0;i< document.orderform.elements.length-14;i++)
  {
	if (document.orderform.elements[i].value == "new") {
		items[j]=new Object();
		items[j]['styles']=new Array();
		j++;
	}
	if (document.orderform.elements[i].value == "mac_ps1") {
		document.orderform.elements[i].name=new Array();
	}

    eval(document.orderform.elements[i].name + "= document.orderform.elements["+i+"]");
  }

}

function initAllPrices() {
/*	alert(items.length);
	for(i=0;i<items.length;i++)	{
		alert(i);
		items[i]['family'].checked = false;
		for(j=0;j<items[i]['styles'].length;j++) {
			 items[i]['styles'][j].checked = false;
		}
		updateSet(i);
	}*/
}

function updatePrices(id) {
    style_num = 0;
   
	for(i=0;i<items[id]['styles'].length;i++)
		if(items[id]['styles'][i].checked == true) style_num++;

	set = items[id]['set'].value;
	lic = parseInt(items[id]['licences'].value)/5-1;

	if(style_num == 0 ) 
		price = 0;
	else 
		price = prices[set][lic][style_num];
	
	items[id]['sum'].value  = price;
	document.getElementById("sum_"+id).innerHTML = "<b>"+price.toFixed(2)+" EUR</b>";

	updateTotal();
}

function updateTotal() {
	total = 0;

	for(i=0;i<items.length;i++)
		total += parseInt(items[i]['sum'].value);
	document.getElementById("sum_total").innerHTML = "<b>"+total.toFixed(2)+" EUR</b>";
	document.orderform.total.value = total;

}

function chooseFamily(me,id) {
	for(i=0;i<items[id]['styles'].length;i++)
		items[id]['styles'][i].checked = me.checked;
	updatePrices(id);
}

function chooseStyle(me,id) {
	num = 0;
	for(i=0;i<items[id]['styles'].length;i++)
		if(items[id]['styles'][i].checked == true) num++;
	if(num == items[id]['styles'].length)
		items[id]['family'].checked = true;
	else
		items[id]['family'].checked = false;		
	updatePrices(id);
}

function updateSet(id) {
	price_style = prices[items[id]['set'].value][parseInt(items[id]['licences'].value)/5-1][1];
	price_family = prices[items[id]['set'].value][parseInt(items[id]['licences'].value)/5-1][parseInt(items[id]['fstylenum'].value)];
	document.getElementById("price_"+id+"_family").innerHTML = price_family.toFixed(2)+" EUR";
	document.getElementById("price_"+id+"_style").innerHTML = price_style.toFixed(2)+" EUR";
	updatePrices(id);
}


function noSubmit(txt) {
	alert(txt);
	return false;
}

function checkForm() {
	if(document.orderform.email.value.indexOf('@') == -1)
		return noSubmit("Make sure to give a valid e-mail address!")
	//if(document.orderform.formats.length > 2)
 	//return noSubmit("Choose a maximum of 2 formats!");
	if(document.orderform.name.value.length < 2)
		return noSubmit("Make sure to give a valid Name");
	if(document.orderform.address.value.length < 2)
		return noSubmit("Make sure to give a valid address");
	if(document.orderform.city.value.length < 2)
		return noSubmit("Make sure to give a valid city");
	if(document.orderform.postcode.value.length < 2)
		return noSubmit("Make sure to give a valid postcode");
	if(document.orderform.agb.checked != true)
		return noSubmit("Make sure to agree to terms of licence agreement");
	//if(document.orderform.formats.length < 1)
	//	return noSubmit("No format chosen!");
	return true;
}

