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 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', 600, 580 );
}

// window.addEvent('domready', function (){    
     // $$('.multiselect').each(function(multiselect){
        // new MTMultiWidget({'datasrc': multiselect});
    // });
// });


function showDetails() {
    var slides = [];
    if( $$('.details') ) {
        $$('.details').each( function( el, index ) {
            slides[index] = new Fx.Slide( el, { wait : true} ).hide();
        } );
        $$('.linkdetails').each( function( el, index ) {
            el.addEvent('click', function( e ) {
                var e = new Event( e ).stop();
                if( slides[index] ) {
                    slides[index].toggle();
                }
            });
        });
    }
}
window.addEvent('domready', function() {
    showDetails();
});

// Hightlight text
function fHighLightText() {
    if( $$('.fhighlight') ) {
        $$('.fhighlight').each( function( el, index ) {
            el.addEvent( 'click', function( e ) {
                var e= new Event( e ).stop();
                el.focus();
                el.select();
            });
        });
    }
}
window.addEvent('domready', function() {
    fHighLightText();
});

// remplace la fonction maxLengthTextarea
function limite(textarea, max, count)
{
    if(textarea.value.length >= max)
    {
        textarea.value = textarea.value.substring(0,max);
    }
    var reste = max - textarea.value.length;
    var affichage_reste =  reste;
    document.getElementById(count).innerHTML = affichage_reste;
}
