var FormHandlerInstanceManager = {
    _instance: null,
    Get: function(e, form, elementsToWatch, cookieNameTransform){
        if(this._instance == null)
            this._instance = new FormHandler(e, form, elementsToWatch, cookieNameTransform);

        if(typeof e != 'undefined' && typeof e.persisted != 'undefined' && e.persisted == true)
            this._instance.PersistInit();
            
        return FormHandler._instance;
    }
};

function FormHandler(e, form, elementsToWatch, cookieNameTransform)
{
    var tthis = this;
    this._form = (typeof form == 'string' ? document.forms[ form ] : form);
    
    this._dataHandler = new FormDataHandler(this._form, cookieNameTransform, this._ShowDataError.bind(this));
    this._dataHandler.Init();
    this._dataHandler.Load();
}

FormHandler.prototype.PersistInit = function()
{
    this._dataHandler.RestoreItems();
}

//hibajelentes a kliensnek
FormHandler.prototype._ShowError = function(msg)
{
    alert(msg);
}

FormHandler.prototype._ShowDataError = function()
{
    this._ShowError(texts['data_not_set_or_incorrect']);
}
