//	Enable/disable and check/un-check the ALL check
function updateToggle() {
	//	Javascript is OK so enable the checkbox
	if (document.thisForm.subscription0.disabled)
		document.thisForm.subscription0.disabled	= false;
	//	Check to see if all subscriptions are selected
	allCheck	= true;
	for (index = 0; index < document.thisForm.subscriptions.length; index++) {
		if (document.thisForm.subscriptions[index].checked == false) {
			allCheck	= false;
			break;
		}
	}
	//	Check or uncheck the ALL checkbox as approprite
	if (allCheck)
		document.thisForm.subscription0.checked = true;
	else
		document.thisForm.subscription0.checked = false;
}

//	Check/un-check all the subscription buttons as appropriate
function checkAll() {
	if (document.thisForm.subscription0.checked)
		for (index = 0; index < document.thisForm.subscriptions.length; index++)
			document.thisForm.subscriptions[index].checked = true;
	else
		for (index = 0; index < document.thisForm.subscriptions.length; index++)
			document.thisForm.subscriptions[index].checked = false;
}

//	Check Other
function chkOther(chkBx,action) {
	//	tweak control name provided for use below
	chkBx	= 'document.thisForm.' + chkBx;
	//	default 'action' value if not supplied
	if (!action)
		action	= 'blur';
	//	check or un-check the 'other' checkbox
	if (document.thisForm.otherReferral.value.length || action == 'focus') {
		eval(chkBx).checked	= true;
	} else {
		eval(chkBx).checked	= false;
	}
}

//	Form submission checks 
function formCheck(e) {
	//	e = event that triggered form submission
	if (!e)
		e	= window.event;	//	for MSIE
	//	What button submitted the form anyway?
	switch(e.value) {
		case 'Submit':
		case 'Update':
			//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
			//	Got any subscriptions (at least one)?
			anyChecked	= false;
			for (index = 0; index < document.thisForm.subscriptions.length; index++) {
				if (document.thisForm.subscriptions[index].checked) {
					anyChecked	= true;
					break;
				}
			}
			if (!anyChecked) {
				alert("Please select at least one item to receive via email.")
				return false;
			}
			//	Member Profile page does not ask for an email address...this gets around checking for that.
			if (document.thisForm.email && document.thisForm.confirmEmail) {
				//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
				//	Did you include something that remotely looks like an email address (and did it match the confirm email)?
				if (document.thisForm.email.value != document.thisForm.confirmEmail.value) {
					alert('Your Email and Confirm Email entries did not match. Please correct.');
					return false;
				}
				theEmail	= document.thisForm.email.value;
				theFilter	= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!theFilter.test(theEmail)) {
					alert('Please enter a properly formatted email address.');
					return false;
				}
				//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
				//	Un-check the "Other" checkbox if the field is empty.
				//	>> code here <<
			}
			break;
		case 'Unsubscribe':
			if (document.thisForm.unsubscribe.checked == false) {
				alert("Please click the checkbox to confirm your decision to unsubscribe from the Teachers' Network.");
				return false;
			}
			break;
		default:
			//	Cancel button clicked or something not anticipated occured.
	}
	//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	//	Form submission completed successfully...
	return true;
}

updateToggle();

