
var programOpts = new Array("Tickles & Tales", "Babes & Toddlers", "Mother Goose(10 months old)", "Mother Goose(12 months old)", "Tales & Tunes", "Toddling Tots", "Tots in Action", "Enjoying Your Toddler", "Boogie Woogie", "Twist & Shout", "Time Together", "Shake Rattle & Roll", "Time for Families","Moment de Plaisir Ensemble (12weeks)");
var programMinAge = new Array(0, 7, 0, 0, 5,11,11,17,17,23,29,29, 0, 0, 0);
var programMaxAge = new Array(7,15,11,13,13,25,19,31,25,36,72,72,72,72,72);

var programOptsParent = new Array("Mothers Are People Too", "Play and Learn", "Making Friends and Other Essential Social Skills", "Fantastic Families");

var locationOpts = new Array("North Service Road - Main", "North Service Road - Satellite", "Sixth Line", "Florence", "Goodlife Fitness (Superstore)", "Longo's (Burloak)", "Clearview Church", "St. James Catholic School", "St. Johns School", "West Oak Village", "Woodside Library", "Wyndham Manor", "Glen Abbey Library", "Iroquois Ridge Library");


Date.prototype.ageLastBirthday = function(dob) {

var cy = this.getFullYear();
var by = dob.getFullYear();
var db = new Date(dob);
db.setFullYear(cy);
var diff = 0;

	diff = (cy - by) *12;
	diff += this.getMonth()-dob.getMonth()-1;
	if (db.getDate() <= this.getDate())
		diff++;
		
	

return diff;
}


// Check if the child is too young or old for the program
function checkAge (ind, birthD, startD){

		var months = startD.ageLastBirthday(birthD);
		ind--;
		
		// alert("checkAge startD = " + startD + "months = " + months + " ind = "+ ind +" minage = " + programMinAge[ind] + " maxage = " +programMaxAge[ind]);
        if (months >= programMinAge[ind] && months < programMaxAge[ind])
	        return true;
        else
        	return false;
}



// this function is used to fill program options on load
function SetProgramOptions() { 

	for (var i = 0; i < programOpts.length; ++i) {
		AddOption(document.forms[0].TotProgram_1, programOpts[i], programOpts[i]);
		AddOption(document.forms[0].TotProgram_2, programOpts[i], programOpts[i]);
		AddOption(document.forms[0].TotProgram_3, programOpts[i], programOpts[i]);		
		AddOption(document.forms[0].TotProgram_4, programOpts[i], programOpts[i]);	
	}
	
	for (i = 0; i < programOptsParent.length; ++i) {
		AddOption(document.forms[0].ParProgram_1, programOptsParent[i], programOptsParent[i]);
		AddOption(document.forms[0].ParProgram_2, programOptsParent[i], programOptsParent[i]);
		AddOption(document.forms[0].ParProgram_3, programOptsParent[i], programOptsParent[i]);
		AddOption(document.forms[0].ParProgram_4, programOptsParent[i], programOptsParent[i]);		
	
	}
	
	
}



// this function is to set location options according to the program selected
function SetLocationOptions(progOpt, locOpt, sDate, sTime, aChildren, aNames) {

	RemoveAllOptions(locOpt);
	RemoveAllOptions(sDate);
	RemoveAllOptions(sTime);
	AddOption(sDate, "Select One", "");
	AddOption(sTime, "Select One", "");
	
	RemoveChildrenNames(aChildren);
	
	if (progOpt.options.selectedIndex == 0) {
		AddOption(locOpt, "Select One", "");
		return;
	}

	if (progOpt.value == programOpts[0]) {
		AddOption(locOpt,locationOpts[0], locationOpts[0]);
		AddOption(locOpt,locationOpts[2], locationOpts[2]);
	}
	else if (progOpt.value == programOpts[1]){
		AddOption(locOpt,locationOpts[0], locationOpts[0]);
	}
	else if (progOpt.value == programOpts[2]){
		AddOption(locOpt,locationOpts[4], locationOpts[4]);
		AddOption(locOpt,locationOpts[2], locationOpts[2]);
	}
	else if (progOpt.value == programOpts[3]){
		AddOption(locOpt,locationOpts[8], locationOpts[8]);	
	}
	else if (progOpt.value == programOpts[4]){
		AddOption(locOpt,locationOpts[12], locationOpts[12]);
		AddOption(locOpt,locationOpts[2], locationOpts[2]);
	}
	else if (progOpt.value == programOpts[5]){
		AddOption(locOpt,locationOpts[0], locationOpts[0]);		
	}
	else if (progOpt.value == programOpts[6]){
		AddOption(locOpt,locationOpts[0], locationOpts[0]);
	}
	else if (progOpt.value == programOpts[7]){
		AddOption(locOpt,locationOpts[1], locationOpts[1]);
	}
	else if (progOpt.value == programOpts[8]){
		AddOption(locOpt,locationOpts[0], locationOpts[0]);	

	}
	else if (progOpt.value == programOpts[9]){
		AddOption(locOpt,locationOpts[2], locationOpts[2]);			
		AddOption(locOpt,locationOpts[0], locationOpts[0]);					
	}
	else if (progOpt.value == programOpts[10]){
		AddOption(locOpt,locationOpts[1], locationOpts[1]);
	}
	else if (progOpt.value == programOpts[11]){
		AddOption(locOpt,locationOpts[0], locationOpts[0]);
		AddOption(locOpt,locationOpts[1], locationOpts[1]);
	}	
	else if (progOpt.value == programOpts[12]){	
		AddOption(locOpt,locationOpts[1], locationOpts[1]);		
	}
	else if (progOpt.value == programOpts[13]){	
		AddOption(locOpt,locationOpts[1], locationOpts[1]);		
	}


	
	locOpt.options.selectedIndex = 0;
	SetStartDateOptions(progOpt, locOpt, sDate, sTime, aChildren, aNames);
	return;
}


function SetStartDateOptions(progOpt, locOpt, sDate, sTime, aChildren, aNames) {
// this function is to set start dates and time slots according to the program and location selected
	RemoveAllOptions(sDate);
	RemoveAllOptions(sTime);


	if (progOpt.value == programOpts[0]) {
		if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/20/2012", "03/20/2012");
			AddOption(sDate,"05/01/2012", "05/01/2012");				
			AddOption(sTime,"1:00 p.m.", "1:00 p.m.");			
		}
		else if (locOpt.value == locationOpts[2]){
			AddOption(sDate,"03/22/2012", "03/22/2012");
			AddOption(sDate,"05/03/2012", "05/03/2012");				
			AddOption(sTime,"2:15 p.m.", "2:15 p.m.");			
		}

	}
	else if (progOpt.value == programOpts[1]){
		if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/20/2012", "03/20/2012");
			AddOption(sDate,"05/01/2012", "05/01/2012");	
			AddOption(sTime,"9:15 a.m.", "9:15 a.m.");			
		}		
	}
	else if (progOpt.value == programOpts[2]){
		if (locOpt.value == locationOpts[4]){
			AddOption(sDate,"03/20/2012", "03/20/2012");
			AddOption(sDate,"05/01/2012", "05/01/2012");	
			AddOption(sTime,"9:30 a.m.", "9:30 a.m.");			
		}
		else if (locOpt.value == locationOpts[2]){
			AddOption(sDate,"03/21/2012", "03/21/2012");
			AddOption(sDate,"05/02/2012", "05/02/2012");				
			AddOption(sTime,"1:00 p.m.", "1:00 p.m.");			
		}

	}
	else if (progOpt.value == programOpts[3]){
		if (locOpt.value == locationOpts[8]){
			AddOption(sDate,"03/22/2012", "03/22/2012");
			AddOption(sDate,"05/03/2012", "05/03/2012");
			AddOption(sTime,"1:45 p.m.", "1:45 p.m.");			
		}
	}
	else if (progOpt.value == programOpts[4]){
		if (locOpt.value == locationOpts[12]){
			AddOption(sDate,"03/19/2012", "03/19/2012");
			AddOption(sDate,"04/30/2012", "04/30/2012");
			AddOption(sTime,"1:30 p.m.", "1:30 p.m.");			
		}
		else if (locOpt.value == locationOpts[2]){
			AddOption(sDate,"03/22/2012", "03/22/2012");
			AddOption(sDate,"05/03/2012", "05/03/2012");				
			AddOption(sTime,"1:00 p.m.", "1:00 p.m.");			
		}
	}
	else if (progOpt.value == programOpts[5]){
		if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/19/2012", "03/19/2012");
			AddOption(sDate,"04/30/2012", "04/30/2012");
			AddOption(sTime,"9:15 a.m.", "9:15 a.m.");			
		}
	}
	else if (progOpt.value == programOpts[6]){
		if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/19/2012", "03/19/2012");
			AddOption(sDate,"04/30/2012", "04/30/2012");			
			AddOption(sTime,"10:45 a.m.", "10:45 a.m.");							
		}
	}
	else if (progOpt.value == programOpts[7]){
		if (locOpt.value == locationOpts[1]){
			AddOption(sDate,"03/21/2012", "03/21/2012");
			AddOption(sDate,"05/02/2012", "05/02/2012");			
			AddOption(sTime,"9:15 a.m.", "9:15 a.m.");							
							
		}
	}	
	else if (progOpt.value == programOpts[8]){
		if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/22/2012", "03/22/2012");
			AddOption(sDate,"05/03/2012", "05/03/2012");			
			AddOption(sTime,"09:30 a.m.", "09:30 a.m.");							
		}
	}	
	else if (progOpt.value == programOpts[9]){
		if (locOpt.value == locationOpts[2]){
			AddOption(sDate,"03/21/2012", "03/21/2012");
			AddOption(sDate,"05/02/2012", "05/02/2012");			
			AddOption(sTime,"09:15 a.m.", "09:15 a.m.");
			AddOption(sTime,"10:45 a.m.", "10:45 a.m.");						
		}
		else if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/22/2012", "03/22/2012");
			AddOption(sDate,"05/03/2012", "05/03/2012");			
			AddOption(sTime,"11:00 a.m.", "11:00 a.m.");			
		}

	}
	else if (progOpt.value == programOpts[10]){
		if (locOpt.value == locationOpts[1]){
			AddOption(sDate,"03/21/2012", "03/21/2012");
			AddOption(sDate,"05/02/2012", "05/02/2012");			
			AddOption(sTime,"10:45 a.m.", "10:45 a.m.");							
		}
	}	
	else if (progOpt.value == programOpts[11]){
		if (locOpt.value == locationOpts[0]){
			AddOption(sDate,"03/21/2012", "03/21/2012");
			AddOption(sDate,"05/02/2012", "05/02/2012");			
			AddOption(sTime,"1:15 p.m.", "1:15 p.m.");			
		}
		else if (locOpt.value == locationOpts[1]){
			AddOption(sDate,"03/22/2012", "03/22/2012");
			AddOption(sDate,"05/03/2012", "05/03/2012");			
			AddOption(sTime,"09:15 a.m.", "09:15 a.m.");
			AddOption(sTime,"10:45 a.m.", "10:45 a.m.");						
		}

	}
	else if (progOpt.value == programOpts[12]){
		if (locOpt.value == locationOpts[1]){
			AddOption(sDate,"03/20/2012", "03/20/2012");
			AddOption(sTime,"1:00 p.m.", "1:00 p.m.");			
		}
	}
	else if (progOpt.value == programOpts[13]){
		if (locOpt.value == locationOpts[1]){
			AddOption(sDate,"03/21/2012", "03/21/2012");
			AddOption(sTime,"1:30 p.m.", "1:30 p.m.");			
		}
	}
	

	
	sDate.selectedIndex = 0;
	sTime.selectedIndex = 0;
	SetChildrenNames(progOpt, locOpt, sDate, sTime, aChildren, aNames);	
}


function SetTimeOptions(progOpt, locOpt, sDate, sTime, aChildren, aNames) 
{
	RemoveChildrenNames(aChildren);
	SetChildrenNames(progOpt, locOpt, sDate, sTime, aChildren, aNames);	

/*	if (progOpt.value != programOpts[11])
		return;
	
	if (sDate.value == "01/04/2011") {
		sTime.options.length = 0;
		AddOption(sTime,"10:45 a.m.", "10:45 a.m.");
	}
	else  {
		sTime.options.length = 0;	
		AddOption(sTime,"1:15 p.m.", "1:15 p.m.");				
	}
*/
return;

}

function SetDateTimeParent (progOpt, locOpt, sDate, sTime, aChildren, aNames) {

	RemoveAllOptions(locOpt);
	RemoveAllOptions(sDate);
	RemoveAllOptions(sTime);	
	RemoveChildrenNames(aChildren);
	
	if (progOpt.options.selectedIndex == 0) {
		AddOption(locOpt, "Select One", "");
		AddOption(sDate, "Select One", "");
		AddOption(sTime, "Select One", "");

		return;
	}
	
	AddOption(locOpt, locationOpts[0], locationOpts[0]);
	
	if (progOpt.value == programOptsParent[0]) {
		AddOption(sDate, "03/20/2012", "03/20/2012");		
		AddOption(sDate, "05/01/2012", "05/01/2012");		
		AddOption(sTime, "9:15 a.m.", "9:15 a.m.");		
	 }
	else if (progOpt.value == programOptsParent[1]) {
		AddOption(sDate, "05/01/2012", "05/01/2012");			
		AddOption(sTime, "1:00 p.m.", "1:00 p.m.");		
	}
	else if (progOpt.value == programOptsParent[2]) {
		AddOption(sDate, "05/02/2012", "05/02/2012");				
		AddOption(sTime, "1:00 p.m.", "1:00 p.m.");
	}
	else if (progOpt.value == programOptsParent[3]) {
		AddOption(sDate, "05/17/2012", "05/17/2012");				
		AddOption(sTime, "9:15 a.m.", "9:15 a.m.");
	}

	
	sDate.selectedIndex = 0;
	sTime.selectedIndex = 0;
	SetChildrenNames(progOpt, locOpt, sDate, sTime, aChildren, aNames);

}


function reminder(sProg, sDate)
{
	if (sProg.value != programOpts[13] && sDate.value.substr(0,2) == "03") {
		alert("Did you know that you can register for programs that start in May, too?");	
	}

}


function GetSpouseName(spouseName)
{
	spouseName.value = "";

}


function CheckRequiredValue (inputField) {

	var inputF = document.getElementById(inputField);
	
	if (inputF.value == "") {
		alert("Your spouse's name is required to register this program.  Please enter it now.");
		inputF.focus();
	}
	
	return

}
function CheckElig(progOpt, locOpt, sDate, sTime, aChildren, aNames) {
	
	var childrenNames, element, displayText, newLine;
	
	var startD = new Date(parseInt(sDate.value.substr(6,4),10), parseInt(sDate.value.substr(0,2),10)-1, parseInt(sDate.value.substr(3,2),10));
	
	SetBabyInfo(document.forms[0]);
	
	if (progOpt.value == programOptsParent[0] || progOpt.value == programOptsParent[2] || progOpt.value == programOptsParent[3] || progOpt.value == programOptsParent[1])
		var ind = programMinAge.length;

	else
		var ind = progOpt.selectedIndex;

	if (!document.getElementById) 
		childrenNames = document.forms[0].elements[aChildren];
	else
		childrenNames = document.getElementById(aChildren);

	var childrenNamesList = document.createElement("DIV");
	childrenNamesList.setAttribute("id", aChildren+1);
	childrenNamesList.setAttribute("name", aChildren+1);


	element = document.createElement("INPUT");
	element.setAttribute("type", "checkbox");
	element.setAttribute("name", aNames);
	element.setAttribute("value", "");
	element.style.visiblity = "hidden";
	element.style.display = "none";
	childrenNamesList.appendChild(element);


	var eligible = 0;
	if (document.forms[0].Child1_FirstName.value != "") {
	
	
		var dob = new Date(parseInt(document.forms[0].Child1_BirthYear.value), parseInt(document.forms[0].Child1_BirthMonth.value)-1, parseInt(document.forms[0].Child1_BirthDay.value));
		
		if (checkAge(ind, dob, startD)) {
	
			element = document.createElement("INPUT");
			element.setAttribute("type", "checkbox");
			element.setAttribute("name", aNames);
			element.setAttribute("value", document.forms[0].Child1_FirstName.value);

			displayText = document.createTextNode(document.forms[0].Child1_FirstName.value); 
		
			childrenNamesList.appendChild(element);
			childrenNamesList.appendChild(displayText);
		
			newLine = document.createElement("p");
			childrenNamesList.appendChild(newLine);
			eligible = eligible + 1;
		}
	}	

	
	if (document.forms[0].Child2_FirstName.value != "") {
		
		var dob = new Date(parseInt(document.forms[0].Child2_BirthYear.value), parseInt(document.forms[0].Child2_BirthMonth.value)-1, parseInt(document.forms[0].Child2_BirthDay.value));

		if (checkAge(ind, dob, startD)) {
			element = document.createElement("INPUT");
			element.setAttribute("type", "checkbox");
			element.setAttribute("name", aNames);
			element.setAttribute("value", document.forms[0].Child2_FirstName.value);

			displayText = document.createTextNode(document.forms[0].Child2_FirstName.value); 
		
			childrenNamesList.appendChild(element);
			childrenNamesList.appendChild(displayText);
			
			newLine = document.createElement("p");
			childrenNamesList.appendChild(newLine);
			eligible = eligible + 1;
		}
	}
		
		
	if (document.forms[0].Child3_FirstName.value != "") {
	
		var dob = new Date(parseInt(document.forms[0].Child3_BirthYear.value), parseInt(document.forms[0].Child3_BirthMonth.value)-1, parseInt(document.forms[0].Child3_BirthDay.value));

		if (checkAge(ind, dob, startD)) {
	
			element = document.createElement("INPUT");
			element.setAttribute("type", "checkbox");
			element.setAttribute("name", aNames);
			element.setAttribute("value", document.forms[0].Child3_FirstName.value);

			displayText = document.createTextNode(document.forms[0].Child3_FirstName.value); 
		
			childrenNamesList.appendChild(element);
			childrenNamesList.appendChild(displayText);
		
			newLine = document.createElement("p");
			childrenNamesList.appendChild(newLine);
			eligible = eligible + 1;			
		}	
	}

	
	if (document.forms[0].Baby_Info.value != "") {		

		var dob = new Date(parseInt(document.forms[0].Baby_BirthYear.value), parseInt(document.forms[0].Baby_BirthMonth.value)-1, parseInt(document.forms[0].Baby_BirthDay.value));
		
		if (checkAge(ind, dob, startD)) {
		
			element = document.createElement("INPUT");
			element.setAttribute("type", "checkbox");
			element.setAttribute("name", aNames);
			element.setAttribute("value", document.forms[0].Baby_Info.value);

			displayText = document.createTextNode(document.forms[0].Baby_Info.value); 
			childrenNamesList.appendChild(element);
			childrenNamesList.appendChild(displayText);

			newLine = document.createElement("p");
			childrenNamesList.appendChild(newLine);
			eligible = eligible + 1;			
		}	
	}
	
	if (eligible > 0)
		childrenNames.appendChild(childrenNamesList);

	
	
	return eligible;
}




function SetChildrenNames(progOpt, locOpt, sDate, sTime, aChildren, aNames) {
	
/*	

	if (progOpt.value == programOptsParent[0] || progOpt.value == programOptsParent[1] || progOpt.value == programOptsParent[2]) {

		element = document.createElement("INPUT");
		element.setAttribute("type", "checkbox");
		element.setAttribute("name", aNames);
		element.setAttribute("value", "None");
		
		displayText = document.createTextNode("None"); 
		
		childrenNamesList.appendChild(element);
		childrenNamesList.appendChild(displayText);
		
		newLine = document.createElement("p");
		childrenNamesList.appendChild(newLine);

	}	
*/	
	
	var eligKid = CheckElig(progOpt, locOpt, sDate, sTime, aChildren, aNames);
		
	if (eligKid == 0) {
	
		if (progOpt.value == programOptsParent[0] || progOpt.value == programOptsParent[2] || progOpt.value == programOptsParent[3] || progOpt.value == programOptsParent[1]){
			RemoveChildrenNames(aChildren);
			return;		
		}
	
		if ((sDate.value.substr(0,2) == "03") && sDate.length > 1) {

			if (confirm("None of your children is eligible for this program by the start date of your choice.\n Do you want to register for the next session instead?")) {
				sDate.selectedIndex = sDate.selectedIndex + 1;
				
				RemoveChildrenNames(aChildren);

				eligKid = CheckElig(progOpt, locOpt, sDate, sTime, aChildren, aNames);

			}
			else {			
				progOpt.selectedIndex = 0;

				RemoveAllOptions(locOpt);
				RemoveAllOptions(sDate);
				RemoveAllOptions(sTime);
				AddOption(locOpt, "Select One", "");
				AddOption(sDate, "Select One", "");
				AddOption(sTime, "Select One", "");
	
				RemoveChildrenNames(aChildren);
				return;
			}
		}
		else {	
				progOpt.selectedIndex = 0;

				RemoveAllOptions(locOpt);
				RemoveAllOptions(sDate);
				RemoveAllOptions(sTime);
				AddOption(locOpt, "Select One", "");
				AddOption(sDate, "Select One", "");
				AddOption(sTime, "Select One", "");
	
				RemoveChildrenNames(aChildren);
			
		}					
	}                  
	
	if (eligKid == 0) {
		alert("None of your children is eligible for this program. \nPlease select another program.");
		
		progOpt.selectedIndex = 0;
		RemoveAllOptions(locOpt);
		RemoveAllOptions(sDate);
		RemoveAllOptions(sTime);
		AddOption(locOpt, "Select One", "");
		AddOption(sDate, "Select One", "");
		AddOption(sTime, "Select One", "");
	
		RemoveChildrenNames(aChildren);
			
		
	}
	
	return;


}



function RemoveChildrenNames(aChildren) {

	var childrenNamesList = aChildren + 1;

	if (!document.getElementById) 
		var childrenNamesDIV = document.forms[0].elements[childrenNamesList];
	else
		var childrenNamesDIV = document.getElementById(childrenNamesList);
		
	if (childrenNamesDIV)
		childrenNamesDIV.parentNode.removeChild(childrenNamesDIV);
		
	return;	

}

function RemoveAllOptions(selectbox)
{
	selectbox.options.length = 0;
	selectbox.selectedIndex = 0;
}


function AddOption(selectBox, text, value )
{
	selectBox[selectBox.options.length] = new Option(text);
	selectBox.options[selectBox.options.length-1].value = value;
	
}


function SetZipCode (zipCode) {
	
	var filterZip = /^(\D{1}\d{1}\D{1})(\d{1}\D{1}\d{1})$/i;

	zipCode.value = zipCode.value.toUpperCase();
	zipCode.value = zipCode.value.replace(/\s/g, '');
	
	if (!filterZip.test(zipCode.value)) {
		alert("Please enter a valid postal code!");
		document.forms[0].Contact_ZipCode.focus();
		return false;
	}	

	var pattern = /^\D{1}\d{1}\D{1}\d{1}\D{1}\d{1}$/;
	
	zipCode.value = zipCode.value.replace(filterZip, "$1$2");
	
	return true;

}

function SetTelephone (telephone) {
	
	if (telephone.name == "Contact_CellPhone" && telephone.value == "")
		return;
		
	//strip out acceptable non-numeric characters	
	var stripped = telephone.value.replace(/[\(\)\.\-\ ]/g, '');
	
	if (isNaN(Number(stripped))) {
		alert("Sorry, " + telephone.name + " contains illegal characters.\nPlease correct it");
		
		if (telephone.name == "Contact_HomePhone")
			document.forms[0].Contact_HomePhone.focus();
		else if (telephone.name == "Contact_CellPhone")
			document.forms[0].Contact_CellPhone.focus();
		else
			document.forms[0].Doctor_Telephone.focus();
			
		return false;
	}	

	if (!(stripped.length == 10)) {
		alert("Sorry, " + telephone.name + " has the wrong length.\nMake sure to include an area code.");

		if (telephone.name == "Contact_HomePhone")
			document.forms[0].Contact_HomePhone.focus();
		else if (telephone.name == "Contact_CellPhone")
			document.forms[0].Contact_CellPhone.focus();
		else
			document.forms[0].Doctor_Telephone.focus();

		return false;
	}

	var pattern = /^(\d{3})(\d{3})(\d{4})$/;
	telephone.value = stripped.replace(pattern, "($1) $2-$3");
}


function SetBabyInfo(regForm)
{
	
	if (regForm.Baby_Yes[0].checked) {
		
		regForm.Baby_Info.value = "Baby " + regForm.Contact_LastName.value + " " + regForm.Baby_BirthMonth.value + "/" + regForm.Baby_BirthDay.value + "/" + regForm.Baby_BirthYear.value;
	}
	else
		regForm.Baby_Info.value = "";
	
	return;
}

function ValidateValue(regForm)
{

	var error = "Sorry, you have not filled in the following required field: \n\n";
	
	if(regForm.Contact_FirstName.value == "") {
		error += "Your first name\n";
		regForm.Contact_FirstName.focus();	
		
		alert(error);
		return false;	
	}
	
	if (regForm.Contact_LastName.value =="") {
		error += "Your last name\n";
		regForm.Contact_LastName.focus();	

		alert(error);		
		return false;			
	}		
	
	if(regForm.Contact_StreetAddress.value == "") {
		error += "Your street address\n";
		regForm.Contact_StreetAddress.focus();		

		alert(error);		
		return false;		
	}

	if (regForm.Contact_City.value == "") {
		error += "Your city\n";
		regForm.Contact_City.focus();		

		alert(error);				
		return false;		
	}		
	
	if (regForm.Contact_ZipCode.value == "") {
		error += "Your postal code\n";
		regForm.Contact_ZipCode.focus();	

		alert(error);		
		return false;			
	}		
			
	if (regForm.Contact_HomePhone.value == "") {
		error += "Your homephone number\n";
		regForm.Contact_HomePhone.focus();		

		alert(error);		
		return false;		
	}
	
			
	
	if (regForm.Contact_EmailYes[0].checked && regForm.Contact_Email.value =="") {
		error += "Your email address\n";
		regForm.Contact_Email.focus();		

		alert(error);		
		return false;		
	}	
	
	if (regForm.Contact_EmailYes[0].checked && regForm.Contact_Email.value != "") {
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!filter.test(regForm.Contact_Email.value)) {
			error += "Your email address is not valid!\n";
			regForm.Contact_Email.focus();	

			alert(error);		
			return false;							
		}
	}		
	
	if (regForm.Contact_EmailYes[1].checked) {
		regForm.Contact_Email.value = "";
		regForm.Contact_Email.style.visibilty = "hidden";			
	}
	
	var childYes = 0;
	
	if (regForm.Child1_FirstName.value != "") {
		if (regForm.Child1_LastName.value == "") {
			error += "Your 1st child's last name\n";
			regForm.Child1_LastName.focus();	

			alert(error);		
			return false;					
		}
		
		if (regForm.Child1_BirthMonth.selectedIndex == 0 || regForm.Child1_BirthDay.selectedIndex == 0 || regForm.Child1_BirthYear.selectedIndex == 0) {
			error += "Your 1st child's birthday\n";
			regForm.Child1_BirthMonth.focus();
			
			alert(error);					
			return false;			
		}		

		if (!regForm.Child1_Sex[0].checked && !regForm.Child1_Sex[1].checked)
		{
			error += "Your 1st child's sex\n";
			regForm.Child1_Sex[0].focus();
			
			alert(error);					
			return false;			
		}

		
		childYes = childYes + 1;
	}	
	
	
	if (regForm.Child2_FirstName.value != "") {
		if (regForm.Child2_LastName.value == "") {
			error += "Your 2nd child's last name\n";
			regForm.Child2_LastName.focus();	

			alert(error);		
			return false;					
		}


	
		if (regForm.Child2_BirthMonth.selectedIndex == 0 || regForm.Child2_BirthDay.selectedIndex == 0 || regForm.Child2_BirthYear.selectedIndex == 0) {
			error += "Your 2nd child's birthday\n";
			regForm.Child2_BirthMonth.focus();
			
			alert(error);					
			return false;			
		}					
	
		if (!regForm.Child2_Sex[0].checked && !regForm.Child2_Sex[1].checked) {
			error += "Your 2nd child's sex\n";
			regForm.Child2_Sex[0].focus();	

			alert(error);		
			return false;					
		}
				
		childYes = childYes + 1;

	}		

	
	if (regForm.Child3_FirstName.value != "") {
		if (regForm.Child3_LastName.value == "") {
			error += "Your 3rd child's last name\n";
			regForm.Child3_LastName.focus();	

			alert(error);		
			return false;					
		}
			
		if (regForm.Child3_BirthMonth.selectedIndex == 0 || regForm.Child3_BirthDay.selectedIndex == 0 || regForm.Child3_BirthYear.selectedIndex == 0) {
			error += "Your 3rd child's birthday\n";
			regForm.Child3_BirthMonth.focus();
			
			alert(error);					
			return false;			
		}						
	
		if (!regForm.Child3_Sex[0].checked && !regForm.Child3_Sex[1].checked) {
			error += "Your 3rd child's sex\n";
			regForm.Child3_Sex[0].focus();	

			alert(error);		
			return false;					
		}
	
		childYes = childYes + 1;
	
	}	



	if (regForm.Baby_Yes[0].checked)
	{
		if (regForm.Baby_BirthMonth.selectedIndex == 0 || regForm.Baby_BirthDay.selectedIndex == 0 || regForm.Baby_BirthYear.selectedIndex == 0) {
			error += "Your Baby's due date\n";
			regForm.Baby_BirthMonth.focus();
			
			alert(error);					
			return false;			
		}
		childYes = childYes + 1;
	}
	


	var progSelected = 0;
	if (regForm.TotProgram_1.selectedIndex != 0) {
	
		if (childYes == 0) {
			error += "You did not enter any child's information.\n";
			regForm.Child1_FirstName.focus();			
			alert(error);					
			return false;			
		}		
	
		var childrenNames = document.forms[0].elements["TotProgramChildrenNames_1[]"];
		var checked = 0;
			
		for (var i = 1; i < childrenNames.length; i++) {
			if ( childrenNames[i].checked) {
				checked = 1;
				break;
			}
		}
		
	
		if (checked==0) {
			alert("Sorry, you have not selected Attending Children's Names for the 1st Choice Parent & Tot Program.\nPlease complete the entry.");
			childrenNames[1].focus();			
			return false;
		}

		progSelected = 1;
	}


	if (regForm.TotProgram_2.selectedIndex != 0) {

		if (childYes == 0) {
			error += "You did not enter any child's information.\n";
			regForm.Child1_FirstName.focus();			
			alert(error);					
			return false;			
		}		

	
		var childrenNames = document.forms[0].elements["TotProgramChildrenNames_2[]"];
		var checked = 0;
			
		for (var i = 1; i < childrenNames.length; i++) {
			if ( childrenNames[i].checked) {
				checked = 1;
				break;
			}
		}
		
	
		if (checked==0) {
			alert("Sorry, you have not selected Attending Children's Names for the 2nd Choice Parent & Tot Program.\nPlease complete the entry.");
			childrenNames[1].focus();			
			return false;
		}
		progSelected = 1;
	}


	if (regForm.TotProgram_3.selectedIndex != 0) {
		if (childYes==0) {
			error += "You did not enter any child's information.\n";
			regForm.Child1_FirstName.focus();			
			alert(error);					
			return false;			
		}		
	
		var childrenNames = document.forms[0].elements["TotProgramChildrenNames_3[]"];
		var checked = 0;
			
		for (var i = 1; i < childrenNames.length; i++) {
			if ( childrenNames[i].checked) {
				checked = 1;
				break;
			}
		}
		
	
		if (checked==0) {
			alert("Sorry, you have not selected Attending Children's Names for the 3rd Choice Parent & Tot Program.\nPlease complete the entry.");
			childrenNames[1].focus();			
			return false;
		}
		progSelected = 1;
	}
	
	if (regForm.TotProgram_4.selectedIndex != 0) {

		if (childYes==0) {
			error += "You did not enter any child's information.\n";
			regForm.Child1_FirstName.focus();			
			alert(error);					
			return false;			
		}		
	
		var childrenNames = document.forms[0].elements["TotProgramChildrenNames_4[]"];
		var checked = 0;
			
		for (var i = 1; i < childrenNames.length; i++) {
			if ( childrenNames[i].checked) {
				checked = 1;
				break;
			}
		}
		
	
		if (checked==0) {
			alert("Sorry, you have not selected Attending Children's Names for the 4th Choice Parent & Tot Program.\nPlease complete the entry.");
			childrenNames[1].focus();			
			return false;
		}
		progSelected = 1;
	}
		
	if (progSelected == 1 && !regForm.OneProgram_YN[0].checked && !regForm.OneProgram_YN[1].checked) {
		alert("Sorry, you have to answear whether you wish to do only ONE program this season or not.")
		regForm.OneProgram_YN[0].focus();
		return false;
	}
	

	
	if (regForm.ParProgram_1.selectedIndex != 0) {

//		if (regForm.ParProgram_1.selectedIndex != 3) {
			var childrenNames = document.forms[0].elements["ParProgramChildrenNames_1[]"];
			var checked = 0;
			
			if (childYes == 0)
				childrenNames[0].checked = true;
			
/*
		}
		else {
			var spouseName = document.forms[0].elements['ParProgramChildren_1_Spouse'];
			if (spouseName.value  == "") {
				alert("Sorry, you have not entered your spouse's name for the 1st Choice Parent & Caregiver Program.\nPlease complete the entry.");
				spouseName.focus();			
				return false;
			}
		}
*/

	}
	
	
	if (regForm.ParProgram_2.selectedIndex != 0) {

			var childrenNames = document.forms[0].elements["ParProgramChildrenNames_2[]"];
			var checked = 0;
			
			if (childYes == 0)
				childrenNames[0].checked = true;
				
			
	}
	

	if (regForm.ParProgram_3.selectedIndex != 0) {

			var childrenNames = document.forms[0].elements["ParProgramChildrenNames_3[]"];
			var checked = 0;
			
			if (childYes == 0)
				childrenNames[0].checked = true;
				
	}
	
	if (regForm.ParProgram_4.selectedIndex != 0) {

			var childrenNames = document.forms[0].elements["ParProgramChildrenNames_4[]"];
			var checked = 0;
			
			if (childYes == 0)
				childrenNames[0].checked = true;
			
	}




	


	if (!regForm.VolunteerYes[0].checked && !regForm.VolunteerYes[1].checked) {
		alert("Sorry, you have to answear whether you can volunteer at the Centre or not.")
		regForm.VolunteerYes[0].focus();
		return false;
	}

	var volunteerList = document.forms[0].elements('Volunteer[]');
	var checked = false;
	if (regForm.VolunteerYes[0].checked) {
		for (var i = 0; i < volunteerList.length-1; i++) {
			if ( volunteerList[i].checked) {
				checked = true;
				break;
			}
		}
		
		if (volunteerList[i].value != "")
			checked = true;
		
		if (!checked) {
			alert("Sorry, you have not selected any area that you can volunteer at the Centre.\nPlease complete the Volunteer Section.");
			volunteerList[0].focus();			
			return false;
		}
	}
	else if (regForm.VolunteerYes[1].checked) {
			for (var i = 0; i < volunteerList.length-1; i++) {
				volunteerList[i].checked = false;
			}

	}
		
//	regForm.Contact_HomePhone.value = stripped;
	
	return true;
}



