// This .js file relates to the OnlinePayment (shop) page ONLY
// 
// Treatments: showHide1
// Retreats: showHide2 / calcre# / CalcRETotal
// Workshops: showHide3 / calcwo# / CalcWOTotal
// AudioCD's: showHide4 / calcd# / CalcCDTotal
// SpiritualCoaching: showHide5 / CalcCoachTotal
// GiftVouchers: showHide6 / showRecipient
//   Also showHide8 for the terms and conditions
// OtherPayments: showHide7
//
// Form Total: CalcFormTotal
//
// ON EACH UPDATE DON'T FORGET TO CHANGE:
// Payfirm.php (online confirmation/PayPal button) 
// /_forms/Payres.html (to go to the client)
// /_forms/OnlinePayment.tpl (to go to Sally)



// --------------------------------------------
// Shows/hides the TREATMENTS Section
// It also returns the fields to default values on hide
function showHide1 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn1').value = "0.00";
      document.getElementById('treatment').value = "EFT";
      document.getElementById('type').value = "Pre-Payment";
      style.display = "none"; 
    }
  } 



// --------------------------------------------
// Shows/hides the RETREATS Section
// It also returns the fields to default values on hide
// WILL NEED UPDATING AS RETREATS ARE ADDED/REMOVED
function showHide2 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn2').value = "0.00";
      document.getElementById('repayquant1').value = '';
      document.getElementById('repayamount1').value = "0.00";
      document.getElementById('repayquant2').value = '';
      document.getElementById('repayamount2').value = "0.00";
      document.getElementById('repaydetails').value = '';
      style.display = "none"; 
    }
  } 
// document.getElementById('repayquant2').value = '';
// document.getElementById('repayamount2').value = "0.00";
// document.getElementById('repayquant3').value = '';
// document.getElementById('repayamount3').value = "0.00";

// RETREAT Section Row Calculation
// These 2 scripts multiply the RETREAT cost x quantity rows
// Add/remove extra functions as necessary
function calcre1() {
    if (isNaN(document.getElementById('repayquant1').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('repayquant1').value; 
	var b = 35; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.repayamount1.value = c.toFixed(2);
  }
function calcre2() {
    if (isNaN(document.getElementById('repayquant2').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('repayquant2').value; 
    var b = 35; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.repayamount2.value = c.toFixed(2);
  }
//function calcre3() {
//    if (isNaN(document.getElementById('repayquant3').value)) //filter input
//    {
//    alert('Numbers only please!');
//    oText.value = '';
//    }
//    var a = document.getElementById('repayquant3').value; 
//    var b = 35; //UPDATE COST PER UNIT AS NECESSARY
//    var c = (a * b);
//    document.forms.shopform.repayamount3.value = c.toFixed(2);
//  }

// RETREAT Section Table Column Sum Calculation
// Adds the row totals together
// DON'T CHANGE (it automatically allows for varying numbers of rows)
function CalcRETotal()
{
var trs = document.getElementById('repay').getElementsByTagName('tr');
	var RESum = 0.00;
	for (i=1; i<=trs.length-2; i++) { 
		RESum += parseFloat(document.getElementById("repayamount" + i).value);
	}
	document.getElementById("amountn2").value = RESum.toFixed(2);
}



// --------------------------------------------
// Shows/hides the WORKSHOPS Section
// It also returns the fields to default values on hide
// WILL NEED UPDATING AS THE NUMBER OF WORKSHOPS CHANGE
function showHide3 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn3').value = "0.00";
      document.getElementById('wopayquant1').value = '';
      document.getElementById('wopayamount1').value = "0.00";
      document.getElementById('wopayquant2').value = '';
      document.getElementById('wopayamount2').value = "0.00";
      document.getElementById('wopayquant3').value = '';
      document.getElementById('wopayamount3').value = "0.00";
      document.getElementById('wopaydetails').value = '';
      style.display = "none"; 
    }
  } 
// document.getElementById('wopayquant2').value = '';
// document.getElementById('wopayamount2').value = "0.00";
// document.getElementById('wopayquant3').value = '';
// document.getElementById('wopayamount3').value = "0.00";
// document.getElementById('wopayquant4').value = '';
// document.getElementById('wopayamount4').value = "0.00";
// document.getElementById('wopayquant5').value = '';
// document.getElementById('wopayamount5').value = "0.00";
// document.getElementById('wopayquant6').value = '';
// document.getElementById('wopayamount6').value = "0.00";
// document.getElementById('wopayquant7').value = '';
// document.getElementById('wopayamount7').value = "0.00";
// document.getElementById('wopayquant8').value = '';
// document.getElementById('wopayamount8').value = "0.00";

// WORKSHOP Section Row Calculation
// These scripts multiply the WORKSHOP cost x quantity rows
// Add/remove extra functions as necessary and don't forget to update the COSTS
  function calcwo1() {
    if (isNaN(document.getElementById('wopayquant1').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('wopayquant1').value; 
	var b = 25; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.wopayamount1.value = c.toFixed(2);
  }
  function calcwo2() {
    if (isNaN(document.getElementById('wopayquant2').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('wopayquant2').value; 
	var b = 25; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.wopayamount2.value = c.toFixed(2);
  }
  function calcwo3() {
    if (isNaN(document.getElementById('wopayquant3').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('wopayquant3').value; 
    var b = 25; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.wopayamount3.value = c.toFixed(2);
  }
//  function calcwo4() {
//  if (isNaN(document.getElementById('wopayquant4').value)) //filter input
//  {
//  alert('Numbers only please!');
//  oText.value = '';
//  }
//  var a = document.getElementById('wopayquant4').value; 
//  var b = 25; //UPDATE COST PER UNIT AS NECESSARY
//  var c = (a * b);
//  document.forms.shopform.wopayamount4.value = c.toFixed(2);
//  }
// function calcwo5() {
// if (isNaN(document.getElementById('wopayquant5').value)) //filter input
// {
// alert('Numbers only please!');
// oText.value = '';
// }
// var a = document.getElementById('wopayquant5').value; 
// var b = 25; //UPDATE COST PER UNIT AS NECESSARY
// var c = (a * b);
// document.forms.shopform.wopayamount5.value = c.toFixed(2);
// }
// function calcwo6() {
// if (isNaN(document.getElementById('wopayquant6').value)) //filter input
// {
// alert('Numbers only please!');
// oText.value = '';
// }
// var a = document.getElementById('wopayquant6').value; 
// var b = 10; //UPDATE COST PER UNIT AS NECESSARY
// var c = (a * b);
// document.forms.shopform.wopayamount6.value = c.toFixed(2);
// }
// function calcwo7() {
// if (isNaN(document.getElementById('wopayquant7').value)) //filter input
// {
// alert('Numbers only please!');
// oText.value = '';
// }
// var a = document.getElementById('wopayquant7').value; 
// var b = 30; //UPDATE COST PER UNIT AS NECESSARY
// var c = (a * b);
// document.forms.shopform.wopayamount7.value = c.toFixed(2);
// }
// function calcwo8() {
// if (isNaN(document.getElementById('wopayquant8').value)) //filter input
// {
// alert('Numbers only please!');
// oText.value = '';
// }
// var a = document.getElementById('wopayquant8').value; 
// var b = 25; //UPDATE COST PER UNIT AS NECESSARY
// var c = (a * b);
// document.forms.shopform.wopayamount8.value = c.toFixed(2);
// }

// WORKSHOP Section Table Column Sum Calculation
// Adds the row totals together
// DON'T CHANGE (it automatically allows for varying numbers of rows)
function CalcWOTotal()
{
var trs = document.getElementById('wopay').getElementsByTagName('tr');
	var WOSum = 0.00;
	for (i=1; i<=trs.length-2; i++) { 
		WOSum += parseFloat(document.getElementById("wopayamount" + i).value);
	}
	document.getElementById("amountn3").value = WOSum.toFixed(2);
}



// --------------------------------------------
// Shows/hides the AUDIO CD Section
// It also returns the fields to default values on hide
// WILL NEED UPDATING AS CD's ARE ADDED/REMOVED
function showHide4 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn4').value = "0.00";
      document.getElementById('cdpayquant1').value = '';
      document.getElementById('cdpayamount1').value = "0.00";
      document.getElementById('cdpayquant2').value = '';
      document.getElementById('cdpayamount2').value = "0.00";
      document.getElementById('cdpayquant3').value = '';
      document.getElementById('cdpayamount3').value = "0.00";
      document.getElementById('cdpayname').value = '';
      document.getElementById('cdpayaddress').value = '';
      style.display = "none"; 
    }
  } 
// AUDIO CD Section Row Calculation
// These 3 scripts multiply the AUDIO CD cost x quantity rows
// Add/remove extra functions as necessary
  function calccd1() {
    if (isNaN(document.getElementById('cdpayquant1').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('cdpayquant1').value; 
	var b = 11.5; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.cdpayamount1.value = c.toFixed(2);
  }
  function calccd2() {
    if (isNaN(document.getElementById('cdpayquant2').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('cdpayquant2').value; 
	var b = 11.5; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.cdpayamount2.value = c.toFixed(2);
  }
  function calccd3() {
    if (isNaN(document.getElementById('cdpayquant3').value)) //filter input
    {
    alert('Numbers only please!');
    oText.value = '';
    }
    var a = document.getElementById('cdpayquant3').value; 
	var b = 11.5; //UPDATE COST PER UNIT AS NECESSARY
    var c = (a * b);
    document.forms.shopform.cdpayamount3.value = c.toFixed(2);
  }
// AUDIO CD Section Table Column Sum Calculation
// Adds the row totals together
// DON'T CHANGE (it automatically allows for varying numbers of rows)
function CalcCDTotal()
{
var trs = document.getElementById('cdpay').getElementsByTagName('tr');
	var CDSum = 0.00;
	for (i=1; i<=trs.length-2; i++) { 
		CDSum += parseFloat(document.getElementById("cdpayamount" + i).value);
	}
	document.getElementById("amountn4").value = CDSum.toFixed(2);
}



// --------------------------------------------
// Shows/hides the SPIRITUAL COACHING Section
// It also returns the fields to default values on hide
function showHide5 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn5').value = "0.00";
      document.getElementById('coachpayamount1').value = '';
      document.getElementById('coachpayamount2').value = "0.00";
      document.getElementById('coachpayamount3').value = "0.00";
      style.display = "none"; 
    }
  } 
// SPIRITUAL COACHING Section Sum Calculation
// Adds the individual costs together (not a table)
// DON'T CHANGE (unless extra lines are added/removed)
function CalcCoachTotal()
{
	var CoachSum = 0.00;
	for (i=1; i<=3; i++) { 
		CoachSum += parseFloat(document.getElementById("coachpayamount" + i).value);
	}
	document.getElementById("amountn5").value = CoachSum.toFixed(2);
}



// --------------------------------------------
// Shows/hides the GIFT VOUCHERS Section
// It also returns the fields to default values on hide
function showHide6 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn6').value = "0.00";
      document.getElementById('gvpayformat').value = "Electronic Format";
      document.getElementById('gvpayissue').value = "Purchaser";
      document.getElementById('gvpayname').value = '';
      document.getElementById('gvpayaddress').value = '';
      document.getElementById('gvpaymessage').value = '';
      style.display = "none"; 
    }
  } 
// Shows/hides the Recipient detail boxes for GIFT VOUCHER Recipients
// (when different from the purchaser)
function showRecipient(divid,value){ 
    if(value == 'Recipient'){ 
      document.getElementById(divid).style.display = 'block'; 
    }
	else { 
      document.getElementById(divid).style.display = 'none'; 
    } 
  } 

// --------------------------------------------
// Shows/hides the TERMS AND CONDITIONS in the GIFT VOUCHERS Section
function showHide8 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      style.display = "none"; 
    }
  } 

// --------------------------------------------
// Shows/hides the OTHER PAYMENTS Section
// It also returns the fields to default values on hide
function showHide7 (id) { 
    var style = document.getElementById(id).style 
    if (style.display == "none") {
      style.display = "block"; 
	}
    else  {
      document.getElementById('amountn7').value = "0.00";
      document.getElementById('genpay').value = "Invoice Payment";
      document.getElementById('genpayinvnr').value = '';
      document.getElementById('genpayproduct').value = '';
      style.display = "none"; 
    }
  } 



// --------------------------------------------
// FORM SUM CALCULATION
// Adds the Section Totals together
// DON'T CHANGE (unless whole sections are added/removed
function CalcFormTotal()
{
	var FormSum = 0.00;
	for (i=1; i<=7; i++) {
		FormSum += parseFloat(document.getElementById("amountn" + i).value);
	}
	document.getElementById("amount").value = FormSum.toFixed(2);
}



<!--UNUSED CODE SNIPPETS
<!--Obtains the number of rows in a table
//var oRows = document.getElementById('MyTable').getElementsByTagName('tr');
//var iRowCount = oRows.length;
//alert('Your table has ' + iRowCount + ' rows.');
//-->
<!--Obtains the rowIndex in a table
//onload = function() {
//    if (!document.getElementsByTagName || !document.createTextNode) return;
//    var rows = document.getElementById('my_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
//    for (i = 0; i < rows.length; i++) {
//       rows[i].onclick = function() {
//            alert(this.rowIndex + 1);
//        }
//    }
//}
//-->
<!--Recalculates the basket totals on the javascript shop script (see Program Files/shop-20)
//function updateBasketView() {
//      for (x=0; x < brefs.length; x++) {
//         if (getProductIndex(brefs[x]) != -1) {
//            bqtys[x] = eval("document.form1.qtyin" + x + ".value");
//         } else {
//            brefs[x] = "foo";
//            bqtys[x] = 0;
//         }
//      }
//      cleanBasket();
//      setItems();
//      window.location = "basket-view.html";
//   }
//-->

