//****************************************************
// returns the amount in the .99 format
//****************************************************
function cent(amount) {
  amount -= 0;
  return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

//**********************************************************
// returns a number rounded to 2 decimal places
//**********************************************************
function round(number) {
  var X
  X = (!X ? 2 : X);
  return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function calcPackageFees() {


//alert("got here");

 if (document.frmPurchase.package[0].checked)
 {
	document.frmPurchase.subtotal.value = "" + cent(150);
 }
 if (document.frmPurchase.package[1].checked)
 {
	document.frmPurchase.subtotal.value = "" + cent(400);
 }
 if (document.frmPurchase.package[2].checked)
 {
	document.frmPurchase.subtotal.value = "" + cent(650);
 } 
 if (document.frmPurchase.package[3].checked)
 {
	document.frmPurchase.subtotal.value = "" + cent(995);
 } 
 if (document.frmPurchase.package[4].checked)
 {
	document.frmPurchase.subtotal.value = "" + cent(2995);
 }  
 if (document.frmPurchase.package[5].checked)
 {
	document.frmPurchase.subtotal.value = "" + cent(4995);
 }   
 TotalCost();
}




//****************************************************************************
// Calculates the total of all conference fees
// Then call the necessary functions to calculate the total cost!
//****************************************************************************
function TotalCost() {
 
 var SubTotal
 var tax
 var Total
 var gst, hst, qst, hstbc, hstns, fees1
 //gst = 12.0
 
 
 gst = 5.0
 hst = 13.0
 qst = 8.5
 hstbc = 12.0
 hstns = 15.00
 
 
 
 SubTotal = (document.frmPurchase.subtotal.value - 0) ;
 //document.frmPurchase.subtotal.value = "" + cent(SubTotal);
 
 fees1 = (document.frmPurchase.subtotal.value - 0);
 
 
  // 13% HST is applicable in Newfoundland and New Brunswick ONLY
		 if (document.frmPurchase.province.value=="Newfoundland"  || document.frmPurchase.province.value=="New Brunswick" || document.frmPurchase.province.value=="Ontario") {
		  
		   tax = fees1 / 100 * hst;
		   tax = Math.floor(tax * 1000)/1000;
		   document.frmPurchase.gst.value = "" + cent(round(tax));
		   document.frmPurchase.displayGST.value = hst;
		   
		   // 12% HST in BC
		 } else if (document.frmPurchase.province.value=="British Columbia") {
		 
		   tax = fees1 / 100 * hstbc;
		   tax = Math.floor(tax * 1000)/1000;
		   document.frmPurchase.gst.value = "" + cent(round(tax));
		   
		   document.frmPurchase.displayGST.value = hstbc;
		   
		   // 15% HST in Nova Scotia
		 } else if (document.frmPurchase.province.value=="Nova Scotia") {
		 
		   tax = fees1 / 100 * hstns;
		   tax = Math.floor(tax * 1000)/1000;
		   document.frmPurchase.gst.value = "" + cent(round(tax));
		   
		   document.frmPurchase.displayGST.value = hstns;
		   
		 // 5% HST in Quebec + 8.5%
		 //} else if (document.frmPurchase.province.value=="QC") {
		 
		  // tax = fees1 / 100 * gst;
		   //subtax = Math.floor(tax * 1000)/1000;
		   //fees1 = fees1 + subtax
		   
		   // Now calculate the 8.5% QST AFTER GST has been added.
		   //tax = fees1 / 100 * qst;
		   //tax = Math.floor(tax * 1000)/1000;
		   //tax = tax + subtax
		   
		   //document.frmPurchase.gst.value = "" + cent(round(tax));
		 
		 		 
		 
		 } else {
		   // figure out the tax
		   tax = fees1 / 100 * gst;
		   tax = Math.floor(tax * 1000)/1000;
		   document.frmPurchase.gst.value = "" + cent(round(tax));
		   document.frmPurchase.displayGST.value = gst;
		 }
 
 
 
 // figure out the tax
  //tax = SubTotal / 100 * gst;
  //tax = Math.floor(tax * 1000)/1000;
  //document.frmPurchase.gst.value = "" + cent(round(tax));

 //now get the total
 Total = (cent(round(tax))-0) + SubTotal
 document.frmPurchase.total.value = cent(round(Total));
 //document.frmPurchase.total.value = "" + formatCurrency(SubTotal);
}

