﻿function forms_validate_newsletter(frm) {
	var result = true;
	var form = document.forms[frm];

	with (form) {
		if (validate_email(mm_newemail, "Please fill in a valid e-mail address.") == false)
		{ mm_newemail.focus(); return false; result = false; }
	}
	return result;
}


function forms_validate_trial(frm) {
	var result = true;
	var form = document.forms[frm];

	with (form) {
		if (validate_text(user_fname, "Please fill in your first name and all mandatory fields.") == false)
		{ user_fname.focus(); return false; result = false; }
		if (validate_text(user_lname, "Please fill in your last name and all mandatory fields.") == false)
		{ user_lname.focus(); return false; result = false; }
		if (validate_email(user_email, "Please fill in a valid e-mail address.") == false)
		{ user_email.focus(); return false; result = false; }
	}
	return result;
}

function forms_validate_distributor(frm) {
	var result = true;
	var form = document.forms[frm];
	with (form) {
		if (validate_text(distributor_company, "Please fill in company name name and all mandatory fields.") == false)
		{ distributor_company.focus(); return false; result = false; }

		if (validate_select(distributor_country, "Please select a country from the list and fill all mandatory fields.") == false)
		{ distributor_country.focus(); return false; result = false; }
		
		if (validate_text(distributor_contact_fname, "Please fill in your first name and all mandatory fields.") == false)
		{ distributor_contact_fname.focus(); return false; result = false; }
		
		if (validate_text(distributor_contact_lname, "Please fill in your last name and all mandatory fields.") == false)
		{ distributor_contact_lname.focus(); return false; result = false; }
	}
	return result;	
}

function validate_text(field, alerttxt) {
	//var reg = /^([A-Za-z]{3,})$/;
	var reg = /^([a-z]+(\'|-|\.\s|\s)?[a-z]*){3,}$/i
	with (field) {
		if (reg.test(value) == false)
		{ alert(alerttxt); return false; }
		else { return true }
	}
}

function validate_email(field, alerttxt) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	with (field) {
		if (reg.test(value) == false)
		{ alert(alerttxt); return false; }
		else { return true }
	}
}

function validate_select(field, alerttxt) {
	with (field) {
		if (options[field.selectedIndex].value == "")
		{ alert(alerttxt); return false; }
		else { return true }
	}
}