
function validEmail(email) {
	return (email.indexOf(".") > 0) && (email.indexOf("@") > 0);
}

function validateDF() {

	test = document.DataForm.eventname.value;
	if (test.length < 2) {
		alert ("Please enter the name of this event");
		return false;
	}
	
	test = document.DataForm.cutoffdate.value;
	if (test.length != 10) {
		alert ("Please enter a cutoff date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
		return false;
	}
	if ((test.charAt(2) != "/") || (test.charAt(5) != "/")) {
		alert ("Please enter a cutoff date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
		return false;
	}
	valid = "0123456789";
	test1 = test.substring(0,2);
	test2 = test.substring(3,5);
	test3 = test.substring(6);
	testAll = test1 + test2 + test3;
	for (var i=0; i < testAll.length; i++) {
		var letter = testAll.charAt(i);
		if (valid.indexOf(letter) != -1) continue;
		alert ("Please enter a cutoff date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
			return false;
		break;
	}	
	if ((parseInt(test.substring(0,2),10) > 31) || (parseInt(test.substring(3,5),10) > 12) || (parseInt(test.substring(6),10) < 2005) || (parseInt(test.substring(6),10) > 2099)) {
		alert ("Please enter a cutoff date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
		return false;
	}
	
	test = document.DataForm.startdate.value;
	if (test.length != 10) {
		alert ("Please enter a starting date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
		return false;
	}
	if ((test.charAt(2) != "/") || (test.charAt(5) != "/")) {
		alert ("Please enter a starting date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
		return false;
	}
	valid = "0123456789";
	test1 = test.substring(0,2);
	test2 = test.substring(3,5);
	test3 = test.substring(6);
	testAll = test1 + test2 + test3;
	for (var i=0; i < testAll.length; i++) {
		var letter = testAll.charAt(i);
		if (valid.indexOf(letter) != -1) continue;
		alert ("Please enter a starting date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
			return false;
		break;
	}	
	if ((parseInt(test.substring(0,2),10) > 31) || (parseInt(test.substring(3,5),10) > 12) || (parseInt(test.substring(6),10) < 2005) || (parseInt(test.substring(6),10) > 2099)) {
		alert ("Please enter a starting date for this event listing in the exact format 'dd/mm/yyyy' or use the pop-up calendar");
		return false;
	}
	
	test = document.DataForm.dateline.value;
	if (test.length < 2) {
		alert ("Please enter a sentence describing the date(s) of this event");
		return false;
	}
		
	test = document.DataForm.description1.value;
	if (test.length < 2) {
		alert ("Please enter a description for this event");
		return false;
	}
		
	test = document.DataForm.description1.value;
	if (test.length > 255) {
		alert ("An event description must be less than 255 characters in length");
		return false;
	}
		
	test = document.DataForm.description2.value;
	if (test.length > 255) {
		alert ("An event description must be less than 255 characters in length");
		return false;
	}
		
	if ((validEmail(document.DataForm.contactemail.value) == false) && (document.DataForm.contactemail.value != "")) {
		alert ("Please enter a valid e-mail address for the information contact");
		return false;
	}
	return true; 
}

function validateFF() {

	if ((validEmail(document.FeedbackForm.email.value) == false) && (document.FeedbackForm.email.value != "")) {
		alert ("Please enter a valid e-mail address in the form 'info@schriemers.ca'");
		return false;
	}

	test = document.FeedbackForm.comments.value;
	if (test.length > 2000) {
		alert ("Wow, you have a lot to say, but please make your comments a little shorter!");
		return false;
	}
	return true; 
}

function validatePF() {

	if (validEmail(document.DoctorForm.email.value) == false) {
		alert ("Please enter a valid e-mail address in the form 'info@schriemers.ca'");
		return false;
	}

	test = document.DoctorForm.question.value;
	if (test.length > 2000) {
		alert ("Wow, you have a lot to say, but please make your question a little shorter!");
		return false;
	}
	if (test.length < 10) {
		alert ("Don't forget to enter your question!");
		return false;
	}
	return true; 
}

function formTrigger() {
	document.PasswordForm.submit();
	return false; 
}

function validateNF() {

	test = document.DataForm.edt.value;
	if (test.length < 2) {
		alert ("Please enter a title for this newsletter, e.g. 'July Newsletter'");
		return false;
	}

	test = document.DataForm.wel.value;
	if (test.length < 2) {
		alert ("Please enter a welcome or introductory message for this newsletter");
		return false;
	}

	test = document.DataForm.b1t.value;
	if (test.length < 2) {
		alert ("Please enter a title or heading for the first content block");
		return false;
	}

	test = document.DataForm.b1c.value;
	if (test.length < 2) {
		alert ("Please enter your content or text for the first content block");
		return false;
	}

	test1 = document.DataForm.b1f.value;
	test2 = document.DataForm.b1p.value;
	test3 = document.DataForm.sendstatus.value;
	if ((test3 == "new") && (test1 == true) && (test2.length < 2)) {
		alert ("You have indicated that you are providing a photo with block 1 but none has been attached!");
		return false;
	}
	if ((test3 == "new") && (test1 == false) && (test2.length > 2)) {
		alert ("If you are attaching a photo to block 1, you must check the corresponding box!");
		return false;
	}
	photoext = test.substr(test2.length-3,3);
	if ((test1 == true) && (test2.length > 3)) {
		if ((photoext != "jpg") && (photoext != "JPG") && (photoext != "peg") && (photoext != "PEG")) {
			alert ("Your block 1 photo must be in JPEG format only");
			return false;
		}
	}

	test1 = document.DataForm.b2t.value;
	test2 = document.DataForm.b2c.value;
	if ((test1.length < 2) && (test2.length > 2)) {
		alert ("You have entered content for block 2 but no title!");
		return false;
	}
	if ((test2.length < 2) && (test1.length > 2)) {
		alert ("You have entered a title for block 2 but no content!");
		return false;
	}

	test1 = document.DataForm.b2f.value;
	test2 = document.DataForm.b2p.value;
	test3 = document.DataForm.sendstatus.value;
	if ((test3 == "new") && (test1 == true) && (test2.length < 2)) {
		alert ("You have indicated that you are providing a photo with block 2 but none has been attached!");
		return false;
	}
	if ((test3 == "new") && (test1 == false) && (test2.length > 2)) {
		alert ("If you are attaching a photo to block 2, you must check the corresponding box!");
		return false;
	}
	photoext = test.substr(test2.length-3,3);
	if ((test1 == true) && (test2.length > 3)) {
		if ((photoext != "jpg") && (photoext != "JPG") && (photoext != "peg") && (photoext != "PEG")) {
			alert ("Your block 2 photo must be in JPEG format only");
			return false;
		}
	}

	test1 = document.DataForm.b3t.value;
	test2 = document.DataForm.b3c.value;
	if ((test1.length < 2) && (test2.length > 2)) {
		alert ("You have entered content for block 3 but no title!");
		return false;
	}
	if ((test2.length < 2) && (test1.length > 2)) {
		alert ("You have entered a title for block 3 but no content!");
		return false;
	}

	test1 = document.DataForm.b3f.value;
	test2 = document.DataForm.b3p.value;
	test3 = document.DataForm.sendstatus.value;
	if ((test3 == "new") && (test1 == true) && (test2.length < 2)) {
		alert ("You have indicated that you are providing a photo with block 3 but none has been attached!");
		return false;
	}
	if ((test3 == "new") && (test1 == false) && (test2.length > 2)) {
		alert ("If you are attaching a photo to block 3, you must check the corresponding box!");
		return false;
	}
	photoext = test.substr(test2.length-3,3);
	if ((test1 == true) && (test2.length > 3)) {
		if ((photoext != "jpg") && (photoext != "JPG") && (photoext != "peg") && (photoext != "PEG")) {
			alert ("Your block 3 photo must be in JPEG format only");
			return false;
		}
	}

	test1 = document.DataForm.b4t.value;
	test2 = document.DataForm.b4c.value;
	if ((test1.length < 2) && (test2.length > 2)) {
		alert ("You have entered content for block 4 but no title!");
		return false;
	}
	if ((test2.length < 2) && (test1.length > 2)) {
		alert ("You have entered a title for block 4 but no content!");
		return false;
	}

	test1 = document.DataForm.b4f.value;
	test2 = document.DataForm.b4p.value;
	test3 = document.DataForm.sendstatus.value;
	if ((test3 == "new") && (test1 == true) && (test2.length < 2)) {
		alert ("You have indicated that you are providing a photo with block 4 but none has been attached!");
		return false;
	}
	if ((test3 == "new") && (test1 == false) && (test2.length > 2)) {
		alert ("If you are attaching a photo to block 4, you must check the corresponding box!");
		return false;
	}
	photoext = test.substr(test2.length-3,3);
	if ((test1 == true) && (test2.length > 3)) {
		if ((photoext != "jpg") && (photoext != "JPG") && (photoext != "peg") && (photoext != "PEG")) {
			alert ("Your block 4 photo must be in JPEG format only");
			return false;
		}
	}

	test1 = document.DataForm.b5t.value;
	test2 = document.DataForm.b5c.value;
	if ((test1.length < 2) && (test2.length > 2)) {
		alert ("You have entered content for block 5 but no title!");
		return false;
	}
	if ((test2.length < 2) && (test1.length > 2)) {
		alert ("You have entered a title for block 5 but no content!");
		return false;
	}

	test1 = document.DataForm.b5f.value;
	test2 = document.DataForm.b5p.value;
	test3 = document.DataForm.sendstatus.value;
	if ((test3 == "new") && (test1 == true) && (test2.length < 2)) {
		alert ("You have indicated that you are providing a photo with block 5 but none has been attached!");
		return false;
	}
	if ((test3 == "new") && (test1 == false) && (test2.length > 2)) {
		alert ("If you are attaching a photo to block 5, you must check the corresponding box!");
		return false;
	}
	photoext = test.substr(test2.length-3,3);
	if ((test1 == true) && (test2.length > 3)) {
		if ((photoext != "jpg") && (photoext != "JPG") && (photoext != "peg") && (photoext != "PEG")) {
			alert ("Your block 5 photo must be in JPEG format only");
			return false;
		}
	}
	return true; 
}

function validateSF() {

	if ((validEmail(document.SubscribeForm.email.value) == false) || (document.SubscribeForm.email.value == "")) {
		alert ("Please enter a valid e-mail address in the form 'info@schriemers.ca'");
		return false;
	}
	return true;
}

