function Corderline(item,units,row)
{
	this.product     = item;
	this.units       = units;
	this.price       = "";
	this.row         = row;
	this.set_product = orderline_set_product;
	this.set_service = orderline_set_service;
	this.set_units   = orderline_set_units;
	this.show        = orderline_show;
	this.calc        = orderline_calc;
}

function orderline_calc()
{	
	if (this.product == "")
	{	
		//no product. initialise all
		this.units   = 0;
		this.price   = "";
	}
	else
	{	
		//product chosen.
		if (this.units == 0)
		{	
			//no units chosen. initialise price
			this.price = "";
		}
		else
		{	
			//units chosen.
			this.price = this.units * this.product.unitprice;
		}
	}
	populate_summary();
}

function orderline_set_product(product_list)
{	
	var index = product_list.selectedIndex;
	if (product_list.selectedIndex == 0)
	{	
		this.product = "";
		this.units   = 0;
		parent.lines[this.row].units_index = 0;
	}
	else
	{	
		this.product = parent.products[index];
	}
	parent.lines[this.row].product_index = index;
	this.calc();
	this.show();
}

function orderline_set_service(service_list)
{	
	var index = service_list.selectedIndex;
	if (service_list.selectedIndex == 0)
	{	
		this.product = "";
		this.units   = 0;
		parent.lines[this.row].units_index = 0;
	}
	else
	{	
		this.product = parent.services[index];
		this.units   = 1;
	}
	parent.lines[this.row].product_index = index;
	parent.lines[this.row].units_index = 1;
	this.calc();
	this.show();
}

function orderline_set_units(unit_list)
{	
	if ( this.product == "" )
	{	
		// no product chosen
		if ( unit_list.selectedIndex != 0 )
		{	
			// units are not being set to zero.
			alert("Choose a product first");
		}
		this.units = 0;
	}
	else
	{	
		// a product was chosen. Apply the new number of units
		this.units = unit_list.selectedIndex;
	}
	parent.lines[this.row].units_index = this.units;	
	this.calc();
	this.show();
}

function orderline_show()
{	
	var product_index;
	var price_index;

	//???????????????????????
	if (this.row<=5)
	{	
		product_index = (this.row-1)*4;
		price_index   = product_index+3;
	}
	else
	{	
		product_index = 20 + (this.row-6)*2;
		price_index   = product_index+1;
	}
	//????????????????????????

	if (document.forms[0].elements[product_index].selectedIndex == 0)
	{	
		//no product chosen, initialise all fields
		//product
		document.forms[0].elements[product_index].selectedIndex = 0;
		if (this.row<=5)
		{	
			//unitprice
			document.forms[0].elements[product_index+1].value = "";
			//units
			document.forms[0].elements[product_index+2].selectedIndex = 0;
		}
		//price
		document.forms[0].elements[price_index].value = "";
	}
	else
	{	
		//product chosen. 
		if (this.row<=5)
		{	
			//unitprice 
			//for products
			document.forms[0].elements[product_index+1].value = FormatNumber(this.product.unitprice,"EUR",4,2);
		}
		else
		{	
			//price for services
			document.forms[0].elements[price_index].value = FormatNumber(this.product.unitprice,"",2,0) + "%";
		}
		if (this.row<=5)
		{	
			//products only
			if (document.forms[0].elements[product_index+2].selectedIndex == 0)
			{	
				//no units chosen, initialise price field
				//price
				document.forms[0].elements[product_index+3].value = "";
			}
			else
			{	
				//units chosen. 
				//price
				document.forms[0].elements[product_index+3].value = FormatNumber(this.price,"EUR",4,2);
			}
		}
	}
} 

function populate_summary()
{	
	//summarise
	str = "";
	total = 0;
	totalproducts = 0;
	for (var i=1 ; i<= orderlines.len ; i++)
	{	
		if (orderlines[i].product != "" && orderlines[i].units > 0)
		{	
			if (i<=5)
			{
				//product
				str   += orderlines[i].units 	
        	                      + " x " + orderlines[i].product.name 
				      + " = " + FormatNumber(orderlines[i].price,"EUR",4,2)
				      + "<br>";
				total += orderlines[i].price;
				totalproducts += orderlines[i].price;
			}
			else
				//service
			{
				serviceprice = totalproducts * (orderlines[i].price / 100);
				str	+= orderlines[i].product.name
					+ " " + FormatNumber(orderlines[i].price,"",2,0) + "%"
					+ " = " + FormatNumber(serviceprice,"EUR",6,2)
					+ "<br>";
				total += serviceprice;
			}
			
		}
	}
	if (parent.shipment == 1)
	{
		//CD-ROM shipment
		total = total + 15;
		str +="CD-ROM shipment EUR 15.00"
	}
	//Put the values in the summary frame
	parent.ordersummary = str;
	parent.total = total;
}
