function timeDelayHideLoading()
{
	setTimeout("hideLoading()",1000);
}
function showLoading(){
    document.getElementById("show_loading_img").innerHTML="<img src='../design/loading.gif'/>";
}
function hideLoading(){
    document.getElementById("show_loading_img").innerHTML="";
}
$(document).ready(function() {
    /***************************************************************************
     * RECHERCHE D'INGREDIENTS
     **************************************************************************/
    var i = 0;
    $('input[name=ingredient]')
    .autocomplete("/_ajax/recette/recette_ingredient_compose_search.php", {
        autoFill: false,
        selectFirst : true,
        matchContains: true,
        delay: 1000,
        minChars: 1,
        max: 30,
        formatItem: function(row) {
            return row[0];
        }
        /*
        formatItem: function(row) {
            return row[0] + " (id: " + row[1] + ")";
        }*/
    })
    .result(function(event, data, formatted) {
        $tone.log('Autocomplete result: '+data[0]+','+data[1]);
        ingredientManager.ajouter(data[0], data[1]);
    });    
    
    
    /*
    $('a').click(function() {
        return confirm('Vous n\'avez pas enregistré vos modifications.\nEtes-vous sûr de vouloir quitter ?');
    });
    */
    
    
    /***************************************************************************
     * VALIDATION DU FORMULAIRE
     **************************************************************************/
    $('form[name=form-ingredient]').submit(function() {
        $('#recap_ingredient > tr.ko').each(function() {
            var id = $(this).attr('id');
            var num_ingredient = id.substr(id.lastIndexOf('_')+1);
            ingredientManager.confirmer(num_ingredient);
        });
        
        if($('#recap_ingredient > tr').size() == 0) {
            window.scrollTo(0,0);
            alert('Vous devez indiquer au moins 1 ingrédient pour votre recette');
            return false;
        }
        if($('#recap_ingredient > tr.ko').size() != 0) {
            window.scrollTo(0,0);
            alert('Vous devez donner les précisions nécessaires à l\'enregistrement des ingrédients');
            return false;
        }
        return true;
    });
    
    
});

