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

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

	options: {},

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

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

    initDom: function() {
        this.dom.formMineType = $('form-minetype');
    },

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

            var mine = this.dom.formMineType.getElements('input[name=mine]')[0];

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

            }).post({ requestId: SKjs.requestId(), method: 'Tecdocvehicles~Index:mineTypeSearch', mine: mine.get('value') });

		}).bind(this));
    },

    onSendMineSearch: function(jsonObj) {
        if (jsonObj.exception === null && jsonObj.error === null) {
	    	window.parent.location = jsonObj.result;
	    } else {
            SKjs.Loader.hide();
            SKjs.fillErrors(this.dom.formMineType.getElements('input'), jsonObj.exception);
	    }
    }
});
