$(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.','.'));
	});
	
	/*faq*/  
	$('#faq div .ali').hide(); 
	$('.qli').toggle(function()
	{
		$('.ali',this).show();
	},function()
	{
		$('.ali',this).hide(); 
	})
	$('#semail').focus(function(){
		if($('#semail').val()=='お客様のメールアドレス'){
			$('#semail').val('');
		}
	}).blur(function(){
		if(!$('#semail').val()||$('#semail').val()=='お客様のメールアドレス'){
			$('#semail').val('お客様のメールアドレス');
		}
	});
	$('#index-send').click(function(){				
		if($('#scontent').val()&&$('#semail').val()){
			$.ajax({
				type: "post",
				url: url+'/Index/suggestion',
				data:{scontent:$('#scontent').val(),semail:$('#semail').val(),type:'ajax'},
				dataType: 'json',
				success: function(data){
					if(data!=1){
						alert(data);
					}else{
						$('.suggestion').css('display','none');
						alert('ごコメントをして頂きありがとう御座いました。');
					}
				}						
			})
		}
	});	
   $("#addfav").click(function(){
                var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';  
                if (document.all) {  
                    window.external.addFavorite('http://www.rmtssp.com', 'RMTSSP')  
                } else if (window.sidebar) {  
                    window.sidebar.addPanel('RMTSSP', 'http://www.rmtssp.com', "")  
                } else {　
                    alert('追加失敗\n' + ctrl + ' + D をクリックしてお気に入りボックスへ')  
                }  
   });
	/*qkbuy*/
	$("#games-select").mouseup(function(){
		var popupLeft = $("#games-select").position().left+25;
		var popuptop = $(".t_game").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-59;
		var popuptop = $(".t_game").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);
	})
});
function popserver(id)
{
	var popupLeft = $("#games-select").position().left+25;
	var popuptop = $(".t_game").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
 $(".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;
}

/*
 * 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;
	}
}
/*
 * 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>');
    }	
}
	/*
	$("#games-select").mouseup(function(){
		var popupLeft = $("#games-select").position().left;
		popobj = new PopupLayer({trigger:"#games-select",popupBlk:"#blk3",closeBtn:"#close",popupLayerClass:'popjpgame',offsets:{x:popupLeft,y:278}});
		$('.popjpgamelist').hide();	
		$('.popjpserver').hide();
	});
	$('.gamejp li').mouseup(function(){
		var popupLeft = $("#games-select").position().left;
		var obj2 = new PopupLayer({trigger:"."+$(this).attr('class'),popupBlk:"#blk4",popupLayerClass:'popjpgamelist',closeBtn:"#close2",offsets:{x:popupLeft,y:278}});
		var obj = $('#'+$(this).attr('class')).find('dd');
		var gamelisthtml = '';
		obj.each(function(){
			gamelisthtml += '<li><a href="javascript:selectgame(\''+$(this).text()+'\','+$(this).find('a').attr('class')+')">'+$(this).text()+'</a></li>';
		})
		$(".gamejpli").html(gamelisthtml);	
		$('.popjpgame').hide();	
		$('.popjpserver').hide();	
	})
	*/ 
