// JavaScript Document
var valid = false;
var repV = false;

function validateForm() {
	//Declaring variables
	surname = document.getElementById("surname").value;
	firstNames = document.getElementById("firstNames").value;
	//email = document.getElementById("email").value;
	phone = document.getElementById("phone").value;
	surnameNominee = document.getElementById("surnameNominee").value;
	firstNamesNominee = document.getElementById("firstNamesNominee").value;
	innovation = document.getElementById("innovation").value;
	
	if (checkRepValue) {
		rep = document.getElementById("repValue").value;
	}
	
	//Declaring Boolean Variables
	var surnameV = false;
	var firstNamesV = false;
	//var emailV = false;
	var phoneV = false;
	var surnameNomineeV = false;
	var firstNameNomineeV = false;
	var innovationV = false;
	
	/**********************************
	 *  Checking all inputs are used  *
	 **********************************/
	
	//checking surname input
	if (surname == "") {
		surnameV = false;
		document.getElementById("surnameDiv").innerHTML = "Surame required.";
	} else {
		surnameV = true;
		document.getElementById("surnameDiv").innerHTML = "";
	}
	
	//checking first input
	if (firstNames == "") {
		firstNamesV = false;
		document.getElementById("firstnameDiv").innerHTML = "First name required.";
	} else {
		firstNamesV = true;
		document.getElementById("firstnameDiv").innerHTML = "";
	}
	
	//checking representing input
	if ((checkRepValue) && (rep == "")) {
		getRepDiv();
	} else {
		repV = true;
		document.getElementById("repDiv1").innerHTML = "";
		document.getElementById("repDiv2").innerHTML = "";
		document.getElementById("repDiv3").innerHTML = "";
	}
	
	//checking innovation input
	if (innovation == "") {
		innovationV = false;
		document.getElementById("innovationDiv").innerHTML = "Description of innovative work required.";
	} else {
		innovationV = true;
		document.getElementById("innovationDiv").innerHTML = "";
	}
	
	//checking surname input
	if (surnameNominee == "") {
		surnameNomineeV = false;
		document.getElementById("surnameNomineeDiv").innerHTML = "Surame required.";
	} else {
		surnameNomineeV = true;
		document.getElementById("surnameNomineeDiv").innerHTML = "";
	}
	
	//checking first input
	if (firstNamesNominee == "") {
		firstNameNomineeV = false;
		document.getElementById("firstnameNomineeDiv").innerHTML = "First name required.";
	} else {
		firstNameNomineeV = true;
		document.getElementById("firstnameNomineeDiv").innerHTML = "";
	}
	
	/**************************
	 *  Checking Valid email  *
	 **************************/
	 
	//apos = email.indexOf("@");
	//dotpos = email.indexOf(".", apos + 1);
	
	//if ((apos < 1) || ((dotpos - apos) < 2)) {
		//emailV = false;
		//document.getElementById("emailDiv").innerHTML = "Valid e-mail address required.";
	//} else {
		//emailV = true;
		//document.getElementById("emailDiv").innerHTML = "";
	//}
	
	/*************************************
	 *  Checking for valid phone number  *
	 *************************************/
	
	//checking mobile number input
	if ((phone == "") || (isNaN(phone))) {
		phoneV = false;
		document.getElementById("phoneDiv").innerHTML = "Provide real number.";
	} else {
		phoneV = true;
		document.getElementById("phoneDiv").innerHTML = "";
	}
	
	/***************************************************
	 *  Final check before form submission is allowed  *
	 ***************************************************/
	if (surnameV && firstNamesV && repV && phoneV && surnameNomineeV && firstNameNomineeV && innovationV) {
		valid = true;
	} else {
		valid = false;
	}
}

/***********************************
 *  Reports that form is complete  *
 ***********************************/
function isValid() {
	return valid;
}

/*****************
 *  Clears From  *
 *****************/
 function clearForm() {
	//clear inputs
	document.getElementById("surname").value = "";
	document.getElementById("firstNames").value = "";
	document.getElementById("relationship").value = "";
	document.getElementById("email").value = "";
	document.getElementById("phone").value = "";
	document.getElementById("fax").value = "";
	document.getElementById("surnameNominee").value = "";
	document.getElementById("firstNamesNominee").value = "";
	//document.naminateForm.rep[0].checked = checked;
	document.getElementById("innovation").value = "";
	if (checkRepValue) {
		document.getElementById("repValue").value = "";
	}
	
	document.getElementById("surnameDiv").innerHTML = "";
	document.getElementById("firstnameDiv").innerHTML = "";
	document.getElementById("repDiv1").innerHTML = "";
	document.getElementById("repDiv2").innerHTML = "";
	document.getElementById("repDiv3").innerHTML = "";
	//document.getElementById("emailDiv").innerHTML = "";
	document.getElementById("phoneDiv").innerHTML = "";
	document.getElementById("firstnameNomineeDiv").innerHTML = "";
	document.getElementById("surnameNomineeDiv").innerHTML = "";
	document.getElementById("innovationDiv").innerHTML = "";
 }
 
 /*************************************************
  *  Change position of Representative input box  *
  *************************************************/
  var checkRepValue = false;
  
  function repChangeState() {
	 
	 if (document.nominateForm.rep[0].checked) {
		 document.getElementById("repSchoolDiv").innerHTML = "";
		 document.getElementById("repChurchDiv").innerHTML = "";
		 document.getElementById("repOtherDiv").innerHTML = "";
		 document.getElementById("repDiv1").innerHTML = "";
	 	 document.getElementById("repDiv2").innerHTML = "";
	 	 document.getElementById("repDiv3").innerHTML = "";
		 checkRepValue = false;
	 }
	 
	 if (document.nominateForm.rep[1].checked) {
		 document.getElementById("repSchoolDiv").innerHTML = "<input name=\"repValue\" id=\"repValue\" size=\"30\" />";
		 document.getElementById("repChurchDiv").innerHTML = "";
		 document.getElementById("repOtherDiv").innerHTML = "";
		 document.getElementById("repDiv1").innerHTML = "";
		 document.getElementById("repDiv2").innerHTML = "";
	 	 document.getElementById("repDiv3").innerHTML = "";
		 checkRepValue = true;
	 }
	 
	 if (document.nominateForm.rep[2].checked) {
		 document.getElementById("repSchoolDiv").innerHTML = "";
		 document.getElementById("repChurchDiv").innerHTML = "<input name=\"repValue\" id=\"repValue\" size=\"30\" />";
		 document.getElementById("repOtherDiv").innerHTML = "";
		 document.getElementById("repDiv1").innerHTML = "";
	 	 document.getElementById("repDiv2").innerHTML = "";
	 	 document.getElementById("repDiv3").innerHTML = "";
		 checkRepValue = true;
	 }
	 
	 if (document.nominateForm.rep[3].checked) {
		 document.getElementById("repSchoolDiv").innerHTML = "";
		 document.getElementById("repChurchDiv").innerHTML = "";
		 document.getElementById("repOtherDiv").innerHTML = "<input name=\"repValue\" id=\"repValue\" size=\"30\" />";
		 document.getElementById("repDiv1").innerHTML = "";
		 document.getElementById("repDiv2").innerHTML = "";
	 	 document.getElementById("repDiv3").innerHTML = "";
		 checkRepValue = true;
	 }
  }
  
  function getRepDiv() {
	  if (document.nominateForm.rep[0].checked) {
		 document.getElementById("repDiv1").innerHTML = "";
		 document.getElementById("repDiv2").innerHTML = "";
		 document.getElementById("repDiv3").innerHTML = "";
		 repV = true;
	 }
	 
	 if (document.nominateForm.rep[1].checked) {
		 document.getElementById("repDiv1").innerHTML = "Please enter institution name.";
		 document.getElementById("repDiv2").innerHTML = "";
		 document.getElementById("repDiv3").innerHTML = "";
		 repV = false;
	 }
	 
	 if (document.nominateForm.rep[2].checked) {
		 document.getElementById("repDiv1").innerHTML = "";
		 document.getElementById("repDiv2").innerHTML = "Please enter institution name.";
		 document.getElementById("repDiv3").innerHTML = "";
		 repV = false;
	 }
	 
	 if (document.nominateForm.rep[3].checked) {
		 document.getElementById("repDiv1").innerHTML = "";
		 document.getElementById("repDiv2").innerHTML = "";
		 document.getElementById("repDiv3").innerHTML = "Please enter institution name.";
		 repV = false;
	 }
  }
 
 /**********************
  *  Load first video  *
  **********************/
  var video1Open = false;
  
  function showVideo1() {
	  if (!video1Open) {
	  	document.getElementById("videoDiv1").innerHTML = "<br/><embed width=\"615\" height=\"370\" src=\"http://www.youtube.com/v/arD374MFk4w&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;hl=en\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" /><br/><br/>";
		video1Open = true;
	  } else {
		  document.getElementById("videoDiv1").innerHTML = "";
		  video1Open = false;
	  }
  }
  
   /*********************
  *  Load second video  *
  ***********************/
  var video2Open = false;
  
  function showVideo2() {
	  if (!video2Open) {
	  	document.getElementById("videoDiv2").innerHTML = "<br/><embed width=\"615\" height=\"370\" src=\"http://www.youtube.com/v/9KY6hBHD8uU&hl=en_GB&fs=1&\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" /><br/><br/>";
		video2Open = true;
	  } else {
		  document.getElementById("videoDiv2").innerHTML = "";
		  video2Open = false;
	  }
  }
  
 /**********************
  *  Load fifth video  *
  **********************/
  var video5Open = false;
  
  function showVideo5() {
	  if (!video5Open) {
	  	document.getElementById("videoDiv5").innerHTML = "<br/><embed width=\"615\" height=\"370\" src=\"http://www.youtube.com/v/aH12Lqg1JYs&hl=en_GB&fs=1&\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" /><br/><br/>";
		video5Open = true;
	  } else {
		  document.getElementById("videoDiv5").innerHTML = "";
		  video5Open = false;
	  }
  }
  
  /****************************
   *  Load Text for students  *
   ****************************/
   var text1Open = false;
   var text2Open = false;
   var text3Open = false;
   var text4Open = false;
   var text5Open = false;
   
   function showText1() {
	   if (!text1Open) {
		   document.getElementById("text1").innerHTML = "<br/>When a lack of money for school fees forced William Kamkwamba to drop out of school at age 14, he did not simply sit and wait for a miracle to come. Instead he created a miracle of his own.<br/><br/>Using the knowledge he could gather from two textbooks at the local library and locally-available materials costing about 2200 Malawian Kwacha (approximately $15 USD), William began constructing a five-meter tall windmill outside his family\'s modest home in rural Mastala village. \"They all thought that maybe I\'m going mad and that maybe I am crazy,\" he says. But he persevered and two months later, he had built a windmill that could power two light bulbs and a radio for his family of 20. William\'s neighbors soon noticed the sounds of Malawian reggae music emanating from his home.<br/><br/>Now William has built a second, larger windmill that produces both alternating and direct current and allows him to charge batteries so his family and neighbors can have electricity even when the wind is not blowing. He has added solar panels, bright lighting and a deep water well to his family compound, and is replicating his work in other parts of Mastala.<br/><br/>After graduating from ALA, William says: \"I want to build a windmill company that provides energy to people across Africa\".<br/><br/>";
		   text1Open = true;
	   } else {
		   document.getElementById("text1").innerHTML = "";
		   text1Open = false;
	   }
   }
   
   function showText2() {
	   if (!text2Open) {
		   document.getElementById("text2").innerHTML = "<br/>With a shortage of qualified teachers and a months-long teachers\' strike crippling government schools across South Africa, Ndzondelelo High School near Port Elizabeth was in dire straits. After the school\'s fruitless search for a Mathematics substitute in the absence of the regular teacher, 16 year-old Miranda Nyathi decided to take matters into her own hands.<br/><br/>\"I saw the need for me to start afternoon and Saturday classes, mainly focused on maths, but then I expanded the classes to science and geography,\" she says. Although she sacrificed her time to help others, \"I found out that I also benefit and I have gained self-confidence and respect.\"<br/><br/>Miranda speaks passionately about her love for education and her belief that it will transform her life: \"It is not a want; it is a need to me.\" An active participant in Ubuntu Education Fund\'s community programs, she is currently founding a science club near her home in Kwa-Zakhele, where she resides with her grandmother. After attending ALA, Miranda plans to empower generations of young leaders by working to place effective teachers in schools across Africa.<br/><br/>";
		   text2Open = true;
	   } else {
		   document.getElementById("text2").innerHTML = "";
		   text2Open = false;
	   }
   }
   
   function showText3() {
	   if (!text3Open) {
		   document.getElementById("text3").innerHTML = "<br/>When Tabitha Tongoi first learned from a Ministry of Education report that the lack of textbooks is a key obstacle to education in marginalized communities across Kenya, she sprung into action. A few weeks later, Tabitha had launched Project ABC (\"A Book for Change\") at Kenya High School. Her aims were threefold: to sensitize the school community about issues affecting disadvantaged youth in Kenya; to provide a platform for Kenya High School students to donate old textbooks; and to raise sponsorship for talented but disadvantaged students at her school.<br/><br/>Over the last year, Tabitha\'s Project ABC has enabled the donation of over 3,000 books and initiated a partnership with award-winning musician Eric Wainaina to organize a charity concert. Of her success with Project ABC, this self-described \"child of mama Africa\" says, \"I hope to build on this foundation and begin a movement that will empower marginalized communities.\" With her peers at Kenya High already volunteering to tutor students in these communities, it seems that the movement has already begun.<br/><br/>After ALA, Tabitha plans to study human rights law and \"serve Africa through legislative action, advocacy, policy-making, and a range of educational interventions... that will improve the quality of education and offer an important escape from poverty.\"<br/><br/>";
		   text3Open = true;
	   } else {
		   document.getElementById("text3").innerHTML = "";
		   text3Open = false;
	   }
   }
   
   function showText4() {
	   if (!text4Open) {
		   document.getElementById("text4").innerHTML = "<br/>At the age of 8, Arkanjelo Paul Lorem fled his home in Sudan for the Kakuma Refugee Camp in northwestern Kenya, where he spent much of his childhood under the care of a social worker. But when he won a scholarship to attend a better-resourced primary school, Lorem also won a greater platform to fulfill his dreams for Africa.<br/><br/>Four years later Lorem passed his Kenya Certificate of Primary Education with straight A\'s and earned admission to Alliance High School in Kikuyu, one of the best secondary institutions in the country. Now in the top 10% of his class, Lorem speaks passionately about education as something that \"liberates the mind and enable[s] one to be independent and self-reliant... to discover his or her purpose in life.\" Yet despite his achievements he has not forgotten the community that raised him. He regularly visits Kakuma Refugee Camp and encourages community members to take action against the rising rates of teenage pregnancy among his former schoolmates in the Sudanese population living there.<br/><br/>The next challenge this young leader will tackle is the \"lamentable lack of proper leadership\" across Africa - an endeavor that resonates poignantly for this survivor of both the Sudanese conflict and the recent leadership crisis in Kenya. In the future, Lorem says, I wish to see [an] Africa where one is not defined by his or her racial or ethnic background... but by what he/she has to offer to humanity... I wish to see a continent where leaders have the interest of the people at heart instead of merely fighting for power... I wish to see a continent where children go to school and not to the battle fields... I wish to see peace and stability in the whole of Africa.\"<br/><br/>";
		   text4Open = true;
	   } else {
		   document.getElementById("text4").innerHTML = "";
		   text4Open = false;
	   }
   }
   function showText5() {
	   if (!text5Open) {
		   document.getElementById("text5").innerHTML = "";
		   text5Open = true;
	   } else {
		   document.getElementById("text5").innerHTML = "";
		   text5Open = false;
	   }
   }
