/* Communications Flash/Javascript */
var EditorDetector=new Class({
	detected:false,
	initialize: function()
		{
		this.forms=$$('form');
		this.forms.each(function (form)
			{
			var editors=form.getElements('object');
			if(editors.length==1)
				{
				editorManager=new EditorManager(form,editors[0]);
				}
			}, this);
		}
	});

var EditorManager=new Class({
	initialize: function(form, editor)
		{
		this.form=form;
		this.editor=editor;
		this.form.addEvent('submit', this.saveDatas.bind(this), true);
		//window.productCallback=this.handleProduct.bind(this);
		//window.dataCallback=this.handleData.bind(this);
		var ftitle=document.getElementById('ftitle');
		if(ftitle&&!document.getElementById('fowner'))
			{
			ftitle.parentNode.style.display='none';
			}
		if(window.productIdentifier)
			this.handleProduct(window.productIdentifier);
		},
	saveDatas: function(event)
		{
		if(document.getElementById('fcgv')&&!document.getElementById('fcgv').checked)
			alert('Merci d\'accepter les conditions de soumission !');
		else
			this.editor.saveDatas();
		event.stop();
		event.stopPropagation();
		},
	handleData: function(datas)
		{
		document.getElementById('fdatas').value=datas;
		this.form.removeEvent('submit', this.saveDatas.bind(this), true);
		var ftitle=document.getElementById('ftitle');
		if(ftitle&&!document.getElementById('fowner'))
			{
			ftitle.parentNode.style.display='block';
			}
		//if(!this.form.hasClass('xcform'))
			this.form.submit();
		},
	handleProduct: function(product)
		{
		window.productIdentifier = product;
		var fsize=document.getElementById('fsize');
		if(fsize)
			{
			var sizes=[];
			sizes['tshirt-men']=['S','M','L','XL'];
			sizes['tshirtml-men']=['S','M','L','XL'];
			sizes['tshirt-women']=['S','M','L'];
			sizes['tshirtml-women']=['S','M','L'];
			sizes['top-women']=['S','M','L'];
			sizes['tshirt-girl']=['4 ans','6 ans','8 ans','10/12 ans'];
			sizes['tshirt-boy']=['3 ans','5 ans','8 ans','10 ans','12/14 ans'];
			sizes['tshirt-baby']=['6 mois','12 mois','18 mois','2 ans'];
			sizes['body-baby']=['6 mois','12 mois','18 mois'];
			while(fsize.firstChild)
				fsize.removeChild(fsize.firstChild);
			if(sizes[product])
				{
				var option;
				for(var i=0; i<sizes[product].length; i++)
					{
					option=document.createElement('option');
					option.setAttribute('value', sizes[product][i]);
					option.setAttribute('label', sizes[product][i]);
					option.innerHTML=sizes[product][i];
					fsize.appendChild(option);
					}
				}
			}
		if(window.catalog)
			window.catalog.update();
		}
});

window.addEvent('domready', function() {
    new EditorDetector();
});
var editorManager = '';
