
var gCategoriesMenuTimeOutId;
var gElement;
// var gFirstLevelCategoryId;
// var gFirstLevelCategoryName;
// var gThemeId;

Event.observe(window, 'load', function(event) {

    if ($('submitFormSearchByKeywords')) {
        $('submitFormSearchByKeywords').observe('click', function(event) {
            Event.stop(event);
            $('formSearchByKeywords').submit();
        });
    }

    if ($('searchBlock')) {
        var categories = $('searchBlock').getElementsByClassName('searchCategoryButton');
        for (var i = 0; i < categories.length; i++) {
            $(categories[i]).observe('click', function(event) {
                Event.stop(event);
                var element = Event.findElement(event, 'input');
                var categoryId = parseInt(element.readAttribute('category_id'));
//                 gThemeId = parseInt(element.readAttribute('parent_category'));
//                 gFirstLevelCategoryName = element.readAttribute('value');
//                 var parentPos = Position.offsetParent($('categoriesContainer'));
                gElement = element;
                categoriesMenu(categoryId);
            });
        }
    }
    
    if ($('searchPicturesContainer')) {
        var pictures = $('searchPicturesContainer').getElementsByClassName('addToAlbum');
        for (var i = 0; i < pictures.length; i++) {
            $(pictures[i]).observe('click', addToAlbum);
        }
        var rateCommentLinks = $('searchPicturesContainer').getElementsByClassName('rateComment');
        for (var i = 0; i < rateCommentLinks.length; i++) {
            $(rateCommentLinks[i]).observe('click', function(event) {
                var element = Event.findElement(event, 'a');
                var pictureId = parseInt(element.readAttribute('picture'));
                var url = document.URL;
                var tmp = url.split('\/');
                var xprints = tmp[3];
                if (xprints != 'visualprint' && xprints != 'visualprints')
                    var url = '/'+xprints+'/visualprints/ajax/picture-details/id/' + pictureId;
                else
                    var url = '/visualprints/ajax/picture-details/id/' + pictureId;
                popupPictureDetails(url);
                Event.stop(event);
            });
        }
        var zoomLinks = $('searchPicturesContainer').getElementsByClassName('zoom');
        for (var i = 0; i < rateCommentLinks.length; i++) {
            $(zoomLinks[i]).observe('click', function(event) {
                var element = Event.element(event);
                var pictureId = parseInt(element.readAttribute('picture'));
                var url = '/visualprints/ajax/picture-details/id/' + pictureId;
                popupPictureDetails(url);
                Event.stop(event);
            });
        }
    }

    if ($('myAlbum')) {
        setRemovePictureListeners();
    }

    if ($('popupContent')) {
//             $(rateCommentLinks[i]).observe('scroll', function(event) {alert('scroll');})
    }

//     if ($('popupContent')) {
//             Event.observe(window, "scroll", function(event) {popupPosition(event);})
//             Event.observe(window, "resize", function(event) {popupPosition(event);})
//     }
});

addComment = function(event) {
    if ($('commentText')) {
        var comment = $('commentText').value;
        var pictureId = parseInt($('addToAlbum').readAttribute('picture'));
        var url = '/visualprints/ajax/save-comment'
        new Ajax.Request(url, {
            method: 'post',
            postBody: $H({comment: comment, pictureId: pictureId}).toQueryString(),
            onComplete: function(transport) {
                var commentsInnerHTML = transport.responseText;
                $('comments').update(commentsInnerHTML);
                $('commentOK').setStyle({display: 'block'});
                setTimeout(function () {
                  $('commentOK').setStyle({display: 'none'});
                }, 4000);
            }
        });
    } else {
        var title = Builder.node('p', {id: 'commentsTitle'}, translate("Saisissez votre commentaire :"));
        var textarea = Builder.node('textarea', {id: 'commentText'});
        $('commentsTitle').remove();
        $('commentsContainer').remove();
        $('comments').appendChild(title);
        $('comments').appendChild(textarea);
        $('commentText').focus();
    }
    Event.stop(event);
}

ratePicture = function(event) {
    var radioButtons = $('formRate').getElements();
    for (var i = 0; i < radioButtons.length; i++) {
        var button = radioButtons[i];
        if (button.checked) {
            var rate = parseInt(button.value);
            var pictureId = parseInt($('addToAlbum').readAttribute('picture'));
            var url = '/visualprints/ajax/rate-picture';
            new Ajax.Request(url, {
                method: 'post',
                postBody: $H({rate: rate, pictureId: pictureId}).toQueryString(),
                onComplete: function(transport) {
                    var spanRateInnerHTML = transport.responseText;
                    $('rate').replace(spanRateInnerHTML);
//                     var msg = Builder.node('span', {
//                         className: 'orange bold',
//                         id: 'rateOk'
//                     }, translate("Votre vote a été enregistré !"));
//                     $('rateOK').show();
                    $('rateOK').setStyle({display: 'block'});
                    setTimeout(function () {
                        $('rateOK').setStyle({display: 'none'});
                    }, 4000);
//                     new Effect.puff('rateOK');
                    button.checked = false;
                    var obj = $('picture' + pictureId);
                    var url = '/visualprints/ajax/update-picture-rating/pictureId/' + pictureId;
                    new Ajax.Request( url, {
                        method: 'get',
                        onComplete: function(transport) {
                        var searchPictureInnerHTML = transport.responseText;
                        obj.replace(searchPictureInnerHTML);}
                        });
                }
            });
            break;
        }
    }
    Event.stop(event);
}

popupPictureDetails = function(url) {
    var center3ColHeight = $('center3Col').getHeight();

    var popupBgHeight = center3ColHeight + 3;
    var popupHeight = center3ColHeight - 43;

    var popup = Builder.node('div', {id: 'popup'}, [
        Builder.node('div', {id: 'popupBackground', style: 'height: ' + popupBgHeight + 'px'}),
        Builder.node('div', {id: 'popupContent', style: 'height: ' + popupHeight + 'px;'}, [
            Builder.node('a', {id: 'popupClose', onclick: 'popupClose(event)'}),
            Builder.node('div', {id: 'popupAjaxContent'})
        ])
    ]);
    $('center3Col').appendChild(popup);
    new Ajax.Updater('popupAjaxContent', url, {
        method: 'get',
        onComplete: function() {
            setTimeout(function() { new Effect.ScrollTo('pageHeader'); }, 1000);
//                     if ($('popupContent')) {
//                             Event.observe(window, "scroll", function(event) {popupReposition(event, popupPositionTop());})
//                             Event.observe(window, "resize", function(event) {popupReposition(event, popupPositionTop());})
//                     }
        }
     });
}

popupClose = function(event) {
//     var pictureId = $('addToAlbum').readAttribute('picture');
    $('popup').remove();
//     new Effect.ScrollTo('picture' + pictureId);
    Event.stop(event);
}

// popupPositionTop = function(popupHeight, popupBgHeight) {
//     // recuperer le scrollY
//     var scrollY = 0;
//     if( typeof( window.pageYOffset ) == 'number' ) {
//       //Netscape compliant
//       scrollY = window.pageYOffset;
//     } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
//       //DOM compliant
//       scrollY = document.body.scrollTop;
//     } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
//       //IE6 standards compliant mode
//       scrollY = document.documentElement.scrollTop;
//     }
//     // recuperer la hauteur de la fenetre
//     var myHeight = 0;
//     if( typeof( window.innerWidth ) == 'number' ) {
//       //Non-IE
//       myHeight = window.innerHeight;
//     } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//       //IE 6+ in 'standards compliant mode'
//       myHeight = document.documentElement.clientHeight;
//     } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//       //IE 4 compatible
//       myHeight = document.body.clientHeight;
//     }
//     var popupHeight = popupHeight + 200;
//
//     var positionTop = scrollY + (myHeight - popupHeight)/2;
//
//     if (popupBgHeight+200 < positionTop + popupHeight)
//         var positionTop = popupBgHeight - popupHeight;
//     if (positionTop < 0)
//         var positionTop = 0;
//
//     return positionTop;
// }
//
// popupReposition = function(event, pos) {
//   if (document.all) {
//     $('popupContent').style.setAttribute("cssText","top:"+pos+";");
//   } else
//     {
//     $('popupContent').setAttribute("style","top:"+pos+";");
//   }
//     Event.stop(event);
// }

loadPictureDetails = function(event, pictureId) {
//     var element = Event.element(event);
//     var pictureId = parseInt(element.readAttribute('picture'));
    var url = document.URL;
    var tmp = url.split('\/');
    var xprints = tmp[3];
    if (xprints != 'visualprint' && xprints != 'visualprints')
        var url = '/'+xprints+'/visualprints/ajax/picture-details/id/' + pictureId;
    else
        var url = '/visualprints/ajax/picture-details/id/' + pictureId;
    new Ajax.Updater('popupAjaxContent', url, {method: 'get'});
    Event.stop(event);
}

addToAlbum = function(event) {
    $('pageBody').setStyle({
      cursor: 'wait'
    });
    var element = Event.element(event);
    var pictureId = parseInt(element.readAttribute('picture'));
    var pictureExists = false;
    var popupClosed = false;
    if ($('myAlbum')) {
        var pictures = $('myAlbum').getElementsByClassName('albumPicture');
        for (var i = 0; i < pictures.length; i++) {
            if (parseInt($(pictures[i]).readAttribute('picture')) == pictureId) {
                pictureExists = true;
                break;
            }
        }
    } else {
        var url = document.URL;
        var tmp = url.split('\/');
        var xprints = tmp[3];
        if (xprints != 'visualprint' && xprints != 'visualprints')
            var url = '/'+xprints+'/visualprints/ajax/update-right-col/setAlbum/1';
        else
            var url = '/visualprints/ajax/update-right-col/setAlbum/1';
        new Ajax.Updater('rightCol', url);
    }
    if (!pictureExists) {
        new Effect.BlindDown(element);
        if ($('picture_' + pictureId) == null) {
            var url = '/visualprints/ajax/add-to-album/id/' + pictureId;
            new Ajax.Updater('rightColContent', url, {
                method: 'get',
                onComplete: function() {
                    var nb = getNbPicturesInAlbum();
                    var nbMin = getNbMinPicturesInAlbum();
                    updateNbPicturesInAlbum(nb, nbMin);
                    showHideGoToStep4Button(nb, nbMin);
                    setRemovePictureListeners();
                    if (nb == nbMin) {
                        popupClosed = true;
                        popupClose(event);
                    }
                    if (nb == 1) {
//                         setEmptyAlbumListener(event);
                        var url = '/visualprints/ajax/update-right-col/setAlbum/1';
                        new Ajax.Updater('rightCol', url, {
                            method: 'get',
                            onComplete: function() {
                                $('emptyAlbum').observe('click', function(event) {
                                    Event.stop(event);
                                    var texte = translate("Êtes-vous sûr(e) de vouloir vider votre album ?");
                                    var response = !confirm(texte);
                                    if (response == false) {
                                        var url = '/visualprints/ajax/empty-session-vars/album/' + response + '/layout/true';
                                        new Ajax.Request(url, {
                                            method: 'get',
                                            onComplete: function () {

                                            },
                                            asynchronous: false
                                        });
                                        var url = document.URL;
                                        if (url.match(/choose-pictures$/)) {
                                            var tmp = url.split('\/');
                                            var xprints = tmp[3];
                                            if (xprints != 'visualprint' && xprints != 'visualprints')
                                                var url = '/'+xprints+'/visualprints/ajax/update-right-col/setAlbum/1';
                                            else
                                                var url = '/visualprints/ajax/update-right-col/setAlbum/1';
                                        } else {
                                            var tmp = url.split('\/');
                                            var xprints = tmp[3];
                                            if (xprints != 'visualprint' && xprints != 'visualprints')
                                                var url = '/'+xprints+'/visualprints/ajax/update-right-col';
                                            else
                                                var url = '/visualprints/ajax/update-right-col';
//                                             var url = '/visualprints/ajax/update-right-col';
                                        }
                                        new Ajax.Updater('rightCol', url, {
                                                          method: 'get',
                                                          onComplete: function () {
                                                              if ($('top20')) { setTop20Listeners(); }
                                                          }
                                        });
                                    }
                                    updateLeftCol();
                                });
                            },
                            asynchronous: false
                        });
                    }
                },
                asynchronous: false
            });
            updateLeftCol();
        }
    } else {
        alert(translate("Cette photo fait déja partie de votre album."));
    }
    if (!popupClosed && !element.hasClassName('addToAlbum')) {
        var nextpicture = parseInt($('nextPicture').readAttribute('nextpicture'));
        if (nextpicture > 0) {
            loadPictureDetails(event, nextpicture);
        } else {
            popupClose(event);
        }
    }
    Event.stop(event);
    $('pageBody').setStyle({
      cursor: 'default'
    });   
}

updateLeftCol = function () {
            var url = document.URL;
            var tmp = url.split('\/');
            var xprints = tmp[3];
            if (xprints != 'visualprint' && xprints != 'visualprints')
                var url = '/'+xprints+'/visualprints/ajax/update-left-col';
            else
                var url = '/visualprints/ajax/update-left-col';
            new Ajax.Request(url, {
                method: 'get',
                onSuccess: function(transport) {
                    var response = transport.responseText;
                    var tabTypes = eval('(' + response + ')');
                    var max = tabTypes[0];
                    for (i=1; i<=max; i++) {
                        var element = document.getElementById('cover'+i);
                       if (element) {
                            element.removeClassName('selectable');
                            if (tabTypes[i]=='selectable') {
                                element.addClassName('selectable');
                            }
                        }
                    }
                },
                asynchronous: false
            });
            
            
            // load prototip
            visualprintsTip();
            //         $JSON_array.='var tabimg'.$t.' = eval(\''.Zend_Json::encode($res1).'\');';

}

updateNbPicturesInAlbum = function(nb, nbMin) {
    $('nbPicturesInAlbum').update(nb);
    var nbMinPicturesToInsert = nbMin - nb;
    if (nbMinPicturesToInsert < 0) {
        nbMinPicturesToInsert = 0;
    }
    if ($('nbMinPicturesToInsertContainer')) {
        if (nbMinPicturesToInsert > 0) {
            $('nbMinPicturesToInsertContainer').setStyle({display: 'inline'});
            $('nbMinPicturesToInsert').update(nbMinPicturesToInsert);
        } else {
            $('nbMinPicturesToInsertContainer').setStyle({display: 'none'});
        }
    }
//     setRemovePictureListeners();
}

getNbPicturesInAlbum = function () {
    var url = '/visualprints/ajax/get-nb-pictures-in-album';
    var nbPicturesInAlbum = 0;
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(transport) {
            nbPicturesInAlbum = parseInt(transport.responseText);
        },
        asynchronous: false
    });
    return nbPicturesInAlbum;
}

getNbMinPicturesInAlbum = function () {
    var url = '/visualprints/ajax/get-nb-min-pictures-in-album';
    var nbMinPicturesInAlbum = 0;
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(transport) {
            nbMinPicturesInAlbum = parseInt(transport.responseText);
        },
        asynchronous: false
    });
    return nbMinPicturesInAlbum;
}

getPublicationTypeName = function() {
    var url = '/visualprints/ajax/get-publication-type-name';
    var publicationTypeName = new String();
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(transport) {
            publicationTypeName = transport.responseText;
        },
        asynchronous: false
    });
    return publicationTypeName;
}

showHideGoToStep4Button = function(nbPicturesInAlbum, nbMin) {
//     var nbMin = getNbMinPicturesInAlbum();
//     var publicationTypeName = getPublicationTypeName();
    if (/*nbPicturesInAlbum > 0 && */nbPicturesInAlbum >= nbMin/* && !$('goToStep4')*/) {
        $('goToStep4Button').className = 'orangeButton284x29';
        var url = document.URL;
        var tmp = url.split('\/');
        var xprints = tmp[3];
        if (xprints != 'visualprint' && xprints != 'visualprints') {
            $('goToStep4Button').href = '/' + xprints + '/visualprints/index/create-publication';
        } else {
            $('goToStep4Button').href = '/visualprints/index/create-publication';
        }
//         $('nbMinPicturesForPublication').remove();
//         if (publicationTypeName != '') {
//             <p id="goToStep4"><a href="/visualprints/index/calendar-poster" title="Créer votre calendrier poster" class="orangeButton284x29">Créer votre calendrier poster</a></p>
//             var a = Builder.node('a', {
//                 href: '/visualprints/index/create-publication',
//                 title: 'Créer votre' + ' ' + publicationTypeName,
//                 className: 'orangeButton284x29'
//             }, 'Créer votre' + ' ' + publicationTypeName);
//             var p = Builder.node('p', {id: 'goToStep4'});
//             p.appendChild(a);
//             $('searchBlock').appendChild(p);
//         }
    } else if (/*nbPicturesInAlbum <= 0*/nbPicturesInAlbum < nbMin /*&& $('goToStep4') *//*|| nbPicturesInAlbum < nbMin*/) {
        $('goToStep4Button').className = 'grayButton284x29';
        $('goToStep4Button').href = 'javascript:void(0);';
//         $('goToStep4').remove();
//         var p = Builder.node('p', [
//
//             ]);
//         $('searchBlock').appendChild(p);
    }
    return true;
}

setRemovePictureListeners = function() {
    var listElements = $('myAlbum').immediateDescendants();
    for (var i = 0; i < listElements.length; i++) {
//             var img = listElements[i].down();
//             new Draggable(img, {revert: true});
        var picture = listElements[i].down();
        $(picture).observe('dblclick', function(event) {
            var element = Event.element(event);
            Event.stop(event);
            var pictureId = parseInt(element.readAttribute('picture'));
            var url = '/visualprints/ajax/remove-picture/id/' + pictureId;
            new Ajax.Request(url, {
                method: 'get',
                onSuccess: function(transport) {
                    var response = transport.responseText;
                    if (response == 'OK') {
                        element.up().setStyle({backgroundImage: 'none'});
                        element.setAttribute('src', '/images/poof.gif');
                        var nb = getNbPicturesInAlbum();
                        var nbMin = getNbMinPicturesInAlbum();
                        updateNbPicturesInAlbum(nb, nbMin);
                        showHideGoToStep4Button(nb, nbMin);
//                         timeOut=setTimeout(function () { element.up().remove()}, 500);
                        new Effect.Opacity(element, { duration:2,
                                                      from:1,
                                                      to:0.5,
                                                      afterFinish: function() { element.up().remove();}
                                                    });
                    }
                },
                asynchronous: false
            });
            updateLeftCol();
        });
    }
//     clearTimeout(timeOut);
}

// categoriesMenu = function(categoryId) {
// categoriesMenu = function(categoryId, element) {
categoriesMenu = function(categoryId) {
    var url = '/visualprints/ajax/get-sub-categories/id/' + categoryId;
//     var tmp = element.readAttribute('id').split('_');
//     var originCategoryId = tmp[1];
//     var originCategoryId = categoryId;
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(transport) {
            var jsonObject = eval('(' + transport.responseText + ')');
            if ($('categoriesMenu')) {
                $('categoriesMenu').remove();
            }

            var ul = Builder.node('ul', {
                id: 'categoriesMenu',
                onmouseout: 'categoriesMenuOut()',
                onmouseover: 'categoriesMenuOver()'
            });

            var li = Builder.node('li', [
                Builder.node('a', {
                    href: 'javascript:void(0);',
                    onclick: "selectCategory(0, '" + addslashes(gElement.readAttribute('first_category_name')) + "', false)"
                }, '')
            ]);
            ul.appendChild(li);

            var nbSubCategories = jsonObject.length;
            if (nbSubCategories > 0) {
                for (var i = 0; i < nbSubCategories; i++) {
                    var category = jsonObject[i];
                    if (i == 0) {
                        if (category['parent_parent_id'] != gElement.readAttribute('theme_id')) {
                            var li = Builder.node('li', [
                                Builder.node('a', {
                                    href: 'javascript:void(0);',
                                    className: 'goBack',
                                    onclick: 'categoriesMenu(' + category['parent_parent_id'] + ')'
                                }, translate("Retour"))
                            ]);
                            ul.appendChild(li);
                        }
                        var li = Builder.node('li', [
                            Builder.node('a', {
                                href: 'javascript:void(0);',
                                onclick: "selectCategory(" + category['parent_id'] + ",'" + translate("Tout dans") + ' ' + addslashes(translate(category['parent_name_' + gLang])) + "', true)"
                            }, translate("Tout dans") + ' ' + translate(category['parent_name_' + gLang]))
                        ]);
                        ul.appendChild(li);
                    }
                    if (category['has_children'] == 'yes') {
                        var li = Builder.node('li', [
                            Builder.node('a', {
                                href: 'javascript:void(0);',
                                className: 'hasChildren',
                                onclick: 'categoriesMenu(' + category['id'] + ')'
                            }, translate(category['name_' + gLang]))
                        ]);
                        ul.appendChild(li);
                    } else {
                        var li = Builder.node('li', [
                            Builder.node('a', {
                                href: 'javascript:void(0);',
                                onclick: "selectCategory(" + category['id'] + ",'" + addslashes(translate(category['name_' + gLang])) + "', true)"
                            }, translate(category['name_' + gLang]))
                        ]);
                        ul.appendChild(li);
                    }
                }
            } else {
                // il n'y a pas de sous-catégories
//                 var parentName = $('btnCategory_' + originCategoryId).readAttribute('parent_name');
//                 if (!parentName)
                    var name = $('btnCategory_' + gElement.readAttribute('first_category_id')).readAttribute('first_category_name');
//                 else
//                     var name = parentName;
//                     name = name.replace(/Tout dans /g,"");
//                 var name = $('btnCategory_' + originCategoryId).readAttribute('title');
                var li = Builder.node('li', [
                    Builder.node('a', {
                        href: 'javascript:void(0);',
                        onclick: "selectCategory(" + gElement.readAttribute('first_category_id') + ",'" + translate("Tout dans") + ' ' + addslashes(name) + "', true)"
                    }, translate("Tout dans") + ' ' + name)
                ]);
                ul.appendChild(li);
            }
//             $('formSearchByCategories').down().appendChild(ul);
//             $('formSearchByCategories').down().down().setAttribute('category', category['parent_id']);
//             var ulHTML = '<ul id="categoriesMenu" onmouseout="categoriesMenuOut()" onmouseover="categoriesMenuOver()">' + ul.innerHTML + '</ul>';

//             new Insertion.After('btnCategory_' + originCategoryId, ulHTML);
//                $('ctrCategory_' + originCategoryId).appendChild(ul);
               $('categoriesContainer').appendChild(ul);
               $(ul).hide();
               Position.clone(gElement, ul, {setWidth: false, setHeight: false});
               $(ul).show();

//             $('category_' + originCategoryId).setAttribute('value',
//             element.setAttribute('category', category['parent_id']);
//             $('formSearchPictures').down().appendChild(ul);
//             $('formSearchPictures').down().down().setAttribute('category', category['parent_id']);
//             $(ul).hide();
//             new Effect.SlideRight(ul, {duration: 0.3});
        }
    });
}

categoriesMenuOut = function() {
    gCategoriesMenuTimeOutId = setTimeout(function () { $('categoriesMenu').hide() }, 1000);
}

categoriesMenuOver = function () {
    clearTimeout(gCategoriesMenuTimeOutId);
    $('categoriesMenu').show();
}

selectCategory = function(categoryId, categoryName, colorPink) {
    var name = categoryName;
    if (categoryName.length > 16 ) {
        name = categoryName.substring(0, 14) + '...';
    }
    if (colorPink) {
        gElement.removeClassName('orangeButtonSelect120x17');
        gElement.addClassName('pinkSelect120x17');
    } else {
        gElement.removeClassName('pinkSelect120x17');
        gElement.addClassName('orangeButtonSelect120x17');
    }
    $('hdnCategory_' + gElement.readAttribute('first_category_id')).setAttribute('value', categoryId);
//     if (categoryId == gElement.readAttribute('first_category_id')) {
//         $('btnCategory_' + gElement.readAttribute('first_category_id')).setAttribute('value', translate("Tout dans") + ' ' + gElement.readAttribute('first_category_name'));
//     } else {
        $('btnCategory_' + gElement.readAttribute('first_category_id')).setAttribute('value', name);
//     }
//                     name = name.replace(/Tout dans /g,"");
//     $('btnCategory_' + originCategoryId).setAttribute('parent_name', categoryName.replace(/Tout dans /g,""));
//     $('btnCategory_' + originCategoryId).innerHTML = name;
    $('categoriesMenu').remove();


}



