function checkemail() {
	var testresults;
	var str = document.demo_account_form.email.value;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults = true
	else
		testresults = false
	return (testresults)
}

function trim(s) {
	while (s.substring(0, 1) == ' ') {
		s = s.substring(1, s.length);
	}
	while (s.substring(s.length - 1, s.length) == ' ') {
		s = s.substring(0, s.length - 1);
	}
	return s;
}

function isNumeric(s) {
	if (s == null)
		return false;

	if (s.length == 0)
		return false;

	for (var i = 0; i < s.length; ++i) {
		if ("1234567890- +()".indexOf(s.charAt(i)) < 0) {
			return false;
		}
	}
	return true;
}


function ValidateForm() {



	//make sure that the first name is not blank.
	if (document.demo_account_form.first_name.value.length == 0) {
		//it isn't so show the user an alert and go to that field
		alert("Please enter your first name");
		document.demo_account_form.first_name.focus();
		//and return false so the form doesn't get submitted
		return false;
	}

	//make sure that the last name field is not blank.
	if (document.demo_account_form.last_name.value.length == 0) {
		//it isn't so show the user an alert and go to that field
		alert("Please enter your last name");
		document.demo_account_form.last_name.focus();
		//and return false so the form doesn't get submitted
		return false;
	}

	//make sure that the country field is not blank.
	if (document.demo_account_form.country.value.length == 0) {
		//it isn't so show the user an alert and go to that field
		alert("Please enter your country");
		document.demo_account_form.country.focus();
		//and return false so the form doesn't get submitted
		return false;
	}

	//make sure that the phone field is not blank.
	if ((document.demo_account_form.phone.value.length < 6) || (isNumeric(document.demo_account_form.phone.value) == false)) {
		//it isn't so show the user an alert and go to that field
		alert("Please enter a valid phone number. Valid characters are (), +, -, and 0-9.");
		document.demo_account_form.phone.focus();
		//and return false so the form doesn't get submitted
		return false;
	}

	//make sure the email address is formatted properly
	if (checkemail() == false) {
		alert("Please check your email address, it is not valid");
		document.demo_account_form.email.focus();
		//and return false so the form doesn't get submitted
		return false;
	}

	document.demo_account_form.resolution.value = window.screen.width + 'x' + window.screen.height;

	//everything checks out, submit the form			

	return true;
}
		