JPGMAG.isok=true;
JPGMAG.check={
	email:function(){
		$j.ajax({
			url:'/actions/email_check.php',
			type:'post',
			data:{e:$j(this).val()},
			success:function(d){
				if(d!='0'){
					JPGMAG.isok&=true;
					$j.ajax({
						url:'/actions/username_check.php',
						type:'post',
						data:{u:$j('#frmemail').val()},
						success:function(x){
							if(x!='0'){
								$j('#frmemail').parent('li').removeClass('formError').find('span').removeClass('stop').addClass('go').html('It\'s cool.');
								JPGMAG.isok&=true;
							}else{
								$j('#frmemail').parent('li').addClass('formError').find('span').removeClass('go').addClass('stop').html('That email address is taken.');
								JPGMAG.isok=false;
							}
						}
					});
				}else{
					$j('#frmemail').parent('li').addClass('formError').find('span').removeClass('go').addClass('stop').html('That\'s not an email address.');
					JPGMAG.isok=false;
				}
			}
		});
	},
	username:function(){
		if(!$j(this).val().match(/^[a-zA-Z0-9]{3}[a-zA-Z0-9]*$/)){
			$j(this).parent('li').addClass('formError').find('span').addClass('stop').html(($j(this).val().match(' '))?'Hey! No spaces!':'Be creative.');
			JPGMAG.isok=false;
		}else{
			$j.ajax({
				url:'/actions/username_check.php',
				type:'post',
				data:{u:$j(this).val()},
				success:function(d){
					if(d!='0'){
						$j('#frmuname').parent('li').removeClass('formError').find('span').removeClass('stop').addClass('go').html('Rocks!');
						JPGMAG.isok&=true;
					}else{
						$j('#frmuname').parent('li').addClass('formError').find('span').removeClass('go').addClass('stop').html('That username is taken.');
						JPGMAG.isok=false;
					}
				}
			});
		}
	},
	password:function(){
		if($j(this).val().length>=5&&$j(this).val().indexOf(' ')<0){
			$j(this).parent('li').removeClass('formError').find('span').removeClass('stop').addClass('go').html('Good one!');
			JPGMAG.isok&=true;
		}else{
			$j(this).parent('li').addClass('formError').find('span').removeClass('go').addClass('stop').html('Try again.');
			JPGMAG.isok=false;
		}
	},
	tos:function(){
		if($j(this).is(':checked')){
			$j(this).parent('p').removeClass().find('span').removeClass().html('');
			JPGMAG.isok&=true;
		}else{
			$j(this).parent('p').addClass('formError').find('span').addClass('stop').html('Check to say...');
			JPGMAG.isok=false;
		}
	},
	all:function(){
		JPGMAG.isok=true;
		JPGMAG.check.email.call($j('#frmemail'));
		JPGMAG.check.username.call($j('#frmuname'));
		JPGMAG.check.password.call($j('#frmpass'));
		JPGMAG.check.tos.call($j('#frmtos'));
		if(JPGMAG.isok==0){JPGMAG.isok=false;}
		return JPGMAG.isok;
	}
}

$j(function(){
	$j('#frmemail').blur(JPGMAG.check.email);
	$j('#frmuname').blur(JPGMAG.check.username);
	$j('#frmpass').blur(JPGMAG.check.password);
	$j('#signupform').submit(JPGMAG.check.all);
});