window.addEvent('domready', function() {
    new SKjs.BoxPwdLost();
});

SKjs.BoxPwdLost = new Class ({
	Implements: [Events, Options],

	options: {
        elmPwdForm:      	'form#passwordLost'
	},

    initialize: function() {
        this.dom            = {};

		this.initDom();
		this.initEvents();
    },

    initDom: function() {
        this.dom.form     	= $$(this.options.elmPwdForm)[0];
        this.dom.submitForm = $$(this.options.elmPwdForm + ' input[type=submit]')[0];
		this.dom.formElms 	= $$(this.options.elmPwdForm + ' input[type=text]');
    },

    initEvents: function() {
    	this.dom.form.addEvent('submit', (function(e) {
            SKjs.Loader.display();
			e.stop();

            var inputValues = {};
            this.dom.formElms.each(function(elm) {
                inputValues[elm.name] = elm.value;
            });

            new Request.JSON({
                url:        SKjs.loaderJSON,
                encoding:   SKjs.encoding,
                onComplete: this.onSendFormPwdLost.bind(this)

            }).post({ requestId: SKjs.requestId(), method: 'Customers~Logon:passwordLost', login: inputValues['login'] });

		}).bind(this));
	},

    onSendFormPwdLost: function(jsonObj) {
        SKjs.Loader.hide();

	    if (jsonObj.exception === null && jsonObj.error === null) {
            SKjs.fillMessage(this.dom.form, jsonObj.result);

	    } else {
	    	SKjs.Loader.hide();
            SKjs.fillErrors(this.dom.formElms, jsonObj.exception);
	    }
    }
});
