// JavaScript Document

function formDataVerify(f) {
	
	// Go through the fields that could have been submitted, 
	//	and validate what's in them if they are there
	
	var errCount = 0;
	var errMessage = "";
	//var patternEmail = /^[\w\.]+@[\w\.]+$/;
	var patternEmail = /^[\w!#\$%&'\*\+-\/=\?\^_`\{}\|~\.]+@[\w-\.]+$/;
	
	if (f.forename) {
		// Check this is not an empty string
		if (f.forename.value.length == 0) {
			errCount++;
			errMessage += "Please fill in your forename" + "\n";
		}
	}
	
	if (f.surname) {
		// Check this is not an empty string
		if (f.surname.value.length == 0) {
			errCount++;
			errMessage += "Please fill in your surname" + "\n";
		}
	}
	
	if (f.fullname) {
		// Check this is not an empty string
		if (f.fullname.value.length == 0) {
			errCount++;
			errMessage += "Please fill in your name" + "\n";
		}
	}

	if (f.email) {
		// Check this is not an empty string
		if (f.email.value.length == 0) {
			errCount++;
			errMessage += "Please fill in your e-mail address" + "\n";
		} else if (! patternEmail.test(f.email.value)) {
			// Check if it is a legal email address
			errCount++;
			errMessage += "Please fill in a real e-mail address" + "\n";
		}
	}
	
	if (f.name == "download-journal") {
		if (f.heard) {
			// Check this is not an empty string
			if (f.heard.selectedIndex < 1) {
				errCount++;
				errMessage += "Please select how you heard about us" + "\n";
			}
		}		
		if (f.region) {
			// Check this is not an empty string
			if (f.region.selectedIndex < 1) {
				errCount++;
				errMessage += "Please select your region" + "\n";
			}
		}				
		if (f.country) {
			// Check this is not an empty string
			if (f.country.selectedIndex < 1) {
				errCount++;
				errMessage += "Please select your country" + "\n";
			}
		}		
	}
	
	//alert("formDataVerify started");	
	
	if (errCount == 0) {
		//alert("verify passed");
		return true;
	} else {
		alert(errMessage);
		return false;
	}
	
}
