﻿function calcTotalListPrice(){
   if ((!isNaN(document.calcTax.listprice.value) && document.calcTax.listprice.value.length > 0 && !isNaN(document.calcTax.freight.value) && document.calcTax.freight.value.length > 0) && parseInt(document.calcTax.listprice.value) >= 20000)
	 {
	   document.calcTax.totallistprice.value = parseInt(document.calcTax.listprice.value) + parseInt(document.calcTax.freight.value);
		 document.getElementById('totallistpricetxt').innerHTML = document.calcTax.totallistprice.value;
		 document.calcTax.pct.disabled = false;
		 calcGroundPrice();
	 }
	 else
	 {
	   document.calcTax.totallistprice.value = "-";
		 document.getElementById('totallistpricetxt').innerHTML = document.calcTax.totallistprice.value;
 		 document.calcTax.pct.disabled = true;
           if (parseInt(document.calcTax.listprice.value) < 20000)
		 document.getElementById('totallistpricetxt').innerHTML = "<font color='red'>Listaprísurin kann ikki verða minni enn 20000 kr</font>";
	 }
}

function calcGroundPrice(){
  if(!isNaN(document.calcTax.listprice.value) && document.calcTax.listprice.value.length > 0)
	{
	  document.calcTax.pctoff.value = parseInt(document.calcTax.totallistprice.value) * (parseInt(document.calcTax.pct.value)/100);
		document.getElementById('pctofftxt').innerHTML = document.calcTax.pctoff.value;
		document.calcTax.groundprice.value = parseInt(document.calcTax.totallistprice.value) - parseInt(document.calcTax.pctoff.value);
		document.getElementById('groundpricetxt').innerHTML = document.calcTax.groundprice.value;
                if (parseInt(document.calcTax.groundprice.value) < 70000)
                {
                  document.calcTax.bound.value = parseInt(document.calcTax.groundprice.value)*0.5;
                  document.getElementById('boundtxt').innerHTML = document.calcTax.bound.value;
                  document.calcTax.rest.value = 0;
                  document.getElementById('resttxt').innerHTML = document.calcTax.rest.value;
                }
                else
                {
                  document.calcTax.bound.value = 35000;
                  document.getElementById('boundtxt').innerHTML = 35000;
		  document.calcTax.rest.value = (parseInt(document.calcTax.groundprice.value) - 70000)*0.75;
                  document.getElementById('resttxt').innerHTML = document.calcTax.rest.value;
                }

		document.calcTax.registerprice.value = parseInt(document.calcTax.bound.value) + parseInt(document.calcTax.rest.value); 
		document.getElementById('registerpricetxt').innerHTML = document.calcTax.registerprice.value;
		document.calcTax.extraprice.value = parseInt(document.calcTax.registerprice.value) * 0.25;
		document.getElementById('extrapricetxt').innerHTML = document.calcTax.extraprice.value;
		document.getElementById('total').innerHTML = parseInt(document.calcTax.registerprice.value) + parseInt(document.calcTax.extraprice.value) + parseInt(document.calcTax.scrapprice.value);
	}
}
