var FeedbackInterface = Class.create();

FeedbackInterface.prototype = Object.extend( (new CCnfDialog('fdb-container')), {

	initialize: function (config)
	{
		this.ajaxLoadingEffect = null;
		this.body = null;
		this.winContainer = 'win-form';

		this.popupObject = null;
		Event.observe(document, 'dom:loaded', this.init.bindAsEventListener(this) );

	},

	init: function()
	{
		initializeWindow();
	},

	initFeedbackForm: function(formName, containerId)
	{
            	if (containerId) {
			this.winContainer = containerId;
		}
		var form = ($(formName));
                
                form.onsubmit = function() { return false }
		Event.observe ( form, 'submit', this.saveFeedback.bindAsEventListener(this) );
		var save = form.getElementsBySelector('a[rel="save"]');
		if ( save )
		{
                    	save.each(function(el) { el.onclick = function() { return false } } )
                        save.invoke('observe', 'click', this.saveFeedback.bindAsEventListener(this) );
		}

	},

	saveFeedback: function(evt)
	{
		var f = Event.findElement(evt,'form');
                var formParams = f.serialize();
                this.setLoadingEffect(this.winContainer);

        if (f.method == 'post')
        {
            new Ajax.Request(f.action, {
                //onCreate: this.onCreateLoading.bind(this),
                //onFailure: this.onFailureLoading.bind(this),
                'onSuccess':this.successLoading.bind(this),
                'postBody':formParams
            });
        }
        else
        {
            new Ajax.Request(f.action+'?'+formParams, {
                //onCreate: this.onCreateLoading.bind(this),
                //onFailure: this.onFailureLoading.bind(this),
                'onSuccess':this.successLoading.bind(this)
            });
        }
        return false;
	},
	successLoading: function (response)
        {
                this.removeLoadingEffect();
		popupWindow.successLoading(response);
		popupWindow.actions();
                return false;
        },

	removeLoadingEffect: function()
        {
		if(this.ajaxLoadingEffect != null){
			this.ajaxLoadingEffect.removeLoadingEffect();
		}	
        },

	setLoadingEffect: function(idWin)
        {
		if(this.ajaxLoadingEffect == null)
		{
			this.ajaxLoadingEffect = new AjaxLoadingEffect({'containerId':idWin});
		}
		this.ajaxLoadingEffect.setLoadingEffect();
	},

        hideInfo: function()
        {
            this.hideCnf();
        }

});

var objFeedback = new FeedbackInterface({});

