// *** NOTE: English-language text in alerts, etc.
function validateEmail(email) {
/*	new version by Laurence 2004 Nov 26
	revised 2005 Nov 04 by Laurence: allow hyphens before @ symbol; rename 'verifyEmail' to 'validateEmail'

	RegExp is a Javascript1.2 feature; tested successfully in WinIE 5.0+, MacIE 5.1, Safari 1.0, WinNN 4.7, WinNN 6.2, WinMoz 1.7
	The pattern matches: 
	- at least one word character ( a-zA-Z0-9_ )
	- followed by any number more including periods and hyphens
	- then a single @
	- then at least one alphanumeric character plus any number more including hyphens and periods
	- plus an ending of an alphanumeric char, a single period, and at least 2 more letters. 
	There can be nothing before or after the pattern; all whitespace, punctuation, etc. not explicitly allowed is forbidden.
*/
	var myRegExp = /^[\w][\w\.\-]*@[a-zA-Z0-9]+[\w\.\-]*[a-zA-Z0-9]\.[a-zA-Z]{2,}$/;
	var sPos = email.search(myRegExp);
	if (sPos >= 0) {
		return true;
	} else {
		return false;
	}
}

function validateSendToFriend() {
	
	var theForm = document.frmSendToFriend;
	var emptyFields = "";

	if (theForm.senderName.value == ""){
		emptyFields += "Your name must not be blank." + "\n" ;
	}
	
	if (theForm.senderEmail.value == ""){
		emptyFields += "Your e-mail address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.senderEmail.value)) {
		emptyFields += "The sender's e-mail address is invalid" + "\n" ;
	}
	
	if (theForm.friendName.value == ""){
		emptyFields += "Your friend's name must not be blank." + "\n" ;
	}
	
	if (theForm.friendEmail.value == ""){
		emptyFields += "Your friend's e-mail address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.friendEmail.value)) {
		emptyFields += "Your friend's e-mail address is invalid" + "\n" ;
	}	

	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}
}

function validateLostPassword() {
	
	var theForm = document.frmPassword;
	var emptyFields = "";

	if (theForm.emailaddress.value == ""){
		emptyFields += "Your e-mail address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailaddress.value)) {
		emptyFields += "Your e-mail address is invalid" + "\n" ;
	}	
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}		
}

function validateSignIn(theForm) {
/*	var theForm = document.frmSignIn; */
	var emptyFields = "";

	if (theForm.emailAddress.value == ""){
		emptyFields += "Your email must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "Your email address format is not recognized." + "\n" ;
	}
	if (theForm.password.value == ""){
		emptyFields += "Your password must not be blank." + "\n" ;
	}

	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}		
}

function validateRateResource(theForm) {
/*	var theForm = document.frmRateResource;
	alert('validating user rating / review...'); */
	var emptyFields = "";

	if (theForm.ratingId.selectedIndex == 0) {
		emptyFields += "Please select a rating from the dropdown list." + "\n" ;
	}

	if (theForm.userReview.value.length > 2000) {
		emptyFields += "User-written reviews are limited to 2000 characters.\nPlease shorten your text from " + theForm.userReview.value.length + " characters to 2000 or less.\n" ;
	}

	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}		
}

function validateProfile(theForm) {
    var theForm = document.frmProfile;
	var emptyFields = "";

	if (theForm.emailaddress.value == ""){
		emptyFields += "Your email must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailaddress.value)) {
		emptyFields += "Your email address format is not recognized." + "\n" ;
	}
	
	if (theForm.password_new.value != "" && theForm.password_confirm.value != ""){
		if (theForm.password_confirm.value != theForm.password_new.value){
        emptyFields += "The passwords you entered do not match." + "\n" ;
      }	
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		theForm.submit();
		return true;
	}		
}

function validateSignUp() {
	
	var theForm = document.frmSignUp;
	var emptyFields = "";

	
	if (theForm.userName.value == ""){
		emptyFields += "Your username must not be blank." + "\n" ;
	}	
	
	if (theForm.emailaddress.value == ""){
	emptyFields += "Your email must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailaddress.value)) {
		emptyFields += "Your email address format is not recognized." + "\n" ;
	}
	
	if (theForm.emailVerify.value == ""){
	emptyFields += "Your email verification must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailVerify.value)) {
		emptyFields += "Your email verification address format is not recognized." + "\n" ;
	}

    if (theForm.emailaddress.value != theForm.emailVerify.value){
        emptyFields += "The email addresses you entered do not match." + "\n" ;
    }
    	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
    //  theForm.submit();
		return true;
	}		
}

function validateFeedback() {
	var theForm = document.frmFeedback;
	var emptyFields = "";
	
	if (theForm.email.value == ""){
	emptyFields += "Your email address must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.email.value)) {
		emptyFields += "Your email address format is not recognized." + "\n" ;
	}
	
	if (theForm.subject.value == ""){
		emptyFields += "You must enter a subject to submit your feedback." + "\n" ;
	}
	
	if (theForm.comments.value == ""){
		emptyFields += "You must enter a comment to submit your feedback." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}
}

function validateSuggest() {
	var theForm = document.frmSuggest;
	var emptyFields = "";
	
	if (theForm.url.value == ""){
		emptyFields += "Please enter a website address to recommend a resource." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}
}

function validateSuggestTopic() {
	var theForm = document.frmSuggestTopic;
	var emptyFields = "";
	
	if (theForm.comments.value == ""){
		emptyFields += "Please describe your feature idea to send to the Editor." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}
}

function validateLendAHand() {
	var theForm = document.frmLendAHand;
	var emptyFields = "";
	
	if (theForm.title.value == ""){
		emptyFields += "You must enter a title." + "\n" ;
	}
	
	if (theForm.body.value == ""){
		emptyFields += "You must enter text into the body of your message." + "\n" ;
	}
		
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}
}

function validateJournal() {
	
	var theForm = document.frmJournal;
	var emptyFields = "";

	if (theForm.firstname.value == ""){
		emptyFields += "Your first name must not be blank." + "\n" ;
	}
	
	if (theForm.lastname.value == ""){
		emptyFields += "Your last name must not be blank." + "\n" ;
	}
	
	if (theForm.address1.value == ""){
		emptyFields += "Address 1 must not be blank." + "\n" ;
	}
	
	if (theForm.city.value == ""){
		emptyFields += "City must not be blank." + "\n" ;
	}
	
	if (theForm.province.value == ""){
		emptyFields += "Province must not be blank." + "\n" ;
	}
	
	if (theForm.pocode.value == ""){
		emptyFields += "Postal Code must not be blank." + "\n" ;
	}

	if (theForm.captchaText.value == ""){
		emptyFields += "Please type in the verification characters." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}
}

function validateConfirmForm() {
	
	var theForm = document.frmSignUp;
	var emptyFields = "";

	if (theForm.userName.value == ""){
		emptyFields += "Your Nickname must not be blank." + "\n" ;
	}
	
	if (theForm.password.value == ""){
		emptyFields += "Your password must not be blank." + "\n" ;
	}
	
	if (theForm.emailaddress.value == ""){
	emptyFields += "Your email address must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailaddress.value)) {
		emptyFields += "Your email address format is not recognized." + "\n" ;
	}
	
	if (theForm.emailVerify.value == ""){
	emptyFields += "Your email verification must not be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailVerify.value)) {
		emptyFields += "Your email verification address format is not recognized." + "\n" ;
	}

    if (theForm.emailaddress.value != theForm.emailVerify.value){
        emptyFields += "The email addresses you entered do not match." + "\n" ;
    }
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
	//	theForm.submit();
		return true;
	}

}

function getOther(){
		var theForm = document.frmSignUp;
		var objStyle = document.getElementById('otherDiv');
		
		if(theForm.comments.selectedIndex == 10){
			//show the other field	
			objStyle.style.display = "block";
		}else{
			objStyle.style.display = "none";
		}
	
}