// JavaScript Document for Hydrogels 2009

function page_load()
{	
	//document.getElementById("IIRA_number").style.display = "none";
	//document.getElementById("Student_number").style.display = "none";
	//document.getElementById("Accom_person").style.display = "none";
	//document.getElementById("creditcard").style.display = "none";
	//document.getElementById("cheque").style.display = "none";
	//document.getElementById("invoice").style.display = "none";	
	//document.getElementById("AccomForm").style.display = "none";
//	document.getElementById("accommodation_days").style.display = "none";
	
	checkdate();
	refreshPage();
	
	//calculateCost();
}

function checkdate()
{
	var now = new Date();
	var cut_off = new Date();
	var cut_off2 = new Date();
	
	cut_off.setDate(01);
	cut_off.setMonth(02); //February!
	cut_off.setYear(2010);
	
	cut_off2.setDate(01);
	cut_off2.setMonth(03); //March!
	cut_off2.setYear(2010);
	
	if(now < cut_off)
	{
		//Before 28-02-2010
		document.reg.RegistrationType[0].disabled = false;
		document.reg.RegistrationType[3].disabled = false;
		document.reg.RegistrationType[6].disabled = false;
		document.reg.RegistrationType[9].disabled = false;
		//Before 31/03/2010
		document.reg.RegistrationType[1].disabled = true;
		document.reg.RegistrationType[4].disabled = true;
		document.reg.RegistrationType[7].disabled = true;
		document.reg.RegistrationType[10].disabled = true;
		//After 31/03/2010
		document.reg.RegistrationType[2].disabled = true;
		document.reg.RegistrationType[5].disabled = true;
		document.reg.RegistrationType[8].disabled = true;
		document.reg.RegistrationType[11].disabled = true;
	}
	
	else if(now < cut_off2)
	{
		//Before 28-02-2010
		document.reg.RegistrationType[0].disabled = true;
		document.reg.RegistrationType[3].disabled = true;
		document.reg.RegistrationType[6].disabled = true;
		document.reg.RegistrationType[9].disabled = true;
		//Before 31/03/2010
		document.reg.RegistrationType[1].disabled = false;
		document.reg.RegistrationType[4].disabled = false;
		document.reg.RegistrationType[7].disabled = false;
		document.reg.RegistrationType[10].disabled = false;
		//After 31/03/2010
		document.reg.RegistrationType[2].disabled = true;
		document.reg.RegistrationType[5].disabled = true;
		document.reg.RegistrationType[8].disabled = true;
		document.reg.RegistrationType[11].disabled = true;
	}	
	
	else
	{
		//Before 28-02-2010
		document.reg.RegistrationType[0].disabled = true;
		document.reg.RegistrationType[3].disabled = true;
		document.reg.RegistrationType[6].disabled = true;
		document.reg.RegistrationType[9].disabled = true;
		//Before 31/03/2010
		document.reg.RegistrationType[1].disabled = true;
		document.reg.RegistrationType[4].disabled = true;
		document.reg.RegistrationType[7].disabled = true;
		document.reg.RegistrationType[10].disabled = true;
		//After 31/03/2010
		document.reg.RegistrationType[2].disabled = false;
		document.reg.RegistrationType[5].disabled = false;
		document.reg.RegistrationType[8].disabled = false;
		document.reg.RegistrationType[11].disabled = false;
	}
}

function refreshPage()
{
	showFields();
	calculateCost();
	return;
	
}

function showFields()
{
	/* When you give multiple items the same name in the DOM (Document Object Model) they are treated as a zero indexed array.
	What this means is that the first item can be found with name[0] the second with name[1], etc. The order is defined by where
	they appear in the html so you should be able to work out the indexes */
/*	if (document.reg.RegistrationType[0].checked)
	{
		document.reg.AccompanyRegistrationType[4].checked = false;
		document.reg.AccompanyRegistrationType[4].disabled = true;

		document.reg.AccompanyRegistrationType[2].disabled = false;
	}
	else if (document.reg.RegistrationType[1].checked)
	{
		document.reg.AccompanyRegistrationType[5].checked = false;
		document.reg.AccompanyRegistrationType[5].disabled = true;

		document.reg.AccompanyRegistrationType[3].disabled = false;
	}
	else if (document.reg.RegistrationType[2].checked)
	{
		document.reg.AccompanyRegistrationType[2].checked = false;
		document.reg.AccompanyRegistrationType[2].disabled = true;

		document.reg.AccompanyRegistrationType[4].disabled = false;
	}
	else if (document.reg.RegistrationType[3].checked)
	{
		document.reg.AccompanyRegistrationType[3].checked = false;
		document.reg.AccompanyRegistrationType[3].disabled = true;

		document.reg.AccompanyRegistrationType[5].disabled = false;
	}	
	
	if(document.reg.AccompanyRegistrationType[0].checked || document.reg.AccompanyRegistrationType[1].checked)
	{
		document.reg.NumAccompanyingPersons.disabled = true;
		document.reg.AccompanyPersonNames.disabled = true;
		//document.reg.AccompanyTitle.disabled = true;
		//document.reg.AccompanyFirstName.disabled = true;
		//document.reg.AccompanyLastName.disabled = true;
		document.reg.AccompanySpecialRequirements.disabled = true;
	}
	else
	{
		document.reg.NumAccompanyingPersons.disabled = false;
		document.reg.AccompanyPersonNames.disabled = false;
		//document.reg.AccompanyTitle.disabled = false;
		//document.reg.AccompanyFirstName.disabled = false;
		//document.reg.AccompanyLastName.disabled = false;
		document.reg.AccompanySpecialRequirements.disabled = false;
	}
/*	else if(document.reg.RegistrationType[4].checked || document.reg.RegistrationType[5].checked)
	{
		//document.reg.SingleDayDinner.checked = false;
		document.reg.SingleDayDinner.disabled = false;
		//document.reg.Guest.checked = false;
		document.reg.Guest.disabled = false;		
	}
*/
/*	else
	{			
		document.reg.SingleDayDinner.disabled = false;
	}
*/

	/*if (reg.Member.value == "Yes")
	{
		reg.Invitedby.disabled = true;
		reg.Invitedby.value = "";
	}
	else
	{
		reg.Invitedby.disabled = false;
	}*/
	
	showPaymentFields();
	
}

function calculateCost()
{
	var total_cost = 0;
	//var accompanyingPersonsCost = 0;
	//var dinnerGuest = 0;
	var accommodationFee = 0;
	var roomCost = 0;
	var noOfNights = 0;
	var noOfRooms = 0;
	var dinner = 0;
	//var liverpool = 0;
	//var tourCost = 0;
	
	with(document)
	{
		/* Registration Costs */
		if (reg.RegistrationType[0].checked)
		{
			total_cost += 240
		}
		else if (reg.RegistrationType[1].checked)
		{
			total_cost += 270
		}
		else if (reg.RegistrationType[2].checked)
		{
			total_cost += 320
		}
		else if (reg.RegistrationType[3].checked)
		{
			total_cost += 320
		}
		else if (reg.RegistrationType[4].checked)
		{
			total_cost += 370
		}
		else if (reg.RegistrationType[5].checked)
		{
			total_cost += 420
		}
		else if (reg.RegistrationType[6].checked)
		{
			total_cost += 320
		}
		else if (reg.RegistrationType[7].checked)
		{
			total_cost += 370
		}
		else if (reg.RegistrationType[8].checked)
		{
			total_cost += 420
		}
		else if (reg.RegistrationType[9].checked)
		{
			total_cost += 370
		}
		else if (reg.RegistrationType[10].checked)
		{
			total_cost += 420
		}
		else if (reg.RegistrationType[11].checked)
		{
			total_cost += 470
		}		


		/* Conference dinner 
		if (reg.ConfDinner.checked == true)
		{
			dinner += 15;	
		}*/
		
		
		/* Visit Liverpool 
		if (reg.VisitLiverpool.checked == true)
		{
			liverpool += 10;	
		}		*/


		/*Conference dinner guest
		if (reg.DinnerGuest.checked == true)
		{
			dinnerGuest += 70;	
		}*/


		/* plus accompanying registration cost 
		if (reg.AccompanyRegistrationType[2].checked)
		{
			accompanyingPersonsCost += 365 * reg.NumAccompanyingPersons.value;
		}
		else if (reg.AccompanyRegistrationType[3].checked)
		{
			accompanyingPersonsCost += 395 * reg.NumAccompanyingPersons.value;
		}
		else if (reg.AccompanyRegistrationType[4].checked)
		{
			accompanyingPersonsCost += 265 * reg.NumAccompanyingPersons.value;
		}		
		else if (reg.AccompanyRegistrationType[5].checked)
		{
			accompanyingPersonsCost += 285 * reg.NumAccompanyingPersons.value;
		}
		
		total_cost += accompanyingPersonsCost;*/


		//getElementById("RegSubCost").value = "£" + total_cost;
		/* room cost */
		if (reg.AccomType[0].checked == true)
		{
			roomCost += 0; //No Accommodation
		}
		else if (reg.AccomType[1].checked == true)
		{
			roomCost += 29.50; //Halls
		}
		else if (reg.AccomType[2].checked == true)
		{
			roomCost += 36.50;
		}
		else if (reg.AccomType[3].checked == true)
		{
			roomCost += 39.50;
		}
		else if (reg.AccomType[4].checked == true)
		{
			roomCost += 50; //Hotels
		}
		else if (reg.AccomType[5].checked == true)
		{
			roomCost += 55;
		}
		else if (reg.AccomType[6].checked == true)
		{
			roomCost += 60;
		}
		else if (reg.AccomType[7].checked == true)
		{
			roomCost += 60;
		}
		else if (reg.AccomType[8].checked == true)
		{
			roomCost += 70;
		}
		else if (reg.AccomType[9].checked == true)
		{
			roomCost += 87;
		}
		else if (reg.AccomType[10].checked == true)
		{
			roomCost += 97;
		}
				
		/* number of nights */
		if (reg.Aug31.checked == true)
		{
			noOfNights++;
		}
		if (reg.Sep01.checked == true)
		{
			noOfNights++;
		}
		if (reg.Sep02.checked == true)
		{
			noOfNights++;
		}
		if (reg.Sep03.checked == true)
		{
			noOfNights++;
		}
		if (reg.Sep04.checked == true)
		{
			noOfNights++;
		}
		if (reg.Sep05.checked == true)
		{
			noOfNights++;
		}
		
		/* Number of rooms needed */
		<!--noOfRooms = reg.NumRoomsWanted.value;
		

		
		
		/* Pre and post conference tour and number of people 
		if (reg.IrelandTour.checked == true)
		{
			tourCost += 225 * reg.NumAttendeesIrelandTour.value;	
		}
		
		if (reg.EnglandTour.checked == true)
		{
			tourCost += 565 * reg.NumAttendeesEnglandTour.value;
		}*/
		
		//tourFee = tourCost * noOfAttendees;
		
		accommodationFee = roomCost * noOfNights;
		
		total_cost += accommodationFee += dinner;
		
		//if(reg.AccType.checked)
		//{
			//total_cost += accommodationFee;
		//}		
		//getElementById("RegSubCost").value = "£" + accommodationFee;
		//total_cost = total_cost.toFixed(2)
		
		getElementById("TotalCost").value = total_cost ;
	}
}

function showPaymentFields()
{
	with(document)
	{
		if(reg.payment_choice[0].checked)
		{
			getElementById("creditcard").style.display = "";
			getElementById("creditcard").disabled = false;
		}
		else
		{
			getElementById("creditcard").style.display = "none";
			getElementById("creditcard").disabled = true;
		}
		
		if(reg.payment_choice[1].checked)
		{
			getElementById("cheque").style.display = "";
			getElementById("cheque").disabled = false;
		}
		else
		{
			getElementById("cheque").style.display = "none";
			getElementById("cheque").disabled = true;
		}
		
		if(reg.payment_choice[2].checked)
		{
			getElementById("invoice").style.display = "";
			getElementById("invoice").disabled = false;
		}
		else
		{
			getElementById("invoice").style.display = "none";
			getElementById("invoice").disabled = true;
		}
		
		reg.issuenumber.disabled = !(reg.cardtype.value == "switch")
		
	}
}



function validateForm()
{
	var validated = true;
	
	if(!checkRequired())
	{
		return false
	}
	
	if (reg.TotalCost.value == "NaN")
	{
		alert("The number of rooms must be a whole number");
		return false;
	}
	
	document.reg.subject.value = "Neurofly 2010: " + document.reg.FirstName.value + " " + document.reg.LastName.value
	
	return true;
}

function checkRequired()
{
	var all_filled = true;
	var required = document.reg.required.value.split(',');
	var personal_details_box_shown = false;
	var any_alert_box_shown = false;
	
	for(var i=0; i<required.length; i++)
	{
		var current_req = document.getElementById(required[i]);
			
		switch(required[i])
		{
			case "Title":
				if((current_req.value == "none") && (any_alert_box_shown == false))
				{
					alert("You have not selected a title in the Personal Details section");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "FirstName":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "LastName":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Institution":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Address":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Postcode":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Email":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Telephone":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			
			case "Department":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Country":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break


			case "Participation":
				if( document.reg.RegistrationType[0].checked == false && 
					document.reg.RegistrationType[1].checked == false && 
					document.reg.RegistrationType[2].checked == false && 
					document.reg.RegistrationType[3].checked == false &&
					document.reg.RegistrationType[4].checked == false && 
					document.reg.RegistrationType[5].checked == false && 
					document.reg.RegistrationType[6].checked == false && 
					document.reg.RegistrationType[7].checked == false &&
					document.reg.RegistrationType[8].checked == false && 
					document.reg.RegistrationType[9].checked == false && 
					document.reg.RegistrationType[10].checked == false &&
					document.reg.RegistrationType[11].checked == false && 
					any_alert_box_shown == false)
				{
					alert("You have not specified your registration type");
					all_filled = false;
					any_alert_box_shown = true;
				}
				
				
			/*case "SocialEvent":
				if( document.reg.SocialEvent[0].checked == false && 
					document.reg.SocialEvent[1].checked == false && 
					//document.reg.RegistrationType[2].checked == false && 
					//document.reg.RegistrationType[3].checked == false && 
					any_alert_box_shown == false)
				{
					alert("You have not specified your social event type");
					all_filled = false;
					any_alert_box_shown = true;
				}*/			
				
				
			/*case "AccompanyingPerson":
				if( document.reg.AccompanyRegistrationType[0].checked == false && 
					document.reg.AccompanyRegistrationType[1].checked == false && 
					document.reg.AccompanyRegistrationType[2].checked == false && 
					document.reg.AccompanyRegistrationType[3].checked == false &&
					document.reg.AccompanyRegistrationType[4].checked == false &&
					document.reg.AccompanyRegistrationType[5].checked == false &&
					any_alert_box_shown == false)
				{
					alert("You have not specified if there will be an accompanying person");
					all_filled = false;
					any_alert_box_shown = true;
				}*/
				
				
			case "Accommodation":
				if( document.reg.AccomType[0].checked == false && 
					document.reg.AccomType[1].checked == false &&
					document.reg.AccomType[2].checked == false &&
					document.reg.AccomType[3].checked == false &&
					document.reg.AccomType[4].checked == false &&
					document.reg.AccomType[5].checked == false &&
					document.reg.AccomType[6].checked == false &&
					document.reg.AccomType[7].checked == false &&
					document.reg.AccomType[8].checked == false &&
					document.reg.AccomType[9].checked == false &&
					document.reg.AccomType[10].checked == false &&
					/*document.reg.AccomType[11].checked == false &&
					document.reg.AccomType[12].checked == false &&
					document.reg.AccomType[13].checked == false &&*/
					any_alert_box_shown == false)
				{
					alert("You have not specified if you require accommodation");
					all_filled = false;
					any_alert_box_shown = true;
				}				
				
				
			break
			
			case "PaymentMethod":
			
				if( !document.reg.payment_choice[0].checked && 
					!document.reg.payment_choice[1].checked && 
					!document.reg.payment_choice[2].checked
					&& any_alert_box_shown == false)
				{										
						alert("You have not specified how you would like to pay");
						all_filled = false;
						any_alert_box_shown = true;
				}
				else if(document.reg.payment_choice[0].checked && !creditCardDetailsFilled() && any_alert_box_shown == false)
				{										
						alert("You have not filled in all your credit card detials");
						all_filled = false;
						any_alert_box_shown = true;
				}
				else if(document.reg.payment_choice[2].checked && !invoiceDetailsFilled() && any_alert_box_shown == false)
				{										
						alert("You have not filled in all your invoicing detials");
						all_filled = false;
						any_alert_box_shown = true;
				}
			break
		}
	}	
	
	return all_filled
}



function creditCardDetailsFilled()
{
	with(document.reg)
	{
		if(cardtype.value == "none" ||
			cardNumber.value == "" ||
			expiry.value == "" ||
			securityNumber.value == "" ||
			cardholdername.value == "" ||
			cardholderhouse.value == "" ||
			cardholderpostcode.value == "")
		{
			return false;
		}
		else if(cardtype.value == "switch" && issuenumber.value == "")
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function invoiceDetailsFilled()
{
	with(document.reg)
	{
		if(InvoiceAddress.value == "" ||
			OrderNumber.value == "" ||
			VATNumber.value == "")
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function submitBox()
{
	input_box = confirm("Are you sure you want to submit this form?");
	
	return input_box;
}

function resetBox()
{
	input_box = confirm("Are you sure you want to reset all the fields in this form?");
	
	return input_box;
}


/*
function refreshPage()
{
	showFields();
	
	calculateCost();
	
}

function showFields()
{	
	showPaymentFields();
	
	showAccommodationFields();
	
	if(document.reg.RegistrationType[2].checked || document.reg.RegistrationType[3].checked)
	{
		document.getElementById("IIRA_number").style.display = "";
	}
	else
	{		
		document.getElementById("IIRA_number").style.display = "none";
	}
	
	
	if(document.reg.RegistrationType[4].checked || document.reg.RegistrationType[5].checked)
	{
		document.getElementById("Student_number").style.display = "";
	}
	else
	{		
		document.getElementById("Student_number").style.display = "none";
	}

	if(document.reg.AccompanyingPerson.checked)
	{
		document.getElementById("Accom_person").style.display = "";
	}
	else
	{		
		document.getElementById("Accom_person").style.display = "none";
		document.reg.AccompanyingPersonDinner.checked = false;
		document.reg.AccompanyingPersonName.value = "";
	}
	
	if(document.reg.StudyTour.checked)
	{
		document.reg.first_choice[0].disabled = false; 
		document.reg.first_choice[1].disabled = false;  
		document.reg.first_choice[2].disabled = false;  
		document.reg.second_choice[0].disabled = false;  
		document.reg.second_choice[1].disabled = false;  
		document.reg.second_choice[2].disabled = false;  
	}
	else
	{
		document.reg.first_choice[0].disabled = true; 
		document.reg.first_choice[1].disabled = true;  
		document.reg.first_choice[2].disabled = true;  
		document.reg.second_choice[0].disabled = true;  
		document.reg.second_choice[1].disabled = true;  
		document.reg.second_choice[2].disabled = true; 
		
		document.reg.first_choice[0].checked = false; 
		document.reg.first_choice[1].checked = false;  
		document.reg.first_choice[2].checked = false;  
		document.reg.second_choice[0].checked = false;  
		document.reg.second_choice[1].checked = false;  
		document.reg.second_choice[2].checked = false;  
	}
}

function showPaymentFields()
{
	with(document)
	{
		if(reg.payment_choice[0].checked)
		{
			getElementById("creditcard").style.display = "";
			getElementById("creditcard").disabled = false;
		}
		else
		{
			getElementById("creditcard").style.display = "none";
			getElementById("creditcard").disabled = true;
		}
		
		if(reg.payment_choice[1].checked)
		{
			getElementById("cheque").style.display = "";
			getElementById("cheque").disabled = false;
		}
		else
		{
			getElementById("cheque").style.display = "none";
			getElementById("cheque").disabled = true;
		}
		
		if(reg.payment_choice[2].checked)
		{
			getElementById("invoice").style.display = "";
			getElementById("invoice").disabled = false;
		}
		else
		{
			getElementById("invoice").style.display = "none";
			getElementById("invoice").disabled = true;
		}
		
		reg.issuenumber.disabled = !(reg.cardtype.value == "switch")
		
	}
}

function showAccommodationFields()
{
	if(document.reg.book_accommodation[0].checked)
	{
		document.getElementById("AccomForm").style.display = "";
		document.getElementById("AccomForm").disabled = false;
	}
	else
	{
		document.getElementById("AccomForm").style.display = "none";
		document.getElementById("AccomForm").disabled = true;
	}
	
	if(document.reg.Hotel[0].checked || document.reg.Hotel[1].checked || document.reg.Hotel[2].checked || document.reg.Hotel[3].checked || document.reg.Hotel[4].checked || document.reg.Hotel[5].checked || document.reg.Hotel[6].checked || document.reg.Hotel[7].checked || document.reg.Hotel[8].checked)
	{
		document.getElementById("accommodation_days").style.display = "";
	}
}

function calculateCost()
{
	var total_cost = 0;
	var accommodationFee = 0;
	
	with(document)
	{
		
		if(reg.Hotel[0].checked)
		{
			accommodationFee = 31;
		}
		else if(reg.Hotel[1].checked)
		{
			accommodationFee = 77.95;
		}
		else if(reg.Hotel[2].checked)
		{
			accommodationFee = 87.95;
		}
		else if(reg.Hotel[3].checked)
		{
			accommodationFee = 86;
		}
		else if(reg.Hotel[4].checked)
		{
			accommodationFee = 106;
		}
		else if(reg.Hotel[5].checked)
		{
			accommodationFee = 89;
		}
		else if(reg.Hotel[6].checked)
		{
			accommodationFee = 106;
		}
		else if(reg.Hotel[7].checked)
		{
			accommodationFee = 98;
		}
		else if(reg.Hotel[8].checked)
		{
			accommodationFee = 108;
		}
		
		if(reg.RegistrationType[0].checked)
		{
			total_cost = 225
		}
		else if(reg.RegistrationType[1].checked)
		{
			total_cost = 325
		}
		else if(reg.RegistrationType[2].checked)
		{
			total_cost = 210
		}
		else if(reg.RegistrationType[3].checked)
		{
			total_cost = 310
		}
		else if(reg.RegistrationType[4].checked)
		{
			total_cost = 110
		}
		else if(reg.RegistrationType[5].checked)
		{
			total_cost = 185
		}
		
		if(reg.AccompanyingPerson.checked)
		{
			total_cost += 50;
		}
		
		if(reg.AccompanyingPersonDinner.checked)
		{
			total_cost += 45;
		}
		
		if(reg.Banquet.checked)
		{
			total_cost += 25;
		}
		
		if(reg.StudyTour.checked)
		{
			total_cost += 25;
		}
		
		if(reg.first_choice[2].checked)
		{
			total_cost += 15;
		}
		
		if(reg.Sunday.checked)
		{
			total_cost += accommodationFee;
		}
		
		if(reg.Monday.checked)
		{
			total_cost += accommodationFee;
		}
		
		if(reg.Tuesday.checked)
		{
			total_cost += accommodationFee;
		}
		
		if(reg.Wednesday.checked)
		{
			total_cost += accommodationFee;
		}		
				
		if(reg.Thursday.checked)
		{
			total_cost += accommodationFee;
		}

		
		total_cost = total_cost.toFixed(2)
		
		getElementById("TotalCost").value = "£" + total_cost;
	}
}

function validateForm()
{
	var validated = true;
	
	if(!checkRequired())
	{
		return false
	}
	
	document.reg.subject.value = "IIRA: " + document.reg.FirstName.value + " " + document.reg.LastName.value
	
	return true;
}

function checkRequired()
{
	var all_filled = true;
	var required = document.reg.required.value.split(',');
	var personal_details_box_shown = false;
	var any_alert_box_shown = false;
	
	for(var i=0; i<required.length; i++)
	{
		var current_req = document.getElementById(required[i]);
			
		switch(required[i])
		{
			case "Title":
				if((current_req.value == "none") && (any_alert_box_shown == false))
				{
					alert("You have not selected a title in the Personal Details section");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			

			case "FirstName":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "LastName":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Institution":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Address":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Postcode":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Email":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Telephone":
				if(current_req.value == "" && !personal_details_box_shown && any_alert_box_shown == false)
				{
					alert("You have not filled in all the required personal details");
					all_filled = false;
					personal_details_box_shown = true;
					any_alert_box_shown = true;
				}
			break
			
			case "Participation":
				if( document.reg.RegistrationType[0].checked == false && 
					document.reg.RegistrationType[1].checked == false && 
					document.reg.RegistrationType[2].checked == false && 
					document.reg.RegistrationType[3].checked == false && 
					document.reg.RegistrationType[4].checked == false && 
					document.reg.RegistrationType[5].checked == false && 
					any_alert_box_shown == false)
				{
					alert("You have not specified your registration type");
					all_filled = false;
					any_alert_box_shown = true;
				}
				
				if((document.reg.RegistrationType[2].checked ||	document.reg.RegistrationType[3].checked) &&
					document.reg.IIRAMembershipNumber.value =='' && any_alert_box_shown == false)
				{
					alert("You have not inputted your IIRA membership number");
					all_filled = false;
					any_alert_box_shown = true;
				}
				
				if((document.reg.RegistrationType[4].checked ||	document.reg.RegistrationType[5].checked) &&
					document.reg.StudentMembershipNumber.value =='' && any_alert_box_shown == false)
				{
					alert("You have not inputted your student membership number");
					all_filled = false;
					any_alert_box_shown = true;
				}
			break
			
			case "PaymentMethod":
			
				if( !document.reg.payment_choice[0].checked && 
					!document.reg.payment_choice[1].checked && 
					!document.reg.payment_choice[2].checked
					&& any_alert_box_shown == false)
				{										
						alert("You have not specified how you would like to pay");
						all_filled = false;
						any_alert_box_shown = true;
				}
				else if(document.reg.payment_choice[0].checked && !creditCardDetailsFilled() && any_alert_box_shown == false)
				{										
						alert("You have not filled in all your credit card detials");
						all_filled = false;
						any_alert_box_shown = true;
				}
				else if(document.reg.payment_choice[2].checked && !invoiceDetailsFilled() && any_alert_box_shown == false)
				{										
						alert("You have not filled in all your invoicing detials");
						all_filled = false;
						any_alert_box_shown = true;
				}
			break
		}
	}	
	
	return all_filled
}



function creditCardDetailsFilled()
{
	with(document.reg)
	{
		if(cardtype.value == "none" ||
			cardNumber.value == "" ||
			expiry.value == "" ||
			securityNumber.value == "" ||
			cardholdername.value == "" ||
			cardholderhouse.value == "" ||
			cardholderpostcode.value == "")
		{
			return false;
		}
		else if(cardtype.value == "switch" && issuenumber.value == "")
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function invoiceDetailsFilled()
{
	with(document.reg)
	{
		if(InvoiceAddress.value == "" ||
			OrderNumber.value == "" ||
			VATNumber.value == "")
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function submitBox()
{
	input_box = confirm("Are you sure you want to submit this form?");
	
	return input_box;
}

function resetBox()
{
	input_box = confirm("Are you sure you want to reset all the fields in this form?");
	
	return input_box;
}

function closeWindow()
{
	window.close();
}*/