// *** 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 validateForm() {
	var theForm = document.frmGetInfo;
	var emptyFields = "";
	if (theForm.chkEmail.checked || theForm.chkMail.checked){
		if (theForm.txtFirstName.value == ""){
			emptyFields += "Your first name must not be blank." + "\n" ;
		}	
		if (theForm.txtLastName.value == ""){
			emptyFields += "Your last name must not be blank." + "\n" ;
		}
		
		//Check fields specific to the delivery method: EMAIL
		if (theForm.chkEmail.checked){
			if (theForm.txtEmail.value == ""){
				emptyFields += "Your email address must not be blank." + "\n" ;
			} else 
			if (!validateEmail(theForm.txtEmail.value)) {
				emptyFields += "Your email address format is not recognized." + "\n" ;
			}	
		}//if (theForm.chkEmail.checked)
		
		//Check fields specific to the delivery method: Regular Mail
		if (theForm.chkMail.checked){
			if (theForm.txtAddress1.value == ""){
				emptyFields += "Your address must not be blank." + "\n" ;
			}				
			if (theForm.txtCity.value == ""){
				emptyFields += "Your city must not be blank." + "\n" ;
			}	
			if (theForm.txtProvince.value == ""){
				emptyFields += "Your province must not be blank." + "\n" ;
			}	
			if (theForm.txtZip.value == ""){
				emptyFields += "Your postal/zip code must not be blank." + "\n" ;
			}	
		}//theForm.chkMail.checked

		
		//Display error message OR allow the form to submit
		if (emptyFields.length >= 1) {
			alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
			return false;
		} 
		else{
			return true;	
		}
	}//theForm.chkEmail.checked || theForm.chkMail.checked
	else
	{
		alert("Please ensure that a method of delivery is selected.");
		return false;
	}
	
}

/*     */
function validateContactMeForm() {
	var theForm = document.frmContactMe;
	var emptyFields = "";
	if (theForm.chkEmail.checked || theForm.chkMail.checked || theForm.chkCall.checked ){
		if (theForm.txtFirstName.value == ""){
			emptyFields += "Your first name must not be blank." + "\n" ;
		}	
		if (theForm.txtLastName.value == ""){
			emptyFields += "Your last name must not be blank." + "\n" ;
		}
		
		//Check fields specific to the delivery method: EMAIL
		if (theForm.chkEmail.checked){
			if (theForm.txtEmail.value == ""){
				emptyFields += "Your email address must not be blank." + "\n" ;
			} else 
			if (!validateEmail(theForm.txtEmail.value)) {
				emptyFields += "Your email address format is not recognized." + "\n" ;
			}	
		}//if (theForm.chkEmail.checked)
		
		//Check fields specific to the delivery method: PHONE
		if (theForm.chkCall.checked){
			if (theForm.txtPhone.value == ""){
				emptyFields += "Your phone number must not be blank." + "\n" ;
			} 
		}//if (theForm.chkEmail.checked)
		
		
		//Check fields specific to the delivery method: Regular Mail
		if (theForm.chkMail.checked){
			if (theForm.txtAddress1.value == ""){
				emptyFields += "Your address must not be blank." + "\n" ;
			}				
			if (theForm.txtCity.value == ""){
				emptyFields += "Your city must not be blank." + "\n" ;
			}	
			if (theForm.txtProvince.value == ""){
				emptyFields += "Your province must not be blank." + "\n" ;
			}	
			if (theForm.txtZip.value == ""){
				emptyFields += "Your postal/zip code must not be blank." + "\n" ;
			}	
		}//theForm.chkMail.checked

		
		//Display error message OR allow the form to submit
		if (emptyFields.length >= 1) {
			alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
			return false;
		} 
		else{
			return true;	
		}
	}//theForm.chkEmail.checked || theForm.chkMail.checked
	else
	{
		alert("Please ensure that a method of delivery is selected.");
		return false;
	}
	
}



function ChangeVisibility(checkbox,field){
	if (checkbox.checked)
		field.style.display="";
	else
		field.style.display="none";
}
function EmailFields(){
//display the required fields
    var chkEmail = document.getElementById('chkEmail');
 	var reqEmail = document.getElementById('reqEmail');
	ChangeVisibility(chkEmail,reqEmail);	
}

function MailFields(){
//display the required fields
    var chkMail = document.getElementById('chkMail');
 	var reqCity = document.getElementById('reqCity');
    var reqProvince = document.getElementById('reqProvince');
	var reqAddress1 = document.getElementById('reqAddress1');
	var reqZip = document.getElementById('reqZip');

	ChangeVisibility(chkMail,reqCity);	
	ChangeVisibility(chkMail,reqProvince);
	ChangeVisibility(chkMail,reqAddress1);
	ChangeVisibility(chkMail,reqZip);	
}

function PhoneFields(){
//display the required fields
    var chkCall = document.getElementById('chkCall');
	var reqPhone = document.getElementById('reqPhone');
	ChangeVisibility(chkCall,reqPhone);	
}