var proName = top.window.location.pathname.split("/")[1];
$.extend({
	login:function(unitObj,secuserObj,nameObj,pwdObj){
		var unit = $(unitObj).combobox('getValue');
		if(unit == ''){
			$.dlg.alertError("请选择单位!");
		}else if($(secuserObj).combobox('getValue') == ''){
			$.dlg.alertError("请选择值班人员!");
		}else if($.validLogin(unitObj,secuserObj,nameObj,pwdObj)){
			var user = $(nameObj).combobox('getValue');
			var pwd = $(pwdObj).textbox('getValue');
			$.ajax({
				type:'post',
		        async:false ,
		        data: {bh:user,dlmm:pwd,"DS300PCSBM" : unit},
		        url : 'loginAction!checkUserAccount.do',
		        success : function(rtn){
		        	if(rtn == 'success'){
		        		location.href = "http://"+window.location.host+"/"+proName+"/frame/main/area/dft/main.jsp";
		        	}else{
		        		$.dlg.alertError("登录用户或密码不正确!");
		        	}
		        } 
		  	});
		}else{
			$.dlg.alertError("登录用户或密码不能为空");
		}
	},
	validLogin:function(unitObj,secuserObj,nameObj,pwdObj){  
		if($(pwdObj).textbox('getValue') == '' || $(nameObj).combobox('getValue') == ''){
			return false;
		}
		return true;
	},
	renderTitle:function(){
		$.ajax({
			type:'post',
	        async:false ,
	        url : 'menuAction!getMenuGroupList.do',
	        success : function(config){
	        	$("title").html(config.systemTitle || "视频综合应用中心平台");
				$("span.area").html(config.customName);
	        } 
	  	});
	}
});
$(function(){
	initDefault();
	$("#loginBtn").on('click',function(){
		$.login("#unit","#secuserName","#userName","#password");
    });
//	$.renderTitle();
});
function initDefault(){
	//test
	$.ajax({
		type:'post',
		async:false,
		url:'loginAction!selectUserRole.do',
		success:function(unit){
			$("#unit").combobox({
				data:unit,
				textField:'SSPCS',  
				valueField:'DS300PCSBM',
				panelWidth:148,
				onSelect:function(record){
					$.ajax({
						type:'post',
						async:false,
						data:{'dwmc':record.SSPCS},
						url:'loginAction!selectUser.do',
						success:function(userName){
							$("#userName").combobox({
								data:userName,
								textField:'XINGMING',  
						        valueField:'BIANHAO',
						        panelWidth:148
						    });
							$("#secuserName").combobox({
								data:userName,
								textField:'XINGMING',  
						        valueField:'BIANHAO',
						        panelWidth:148
						     });
						}
					})	
					$.ajax({
						type:'post',
						async:false,
						data:{'pcsbm':record.DS300PCSBM},
						url:'loginAction!selectUserRole.do'
					});
				}
		    });
		}
	})
}
function focuslogin(t){
	var event = (window.event ||arguments.callee.caller.arguments[0]);
	if (window.event.keyCode == 13) {
		$.login("#unit","#secuserName","#userName","#password");
	}
}