/*
 * @Remark 客服中心JS
 * @Author miracle
 * @Create time 2010-02-26
 * @Last edit time 
 */

$(document).ready(function(){
	//下拉菜单
	$(".r_s_select").hover(function(){
		clearTimeout(t);
		$(this).addClass("r_s_select2");
	},function(){
		$(this).removeClass("r_s_select2");
		t = setTimeout(function(){
			$("#headSel").hide();
		},4000);
	})
	.click(function(){
		$("#headSel").slideToggle('fast');
	});
	//点击下拉菜单
	$("#headSel > li").click(function(){
		$type = $("#headSel > li").index($(this))+1;
		$("#headSel").hide();
		$(".r_s_select").text($(this).text());
		$("#searchtype").val($type);
		$("#text").focus();
	});
	//搜索文字提示
	$('#searchtext').focus(function(){
		if($(this).val()=="请输入您关注的问题关键字，例如：充值")
			$(this).val('').css("color","#000000");
	}).blur(function(){
		if($(this).val()==""){
			$(this).val('请输入您关注的问题关键字，例如：充值').removeAttr("style");
		}
	});

});

/**
 * 提交搜索时的表单验证
 */
function checkSearch(){
	if($("#searchtext").val()=="" || $("#searchtext").val()=="请输入您关注的问题关键字，例如：充值"){
		alert("请输入您关注的问题关键字");
		$("#searchtext").focus();
		return false;
	}
}

/**
 * 根据大类的ID调取小类
 * @param num //大类的ID
 */
function openSmall(num){
	var main = $('#hotfloatdiv');
	var divTop = (document.documentElement.clientHeight-main.height())/2+document.documentElement.scrollTop;
	$("#small_sort").html('正在加载，请稍后....');
	main.show().css("top",divTop);
	$.ajax({
	   type: "GET",
	   url:"/api/secondjson/",
	   dataType: "json",
	   data: "cate_id=" + num,
	   success: function(data) {
		var f = '';
			 $.each(data,function(i,n){
			 f += '<li><input name="" type="radio" value="'+n.id+'" id="small_id_'+n.id+'" onclick="chioceCate('+num+','+n.id+');" /><label for="small_id_'+n.id+'"><strong>'+n.smallname+'</strong></label><h3>'+n.tips+'</h3></li>';
			});
			$("#small_sort").html(f);
			divTop = (document.documentElement.clientHeight-main.height())/2+document.documentElement.scrollTop;
			main.animate({"top":divTop},"slow").show();
	   }
	  });
}

/**
 * 根据大类的ID调取小类 （合作商使用）
 * @param num //大类的ID
 */
function openSmall2(num){
	var main = $('#hotfloatdiv');
	var divTop = (document.documentElement.clientHeight-main.height())/2+document.documentElement.scrollTop;
	$("#small_sort").html('正在加载，请稍后....');
	main.show().css("top",divTop);
	$.ajax({
	   type: "GET",
	   url:"/api/secondjson/",
	   dataType: "json",
	   data: "cate_id=" + num,
	   success: function(data) {
		var f = '';
			 $.each(data,function(i,n){
			 f += '<li><input name="" type="radio" value="'+n.id+'" id="small_id_'+n.id+'" onclick="chioceCate2('+num+','+n.id+');" /><label for="small_id_'+n.id+'"><strong>'+n.smallname+'</strong></label><h3>'+n.tips+'</h3></li>';
			});
			$("#small_sort").html(f);
			divTop = (document.documentElement.clientHeight-main.height())/2+document.documentElement.scrollTop;
			main.animate({"top":divTop},"slow").show();
	   }
	  });
}

/**
 * 跳转到输入标题的页面
 */
function chioceCate(big,small){
	location.href='/question/addtitle/cate_id/'+big+'/small_id/'+small;
}
/**
 * 跳转到输入标题的页面（合作商使用）
 */
function chioceCate2(big,small){
	location.href='/questionhz/addtitle/cate_id/'+big+'/small_id/'+small;
}

/**
 * 输入问题标题的JS验证
 */
function checkStep1(){
	val = $('#title').val();
	len = getLength(val);
	if(len<2){
		alert('标题不能少于2个字符！');
		$('#title').focus();
		return false;
	}else if(len>50){
		alert('标题不能超过25个字50个字符！');
		$('#title').focus();
		return false;
	}
	
	var forbidChar = new Array(",","-","/","\\","'","%","\"");
	for (var i = 0;i < forbidChar.length ; i++){
	  if(val.indexOf(forbidChar[i]) >= 0){
	      alert("您输入的信息含有非法字符：“ "+forbidChar[i]+" ” 请更正！");
	      return false;
	  }
	}
}

/**
 * 显示游戏分区和服务器
 */
function showarea(area,server){
	$.ajax({
	   type: "GET",
	   url:"/api/areabyid/",
	   dataType: "html",
	   data: "id=" + area,
	   success: function(data) {
			$('#areatext').html(data);
		}
	});
	$.ajax({
	   type: "GET",
	   url:"/api/serverbyid/",
	   dataType: "html",
	   data: "id=" + server,
	   success: function(data) {
		   $('#servertext').html(data);
		}
	});	
}
/**
 * 添加评价
 */
function addReview(type){
	var value=0;
	var content = "";
	$('input[name=review]').each(function(){
		if(this.checked){
			value=$(this).val();	
		}
	});
	if(type==1){
		content = $('#appraise_msg_1').val();
	}else{
		if(show){
			content = $('#appraise_msg_2').val();
		}
	}
	if(confirm('评价后就不能进行追加了，您确定吗？')){
		$.post("/api/addreview/",{id:$('#id').val(),text:value,appraise_msg:content},function(data){
			if(data){
				alert('极光互动感谢您的评价！');
				$('#opinion').html(data);
				$('#askans').hide();
			}else{
				alert('评价失败，请稍候再试！');
			}
		});
	}
}

/**
 * 验证追加
 */
function checkNewadd(){
	len = getLength($('#content').val());
	if($('#content').val()==''){
		alert('内容不能为空！');
		$('#content').focus();
		return false;
	}else if(len>2000){
		alert('内容不能大于1000字，您输了'+len+'个字！');
		$('#content').focus();
		return false;
	}
}

/**
 * 验证追加
 */
function checkNewadd2(){
	len = getLength($('#content').val());
	if($('#content').val()==''){
		$(".error").text("追加内容不能为空").show();
		return false;
	}else if(len>2000){
		$(".error").text('内容不能大于1000字，您输了'+len+'个字！').show();
		return false;
	}
}

/**
 * 同意相关协议
 */
function checkOne(){
	if(!$('#agreement').attr('checked')){
		alert('请先勾选“已经了解并同意上述规则”');
		return false;
	}
}

/**
 * 资料修改JS验证
 */
function checkApply(){
	var username=/^[A-Za-z]\w+$/;
	if($('#targetuser').val()==''){
		alert('请输入目标账号');
		$('#targetuser').focus();
		return false;
	}else if(!username.test($('#targetuser').val())){
		alert('通行证必须以字母开头，由字母和数字组成的字符串！');
		$('#targetuser').focus();
		return false;
	}
	if($('#checkcode').val()==""){
		alert('请输入验证码！');
		$('#checkcode').focus();
		return false;
	}
}

/**
 * 切换
 */
function showTab(num1,num2){
	$('#'+num1+'').show();
	$('#'+num2+'').hide();
}

/**
 * 资料修改JS验证
 */
function checkSuccess(){
	if($("#type").val()==1){
		if($('#newcard').val()==''){
			alert('请输入新的身份证号');
			$('#newcard').focus();
			return false;
		}else{
			var text= isCardID($('#newcard').val());
			if(text!=true){
				alert(text);
				$('#newcard').focus();
				return false;
			}
		}
		if($('#newfile').val()==''){
			alert('请上传新的身份证照片');
			return false;
		}
	}
	if($("input[name='infro_type']:checked").val()==1){
		var idcard = $("#oldcard").val();
		if(idcard==""){
			alert("请输入当前身份证！");
			return false;
		}
		var idcardtext = isCardID(idcard);
		if(idcardtext!=true){
			alert(idcardtext);
			return false;
		}
		if($('#oldfile').val()==''){
			alert('请上传旧身份证照片');
			return false;
		}
	}else{
		if($('#text8').val()!=""){
			var email = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			if (!email.test($('#text8').val())){       
				alert('请输入正确的邮箱地址');
				$('#text8').focus();  
				return false;
			}
		}
		if($('#text14').val()!=""){
			var regu =/^(13|15|18)[0-9]{9}$/;
			var p1 = /(\d{3}-)(\d{8})$|(\d{4}-)(\d{7})$|(\d{4}-)(\d{8})$/;   
			if (!p1.test($('#text14').val()) && !regu.test($('#text14').val())){       
				alert('请输入正确的电话或者手机号');
				$('#text14').focus();  
				return false;
			}
		}
	}
}

/**
 * 资料修改JS验证
 */
function checkEmail(){
	var email = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if($("#type").val()==3){
		if (!email.test($('#newcard').val())){
			alert('请输入正确的邮箱地址');
			$('#newcard').focus();
			return false;
		}else if($('#newcard').val()!=$('#renewcard').val()){
			alert('请确认您的邮箱地址');
			$('#renewcard').focus();
			return false;
		}
	}
	if($("input[name='infro_type']:checked").val()==3){
		if (!email.test($('#oldemail').val())){
			alert('请输入正确的绑定邮箱地址');
			$('#oldemail').focus();
			return false;
		}
	}else if($("input[name='infro_type']:checked").val()==1){
		var idcard = $("#oldcard").val();
		if(idcard==""){
			alert("请输入当前身份证！");
			return false;
		}
		var idcardtext = isCardID(idcard);
		if(idcardtext!=true){
			alert(idcardtext);
			return false;
		}
		if($('#oldfile').val()==''){
			alert('请上传旧身份证照片');
			return false;
		}
	}else{
		if($('#text8').val()!=""){
			if (!email.test($('#text8').val())){
				alert('请输入正确的邮箱地址');
				$('#text8').focus();  
				return false;
			}
		}
		if($('#text14').val()!=""){
			var regu =/^(13|15|18)[0-9]{9}$/;
			var p1 = /(\d{3}-)(\d{8})$|(\d{4}-)(\d{7})$|(\d{4}-)(\d{8})$/; 
			if (!p1.test($('#text14').val()) && !regu.test($('#text14').val())){       
				alert('请输入正确的电话或者手机号');
				$('#text14').focus();  
				return false;
			}
		}
	}
}

function checkCard(){
	if($("#question1").val()=="0"){
		alert('请选择安全问题1');
		return false;
	}else if($("#question1").val()=="自定义" && $("#myquestion1").val()==""){
		alert('请填写自定义问题1');
		$("#myquestion1").focus();
		return false;
	}
	if($("#answer1").val()==""){
		alert('请填写答案1');
		$("#answer1").focus();
		return false;
	}
	if($("#question2").val()=="0"){
		alert('请选择安全问题2');
		return false;
	}else if($("#question2").val()=="自定义" && $("#myquestion2").val()==""){
		alert('请填写自定义问题2');
		$("#myquestion2").focus();
		return false;
	}
	if($("#answer2").val()==""){
		alert('请填写答案1');
		$("#answer2").focus();
		return false;
	}
	if($('#idcard').val()==''){
		alert('请输入身份证号');
		$('#idcard').focus();
		return false;
	}else{
		var text= isCardID($('#idcard').val());
		if(text!=true){
			alert(text);
			$('#idcard').focus();
			return false;
		}
	}
}

function checkAccounts(){
	if($("#question_1").val()=="0"){
		alert('请选择安全问题1');
		return false;
	}else if($("#question_1").val()=="自定义" && $("#myquestion_1").val()==""){
		alert('请填写自定义问题1');
		$("#myquestion_1").focus();
		return false;
	}
	if($("#answer_1").val()==""){
		alert('请填写答案1');
		$("#answer_1").focus();
		return false;
	}
	if($("#question_2").val()=="0"){
		alert('请选择安全问题2');
		return false;
	}else if($("#question_2").val()=="自定义" && $("#myquestion_2").val()==""){
		alert('请填写自定义问题2');
		$("#myquestion_2").focus();
		return false;
	}
	if($("#answer_2").val()==""){
		alert('请填写答案2');
		$("#answer_2").focus();
		return false;
	}
}

function checkAccounts2(){
	if($("#question_1_1").val()=="0"){
		alert('请选择安全问题1');
		return false;
	}else if($("#question_1_1").val()=="自定义" && $("#myquestion_1_1").val()==""){
		alert('请填写自定义问题1');
		$("#myquestion_1_1").focus();
		return false;
	}
	if($("#answer_1_1").val()==""){
		alert('请填写答案1');
		$("#answer_1_1").focus();
		return false;
	}
	if($("#question_1_2").val()=="0"){
		alert('请选择安全问题2');
		return false;
	}else if($("#question_1_2").val()=="自定义" && $("#myquestion_1_2").val()==""){
		alert('请填写自定义问题2');
		$("#myquestion_1_2").focus();
		return false;
	}
	if($("#answer_1_2").val()==""){
		alert('请填写答案2');
		$("#answer_1_2").focus();
		return false;
	}
}

function checkAccounts3(){
	if($("#yanswer1").val()==""){
		alert('请填写原答案1');
		$("#yanswer1").focus();
		return false;
	}
	if($("#yanswer2").val()==""){
		alert('请填写原答案2');
		$("#yanswer2").focus();
		return false;
	}
	if($("#question_4_1").val()=="0"){
		alert('请选择安全问题1');
		return false;
	}else if($("#question_4_1").val()=="自定义" && $("#myquestion_4_1").val()==""){
		alert('请填写自定义问题1');
		$("#myquestion_4_1").focus();
		return false;
	}
	if($("#answer_4_1").val()==""){
		alert('请填写答案1');
		$("#answer_4_1").focus();
		return false;
	}
	if($("#question_4_2").val()=="0"){
		alert('请选择安全问题2');
		return false;
	}else if($("#question_4_2").val()=="自定义" && $("#myquestion_4_2").val()==""){
		alert('请填写自定义问题2');
		$("#myquestion_4_2").focus();
		return false;
	}
	if($("#answer_4_2").val()==""){
		alert('请填写答案2');
		$("#answer_4_2").focus();
		return false;
	}
}

/**
 * 显示资料申请状态
 */
function applyDetail(id){
	var main = $('.hotfloatdiv');
	var divTop=0;
	$("#newText").empty();
	$.ajax({
	   type: "GET",
	   url:"/api/applydetail/",
	   dataType: "html",
	   data: "id=" + id,
	   success: function(data) {
	   		$("#newText").html(data);
			divTop = (document.documentElement.clientHeight-main.height())/2+document.documentElement.scrollTop;
			main.css({"top":divTop}).show();
	   }
	});
}

/**
 * 显示物品恢复申请状态
 */
function applyDetail2(id){
	var main = $('.hotfloatdiv');
	var divTop=0;
	$("#newText").empty();
	$.ajax({
	   type: "post",
	   url:"/api/hfdetail/",
	   dataType: "html",
	   data: "id=" + id,
	   success: function(data) {
	   		$("#newText").html(data);
			divTop = (document.documentElement.clientHeight-main.height())/2+document.documentElement.scrollTop;
			main.css({"top":divTop}).show();
	   }
	});
}

/**
 * 单击更换验证码
 */
function cschangeRegImg()
{
	document.getElementById("codeimg").src = "/api/code/"+Math.random();
}

/**
 * 检查验证码
 */
function checkCode(val){
	$.ajax({
	   type: "GET",
	   url:"/api/checkcode/",
	   dataType: "json",
	   data: "code=" + val,
	   success: function(data) {
			yzm = data;
	   }
	  });
}

function addGameReview(){
	var value=0;
	var content = "";
	$('input[name=review]').each(function(){
		if(this.checked){
			value=$(this).val();	
		}
	});
	content = $('#appraise_msg').val();
	$.post("/api/addreview/",{id:$('#id').val(),text:value,appraise_msg:content},function(data){
		if(data){
			$('#opinion').html(data);
			$('#myForm').remove();
		}
	});
}

function tagOver2(name,x,n){
	clearTimeout(fodTime);
	fodTime = setTimeout(function(){
		setTab(name,x,n);
		$("li.right").hide();
		$("#more_"+x).show();
	},100);
}
