var currentURL = '';

function ajaxMenu(menuType, menuID) {
    if (menuType == 'category') {
        if ($('submenu'+menuID).innerHTML != '') {
            $('submenu'+menuID).innerHTML = '';
            return false;
        }
        new Ajax.Request('/ajaxmenu.html',
        {
            method:'get',
            parameters: {
                categoryid: menuID
            },
            onSuccess: function(transport){
                //alert(transport.responseText);
                $('submenu'+menuID).innerHTML = transport.responseText;
            },
            onFailure: function(){ alert('Ошибка ajax-меню.') }
        });
    } else {
        if ($('subvendor'+menuID).innerHTML != '') {
            $('subvendor'+menuID).innerHTML = '';
            return false;
        }
        new Ajax.Request('/ajaxmenu.html',
        {
            method:'get',
            parameters: {
                vendorid: menuID
            },
            onSuccess: function(transport){
                //alert(transport.responseText);
                $('subvendor'+menuID).innerHTML = transport.responseText;
            },
            onFailure: function(){ alert('Ошибка ajax-меню.') }
        });
    }
}

function ajaxMenu2(categoryID, vendorID, divID) {
    if ($(divID).innerHTML != '') {
        $(divID).innerHTML = '';
        return false;
    }
    new Ajax.Request('/ajaxmenu.html',
    {
        method:'get',
        parameters: {
            categoryid2: categoryID,
            vendorid2: vendorID
        },
        onSuccess: function(transport){
            $(divID).innerHTML = transport.responseText;
        },
        onFailure: function(){ alert('Ошибка ajax-меню.') }
    });
}

function ajaxPage(url) {
    $('ajaxcontentid').innerHTML = 'Загрузка...';
    new Ajax.Request(url, {
        method:'get',
        onSuccess: function(transport){
            currentURL = url;
            $('ajaxcontentid').innerHTML = transport.responseText;
            Effect.ScrollTo('ajaxcontentid');
        },
        onFailure: function(){ alert('Ошибка ajax-content.') }
    });

    return false;
}

/*-----------------------------------------------------------
Toggles element's display value
Input: any number of element id's
Output: none
---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
        d.style.display = 'block';
        else
        d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
Toggles tabs - Closes any open tabs, and then opens current tab
Input:     1.The number of the current tab
2.The number of tabs
3.(optional)The number of the tab to leave open
4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
Output: none
---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                    h.removeClassName('selected');
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                    Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 2}});
                    else
                    toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
        h.id = 'tabHeaderActive';
        h.toggleClassName('selected');
        h.blur();
        var c = $('tabContent'+num);
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 2}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}
