
	var warningimg = '';
	var validCheckedEmail ='';
	
	$.localScroll({
		lazy:true,
		hash:true,
		onAfter:function( anchor, settings ){
			$(anchor).animate( { opacity: 0 }, blinkSpeed);
			$(anchor).animate( { opacity: 100 }, blinkSpeed);
		}
	});
	
	function validateSignup()
	{
		showLoading();
		
		//name
		name = $("#signup_name").attr('value');
		if (!name || name == defaulttext['signup_name'] ) 
		{
			$("#name_error").html(warningimg + 'Please enter your name.');
			$.scrollTo('#required', scrollspeed);
			hideLoading();
			return false;
		}
		else
		{
			$("#name_error").html('');
		}
		
		//password
		password = $("#password").attr('value');
		
		if ( 
			( !update && (password.length < 3 || password.length > 30) )
			|| ( update && password && (password.length < 3 || password.length > 30) )
			
			)
		{
			$("#password_error").html(warningimg + 'Your password should be between 3 and 30 characters.');
			hideLoading();
			$.scrollTo('#required', scrollspeed);
			return false;
		}
		else
		{
			$("#password_error").html('');
		}
		
		//confirm password
		confirmpassword = $("#confirmpassword").attr('value');
		
		if (confirmpassword != password) 
		{
			$("#confirmpassword_error").html(warningimg + 'Password and Confirm Password do not match.');
			$.scrollTo('#required', scrollspeed);
			hideLoading();
			return false;
		}
		else
		{
			$("#confirmpassword_error").html('');
		}
		
		//email
		email = $("#signup_email").attr('value');
		
		//If the email entered was not in the right format
		if ( !isValidEmail(email) ) 
		{
			$("#email_error").html(warningimg + 'Please enter a valid email address.');
			$.scrollTo('#required', scrollspeed);
			hideLoading();
			return false;
		}
		
		//If the email has already been checked and hasn't changed
		else if ( email == validCheckedEmail || email == currentemail )
		{
			$("#email_error").html('');

			//All checked, submit the form
			$("#signupform").submit();
		}	
		
		//If a new email in the right format was entered, check if it's already registered
		else
		{
			$.ajax({
			   type: "GET",
			   url: "createaccount_checkemail.php",
			   data: "email=" + email,
			   success: function(msg){
				 
					msg = $.trim(msg);
				 
					if (msg == "taken") 
					{
						$("#email_error").html(warningimg + 'That email address is already registered.');
						$.scrollTo('#required', scrollspeed);
						hideLoading();
						return false;
					}
					else if ( msg == "available" )
					{
						$("#email_error").html('');
						//All checked, submit the form
						$("#signupform").submit();
					}	
					else 
					{
						$("#email_error").html(warningimg + 'Something went wrong whilst checking your e-mail address, please try again.');
						$.scrollTo('#required', scrollspeed);
						hideLoading();
						return false;
					}
				 
			   }
			}); 
		}
		
	}
	
		
	function showLoading()
	{
		$("#loading").css("display","block");
		$("#signup_button").attr("disabled","disabled");
	}
	
	function hideLoading()
	{
		$("#loading").css("display","none");
		$("#signup_button").attr("disabled","");
	}
	
			
	function isValidEmail(str) {
	   return ( str.indexOf("@") >  0);
	}
	
	
