function add_member_check()
{
	var root=document.add_member;
	var username = root.username;
	var password = root.password;
	var confirm_password = root.confirm_password;
	var address = root.address;
	var name = root.name;
	var email = root.email;
	
//	var day = root.day;
//	var month = root.month;
//	var year = root.year;
//	if(day.value==''){
//		alert("Please select your day of birth.");
//		day.focus();
//		return false;
//	}
//	if(month.value==''){
//		alert("Please select the month on which you were born.");
//		month.focus();
//		return false;
//	}
//	if(year.value==''){
//		alert("Please select the year in which you were born.");
//		year.focus();
//		return false;
//	}
	if (username.value=='')
	{
		alert('Please insert a username.');
		username.select();
		return false;
	}
	if (password.value=='')
	{
		alert('Please insert a password.');
		password.select();
		return false;
	}
	if (confirm_password.value=='')
	{
		alert('Please insert the password confirmation.');
		confirm_password.select();
		return false;
	}
	if (password.value != confirm_password.value)
	{
		alert('The password and its confirmation doesn\'t match.');
		confirm_password.select();
		return false;
	}
	if (address.value=='')
	{
		alert('Please insert the address.');
		address.select();
		return false;
	}
	if (name.value=='')
	{
		alert('Please insert a name.');
		name.select();
		return false;
	}
	if(email.value == '')
	{
		alert('Please insert E-mail address.');
		email.select();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = email.value.match(pattern);
	if(!flag2)
	{
		alert("Please enter a valid E-mail address.");
		email.select();
		return false;
	}
//	if(date.value == '')
//	{
//		alert('Please insert the date of birth.');
//		date.select();
//		return false;
//	}
	return true; 
}

function edit_member_check()
{
	var root=document.edit_member;
	var username = root.username;
	var address = root.address;
	var name = root.name;
	var email = root.email;
	
//	var day = root.day;
//	var month = root.month;
//	var year = root.year;
//	if(day.value==''){
//		alert("Please select your day of birth.");
//		day.focus();
//		return false;
//	}
//	if(month.value==''){
//		alert("Please select the month on which you were born.");
//		month.focus();
//		return false;
//	}
//	if(year.value==''){
//		alert("Please select the year in which you were born.");
//		year.focus();
//		return false;
//	}
	
	if (username.value=='')
	{
		alert('Please insert a username.');
		username.select();
		return false;
	}
	if (address.value=='')
	{
		alert('Please insert the address.');
		address.focus();
		return false;
	}
	if (name.value=='')
	{
		alert('Please insert a name.');
		name.select();
		return false;
	}
	if(email.value == '')
	{
		alert('Please insert E-mail address.');
		email.select();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = email.value.match(pattern);
	if(!flag2)
	{
		alert("Please enter a valid E-mail address.");
		email.select();
		return false;
	}
	
	return true; 
}

function validateLogin(){
	var root = document.loginForm;
	var username = root.username;
	var password = root.password;
	if(username.value==''||username.value=='Username'){
		alert("Please enter your username.");
		username.focus();
		return false;
	}
	if(password.value ==''||password.value=='Password'){
		alert("Please enter your password.");
		password.focus();
		return false;
	}
	var hassed_password = hex_md5(password.value);
	
	password.value = hassed_password;
	
	root.hash.value = 'yes';
	return true;
}
function validateRegister(){
	var root = document.membersform;
	var name = root.name;
	var email = root.email;
	var address = root.address;
	var username = root.username;
	var password = root.password;
	var confirm = root.confirm;
//	var day = root.day;
//	var month = root.month;
//	var year = root.year;
	
	if(name.value==''){
		alert("Please enter your name");
		name.focus();
		return false;
	}
	if(email.value ==''){
		alert("Please enter your email.");
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = email.value.match(pattern);
	if(!flag2)
	{
		alert("Please enter a valid E-mail address.");
		email.select();
		return false;
	}
	if(address.value == '')
	{
		alert('Please provide your address.');
		address.focus();
		return false;
	}
	if(username.value ==''){
		alert("Please enter a username and click on check to see if it is available");
		username.focus();
		return false;
	}
	if(password.value==''){
		alert("Please enter a password.");
		password.focus();
		return false;
	}
	if(confirm.value==''){
		alert("Please confirm your password.");
		confirm.focus();
		return false;
	}
	if(confirm.value != password.value){
		alert("The password and it's confirmation do not match");
		confirm.focus();
		return false;
	}
//	if(day.value==''){
//		alert("Please select your day of birth.");
//		day.focus();
//		return false;
//	}
//	if(month.value==''){
//		alert("Please select the month on which you were born.");
//		month.focus();
//		return false;
//	}
//	if(year.value==''){
//		alert("Please select the year in which you were born.");
//		year.focus();
//		return false;
//	}
	
//	var hashed_password = hex_md5(password.value);
//	var hashed_confirm = hex_md5(confirm.value);
//	password.value = hashed_password;
//	confirm.value = hashed_confirm;
//	root.hash.value='yes';
	return true;
}

function checkUsername(){
	var username = document.register.username.value;
	if(username ==''){
		alert("Please type a Username first.");
		return false;
	}
	window.open("/members/check.php?username="+username,"Check","width=200,height=100,top=400,left=400,scrollbars=no,toolbar=no,resizable=no,statusbar=no");
	return true;
}

function  validateRecovery(){
	var root = document.password_rec;
	var email = root.email;
	var username = root.username;
	if(username.value ==''){
		alert("Please enter your username.");
		username.focus();
		return false;
	}
	if(email.value ==''){
		alert("Please enter your email.");
		email.focus();
		return false;
	}
	
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = email.value.match(pattern);
	if(!flag2)
	{
		alert("Please enter a valid E-mail address.");
		email.focus();
		return false;
	}
	
	return true;
}

function validateEdit(){
	var root = document.editProfile;
	var name = root.name;
	var email = root.email;
	var profession = root.profession;
	if(name.value==''){
		alert("Please enter your name.");
		name.focus();
		return false;
	}
	if(email.value==''){
		alert("Please enter your email address.");
		email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	var flag2 = email.value.match(pattern);
	if(!flag2)
	{
		alert("Please enter a valid E-mail address.");
		email.select();
		return false;
	}
	if(profession.value==''){
		alert("Please choose a profession.");
		profession.focus();
		return false;
	}
		
	return true;
}

function validatePassword(){
	
	var root = document.change_password;
	
	var old_pass = root.old;
	
	var password = root.newp;
	
	var confirm = root.confnew;
	
	if(old_pass.value==''){
		alert("Please enter your old password.");
		old_pass.focus();
		return false;
	}
	
	if(password.value==''){
		alert("Please enter a new password.");
		password.focus();
		return false;
	}
	if(confirm.value==''){
		alert("Please confirm your new password.");
		confirm.focus();
		return false;
	}
	if(confirm.value != password.value){
		alert("The password and it's confirmation do not match");
		return false;
	}
	return true;
}

function checkUsername(){
	var username = document.add_member.username.value;
		window.open('check_username.php?username='+username,'check','width=200,height=100');
}

function clearForm(){
	var status = confirm("Are you sure you want to clear the form?");
	if(status == false)
		return false;
	
	var root = document.change_password;
	var old_password = root.old;
	var new_password = root.newp;
	var confirmp = root.confnew;
	
	old_password.value='';
	new_password.value='';
	confirmp.value='';
	
	return false; 
}
