// JavaScript Document
// An assortment of scripts for website functions

// Pop up window script
<!-- Idea by:  Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL:  http://fineline.xs.mw -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500,left = 350,top = 134');");
}
// End -->

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


<!-- This popup script can vary the dimensions of the pop up window -->

<!-- Begin
function videopopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=350,height=375,left = 350,top = 134');");
}
// End -->

<!-- Display or hide Chaplain text box --?
function chaplain(divname) {
	var opt = getSelectValue("n_nominate","Nominators_relationship");
	if (opt == "Chaplain"){
		document.getElementById(divname).style.display = "block";
	 }
	 else
	 {
		document.getElementById(divname).style.display = "none";
	 }

}


<!-- Begin
function formmessage(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=300,left = 350,top = 134');");
}
// End -->

// Menu script to display menu items when called
<!--
window.onload=show;
function show(id) {
	mydiv = document.getElementById("moviemenu");
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';	}
	}
	
if (d) {d.style.display='block';
	}
	}
//-->


// This function gets the selected Event item - Dropdown lists etc.
	function getSelectValue(formname, selectname)
	{
	var theEvent = document[formname] [selectname];
	for (i=0;i<theEvent.length;i++)
		{
	     if (theEvent[i].selected)
	 	{
	    	 return theEvent[i].value;	
	   	}
	  	}			 	
	} 

// Specify YWC Dates for Registration purposes
	var current_date = new Date ();
	var ywc_date;
	var launch_date;
	var nominations_closed;
	ywc_date = new Date (2009, 4, 30); // Jan = 0, Feb = 1, Mar = 2, etc. (yy,mm,dd)
	launch_date = new Date (2009, 1, 23); // Jan = 0, Feb = 1, Mar = 2, etc. (yy,mm,dd)
	nominations_closed = new Date (2009, 4, 15); // Jan = 0, Feb = 1, Mar = 2, etc. (yy,mm,dd)
	test_date = new Date (2009, 1, 12); // Jan = 0, Feb = 1, Mar = 2, etc. (yy,mm,dd)
	
//Set up random images to test for human users
	var theImages = new Array() // do not change this
	// To add more image files, continue with the
	// pattern below, adding to the array.

	theImages[0] = '/images/rdm/0018.gif' //car.gif'
	theImages[1] = '/images/rdm/0027.gif' //cat.gif'
	theImages[2] = '/images/rdm/0036.gif' //chair.gif'
	theImages[3] = '/images/rdm/0045.gif' //clock.gif'
	theImages[4] = '/images/rdm/0054.gif' //cross.gif'
	theImages[5] = '/images/rdm/0063.gif' //dog.gif'
	theImages[6] = '/images/rdm/0072.gif' //ladder.gif'
	theImages[7] = '/images/rdm/0081.gif' //lion.gif'
	theImages[8] = '/images/rdm/0090.gif' //mouse.gif' 

	// do not edit anything below this line

	var j = 0
	var p = theImages.length;
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	   preBuffer[i] = new Image()
	   preBuffer[i].src = theImages[i]
		}
	var whichImage = Math.round(Math.random()*(p-1));
//	document.write(whichImage);
function showImage(){
	document.write('<img src="'+theImages[whichImage]+'">');
}

//  End -->
	

// Church Registration Form Validation
function validatechurchform() {
	// Validate Registration Dates
	if (current_date > ywc_date)
		{
			alert("Sorry, This year's Yes We Care event is now completed!");
			return false;
		}
	if ((current_date < launch_date) && (current_date > test_date))
		{
			alert("Sorry, Registrations will only be received after the official launch date!");
			return false;
		}
	
	// Validate Church Name
	if(!document.c_churchfrm.Church.value)
		{
		alert("You must enter the Church's name");
		document.c_churchfrm.Church.focus();
		return false;
		}
	// Validate empty hidden postcode field
	if(document.c_churchfrm.postcode.value)
		{
			return false;
		}
	// Validate Church Address
	if(!document.c_churchfrm.Address.value)
		{
		alert("You must enter the Church's address");
		document.c_churchfrm.Address.focus();
		return false;
		}
	// Validate Contact Person
	if(!document.c_churchfrm.Contact_Person.value)
		{
		alert("You must enter the Contact Person");
		document.c_churchfrm.Contact_Person.focus();
		return false;
		}
	// Validate Telephone
	if(!document.c_churchfrm.Telephone.value)
		{
		alert("You must enter a Telephone Number");
		document.c_churchfrm.Telephone.focus();
		return false;
		}	
	// Validate email
	var validEmail = "";
	var theEmail = document.c_churchfrm.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)
		{
		validEmail = true;
		}
		if  (validEmail == "")
			{
			alert("Please enter a valid email address");
			document.c_churchfrm.email.focus();
			return false;
			}
	// Validate Region
	var region = getSelectValue("c_churchfrm","Region");
	 if (region ==null || region == "None")
	//if (recipient == "0")
	{
	 	alert("Please select a Region!");
		return false;   
	} 
	// Validate Question and Answer
		var Ans = getSelectValue("c_churchfrm","Ans");
		if (Ans == "None" || Ans ==null || whichImage != Ans){
			alert("A correct answer to the picture question is essential before proceeding!");
			return false;
			}
			
	// If the contents are valid, return true
    // If the contents are not valid, provide details of the problems and return false.	
	// else
		{
			document.c_churchfrm.Ans.value = "";
			return true;
		}
}

// Technician Form Validation

function validatetechfrm() {
	// Validate Registration Dates
	if (current_date > ywc_date)
		{
			alert("Sorry, This year's Yes We Care event is now completed!");
			return false;
		}
	if ((current_date < launch_date) && (current_date > test_date))
		{
			alert("Sorry, Registrations will only be received after the official launch date!");
			return false;
		}
	
	// Validate the Technician's Name
	if(!document.t_technicians.Technicians_Name.value)
		{
		alert("You must enter your name");
		document.t_technicians.Technicians_Name.focus();
		return false;
		}
		// Validate empty hidden postcode field
	if(document.t_technicians.postcode.value)
		{
			return false;
		}
	// Validate Church Address
	if(!document.t_technicians.Address.value)
		{
		alert("You must enter your address");
		document.t_technicians.Address.focus();
		return false;
		}
	// Validate Telephone and Mobile
	if((!document.t_technicians.Mobile.value) && (!document.t_technicians.Telephone.value))
		{
		alert("Either a Telephone or Mobile Number must be supplied.");
		document.t_technicians.Telephone.focus();
		return false;
		}
	// Validate email
	var validEmail = "";
	var theEmail = document.t_technicians.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)
		{
		validEmail = true;
		}
		if  (validEmail == "")
			{
			alert("Please enter a valid email address");
			document.t_technicians.email.focus();
			return false;
			}
	// Validate Expertise
		if(!document.t_technicians.Expertise.value)
		{
		alert("Please specify your area of expertise");
		document.t_technicians.Expertise.focus();
		return false;
		}
	
	// Validate Region/recipient
	var recipient = getSelectValue("t_technicians","recipient");
	 if (recipient ==null || recipient == "None")
	//if (recipient == "0")
	{
	 	alert("Please select a Region!");
		return false;   
	} 
	// Validate Question and Answer
		var Ans = getSelectValue("t_technicians","Ans");
		if (Ans == "None" || Ans ==null || whichImage != Ans){
			alert("A correct answer to the picture question is essential before proceeding!");
			return false;
			}
	
	// If the contents are valid, return true
    // If the contents are not valid, provide details of the problems and return false.	
	// else
		{
			document.t_technicians.Ans.value = "";
			return true;
		}
}

// Validate Volunteer Form
function volunteervalidate() {
	
		// Validate Registration Dates
	if (current_date > ywc_date)
		{
			alert("Sorry, This year's Yes We Care event is now completed!");
			return false;
		}
	if ((current_date < launch_date) && (current_date > test_date))
		{
			alert("Sorry, Registrations will only be received after the official launch date!");
			return false;
		}
		
	// Validate the Volunteer's Name
	if(!document.v_volunteer.Volunteers_Name.value)
		{
		alert("You must enter your name");
		document.v_volunteer.Volunteers_Name.focus();
		return false;
		}
	// Validate empty hidden postcode field
	if(document.v_volunteer.postcode.value)
		{
			return false;
		}
	// Validate Church Address
	if(!document.v_volunteer.Address.value)
		{
		alert("You must enter your address");
		document.v_volunteer.Address.focus();
		return false;
		}
	// Validate Telephone and Mobile
	if((!document.v_volunteer.Mobile.value) && (!document.v_volunteer.Telephone.value))
		{
		alert("Either a Telephone or Mobile Number must be supplied.");
		document.v_volunteer.Telephone.focus();
		return false;
		}
	// Validate email
	var validEmail = "";
	var theEmail = document.v_volunteer.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)
		{
		validEmail = true;
		}
		if  (validEmail == "")
			{
			alert("Please enter a valid email address");
			document.v_volunteer.email.focus();
			return false;
			}
	// Validate Name of Church
	/*	if(!document.v_volunteer.Church.value)
		{
		alert("Please specify your Church");
		document.v_volunteer.Church.focus();
		return false;
		}
	*/
	// Validate Region/recipient
	var recipient = getSelectValue("v_volunteer","recipient");
	 if (recipient ==null || recipient == "None")
	//if (recipient == "0")
	{
	 	alert("Please select a Region!");
		return false;   
	} 
	// Validate Question and Answer
		var Ans = getSelectValue("v_volunteer","Ans");
		if (Ans == "None" || Ans ==null || whichImage != Ans){
			alert("A correct answer to the picture question is essential before proceeding!");
			return false;
			}
	
	// If the contents are valid, return true
    // If the contents are not valid, provide details of the problems and return false.	
	// else
		{
			document.v_volunteer.Ans.value = "";
			return true;
		}
}

// Validate Nominate a Home form
function nominatevalidate() {
	// Validate Registration Dates
	if (current_date > nominations_closed)
		{
			alert("Sorry, Nominations are no-longer possible for this year!");
			return false;
		}
	if ((current_date < launch_date) && (current_date > test_date))
		{
			alert("Sorry, Registrations will only be received after the official launch date!");
			return false;
		}
	// Validate the eligibility	
	var rel = getSelectValue("n_nominate","eligibility");
	 if (rel ==null || rel == "None")
	{
	 	alert("Please indicate the person's eligibility");
		return false;   
	}
	
	// Validate the Occupant's Name
	if(!document.n_nominate.Occupants_Name.value)
		{
		alert("You must enter the occupant's name");
		document.n_nominate.Occupants_Name.focus();
		return false;
		}
	// Validate empty hidden postcode field
	if(document.n_nominate.postcode.value)
		{
			return false;
		}
	// Validate Occumpant's Address
	if(!document.n_nominate.Occupants_Address.value)
		{
		alert("You must enter the occupant's address");
		document.n_nominate.Occupants_Address.focus();
		return false;
		}
	// Validate Occupant's Telephone
	if(!document.n_nominate.Occupants_Telephone.value)
		{
		alert("Please enter the Occumpant's telephone or Mobile Number.");
		document.n_nominate.Occupants_Telephone.focus();
		return false;
		}
	// Validate Help Needed
	if(!document.n_nominate.Help_Needed.value)
		{
		alert("Please indicate the type of help needed.");
		document.n_nominate.Help_Needed.focus();
		return false;
		}	
	// Validate Occupant's Knowledge of Nomination
	var know = getSelectValue("n_nominate","Occupants_know");
	 if (know ==null || know == "None")
	{
	 	alert("Please indicate if the occupuants know of this nomination");
		return false;   
	}	
	// Validate Region/recipient
	var region = getSelectValue("n_nominate","Region");
	 if (region ==null || region == "None")
	//if (recipient == "0")
	{
	 	alert("Please select a Region!");
		return false;   
	} 		
	// Validate Nominator
		if(!document.n_nominate.Nominator.value)
		{
		alert("Please enter your name");
		document.n_nominate.Nominator.focus();
		return false;
		}
		if(document.n_nominate.Occupants_Name.value == document.n_nominate.Nominator.value)
		{
			alert("Sorry, the Nominator and the Nominee cannot be the same person.");
			document.n_nominate.Nominator.focus();
			return false;
		}
		// Validate Nominator's Telephone
		if(!document.n_nominate.Nominators_telephone.value)
		{
		alert("Please enter your mobile or telephone number");
		document.n_nominate.Nominators_telephone.focus();
		return false;
		}
		if(document.n_nominate.Occupants_Telephone.value == document.n_nominate.Nominators_telephone.value)
		{
			alert("Sorry, the Nominator and the Nominee's telephone cannot be the same.");
			document.n_nominate.Nominator.focus();
			return false;
		}
	// Validate email
	var validEmail = "";
	var theEmail = document.n_nominate.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)
		{
		validEmail = true;
		}
		if  (validEmail == "")
			{
			alert("Please enter a valid email address");
			document.n_nominate.email.focus();
			return false;
			}
	// Validate Nominator's Relationship
	var rel = getSelectValue("n_nominate","Nominators_relationship");
	 if (rel ==null || rel == "None")
	{
	 	alert("Please indicate your relationshipship");
		return false;   
	}	
	// Validate Question and Answer
		var Ans = getSelectValue("n_nominate","Ans");
		if (Ans == "None" || Ans ==null || whichImage != Ans){
			alert("A correct answer to the picture question is essential before proceeding!");
			return false;
			}
	
	// If the contents are valid, return true
    // If the contents are not valid, provide details of the problems and return false.	
	// else
		{
			document.n_nominate.Ans.value = "";
			return true;
		} 
}
// Validate the Message Form
function messagefrmvalidation() {
	// Discover who the recipient is
	var recipient = getSelectValue("message_frm","recipient");
	// Validate Registration Dates
	// Determine if recipient is webmaster or general admin
	if (current_date > ywc_date+30)
		{
			if (recipient ==null || recipient == "None")
			{
				alert("Please select a Region!");
				return false;
			}
			if (recipient != "Chair" || recipient != "Web")
			{
			alert("Sorry, This year's Yes We Care event is now completed!\nOnly the Chairman and Webmaster\ncan be contacted using this form");
			return false;
			}
		}
	// Validate Region/recipient
	if (recipient ==null || recipient == "None")
	{
	 	alert("Please choose a recipient of this message!");
		return false;   
	} 
	// Validate the Name
	if(!document.message_frm.Name.value)
		{
		alert("You must enter your name");
		document.message_frm.Name.focus();
		return false;
		}
	// Validate empty hidden address & postcode fields
	if((document.message_frm.postcode.value) || (document.message_frm.Address.value))
		{
			return false;
		}
	// Validate two email address fields
		if(document.message_frm.email.value != document.message_frm.email_ck.value)
		{
		alert("Your two emails do not match!\nPlease try again.");
		document.message_frm.email.focus();
		return false;
		}
	// Validate email
	var validEmail = "";
	var theEmail = document.message_frm.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)
		{
		validEmail = true;
		}
		if  (validEmail == "")
			{
			alert("Please enter a valid email address");
			document.message_frm.email.focus();
			return false;
			}
	// Validate Message
	if(!document.message_frm.Message.value)
		{
		alert("You have not entered any message yet!");
		document.message_frm.Message.focus();
		return false;
		}
	// Validate Question and Answer
		var Ans = getSelectValue("message_frm","Ans");
		if (Ans == "None" || Ans ==null || whichImage != Ans){
			alert("A correct answer to the picture question is essential before proceeding!");
			return false;
			}
	
	// If the contents are valid, return true
    // If the contents are not valid, provide details of the problems and return false.	
	// else
		{
			document.message_frm.email_ck.value = "";
			document.message_frm.Ans.value = "";
			return true;
		}
}

//Validate Prayer form
function validateprayerfrm(){
		// Validate Registration Dates
/*	if (current_date > ywc_date)
		{
			alert("Sorry, This year's Yes We Care event is now completed!");
			return false;
		}
	if ((current_date < launch_date) && (current_date > test_date))
		{
			alert("Sorry, Registrations will only be received after the official launch date!");
			return false;
		}
	*/
	// Validate First Name

	if(!document.prayerfrm.FirstName.value)
		{
		alert("You must enter your first name");
		document.prayerfrm.FirstName.focus();
		return false;
		}
		//Validate Last Name
	if(!document.prayerfrm.LastName.value)
		{
		alert("You must enter your last name");
		document.prayerfrm.LastName.focus();
		return false;
		}
	// Validate email
	var validEmail = "";
	var theEmail = document.prayerfrm.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)
		{
		validEmail = true;
		}
		if  (validEmail == "")
			{
			alert("Please enter a valid email address");
			document.prayerfrm.email.focus();
			return false;
			}
	// Validate Church
		if(!document.prayerfrm.Church.value)
		{
		alert("You must enter the name of your church");
		document.prayerfrm.Church.focus();
		return false;
		}
	// Validate Pastor's name
		if(!document.prayerfrm.Pastors_Name.value)
		{
		alert("You must enter your Pastor's name");
		document.prayerfrm.Pastors_Name.focus();
		return false;
		}
	// If the contents are valid, return true
	
	 else
		{
			return true;
		}
	
}
