// Form constants

var NUMBER_OF_COURSES = 30;
var DAY_ONE = "Day 1: Mon 21 June";
var DAY_TWO = "Day 2: Tues 22 June";

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 21 June","");
			options[1]=new Option("Building your Senior Management Team (ASE4)","ASE4");
			options[2]=new Option("Schmoozing: Effective Networking Skills (AIC1)","AIC1");
			options[3]=new Option("Better Success with Fundraising Materials (AFS3)","AFS3");
			//options[4]=new Option("Campaigns: Strategy and Planning (ACP5)","ACP5");
			options[4]=new Option("Charities and Trading (ALE3)","ALE3");
			options[5]=new Option("Community Fundraising in 2010 (AFS5)","AFS5");
			options[6]=new Option("Delegation - can’t someone else do it? (APM1)","APM1");
			options[7]=new Option("Developing the Culture for Your Organisation (ASE2)","ASE2");
			options[8]=new Option("Don’t Just Get Through the Recession- Get Stronger (AMM4)","AMM4");
			//options[10]=new Option("Duties of a Company Secretary (ALE5)","ALE5");
			//options[10]=new Option("Duties of a Trustee (ALE2)","ALE2");
			options[9]=new Option("Everyone’s Got A Strategy... (AMM5)","AMM5");
			options[10]=new Option("Finance for Non Finance People (AFM1)","AFM1");
			options[11]=new Option("Fundraising Law and Intellectual Property (ALE4)","ALE4");
			options[12]=new Option("Getting Money from Government (AMM2)","AMM2");
			options[13]=new Option("Getting your Stories into the Media (AIC3)","AIC3");
			options[14]=new Option("What Is the Best Sustainable Income? (AFS4)","AFS4");
			options[15]=new Option("Influencing Decision Makers  (ACP1)","ACP1");
			options[16]=new Option("Is Relationship Fundraising a Myth or a Reality? (AMM3)","AMM3");
			options[17]=new Option("Leadership of Charities – Priorities for the Future (ASE1)","ASE1");
			options[18]=new Option("Leaflets, Brochures, Articles et al (AIC5)","AIC5");
			options[19]=new Option("Legacy Visions - What Are They and Why They Are So Important? (AFS2)","AFS2");
			options[20]=new Option("Managing Absence  (AHR1)","AHR1");
			options[21]=new Option("Managing People Remotely  (APM2)","APM2");
			options[22]=new Option("Managing the Appraisal Process (AHR3)","AHR3");
			options[23]=new Option("Marketing your Campaign (ACP3)","ACP3");
			options[24]=new Option("Mergers and Collaboration (AFM2)","AFM2");
			options[25]=new Option("Mobilising Support through Networking & Communication (ACP2)","ACP2");
			options[26]=new Option("Motivation Matters  (AHR4)","AHR4");
			options[27]=new Option("Preparing Charity Accounts (AFM3)","AFM3");
			options[28]=new Option("Project Management (APM5)","APM5");
			options[29]=new Option("Pros and Cons of the New CIO Structure (ALE1)","ALE1");
			options[30]=new Option("Shout the Loudest (AIC4)","AIC4");
			options[31]=new Option("Strengthening Governance Through Codes of Conduct (ASE3)","ASE3");
			options[32]=new Option("Super Self Esteem and Confidence (AHR2)","AHR2");
			options[33]=new Option("Support & supervision of staff (APM4)","APM4");
			options[34]=new Option("Time Management (APM3)","APM3");
			options[35]=new Option("Utilising Local Media for Promotion and Marketing (ACP4)","ACP4");
			options[36]=new Option("VAT Update (AFM4)","AFM4");
			options[37]=new Option("Why Are Proposals So Boring? (AFS1)","AFS1");
			options[38]=new Option("Why Companies Want to Give Money? (AMM1)","AMM1");
			options[39]=new Option("Writing a Budget (AFM5)","AFM5");
			options[40]=new Option("‘Who do you think you are’ - Myers Briggs (AHR5)","AHR5");
			
			//options[44]=new Option("Winning people over - attention grabbing (AIC2)","AIC2");
			//options[45]=new Option("Writing a Budget (AMM1)","AMM1");
			//options[46]=new Option("Writing effective fundraising letters and proposals (AFM6)","AFM6");
		}
		if (Indx==2)   
		{
			options[0]=new Option("Choose a session for Tuesday 22 June","");
			options[1]=new Option("Strategic Planning (BSE1)","BSE1");  
			options[2]=new Option("Quaint or Quirky? Inspirational Fundraising (BSM4)","BSM4");    
			options[3]=new Option("Career Development (BHR2)","BHR2");       
			options[4]=new Option("Change Management (BSE4)","BSE4");		
			options[5]=new Option("Communicate to Influence (BIC5)","BIC5"); 		
			options[6]=new Option("Developing More Sustainable Fundraising Sources (BFS3)","BFS3"); 
			options[7]=new Option("Developing Team Performance (BPM3)","BPM3"); 	
			options[8]=new Option("Drawing up a Business Plan (BSE3)","BSE3");
			options[9]=new Option("Effective Internal Communications (BHR3)","BHR3"); 
			options[10]=new Option("Emotional Intelligence for Leaders (BSE5)","BSE5"); 
			options[11]=new Option("Financially Managing Grants and Contracts (BFM1)","BFM1");
			options[12]=new Option("Great Writing Made Simple (BIC3)","BIC3");
			options[13]=new Option("How Social Media Can Help Achieve your Goals (BSM1)","BSM1");
			options[14]=new Option("How to make the Ask (BSM2)","BSM2");
			options[15]=new Option("How to Manage your Above and Below Average Performers (BPM2)","BPM2");
			options[16]=new Option("Individual Donors - Are you Missing Out? (BFS2)","BFS2");
			options[17]=new Option("Legal Structures for Social Enterprise (BLE4)","BLE4");
			options[18]=new Option("Maintaining Staff Morale During Change (BPM4)","BPM4");
			//options[19]=new Option("Managing Risk (BLE3)","BLE3");
			options[19]=new Option("Managing Staff Learning and Development (BHR5)","BHR5");
			options[20]=new Option("Managing Volunteers (BMV1)","BMV1");
			options[21]=new Option("Mergers, Partnerships & Collaborative Working (BLE5)","BLE5");
			options[22]=new Option("Money Laundering (BFM4)","BFM4");
			options[23]=new Option("Monitoring & Evaluation (BPM5)","BPM5");
			options[24]=new Option("PAYE Top Tips - Employees to Volunteers (BFM5)","BFM5");
			//options[26]=new Option("Posh Frocks and Dicky Bows (BSM3)","BSM3");
			options[25]=new Option("Presentations with Punch (BIC4)","BIC4");
			options[26]=new Option("Presenting Financial Information Favourably (BFM2)","BFM2");
			options[27]=new Option("Promoting Mental Health and Well being in the Workplace (BHR4)","BHR4");
			options[28]=new Option("Raising Money from Trusts (BFS1)","BFS1");
			options[29]=new Option("Recruiting Volunteers (BMV3)","BMV3"); 
			options[30]=new Option("Retaining Volunteers (BMV4)","BMV4"); 
			options[31]=new Option("Secrets of a Successful E-newsletter (BIC2)","BIC2"); 
			options[32]=new Option("SORP - Accounting and financial reporting update including reporting on public benefit (BFM3)","BFM3"); 
			options[33]=new Option("Sustainable Funding - Considering the Options (BFS5)","BFS5"); 
			options[34]=new Option("Top Employment Law Pitfalls (BLE1)","BLE1"); 
			options[35]=new Option("Training Volunteers (BMV5)","BMV5"); 
			options[36]=new Option("Understanding your Memorandum and Articles of Association and improving your Governance (BLE2)","BLE2"); 
			options[37]=new Option("Volunteers and the Law (BMV2)","BMV2"); 
			options[38]=new Option("What is your Management Style? (BPM1)","BPM1");
			options[39]=new Option("Writing an HR Strategy (BHR1)","BHR1"); 
			options[40]=new Option("Writing Effective Fundraising Letters and Proposals (BFS4)","BFS4"); 
			options[41]=new Option("Writing for the Web (BIC1)","BIC1"); 
			//options[44]=new Option("Why are proposals so boring? (BFM2)","BFM2"); 
			//options[45]=new Option("Why companies want to give money (BFS5)","BFS5"); 
			//options[46]=new Option("Working with your trustees and building your board (BLS5)","BLS5");
				}
		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();
	//price1 = getCost(getSelectedCourses());
	//document.getElementById("cost" + row).value = price1;

	calculateCost();
}

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);
		
}

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("GrandTotal").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);
	}
}


function termsWindow(){
	terms_window = open("terms.html","terms",'scrollbars,width=600,height=700');
}
