 document.write('<script type="text/javascript" src="https://ssl.captcha.qq.com/TCaptcha.js?ver=' + localStorage.getItem('version') + '"></scr' + 'ipt>');

$('.top').attr('style', "margin-top:"+(localStorage.getItem("ipxSizeTop")*4)+"px;")
mui.init({
	beforeback: function() {　　　　 //获得父页面的webview
		var list = plus.webview.currentWebview().opener();　　　　 //触发父页面的自定义事件(refresh),从而进行刷新
		mui.fire(list, 'refresh');
		//返回true,继续页面关闭逻辑
		return true;
	}
});
mui.plusReady(function() {
	localStorage.removeItem("userId")
	localStorage.removeItem("userName")
	$('.loginbg').height(window.screen.height);
	$('.btn').attr('id','Tcaptcha');
	$('.btn').attr('data-appid','2089606583');
	$('.btn').attr('data-cbfn','callback');
	window.callback = function(res){
		// //console.log(JSON.stringify(res));
		$('.btn').removeAttr('disabled');
		// res（未通过验证）= {ret: 1, ticket: null}
		// res（验证成功） = {ret: 0, ticket: "String", randstr: "String"}
		
		if(res.ret === 0){
			var send_data = {};
			send_data.loginName = $('#loginName').val();
			send_data.loginPwd = $('#loginPwd').val();
			send_data.ticket = res.ticket;  // 票据
			send_data.randstr = res.randstr;
			 var url = qlgUrl('app/users/checkLogin');
			 // var url = hyhUrl('app/users/checkLogin');

			JZL.ajax(url, send_data, function(data){
				if(data.status == 1) {
					var token = data.data.token;
					localStorage.setItem('token', token);
					////console.log(data.data.token);
					mui.back();
					return;
				} else {
					mui.alert(data.msg);
				}
			}, 'POST',0);
		}
	}
	mui('.down').on('tap', '.btn', function() {

		var loginName = $('#loginName').val();

		var loginPwd = $('#loginPwd').val();

		if(loginName == '') {

			mui.alert('用户名不能为空！');

			return;

		}

		if(loginPwd == '') {

			mui.alert('密码不能为空！');

			return;
		}
		$('.btn').attr('disabled', 'disabled');
		var captcha1 = new TencentCaptcha(document.getElementById('Tcaptcha'));
		captcha1.show();
		setTimeout(function(){
			$('.feedback-group',document.getElementById('tcaptcha_iframe').contentWindow.document).hide();
		// $('.feedback-group',document.frames("")).hide();
		},2000)
		//$(this).trigger('click');
		return; 
		//					var loginName = 'zxcvbn';
		//			s		var loginPwd = 'zxcvbn';
		
		mui.ajax(qlgUrl('app/users/checkLogin'), { 
			 // mui.ajax(hyhUrl('app/users/checkLogin'), { 

			data: {
				loginName: loginName,
				loginPwd: loginPwd,
				nameType: 3,
				ticker:ticker
			},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒
			success: function(data) {
				//服务器返回响应，根据响应结果，分析是否登录成功;
// //console.log(data);
				if(data.status == 1) {
					var token = data.data.token;
					localStorage.setItem('token', token);
					////console.log(data.data.token);
					mui.back();
					return;
				} else {
					mui.alert(data.msg);
				}

				$('.btn').removeAttr('disabled');

			},

			error: function(xhr, type, errorThrown) {
				//异常处理;
				//						mui.alert(type);      
			}
		}); 
	})
	mui('.down').on('tap', '#register', function() {
		// JZL.openWindow('register.html', 'register.html');
		JZL.openWindow('register.html', 'register.html');

	})
	mui('.down').on('tap', '#fogetpsd', function() {
		JZL.openWindow('setting_fogetPwd.html', 'setting_fogetPwd.html');
	})
	
})