function getCampsite(what) 
{
    if (what.value != '') 
	{
        var camp_site = what.value;
		alert ($camp_site);
    }
}
function getCategory(what) {
    if (what.value != '') {
        var category_selected = what.value;
        document.location=('view_service_provider_details.php?cat=' + category_selected);
    }
}
function getCompany(what) {
    if (what.value != '') {
        var category_selected = document.service_select.cat_sel.value;
        var company = what.value;
        document.location=('view_service_provider_details.php?cat=' + category_selected + '&comp=' + company);
    }
}
function ShowUser(who) {
    if (who.value != '') {
        var user_selected = who.value;
        document.location=('view_user_details.php?user=' + user_selected);
    }
}
function JavaPreviewMessage(mess_id,page_num) {
	if (mess_id != '') {
        var mess_selected = mess_id;
		document.location=('display_message.php?mode=preview&mess_id=' + mess_selected + '&page=' + page_num);
    }
}
function JavaShowMessage(mess_id) {
    if (mess_id != '') {
        var mess_selected = mess_id;
        document.location=('display_message.php?mode=show&mess_id=' + mess_selected);
    }
}
function CheckUserInput()
{
		if (document.signin.username.value=="")
  	{
		alert("Please Enter a Username");
		document.signin.username.focus();
		return false;
  	}
		if (document.signin.password.value=="")
  	{
	  	alert("Please Enter a Password");
	  	document.signin.password.focus();
		return false;
  	}
		return true;
}
function CheckPasswordInput(mode)
{
	if (mode=="request")
		{
			if (document.forms['password'].username.value=="")
  			{
			alert("Please enter a username");
			document.forms['password'].username.focus();
			return false;
  			}
		if (document.forms['password'].email.value=="")
  			{
	  		alert("Please enter an email address");
	  		document.forms['password'].email.focus();
			return false;
  			}
			return true;
		}
	if (mode=="reset")
		{
		if (document.password.old_password.value=="")
  			{
			alert("Please Enter a old Password");
			document.forms['password'].password.focus();
			return false;
  			}
		if (document.forms['password'].new_password.value=="")
  			{
	  		alert("Please Enter a new Password");
	  		document.forms['password'].password.focus();
			return false;
  			}
		if (document.forms['password'].confirm_password.value=="")
  			{
	  		alert("Please confirm new Password");
	  		document.forms['password'].confirm_password.focus();
			return false;
  			}
		if (document.forms['password'].new_password.value!=document.forms['password'].confirm_password.value)
			{
			alert("New passwords do not match");
	  		document.forms['password'].new_password.focus();
			return false;
  			}
			return true;
		}

}
function MM_findObj(n, d) 
{
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) 
{
var obj = MM_findObj(objName); if (obj) obj.value = obj.value + newText;
}

function GetFeederSchools(name)
{
	document.location=('schools.php?&show=venue&mode=look&sort=name&name=' + name );
}
function AddNewSchool(name)
{
	document.location=('school.php?mode=create&show=venue&name=' + name );
}
function RemoveSchool(school_id,name)
{
	document.location=('school.php?mode=confirm&show=venue&school_id=' + school_id + '&name=' + name);
}
function DeleteSchool(school_id,name)
{
	document.location=('school.php?mode=delete&show=venue&school_id=' + school_id + '&name=' + name);
}
function RemoveChild(child_id)
{
	document.location=('child.php?mode=confirm&show=child&child_id=' + child_id);
}
function DeleteChild(child_id)
{
	document.location=('child.php?mode=delete&show=child&child_id=' + child_id);
}
function RemoveSite(site_id)
{
	document.location=('site.php?mode=confirm&show=venue&site_id=' + site_id);
}
function DeleteSite(site_id)
{
	document.location=('site.php?mode=delete&show=venue&site_id=' + site_id);
}
function RemoveCoach(coach_id)
{
	document.location=('coach.php?mode=confirm&show=coach&coach_id=' + coach_id);
}
function DeleteCoach(coach_id)
{
	document.location=('coach.php?mode=delete&show=coach&coach_id=' + coach_id);
}
function RemoveCamp(camp_id)
{
	document.location=('camp.php?mode=confirm&show=camp&camp_id=' + camp_id);
}
function DeleteCamp(camp_id)
{
	document.location=('camp.php?mode=delete&show=camp&camp_id=' + camp_id);
}
function SortByAge(mode,show,camp_id)
{
	document.location=('children.php?mode=' + mode + '&show=' + show + '&sort=age&number=%&camp_id=' + camp_id);
}
function SortByName(mode,show,camp_id)
{
	document.location=('children.php?mode=' + mode + '&show=' + show + '&sort=last_name&letter=%&camp_id=' + camp_id);
}
function SortByTown(mode,show,camp_id)
{
	document.location=('children.php?mode=' + mode + '&show=' + show + '&sort=town&camp_id=' + camp_id);
}
function SortSiteByCapacity()
{
	document.location=('sites.php?mode=look&show=venue&sort=capacity');
}
function SortSiteByName()
{
	document.location=('sites.php?mode=look&show=venue&sort=name');
}
function CampSortByName()
{
	document.location=('camps.php?mode=look&show=camp&sort=name');
}
function CampSortByDate()
{
	document.location=('camps.php?mode=look&show=camp&sort=date');
}
function SetAllWeek(time,camp)
{
	var cost=eval("document.forms.child." + time + "_cost_" + camp);
	var all_week=eval("document.forms.child.all_"  + time + "_" + camp);
	var rate=eval("document.forms.child." + time + "_week_rate_" + camp);
	var monday=eval("document.forms.child.mon_" + time + "_" + camp);
	var tuesday=eval("document.forms.child.tue_" + time + "_" + camp);
	var wednesday=eval("document.forms.child.wed_" + time + "_" + camp);
	var thursday=eval("document.forms.child.thur_" + time + "_" + camp);
	var friday=eval("document.forms.child.fri_" + time + "_" + camp);
	var mon=eval("document.forms.child.mon_" + camp);
	var tue=eval("document.forms.child.tue_" + camp);
	var wed=eval("document.forms.child.wed_" + camp);
	var thur=eval("document.forms.child.thur_" + camp);
	var fri=eval("document.forms.child.fri_" + camp);

	cost.value=0
	if (all_week.checked)
	{cost.value=parseFloat(rate.value);
	if (mon.value=="on")
		{monday.checked=true;}
	if (tue.value=="on")
		{tuesday.checked=true;}
	if (wed.value=="on")
		{wednesday.checked=true;}
	if (thur.value=="on")
		{thursday.checked=true;}
	if (fri.value=="on")
		{friday.checked=true;}
	}
	if (!all_week.checked)
	{cost.value=0;
	if (mon.value=="on")
		{monday.checked=false;}
	if (tue.value=="on")
		{tuesday.checked=false;}
	if (wed.value=="on")
		{wednesday.checked=false;}
	if (thur.value=="on")
		{thursday.checked=false;}
	if (fri.value=="on")
		{friday.checked=false;}
	}
	TotalWeek(camp);

}
function CheckWeek(time,camp)
{
	var rate=eval("document.forms.child." + time + "_week_rate_" + camp);
	var cost=eval("document.forms.child." + time + "_cost_" + camp);
	var all_week=eval("document.forms.child.all_"  + time + "_" + camp);
	var monday=eval("document.forms.child.mon_" + time + "_" + camp);
	var tuesday=eval("document.forms.child.tue_" + time + "_" + camp);
	var wednesday=eval("document.forms.child.wed_" + time + "_" + camp);
	var thursday=eval("document.forms.child.thur_" + time + "_" + camp);
	var friday=eval("document.forms.child.fri_" + time + "_" + camp);
	var mon_camp=eval("document.forms.child.mon_" + camp);
	var tue_camp=eval("document.forms.child.tue_" + camp);
	var wed_camp=eval("document.forms.child.wed_" + camp);
	var thur_camp=eval("document.forms.child.thur_" + camp);
	var fri_camp=eval("document.forms.child.fri_" + camp);
	var camp_num_days=0;
	var camping_num_days=0;
		if (mon_camp.value=="on")
			{camp_num_days=camp_num_days+1;}
		if (tue_camp.value=="on")
			{camp_num_days=camp_num_days+1;}
		if (wed_camp.value=="on")
			{camp_num_days=camp_num_days+1;}
		if (thur_camp.value=="on")
			{camp_num_days=camp_num_days+1;}
		if (fri_camp.value=="on")
			{camp_num_days=camp_num_days+1;}
		if (monday.checked)
			{camping_num_days=camping_num_days+1;}
		if (tuesday.checked)
			{camping_num_days=camping_num_days+1;}
		if (wednesday.checked)
			{camping_num_days=camping_num_days+1;}
		if (thursday.checked)
			{camping_num_days=camping_num_days+1;}
		if (friday.checked)
			{camping_num_days=camping_num_days+1;}
		if (camp_num_days==camping_num_days)
			{
				all_week.checked=true; 
				SetAllWeek(time,camp);
			} 
			else
				{	
					all_week.checked=false;
					cost.value=0;
				}
}
function CalculateBalance(camp,cost)
{
	if (!cost) cost=eval("document.forms.child.cost_" + camp + ".value");
	paid=eval("document.forms.child.received_" + camp);
	bal=parseFloat(cost)-parseFloat(paid.value);
	balance=eval("document.forms.child.balance_" + camp);
	balance.value=bal.toFixed(2);
}
function CalculateCosts(period,time,camp)
{
		var monday=eval("document.forms.child.mon_" + time + "_" + camp);
		var tuesday=eval("document.forms.child.tue_" + time + "_" + camp);
		var wednesday=eval("document.forms.child.wed_" + time + "_" + camp);
		var thursday=eval("document.forms.child.thur_" + time + "_" + camp);
		var friday=eval("document.forms.child.fri_" + time + "_" + camp);
		var rate=eval("document.forms.child." + time + "_rate_" + camp);
		var cost=eval("document.forms.child." + time + "_cost_" + camp);
		var day=eval("document.forms.child." + period + "_cost_" + camp);
		var late=eval("document.forms.child." + period + "_cost_" + camp);
		var all_week=eval("document.forms.child.all_"  + time + "_" + camp);
		var total_cost=eval("document.forms.child.cost_" + camp);
		var total=0;
	CheckWeek(time,camp);
	if (all_week.checked==false)
		{	
		if (monday.checked==true) 
		 	{	total=(parseFloat(cost.value)+parseFloat(rate.value));
 				cost.value=parseFloat(total);
			}
		if (tuesday.checked==true) 
		 	{	total=(parseFloat(cost.value)+parseFloat(rate.value));
 				cost.value=parseFloat(total);
			}
		if (wednesday.checked==true) 
		 	{	total=(parseFloat(cost.value)+parseFloat(rate.value));
 				cost.value=parseFloat(total);
			}
		if (thursday.checked==true) 
		 	{	total=(parseFloat(cost.value)+parseFloat(rate.value));
 				cost.value=parseFloat(total);
			}
		if (friday.checked==true) 
		 	{	total=(parseFloat(cost.value)+parseFloat(rate.value));
 				cost.value=parseFloat(total);
			}
		TotalWeek(camp);
		}
}
function TotalWeek(camp)
{
	var total=eval("document.forms.child.cost_" + camp);
	var early=eval("document.forms.child.early_cost_" + camp);
	var day=eval("document.forms.child.day_cost_" + camp);
	var late=eval("document.forms.child.late_cost_" + camp);
	var early_check=eval("document.forms.child.all_early_" + camp);
	var day_check=eval("document.forms.child.all_day_" + camp);
	var late_check=eval("document.forms.child.all_late_" + camp);
	var full_discount=eval("document.forms.child.full_discount_" + camp);
	var family_discount=eval("document.forms.child.family_discount_" + camp);
	var family_check=eval("document.forms.child.family_" + camp);
		if (day_check.checked)
		{
			total.value=parseFloat(early.value)+parseFloat(late.value)+parseFloat(day.value);
		}
		if (early_check.checked && late_check.checked)
		{
			total.value=(parseFloat(early.value)+parseFloat(day.value)+parseFloat(late.value))-parseFloat(full_discount.value);
		}
		else
		{
			total.value=parseFloat(early.value)+parseFloat(day.value)+parseFloat(late.value);
		}
		CalculateBalance(camp,total.value);
}
function getCamp(what,mode,child_id) {
    if (what.value != '') {
        var camp_selected = what.value;
        document.location=('child.php?mode=addtocamp&show=child&camp=' + camp_selected + '&child_id=' + child_id);
		}
}

function getCampDates(what) {
    if (what.value != '') {
        var camp_selected = document.service_select.cat_sel.value;
        var camp_date = what.value;
        document.location=('child.php?mode=addtocamp&show=child&camp=' + camp_selected + '&camp_date=' + camp_date);
    }
}

function ValidateCamp()
{
    var from_day=eval(document.forms['camp'].day_from.value);
	var from_month=eval(document.forms['camp'].month_from.value);
	var from_year=eval(document.forms['camp'].year_from.value);
	var to_day=eval(document.forms['camp'].day_to.value);
	var to_month=eval(document.forms['camp'].month_to.value);
	var to_year=eval(document.forms['camp'].year_to.value);
	
	if (document.forms['camp'].campsite.selectedIndex == 0)
		{alert ("You must select a site for the camp");
		document.forms['camp'].campsite.focus;
		return false
		}
	if (document.forms['camp'].day_from.selectedIndex == 0)
		{alert ("You must select a date for the camp");
		document.forms['camp'].day_from.focus;
		return false
		}
	if (document.forms['camp'].month_from.selectedIndex == 0)
		{alert ("You must select a date for the camp");
		document.forms['camp'].month_from.focus;
		return false
		}
	if (document.forms['camp'].year_from.selectedIndex == 0)
		{alert ("You must select a date for the camp");
		document.forms['camp'].year_from.focus;
		return false
		}
	if (document.forms['camp'].day_to.selectedIndex == 0)
		{alert ("You must select a date for the camp");
		document.forms['camp'].day_to.focus;
		return false
		}
	if (document.forms['camp'].month_to.selectedIndex == 0)
		{alert ("You must select a date for the camp");
		document.forms['camp'].month_to.focus;
		return false
		}
	if (document.forms['camp'].year_to.selectedIndex == 0)
		{alert ("You must select a date for the camp");
		document.forms['camp'].year_to.focus;
		return false
		}
	return true
 }
function NewChild()
{
	document.location=('child.php?mode=create&show=child');
}
function ChildCampRegister(child_id)
{
	document.location=('child.php?mode=addtocamp&show=child&child_id=' + child_id);
}
function CheckName(camp,index) 
{
    document.location=('child.php?mode=find&show=child&camp_id=' + camp + '&SearchField=' + escape(document.child['last_name[0]'].value));
}
function CallSearchWindow(SearchField,NumResults)  
{
        var url = 'children.php?mode=found&last_name=' + escape(SearchField);
 		var height = (NumResults * 20);
 		var options = 'scrollbars,resizable,width=800, height=400';
        winRef = window.open(url,'SearchWindow',options);
		if (window.focus) {winRef.focus()};
}
function PopulateChild(child,camp)
{
	window.opener.location.href='child.php?mode=addtocamp&show=child&child_id=' + child + '&camp_id=' + camp;
	window.setTimeout('window.close()',20);
}
function PopulateFamily(family,camp,name)
{
	window.opener.location.href='child.php?mode=addtofamily&show=child&family_id=' + family + '&camp_id=' + camp + '&last_name=' + name;
	window.setTimeout('window.close()',20);
}

function CloseWindow(name,camp)
{
		window.opener.location.href='child.php?mode=createnotfound&show=child&camp_id=' + camp + '&last_name=' + name;
		window.setTimeout('window.close()',20);
}
function CheckCamp(child_id) 
{
    document.location=('child.php?mode=campfind&show=child&campsite=' + escape(document.forms['child'].camp.value) + '&child_id=' + child_id);
}
function CheckCampRegister(child,camp_num) 
{
    document.location=('register.php?page=3&child=' + child + '&camp_num=' + camp_num + '&campsite=' + escape(document.register['camp[' + camp_num + ']'].value));
}
function GetCampDetails(child,camp_num)
{
    document.location=('register.php?page=3&mode=days&child=' + child + '&camp_num=' + camp_num + '&campsite=' + escape(document.register['camp[' + camp_num + ']'].value) + '&camp=' + escape(document.register['campdate[' + camp_num + ']'].value));	
}
function CallCampSearchWindow(campsite,child)  
{
        var url = 'camps.php?mode=found&campsite=' + escape(campsite) + '&child_id=' + escape(child);
        var options = 'scrollbars,resizable,width=804, height=200';
        window.open(url,'SearchWindow',options);
}
function PopulateCampChild(child,camp)
{
	window.opener.location.href='child.php?mode=addtocamp&show=child&child_id=' + child + '&camp_id=' + camp;
	window.setTimeout('window.close()',20);
}
function EditChildCamp(child,camp)
{
    document.location=('child.php?mode=editcamp&show=child&camp_id=' + camp + '&child_id=' + child);
	
}
function PrintOfferLetter(child)
{
    document.location=('child.php?mode=printcampletter&show=child&child_id=' + child);
}
function CreateChild()
{
	document.location=('child.php?mode=create&show=child');
}
function ViewCampers(camp)
{
	document.location=('children.php?mode=camp&show=camp&camp_id=' + camp)
}
function CalculateAge(num)
{
	var dd=eval("document.getElementById('dob_day_" + num + "')");
	var mm=eval("document.getElementById('dob_mon_" + num + "')");
	var yy=eval("document.getElementById('dob_year_" + num + "')");
	var out_age=eval("document.getElementById('age_" + num + "')");
	if (dd.value) 
		{
			if ((dd.value < 1) || (dd.value > 31)) 
			{alert ("day must be between 1 and 31 you entered " + dd.value);
			dd.focus();
			dd.value=0;
			dd.select();
			return false}
		}
	else 
		{
			return false
		}
	if (mm.value)
		{
			if ((mm.value < 1) || (mm.value > 12))
			{alert ("month must be between 1 and 12");
			setTimeout('mm.focus()',1);
			return false}
		}
	else
		{
			return false
		}
	if (yy.value)
		{
			if (yy.value<4)
			{ alert ("please enter full-year (yyyy)");
			setTimeout('yy.focus()',1);
			return false}
		}
	else
		{
			return false
		}

	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear = days.getFullYear();
	age = gyear - yy.value;
	if((mm.value == (gmonth + 1)) && (dd.value <= parseInt(gdate))) 
		{
		age = age;
		}
		else 
		{
		if(mm.value <= (gmonth)) 
		{
		age = age;
		}
		else 
		{
		age = age - 1; 
   		}}
	out_age.value=parseInt(age);
}
function CalculateAge2(num)
{
	var dd=eval("document.getElementById('dob_day')");
	var mm=eval("document.getElementById('dob_mon')");
	var yy=eval("document.getElementById('dob_year')");
	var out_age=eval("document.getElementById('age')");
	if (dd.value) 
		{
			if ((dd.value < 1) || (dd.value > 31)) 
			{alert ("day must be between 1 and 31 you entered " + dd.value);
			dd.focus();
			dd.value=0;
			dd.select();
			return false}
		}
	else 
		{
			return false
		}
	if (mm.value)
		{
			if ((mm.value < 1) || (mm.value > 12))
			{alert ("month must be between 1 and 12");
			setTimeout('mm.focus()',1);
			return false}
		}
	else
		{
			return false
		}
	if (yy.value)
		{
			if (yy.value<4)
			{ alert ("please enter full-year (yyyy)");
			setTimeout('yy.focus()',1);
			return false}
		}
	else
		{
			return false
		}

	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear = days.getFullYear();
	age = gyear - yy.value;
	if((mm.value == (gmonth + 1)) && (dd.value <= parseInt(gdate))) 
		{
		age = age;
		}
		else 
		{
		if(mm.value <= (gmonth)) 
		{
		age = age;
		}
		else 
		{
		age = age - 1; 
   		}}
	out_age.value=parseInt(age);
}
function chkAll(field)
{
		for (var i = 0; i < document.children["sel_child[]"].length; i++) {
		document.children["sel_child[]"][i].checked = field.checked }
}
function CheckChildTicks(field)
{
		if (document.child[field].checked)
			{ return true }
		for (var i = 0; i < document.child[field].length; i++) 
		{
		if (document.child[field][i].checked)
			{ return true }
		}
		alert ("You must make a selection first")
		return false
}
function CheckChildrenTicks(field)
{
		if (document.children[field].checked)
			{ return true }
		for (var i = 0; i < document.children[field].length; i++) 
		{
		if (document.children[field][i].checked)
			{ return true }
		}
		alert ("You must make a selection first")
		return false
}
function QualCheck(qual)
{
	if (qual.checked==true)
		{ field=qual.value;
		setTimeout("document.coach[field].focus()",100);
		}
	if (qual.checked==false)
		{ field=qual.value;
		document.coach[field].value="";
		}
}
function RegisterQualCheck(qual)
{
	if (qual.checked==true)
		{ field=qual.value;
		setTimeout("document.register[field].focus()",100);
		}
	if (qual.checked==false)
		{ field=qual.value;
		document.register[field].value="";
		}
}
function EditQual(leader,qual)
{
}
function CheckSelections()
{
		if ((document.forms['leader_ask'].search_town.value) && (document.forms['leader_ask'].search_postcode.value))
			{  
 			alert ("You can't enter both a postcode and a town to search");
			document.forms['leader_ask'].search_town.focus();
			return false;
			}
		if ((!document.forms['leader_ask'].search_town.value) && (!document.forms['leader_ask'].search_postcode.value))
			{ 
			alert ("You must enter either a postcode or a town to search");
			document.forms['leader_ask'].search_town.focus();
			return false ;
			}
}
function CheckRegistration()
{
		if (!document.forms['register'].first_name.value)
			{
				alert ("You must enter a first name");
				document.forms['register'].first_name.focus();
			}
		else if (!document.forms['register'].last_name.value)
			{
				alert ("You must enter a last name");
				document.forms['register'].last_name.focus();
			}
		else if (!document.forms['register'].email.value)
			{
				alert ("You must enter a email address");
				document.forms['register'].email.focus();
			}
		else if (!document.forms['register'].road.value)
			{
				alert ("You must enter an address");
				document.forms['register'].road.focus();
			}
		else if (!document.forms['register'].town.value)
			{
				alert ("You must enter a town");
				document.forms['register'].town.focus();
			}
		else if (!document.forms['register'].postcode.value)
			{
				alert ("You must enter a postcode");
				document.forms['register'].postcode.focus();
			}
		else if (!document.forms['register'].tel.value)
			{
				alert ("You must enter a telephone number");
				document.forms['register'].tel.focus();
			}
		else 
			{
				document.register.submit();
			}
}
function AssignCoach(camp_id,coach_id)
{
	document.location=('coaches.php?mode=assign&search=n&sort=last_name&camp_id=' + camp_id + '&coach_id=' + coach_id)
}
function DeassignCoach(coach_id,camp_id)
{
	document.location=('coaches.php?mode=deassign&search=n&sort=last_name&camp_id=' + camp_id + '&coach_id=' + coach_id)
}
function setFocus(field)
{
	focus_field=document.getElementById(field);
	focus_field.focus();
}
function OrderByCamp(sorttype,range,letter,number)
{
	camp_id=eval('document.forms[0].campname.value');
	document.location=('children.php?mode=look&show=child&sort=' + sorttype + '&letter=' + letter + '&range=' + range + '&number=' + number + '&camp_id=' + camp_id);
}