
/**
 *@ just_digit
 *@ INPUT输入字符串限制为 整数
 *@ id : 要控制的input ID
 */
function just_digit (obj) {
	$(obj).val($(obj).val().replace(/[^0-9]/g,''));
}

/**
 *@ getAuth
 *@ 更换验证码
 */
function getAuth() {
	$("#auth_img").click();
}

/**
 *@ just_float
 *@ INPUT输入字符串限制为 浮点数
 */
function just_float (obj) {
	$(obj).val($(obj).val().replace(/[^0-9.]/g,''))
}

/**
 *@ just_char
 *@ INPUT输入字符串限制为 英文字符
 */
function just_char (obj) {
	$(obj).val($(obj).val().replace(/[^a-zA-Z]/g,''))
}

/**
 *@ just_digit_line
 *@ INPUT输入字符串限制为 整数-_
 */
function just_digit_line (obj) {
	$(obj).val($(obj).val().replace(/[^0-9\-_]/g,''));
}

/**
 *@ isUrl Javascript判断是否为一个合法的URL
 */
function isUrl(str) {
	pregMatch = /^http:\/\/[\w]+\.[\w]+[\S]*/;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isIcq Javascript判断是否为一个QQ号码
 */
function isIcq(str) {
	pregMatch = /^[1-9][0-9]{3,9}$/;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isMobile Javascript判断是否为一个手机号码
 */
function isMobile(str) {
	pregMatch = /^[1][3458][0-9]{9}$/;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isPhone Javascript判断是否为一个座机号码
 */
function isPhone(str) {
	pregMatch = /^[0-9]{3,4}-[1-9][0-9]{6,7}$/;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isMobile Javascript判断是否为一个手机号码
 */
function isTel(str) {
	pregMatch = /^[1][3458][0-9]{9}$/;
	pregPhone = /^[0-9]{3,4}-[1-9][0-9]{6,7}$/;
	if (pregMatch.test(str)) {
		return true;
	} else if (pregPhone.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isMobile Javascript判断是否为一个手机号码
 */
function isDegit(str) {
	pregMatch = /^[1][0-9]{0,9}$/;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isMobile Javascript判断是否为一个URL地址
 */
function isUrl(str) {
	pregMatch = /^http:\/\/[\w]+\.[\w]+[\S]*/;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isEmail Javascript判断是否为一个邮箱
 */
function isEmail(str) {
	pregMatch = /^[1-9a-z][0-9a-z_]{2,30}@[1-9a-z][0-9a-z]+(\.[a-z])+/i;
	if (pregMatch.test(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 *@ isEmail Javascript判断是否为一个合法的用户名
 */
function isUserName(str) {
	pregUser = /\s+|^c:\\con\\con|[%,\*\"\s\<\>\&]|\xA1\xA1|\xAC\xA3|^Guest|^\xD3\xCE\xBF\xCD|\xB9\x43\xAB\xC8/i;
	if (!pregUser.test(str)) {
		if (str.length >= 3 && str.length <= 15) {
			return true;
		}
	}
	return false;
}


/**
 *@ rsyncClose
 *@ 打开RSYNC异步提示
 */
function rsyncLoading() {
	$.Dialogs.open({type:'loading',text:'加载中...',src:'/images/loading.gif'});
}

/**
 *@ rsyncClose
 *@ 关闭RSYNC异步提示
 */
function rsyncClose() {
	$.Dialogs.close();
}


/**
 *@ showMsg
 *@ 本函数依赖于 artDialog 对话框插件
 *@ msg : 要给用户提示的信息
 */
function showOk(msg, jumpUrl, callback, arg1, arg2, arg3) {
	setTimeout(
		function (){$.Dialogs.open(
			{
				type:'success',text:msg
			},
			{
				afterClose:function(){
					if (jumpUrl) {
						document.location.href = jumpUrl;
					} else if (callback) {
						callback(arg1, arg2, arg3);
					}
				}
			}
		)}
	, 100);
}

/**
 *@ showMsg
 *@ msg : 要给用户提示的信息
 */
function showError(msg, focus, jumpUrl, callback, arg1, arg2, arg3) {
	setTimeout(
		function (){$.Dialogs.open(
			{
				type:'fail',text:msg
			},
			{
				afterClose:function(){
					if (focus) {
						$("#"+focus).focus();
					}
					if (jumpUrl) {
						document.location.href = jumpUrl;
					}
					
					if (callback && callback != 'success') {
						callback(arg1, arg2, arg3);
					}
				}
			}
		)}
	,100);
}


/**
 *@ rsyncLogin 异步弹出框登录平台
 */
function rsyncLogin(callfun, arg1, arg2, arg3) {
	var htmlString = 
		'<div class="login" style="background-color:#FFFFFF;">'+
			'<h5>登录帐户 >> 去购物 >> 返利到您的帐户<img onclick="rsyncClose();" src="images/login_gb.gif" /></h5>'+
			'<div class="usernr">'+
				'<form>'+
					'<dl>'+
						'<dd><span>用户名：</span>'+
						'<input name="u_mail" id="u_mail" value="请输入用户名或邮箱" style="color:grey;" onclick="this.value=&quot;&quot;" type="text" maxlength="40" /></dd>'+
						'<dd>'+
							'<span>密码：</span>'+
							'<input name="u_passwd" id="u_passwd" type="password" maxlength="20" />'+
							'<em>忘记密码？</em>'+
						'</dd>'+
						'<dd>'+
							'<span>验证码：</span>'+
							'<input name="auth" id="auth" class="lzm" type="text" maxlength="4" />'+
							'<img id="auth_img" src="/?c=login&a=auth" onclick="this.src=&quot;/?c=login&a=auth&random=&quot;+Math.random();" /> '+
							'<em class="grey">看不清？</em>'+
							'<em class="red"><a href="#" onclick="getAuth(); return false;" style="color:red;">换一张</a></em>'+
						'</dd>'+
						'<dd class="dl"><input id="loginSubmit" type="button" value="登录" /></dd>'+
						'<dd class="checkbox">'+
							'<input name="agree" type="checkbox" value="1" checked="1" /> '+
							'<em>保持登录<a href="/?c=register"><em class="red">快速注册！</em></a></em>'+
						'</dd>'+
					'</dl>'+
				'</form>'+
			'</div>'+
		'</div>';
	
	$.Dialogs.open({type:'html',html:htmlString,modal:true},{height:400,width:550});
	
	$("#loginSubmit").click(function(){
		if ($("#u_mail").val() == '请输入用户名或邮箱' || (!isEmail($("#u_mail").val()) && !isUserName($("#u_mail").val()))) {
			$("#u_mail").val('');
			$("#u_mail").focus();
			return false;
		}
		if ($("#u_passwd").val().length > 20 || $("#u_passwd").val().length < 6) {
			$("#u_passwd").focus();
			return false;
		}
		if ($("#auth").val().length != 4) {
			$("#auth").focus();
			return false;
		}
		rsyncClose();
		$.ajax({
			type: "POST",
			url: "/?c=login&a=rsyncLogin",
			data: "u_mail="+$("#u_mail").val()+"&u_passwd="+$("#u_passwd").val()+"&auth="+$("#auth").val()+"&random="+Math.random(),
			dataType: "json",
			beforeSend: rsyncLoading,
			success: function(response) {
				rsyncClose();
				if (response.status) {
					if (callfun) {
						callfun(arg1, arg2, arg3);
					}
				} else {
					showError(response.info, '', '', rsyncLogin, callfun, arg1, arg2);
				}
			}
		});
	});
}
