$(document).ready(function(){	
	$("form#signupform").submit(function() {
	// we want to store the values from the form input box, then send via ajax below
	var fname = $('#fname').attr('value');
	var lname = $('#lname').attr('value'); 
	var email = $('#email').attr('value'); 
	var password = $('#password').attr('value');
	var gender = $('#gender').attr('value'); 
	var reg_year = $('#reg_year').attr('value');
	var reg_month = $('#reg_month').attr('value');
	var reg_day = $('#reg_day').attr('value'); 
		
	//If button submit is click and email is still empty
	if ($('#email').val().length < 1) {
			$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{
			  //add message and change the class of the box and start fading
			  $(this).html('Enter your email').addClass('messageboxerror').fadeTo(900,10);
			  $('#email').focus();
			  $('#signup').attr('disabled', 'disabled');
			});
			return false;
	}
	//If button submit is click and password is still empty
	if ($('#password').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Enter your password').addClass('messageboxerror').fadeTo(900,10);
			  $('#password').focus();
			});
			return false;
	}else{
		$("#password").change(function(){
			$("#msgbox").fadeOut('slow');	
			//$('#signup').removeAttr('disabled');
		});
	}
	//If button submit is click and password is less than 5 character
	if ($('#password').val().length < 5) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('At least 5 character').addClass('messageboxerror').fadeTo(900,10);
			  $('#password').focus();
			});
			return false;
	}else{
		$("#password").change(function(){
			$("#msgbox").fadeOut('slow');	
		});
	}
	//If button submit is click and firstname is still empty
	if ($('#fname').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Enter your firstname').addClass('messageboxerror').fadeTo(900,10);
			  $('#fname').focus();
			});
			return false;
	}else{
		$("#fname").change(function(){
			$("#msgbox").fadeOut('slow');	
		});
	}
	//If button submit is click and lastname is still empty
	if ($('#lname').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Enter your lastname').addClass('messageboxerror').fadeTo(900,10);
			  $('#lname').focus();
			});
			return false;
	}else{
		$("#lname").change(function(){
			$("#msgbox").fadeOut('slow');	
		});
	}
	//If button submit is click and year of birth doesnt choose yet
	if ($('#reg_year').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Year of birthday').addClass('messageboxerror').fadeTo(900,10);
			  $('#reg_year').focus();
			});
			return false;
	}else{
		$("#reg_year").change(function(){
			$("#msgbox").fadeOut('slow');
		});
	}
	//If button submit is click and month of birth doesnt choose yet
	if ($('#reg_month').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Month of birthday').addClass('messageboxerror').fadeTo(900,10);
			  $('#reg_month').focus();
			});
			return false;
	}else{
		$("#reg_month").change(function(){
			$("#msgbox").fadeOut('slow');
		});
	}
	//If button submit is click and day of birth doesnt choose yet
	if ($('#reg_day').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Day of birthday').addClass('messageboxerror').fadeTo(900,10);
			  $('#reg_day').focus();
			});
			return false;
	}else{
		$("#reg_day").change(function(){
			$("#msgbox").fadeOut('slow');
		});
	}
	//If button submit is click and gender doesnt choose yet
	if ($('#gender').val().length < 1) {
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");		
			$("#msgbox").fadeTo(200,0.1,function(){ //start fading the messagebox
			  //add message and change the class of the box and start fading
			  $(this).html('Your Gender').addClass('messageboxerror').fadeTo(900,10);
			  $('#gender').focus();
			});
			return false;
	}else{
		$("#gender").change(function(){
			$("#msgbox").fadeOut('slow');
		});
	}
	
			
	$.ajax({
			type: "POST",
			url: "dcmembersave.php",
			data: "fname="+ fname + "&lname=" + lname + "&email=" + email + "&password=" + password + "&gender=" + gender + "&reg_year=" + reg_year + "&reg_month=" + reg_month + "&reg_day=" + reg_day,
			success: function(){
				$('form#signupform').hide('slow');
				$('#signup').hide('slow');
				$('div.success').fadeIn('slow');
				$(".messageboxok").fadeOut('slow');
				$("#msgbox").fadeOut('slow');
			}
	});
	
	return false;
	});
}); 

