//2007-02-05, ET : Altered so it can tell encrypted field values 
//2007-03-05, ET : create 2 sep functions - as only testing anti-spam change (which sends through email, confirmemail & text) on sites3, not howis or jobs at the moment - when they go over can remove first one and alter sites3 again. 

function validateformspam(Email,ConfirmEmail,Text) {
	
	 for (var i = 0; i<document.form.elements.length; i++){
			if(i == Email){
				var Email = document.form.elements[i].value;
				}
			else if(i == ConfirmEmail){
				var ConfirmEmail = document.form.elements[i].value;
				}
			else if (i == Text){
				var Text = document.form.elements[i].value;
				}
			
			}
	
	// If the user HAS NOT entered an email address
	if(Email!= "" && Email != "cyfeiriad e-bost yma") { 
		// Check to see if the value entered in the email field matches the value in the confirm email field
		if (Email != ConfirmEmail) {
			alert("Nid yw'r cyfeiriadau e-bost yn cyd-fynd.");
			return false;
		} else {
			// check to see if the email addresses entered are of a valid format
			if(Email.match(/^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$/i)) { 
				/* If the email address has been entered, the email addresses match and are 
				   of a valid format, Check to see if a comment has been entered*/
				if(Text == "" || Text == "eich adborth yma") {
					alert("Rhaid i chi nodi sylwadau.");
					return false;
				} else {
					return true;
				}
			} else {
				alert("Mae fformat y cyfeiriad e-bost yn anghywir.");
				return false;
			}
		}
	} else {
		/* If the email address has been entered, the email addresses match and are 
		of a valid format, Check to see if a comment has been entered*/
		if(Text == "" || Text == "eich adborth yma") {
			alert("Rhaid i chi nodi sylwadau.");
			return false;
		} else {
			return true;
		}
	}
}


function validateform() {
	// If the user HAS NOT entered an email address
	if(form.Email.value != "" && form.Email.value != "cyfeiriad e-bost yma") { 
		// Check to see if the value entered in the email field matches the value in the confirm email field
		if (form.Email.value != form.ConfirmEmail.value) {
			alert("Nid yw'r cyfeiriadau e-bost yn cyd-fynd.");
			return false;
		} else {
			// check to see if the email addresses entered are of a valid format
			if(form.Email.value.match(/^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$/i)) { 
				/* If the email address has been entered, the email addresses match and are 
				   of a valid format, Check to see if a comment has been entered*/
				if(form.Text.value == "" || form.Text.value == "eich adborth yma") {
					alert("Rhaid i chi nodi sylwadau.");
					return false;
				} else {
					return true;
				}
			} else {
				alert("Mae fformat y cyfeiriad e-bost yn anghywir.");
				return false;
			}
		}
	} else {
		/* If the email address has been entered, the email addresses match and are 
		of a valid format, Check to see if a comment has been entered*/
		if(form.Text.value == "" || form.Text.value == "eich adborth yma") {
			alert("Rhaid i chi nodi sylwadau.");
			return false;
		} else {
			return true;
		}
	}
}


