function updateRate(option, itemTotal){
  var option_value = "price" + option;
  var option_quantity = "quantity" + option;

  if (document.Form[option].checked == true){
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) - Number(document.Form[itemTotal].value);
    document.Form[itemTotal].value = Number(document.Form[itemTotal].value) + Number(document.Form[option_value].value);
    if (document.Form[itemTotal].value.indexOf(".") == "-1") {
		document.Form[itemTotal].value = document.Form[itemTotal].value + ".00";
	}
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) + Number(document.Form[itemTotal].value);
    if (document.Form.SUBTOTAL.value.indexOf(".") == "-1") {
		document.Form.SUBTOTAL.value = document.Form.SUBTOTAL.value + ".00";
	}
    document.Form[option_quantity].value = 1;
    
  } else {
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) - Number(document.Form[itemTotal].value);
    document.Form[itemTotal].value = Number(document.Form[itemTotal].value) - Number(document.Form[option_value].value);
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) + Number(document.Form[itemTotal].value);
    document.Form[option_quantity].value = Number(document.Form[option_quantity].value) - 1;
  }
  updateTotals();
}

function updateDinnerRate(option, itemTotal){
  var option_value = "price" + option; 
  var option_quantity = "quantity" + option;
  var option_subtotal = "subtotal" + option;


  if (document.Form[option].value != ""){
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) - Number(document.Form[itemTotal].value);
    document.Form[itemTotal].value = Number(document.Form[option].value) * Number(document.Form[option_value].value);
    if (document.Form[itemTotal].value.indexOf(".") == "-1") {
		document.Form[itemTotal].value = document.Form[itemTotal].value + ".00";
	}
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) + Number(document.Form[itemTotal].value);
    document.Form[option_quantity].value = Number(document.Form[option].value);
	document.Form[option_subtotal].value = Number(document.Form[itemTotal].value);
	if (document.Form[option_subtotal].value.indexOf(".") == "-1") {
		document.Form[option_subtotal].value = document.Form[option_subtotal].value + ".00";
	}
    if (document.Form.SUBTOTAL.value.indexOf(".") == "-1") {
		document.Form.SUBTOTAL.value = document.Form.SUBTOTAL.value + ".00";
	}
  } else {
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) - Number(document.Form[itemTotal].value);
    document.Form[itemTotal].value = 0;
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) + Number(document.Form[itemTotal].value);
    document.Form[option_quantity].value = 0;
    document.Form[option_subtotal].value = 0;
  }
  updateTotals();
}

function updateCheckedItems(option){
  var option_value = "price" + option; 
  var option_quantity = "quantity" + option;
  var display_value = "display" + option;

  if (document.Form[option].checked == true){ 
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) + Number(document.Form[option_value].value);
    document.Form[option_quantity].value = Number(document.Form[option_quantity].value) + 1;
    
    if (document.Form[display_value]){
      document.Form[display_value].value = Number(document.Form[option_value].value);
      	if (document.Form[display_value].value.indexOf(".") == "-1") {
			document.Form[display_value].value = document.Form[display_value].value + ".00";
		}

    }
    
  } else {
    document.Form.SUBTOTAL.value = Number(document.Form.SUBTOTAL.value) - Number(document.Form[option_value].value);
    document.Form[option_quantity].value = Number(document.Form[option_quantity].value) - 1;
    if (document.Form[display_value]){
      document.Form[display_value].value = 0;
    }
  }
  updateTotals();
}

function updateMemberType(option){
  var option_quantity = "quantity" + option;

  if (document.Form[option].checked == true){
    document.Form[option_quantity].value = Number(document.Form[option_quantity].value) + 1;
  } else {
    document.Form[option_quantity].value = Number(document.Form[option_quantity].value) - 1;
  }
  
  // Check if any of the check boxes at the top are checked
  if (checkMemberType()) {
	setGuestState(true);
  }
  else {
	setGuestState(false);
  }
}

function updateTotals(){
  // Update line below for GST rate changes.
  document.Form.GST.value = (Number(document.Form.SUBTOTAL.value) * 5) / 100;
  document.Form.TOTAL.value = ((Number(document.Form.SUBTOTAL.value) + Number(document.Form.GST.value) + 0.00)*100) / 100;
  todecimal();
  document.Form.gst.value = document.Form.GST.value;
  document.Form.charge_total.value = document.Form.TOTAL.value; 
}

function todecimal(){
  if (document.Form.GST.value.indexOf(".") == "-1"){
    document.Form.GST.value = document.Form.GST.value + ".00";
  }else if ((document.Form.GST.value.length - document.Form.GST.value.indexOf(".")) <= 2){
    document.Form.GST.value = document.Form.GST.value + "0";
  }
  if (document.Form.TOTAL.value.indexOf(".") == "-1"){
    document.Form.TOTAL.value = document.Form.TOTAL.value + ".00";
  }else if ((document.Form.TOTAL.value.length - document.Form.TOTAL.value.indexOf(".")) <= 2){
    document.Form.TOTAL.value = document.Form.TOTAL.value + "0";
  }
}


function SetFCode() {
	if (document.Form.bill_first_name.value == "") {
		alert("Vous devez inscrire un nom.");
		document.Form.bill_first_name.focus();
		return false;
	}
	if (document.Form.email.value == "") {
		alert("Vous devez inscrire une adresse de courriel");
		document.Form.email.focus();
		return false;
	}
	var re, d, n, s = "";
	n = document.Form.elements("bill_first_name").value;
	d = new Date();
	s += d.getYear();
	s += d.getMonth()+1;
	s += d.getDate()+"-";
	s += d.getHours();
	s += d.getMinutes()+"-";
	re = /\./gi;
	while (n.search(re)>0) {
		n = n.replace(re,"");
	}
	re = /\ /gi;
	while (n.search(re)>0) {
		n = n.replace(" ","-");
	}
	s += n;
	document.Form.elements("order_id").value = "CF"+s;
	return true;
}




function SetNCode() {
	if (document.Form.bill_first_name.value == "") {
		alert("You must enter in a Name.");
		document.Form.bill_first_name.focus();
		return false;
	}
	if (document.Form.email.value == "") {
		alert("You must enter in an E-Mail address.");
		document.Form.email.focus();
		return false;
	}
	var re, d, n, s = "";
	n = document.Form.elements("bill_first_name").value;
	d = new Date();
	s += d.getYear();
	s += d.getMonth()+1;
	s += d.getDate()+"-";
	s += d.getHours();
	s += d.getMinutes()+"-";
	re = /\./gi;
	while (n.search(re)>0) {
		n = n.replace(re,"");
	}
	re = /\ /gi;
	while (n.search(re)>0) {
		n = n.replace(" ","-");
	}
	s += n;
	//document.Form.elements("order_id").value = "CF"+s;
	return true;
}

function checkMemberType() {
	var lRtn = false;
	if (document.Form.CPRS.checked == true || document.Form.NONMEMB.checked == true || document.Form.GA.checked == true) {
		lRtn = true;
	}
	else {
		lRtn = false;
	}
	return lRtn;
}


// NOT BEING CALLED ANYMORE
function enableExtraTickets(obj) {
	var guestState = false;

	// If the Guest Name field is blank, disable all "Extra Tickets" options
	if (obj.value != "") {
		guestState = true;
	}
	
	if (guestState == true) {
		setGuestState(guestState);
	}
	else {
		setGuestState(guestState);
	}
}

function setGuestState(state) {
	// If state is False, disable all "Extra Ticket" options
	if (state == false) {
		//document.Form.MALL.disabled=true;
		//document.Form.displayMALL.disabled=true;
		document.Form.RJAMES.disabled=true;
		document.Form.RJAMES.value=0;
		updateDinnerRate("RJAMES", "displayRJAMES");
		document.Form.displayRJAMES.disabled=true;
		
		document.Form.DINNER8.disabled=true;
		document.Form.DINNER8.value=0;
		updateDinnerRate("DINNER8", "displayDINNER8");
		document.Form.displayDINNER8.disabled=true;
		
		document.Form.BREAKF9.disabled=true;
		document.Form.BREAKF9.value=0;
		updateDinnerRate("BREAKF9", "displayBREAKF9");
		document.Form.displayBREAKF9.disabled=true;
		
		document.Form.TISDALL9.disabled=true;
		document.Form.TISDALL9.value=0;
		updateDinnerRate("TISDALL9", "displayTISDALL9");
		document.Form.displayTISDALL9.disabled=true;
		
		document.Form.DINNER9.disabled=true;
		document.Form.DINNER9.value=0;
		updateDinnerRate("DINNER9", "displayDINNER9");
		document.Form.displayDINNER9.disabled=true;
		
		document.Form.BREAKF10.disabled=true;
		document.Form.BREAKF10.value=0;
		updateDinnerRate("BREAKF10", "displayBREAKF10");
		document.Form.displayBREAKF10.disabled=true;		
		
		document.Form.HILLIER.disabled=true;
		document.Form.HILLIER.value=0;
		updateDinnerRate("HILLIER", "displayHILLIER");
		document.Form.displayHILLIER.disabled=true;
		
		document.Form.GALA.disabled=true;
		document.Form.GALA.value=0;
		updateDinnerRate("GALA", "displayGALA");
		document.Form.displayGALA.disabled=true;
	}
	// Enable all "Extra Tickets" options
	else {
		//document.Form.MALL.disabled=false;
		//document.Form.displayMALL.disabled=false;
		document.Form.RJAMES.disabled=false;
		document.Form.displayRJAMES.disabled=false;
		document.Form.DINNER8.disabled=false;
		document.Form.displayDINNER8.disabled=false;
		document.Form.BREAKF9.disabled=false;
		document.Form.displayBREAKF9.disabled=false;
		document.Form.TISDALL9.disabled=false;
		document.Form.displayTISDALL9.disabled=false;
		document.Form.DINNER9.disabled=false;
		document.Form.displayDINNER9.disabled=false;
		document.Form.BREAKF10.disabled=false;
		document.Form.displayBREAKF10.disabled=false;		
		document.Form.HILLIER.disabled=false;
		document.Form.displayHILLIER.disabled=false;
		document.Form.GALA.disabled=false;
		document.Form.displayGALA.disabled=false;
	}
}



