function validate() {
	var fname = trim(document.getElementById("firstname").value);
	var lname = trim(document.getElementById("lastname").value);
	var uid = trim(document.getElementById("email").value);
	var pwd = trim(document.getElementById("password").value);
	var confirm = trim(document.getElementById("confirm").value);

	if ((fname.length>0) && (lname.length>0) && (uid.length>0) && (pwd.length>0) && (confirm.length>0)) {
		if (pwd == confirm) {
			return true;
		}else{
			alert("Password is not equal!");
		}
	}else{
		alert("Fields with * are required!");
	}
	return false;
}

function validate_registration(frm) {
	var fname = trim(document.getElementById("firstname").value);
	var lname = trim(document.getElementById("lastname").value);
	var email = trim(document.getElementById("email").value);
	
	if ((fname.length>0) && (lname.length>0) && (email.length>0)) {
		if (validate_email(email) == true) {
			document.getElementById(frm).submit();
			return true;
		}else{
			alert("Email is not in a correct format.");
		}
	}else{
		alert("All fields are required!");
	}
	return false;
}

function validate_subscription(frm) {
	var fname = trim(document.getElementById("subscribe_fullname").value);
	var email = trim(document.getElementById("subscribe_email").value);
	
	if ((fname.length>0) && (email.length>0)) {
		if (validate_email(email) == true) {
			document.getElementById(frm).submit();
			return true;
		}else{
			alert("Email is not in a correct format.");
		}
	}else{
		alert("All fields are required!");
	}
	return false;
}

function validate_email(email) {
	return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}