CosMooPopForm = new Class({
	Implements: [Options],
	
	options: {
		id: 'CMPopForm',
		classPopup:'contPopup',
		classClose:'closePopup',
		imgClose:'immagini/grafica/cosmoopopup/chiudi.png',
		editUrl:'',
		rootPath:'',
		zIndex:1000
	},
	
	initialize: function(options)
	{
		this.setOptions(options);
	},
	
	attach: function(selector)
	{
		var obj = this;
		buttons = $$(selector);
		buttons.each(function(el){ 
			el.addEvent('click', function(ev){
				var id = this.get('rel');
				obj.edit(id);
			});
		});
	},
	
	edit:function(id)
	{
		var obj = this;
		var tfcForm = new CosMooFC({'id':this.options.id, 'root_path':obj.options.rootPath, afterSubmit: function(data){
			obj.pop_grid.hide();
		}});
		
	    tfcForm.createByUrl(obj.options.editUrl, {'id':id});		
	    obj.openWin(tfcForm.getForm());
	    
	    //per compatibilita con ie7 devo checcare le checkbox dopo averle messe nel dom
		$$(".boxChecked").each(function(el){
			el.set("checked", "checked");
		});
		var editors = $$('.textEditor textarea');
		editors.each(function(el, index){el.moorte({buttons:'div.Toolbar:[bold,italic,underline,strikethrough, Justify, undo, redo]'});});
	},
	
	openWin: function(content)
	{
    	this.pop_grid = new CosMooPopup({
			width: 'auto',
			height: 'auto',
			content: content,
			classClose: 'closePopup',
			classPopup: 'contPopup',
			rootPath: this.options.rootPath,
			modal: true,
			zIndex: this.options.zIndex
		});
    	this.pop_grid.show();
    	/*this.pop_grid.sticky.addEvent('close', function(){
			$$('.swiff-uploader-box').each(function(el){el.destroy()});
		});*/
	}
});
