// function to calculate the total cost field
// functions all copyright 2002 by Webscorpion.com.

function SumItUp() {
  var totalsetup = 0; 
  var totalcost = 0;
  var costname;
  var setupname;
  var i;
 
  for (i=1; i <= 5; i++) {
    costname   = "cost" + i; 
	setupname  = "setup" + i;
    totalsetup += 1 * document.order[setupname].value;
    totalcost  += 1 * document.order[costname].value;
  }
  yearcost = totalcost * 11;
  document.order.totalsetup.value = totalsetup;
  document.order.totalcost.value = totalcost;
  document.order.yearsetup.value = totalsetup;
  document.order.yearcost.value = yearcost;  
  
  
  
  if (totalcost < 10) {
  	document.order.yearly.checked = true;
	document.order.notice.value = "Due to billing overhead minimal monthly charge is $10";
	} else 
	document.order.notice.value = "";  
  
  if (document.order.yearly.checked)
	  document.order.billedccusd.value = yearcost + totalsetup;
  else
	  document.order.billedccusd.value = totalcost + totalsetup;  
  document.order.billedppusd.value = document.order.billedccusd.value;
  


//  document.order.billedmbeur.value = parseInt(document.order.billedccusd.value * 0.8);

}

// function to update cost when quantity is changed
function UpdateCost(number, unitsetup, unitcost) {
   var costname = "cost" + number;
   var setupname = "setup" + number;
   var qtyname = "qty" + number;
   var input = document.order[qtyname].value;
   if (input == 0) unitsetup = 0;
   document.order[qtyname].value = input;
   document.order[setupname].value = unitsetup;
   document.order[costname].value = document.order[qtyname].value * unitcost; 
   SumItUp();
}

function UpdatePlan() {
  switch (document.order.qty1.value)
  {
    case "A":
	  document.order.setup1.value = 0;
	  document.order.cost1.value = 25;
	  break;
    case "B":
	  document.order.setup1.value = 0;
	  document.order.cost1.value = 40;
	  break;
    case "C":
	  document.order.setup1.value = 0;
	  document.order.cost1.value = 55;
	  break;    
	case "D":
	  document.order.setup1.value = 0;
	  document.order.cost1.value = 70;
	  break;
    default:
	  document.order.setup1.value = 0;
	  document.order.cost1.value = 0;
	  break;
  }
  SumItUp();
}

function UpdateTick(number, setupcost, unitcost) {
  var setupname = "setup" + number;
  var costname = "cost" + number;
  var qtyname = "qty" + number;
  if (document.order[qtyname].checked) {
    document.order[setupname].value = setupcost;
    document.order[costname].value = unitcost;
  } else {
     document.order[setupname].value = 0.00;
     document.order[costname].value = 0.00;
  }
  SumItUp();
}

function recalcAll() {
  UpdatePlan();
  UpdateTick(2, 0, 25);
  UpdateCost(3, 0, 20);
  UpdateCost(4, 0, 20);  
  UpdateTick(5, 0, 20);  
}

function undo() {
  alert("Please do not update total fields.\nThey are updated automatically based on items chosen in the order column, left.");
  UpdatePlan();
}


