		var g_surname="";
		var g_christian =""; 
		var g_title="";
function get_values(thisform,bid,action) {
	var file = '/js/get_details.php?action='+action+'&bookingid='+bid;
 	var head = document.getElementsByTagName('head').item(0);
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script);
	script.onload = function () {
		if (action === "group") {
			thisform.group_leader_surname.value=g_surname;
			thisform.group_leader_christian.value=g_christian; 
			thisform.group_leader_title.value=g_title;
		} else if (action === "camping") {
			thisform.share_firstname.value=g_surname;
			thisform.share_lastname.value=g_christian;
	  }
		return true;
	}
	void(head.appendChild(script));
	if (action === "group") {
		thisform.group_leader_surname.value=g_surname;
		thisform.group_leader_christian.value=g_christian; 
		thisform.group_leader_title.value=g_title;
	} else if (action === "camping") {
		thisform.share_firstname.value=g_surname;
		thisform.share_lastname.value=g_christian;
	}
}
function filterArray (selbox,arrayname,roleid) {
   	var outputarray = new Array();
   	var counter= 0;
		selbox.options.length = 0;
    for (var i=0; i < arrayname.length; i++) {
           if (arrayname[i][2] === roleid) {
           		outputarray[counter] = new Array('arrayname[i][0]','arrayname[i][1]');
      				var opt = new Option(arrayname[i][1], arrayname[i][0]);
      				selbox[selbox.length] = opt;
           		counter++;
           }
     }
}

function doGetChurch(pc,town,church) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var h = new getchurch(GetChurchHandler);

	// Call the remote method (method lower case!)
	h.get_church(pc,town,church);
}
// A handler is required to accept the response
// of asychronous calls...
var GetChurchHandler = {

	// Function must have same name as remote method
	get_church: function(result) {
		eval(result);
		// clear box first
		popSelect(document.getElementById("c_box"),church_list);
	}
}
function doGetCampingChurch(pc,town,church) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var h = new getcampingchurch(GetCampingChurchHandler);

	// Call the remote method (method lower case!)
	h.get_campingchurch(pc,town,church);
}
// A handler is required to accept the response
// of asychronous calls...
var GetCampingChurchHandler = {

	// Function must have same name as remote method
	get_campingchurch: function(result) {
		eval(result);
		// clear box first
		popSelect(document.getElementById("c_box"),church_list);
	}
}
function doGetAddress(postcode,property) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var j = new getaddress(GetAddressHandler);
	// Call the remote method (method lower case!)
	j.get_address(postcode,property);

}
// A handler is required to accept the response
// of asychronous calls...
var GetAddressHandler = {

	// Function must have same name as remote method
	get_address: function(result) {
		eval(result);
       	if (address_list[0][0] =='') {
			alert("Sorry we do not recognise that address, please re-enter or enter your full address in the box below.");
			show('full_address');
		} else {
			popSelect(document.getElementById("a_box"),address_list);
			hide('contact_simple'); 
			show('address_box');
		}
	}
}
function doGetAddress2(postcode,property) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var b = new getaddress(GetAddressHandler2);
	// Call the remote method (method lower case!)
	b.get_address(postcode,property);
}
// A handler is required to accept the response
// of asychronous calls...
var GetAddressHandler2 = {

	// Function must have same name as remote method
	get_address: function(result) {
		eval(result);
		if (address_list[0][0] =='') {
			alert("Sorry we do not recognise that address, please re-enter or enter your full address in the box below.");
			show('full_address_ref2');
		} else {
			popSelect(document.getElementById("a_box2"),address_list);
			hide('contact_simple_ref2'); 
			show('address_box_ref2');
		}
	}
}
function doGetAddressDetails(postkey) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var h = new getaddressdetails(GetAddressDetailsHandler);

	// Call the remote method (method lower case!)
	h.get_address_details(postkey);
}
// A handler is required to accept the response
// of asychronous calls...
var GetAddressDetailsHandler = {

	// Function must have same name as remote method
	get_address_details: function(result) {
		eval(result);
		document.getElementById("country").value="20";
		document.getElementById("postcode").value=postcode;
		document.getElementById("town").value=town;
		document.getElementById("address1").value=street;
		if (organisation != "") {
			document.getElementById("address").value=organisation;
		} else {
				document.getElementById("address").value=property;		
		}	
		document.getElementById("postkey").value=postkey;
		document.getElementById("lat").value=lat;
		document.getElementById("lon").value=lon;
		document.getElementById("country").readOnly=1;
		document.getElementById("postcode").readOnly=1;
		document.getElementById("town").readOnly=1;
		document.getElementById("address1").readOnly=1;
		if (property !="") {
			document.getElementById("address").readOnly=1;
		}
	}
}
function selectByValue( elem, value )

{
var opt, i = 0;
while( opt = elem.options[i++] )
{
if ( opt.text == value )
{
opt.selected = true;
return;
}
}
}
function doGetAddressDetails2(postkey) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var h = new getaddressdetails(GetAddressDetailsHandler2);

	// Call the remote method (method lower case!)
	h.get_address_details(postkey);
}
// A handler is required to accept the response
// of asychronous calls...
var GetAddressDetailsHandler2 = {

	// Function must have same name as remote method
	get_address_details: function(result) {
		eval(result);
		document.getElementById("country_ref2").value="20";
		document.getElementById("postcode_ref2").value=postcode;
		document.getElementById("town_ref2").value=town;
		document.getElementById("address1_ref2").value=street;
		document.getElementById("address_ref2").value=property;
		document.getElementById("postkey_ref2").value=postkey;
		document.getElementById("lat_ref2").value=lat;
		document.getElementById("lon_ref2").value=lon;
		document.getElementById("country_ref2").readOnly=1;
		document.getElementById("postcode_ref2").readOnly=1;
		document.getElementById("town_ref2").readOnly=1;
		document.getElementById("address1_ref2").readOnly=1;
		if (property !="") {
			document.getElementById("address_ref2").readOnly=1;
		}
	}
}
function doGetDetails(myid) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var h = new getdetails(GetDetailsHandler);

	// Call the remote method (method lower case!)
	h.get_details(myid);
}
// A handler is required to accept the response
// of asychronous calls...
var GetDetailsHandler = {

	// Function must have same name as remote method
	get_details: function(result) {
		eval(result);
		document.getElementById("share_surname").value=g_surname;
		document.getElementById("share_christian").value=g_christian;		
	}
}
function doGetFees(eventid,dobyear,dobmonth,dobday) {
	// Create the client object, passing the async
	// handler. Note lower case!
	//alert ("month"+dobmonth+"day"+dobday);
	if (dobmonth == "" || dobday == ""  || dobyear == "" ) {
		return;
	}
	var f = new getfee(GetFeeHandler);
	// Call the remote method (method lower case!)
	f.get_fee(eventid,dobyear,dobmonth,dobday);
}
// A handler is required to accept the response
// of asychronous calls...
var GetFeeHandler = {
	// Function must have same name as remote method
	get_fee: function(result) {
		eval(result);
		document.getElementById("fee").value=rate;	
		document.getElementById("feeid").value=feeid;
		if (deposit > 0) {
		document.getElementById("deposit").value=deposit;
		}
	}
}
function doGetDetails2(myid) {
	// Create the client object, passing the async
	// handler. Note lower case!
	var h = new getdetails(GetDetailsHandler2);

	// Call the remote method (method lower case!)
	h.get_details(myid);
}
// A handler is required to accept the response
// of asychronous calls...
var GetDetailsHandler2 = {

	// Function must have same name as remote method
	get_details: function(result) {
		eval(result);
		document.getElementById("carer_name").value=g_surname+" "+g_christian;		
	}
}
function popSelect (selbox,arrayname) {
	selbox.options.length = 0;
   for (var x = 0; x < arrayname.length; x++){
      var opt = new Option(arrayname[x][1], arrayname[x][0]);
       selbox[selbox.length] = opt;
      }
}
function populate_churches(thisform,churchid,churchvalue) {
	var mychurch_array=churchvalue.split(",");
	thisform.church_attended.value =mychurch_array[0];
	thisform.church_town.value = mychurch_array[1];
	var strip_pc =mychurch_array[2].replace("(","");
	thisform.church_pc.value=strip_pc.replace(")","");
	thisform.church_id.value=churchid;
}
function populate_camping_churches(thisform,churchid,churchvalue) {
	var mychurch_array=churchvalue.split(",");
	thisform.church_attended.value =leftTrim(mychurch_array[0]);
	thisform.church_town.value = leftTrim(mychurch_array[1]);
	var strip_pc =mychurch_array[2].replace("(","");
	thisform.church_pc.value=leftTrim(strip_pc.replace(")",""));
}
function leftTrim(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}
function populate_camp(thisform,churchid,churchvalue) {
	var mychurch_array=churchvalue.split(",");
	thisform.camp_group.value =mychurch_array[0];
	thisform.camp_town.value = mychurch_array[1];
	var strip_pc =mychurch_array[2].replace("(","");
	thisform.camp_pc.value=strip_pc.replace(")","");
	thisform.camp_id.value=churchid;
}
function deleteOption(theSel,theValue) { 	
	for (var x=0;x<theSel.length;x++) {
		if (theSel.options[x].value==theValue) {
			theSel.options[x]= null;
		}
	}
}
function checkBox(dropdown,sid) {
	var thisvalue = "Pebbles";
	thisvalue =(dropdown[dropdown.selectedIndex].text);
	if (thisvalue == "Pebbles" || thisvalue =="Gems" || thisvalue == "Ground Breakers" || thisvalue == "Rock Solid" || thisvalue == "Boulder Gang" || thisvalue == "Our Place") {
		show(sid);
	}
}
function check_delegates(delegates,workers) {
	if (workers > delegates) {
		alert ("Sorry you can't have more team members than delegates in your party");
	document.forms.main.delegate_workers[document.forms.main.delegate_workers.selectedIndex].value=delegates;
	}
}
function validateOnSubmit() {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
if (!validatePresent(document.forms.main.church_attended, 'church_attended_form') && !validatePresent(document.forms.main.church_town, 'church_attended_form')&& !validatePresent(document.forms.main.church_pc, 'church_attended_form') ) errs += 1; 
		if (!validatePresent(document.forms.main.address1, 'address1_form') && !validatePresent(document.forms.main.address, 'address1_form')) {
		errs+=1;
	  show('full_address');
	}
  var gendercheck=0;
	var j=document.forms.main.gender.length; 
	for (i=0; i<j; i++){
		if(document.forms.main.gender[i].checked) {
			gendercheck++;
		}
	}
	if (gendercheck == 0) {
				var elem = document.getElementById('gender_form');
  			elem.firstChild.nodeValue = "ERROR: you must tell us your gender"; 
  				elem.className = "error";
				errs+=1;
	}
	if (document.forms.main.adult.checked == false) {
		if (!validateSelectBox(document.forms.main.DOBDay,'dob_form','true') )errs += 1;			
		if (!validateSelectBox(document.forms.main.DOBMonth,'dob_form','true') )errs += 1;	
		if (!validateSelectBox(document.forms.main.DOBYear,'dob_form','true') )errs += 1;	
	}
	if(!validateTelnr(document.forms.main.tel,'telday_form','true') && !validateTelnr(document.forms.main.tel_evening,'telday_form','true') && !validateTelnr(document.forms.main.mobile,'telday_form','true')) errs += 1; 
	if (!validatePresent(document.forms.main.christian_name,  'christian_form','true'))        errs += 1; 
	if (!validatePresent(document.forms.main.surname,  'surname_form','true'))        errs += 1; 
	if (!validateSelectBox(document.forms.main.title,'title_form','true') )errs += 1; 
	if (!validatePresent(document.forms.main.password,   'password_form',  true)) errs += 1;  
	if (!validateEmail(document.forms.main.email, 'email_form', true)) errs += 1; 	
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function TeamsValidateOnSubmit() {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
if (!validatePresent(document.forms.main.church_attended, 'church_attended_form') && !validatePresent(document.forms.main.church_town, 'church_attended_form')&& !validatePresent(document.forms.main.church_pc, 'church_attended_form') ) errs += 1; 
		if (!validatePresent(document.forms.main.address1, 'address1_form')) {
		errs+=1;
	  show('full_address');
	}
  var gendercheck=0;
	var j=document.forms.main.gender.length; 
	for (i=0; i<j; i++){
		if(document.forms.main.gender[i].checked) {
			gendercheck++;
		}
	}
	if (gendercheck == 0) {
				var elem = document.getElementById('gender_form');
  			elem.firstChild.nodeValue = "ERROR: you must tell us your gender"; 
  				elem.className = "error";
				errs+=1;
	}
	if (!validateSelectBox(document.forms.main.DOBDay,'dob_form','true') )errs += 1;			
	if (!validateSelectBox(document.forms.main.DOBMonth,'dob_form','true') )errs += 1;	
	if (!validateSelectBox(document.forms.main.DOBYear,'dob_form','true') )errs += 1;	
	if(!validateTelnr(document.forms.main.tel,'telday_form','true') && !validateTelnr(document.forms.main.tel_evening,'telday_form','true') && !validateTelnr(document.forms.main.mobile,'telday_form','true')) errs += 1; 
	if (!validatePresent(document.forms.main.christian_name,  'christian_form','true'))        errs += 1; 
	if (!validatePresent(document.forms.main.surname,  'surname_form','true'))        errs += 1; 
	if (!validateSelectBox(document.forms.main.title,'title_form','true') )errs += 1; 
	if (!validatePresent(document.forms.main.password,   'password_form',  true)) errs += 1;  
	if (!validateEmail(document.forms.main.email, 'email_form', true)) errs += 1; 	
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function ValidateRegister() {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (!validateCheckbox(document.forms.register.confirm, 'confirm_form',true)) errs += 1;
	if (!validatePresent(document.forms.register.password,   'password_form',  true)) errs += 1;  
	if (!validateEmail(document.forms.register.email, 'email_form', true)) errs += 1; 	
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function ValidateBookingRef() {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (!validatePresent(document.forms.booking_form.booking_ref,   'booking_ref_form',  true)) {
		errs += 1;
		alert ("Please enter your Order Number");
	}  
	if (document.forms.booking_form.booking_ref.value != document.forms.booking_form.booking_ref_c.value) {
		errs += 1;
		alert ("In order to verify your Order Number, please ensure it is entered in both boxes correctly.");
		 msg ('booking_ref_c_form', "error", "  ERROR: Entered numbers do not match");  
	} 	
	return (errs==0);
}

function ValidateCampingChurch() {
	var elem;
	var errs=0;
	var message="";
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (document.forms.church.event[document.forms.church.event.selectedIndex].value == "0" || document.forms.church.event[document.forms.church.event.selectedIndex].value == "") {
		errs += 1;
		message += "Please select the event you will be attending\n";	
		msg ('select_event_form', "error", "  ERROR: Please select your event");  
	} 
	if (!validatePresent(document.forms.church.church_attended, 'church_attended_form') && !validatePresent(document.forms.church.church_town, 'church_attended_form')&& !validatePresent(document.forms.church.church_pc, 'church_attended_form') ) {
		errs += 1; 
		message += "Please enter your church details\n";
} else if (document.getElementById('churchbox').style.display!="block") { 
		errs += 1; 
		message += "Please click Get Church Details\n";	
} else {
	if (!validateSelectBox(document.forms.church.c_box,'churchbox_form') || document.forms.church.c_box[document.forms.church.c_box.selectedIndex].value == "8888") {
		errs += 1; 
		message += "Please select your Church from the List\n";			
	} 
}
		
		
	if (errs>0)  {
	 alert('There are fields which need correction before submitting:\n\n'+message);
	}
	return (errs==0);
}
function OrdinandsValidateOnSubmit() {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (!validatePresent(document.forms.main.address1, 'address1_form')) {
		errs+=1;
	  show('full_address');
	}
  var gendercheck=0;
	var j=document.forms.main.gender.length; 
	for (i=0; i<j; i++){
		if(document.forms.main.gender[i].checked) {
			gendercheck++;
		}
	}
	if (gendercheck == 0) {
				var elem = document.getElementById('gender_form');
  			elem.firstChild.nodeValue = "ERROR: you must tell us your gender"; 
  				elem.className = "error";
				errs+=1;
	}
	if(!validateTelnr(document.forms.main.tel,'telday_form','true') && !validateTelnr(document.forms.main.tel_evening,'telday_form','true') && !validateTelnr(document.forms.main.mobile,'telday_form','true')) errs += 1; 
	if (!validatePresent(document.forms.main.christian_name,  'christian_form','true'))        errs += 1; 
	if (!validatePresent(document.forms.main.surname,  'surname_form','true'))        errs += 1; 
	if (document.forms.main.title[document.forms.main.title.selectedIndex].value == "0") {
		var elem = document.getElementById('title_form');
  	elem.firstChild.nodeValue = "ERROR: required"; 
  	elem.className = "error";
		errs+=1;
	}
	if (!validatePresent(document.forms.main.password,   'password_form',  true)) errs += 1;  
	if (!validateEmail(document.forms.main.email, 'email_form', true)) errs += 1; 	
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function DelegatesValidateOnSubmit(delegate_count,worker_num) {
	var elem;
	var errs=0;
	var del_count=delegate_count;
//	var del_count=delegate_count+1;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	for (var x = 1; x <del_count; x++){
			var cfield='christian_name'+x;
			var c2field=eval("document.forms.delegates."+cfield);
			var sfield='surname'+x;
			var s2field=eval("document.forms.delegates."+sfield);
			var gfield='gender'+x;
			var g2field=eval("document.forms.delegates."+gfield);	
			var tfield='title'+x;
			var t2field=eval("document.forms.delegates."+tfield);			
			var adultfield='adult'+x;
			var adultfield2=eval("document.forms.delegates."+adultfield);	
			var dobdayfield='dob'+x+'Day';
			var dobdayfield2=eval("document.forms.delegates."+dobdayfield);
			var dobmonthfield='dob'+x+'Month';
			var dobmonthfield2=eval("document.forms.delegates."+dobmonthfield);
			var dobyearfield='dob'+x+'Year';
			var dobyearfield2=eval("document.forms.delegates."+dobyearfield);
			var delegate1_field='delegate1_form'+x;
			var delegate2_field='delegate2_form'+x;
			var delegate_gender_field='delegate_gender_form'+x;
			var delegate_title_field='delegate_title_form'+x;
    	if (!validatePresent(c2field, delegate1_field, 'true')) errs += 1; 
    	if (!validatePresent(s2field, delegate2_field, 'true')) errs += 1;   
  		if (!validateRadio(g2field, delegate_gender_field)) errs += 1;
			if (!validateSelectBox(t2field,delegate_title_field))errs += 1; 
			if (adultfield2.checked == false) {
				if (!validateSelectBox(dobdayfield2,delegate1_field,'true') )errs += 1;			
				if (!validateSelectBox(dobmonthfield2,delegate1_field,'true') )errs += 1;	
				if (!validateSelectBox(dobyearfield2,delegate1_field,'true') )errs += 1;	
			}
   }
		// count the number of workers ticked
	// get number of workers selected previously
	worker_check=number_of_workers(del_count);
	if (worker_check < worker_num) {
		alert ("You have not selected all your worker delegates please tick their boxes on the form");
		return false;
	} 
  document.forms.delegates.stage4.value='Proceed To Stage 3';
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function YouthDelegatesValidateOnSubmit(delegate_count,worker_num) {
	var elem;
	var errs=0;
	var del_count=delegate_count;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (!validatePresent(document.forms.delegates.group_leader_surname, 'group_leader_surname_form')) errs += 1;
	if (!validatePresent(document.forms.delegates.group_leader_christian, 'group_leader_christian_form')) errs += 1;
	for (var x = 1; x <del_count; x++){
			var cfield='christian_name'+x;
			var c2field=eval("document.forms.delegates."+cfield);
			var sfield='surname'+x;
			var s2field=eval("document.forms.delegates."+sfield);
			var gfield='gender'+x;
			var g2field=eval("document.forms.delegates."+gfield);	
			var tfield='title'+x;
			var t2field=eval("document.forms.delegates."+tfield);			
			var adultfield='adult'+x;
			var adultfield2=eval("document.forms.delegates."+adultfield);	
			var dobdayfield='dob'+x+'Day';
			var dobdayfield2=eval("document.forms.delegates."+dobdayfield);
			var dobmonthfield='dob'+x+'Month';
			var dobmonthfield2=eval("document.forms.delegates."+dobmonthfield);
			var dobyearfield='dob'+x+'Year';
			var dobyearfield2=eval("document.forms.delegates."+dobyearfield);
			var delegate_field='delegate_form'+x;
    	if (!validatePresent(c2field, delegate_field, 'true')) errs += 1; 
    	if (!validatePresent(s2field, delegate_field, 'true')) errs += 1;   
  		if (!validateRadio(g2field, delegate_field)) errs += 1;
			if (!validateSelectBox(t2field,delegate_field) )errs += 1; 
			if (adultfield2.checked == false) {
				if (!validateSelectBox(dobdayfield2,delegate_field,'true') )errs += 1;			
				if (!validateSelectBox(dobmonthfield2,delegate_field,'true') )errs += 1;	
				if (!validateSelectBox(dobyearfield2,delegate_field,'true') )errs += 1;	
			}
   }
   		// count the number of workers ticked
	// get number of workers selected previously
	worker_check=number_of_workers(del_count);
	if (worker_check < worker_num) {
		alert ("You have not selected all your worker delegates please tick their boxes on the form");
		return false;
	} 
   	document.forms.delegates.stage4.value='Proceed To Stage 3';
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function RefereeValidateOnSubmit() {
	var elem;
	var errs=0;
	if (!validateSelectBox(document.forms.main.title1,'title_form1','true') )errs += 1; 
	if (!validatePresent(document.forms.main.christian_name1, 'christian_form1','true')) errs += 1;
	if (!validatePresent(document.forms.main.surname1, 'surname_form1','true')) errs += 1;
	if (!validateTelnr(document.forms.main.tel1,'telday_form1','true')) errs += 1;
	if (!validatePresent(document.forms.main.position1,'position_form1','true')) errs += 1;
	if (!validatePresent(document.forms.main.christian_name2, 'christian_form2','true')) errs += 1;
	if (!validatePresent(document.forms.main.surname2, 'surname_form2','true')) errs += 1;
	if (!validateSelectBox(document.forms.main.title2,'title_form2','true') )errs += 1; 
	if (!validateTelnr(document.forms.main.tel2,'telday_form2','true')) errs += 1;
	if (!validatePresent(document.forms.main.position2,'position_form2','true')) errs += 1;
	if (!validatePresent(document.forms.main.all_skills, 'all_skills_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.church_area, 'church_area_form','true')) errs += 1;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	
	return (errs==0);
}
function YouthRefereeValidateOnSubmit() {
	var elem;
	var errs=0;
  if (!validateSelectBox(document.forms.main.title1,'title_form1','true') )errs += 1; 
	if (!validatePresent(document.forms.main.christian_name1, 'christian_form1','true')) errs += 1;
	if (!validatePresent(document.forms.main.surname1, 'surname_form1','true')) errs += 1;
	if (!validateTelnr(document.forms.main.tel1,'telday_form1','true')) errs += 1;
	if (!validatePresent(document.forms.main.position1,'position_form1','true')) errs += 1;
  if (!validateSelectBox(document.forms.main.title2,'title_form2','true') )errs += 1; 
	if (!validatePresent(document.forms.main.christian_name2, 'christian_form2','true')) errs += 1;
	if (!validatePresent(document.forms.main.surname2, 'surname_form2','true')) errs += 1;
	if (!validateTelnr(document.forms.main.tel2,'telday_form2','true')) errs += 1;
	if (!validatePresent(document.forms.main.position2,'position_form2','true')) errs += 1;
	if (!validatePresent(document.forms.main.artistic,'artistic_form')) errs += 1;
	if (!validatePresent(document.forms.main.experience, 'experience_form')) errs += 1;
	if (!validatePresent(document.forms.main.other_skills, 'other_skills_form')) errs += 1;
	if (!validatePresent(document.forms.main.church_area, 'church_area_form')) errs += 1;
	if (!validateRadio(document.forms.main.first_aid, 'first_aid_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.epipen, 'epipen_form','true')) errs += 1;	
	if (!validateRadio(document.forms.main.special, 'special_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.qualification, 'qualifications_form','true')) errs += 1;	
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	
	return (errs==0);
}
function WorkerValidateOnSubmit() {
	var elem;
	var errs=0;
	if (!validateRadio(document.forms.main.treatment, 'treatment_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.physical, 'physical_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.mental, 'mental_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.how_long, 'how_long_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.how_matured, 'how_matured_form','true')) errs += 1;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	
	return (errs==0);
}
function YouthWorkerValidateOnSubmit() {
	var elem;
	var errs=0;
	if (!validateCheckbox(document.forms.main.cpp, 'cpp_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.treatment, 'treatment_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.physical, 'physical_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.mental, 'mental_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.how_long, 'how_long_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.how_matured, 'how_matured_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.carer_id, 'carer_id_form','true')) errs += 1;
	if (!validatePresent(document.forms.main.carer_name, 'carer_name_form','true')) errs += 1;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	
	return (errs==0);
}
function ExtraValidateOnSubmit() {
	var elem;
	var errs=0;
	if (!validateCheckbox(document.forms.main.tnc, 'tnc_form','true')) errs += 1;
	if (!validateCheckbox(document.forms.main.agree, 'agree_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.convicted, 'convicted_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.enquiry, 'enquiry_form','true')) errs += 1;
	if (!validateRadio(document.forms.main.conduct, 'conduct_form','true')) errs += 1;

	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	
	return (errs==0);
}


function TeamsAccommodationValidateOnSubmit(delegate_count) {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	var accom_count=CountAccomodation();
	if (delegate_count > 4) {
		if (accom_count > delegate_count) {
			var agree=confirm("Warning: Please only book accomodation for delegates in your party. Would you like to recheck your accommodation options?");
			if (agree) {
					return false ;
			} 
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = "Warning: Please only book accomodation for delegates in your party"; 
  		elem.className = "error";
		}
	} else {
		if (accom_count > 5) {
			var agree = confirm("Warning: Please only book accomodation for delegates in your party. Would you like to recheck your accommodation options?");
			if (agree) {
					return false ;
			} 
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = "Warning: Please only book accomodation for delegates in your party"; 
  		elem.className = "error";
		}
	}
	if (accom_count == 0 && document.forms.main.offsite.checked !=true &&  (document.forms.main.share_surname.value == ""  || document.forms.main.shringwith_regno.value == "")  ) {
		alert ("Please either enter your accommodation details, whether you are staying off site or who you are sharing with");
		return false;
	}
if (!validatePresent(document.forms.main.camp_group,'camp_attended_form','true')||!validatePresent(document.forms.main.camp_town,'camp_attended_form','true') ) errs += 1; 	
		if (!validateRadio(document.forms.main.tshirt, 'tshirt_form','true')) errs += 1;
		if (!validateSelectBox(document.forms.main.first_role,'team_form','true') )errs += 1; 	
	
	
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function BookingAccommodationValidateOnSubmit(delegate_count,all_off_site) {
	var elem;
	var errs=0;

	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
	var accom_count=CountAccomodation();
	if (all_off_site == "true" && accom_count > 0) {
		alert ("Warning: All your delegates have been flagged as staying off site, therefore your accomodation will not be counted");
		return true;
	}
	if (delegate_count > 4) {
		if (accom_count > delegate_count) {
			var agree=confirm("Warning: Please only book accomodation for delegates in your party. Would you like to recheck your accommodation options?");
			if (agree) {
					return false ;
			} 
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = "Warning: Please only book accomodation for delegates in your party"; 
  		elem.className = "error";
		}
	} else {
		if (accom_count > 5) {
			var agree = confirm("Warning: Please only book accomodation for delegates in your party. Would you like to recheck your accommodation options?");
			if (agree) {
					return false ;
			} 
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = "Warning: Please only book accomodation for delegates in your party"; 
  		elem.className = "error";
		}
	}
	if (accom_count == 0 && all_off_site !="true" &&  (document.forms.main.share_surname.value == ""  || document.forms.main.shringwith_regno.value == "")  ) {
		alert ("Please either enter your accommodation details or who you are sharing with");
		return false;
	}
if (all_off_site !="true"  && !validatePresent(document.forms.main.camp_group,'camp_attended_form','true')||!validatePresent(document.forms.main.camp_town,'camp_attended_form','true') ) errs += 1; 	
	if (errs>1)  alert('There are fields which need correction before sending');
	if (errs==1) alert('There is a field which needs correction before sending');
	return (errs==0);
}
function CountAccomodation() {
  var field1=eval(document.forms.main.accom_trailertents);
	var field2=eval(document.forms.main.accom_xlargetents);
	var field3=eval(document.forms.main.accom_largetents);
	var field4=eval(document.forms.main.accom_mediumtents);
	var field5=eval(document.forms.main.accom_smalltents);
	var field6=eval(document.forms.main.accom_motorhomes);
	var field7=eval(document.forms.main.accom_awnings);
  var field8=eval(document.forms.main.accom_caravans);
	var accom_count =parseInt(field1[field1.selectedIndex].value) + parseInt (field2[field2.selectedIndex].value)+ parseInt (field3[field3.selectedIndex].value)+ parseInt (field4[field4.selectedIndex].value)+ parseInt (field5[field5.selectedIndex].value)+ parseInt (field6[field6.selectedIndex].value)+ parseInt (field7[field7.selectedIndex].value)+ parseInt (field8[field8.selectedIndex].value);
	return (accom_count);	
}
function ValidateAccommodation(field,delegate_count) {
  var accom_count=CountAccomodation();
  if (delegate_count == '') {
  	delegate_count=1;
  }
	var elem;
	var errs=0;
	if (delegate_count > 4) {
		if (accom_count > delegate_count) {
			alert ("Warning: Please only book accommodation for delegates in your party");
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = "Warning: Please only book accommodation for delegates in your party"; 
  		elem.className = "error";
			errs+=1;
		} else {
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = ""; 
  		elem.className = "info";		
		}
	} else {
		if (accom_count > 5) {
			alert ("Warning: Please only book accomodation for delegates in your party");
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = "Warning: Please only book accommodation for delegates in your party"; 
  		elem.className = "error";
			errs+=1;		
		} else {
			var elem = document.getElementById('accommodation_form');
			elem.firstChild.nodeValue = ""; 
  		elem.className = "info";		
		}
	}
}
function BookingConfirmValidateOnSubmit(thisform) {
	var elem;
	var errs=0;
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
if (thisform.tnc.checked != true) {
  errs +=1;	
}
	if (errs>1)  alert('Please accept our terms and conditions');
	if (errs==1) alert('Please accept our terms and conditions');
	return (errs==0);
}
function checkDoBFee(month,day,year,row,worker,deposit){	
		if (worker != true && deposit != true) {
			if (month == "" || day == ""  || year == "" ) {
				return;
			}			 
			var today = new Date();
		// javascript calc from full ob with ageon
			var birthdate=new Date(year, month-1, day);
			var ageon_array=ageon.split("-");
			var ageondate=new Date(ageon_array[0], ageon_array[1]-1, ageon_array[2]);
			var one_year=1000 * 60 * 60 * 24 * 365.25;
			var result = eval((ageondate - birthdate)/one_year);
			if(!isNaN(result)){	
				if (result <= 3) {
					var creche=confirm("You have the option of having your child in Gems - click ok to be allocated a place (there is a fee for this) or click cancel and your child won't be given a Gems place");
				}
				for (var x = 0; x <=fee_list.length; x++){
					if (fee_list[x][0] > result) {
						if (creche) {
							if (fee_list[x][4] == 1) {
								var fee_field=eval("document.forms.delegates.fee"+row);
								var feeid_field=eval("document.forms.delegates.feeid"+row);
								var deposit_field=eval("document.forms.delegates.deposit"+row);
								var creche_field=eval("document.forms.delegates.creche"+row);
								fee_field.value=fee_list[x][1];
								feeid_field.value=fee_list[x][2];
								deposit_field.value=fee_list[x][3];							
								creche_field.value="true";
								return;
							}
						} else {
							var fee_field=eval("document.forms.delegates.fee"+row);
							var feeid_field=eval("document.forms.delegates.feeid"+row);
							var deposit_field=eval("document.forms.delegates.deposit"+row);
							fee_field.value=fee_list[x][1];
							feeid_field.value=fee_list[x][2];
							deposit_field.value=fee_list[x][3];
							return;
						}
					}
				}	
     	} 
		} 
}
function check_adult(box,year) {
	//this should be current year -20
	var nowdate=new Date();
	var twenty_year=nowdate.getFullYear()-20;
	if (year >= twenty_year && year != "") {
		box.checked=false;
	} else {
		box.checked=true;
	}
}
function check_worker(this_field,month,day,year,adult,rownum) {
	if (this_field.checked == true) {
  	var birthdate=new Date(year, month-1, day);
		var ageon_array=ageon.split("-");
		var ageondate=new Date(ageon_array[0], ageon_array[1]-1, ageon_array[2]);
		var one_year=1000 * 60 * 60 * 24 * 365.25;
		var result = eval((ageondate - birthdate)/one_year);
  	if (adult != true && result < 13) {
			alert ("We are sorry you must be over 13 at the conference to volunteer as a team member");
			this_field.checked = false;
			checkDoBFee(day,month,year,rownum,'false','false');
			return;
		}
	}
}
function setadult(status,rownum,worker,deposit) {
	var year_field ="document.forms.delegates.dob"+rownum+"Year";
	year_field2 = eval(year_field);
	var month_field ="document.forms.delegates.dob"+rownum+"Month";
	month_field2 = eval(month_field);
	var day_field ="document.forms.delegates.dob"+rownum+"Day";
	day_field2 = eval(day_field);
	if (status != false) {
		year_field2.selectedIndex=0;
		month_field2.selectedIndex=0;
		day_field2.selectedIndex=0;	
		checkDoBFee('12','5','1971',rownum,worker,deposit);
	}
}
function calc_total(delegate_count) {
	var run_total=0;
	var mainval= parseInt(document.getElementById('fee_main').value);
	for (var x = 1; x <delegate_count; x++){
		var field='fee'+x;
      	var inpval= parseInt(document.getElementById(field).value);
      	run_total = run_total + inpval;
   }
	document.getElementById('total').value = run_total+mainval;
}
function change_deposit(this_field,fee_field,deposit_value,month_field,day_field,year_field,row,adult,worker) {
	if (worker != true && fee_field.value != "0.00") {
		if (this_field.checked == true) {
			fee_field.value=deposit_value;
		} else {
			if (adult == true) {
				checkDoBFee('12','5','1971',row,worker,this.field.checked);
			} else  {
				checkDoBFee(month_field,day_field,year_field,row,worker,this_field.checked);			
			}	
		}
	}
}
function change_worker(this_field,fee_field,month,day,year,row,adult,deposit,deposit_value,worker_num,del_count) {
		// count the number of workers ticked
	// get number of workers selected previously
	worker_check=number_of_workers(del_count);
	if (worker_check <= worker_num) {
	} else {
		this_field.checked=false;
		alert ("You have already selected all the workers for your booking");
		return;
	}
	if (this_field.checked == true) {
   	var birthdate=new Date(year, month-1, day);
		var ageon_array=ageon.split("-");
		var ageondate=new Date(ageon_array[0], ageon_array[1]-1, ageon_array[2]);
		var one_year=1000 * 60 * 60 * 24 * 365.25;
		var result = eval((ageondate - birthdate)/one_year);
		if (adult != true && result < 13) {
			alert ("We are sorry you must be over 13 at the conference to volunteer as a team member");
			this_field.checked = false;
			return;
		}
		fee_field.value="0.00";
	} else {
		if (deposit != true) {
			if (adult == true) {
				checkDoBFee('12','5','1971',row,this_field.checked,'false');
			} else {
				checkDoBFee(month,day,year,row,this_field.checked,'false');			
			}
		} else {
			fee_field.value=deposit_value;	
		}	
	}
}
function change_offsite(offsite,parent_worker,adult,month,day,year) {
	var birthdate=new Date(year, month-1, day);
	var ageon_array=ageon.split("-");
	var ageondate=new Date(ageon_array[0], ageon_array[1]-1, ageon_array[2]);
	var one_year=1000 * 60 * 60 * 24 * 365.25;
	var result = eval((ageondate - birthdate)/one_year);
	if (offsite.checked == true && result < 14 && adult != true) {
		alert ("Children staying off site should be staying with a responsible adult");
	}
}
function check_main_worker(thisform,thisbox,eventid) {
	if (thisbox.checked==true) {
		thisform.fee.value="0.00";
		thisform.deposit.value="0.00";
	} else {
		if (thisform.adult.checked == true) {
			doGetFees(eventid,'1971','12','3');			
		} else {
			doGetFees(eventid,thisform.DOBYear.value,thisform.DOBMonth.value,thisform.DOBDay.value);
		}
	}
}
function clear_email() {
	if (document.getElementById('email2_form')) { 
		document.getElementById('email2_form').firstChild.nodeValue='';
	}
}
function number_of_workers(del_count) {
			var worker_count=0;
	    for (var i=1; i < del_count; i++) {
          var field="document.forms.delegates.worker"+i;
          var field2=eval(field);
          if (field2.checked == true) {
          	worker_count++;
          }
     	}
     	return worker_count;
}
function validateMembershipOnSubmit() {
	var elem;
	var errs=0;
	var error_fields="";
	if (document.forms.main.spouse.value == "true") {
		if (!validatePresent(document.forms.main.spouse_christian_name,  's_christian_form','true'))   {
		     errs += 1; 
				 error_fields +="Your Spouse's Christian Name\n";
		}
		if (!validatePresent(document.forms.main.spouse_surname,  's_surname_form','true'))  {
			errs += 1;
			error_fields +="Your Spouse's Surname\n";
		} 
		if (!validatePresent(document.forms.main.spouse_email,  's_email_form','true'))   {
		     errs += 1; 
			 error_fields +="Your Spouse's Email\n";
		}
	}
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.
if (!validatePresent(document.forms.main.church_attended, 'church_attended_form') && !validatePresent(document.forms.main.church_town, 'church_attended_form')&& !validatePresent(document.forms.main.church_pc, 'church_attended_form') ) {
	errs += 1; 
	error_fields +="Your Church Details\n";
}
	if (!validatePresent(document.forms.main.leader, 'leader_form')) {
		error_fields +="Your Church Leader's Name\n";
		errs += 1;
	}
	if (!validateTelnr(document.forms.main.office_tel, 'office_tel_form', true)) {
		error_fields +="Your Church's Telephone Number\n";
		errs += 1;
	}
	if(!validateTelnr(document.forms.main.Tel_Home,'home_form','true') && !validateTelnr(document.forms.main.Tel_Work,'work_form','true') && !validateTelnr(document.forms.main.Tel_Mob,'mobile_form','true')) {
		errs += 1;
		error_fields +="A Contact Phone Number\n";
	} 
	if (!validateEmail(document.forms.main.email, 'email_form', true)) {
		error_fields +="Your Email Address\n";
		errs += 1;
	}
if (!validatePresent(document.forms.main.address1, 'address1_form') && !validatePresent(document.forms.main.postcode, 'postcode_form') ) {
		errs+=1;
		error_fields +="Your Full Address Details\n";
	  show('full_address');
	}
	if (!validatePresent(document.forms.main.job_title,  'job_title_form','true'))   {
		     errs += 1; 
				 error_fields +="Your Job Title\n";
	}
	if (!validatePresent(document.forms.main.christian_name,  'christian_form','true'))   {
		     errs += 1; 
				 error_fields +="Your Christian Name\n";
	}
	if (!validatePresent(document.forms.main.surname,  'surname_form','true'))  {
		errs += 1;
		error_fields +="Your Surname\n";
	} 
	if (!validateSelectBox(document.forms.main.title,'title_form','true') ) {
		error_fields +="Your title\n";
		errs += 1;
	}   
 	
	if (errs>1)  alert('There are fields which need correction before sending\n'+error_fields);
	if (errs==1) alert('There is a field which needs correction before sending\n'+error_fields);
	return (errs==0);
}
function validateDonateOnSubmit() {
	var elem;
	var errs=0;
	var error_fields="";
	// execute all element validations in reverse order, so focus gets
	// set to the first one in error.

 	if (document.forms.main.donation_amount[4].checked==true && !validateNumeric(document.forms.main.other_amount,'donate_form','true')) {
		error_fields +="Your Donation Amount\n";
		errs += 1;
	} 
	if(document.forms.main.email.value != document.forms.main.email_c.value ) {
		msg('email_c_form','error','Email Addresses don\'t match');
		errs += 1;
		error_fields +="Your Email Addresses don't match\n";
	}  
	if(!validateEmail(document.forms.main.email,'email_form','true') ) {
		errs += 1;
		error_fields +="A Valid Email Address\n";
	}  
	if(!validateTelnr(document.forms.main.Tel_Home,'home_form','true') ) {
		errs += 1;
		error_fields +="A Contact Phone Number\n";
	} 
if (!validatePresent(document.forms.main.address1, 'address1_form') && !validatePresent(document.forms.main.postcode, 'postcode_form') && !validatePresent(document.forms.main.town, 'address2_form', 'true')) {
		errs+=1;
		error_fields +="Your Full Address Details\n";
	  show('full_address');
	}

	if (!validatePresent(document.forms.main.christian_name,  'christian_form','true'))   {
		     errs += 1; 
				 error_fields +="Your Christian Name\n";
	}
	if (!validatePresent(document.forms.main.surname,  'surname_form','true'))  {
		errs += 1;
		error_fields +="Your Surname\n";
	} 
	if (!validateSelectBox(document.forms.main.title,'title_form','true') ) {
		error_fields +="Your title\n";
		errs += 1;
	}   
 	
	if (errs>1)  alert('There are fields which need correction before sending\n'+error_fields);
	if (errs==1) alert('There is a field which needs correction before sending\n'+error_fields);
	return (errs==0);
}
function check_amount() {
	// get which one is checked
	var j=document.forms.main.donation_amount.length; 
	for (i=0; i<j; i++){
		if(document.forms.main.donation_amount[i].checked) {
				if (document.forms.main.donation_amount[i].value != "other") {
					document.getElementById('gift_aid_amount').value =document.forms.main.donation_amount[i].value;
				} else {
					document.getElementById('gift_aid_amount').value =document.getElementById('donate_other_value').value;			
				}
		}
	}	
	if (document.getElementById('donate_other_value').value != "") {
		document.forms.main.donation_amount[j-1].checked=true;
	}
}
function check_email() {
		if(document.forms.main.email.value != document.forms.main.email_c.value ) {
		msg('email_c_form','error','Email Addresses don\'t match');
	}  
}