var grandtotal;

function setotherBank() {
	var frm = document.TheForm
	
	if (frm.lcbank.value == "OTHER") {
		frm.otherbankname.style.visibility = "visible"
	}
	else {
		frm.otherbankname.style.visibility = "hidden"
	}
}

function setotherBank_draft() {
	var frm = document.TheForm
	
	if (frm.bank.value == "OTHER") {
		frm.otherbankname_draft.style.visibility = "visible"
	}
	else {
		frm.otherbankname_draft.style.visibility = "hidden"
	}
}

function on_delegate_type() {
	var frm = document.TheForm
	
	for (i=0;i<5;i++)
	{
		frm.delegate_type[i].disabled = false
	}
}

function off_delegate_type() {
	var frm = document.TheForm
	
	for (i=0;i<5;i++)
	{
		frm.delegate_type[i].disabled = true
	}
}


function set_conference() {
	var frm = document.TheForm
	
	// reset the value
	frm.txt_full_standart.value = "0"
	frm.txt_full_associates.value = "0"
	frm.txt_full_student.value = "0"
	frm.txt_main_standart.value = "0"
	frm.txt_main_associates.value = "0"
	frm.txt_main_student.value = "0"
	frm.txt_day_reg.value = "0"
	
	// active all component
	for (i=0;i<3;i++)
	{
		frm.day_reg[i].disabled = false
	}



	for (i=0;i<3;i++)
	{
		frm.day_reg[i].checked = false
	}
	
	
	// initialization
	if (frm.conference[3].checked)
	{
		frm.txt_full_standart.value = frm.price_full_conference_standart.value

		// non active some component
		for (i=0;i<3;i++)
		{
			frm.day_reg[i].disabled = true
		}
		frm.workshop1[0].disabled = true
		frm.workshop1[1].disabled = true
		frm.workshop1[2].disabled = true
		
		frm.workshop2[0].disabled = true
		frm.workshop2[1].disabled = true
		frm.workshop2[2].disabled = true
		
		off_delegate_type()
	}
	else if (frm.conference[4].checked)
	{
		frm.txt_full_associates.value = frm.price_full_conference_associates.value

		// non active some component
		for (i=0;i<3;i++)
		{
			frm.day_reg[i].disabled = true
		}
		frm.workshop1[0].disabled = true
		frm.workshop1[1].disabled = true
		frm.workshop1[2].disabled = true
		
		frm.workshop2[0].disabled = true
		frm.workshop2[1].disabled = true
		frm.workshop2[2].disabled = true
		
		on_delegate_type()
	}
	else if (frm.conference[5].checked)
	{
		frm.txt_full_student.value = frm.price_full_conference_student.value

		// non active some component
		for (i=0;i<3;i++)
		{
			frm.day_reg[i].disabled = true
		}
		frm.workshop1[0].disabled = true
		frm.workshop1[1].disabled = true
		frm.workshop1[2].disabled = true
		
		frm.workshop2[0].disabled = true
		frm.workshop2[1].disabled = true
		frm.workshop2[2].disabled = true
		
		off_delegate_type()
	}
	else if (frm.conference[0].checked)
	{
		frm.txt_main_standart.value = frm.price_main_conference_standart.value
		
		// non active some component
		for (i=0;i<3;i++)
		{
			frm.day_reg[i].disabled = true
			frm.workshop1[i].disabled = false
			frm.workshop2[i].disabled = false
		}
		
		off_delegate_type()
	}
	else if (frm.conference[1].checked)
	{
		frm.txt_main_associates.value = frm.price_main_conference_associates.value
		
		// non active some component
		for (i=0;i<3;i++)
		{
			frm.day_reg[i].disabled = true
			frm.workshop1[i].disabled = false
			frm.workshop2[i].disabled = false
		}
		
		on_delegate_type()
	}
	else if (frm.conference[2].checked)
	{
		frm.txt_main_student.value = frm.price_main_conference_student.value
		
		// non active some component
		for (i=0;i<3;i++)
		{
			frm.day_reg[i].disabled = true
			frm.workshop1[i].disabled = false
			frm.workshop2[i].disabled = false
		}
		
		off_delegate_type()
	}
	
	
	/*
	for (i=0;i<3;i++)
	{
		frm.day_reg[i].disabled = true
	}
	frm.workshop1.disabled = true
	frm.workshop2.disabled = true
	frm.conference_dinner.disabled = true
	*/
	
	check_main_plus_workshop()
	
	total_amount()
}

function set_day_registration() {
	var frm = document.TheForm
	
	for (i=0;i<6;i++)
	{
		frm.conference[i].disabled = true	
	}

	frm.txt_full_standart.value = "0"
	frm.txt_full_associates.value = "0"
	frm.txt_full_student.value = "0"
	frm.txt_main_standart.value = "0"
	frm.txt_main_associates.value = "0"
	frm.txt_main_student.value = "0"
	frm.txt_day_reg.value = "0"
	
	frm.txt_conference_dinner.value = "0"
	
	// initialization
	frm.txt_day_reg.value = frm.price_day_registration.value
	
	total_amount()
}

function set_workshop1() {
	var frm = document.TheForm
	
	for (i=3;i<6;i++)
	{
		frm.conference[i].disabled = true	
	}
	frm.txt_full_standart.value = "0"
	frm.txt_full_associates.value = "0"
	frm.txt_full_student.value = "0"
	frm.txt_workshop1.value = "0"

	frm.txt_workshop1.value = frm.price_pre_conference_workshop1.value
	
	check_main_plus_workshop()

	total_amount()
}

function set_workshop2() {
	var frm = document.TheForm
	
	for (i=3;i<6;i++)
	{
		frm.conference[i].disabled = true	
	}
	frm.txt_full_standart.value = "0"
	frm.txt_full_associates.value = "0"
	frm.txt_full_student.value = "0"
	frm.txt_workshop2.value = "0"

	frm.txt_workshop2.value = frm.price_pre_conference_workshop2.value

	check_main_plus_workshop()

	total_amount()
}

function check_main_plus_workshop() {
	var frm = document.TheForm
	
	if ((frm.conference[0].checked || frm.conference[1].checked) || frm.conference[2].checked) {
		if ((frm.workshop1[0].checked || frm.workshop1[1].checked) || frm.workshop1[2].checked) {
			if ((frm.workshop2[0].checked || frm.workshop2[1].checked) || frm.workshop2[2].checked) {
				temp_flag = 0;
				if (frm.conference[0].checked) {
					temp_flag = 1;
				}
				else if (frm.conference[1].checked) {
					temp_flag = 2;
				}
				else if (frm.conference[2].checked) {
					temp_flag = 3;
				}

				reset_selection()
				
				for (i=0;i<3;i++)
				{
					frm.conference[i].disabled = true	
					frm.day_reg[i].disabled = true
					frm.workshop1[i].disabled = true
					frm.workshop2[i].disabled = true
				}
				
				if (temp_flag == 1) {
					frm.conference[3].checked = true
					frm.txt_full_standart.value = frm.price_full_conference_standart.value
				}
				else if (temp_flag == 2) {
					frm.conference[4].checked = true
					frm.txt_full_associates.value = frm.price_full_conference_associates.value
				}
				else if (temp_flag == 3) {
					frm.conference[5].checked = true
					frm.txt_full_student.value = frm.price_full_conference_student.value
				}
			}
		}
	}
}

function set_conference_dinner() {
	var frm = document.TheForm
	
	frm.txt_conference_dinner.value = "0"

	if (frm.conference_dinner.checked)
	{
		frm.txt_conference_dinner.value = parseInt(frm.price_conference_dinner.value) * parseInt(frm.confdinner_qty.options[frm.confdinner_qty.selectedIndex].value)
	}
	else
	{
		frm.txt_conference_dinner.value = "0"
	}
	
	total_amount()
}


function reset_selection() {
	var frm = document.TheForm
	
	for (i=0;i<6;i++)
	{
		frm.conference[i].disabled = false	
		frm.conference[i].checked = false
	}
	for (i=0;i<3;i++)
	{
		frm.day_reg[i].disabled = false	
		frm.workshop1[i].disabled = false
		frm.workshop2[i].disabled = false

		frm.day_reg[i].checked = false	
		frm.workshop1[i].checked = false
		frm.workshop2[i].checked = false
	}
	frm.conference_dinner.disabled = false
	frm.conference_dinner.checked = false
	
	frm.txt_full_standart.value = "0"
	frm.txt_full_associates.value = "0"
	frm.txt_full_student.value = "0"
	frm.txt_main_standart.value = "0"
	frm.txt_main_associates.value = "0"
	frm.txt_main_student.value = "0"
	frm.txt_day_reg.value = "0"
	frm.txt_workshop1.value = "0"
	frm.txt_workshop2.value = "0"
	frm.txt_conference_dinner.value = "0"
	frm.confdinner_qty.value = "1"
	
	total_amount()
}

function total_amount()
{
	var frm = document.TheForm
	var total;
	var temp;
	
	total = 0;
	
	total = total + parseFloat(frm.txt_full_standart.value) + parseFloat(frm.txt_full_associates.value) + parseFloat(frm.txt_full_student.value) + parseFloat(frm.txt_main_standart.value) + parseFloat(frm.txt_main_associates.value) + parseFloat(frm.txt_main_student.value)
	total = total + parseFloat(frm.txt_day_reg.value) + parseFloat(frm.txt_workshop1.value) + parseFloat(frm.txt_workshop2.value) + parseFloat(frm.txt_conference_dinner.value)
	
	//total = (total + parseFloat(frm.price_admin_fee.value) + (total *  parseFloat(frm.price_admin_charge_percent.value))) * parseFloat(frm.price_fx_rate.value)
	//if (total == 50) { total = 0 }
	frm.grandtotal.value = total
	grandtotal = total
	
	if (frm.pay_option[0].checked)
	{
		temp_total = (grandtotal *  (1+parseFloat(frm.price_admin_charge_percent.value))) * parseFloat(frm.price_fx_rate.value)
		frm.cc_gtotal.value = grandtotal
		frm.authorised_amt_sgd.value = temp_total
	}
	else if (frm.pay_option[1].checked)
	{
		frm.lccheque_amt.value = grandtotal
	}
	else if (frm.pay_option[2].checked)
	{
		frm.cheque_amt.value = grandtotal + parseFloat(frm.price_admin_fee.value)
	}
}

function payment() {
	var frm = document.TheForm
	
	frm.cc_gtotal.value = "0"
	frm.authorised_amt_sgd.value = "0"
	frm.lccheque_amt.value = "0"
	frm.cheque_amt.value = "0"
	
	if (frm.pay_option[0].checked)
	{
		total = (grandtotal *  (1+parseFloat(frm.price_admin_charge_percent.value))) * parseFloat(frm.price_fx_rate.value)
		frm.cc_gtotal.value = grandtotal
		frm.authorised_amt_sgd.value = total
		frm.lccheque_no.value = ""
		frm.cheque_no.value = ""
		frm.lcbank.value = ""
		frm.bank.value = ""
	}
	else if (frm.pay_option[1].checked)
	{
		frm.lccheque_amt.value = grandtotal
		frm.cheque_no.value = ""
		frm.bank.value = ""
		
		// erase cc
		frm.cc_name.value = ""
		frm.cc_no1.value = ""
		frm.cc_no2.value = ""
		frm.cc_no3.value = ""
		frm.cc_no4.value = ""
		frm.cc_mm.value = ""
		frm.cc_yy.value = ""
		frm.cc_id.value = ""
	}
	else if (frm.pay_option[2].checked)
	{
		frm.cheque_amt.value = grandtotal + parseFloat(frm.price_admin_fee.value)
		frm.lccheque_no.value = ""
		frm.lcbank.value = ""

		// erase cc
		frm.cc_name.value = ""
		frm.cc_no1.value = ""
		frm.cc_no2.value = ""
		frm.cc_no3.value = ""
		frm.cc_no4.value = ""
		frm.cc_mm.value = ""
		frm.cc_yy.value = ""
		frm.cc_id.value = ""
	}
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}

function verifyRegForm()
{
  var frm = document.TheForm

  if (document.TheForm.salutation.value.length == 0) {
	alert("Please select the title.");
	document.TheForm.salutation.focus();
	return false;
  }

  if (document.TheForm.firstname.value.length == 0) {
	alert("Please enter your first name.");
	document.TheForm.firstname.focus();
	return false;
  }

  if (document.TheForm.lastname.value.length == 0) {
	alert("Please enter your last name.");
	document.TheForm.lastname.focus();
	return false;
  }

  if (document.TheForm.company.value.length == 0) {
	alert("Please enter your company name.");
	document.TheForm.company.focus();
	return false;
  }

  if (document.TheForm.designation.value.length == 0) {
	alert("Please enter your designation.");
	document.TheForm.designation.focus();
	return false;
  }

  if (document.TheForm.address.value.length == 0) {
	alert("Please enter your mailing address.");
	document.TheForm.address.focus();
	return false;
  }


  if (document.TheForm.city.value.length == 0) {
	alert("Please enter the city name.");
	document.TheForm.city.focus();
	return false;
  }

  if (document.TheForm.zip.value.length == 0) {
	alert("Please enter the zip code.");
	document.TheForm.zip.focus();
	return false;
  }

  if (document.TheForm.country.value.length == 0) {
	alert("Please select your country.");
	document.TheForm.country.focus();
	return false;
  }

  if (document.TheForm.tel_cc.value.length == 0) {
	alert("Please select your telephone number country code.");
	document.TheForm.tel_cc.focus();
	return false;
  }
  fldValue = TheForm.tel_cc.value;
	//  if ( fldValue != parseInt(fldValue) )
	if (isNumeric (fldValue) != true)
  {
	alert('Please enter the country code in numeric values only.');
	document.TheForm.tel_cc.focus();
	return false;
  }

  if (document.TheForm.tel_ac.value.length != 0) {
  fldValue = TheForm.tel_ac.value;
  //if ( fldValue != parseInt(fldValue) )
  if (isNumeric (fldValue) != true)
  {
	alert('Please enter the area code in numeric values only.');
	document.TheForm.tel_ac.focus();
	return false;
  }
  }

  if (document.TheForm.tel_no.value.length == 0) {
	alert("Please enter your telephone number.");
	document.TheForm.tel_no.focus();
	return false;
  }
  fldValue = TheForm.tel_no.value;
  //if ( fldValue != parseInt(fldValue) )
  if (isNumeric (fldValue) != true)
  {
	alert('Please enter the telephone number in numeric values only.');
	document.TheForm.tel_no.focus();
	return false;
  }

  if (document.TheForm.fax_cc.value.length == 0) {
	alert("Please select your fax number country code.");
	document.TheForm.fax_cc.focus();
	return false;
  }
  fldValue = TheForm.fax_cc.value;
  if (isNumeric (fldValue) != true)
  {
	alert('Please enter the fax country code in numeric values only.');
	document.TheForm.fax_cc.focus();
	return false;
  }

  if (document.TheForm.fax_ac.value.length != 0) {
  fldValue = TheForm.fax_ac.value;
  if (isNumeric (fldValue) != true)
  {
	alert('Please enter the fax area code in numeric values only.');
	document.TheForm.fax_ac.focus();
	return false;
  }
  }


  if (document.TheForm.fax_no.value.length == 0) {
	alert("Please enter your fax number.");
	document.TheForm.fax_no.focus();
	return false;
  }
  fldValue = TheForm.fax_no.value;
  if (isNumeric (fldValue) != true)
  {
	alert('Please enter the fax number in numeric values only.');
	document.TheForm.fax_no.focus();
	return false;
  }

  if (document.TheForm.email.value.length == 0) {
	alert("Please enter your email address.");
	document.TheForm.email.focus();
	return false;
  } else
  	{
  		if (document.TheForm.email.value.charAt(0) == " ")
  		{
  		  alert("The first character of Email field cannot be space.");
		  document.TheForm.email.focus();
   		  return false;
   		} else
   		    {
   		     	var email_v = document.TheForm.email.value;
		    	if (email_v.search('@') == -1) {
		     	   alert("Invalid Email Address without '@'.");
		           document.TheForm.email.focus();
		           return false;
			}
   		    }
  	}
/*
  if (frm.delegate_class_rb[0].checked == false && frm.delegate_class_rb[1].checked == false 
  && frm.delegate_class_rb[2].checked == false && frm.aperson_cb.checked == false 
  && frm.plenary30052004_cb.checked == false && frm.plenary31052004_cb.checked == false 
  && frm.teaching01062004_cb.checked == false && frm.teaching02062004_cb.checked == false 
  && frm.teaching03062004_cb.checked == false)
  {
  	alert("Please select a Full Conference item or Day Rated Conference item for registration.");
  	frm.conf_type_rb[0].focus();
  	return false;
  }
*/

	if (document.TheForm.conference[1].checked == true || document.TheForm.conference[4].checked == true)
	{
		if (document.TheForm.delegate_type[0].checked == false && document.TheForm.delegate_type[1].checked == false && document.TheForm.delegate_type[2].checked == false && document.TheForm.delegate_type[3].checked == false && document.TheForm.delegate_type[4].checked == false)
		{
			alert("Please choose your Delegate Type.");
			document.TheForm.delegate_type[0].focus();
			return false;
		}
	}
	
  
  if (document.TheForm.food_pref[0].checked == false && document.TheForm.food_pref[1].checked == false && document.TheForm.food_pref[2].checked == false)
  {
	alert("Please choose your Food Preference.");
	document.TheForm.food_pref[0].focus();
	return false;
  }

/*
	if (document.TheForm.tour_pref[0].checked == false && document.TheForm.tour_pref[1].checked == false)
  	  {
		alert("Please choose your Tour Preference.");
		document.TheForm.tour_pref[0].focus();
		return false;
  	  }
*/

  if (document.TheForm.pay_option[0].checked == false && document.TheForm.pay_option[1].checked == false && document.TheForm.pay_option[2].checked == false)
  {
   	alert("Please select one of the payment method.");
   	document.TheForm.pay_option[0].focus();
   	return false;
  }


  if (document.TheForm.pay_option[0].checked)
  {
  	var frm = document.TheForm

  	if (document.TheForm.cc_type[0].checked == false && document.TheForm.cc_type[1].checked == false && document.TheForm.cc_type[2].checked == false)
  	{
  	   alert("Please select the type of credit card that you are using.");
  	   document.TheForm.cc_type[0].focus();
  	   return false;
  	}

  	if (document.TheForm.cc_name.value.length == 0)
  	{
  	   alert("Please enter the credit card holder's name.");
  	   document.TheForm.cc_name.focus();
  	   return false;
  	}

  	if (check_cc() == false)
  	{
  	  return false;
  	}

	if (document.TheForm.cc_mm.value.length == 0) {
		alert("Please select the month of the expiry date.");
		document.TheForm.cc_mm.focus();
		return false;
	}

	if (document.TheForm.cc_yy.value.length == 0) {
		alert("Please select the year of the expiry date.");
		document.TheForm.cc_yy.focus();
		return false;
	}
  }
  else if (document.TheForm.pay_option[1].checked)
  {
    	var frm = document.TheForm
  	if (frm.lccheque_no.value.length == 0)
  	{
		alert("Please enter the Cheque number.");
		frm.lccheque_no.focus();
		return false;
  	}

    	if (frm.lcbank.value == "")
    	{
  		alert("Please select a bank from the list.");
  		frm.lcbank.focus();
  		return false;
  	}
  }
  else if (document.TheForm.pay_option[2].checked)
  {
    	var frm = document.TheForm
  	if (frm.cheque_no.value.length == 0)
  	{
		alert("Please enter the Cheque number.");
		frm.cheque_no.focus();
		return false;
  	}

    	if (frm.bank.value.length == 0)
    	{
  		alert("Please select a bank from the list.");
  		frm.bank.focus();
  		return false;
  	}

  }

  return true;
}
