dojo.require("dojo.parser");
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");
dojo.require("dijit.form.Textarea");

/**
 * @author DREDroot
 *
 */
dojo.declare("dojom.widgets.FeedbackForm", null, 
{    
	floater: null, 
	onSubmit: null,
	templates: 'lib/dojom/widgets/templates/FeedbackForm.html',
	headtext: 'Send the message for administration',
	 	        	
	constructor: function(onSubmit,headtext) 
	{
		this.onSubmit = onSubmit;
		if(headtext) this.headtext = headtext;
		this.create();
	},
	
	create : function()
	{		
		var obj = this;
        var floater;
		if(!dijit.byId('feedback_floater'))
		{		
			var node = document.createElement('div');
			dojo.body().appendChild(node);	
			
			var floater = new dijit.Dialog({
					id:"feedback_floater",
					title:"Feadback",
					submit: obj.submit				
				},node);
			
	
			
												
			
			dojo.connect(floater,'onLoad',function(){				
				dijit.byId('headtextContent').setContent(obj.headtext);
				
				/*
				dojo.connect(floater,'hide',function(){					
					dijit.byId('headtextContent').destroy();
					//document.getElementById('feedbackTextarea').destroy();
					dijit.byId('feedbackOkButton').destroy();
					dijit.byId('feedbackCloseButton').destroy();
					floater.destroy();
				});*/
				
				setTimeout(dojo.hitch(obj, function(){
					document.getElementById('feedbackTextarea').focus();
				}), 1000);		
			});
			
		}
		else 
			floater = dijit.byId('feedback_floater');
		
		floater.setHref(this.templates);	
		this.floater = floater;
		this.floater.execute = obj.onSubmit;
		floater.show();
		floater.layout();
		return floater;
	},
	
	submit : function()
	{
		var message = document.getElementById('feedbackTextarea').value;
		
		if(message && message!='')
		{
			dijit.byId('feedback_floater').execute({
					'message' : message					
				});
			dijit.byId('feedback_floater').hide();							
		}
		else
		{ 
			document.getElementById('feedbackTextarea').focus();			
		}	
	}
	
        	
});
