$(document).ready(function()
{
	$(function() {
		$('#password').pstrength();
	});

	$(document).ready(function(){
    	$("#registerForm").validate();
	  });
	
	$("#registerForm").submit(function()
	{
		//UK_check if form is valid!
		if ($("#registerForm").valid()) {
			//remove all the class add the messagebox classes and start fading
			$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
			//check the username exists or not from ajax
			//alert ($('#c_email').val());
			$.post("ajax/ajax_register.php", {
				username: $('#username').val(),
				email: $('#email').val(),
				c_email: $('#c_email').val(),
				password: $('#password').val(),
				c_password: $('#c_password').val()
			}, function(data){
			
				if (data == 'ok') //if correct login detail
				{
					$("#msgbox").fadeTo(200, 0.1, function() //start fading the messagebox
					{
						//add message and change the class of the box and start fading
						$(this).html('Account Created...').addClass('messageboxok').fadeTo(900, 1, function(){
							//redirect to secure page
							document.location = 'login.php';
						});
						
					});
				}
				else {
				
					$("#msgbox").fadeTo(200, 0.1, function() //start fading the messagebox
					{
						//add message and change the class of the box and start fading
						$(this).html(data).addClass('messageboxerror').fadeTo(900, 1);
					});
				}
			});
			return false; //not to post the  form physically
		}
	});
	
	//now call the ajax also focus move from 
	$("#c_password").blur(function()
	{
		$("#registerForm").trigger('register');
	});
	
});

