<{import file="member/reg_header.html" title="会员登陆"}>
<style type="text/css">
#vcodebox{ display:none; }
</style>
<div class="main_bar">
	<div class="lunbo">
		<{ads alias="member_login" data="bg_ads"}>
		<{foreach item="i" from=$bg_ads}> 
			<{if $i.type == '2'}>
				<a href="<{$i.link}>" target="_blank" style="background: url(<{$__IMG__}><{$i.content|img_size:1920x500}>) center center;"></a>
			<{/if}> 
		<{/foreach}>
	</div>
	<div class="main">
		<form action="#" method="post">
			<div class="reg_box">
				<div class="bname"><span>用户登录</span></div>
				<div class="bcon">
					<div id="error_msg" style="display:none;"></div>
					<div class="binput"><i class="i1"></i><input type="text" name="username" placeholder="用户名/邮箱/电话号码" id="text"/></div>
					<div class="binput"><i class="i2"></i><input type="password" name="password" id="password" placeholder="密码"/></div>
					<div class="binput" id="vcodebox">
						<i class="i3"></i><input type="text" name="vcode" size="10" id="vcode" placeholder="验证码" maxlength="4"/>
						<a href="javascript:;" onClick="change_img()"><img id="vcode_img" src="<{$__URI__}>ajax/vcode"/></a>
					</div>
					<div class="binput" style="border:none;"><input type="submit" name="submit" class="submit_login" value="登录"/></div>
				</div>
				<div class="login_reg_box">
					<a href="<{$__URI__}>member/forget" style="padding-right:30px;">忘记密码</a>
					<a href="<{$__URI__}>member/register">立即注册</a> 
				</div>
				
				<{uqcms m="api" v="conn" c="alist:type=login"}> 
				<{if $conn}>
					<div class="sub_frm">
						<label style="color:#999;">快捷方式登录：</label>
						<div class="sub_con">
							<{foreach item=i from=$conn}> 
								<a href="<{$__URI__}>member/connect?alias=<{$i.alias}>&state=<{math equation=rand(0,10000)}>" class="connect"><img src="<{$__PUBLIC__}>images/connect/32<{$i.alias}>.png"><span><{$i.name}></span></a>
							<{/foreach}> 
						</div>
					</div>
				<{/if}>
			</div>
		</form>
	</div> 
</div>
<div class="copyright_bar">
	<div class="copyright"><{$UQCMS.site_copyright}></div>
</div>
<{import file="bottom.html"}>
<script type="text/javascript">
function GetQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
} 
$(function(){ 
	$('form').submit(function(){ 
		var username = $('input[name=username]').val();
		var password = $('input[name=password]').val(); 
		if(username == ''){$("#error_msg").show().html('用户名不能为空'); return false;} 
		if(password == ''){$("#error_msg").show().html('密码不能为空'); return false;} 
		$('.submit_login').attr("disabled", true).val('正在登陆..');
		var vcode = $('#vcode').val(); 
		$.ajax({
			type:'POST',
			url:URI+'member/login_do',
			data:{username:username, password:password, vcode:vcode}, 
			success:function(result){
				var data = jQuery.parseJSON(result); 
				if(data.error == '0'){
					<{if $smarty.get.returnUrl}>
						location.href=GetQueryString('returnUrl'); 
					<{else}>
						location.href=URI+"index/index";
					<{/if}> 
				}else{
					ckVcode();
					$("#error_msg").show().html(data.msg);
					$('.submit_login').attr("disabled", false).val('登陆');
					change_img();
				}
			},
			error:function(){
				$.alert('错误');
				$('.submit_login').attr("disabled", false).val('登陆');
			}
		});
		return false; 
	});
	
	$("input[name='username'],input[name='password']").blur(function(){ 
		ckVcode();
	});
	
	function ckVcode(){ 
		var username = $("input[name='username']").val();
		if(username == '' || username == undefined){
			$("#vcodebox").hide();
		}else{
			$.post('<{$__URI__}>member/is_vcode', {username:username}, function(result){
				data = jQuery.parseJSON(result);
				if(data.error == '1'){
					$("#vcodebox").show();
				}else{
					$("#vcodebox").hide();
				}
			});
			return false;
		} 
	} 
	
});
function change_img(){ 
	var timestamp = (new Date()).valueOf();
	var src = URI+'ajax/vcode?time='+timestamp;
	$("#vcode_img").attr('src',src);
} 
</script>
