function Article(id, price1, price4, price10) {
	this.id = id;

	this.price1  = parseFloat(price1);
	this.price4  = parseFloat(price4);
	this.price10 = parseFloat(price10);

	this.qtyInput1  = document.getElementById('qty-'+this.id+'-1');
	this.qtyInput4  = document.getElementById('qty-'+this.id+'-4');
	this.qtyInput10 = document.getElementById('qty-'+this.id+'-10');
}

function check_quantity(evt) {
	var charCode = (window.event) ? evt.keyCode : evt.which;
	//alert(charCode);
	if(
		8  == charCode || // backspace
		9  == charCode || // tab
		37 == charCode || // left arrow
		39 == charCode || // right arrow
		(48 <= charCode && 57 >= charCode) // 0-9
	)
		return true;
	
	return false;
}

function calculate_totalprice(type_) {
	// global var : articles
	var frm, totalprice;
	
	if(undefined == frm) {
		frm = document.forms['orderfrm'];
		totalprice = document.getElementById('tpvalue');
	}
	
	totalprice = 0;
	
	for(var i = 0; i < articles.length; i++) {

		var art = articles[i];

		//if(1 == type_) {
		//	art.qtyInput4.value  = '';
		//	art.qtyInput10.value = '';
		//}
		//else if(4 == type_) {
		//	art.qtyInput1.value  = '';
		//	art.qtyInput10.value = '';
		//}
		//else if(10 == type_) {
		//	art.qtyInput1.value = '';
		//	art.qtyInput4.value = '';
		//}

		var qty1  = parseInt(art.qtyInput1.value)  || 0;
		var qty4  = parseInt(art.qtyInput4.value)  || 0;
		var qty10 = parseInt(art.qtyInput10.value) || 0;
		
		if(10 <= qty10) {
			qty1 = 0;
			qty4 = 0;
			art.qtyInput1.value = '';
			art.qtyInput4.value = '';
		}
		else {
			qty10 = 0;
			art.qtyInput10.value = '';
		}
		
		if(4 <= qty4 && 9 >= qty4) {
			qty1 = 0;
			art.qtyInput1.value = '';
		}
		else {
			qty4 = 0;
			art.qtyInput4.value = '';
		}
		
		if(0 == qty1 || 4 <= qty1) {
			qty1 = 0;
			art.qtyInput1.value = '';
		}
		
		if(0 == qty1) {
			art.qtyInput1.className = 'emptyqty';
			qty1 = 0;
		}
		else
			art.qtyInput1.className = 'filledqty';
			
		if(0 == qty4) {
			art.qtyInput4.className = 'emptyqty';
			qty4 = 0;
		}
		else
			art.qtyInput4.className = 'filledqty';
			
		if(0 == qty10) {
			art.qtyInput10.className = 'emptyqty';
			qty10 = 0;
		}
		else
			art.qtyInput10.className = 'filledqty';
		
		totalprice += (qty1 * art.price1 + qty4 * art.price4 + qty10 * art.price10);
	}
	
	
	if(0 < totalprice) totalprice += deliveryprice;
	
	totalprice = Math.round(totalprice * 100) / 100;
	
	totalprice = new String(totalprice);
	
	var idot = totalprice.indexOf('.');
	if(-1 == idot)
		totalprice += '.00';
	else if(1 == totalprice.substr(idot+1).length)
		totalprice += '0';
		
	document.getElementById('tpvalue').innerHTML = totalprice+' &euro;';
	
}

function check_orderform(frm) {
	var inputs = frm.getElementsByTagName('input');
	
	var fill = false;
	
	for(var i = 0; i < inputs.length; i++) {
		if(
			   0 == inputs[i].name.indexOf('qty-')
			&& 0 < inputs[i].value.length
		) {
			fill = true;
			break;
		}
	}
	
	if(!fill) alert('Veuillez renseigner au moins une quantité');

	return fill;
}
