var urlPicture = "http://png.gc73.com.cn";
var identityCardCheckFlag = false;//身份证号码验证标志位
var realNameCheckFlag;//真实姓名验证标示位
var reIdentityCardCheckFlag = false;//再次输入身份证号码验证标志位
var emailCheckFlag = false;//邮箱验证标志位
var validCodeCheckFlag = false;//网页验证码标志位
var mobileCheckFlag = false;//手机验证标志位
var redirection = ""; //页面重定向（用于必须登录后再能访问的页面）
var bindType="";//传入getAccountLevel方法的bind参数
var ifNewCard = false;
//校验身份证格式
function checkIdentityCard(id){
	var identityCard = $('#'+id).val();
	if("" == identityCard) {
		defaultMessage(id , '请输入您帐号绑定的身份证号码');
		identityCardCheckFlag = false;
		return;
	}
	if(identityCard.length != 18 && identityCard.length != 15){
		errorMsgShow(id, "您填写身份证号码位数不对");
		identityCardCheckFlag = false;
		return;
	}
	if('identityCard' == id) { //对第一次输入的身份证号码进行验证
		$.ajax({url:'../identityCardCheck.do',type:'post',dataType:'json',data:{'identityCard':identityCard},
			success:function(data){
				 if(data.error == "E"){
				 	errorMsgShow(id, "输入身份证号码不合法，请重新填写");
				 	identityCardCheckFlag = false;
				 	if($('#reIdentityCard').val() != ''){
				 		errorMsgShow('reIdentityCard', "请再次确认身份证号码");
				 		reIdentityCardCheckFlag = false;
				 	}
				 } else {
				 	successMsgShow(id, "验证通过");
				 	identityCardCheckFlag = true;
				 	if($('#reIdentityCard').val() != '' && $('#identityCard').val() == $('#reIdentityCard').val()){
				 		successMsgShow('reIdentityCard', "验证通过");
				 		reIdentityCardCheckFlag = true;
				 	}
				 }
			}
		});
	} else { //对再次输入的身份证号码进行验证
		if("" == $('#identityCard').val()) {
			errorMsgShow(id, "请先在上面的输入框中填写您的身份证号码");
			reIdentityCardCheckFlag = false;
			return;
		}
		if($('#identityCard').val() != $('#reIdentityCard').val()){
			errorMsgShow(id, "两次输入的身份证号码不一致");
			reIdentityCardCheckFlag = false;
			return;
		}
		successMsgShow(id, "验证通过");
		reIdentityCardCheckFlag = true;
	}
}

function checkRealName(id) {
	var realName = $("#"+id).val();
	if("" == realName) {
		defaultMessage('realName', '请输入您的真实姓名');
		realNameCheckFlag = false;
		return;
	}
	RegisterInfoService.checkRealName(realName, {
		callback : function(str) {
			if (str == 'S') {
				realNameCheckFlag = true;
				successMsgShow(id, "验证通过");
				return;
			} else {
				realNameCheckFlag = false;
				errorMsgShow(id, str);
				if ($("#"+id).attr("readonly") == true) {
			        $("#"+id).removeAttr("readonly");
			        $("#"+id).val('');
					defaultMessage('realName', '请输入您的真实姓名');
					$("#"+id).focus();
			    }
				return;
			}
		},
		timeout : 5000,
		errorHandler : function(message){
			realNameFlag = false;
			alert("系统运行出现问题" + message);
			return;
		}
	});
}

function checkBindRealName(val , key){
	realNameCheckFlag = undefined;
	if("" == val) {
		if(ifNewCard){
			defaultMessage('realName', '新手卡玩家可以不必填写此项');
		}else{
			defaultMessage('realName', '请输入您的真实姓名');
		}
		realNameCheckFlag = false;
		return;
	}
	var realNameReg = new RegExp("^[\u4E00-\u9fa5]+$");
	if(!realNameReg.test(val)){
		errorMsgShow('realName', "您的真实姓名包含非中文字符");
		realNameCheckFlag = false;
		return;
	}
	if(val.length  < 2){
		errorMsgShow('realName', "您的真实姓名长度不对");
		realNameCheckFlag = false;
		return;
	}
	var number;
	if(key != undefined){
		number = getCookie(key);
		if(number != null && number != undefined && parseInt(number) > 5){
			errorMsgShow('realName', "您的真实姓名错误超过5次，请24小时后重新绑定");
			realNameCheckFlag = false;
			return;
		}
		
	}
	$.ajax({url:'checkRealName.do',type:'post',dataType:'json',contentType:'application/x-www-form-urlencoded;charset=UTF-8',data:{'realName':val},
		success:function(data){
			if(data.error == 'S'){
				realNameCheckFlag = true;
				successMsgShow('realName', "验证通过");
				return;
			}else{
				errorMsgShow('realName', data.message);
				realNameCheckFlag = false;
				if(number == null || number == undefined ){
					setCookie(key , 1 , 1);
				}else{
					setCookie(key , parseInt(number) + 1 , 1);
				}
				return;
			}
		},
		error:function(data){
			alert('网络异常，请稍后重试');
		}
	});
}

/**
 * 检查已经绑定过的身份证
 * @param id 输入框的id
 * @return
 */
function checkBindIdentityCard(id){
	var identityCard = $('#'+id).val();
	if("" == identityCard) {
		defaultMessage(id , '请输入您帐号绑定的身份证号码');
		identityCardCheckFlag = false;
		return;
	}
	if(identityCard.length != 18 && identityCard.length != 15){
		errorMsgShow(id, "您填写身份证号码位数不对");
		identityCardCheckFlag = false;
		return;
	}
	$.ajax({url:'checkUserIdentityCard.do',type:'post',dataType:'json',data:{'identityCard':identityCard},
		success:function(data){
			if(data.error == "S"){
			 	successMsgShow(id, "验证通过");
			 	identityCardCheckFlag = true;
			 }else if(data.error == "I"){
				 errorMsgShow(id, data.message);
				 identityCardCheckFlag = false;
				 window.location.href="index.html";
			 }else{
			 	errorMsgShow(id, data.message);
			 	identityCardCheckFlag = false;
			 }
		}
	});
}
//校验邮箱格式
function checkEmail(id) {
	var email = $("#"+id).val();
	if("" == email) {
		defaultMessage('email', '请填写您最常用的邮箱');
		emailCheckFlag = false;
		return;
	}
	$.ajax({url:'../emailCheck.do',type:'post',dataType:'json',data:{'email':email},
			success:function(data){
				 if(data.error == "E"){
				 	errorMsgShow(id, "输入邮箱不合法，请重新填写");
				 	emailCheckFlag = false;
				 } else {
				 	successMsgShow(id, "验证通过");
				 	emailCheckFlag = true;
				 }
			}
		});
}
//校验手机号码
function checkMobile(id) {
	var mobile = $("#"+id).val();
	if("" == mobile) {
		defaultMessage(id, "请输入您要绑定的手机号码");
		mobileCheckFlag = false;
		return;
	}	
	$.ajax({url:'checkMobile.do',type:'post',dataType:'json',data:{'mobilePhone':mobile},
			success:function(data){
				$('#userNameDWR').val(data.username);
				if(data.error == "E"){
					errorMsgShow(id, data.message);
					mobileCheckFlag = false;
				} else if (data.error == "K") {
					if (confirm("尊敬的用户：\n\n    您好，如果您的手机接收短信延时，可能是由于通讯运营商 \n 网关服务繁忙，请您耐心等待1~2分钟，如果长时间收不到短信， \n 请重新尝试。如还有其他疑问，您也可以联系我们的客服进行  \n 相关咨询。 \n\n    您是否继续进行操作？")) {
						successMsgShow(id, "验证通过");
						mobileCheckFlag = true;
					} else {
						errorMsgShow(id, "");
						mobileCheckFlag = false;
					}
				} else {
					successMsgShow(id, "验证通过");
					mobileCheckFlag = true;
				}
			}
	});
}
//验证手机号码格式
function isMobel(value) {   
	if(/^13\d{9}$/g.test(value) || (/^15[0-35-9]\d{8}$/g.test(value)) || (/^18[05-9]\d{8}$/g.test(value))) {
		return true;
	}else{
		return false;   
	}
}

/**
 * 检查绑定过的手机号码
 * @param id 输入框的id
 * @return
 */
function checkBindMobile(id){
	var mobile = $("#"+id).val();
	if("" == mobile) {
		defaultMessage(id, "请输入您要解绑的手机号码");
		mobileCheckFlag = false;
		return;
	}
	$.ajax({
		url:'checkBindMobilePhone.do',
		type:'post',
		dataType:'json',
		data:{mobilePhone:$('#mobilePhone').val()},
		success:function(data){
			if(data.error == 'S'){
				successMsgShow(id, "验证通过");
				mobileCheckFlag = true;
			}else if(data.error == 'G'){
				errorMsgShow(id, data.message);
				mobileCheckFlag = false;
				window.location.href="index.html";
			}else{
				errorMsgShow(id, data.message);
				mobileCheckFlag = false;
			}
		}
	})
}

//绑定身份证
function bindIdentityCard() {
	if(identityCardCheckFlag&&reIdentityCardCheckFlag&&realNameCheckFlag) {
		$('#bindIdentityCardFrm').submit();
	} else {
		var errMsg = "";

		if(!realNameCheckFlag) {
			errMsg += "请正确填写您的真实姓名\n";
		}
		if(!identityCardCheckFlag) {
			errMsg += "请正确填写您的身份证号码\n";
		}
		if(!reIdentityCardCheckFlag) {
			errMsg += "两次输入的身份证号码不一致";
		}
		alert(errMsg);
	}
}

//绑定安全邮箱
function bindEmailBind() {
	if(identityCardCheckFlag&&emailCheckFlag) {
		$('#bindEmailFrm').submit();
	} else {
		var errMsg = "";
		if(!identityCardCheckFlag) {
			errMsg += "请填写您正确的身份证号码\n";
		}
		if(!emailCheckFlag) {
			errMsg += "请填写您最常用的邮箱";
		}
		alert(errMsg);
	}
}

//登录后才能访问
function redirectBeforeLogined(url) {
	$.ajax({url:'../checkLogined.do',type:'post',dataType:'json',success:function(data){
			if(data.error == "S"){
				window.location.href = url;
			}else{
				redirection = url;
				tb_show('result','login.html?height=229&width=458&modal=true&inlineId=infobar','thickbox','false');
			}
		}
	});
}

//登录
function safetyLogin(event){
	if(event == undefined || event.keyCode == 13){
		if(checkLogin()) {
			login();
			setTimeout(timeoutLogin,1000);
		}
	}
}

function checkLogin() {
	var userName = $('#userName').val();
	var password = $('#password').val();
	var validCode = $('#validCode').val();
	if('' == userName) {
		alert("请填写您的游戏帐号");
		return false;
	}
	if('' == password) {
		alert("请填写您的帐号密码");
		return false;
	}
	if('' == validCode) {
		alert("请填写验证码");
		return false;
	}
	return true;
}

function timeoutLogin(){
	if(loginSuccess){
		tb_remove();
		if(bindType != undefined && bindType != "") {
			getAccountLevel('login', bindType);
		} else {
			window.location.reload();
		}
	}
}

//发送手机验证码
function sendMobileValidNum(){
	var _realName = $('#realName').val();
	var _userNameStr = $('#userNameStr').val();
	var regex = new RegExp("((([uU]{1}[bB]{1}|[uU]{1}[qQ]{1}|[vV]{1}[qQ]{1})[a-zA-Z]{2})|([xX]{1}[sS]{1}[aAkKvV]{1}[a-zA-Z]{1}))[0-9]{4}");
	if(regex.test(_userNameStr)){
		identityCardCheckFlag = true;
	}
	if(!ifNewCard && realNameCheckFlag != undefined && realNameCheckFlag == false){
		alert('您填写的真实姓名与注册时的真实姓名不一致。请重新输入。');
		return;
	}
	if(identityCardCheckFlag&&mobileCheckFlag&&validCodeCheckFlag) {
		var mobilePhone = $('#mobilePhone').val();
		var user_name = $('#userNameDWR').val();
		MobileBindDWRService.mobileBindChargeCheck(mobilePhone, user_name, {
			callback : function(str) {
				if (str == "ERROR") {
					alert("对不起，该帐号已经成功绑定了手机号码");
					return false;
				} else if (str == "E") {
					if (confirm("您好，活动期间，再次绑定时，更换绑定手机号码，您需要支付100000星豆的手续费。确定支付星豆来完成绑定吗？")) {
						$.ajax({
					        url: 'sendMobileValidNum.do',
					        type: 'post',
					        cache: false,
					        dataType: 'json',
					        contentType:'application/x-www-form-urlencoded;charset=UTF-8',
					        data: {'realName': _realName , 'identityCard' : $('#identityCard').val() , 'mobilePhone' : $('#mobilePhone').val() , 'validCode' :$('#validCodePop').val()},
					        success: function(data){
					        	if("G" == data.error) {
					        		tb_show('result','login.html?height=229&width=458&modal=true&inlineId=infobar','thickbox','false');
					        	}else if ("U" == data.error){
					        		alert(data.message);
					        		window.location.href='index.html';
					        	}else if ("S" == data.error || "I" == data.error) {
					        		alert("尊敬的用户：\n    您好！手机验证码已经发送至您的手机，请注意查收。");
					            	$("#sendMobileValidNumFrm").submit();
					        	}else {
					        		alert(data.message);
					        	}
					        }
						});
					} else {
						window.location.href="index.html";
					}
				} else {
					$.ajax({
				        url: 'sendMobileValidNum.do',
				        type: 'post',
				        cache: false,
				        dataType: 'json',
				        contentType:'application/x-www-form-urlencoded;charset=UTF-8',
				        data: {'realName': _realName ,'identityCard' : $('#identityCard').val() , 'mobilePhone' : $('#mobilePhone').val() , 'validCode' :$('#validCodePop').val()},
				        success: function(data){
				        	if("G" == data.error) {
				        		tb_show('result','login.html?height=229&width=458&modal=true&inlineId=infobar','thickbox','false');
				        	}else if ("U" == data.error){
				        		alert(data.message);
				        		window.location.href='index.html';
				        	}else if ("S" == data.error || "I" == data.error) {
				        		alert("尊敬的用户：\n    您好！手机验证码已经发送至您的手机，请注意查收。");
				            	$("#sendMobileValidNumFrm").submit();
				        	}else {
				        		alert(data.message);
				        	}
				        }
					});
				}
			},
			timeout:50000,
			errorHandler : function(message) {
				alert("网络异常，请刷新页面后重新操作");
				return false;
			}
		});
	} else {
		var errMsg = "";
		
		if(!identityCardCheckFlag) {
			errMsg += "请填写您正确的身份证号码\n";
		}
		if(!mobileCheckFlag) {
			errMsg += "请填写您正确的手机号码\n";
		}
		if(!validCodeCheckFlag){
			errMsg += "请正确填写验证码";
		}
		alert(errMsg);
	}
}
//绑定手机
function bindMobile() {
	if("" == $('#validNum').val()) {
		alert("验证码不能为空")
		return;
	}
	$('#bindMobileFrm').submit();
}

var emails = new Array('http://mail.163.com' , 'http://mail.126.com' , 'http://mail.sina.com' , 'http://mail.sina.com' , 'http://mail.sina.com' , 'http://mail.cn.yahoo.com' , 'http://mail.cn.yahoo.com' , 'http://mail.tom.com' , 'http://mail.21cn.com' , 'http://mail.yeah.net' , 'http://mail.qq.com' , 'http://gmail.google.com' , 'http://www.hotmail.com' , 'http://mail.139.com');
var regexs = new Array('@163.com' , '@126.com' , '@sina.com' , '@sina.cn' , '@vip.sina.com' , '@yahoo.com.cn' , '@yahoo.cn' , '@tom.com' , '@21cn.com' , '@yeah.net' , '@qq.com' , '@gmail.com' , '@hotmail.com' , '@139.com');

/**
 * 将邮箱转换成对应的官网地址
 * @param email 邮箱
 * @return
 */
function getEmailUrl(email){
	var regex;
	for ( var i = 0; i < regexs.length; i++) {
		regex = new RegExp(regexs[i]);
		if(regex.test(email)){
			document.getElementById('loginMail').href=emails[i];
			return;
		}
	}
	document.getElementById('loginMail').href='http://mail.' + email.substring(8,email.length);
}


/**
 * 禁止重复获取
 * @param _this
 * @return
 */
function noRepeatSend(){
	alert("验证码已发送，请不要频繁获取");
	if(sendValidFlag) {
		setTimeout(function(){
			document.getElementById('reaptLink').onclick=repeatSendValidNum;
			 sendValidFlag = false;
		}, 30000);
	} 
}

/**
 * 解绑手机获取验证码
 * @return
 */
function releaveMobileBindNum(){
	var _userNameStr = $('#userNameStr').val();
	var regex = new RegExp("xs[akv]{1}[a-zA-z]{1}[0-9]{4}");
	if(regex.test(_userNameStr)){
		identityCardCheckFlag = true;
	}
	if(!checkReleaveMobileBindNum()) {
		return;
	}
	if(!identityCardCheckFlag){
		alert("您填写的身份证号有误，请检查");
		return;
	}
	if(!mobileCheckFlag){
		alert("您填写的手机号码有误，请检查");
		return;
	}
	if(!validCodeCheckFlag){
		alert("您填写的验证码有误，请检查");
		return;
	}
	$.ajax({
	        url: 'sendRelieveMobileBindValidNum.do',
	        type: 'post',
	        cache: false,
	        dataType: 'json',
	        data: {'identityCard' : $('#identityCard').val() , 'mobilePhone' : $('#mobilePhone').val() , 'validCode' :$('#validCodePop').val()},
	        success: function(data){
	        	if("G" == data.error) {
	        		tb_show('result','login.html?height=229&width=458&modal=true&inlineId=infobar','thickbox','false');
	        	} else if ("S" == data.error || "R" == data.error) {
	        		alert("尊敬的用户：\n    您好！手机验证码已经发送至您的手机，请注意查收。");
	            	$('#releaveMobileBindForm').submit();
	        	}else {
	        		alert(data.message);
	        	}
	        }
		});
}

function releaveMobileBind(){
	if(!checkReleaveMobileBindNum()) {
		return;
	}
	if($('#validNum').val() == ''){
		alert("请输入您收到的手机验证码");
		return;
	}
	$('#releaveMobileNumForm').submit();
}

function checkReleaveMobileBindNum() {
	var checkNum = getCookie("rmbnum");
	if(checkNum == null || checkNum == 'undefined'){
		checkNum = 0;
		setCookie("rmbnum",checkNum,1);
		return true;
	}
	if(parseInt(checkNum) >= 6){
		alert("输入手机验证码错误6次，24小时内不能进行手机解绑。");
		window.location.href = "index.html";
		return false;
	}
	return true;
}

function click_label(id) {
	for(var i=1;i<=4;i++) {
		var className = 'phone_label_off';
		var style = 'display:none';
		if(i == id) {
			className = 'phone_label_on';
			style = 'display:block';
		}
		$("#phone_label_"+i).attr('className', className);
		$("#succeed_label_"+i).attr('style', style);
	}
}

//离开绑定手机验证码页面前的操作
function leaveMobileBindPage() {
	if("" == $('#validNum').val()){
		event.returnValue = "您还没收到验证码吗？请您再耐心等待两分钟 。";
	}
}

//显示成功信息
function successMsgShow(id, msg) {
	$('#'+id+'Info').attr('style','color:#006600;font-size:12px;');
	$('#'+id+'Info').html('<img src='+urlPicture+'/website_img/right_icon.gif width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-left:10px;"/>'+msg);
}
//显示错误信息
function errorMsgShow(id, msg) {
	$('#'+id+'Info').attr('style','color:red;font-size:12px;font-weight:100;');
	$('#'+id+'Info').html('<img src='+urlPicture+'/website_img/error_icon.gif width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-left:10px;"/>'+msg);
}

/**
 * 将输入框变成默认的信息
 * @param id	输入框id
 * @param message	默认信息内容
 * @return
 */
function defaultMessage(id , message){
	var defaultMessage = '<img src="http://png.gc73.com.cn/website_img/accouts_sanjiao.png" width="4" height="7" />' + message + '</span>';
	$('#' + id + 'Info').html(defaultMessage);
	document.getElementById(id + "Info").className = 'accounts_clew';
	$('#'+id+'Info').attr('style','');
}

/**
 * 获取用户绑定情况
 * @param loginFlag 是否需要登录
 * @param bind	检查绑定项目
 * @return
 */
function getAccountLevel(loginFlag , bind){
	bindType = bind;
	$.ajax({
		url:'accountSafetyCenter.do',
		type:'post',
		dataType:'json',
		success:function(data){
			if(data.code == 'S'){
				if(data.mobilePhone != ''){
					if(bind == 'mobilePhone'){
						window.location.href='index.html';
					}else{
						$('#bind_telephone').html('<div><img src="http://png.gc73.com.cn/website_img/succeed_binding_phone.gif" width="132" height="31" border="0" /></div><div style="margin-top:5px;"><a href="bindPhoneFunction.html"><img src="http://png.gc73.com.cn/website_img/binding_phone_function.gif" width="132" height="31" border="0" /></a></div>');
						$('#relieveMobileBindLink').show();
						$('#bind_mobile_phone_info').html('您的帐号绑定的手机号码为： ' + data.mobilePhone);
					}
				}else{
					if(bind == 'mobilePhone'){
						window.location.href='mobileBindPage.do';
					}else{
						$('#relieveMobileBindLink').hide();
						$('#bind_telephone').html('<div><a href="mobileBindPage.do"><img src="http://png.gc73.com.cn/website_img/will_binding_phone.png" width="132" height="31" border="0" /></a></div><div style="margin-top:5px;"><a href="bindPhoneFunction.html"><img src="http://png.gc73.com.cn/website_img/binding_phone_function.gif" width="132" height="31" border="0" /></a></div>');
					}
				}
				if(data.cardNo != ''){
					if(bind == 'cardNo'){
						window.location.href='index.html';
					}else{
						$('#bind_card_no').html('<div><img src="http://png.gc73.com.cn/website_img/succeed_binding_cardid.png" width="132" height="31" border="0" /></div>');				
						$('#bind_card_no_info').html('您的帐号绑定的身份证为： ' + data.cardNo);
						$('#cardNoDetail').attr('style','padding-top:15px;');
					}
				}else{
					if(bind == 'cardNo'){
						window.location.href="identityCardBindPage.do";
					}else{
						$('#bind_card_no').html('<div><a href="identityCardBindPage.do"><img src="http://png.gc73.com.cn/website_img/will_binding_cardid.png" width="132" height="31" border="0" /></a></div>');
					}
				}
				if(data.email != ''){
					if(bind == 'email'){
						window.location.href="index.html";
					}else{
						$('#bind_email').html('<div><img src="http://png.gc73.com.cn/website_img/succeed_binding_email.png" width="132" height="31" border="0" /></div>');
						$('#bind_email_info').html('您的帐号绑定的邮箱为： ' + data.email);
						$('#emailDetail').attr('style','padding-top:15px;');
					}
				}else{
					if(bind == 'email'){
						window.location.href='emailBindPage.do';
					}else{
						$('#bind_email').html('<div><a href="emailBindPage.do"><img src="http://png.gc73.com.cn/website_img/will_binding_email.png" width="132" height="31" border="0" /></a></div>');
					}
				}
			}else if(data.code == 'G'){
				if(loginFlag == undefined || loginFlag == 'login'){
					tb_show('result','login.html?height=229&width=458&modal=true&inlineId=infobar','thickbox','false');
				}else{
					return;
				}
			}else{
				alert(data.message);
			}
		},
		error:function(data){
			alert('网络异常，请稍后重试');
		}
	})
}

/**
 * 加载页面完成做出的对应的判断
 * @param code 返回码
 * @param message	返回信息
 * @param bind	身份证绑定标志
 * @return
 */
function safetyReadyMessage(code , message , bind){
	if(code == 'G'){
		//window.location.href="index.html";
		tb_show('result','login.html?height=229&width=458&modal=true&inlineId=infobar','thickbox','false');
	}else if(code == 'H'){
		if(bind != undefined){
			return;
		}
		if(message != undefined && message != ''){
			alert(message);
		}else{
			alert("您还没有绑定身份证，请先绑定身份证");
		}
		window.location.href="identityCardBindPage.do";
	}else if(code == 'M'){
		if(message != undefined && message != ''){
			alert(message);
		}
		window.location.href="emailBindPage.do";
	}else if(code == 'T'){
		if(message != undefined && message != ''){
			alert(message);
		}
		window.location.href="mobileBindPage.do";
	}else if(code == 'U') {
		if(message != undefined && message != ''){
			alert(message);
		}
		window.location.href="index.html";
	} else if (code == 'GAMEMONEY_NOT_ENOUGH') {
		alert("亲爱的用户：\r\n  对不起，您手头的星豆不足以支付本次绑定，请去大厅我的银行中提取星豆，重新登录后操作");
		return;
	} else if (code == 'MONEY_NOT_ENOUGH') {
		alert("亲爱的用户：\r\n  对不起，您手头的星豆不足以支付本次绑定！您可以先去充值，然后再进行此操作！");
		return;
	} else if (code == 'NO_CHARGE') {
		alert("亲爱的用户： \r\n   恭喜您绑定成功，此次绑定免费，此后如需更换绑定手机号码，活动期间，仅需支付100000星豆的手续费。");
		return;
	} else if (code == 'CHARGE') {
		alert("亲爱的用户： \r\n   您的帐号已成功更改绑定的手机号码，已从您的帐号扣除手续费100000星豆。");
		return;
	} else if (code =='RMB_VALIDNUM_ERROR'){ //解绑手机短信验证码错误
		alert(message);
		var checkNum = getCookie("rmbnum");
		if(checkNum == null || checkNum == 'undefined'){
			checkNum = 0;
		}
		setCookie("rmbnum", parseInt(checkNum) + 1, 1);
		return;
	} else{
		if(message != undefined && message != ''){
			alert(message);
		}
	}
}

function changeValidCodePop(relative_path){
	if(relative_path == undefined){
		relative_path = "../";
	}
	$('#geneValidCodePop').attr('src', relative_path + "valid_code.jsp?id="+ Math.random());
}

function validCodeFaddingPop(str){
    if(str.length>0){
        $('#validCodePopInfo').html('');
        validCodeCheckFlag = false;
    }
    if(str.length==4){
    	$.ajax({url:'../checkValidCode.do',type:'post',dataType:'json',data:{'rUser.validCode':str},
			success:function(data){
				if(data.error  == "S"){
					$('#validCodePopInfo').attr('style','color:#006600;font-size:12px;');
					$('#validCodePopInfo').html('<img src='+urlPicture+'/website_img/right_icon.gif width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-left:10px;"/>'+data.returnMessage);
					validCodeCheckFlag = true;
				}else{
					$('#validCodePopInfo').attr('style','color:red;font-size:12px;font-weight:100;');
					$('#validCodePopInfo').html('<img src='+urlPicture+'/website_img/error_icon.gif width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-left:10px;"/>'+data.returnMessage);
					validCodeCheckFlag = false;
				}
			}
		});
    }
}

function checkValidCodePop(){
	var validCode = $('#validCodePop').val();
	$.ajax({url:'../checkValidCode.do',type:'post',dataType:'json',data:{'rUser.validCode':validCode},
		success:function(data){
			if(data.error  == "S"){
				$('#validCodePopInfo').attr('style','color:#006600;font-size:12px;');
				$('#validCodePopInfo').html('<img src='+urlPicture+'/website_img/right_icon.gif width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-left:10px;"/>'+data.returnMessage);
				validCodeCheckFlag = true;
			}else{
				$('#validCodePopInfo').attr('style','color:red;font-size:12px;font-weight:100;');
				$('#validCodePopInfo').html('<img src='+urlPicture+'/website_img/error_icon.gif width="15" height="14" style="vertical-align:bottom;display:inline;position:relative;padding-left:10px;"/>'+data.returnMessage);
				validCodeCheckFlag = false;
			}
		}
	})
}
