/* calculator code for JCCSF ticket form */

var theSubTotal = 0;
var theDiscount = 0;
var theDonation;
var thePatron;
var theGrandTotal;
var theProcessingFee = 6;
var showCount;

function doMember(what){
  if(what == "public"){
    document.getElementById('show1Price').innerHTML = 26.00.toFixed(2);
    document.getElementById('show3Price').innerHTML = 26.00.toFixed(2);;
    document.getElementById('show4Price').innerHTML = 26.00.toFixed(2);;
    document.getElementById('show5Price').innerHTML = 26.00.toFixed(2);;
    document.getElementById('show6Price').innerHTML = 26.00.toFixed(2);;
    document.getElementById('show7Price').innerHTML = 15.00.toFixed(2);;
    document.getElementById('show8Price').innerHTML = 15.00.toFixed(2);;
    document.getElementById('show9Price').innerHTML = 25.00.toFixed(2);;
    } else {
    document.getElementById('show1Price').innerHTML = 22.00.toFixed(2);;
    document.getElementById('show3Price').innerHTML = 22.00.toFixed(2);;
    document.getElementById('show4Price').innerHTML = 22.00.toFixed(2);;
    document.getElementById('show5Price').innerHTML = 22.00.toFixed(2);;
    document.getElementById('show6Price').innerHTML = 22.00.toFixed(2);;
    document.getElementById('show7Price').innerHTML = 12.00.toFixed(2);;
    document.getElementById('show8Price').innerHTML = 12.00.toFixed(2);;
    document.getElementById('show9Price').innerHTML = 23.00.toFixed(2);;
  }
  calculateExt()
}

function countShows()
{
  showCount = 0;
  for(i = 1; i <= 10; i++)
  {
    if(document.getElementById('show' + i + "Qty").value > 0)
    {
      showCount = showCount + 1;
    }
  }
}


function calculateExt(){
  for(i = 1; i <= 10; i++){
    document.getElementById('show' + i + "Ext").value =
      (document.getElementById('show' + i + "Qty").value *
      document.getElementById('show' + i + "Price").innerHTML).toFixed(2);
  }
  calculateTotals()
}

function calculateTotals(){
  calculateSubTotal();
  countShows();
  calculate20PercentDiscount();
  calculateDonation();
  calculatePatron();
  calculateGrandTotal();
  writeGrandTotal();
}

function calculateSubTotal(){
  theSubTotal = 0;
  for(i = 1; i <= 10; i++){
    theSubTotal= theSubTotal + parseInt(document.getElementById('show' + i + "Ext").innerHTML);
  }
  document.getElementById("subTotal").innerHTML = theSubTotal.toFixed(2);
}

function calculate20PercentDiscount(){
  if (showCount >= 3)
  {
    theDiscount = theSubTotal * .20;
  }
  else if (showCount < 3)
  {
    theDiscount = 0;
  }
  document.getElementById("20PercentDiscount").innerHTML = theDiscount.toFixed(2);
}

function calculateGrandTotal(){
  theGrandTotal = theSubTotal - theDiscount + theDonation + thePatron + theProcessingFee;
}


function calculateDonation(){
  theDonation = parseInt(document.getElementById("donation").value);
}

function calculatePatron(){
  thePatron = parseInt(document.getElementById("patron").value);
}

function writeGrandTotal(){
  document.getElementById("grantTotal").innerHTML= theGrandTotal.toFixed(2)
}
