$package('difc.signinbar',
    $class('SignAction').$implements(ejs.events.IEventDispatcher).$define(
        $private({
            h_httper:null,
            onSigninHandler:function(event){
                this._$h_httper.removeEventListener(ejs.net.ResultEvent.COMPLETE, this._$onSigninHandler);
                var _o_result = JSON.parse(event.result);
                if(_o_result['errorCode']>0){
                    if(_o_result['failureWords'])
                        alert(_o_result['failureWords']);
                }
                else{
                    if(_o_result['location'])
                        location.href = _o_result['location'];
                    else
                        location.href = location.href;
                }
            },
            onSignoutHandler:function(event){
                this._$h_httper.removeEventListener(ejs.net.ResultEvent.COMPLETE, this._$onSignoutHandler);
                var _o_result = JSON.parse(event.result);
                if(_o_result['errorCode']>0){
                    if(_o_result['failureWords'])
                        alert(_o_result['failureWords']);
                }
                else{
                    if(_o_result['location'])
                        location.href = _o_result['location'];
                    else
                        location.href = location.href;
                }
            },
            onFaultHandler:function(event){
                //alert(event.errorCode);
            }
        }),
        $public({
            construct:function(){
                this._$h_httper = new ejs.net.HttpService();
                this._$h_httper.eventHandle = this;
                this._$h_httper.url = '/ws/archangel/php_service/handleapp/signinbar.app.class.php';
                this._$h_httper.resultType = ejs.net.ResultType.text;
                this._$h_httper.method = ejs.net.HttpMethod.post;
                this._$h_httper.addEventListener(ejs.net.FaultEvent, this._$onFaultHandler);
            },
            request:function(){
                var args = arguments[0]||{};
                switch(args.action){
                    case 'signin':
                        if(args.usrid=='' || args.pwd==''){
                            if(args.nullValidText)
                                alert(decodeURIComponent(args.nullValidText));
                            return;
                        }                            
                        this._$h_httper.addEventListener(ejs.net.ResultEvent.COMPLETE, this._$onSigninHandler);
                        this._$h_httper.send([
                            'req=request',
                            '&action=signin',
                            '&usrid=',encodeURIComponent(args.usrid),
                            '&pwd=',encodeURIComponent(hex_md5(args.pwd)),
                            '&type=', encodeURIComponent(args.type),
                            '&id=', encodeURIComponent(args.id)
                        ].join(''));
                        break;
                    case 'signout':
                        this._$h_httper.addEventListener(ejs.net.ResultEvent.COMPLETE, this._$onSignoutHandler);
                        this._$h_httper.send([
                            'req=request&action=signout',
                            '&type=', encodeURIComponent(args.type),
                            '&id=', encodeURIComponent(args.id)
                        ].join(''));
                        break;
                }
            }
        })
    )        
);

