
function setIcons(trElement, icons){
    var tds = trElement.getElementsByTagName("td");

    for (var i = 0; i < tds.length-1; i++) {
        if (icons.length == 0) {
            htmlContent = '<!-- -->';
        } else {
            switch(icons[i][0]) {
                case 0:
                    htmlContent = '<span onmouseover="showIcoTooltip(this, ' + icons[i][1] + ')" onmouseout="hideIcoTooltip(this, 0)" class="ico-table ico-erfullt"><!-- --></span>';
                    break;

                case 1:
                    htmlContent = '<span onmouseover="showIcoTooltip(this, ' + icons[i][1] + ')" onmouseout="hideIcoTooltip(this, 1)" class="ico-table ico-erfullt-bracket"><!-- --></span>';
                    break;

                case 2:
                    htmlContent = '<span onmouseover="showIcoTooltip(this, ' + icons[i][1] + ')" onmouseout="hideIcoTooltip(this, 2)" class="ico-table ico-bedingt-erfullt"><!-- --></span>';
                    break;

                case 3:
                    htmlContent = '<span onmouseover="showIcoTooltip(this, ' + icons[i][1] + ')" onmouseout="hideIcoTooltip(this, 3)" class="ico-table ico-nicht-erfullt"><!-- --></span>';
                    break;
            }
        }
        if (typeof(tds[i + 1]) != 'undefined') {
            $(tds[i + 1]).find(".ico-box").html(htmlContent);
        }
    }
}

function showIcoTooltip(icoElement, tooltipReference) {
    $(icoElement).parent().parent().find(".ico-info-box-content").html(tooltipIcons[tooltipReference]);
    $(icoElement).parent().parent().find(".ico-info-box").show();
}

function hideIcoTooltip(icoElement, tooltipReference) {
    $(icoElement).parent().parent().find(".ico-info-box").hide();
}

function calculateIcons(selectElement) {
    setIcons(selectElement.parentNode.parentNode, eval(selectElement.value));
}

function disableButtons(selector) {
    /*$(selector).bind("click",function(){return false;}).addClass("disabled-button");*/
    $(selector).addClass("disabled-button");
}

function checkIconRows(tableId) {
    var options = [];
    var emptyField = true;

    $("#" + tableId + " select").each(function(){
        options.push(eval(this.value));
    });

    for (var i = 0; i < options.length; i++) {
        if (options[i].length != 0) {
            emptyField = false;
            break;
        }
    }

    if (emptyField) {
        disableButtons("#" + tableId + " .button-green");
    } else {
        /*$("#" + tableId + " .button-green").unbind("click").removeClass("disabled-button");*/
        $("#" + tableId + " .button-green").removeClass("disabled-button");
        $("#" + tableId + " td .ico-table").removeClass("disabled-cell");

        var totalColumns = $("#" + tableId + " td").length;

        for (var x = 0; x < totalColumns; x++) {
            for (var i = 0; i < options.length; i++) {
                if (typeof(options[i][x]) != "undefined" && options[i][x][0] == 3) {
                    disableButtons("#" + tableId + " .button-green:eq(" + x + ")");

                    $("#" + tableId + " tbody tr").each(function(){
                        $(this).find("td:eq(" + (x + 1) + ") .ico-table").addClass("disabled-cell");
                    });
                    
                    break;
                }
            }
        }
    }
    
    if ($("#" + tableId + " .disabled-button").length == 5) {
        openallColumnsDisabledPopup();
    }
}

function showBlock(choosenItem, obj) {
	if (choosenItem) {
        $('.btn').removeClass('btn-selected');
        $(obj).addClass('btn-selected');
		$('.blockList').hide();
		$('#blockList' + choosenItem).show();
	} else {
		$('.blockList').hide();
		$('#blockList0').show();
	}
}

function showListSubItem(linkObject){
    $('.showBlockList').show();
    $('.blockListSubItem').hide();
    $(linkObject).prev('.blockListSubItem').show();
    $(linkObject).hide();
}
