Ext.onReady(function(){
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'under';

	var logoPanel = new Ext.Panel({
 		baseCls: 'x-plain',
 		id: 'login-logo',
 		region: 'center'
 	});
 	
    var loginForm = new Ext.FormPanel({
    	url: 'login.do',
		baseCls: 'x-plain',
 		defaults: {width: 200},
 		defaultType: 'textfield',
 		frame: false,
 		height: 120,
 		id: 'login-form',
 		labelWidth:120,
 		labelAlign: 'right',
 		region: 'south',
 		
 		items: [{
	 		fieldLabel: '用户名',
	 		name: 'username',
			allowBlank:false,
			labelStyle: 'font-weight:bold;',
			blankText:'请输入用户名'
 		},{
			fieldLabel: '密&nbsp;&nbsp;&nbsp;码',
	 		inputType: 'password',
	 		name: 'password',
	 		allowBlank:false,
	 		labelStyle: 'font-weight:bold;',
			blankText:'请输入密码'
 		},{
 			xtype: 'panel',
 			baseCls: 'background-color:x-plain',
			defaultType: 'radio',
 			layout: 'table',
 			border: false,
 			isFormField: true,
 			items: [
 			// 去掉集团用户登陆口 2010-08-25 ＨＰＷ 2010-09-02添加集团用户登陆,为了顺丰测试用
 			{
	 			boxLabel: '集团用户',
	 			name: 'userType',
	 			inputValue: 0,
	 			checked: true
 			},
 			{
	 			boxLabel: '个人用户',
	 			name: 'userType',
	 			inputValue: 1
	 			//ＨＰＷ 2010-09-02 暂时去掉了个人用户默认选中框
	 			//,
	 			//checked: true
 			}]
 		}]
    });
    
    var form = loginForm.getForm();
    
    var win = new Ext.Window({
    	title: '用户登录',
    	buttonAlign: 'center',
		closable: false,
	 	draggable: false,
	 	layout: 'border',
	 	width: 450,
	 	height: 230,
	 	resizable: false,
	 	renderTo: 'login-win',
	 	
	 	items: [
		 	logoPanel,
		 	loginForm
	 	],
	 	buttons: [{
	 		text: '登录',
		 	handler: checkLogin
			},{
		 	text: '重置',
		 	handler: function(){
		 		form.reset();
		 	}
		}],
	 	keys: {
        	key: [13],
	        fn: checkLogin
      	}
	});
	
	function checkLogin(){
		if(form.isValid()){
			form.doAction('submit', {
				url: 'login.do',
				waitTitle: '验证信息',
				waitMsg: '正在验证用户名和密码，请稍候...',
				method: 'post',
				success: function(f, a){
					if(a.result.msg == 'ok'){
						//pop;
						//window.location.href = 'ribbon.jsp?t=' + new Date().getTime();
						//var paras = 'status=no,location=no,scrollbars=no,resizable=yes,left=0,top=0,height='+(screen.availHeight-36)+',width='+(screen.availWidth-0);
						//window.open('menu.jsp',"_pop",paras);
						window.location.href = 'menu.jsp';
					}else{
						Ext.Msg.alert('提示窗口', a.result.msg);
					}
				},
				failure: function(f, a){
					Ext.Msg.alert('错误','服务器端出现错误,请稍后再试！');
				}
			});
		}
	}
	
	function pop(){
		var paras = 'status=yes,left=0,top=0,height='+(screen.availHeight-36)+',width='+(screen.availWidth-0);
		if(obj==null||obj=="undefined"||obj.closed){
			obj = window.open('main.jsp',"_pop",paras);
		}else{
			obj.window.close();
			obj = window.open('main.jsp',"_pop",paras);		
		}		
	} 
	
	win.show();
});
