/**
 * @author Attila Kecsmar
 */
function wsTree(param){
	if (document.getElementById(param+'_ul')) {
		if (document.getElementById(param + '_ul').style.display == 'block') {
			document.getElementById(param + '_ul').style.display = 'none';
            document.getElementById(param).className = '';
		}
		else {
			document.getElementById(param + '_ul').style.display = 'block';
            document.getElementById(param).className = 'hover';
		}
	}
}

function compareCheck() {
    var c = 0, i = 0;
    do {
        box = eval('document.productlist.compare_' + i);
        if (box && box.checked) {
            c++;
        }
        i++;
    } while (box);
    i = 0;
    if (c < 2) {
        document.WebshopProductsSort.comparebutton.disable();
    } else {
        document.WebshopProductsSort.comparebutton.enable();
    }
    do {
        box = eval('document.productlist.compare_' + i);
        if (box && !box.checked) {
            if (c < 2) {
                box.enable();
            } else {
                box.disable();
            }
        }
        i++;
    } while (box);
}

function showOffersTabInner(id, secDelay) {
    var i = 0;
    do {
        li = document.getElementById('Offer' + i);
        if (li && (i == id)) {
            li.className = 'activeOffer';
        } else if (li) {
            li.className = '';
        }
        i++;
    } while (li);
    new Ajax.Request(
        path_current + '/ajax',
        {
            method: "post",
            parameters: {
                _action: 'productoffers_list ajax_loadtemplate',
                _template: 'productoffers/list_inner',
                wsoffer_id: offers[id]
            },
            onComplete: function(_oRequest) {
                $('WebshopOffersInner').innerHTML = _oRequest.responseText;
                Effect.Appear('WebshopOffersInner', { duration: secDelay });
            }
        }
    );
}

function showOffersTab(id) {
    var secDelay = 0.5;
    Effect.Fade('WebshopOffersInner', {duration: secDelay});
    setTimeout('showOffersTabInner(' + id + ',' + secDelay + ')', secDelay * 1000);
    return false;
}

function startCycleOffers() {
	cycleOffers(1);
}

function cycleOffers(id) {
	return;
    if (!cycle) {
        return;
    }
    if (offers.length <= id) {
        id = 0;
    }
    showOffersTab(id);
    id++;
    setTimeout(function(){cycleOffers(id);}, 10000);
}

/**
 * Toggle Product Search Box
 */
function toggleSearchBox() {
	newValue = $('WebshopSearch').style.display == 'none'?'block':'none';
	$('ShowSearchBoxControl').style.display = $('WebshopSearch').style.display;
	$('HideSearchBoxControl').style.display = newValue;
	$('WebshopSearch').style.display = newValue;
	return false;
}

function showSearchTab(_iId) {
    var secDelay = 0.25;
    var i = 1;
    var done = false;
    do {
        tab = document.getElementById('WebshopSearchGroup' + i);
        if (tab && (tab.style.display != 'none')) {
            Effect.Fade('WebshopSearchGroup' + i, { duration: secDelay });
            done = true;
        }
        menu = document.getElementById('SearchMenu' + i);
        if (menu) {
            menu.className = '';
        }
        i++;
    } while (!done && tab);
    setTimeout('Effect.Appear(\'WebshopSearchGroup' + _iId + '\', {duration:' + secDelay + '})', secDelay * 1000);
    $('SearchMenu' + _iId).className = 'activeMenu';
    return false;
}

