// Form constants

var NUMBER_OF_COURSES = 30; //30 booking lines
var DAY_ONE = "Day 1: Mon 27 June";
var DAY_TWO = "Day 2: Tues 28 June";
// Add lunch constant
var LUNCH_COST = 7.00;

function getDay(nDay)
{
	if (nDay == 1)
	{
		return DAY_ONE;
	}
	if (nDay == 2)
	{
		return DAY_TWO;
	}
}

function getSelectedCourses()
{
	var aCourseCodes = [];

	for (var row = 1 ; row <= NUMBER_OF_COURSES ; row++ )
	{
		var courseCode = document.getElementById("CourseCode" + row).value.toString();
		if (courseCode != "")
		{
			aCourseCodes.push(courseCode);

		// re - calculate the cost of all the courses of on the page
			document.getElementById("cost" + row).value = getCost(aCourseCodes);
		}
	}
	return aCourseCodes;
}

function ldMenu(mySubject, row) 
{
	var Indx=mySubject;

	with(document.getElementById("course" + row))
	{
		options.length=0;

		if (Indx==0)
		{
			options[0]=new Option("Pages appear here","");
		}
		if (Indx==1)
		{
			options[0]=new Option("Choose a session for Monday 27 June","");
			options[1]=new Option("Action Learning Sets (APM2)","APM2");
			options[2]=new Option("Adopting a Coaching Style of Management (APM1)","APM1");
			options[3]=new Option("All About Me (AMY1)","AMY1");
			options[4]=new Option("An Example of a Wonderful Campaign (ACS4)","ACS4");
			options[5]=new Option("Building your Senior Management Team (ABG4)","ABG4");
			options[6]=new Option("Campaigning & Lobbying Tips (ACL1)","ACL1");
			options[7]=new Option("Campaigning Strategy & Planning (ACL3)","ACL3");
			options[8]=new Option("Charities and Trading (ALE3)","ALE3");
			options[9]=new Option("Chief Exectuives and Chairs - A Partnership made in Heaven! (ABG1)","ABG1");
			options[10]=new Option("Community Fundraising - Top Tips (AFS2)","AFS2");
			options[11]=new Option("Cutting Edge Developments in Governance and Management (ABG2)","ABG2");
			options[12]=new Option("Don't Panic - A Structured Apprach to Dealing with Loss of Income (AMM2)","AMM2");
			options[13]=new Option("Duties of a Company Secretary (ALE1)","ALE1");
			options[14]=new Option("Duties of a Trustee (ALE2)","ALE2");
			options[15]=new Option("Earned Income Venture - an Alternative to Traditional Fundraising (ACS3)","ACS3");
			options[16]=new Option("Emotional Intelligence (AMY2)","AMY2");
			options[17]=new Option("Enewsletters (ACW2)","ACW2");
			options[18]=new Option("Events Fundraising  (AMM1)","AMM1");
			options[19]=new Option("Fundraising from Individuals - Getting it Right from the Start (AMM4)","AMM4");
			options[20]=new Option("Great Writing Made Simple (ACW4)","ACW4");
			options[21]=new Option("Hooking Interest from Companies (AFS3)","AFS3");
			options[22]=new Option("How Social Media can Help Achieve your Goals  (AMM5)","AMM5");
			options[23]=new Option("Major Donor Fundraising  (AFS5)","AFS5");
			options[24]=new Option("Managing Major Change (ACS1)","ACS1");
			options[25]=new Option("Marketing on Limited Budgets (ACW5)","ACW5");
			options[26]=new Option("Motivating Yourself and Others (AMY4)","AMY4");
			options[27]=new Option("NLP Communication (AMY3)","AMY3");
			options[28]=new Option("Personalities Matter? Being a Better Trustee  (ABG5)","ABG5");
			options[29]=new Option("Perspectives on Change (ACS2)","ACS2");
			options[30]=new Option("Practical Project Management (APM5)","APM5");
			options[31]=new Option("Press and Media Support (ACL2)","ACL2");
			options[32]=new Option("Ready for Bid Writing (AMM3)","AMM3");
			options[33]=new Option("Refreshing and Recruiting Board Members (ABG3)","ABG3");
			options[34]=new Option("Risk Management (ALE4)","ALE4");
			options[35]=new Option("Showing you Make a Difference (APM3)","APM3");
			options[36]=new Option("Super Self-Esteem and Assertiveness (AMY5)","AMY5");
			options[37]=new Option("Ten Golden Rules for Influencing Policy Makers (ACL5)","ACL5");
			options[38]=new Option("The Wild Idea Club (APM4)","APM4");
			options[39]=new Option("Understanding your Memorandum and Articles of Association and Improving your Governance (ALE5)","ALE5");
			options[40]=new Option("Using Story Telling to Develop People and Organisations (ACW3)","ACW3");
			options[41]=new Option("What is the Best Sustainable Income? (AFS4)","AFS4");
			options[42]=new Option("Why are Proposals so Boring? (AFS1)","AFS1");
			options[43]=new Option("Writing for the Web(ACW1)","ACW1");
			
			
		}
		if (Indx==2)   
		{
			options[0]=new Option("Choose a session for Tuesday 28 June","");
			options[1]=new Option("A-Z of HR for Beginners - Masterclass (BHR4)","BHR4");  
			options[2]=new Option("Business Planning in Tough Times (BSE3)","BSE3");    
			options[3]=new Option("Can we get Legacies? (BFS2)","BFS2");       
			options[4]=new Option("Communicate to Influence (BCS1)","BCS1");		
			options[5]=new Option("Creating High Performing Teams - Masterclass (BMY4)","BMY4"); 		
			options[6]=new Option("Dealing with Grievances (BHR3)","BHR3"); 
			options[7]=new Option("Delegation (BMY2)","BMY2"); 	
			options[8]=new Option("Developing More Sustainable Fundraising Sources (BMM2)","BMM2");
			options[9]=new Option("Developing your Fundraising Message (BFS1)","BFS1"); 
			options[10]=new Option("Encouraging a Self Leadership Culture (BMY1)","BMY1"); 
			options[11]=new Option("Finance for Non-Finance People (BFM2)","BFM2");
			options[12]=new Option("Fundraising for Beginners - Masterclass (BFS4)","BFS4");
			options[13]=new Option("Getting Better Results - Communicating Finances Effectively to Staff (BFM3)","BFM3");
			options[14]=new Option("Governance (BHR1)","BHR1");
			options[15]=new Option("Key Messaging for Charities - Masterclass (BCS4)","BCS4");
			options[16]=new Option("Leading in Stormy Weather (BSE1)","BSE1");
			options[17]=new Option("Managing Absence (BHR2)","BHR2");
			options[18]=new Option("Managing People Remotely (BPM1)","BPM1");
			options[19]=new Option("New to Management - Masterclass (BPM4)","BPM4");
			options[20]=new Option("Presentations with a Punch (BCS3)","BCS3");
			options[21]=new Option("Project Management (BPM2)","BPM2");
			options[22]=new Option("Psychology of Giving (BFS3)","BFS3");
			options[23]=new Option("Raising Money from Trusts (BMM1)","BMM1");
			options[24]=new Option("Recruiting, Inducting and Motivating Volunteers - Masterclass (BMV4)","BMV4");
			options[25]=new Option("Relationship Fundraising - Myth or Legend (BMM3)","BMM3");
			options[26]=new Option("Resilience - The Positive Capacity to Bounce Back (BMY3)","BMY3");
			options[27]=new Option("Schmoozing - Effective Networking Skills (BCS2)","BCS2");
			options[28]=new Option("Strategic Planning - Masterclass (BSE4)","BSE4");
			options[29]=new Option("Strategic Volunteer Management (BMV3)","BMV3");
			options[30]=new Option("The Future of Commissioning (BFM1)","BFM1");
			options[31]=new Option("Tools and Techniques for Problem Solving (BPM3)","BPM3"); 
			options[32]=new Option("Using Creativity to Facilitate Change (BSE2)","BSE2"); 
			options[33]=new Option("Volunteer Management (BMV1)","BMV1"); 
			options[34]=new Option("Volunteers and the Law (BMV2)","BMV2"); 
			options[35]=new Option("Writing a Budget - Masterclass (BFM4)","BFM4"); 
			options[36]=new Option("Writing Effectice Fundraising Letters and Proposals - Masterclass (BMM4)","BMM4"); 
			
				}
		options[0].selected=true;
	}
}

function Results(row, select)
{
	//Populate the course code box
	document.getElementById("CourseCode" + row).value = select.options[select.selectedIndex].value;

	//get the cost
	getSelectedCourses();
	calculateCost();   // Calculate grand tt

// Added new way of calculating course cost and lunch cost
// calculateCourseCost() is not yet implemented
//calculateCourseCost();

// calculateLunchCost() is not yet implemented properly
//calculateLunchCost();
//new way ends here
}

function check_form (){
		var terms_conditions = document.form1.terms_checkbox.checked;
		var check_name = document.form1.contact_name;
		var check_email = document.form1.email;
		var check_organisation = document.form1.organisation;
		var check_address = document.form1.address1;
		var check_telnumber = document.form1.tel;
		var check_postcode = document.form1.post_code;
		var check_confirm = document.form1.email_confirm;
	
		
		if (check_name.value == '')
		{
			alert("Please enter a contact name.");
			document.form1.contact_name.focus();
			return(false);
		}
		if (check_email.value == '')
		{
			alert("Please enter a valid email address.");
			document.form1.email.focus();
			return(false);
		}
		if (check_confirm.value == '')
		{
			alert("Please confirm your email address.");
			document.form1.email_confirm.focus();
			return(false);
		}
		if (check_organisation.value == '')
		{
			alert("Please enter the organisation name, if you do not have an organisation name then enter 'None'");
			document.form1.organisation.focus();
			return(false);
		}
		if (check_address.value == '')
		{
			alert("Please enter your full address including your post code.");
			document.form1.address1.focus();
			return(false);
		}
		if (check_postcode.value == '')
		{
			alert("Please enter your post code.");
			document.form1.post_code.focus();
			return(false);
		}
		if (check_telnumber.value == '')
		{
			alert("Please enter your telephone number.");
			document.form1.tel.focus();
			return(false);
		}		
	        
		if (terms_conditions == false)
		{
			alert("Please read and tick the terms & conditions checkbox.");
			document.form1.terms_checkbox.focus();
			return(false);
		}if (check_confirm.value == check_email.value) { return true; }

		{
			alert("Email addresses are different");
			document.form1.email.focus();
			return(false);
		}
		return(true);
		
}
//Old way of calculating cost

function calculateCost()
{
	var TotalCost = 0;
	
	for (var i = 1; i <= NUMBER_OF_COURSES; i++ )
	{
		if (document.getElementById("cost" + i).value != '')
		{
			TotalCost += parseFloat(document.getElementById("cost" + i).value);
		}
	}
	//display to two decimal places	
	document.getElementById("CourseTotal").value = TotalCost.toFixed(2);	

	//display early bird discount if one applies
	if (isEarlyBirdDiscountDate())
	{
		var discount = TotalCost * (1 - EARLY_BIRD_DISCOUNT_RATE);
		document.getElementById("DiscountTotal").value = discount.toFixed(2);
	}
	else
	{
		document.getElementById("DiscountTotal").value = TotalCost.toFixed(2);
	}

	// display GrandTotal
	calculateGrandTotal();
}

//Old way ends here

//Newly added way of calculating costs
function calculateLunchCost()
{
	var TotalCost = 0;
	
	for (var i = 1; i <= NUMBER_OF_COURSES; i++ )
	{
		TotalCost += parseFloat(document.getElementById("lunch" + i).value);
	}
	//display to two decimal places
	document.getElementById("LunchTotal").value = parseFloat(LUNCH_COST * TotalCost).toFixed(2);
	
	// Need to re-calculate the other totals
	calculateCost();
	
	
}
//Part of the new way commented out because it needs modifying
function calculateGrandTotal()
{
	var lunchTotal = parseFloat(document.getElementById("LunchTotal").value).toFixed(2);
	var discountTotal = parseFloat(document.getElementById("DiscountTotal").value).toFixed(2);
	
	with(document)
	{
		getElementById("GrandTotal").value = parseFloat(lunchTotal*1.00 + discountTotal*1.00).toFixed(2);
	}
}


function termsWindow(){
	terms_window = open("terms.html","terms",'scrollbars,width=600,height=700');
}

