$(document).ready(function() { 
	$('.onfocus').mouseover(function(){
		var imgsrc = $(this).attr('src');
		$(this).attr('src',imgsrc.replace('.','_on.'));
	}).mouseout(function(){
		var imgsrc = $(this).attr('src');
		$(this).attr('src',imgsrc.replace('_on.','.'));
	});
	/*qkbuy*/
	$("#games-select").mouseup(function(){
		var popupLeft = $("#games-select").position().left;
		var popuptop = $("#games-select").position().top+40;
		new PopupLayer({trigger:"#games-select",popupBlk:"#blk3",closeBtn:".close",popupLayerClass:'popjpgame',offsets:{x:popupLeft,y:popuptop}});
		$("#blk5").hide().css('z-index',-1);
		$(".serverjplist li").remove();
	});	
	$("#blk3 li a").mousedown(function(){
		var tid = $(this).attr("id");
		var icoimg = $(this).children().attr('src');
		var popupLeft = $("#games-select").position().left;
		var popuptop = $("#games-select").position().top+40;		
		new PopupLayer({trigger:"#"+tid,popupBlk:"#blk4",closeBtn:".close",popupLayerClass:'popjpgamelist',offsets:{x:popupLeft,y:popuptop}});
		$.ajax({
			url: url+"/gamelistajax/"+$(this).attr("name"),
			dataType: 'json',
			success: function(data){
				if(data.data == null){return false;}
				$('.jpkico').attr('src',icoimg);
				$(".gamejplist li").remove();
				for(var i=0;i<data.data.length;i++){
					$(".gamejplist").append('<li><a href="javascript:popserver('+data.data[i].id+')" id="ogameajax_'+data.data[i].id+'">'+(i+1)+"."+data.data[i].gname+'</a></li>');	
					}				
			}			
		});	
	});	
	$('.close5').click(function(){
		$(".serverjplist li").remove();
		$("#blk5").hide().css('z-index',-1);
	})	
	/*faq*/  
	$('#faq div .ali').hide(); 
	$('.qli').toggle(function()
	{
		$('.ali',this).show();
	},function()
	{
		$('.ali',this).hide(); 
	})
   $("#addfav").click(function(){
                var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';  
                if (document.all) {  
                    window.external.addFavorite('http://www.rmt-mm.com', 'RMT-MM')  
                } else if (window.sidebar) {  
                    window.sidebar.addPanel('RMT-MM', 'http://www.rmt-mm.com', "")  
                } else {　
                    alert('追加失敗\n' + ctrl + ' + D をクリックしてお気に入りボックスへ')  
                }  
   })
});
function popserver(id)
{
	var popupLeft = $("#games-select").position().left;
	var popuptop = $("#games-select").position().top+40;	
	$.ajax({
		url: url+"/serverlistajax/"+id,
		dataType: 'json',
		success: function(data){
			if(data.data == null){return false;}
			$(".serverjplist li").remove();
			for(var i=0;i<data.data.length;i++){
				$(".serverjplist").append('<li><a href="'+data.data[i].orderurl+'">'+(i+1)+"."+data.data[i].pname+'</a></li>');	
				}				
		}			
	});	
	$(".popjpgame").hide();	
	if($(".popjpgame").length>1){
		$(".popjpgame:first").remove();
	}	
	$(".popjpgamelist").hide();	
	if($(".popjpgamelist").length>1){
		$(".popjpgamelist:first").remove();
	}
	$("#blk5").show().css({position:"absolute","z-index":3,left:popupLeft,top:popuptop,zoom:1});
}
/*tr*/
$(document).ready(function(){
 $(".pricetable tr:nth-child(2n+1)").addClass("evenbg");
 $(".pricetable tr:not(:first)").mouseover(function() {
            $(this).addClass("highlight");
        }).mouseout(function() {
            $(this).removeClass("highlight");
         });
 $(".saletable tr:nth-child(2n+1)").addClass("evenbg_sale");
 $(".saletable tr:not(:first)").mouseover(function() {
            $(this).addClass("highlight_sale");
        }).mouseout(function() {
            $(this).removeClass("highlight_sale");
         })		 
});
function refresh_code(event) {
	$('#'+event).attr('src', url+"/Base/verify/"+Math.random());
}
/*
 * Check the existence of members
 */
function checkName(){
	var email = $('#ue').val();
	if(email=='' || !(/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,5}$/i).test(email)) {
		alert('メールが間違っている');
		return false;
	} else {
		return true;
	}
}
/*
 * Check the password is correct
 */
function checkPwd(){
	var pwd = $('#up').val();
	if(pwd=='' || !(/^\S{6,16}$/i).test(pwd)) {
		alert('パスワードが間違っている');
		return false;
	} else {
		return true;
	}
}
/*
 * Check the existence of members
 */
function checkNewName(){
	var email = $('#ue_N').val();
	if(email=='' || (/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,5}$/i).exec(email)==null) {
		$("#result").html('電子メールの形式が修正されていません');
		$('#result').css('color', '#AA0033');
		return false;
	}
	
	$('#result').html('正しい');
	$('#result').css('color', '#008000');
	
	$.ajax({
		url: url+"/Member/checkAccount/email/"+$('#ue_N').val(),
		dataType: 'json',
		success: function(response){
			$("#result").html(response.data);
		}
	});
	return true;
}
function checkNPwdAgain(){
	var pwd = $('#up_NN').val();
	if(!(/^\S{6,16}$/i).test(pwd)) {
		$('#nn').show();
		$('#yy').hide();
		return false;
	}
	if(pwd == $('#pwd_chk').val()) {
		$('#yy').show();
		$('#nn').hide();
		return true;
	} else {
		$('#nn').show();
		$('#yy').hide();
		return false;
	}
}
/*
 * Check the password is correct
 */
function checkNewPwd(){
	var pwd = $('#up_N').val();
	if(pwd=='' || (/^\S{6,16}$/i).exec(pwd)==null) {
		$('#pwdresult').html('不適切なパスワードの形式');
		$('#pwdresult').css('color', '#AA0033');
		return false;
	} else {
		$('#pwdresult').html('正しい');
		$('#pwdresult').css('color', '#008000');
		return true;
	}
}
function checkPwdAgain(){
	if(!($('#up_N').val())) {
		$('#divrp').html('同一のパスワードを入力して下さい。');
		$('#divrp').css('color', '#AA0033');
		return false;
	}
	if($('#up_N').val() == $('#pwd_chk').val()) {
		$('#divrp').html('正しい');
		$('#divrp').css('color', '#008000');		
		return true;
	} else {
		$('#divrp').html('同一のパスワードを入力して下さい。');
		$('#divrp').css('color', '#AA0033');
		return false;
	}
}
/*
 * Asynchronous login
 */
function asyn_login() {
	if(checkName()==false || checkPwd()==false) { return false; }
}
/*
 * Asynchronous logout
 */
function asyn_logout() {
	window.location.href = url+'/Member/logout';
}
function isnull(node,event){
	var val = jQuery.trim($("input[name="+node+"]").val());
	$("input[name="+node+"]").parent().find('label').remove();
	if(!val.length){
		$("input[name="+node+"]").after('<label generated="true" class="oerror notice"> '+event+'</label>');
	}else{
		$("input[name="+node+"]").after('<label generated="true" class="success notice"></label>');
	}
}
function isemail(node,event){
	$("input[name="+node+"]").parent().find('label').remove();
	var re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var email = $("input[name="+node+"]").val();
    if(!re.test(email)){
    	$("input[name="+node+"]").after('<label generated="true" class="oerror notice"> '+event+'</label>');
    }else{
   		$("input[name="+node+"]").after('<label generated="true" class="success notice"></label>');
    }
}
function valitotal(node){
	$("input[name="+node+"]").parent().find('label').remove();
	var re = /^[0-9]*[1-9][0-9]*$/;
	var val = $("input[name="+node+"]").val();
    if(!re.test(val)){
    	$("input[name="+node+"]").parent().append('<label generated="true" class="oerror"></label>');
    }else{
   		$("input[name="+node+"]").parent().append('<label generated="true" class="success"></label>');
    }	
}
