$(document).ready(function(){

	// set focusfields plugin
	//$("input, textarea, select").apfocusfields();
	$("#joinmember").bind("click", function () {
		window.location.href="sign-up.php";
	});
	
	$("#password").keypress(function(e){
		if(e.which ==13) $("#submitsignin").click();
	});


// check email value
	$('#email').blur(function(){
		if(this.value.length>0){
			if(this.value != '' && !/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)){
				$(".error_messsage").html($MultiLanguage.err_email); 
				return false;
			}
		}else{
			$(".error_messsage").html($MultiLanguage.err_empty); 
			return false;
		}
		//$(this).apnotice({runmode:'remove'});
	});

// check password value
	$('#password').blur( function() {
		if ($(this).val()=='') { 
			$(".error_messsage").html($MultiLanguage.err_empty);
			return false; 
		}
		if ( $(this).val().length<6 || $(this).val().length>16 ) {
			$(".error_messsage").html($MultiLanguage.err_password); 
			return false; 
		}
	});


	$("#submitsignin").click(function() {
			//$('#email,#password').blur();
			var params = 'runmode=signin&'+	$(":input").serialize();
			$.post('/php/member/member.php',params, function(data){
				data = eval("(" + data + ")");
				if(data.result=='success') {
					if (data.referer.length > 1) {
						
						window.location.href= data.referer; //返回来路页
						
					}else{
						$(".error_messsage").html(data.note);
						
						window.location.href='/member/order-history.php';
						
					}
					
				} else {
					//alert('ooo');
					$(".error_messsage").html(data.note);
					if (data.item) $("#" + data.item).focus();
				}
			});
	});
	
});
