Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';
Ext.onReady(function(){
	//submit
	
	function summitFn(){
			//data
//		    var btnId = this.id;
			var errorMsg = '';
			var userName = Ext.get('userName').dom.value.trim();
			var userPassword = Ext.get('userPassword').dom.value.trim();
            //ajax
			if(userName == '')
			{
				errorMsg += "用户名称不能为空！<br>";
				ExtMsg(errorMsg);
			}
			if(userPassword == '')
			{
				errorMsg += "用户密码不能为空！<br>";
				ExtMsg(errorMsg);
			}
			else
			{
				Ext.Ajax.request({
					url:'loginCheck.php',
					method:'post',
					params:{
						userName:userName,
						userPassword:userPassword
					},
					success:function(response, options) {
						var errorMsg ='';
						var responseObj = Ext.util.JSON.decode(response.responseText);
//						alert(responseObj.flag);
						if(responseObj.flag=='4'){
	                        document.location.href="main.php";//登录成功  -- 散客
	                     }
						if(responseObj.flag=='5'){
	                        document.location.href="syssearch/main.php";//登录成功 -- 固客
	                     }	                     
	                    if(responseObj.flag=='2'){
	                     	errorMsg = "用户密码错误！";
	                     	ExtMsg(errorMsg);
	                     }
	                    if(responseObj.flag=='3'){
	                     	errorMsg = "用户名不存在！";
	                     	ExtMsg(errorMsg);
	                     }
	
					}
				});
			}
		};
	//提示
	function ExtMsg(errorMsg){ 
		Ext.MessageBox.show({
		title:'状态',
		width:200,
		closable:false,
		modal:false,
		msg: "<div style='text-align:left'>"+errorMsg+"</div>",
		buttons:Ext.MessageBox.OK,
//		animEl: id,
		icon:Ext.MessageBox.ERROR
		});
	};
	//
	Ext.get('userName').on('keypress',function(e){
		if (e.getKey() == e.ENTER ) {   
                    summitFn();  
        }
	});		
	Ext.get('userPassword').on('keypress',function(e){
		if (e.getKey() == e.ENTER ) {   
                    summitFn();  
        }
	});
	Ext.get('subBtn').on('click',summitFn);	
})


