//*****************************************************************************************************
function check_enter_email () {
	var email = document.getElementById('email');
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (!filter.test (email.value)) {
		alert ('Please provide a valid email address');
		email.focus ();
		return false;
	}
} // function check_enter_email

//*****************************************************************************************************
// Checks and verifies that the password and confirmation be the same one. If error returns false.
function check_password () {
	var p = document.getElementById ('password').value;
	var c = document.getElementById ('password_confirm').value;

	if (p != c) {
		alert ("Password and confirmation don't match !");
		return false;
	}

	return true;
} // function check_password

//*****************************************************************************************************
// Verifies that the age is > 18, 21 in mississippi and 19 in alabama. If error returns false.
function minimum_age () {
	var st = document.getElementById ('state');
	var state = st.options[st.selectedIndex].value;
	var date = document.getElementById ('birth_date').value;

	// Need to calculate the age
	now = new Date ();

	birth_date = date.split ('-');
	if (birth_date.length == 3) {
		born = new Date (birth_date[0], birth_date[1]*1-1, birth_date[2]);
		// Age is rounded down. if missing one day for birthday it will say as it is.
		age = Math.floor ((now.getTime () - born.getTime ()) / (365.25 * 24 * 60 * 60 * 1000));
	}

	// NE (nebraska), AL (alabama) > 19
	// MS (Mississippi) > 21
	// All others > 18
	if ((age < 18) || ((age < 21) && (state == 'MS')) || ((age < 19) && ((state == 'AL') || (state == 'NE')))) {
		alert ('Sorry, you must be over the legal age in your state to register in our website.' + age);
		return false;
	}
	
} // function minimum_age

//*****************************************************************************************************
// The user MUST choose at least 2 options
function choose_minimum () {
	var frm = document.getElementById ('frmPreferences');
	var i=0;
	var q=0;

	for (i=i; i < frm.elements.length; i++) {
		if ((frm.elements[i].type == 'checkbox') && (frm.elements[i].checked)) {
			q++;
		}
	} // for i

	// Minimum: 2
	if (q < 2) {
		alert ('Please select at least two options of your preference.');
		return false;
	}

	return true;
} //function choos_minimum
