function fDelete(){
	$$('.fDelete').each(function(el){
		el.addEvent('click', function(e){
			e = new Event(e);
			if( !confirm(el.title ? el.title : 'Etes vous sûr de vouloir supprimer cet élément ?')){
				e.stop();
			}
		});
	});
}

function fFlashMessage() {
	new mooFlashMessage($$('.flash'));
}

function fInit(){
	fDelete();
	fFlashMessage();
}
window.addEvent('domready', fInit);


function addBottles (nomChamp,  cndcols) {
	if(nomChamp) {
			var qte = parseInt(document.getElementById(nomChamp).value);
			document.getElementById(nomChamp).value = qte+parseInt(cndcols);
		}
}


function substractBottles ( nomChamp, cndcols){
	if(nomChamp) {
		var qte = parseInt(document.getElementById(nomChamp).value);
		if (parseInt(cndcols)==1 && qte <= 1){
			qte = 1;
		}else 
			if (parseInt(cndcols)==6 && qte <= 6){
				qte = 6;
			}else{
			qte-=parseInt(cndcols);
		}
		document.getElementById(nomChamp).value = qte;
	}
}


function ajoutPanier(nomChamp,  cndcols){
	addBottles (nomChamp,  cndcols);
	document.panier.submit();
}



function substractPanier(nomChamp,  cndcols){
	substractBottles (nomChamp,  cndcols);
	document.panier.submit();
}

function popup( href, name, h, l ) {
	var hauteur = Math.round( ( screen.availHeight - h ) / 2 );
	var largeur = Math.round( ( screen.availWidth - l ) / 2 );
	var popup = window.open( href, name, 'toolbar=0,location=0,directories=0,status=0, scrollbars=1,resizable=1,menubar=0,top='+hauteur+',left='+largeur+',width='+l+',height='+h);
	popup.focus();
	return false;	
}

function popupOrder( Obj ) {
	return popup( Obj.href, 'order', 700, 580 );
}

function popupInvoice(Obj) {
	return popup(Obj.href, 'invoice', 700, 580);
}


function del( Obj ) {
	var label = ( Obj.title ) ? Obj.title : 'Etes vous sûr de vouloir supprimer cet élément ?';
	return confirm( label );	
}


// formulaire primeur
// ajout d'une ligne dans le tableau
function addformlinePrimeur() {
	var nbLine = parseInt($('nbformline').getValue());
	if( $('addformbottle') ) {
		$('addformbottle').addEvent('click', function(e){
			var e = new Event(e);
			e.stop();
			nbLine = nbLine + 1;
			//alert(nbLine );
			//$('nbformline').setText(nbLine);
			
			$('nbformline').setProperty('value', nbLine);
			
			var new_tr = new Element( 'div' ).injectInside($('test')) ; // creation tr
			
			
			//var new_tr = new Element( 'tr' ) ; // creation tr
			//$(new_tr).injectInside($('formprimeurvin'));
			
			new Ajax('addformprimeur.php', {
				method: 'get',
				data: 'line='+nbLine,
				update: new_tr
				// onComplete: function() {
				// }
			}).request();
		});
	}
}
window.addEvent('domready', function() {
	if( $('formprimeurvin') ) {
		addformlinePrimeur();
	}
});
