$.extend({
	login : function(nameObj, pwdObj) {
		if ($.validLogin(nameObj, pwdObj)) {
			var username = $(nameObj).val();
			var password = $(pwdObj).val();
			$.ajax({
		          type:'post',
		          url : 'loginAction!userloginValidation.do',
		          data:{
						username:username,
						password:password
				  },
		          success:function(data){
		        	  if(data == 'success'){
		        		  $.setLogInVal(username,password);
		        		  window.location  = $.proPath()+"/frame/main/area/console/main.jsp";
		        	  }else if(data == 'error'){
		        		  $(nameObj).focus();
		        		  $.showMsg("用户名或密码错误");
		        		  return;
		        	  }else if(data == 'lock'){
		        		  $(nameObj).focus();
		        		  $.showMsg("账户已被冻结，请联系管理员");
		        		  return;
		        	  }else if(data == 'fail'){
		        		  $(nameObj).focus();
		        		  $.showMsg("用户名不存在");
		        		  return;
		        	  }
		          },error:function(a,b,c){
		        	  console.log(a);
		        	  console.log(b);
		        	  console.log(c);
		          }
		      });     
		} else {
			$.showMsg("用户名或密码不能为空");
			return;
		}
	},
	validLogin : function(nameObj, pwdObj) {
		if (!$(nameObj).val() || $(nameObj).val() == "请输入用户名") {
			$(nameObj).focus();
			return false;
		}
		if (!$(pwdObj).val()) {
			$(pwdObj).focus();
			return false;
		}
		return true;
	},
	renderTitle : function() {
		// LoginAction.getSystemConfig(function(config){
		// $("title").html(config.systemTitle || "");
		// $("span.area").html(config.customName);
		// });
	},
	//设置登陆Cookie
	setLogInVal : function(userName,pwd) {
		var ck = $("#remember").prop("checked");
		if(ck) {
			$.ck("username",userName,{expires:30});
			$.ck("password",pwd,{expires:30});
		} else {
			$.ck("username","");
			$.ck("password","");
		}
		$.ck("checked",ck,{expires:30});
	}
});
$(function() {	
	// 重启impAweb  tomcat需要管理员权限
	//restartAweb();
	checkSupport();
	$("#username").focus();
	$("#userLogin").click(function(){
	 	$.login("#username","#password"); 	
	});
	hrefDivReady();
});

function checkSupport() {
	if (!(/webkit/.test(navigator.userAgent.toLowerCase()))) {
		if (confirm("请使用谷歌浏览器，是否下载谷歌浏览器?")) {
			var model = {};
			model.downloadUrl = document.getElementById("chromeDownUrl").value;
			VersionInfoService.download_VersionInfo(model, function(data) {
				if (data != null) {
					if (data.indexOf("&privatePath=versionPath") != -1) {
						window.location.href = downloadUrl;
					} else {
						window.location.href = data + "&privatePath=versionPath";
					}
				} else {
					$.showMsg("下载资源有问题!");
				}
			});
		} else {
			document.write("<b style='color:red;'>对不起，当前浏览器不支持。。<b>");
			return;
		}
	} else {
		/*
		if ($.ck("userName")) {
			$("#username").val($.ck("userName"));
			$("#password").focus();
		}
		*/
		$("#username").val($.ck("username"));
		$("#password").val($.ck("password"));
		$("#remember").prop("checked",$.ck("checked") === "true" ? true : false);
	}
}

function updateOcx() {
	var OCX_VERSION = "";
	try {
		var ocxVersion = ocx.iSeeOcxGetVersion();
		var sysOcxVersion = document.getElementById("ocxVersion").value;
		console.log("=sysOcxVersion=" + sysOcxVersion + "=ocxVersion="
				+ ocxVersion + "=sysOcxVersion>ocxVersion="
				+ (sysOcxVersion > ocxVersion));
		if (sysOcxVersion > ocxVersion) {
			if (confirm("未安装WEBOCX或WEBOCX版本过低，是否下载最新版本WEBOCX?")) {
				var ocxDownUrl = document.getElementById("ocxDownUrl").value;
				downSource(ocxDownUrl);
			}
		}

	} catch (e) {
		if (confirm("未安装WEBOCX或WEBOCX版本过低，是否下载最新版本WEBOCX?")) {
			var ocxDownUrl = document.getElementById("ocxDownUrl").value;
			downSource(ocxDownUrl);
		}
	}
}

function focuslogin(t) {
	var event = (window.event || arguments.callee.caller.arguments[0]);
	if (event.keyCode == 13) {
		if (!t && $(t).val() == "") {
			return;
		}
		event.keyCode = 9;
		$.login("#username", "#password");
	}
}
function hrefDivReady(){
	var r={};
	r.sffb = 1;
	r.page = 1;
	r.rows = 10;	
	r.order = " order by px asc ";
	$.ajax({
		type:'post',
        url : 'xtbbxxAction!listXtbbxxByPage.do',
        data:r,
        success:function(rs){
        	var html="";
    		if(rs && rs.rows.length){
    			console.log("=rs.rows.length="+rs.rows.length);
    			for(var i=0;i<rs.rows.length;i++){
    				var xtbbxx = rs.rows[i];
    				html += "<li><a href='javascript:downSource(\""+xtbbxx.xzdz+"\");'>" + xtbbxx.bbmc + "</a></li>";
    			}
    			$("#firstShowDiv").css("display","inline-block").append(html);
    		}else{
    			$("#firstShowDiv").hide(1);
    		}
        },error:function(a,b,c){
      	  console.log(c);
        }
    });     
	return;
}
function downSource(url){
	if(url.indexOf("&privatePath=downPath")!=-1){
		
	}else{
		downloadUrl =   $.proPath()+"/download?path="+url+"&privatePath=downPath";
	}
	window.location.href=downloadUrl;
}


// 重启impAweb
function restartAweb(){
	/*
	$.ajax({
		type : 'post',
		dataType : 'json',
		data : {},
		url : 'xtbbxxAction!restartAweb.do',
		success : function(res){
			console.log("重启aweb服务：",res);
		}
	})	
	*/
	
}