
var RC = new Class({
	pr_slide : null,
	
	initialize : function()
	{

	 
	},
	
	showConvert : function()
	{
		$('menu').empty();
		app.load('rc', { actions : 'show_convert' }, 
				{ onSuccess : function()
					{
						app.Highlight('rc');
						//this.Parse();
					}.bind(this)
				});
		
	},
		
	Parse : function(save_rc)
	{
		$$('.error').empty();
		
		$('form_rc').send(
		{
			onSuccess : function()
			{
				var xml = new XML(this.response.xml)
				if(!xml || xml.error)
					return alert(this.response.text);
				
				if(xml.ParseErrors())
					return;

				app.rc.Convert();
				
			//	void(window.clipboardData.setData('Text', $('bbcode').value));
			
			}
		});
	
	},
	
	Convert : function(menu, pres)
	{
		if(!pres)
			pres = 'B';
			
		var opts = { };
		if($('form_options') && !menu)
			opts = { data : $('form_options') };
		else
			this.showMenu('convert', pres);
		
		opts.onSuccess = function()
		{
			$('preview').onselectstart =  function() { return false };
		};
			
		app.load('rc', { actions : 'convert', presentation : pres }, opts);
	},
		
	
	showMenu : function(type, presentation)
	{
		app.load('rc', { actions : 'menu', type : type, presentation: presentation }, { update : $('menu') });
	},
	
	loadRC : function(rc_id)
	{
		new Ajax(MODULE_DIR + 'rc/xValid.php?actions=load_rc&rc_id=' + rc_id, 
		{ 
			onSuccess : function()
			{
				var xml = new XML(this.response.xml)
				if(!xml || xml.error)
					return alert(this.response.text);
				
				app.rc.showRC();
				//app.rc.Convert();
			}
		}).request();
	},
	
	showRC : function()
	{
		app.load('rc', { actions : 'show_rc'});
		this.showMenu('show');
	},
	
	setPassword : function(event)
	{
		new Event(event).stop();
		
		$$('.error').empty();
		$('form_password').send(
		{
			onSuccess : function()
			{
				var xml = new XML(this.response.xml);
				if(!xml || xml.error)
					return alert(this.response.text);
					
				if(!xml.ParseErrors())
					app.rc.showRC();
			}
		});
	},
	
	SelectUnitColor : function(el)
	{
		$$('.unit_color').setStyle('borderColor', '#f6ebba');
		el.setStyle('borderColor', '#999999');
		
		var colors = { 'none' : 'Aucune colorisation',
						'red' : 'Colorisation rouge',
						'green' : 'Colorisation verte',
						'blue' : 'Colorisation bleue' };
			
		$('unit_color_input').value = el.id;
		$('unit_color_libelle').setHTML(colors[el.id]);
		this.Convert();
	}
		
});

