// -------------------------------------------------------------------
// 
// SOME CALC FUNCTIONS 
// -------------------------------------------------------------------

function calctotal(qtd,unit_price,discount){
	var total=qtd*unit_price;
	if(discount.substr(discount.length-1,1)=='%') {
		var liquid_discount=parseFloat(discount);
		
		return  total-(total*(liquid_discount/100));
	} else {
		return total-discount;
	}
}

function ContractSUM(){
	var total1=parseFloat(document.getElementById('mag_total_0').value);
	var total2=parseFloat(document.getElementById('mag_total_1').value);
	var total3=parseFloat(document.getElementById('mag_total_2').value);
	var total4=parseFloat(document.getElementById('snack_total_0').value);
	var total5=parseFloat(document.getElementById('snack_total_1').value);
	var total6=parseFloat(document.getElementById('banner_total_1').value);
	var total7=parseFloat(document.getElementById('banner_total_2').value);
	
	var contractSUM=0;
	
	if (total1) { contractSUM+=total1; }
	if (total2) { contractSUM+=total2; }
	if (total3) { contractSUM+=total3; }
	if (total4) { contractSUM+=total4; }
	if (total5) { contractSUM+=total5; }
	if (total6) { contractSUM+=total6; }
	if (total7) { contractSUM+=total7; }
	
	document.getElementById('total').value = Math.round(contractSUM*100)/100;
}

function LineContractSUM(){
	document.getElementById('mag_total_0').value = calctotal(document.getElementById('mag_nr_editions_0').value,document.getElementById('mag_unit_price_0').value,document.getElementById('mag_discount_0').value)
	document.getElementById('mag_total_1').value = calctotal(document.getElementById('mag_nr_editions_1').value,document.getElementById('mag_unit_price_1').value,document.getElementById('mag_discount_1').value)
	document.getElementById('mag_total_2').value = calctotal(document.getElementById('mag_nr_editions_2').value,document.getElementById('mag_unit_price_2').value,document.getElementById('mag_discount_2').value)
	
	document.getElementById('snack_total_0').value = calctotal(document.getElementById('snack_nr_modules_0').value,document.getElementById('snack_unit_price_0').value,document.getElementById('snack_discount_0').value)
	document.getElementById('snack_total_1').value = calctotal(document.getElementById('snack_nr_modules_1').value,document.getElementById('snack_unit_price_1').value,document.getElementById('snack_discount_1').value)
	
	document.getElementById('banner_total_1').value = calctotal(1,document.getElementById('banner_price_1').value,document.getElementById('banner_discount_1').value)
	document.getElementById('banner_total_2').value = calctotal(1,document.getElementById('banner_price_2').value,document.getElementById('banner_discount_2').value)
	
}

