﻿Ext.BLANK_IMAGE_URL="../Public/Ext/resources/images/default/s.gif";
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

//刷新验证码函数
function reloadcode(){
    var verify = document.getElementById('safecode');
	verify.setAttribute('src', '../../../../Ejs/chknumber.php?' + Math.random());
}

Login = function(){
	var win,
		form,
		submitUrl = app + '/Login/CheckLogin/' ;

	function onSubmit(){
		this.showMask();

		form.submit({
			reset: true
		});
	}

	return{
		Init:function(){

			var formPanel = new Ext.form.FormPanel({
		        baseCls: 'x-plain',
		        baseParams: {
		        	module: 'login'
		        },
		        defaults: {
		        	width: 150
		        },
		        defaultType: 'textfield',
		        id: 'login-form',
		        items: [{
		            fieldLabel: M_MEG.user,
                    cls: 'user-icon' ,
                    style : "font-size: 12px" ,
		            name: 'login_user'
		        },{
		            fieldLabel: M_MEG.pw,
                    cls: 'key-icon' ,
                    style : "font-size: 12px" ,
		            inputType: 'password',
		            name: 'login_pass'
		        },{
                    cls: 'randcode-icon',
                    style : "font-size: 12px" ,
                    name: 'chknumber',
                    id: 'randCode',
                    fieldLabel: M_MEG.yzm,
                    maxLength: 4,
                    width: 85,
					validator: function(v){
						return true ;
					} ,
					invalidText: M_MEG.yzmbzq ,
					maxLengthText: M_MEG.ccyzmzdzfs
                }],
		        labelWidth:55,
		        listeners: {
					'actioncomplete': {
						fn: this.onActionComplete,
						scope: this
					},
					'actionfailed': {
						fn: this.onActionFailed,
						scope: this
					}
				},
		        region: 'center',
		        url: submitUrl
		    });

		   win = new Ext.Panel({
		        buttons: [{
		        	handler: onSubmit,
		        	scope: Login,
		            text: M_MEG.dl
		        }],
		        buttonAlign: 'right',
		        closable: false,
		        draggable: false,
		        height: 145,
		        id: 'login-win',
		        keys: {
		        	key: [13], // enter key
			        fn: onSubmit,
			        scope:this
		        },
		        layout: 'border',
		        minHeight: 145,
		        minWidth: 260,
		        plain: true,
		        resizable: false,
		        items: [
		        	formPanel
		        ],
				border:false,
				bodyStyle:"background:none",
				//title: 'CSA订单系统登录',
                //iconCls: 'login-icon' ,
		        width: 260,
				renderTo:"loginform"
		    });

			form = formPanel.getForm();

			formPanel.on('render', function(){
				var f = form.findField('user');
				if(f){
					f.focus();
				}
			}, this, {delay: 200});

		    win.show();
            var bd = Ext.getDom('randCode');
            var bd2 = Ext.get(bd.parentNode);
            bd2.createChild([{
            tag: 'span',
            html: ' <a href="javascript:reloadcode();">',
			style: 'margin-left:17px'
            },{
            tag: 'img',
            id: 'safecode',
            src : '../../../../Ejs/chknumber.php?'+ Math.random(),
            align: 'absbottom' ,
			html: '</a>'
            }]);
		},

		hideMask : function(){
			this.pMask.hide();
			win.buttons[0].enable();
		},

		onActionComplete : function(f, a){
			this.hideMask();
			if(a && a.result){
				win.destroy(true);
				window.location = app;
			}
		},

		onActionFailed : function(){
			this.hideMask();
		},

		showMask : function(msg){
			if(!this.pMask){
		        this.pMask = new Ext.LoadMask(win.body, {
		        	msg: M_MEG.wait
		        });
			}

			if(msg){
				this.pMask.msg = msg;
			}
	    	this.pMask.show();
	    	win.buttons[0].disable();
	    }
	};
}();

Ext.onReady(Login.Init, Login, true);
