Event.observe(window,'load',initAjoutPanierObserver);
Event.observe(window,'load',initFormAjoutPanier);
Event.observe(window,'load',initFormProdAssoc);

function initAjoutPanierObserver()
{
	var matiereList = $('prodMatiereId');
	var urlPage = $F('urlPage');
	if(matiereList && urlPage)
	{
		
		var matiereValue= $F('prodMatiereId');
		Event.observe(matiereList,'change',updateMatiere);
	}
}

function updateMatiere(evt)
{
	var el = Event.element(evt);
	var matiereValue= $F(el.id);
	var matiereName = el.name;
	var urlPage = $F('urlPage');
	if(matiereValue != '')
	{
		var pos = urlPage.indexOf('?');
		if(pos != -1)
		{
			document.location=urlPage+'&'+matiereName+'='+matiereValue;
		}
		else
		{
			document.location=urlPage+'?'+matiereName+'='+matiereValue;
		}
	}
}

function initFormProdAssoc()
{
	Event.observe('listProdAssoc','change',function(){if(this.value != '') document.location=this.value;});
}

function initFormAjoutPanier()
{
	Event.observe('formAjoutPanier','submit',checkFormAjoutPanier);
}
function checkFormAjoutPanier(evt)
{
	var matiereId = $F('prodMatiereId');
	var tailleId = $F('prodTailleId');
	var produitId = $F('prodId');
	if(produitId == '')
	{
		alert('Ce produit est épuisé');
		Event.stop(evt);
	}
	var err = '';
	if(matiereId == '')
	{
		err += 'Veuillez renseigner la matière\n';
	}
	if(tailleId == '')
	{
		err += 'Veuillez renseigner la taille';
	}
	if(err)
	{
		alert(err);
		Event.stop(evt);
	}
}