$(document).ready(function()
{
	$('#login_area').load("/loginArea/time_"+Math.random(),function()
	{	
		$("#nav_login_btn").css("cursor","pointer").live("click",function()
		{
				var errmsg = '';
				if($("input[name=nav_email]").val()==''){
					errmsg += 'メールアドレスを入力してください\n';
				}
				if($("input[name=nav_password]").val()==''){
					errmsg += 'パスワードを入力してください\n';
				}
				if(errmsg != '')
				{
					alert(errmsg);
				}else{
					var options = {
						url:'/loginArea_doLogin',
						type:'POST',
						dataType:'json',
						success: function(data){
							if(data.err)
							{
								alert(data.err);
							}else{
								//$('#login_area').empty();
								//$('#login_area').load("/loginArea");
								window.location.reload();
							}
						}
					};
					$('#nav_login_form').ajaxSubmit(options);
				}
		 });
		$('form').live("keypress",function(event){
		if(event.keyCode == 13){
			var nx, me = event.target;
			if(me.type == 'text' || me.type == 'password' || me.type == 'checkbox'){
				var i = 0;
				if(!this.key13first){
					var index = 0, stack = [];
					while(i < this.elements.length){
						nx = this.elements[i++];
						if(nx.tabIndex){
							if(nx.tabIndex == 1)this.firstElement = nx;
							if(index < nx.tabIndex)index = nx.tabIndex;
						}else{
							stack.push(nx);
						}
					}
					while(nx = stack.shift())nx.tabIndex = ++index;
					if(!this.firstElement)this.firstElement = this.elements[0];

					i = 0;
					this.key13first = 1;
				}
				while(i < this.elements.length){
					nx = this.elements[i++];
					if(nx.tabIndex == me.tabIndex + 1){
						nx.type == 'button' || nx.type == 'submit' || nx.type == 'image' ? nx.click() : nx.focus();
						break;
					}
				}
				if(i >= this.elements.length)this.firstElement.focus();
			}
		}
	});
		 $("#nav_register_btn").css("cursor","pointer").live("click",function()
		 {
			 window.open("/member/register");
		 });

	});
});
function addfavorite(url, title){
	try{
		window.external.addfavorite(url, title);
	}catch (e){
		try{
			window.sidebar.addPanel(title, url, '');
		}catch (e){
			alert('ブラウザがそっぽをご使用くださいctrl + d收藏!');
		}
	}
}	
