﻿/*
FUNCTIONS.JS
Common functions to the site
*/

function openLinkWindow(href) {
	window.open(href, '_blank');
	return false;
}

function ValidateForm(form) {
	validated = true;
	
	switch(form.id) {
		case "contact":
			if (form["msg"].value == "") {
				msg       = "You haven't said anything!\n\nPlease enter this information before you continue.";
				validated = false;
				form["msg"].focus();
			}
			
			if (ValidateEmail(form["email"].value) != true) {
				msg       = "That's not a proper e-mail address.\n\nPlease check it and try again.";
				validated = false;
				form["email"].focus();
			}
			
			if (form["email"].value == "") {
				msg       = "You must enter your e-mail address.\n\nPlease enter this information before you continue.";
				validated = false;
				form["email"].focus();
			}
			
			if (form["telno"].value == "") {
				msg       = "You must enter your telephone number.\n\nPlease enter this information before you continue.";
				validated = false;
				form["telno"].focus();
			}
			
			if (form["address"].value == "") {
				msg       = "You must enter your address.\n\nPlease enter this information before you continue.";
				validated = false;
				form["address"].focus();
			}

			if (form["you"].value == "") {
				msg       = "You must enter your name.\n\nPlease enter this information before you continue.";
				validated = false;
				form["you"].focus();
			}
			
			break;
	}
	
	if (!validated) { alert(msg) }

	return validated;
}

function ValidateEmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	return reg.test(email);
}
