// <![CDATA[

function show_hide_details(id) {
    var data_elem_name = "additional_data" + id;
    var img_elem_name = "block_arrow_img" + id;
    var elem_div = document.getElementById(data_elem_name);
    var elem_img = document.getElementById(img_elem_name);
    if (elem_div && elem_img) {
        var to_show = (elem_div.style.display == "none");
        elem_div.style.display = to_show ? "" : "none";
        elem_img.setAttribute("src", to_show ? "../images/arr_d.png" : "../images/arr_r.png");
    }
}

function show_hide_advanced(id) {
    var img_elem_name = "block_arrow_img" + id;
    var filters_elem_name = "additional_filters" + id;
    var filters_apply_name = "additional_filters_apply" + id;
    var main_filters_name = "main_filters" + id;

    var filter1 = "changeCategory";
    var filter2 = "changeUI";
    var filter3 = "changeSize";
    var filter4 = "changeLicense";
    var filter5 = "changeVendor";

    var elem_img = document.getElementById(img_elem_name);
    var elem_filters = document.getElementById(filters_elem_name);
    var elem_filters_apply = document.getElementById(filters_apply_name);
    var elem_main_filters = document.getElementById(main_filters_name);

    var elem_filter1 = document.getElementById(filter1);
    var elem_filter2 = document.getElementById(filter2);
    var elem_filter3 = document.getElementById(filter3);
    var elem_filter4 = document.getElementById(filter4);
    var elem_filter5 = document.getElementById(filter5);

    if (elem_img && elem_filters && elem_main_filters) {
        var to_show = (elem_filters.style.display == "none");
        elem_filters.style.display = to_show ? "" : "none";
        elem_filters_apply.style.display = to_show ? "" : "none";
        elem_img.setAttribute("src", to_show ? "../images/arr_d.png" : "../images/arr_r.png");

        elem_filter1.style.display = to_show ? "none" : "";
        elem_filter2.style.display = to_show ? "none" : "";
        elem_filter3.style.display = to_show ? "none" : "";
        elem_filter4.style.display = to_show ? "none" : "";
        elem_filter5.style.display = to_show ? "none" : "";
    }
}

var last_tooltip = '';
var tooltip_texts = new Array();
tooltip_texts['app_size'] = 'Applications can be classified as "Small", "Medium" and "Large", <br/> depending on the number of external interfaces they use: <ul><li>Small - less than 100 interfaces</li><li>Medium - from 100 to 999 interfaces</li><li>Large - 1000 and more interfacess</li></ul>';
tooltip_texts['app_license'] = 'Application licensing type: <ul><li>Open Source - completely open applications</li><li>Proprietary</li><li>Mixed - for products that have both open and proprietary versions</li></ul>';
tooltip_texts['app_ui'] = 'Application user interface kind - either GUI or non-GUI.';
tooltip_texts['app_vendor'] = 'Application vendor. <br/>Application vendor for standalone proprietary applications<br/> or distribution vendor for applications got from distribution packages.';
tooltip_texts['app_category'] = 'Application category. <br/>Categories are set on the basis of application functionality.';
tooltip_texts['count_rejected'] = 'Count elements that are not considered as LSB candidates.';
tooltip_texts['count_unofficial'] = 'Take into account unofficial distribution releases.';
tooltip_texts['referenced_spec'] = 'The document is referenced in the main element documentation.';
tooltip_texts['arch'] = 'Observe the data from a certain architecture point of view.';
tooltip_texts['lsbver'] = 'Observe the data from a certain LSB version point of view.';
tooltip_texts['distr_filt'] = 'Take into account only distributions with certain name.';
tooltip_texts['approved_cmd'] = 'Do we guarantee that we have correct information about this command in every distribution?';
tooltip_texts['approved_lib'] = 'Do we guarantee that we have correct information about this library in every distribution?';
tooltip_texts['search_limit'] = 'Limit number of search results for each category';

tooltip_texts['ft_phase_1'] = 'General state of the Identification phase - is it completed and were any issues discovered.';
tooltip_texts['ft_demand'] = 'Is there a sufficient demand for the component?';
tooltip_texts['ft_license'] = 'Is licensing policy ok?';
tooltip_texts['ft_best'] = 'Does the component represent the "best practice" for the problem it solves?';
tooltip_texts['ft_stable'] = 'Does the component have stable ABI?';
tooltip_texts['ft_depends'] = 'The runtime dependencies of the component should either already exist in the LSB, or abstracted away so that specifing their interfaces is not required.';
tooltip_texts['ft_phase_2'] = 'General state of the Investigation phase - is it completed and were any issues discovered.';
tooltip_texts['ft_rationale'] = 'The rationale for the why the component was added and for all parts of the specification should be recorded and published.';
tooltip_texts['ft_upstream'] = 'The upstream maintainers must be committed to backwards compatibility (for some defined version) and stability.';
tooltip_texts['ft_distros'] = 'The component maintainers for the distributors should be willing to work with on providing a standard everyone can agree on and adopt.';
tooltip_texts['ft_versions'] = 'The upstream maintainers, distributions, and developers should be synced up on compatible versions.';
tooltip_texts['ft_patches'] = 'Distribution-specific patches influencing component behavior should be taken in to account.';
tooltip_texts['ft_phase_3'] = 'General state of the Implementation phase - is it completed and were any issues discovered.';
tooltip_texts['ft_db'] = 'Is all necessary data imported to the database?';
tooltip_texts['ft_spec'] = 'Is written specification for the component is ready?';
tooltip_texts['ft_test'] = 'Does LSB provide any tests for this component?';
tooltip_texts['ft_devel'] = 'Does LSB SDK provides support for this component?';
tooltip_texts['ft_sample'] = 'Does LSB Sample Implementation contains this component?';
tooltip_texts['ft_appbat'] = 'Does LSB Application Battery contains applications touching this component?';

var just_shown_tooltip = false;

function show_hide_tooltip(id, event) {
    var tt_window = document.getElementById("tooltip");
    if (tt_window) {
        if (last_tooltip != id) {
            var tt_text = document.getElementById("tooltip_text");
            if (tt_text) {
                if (tooltip_texts[id])
                    tt_text.innerHTML = tooltip_texts[id] + '<br /><div align="right"><a href="../commons/help.php#' + id + '" onclick="javascript:hide_tooltip();"><i>Details...</i></a></div>';
                else
                    tt_text.innerHTML = '<font color="red"><em>Sorry, no information for this item was found!</em></font><br/>We would be glad to <a href="../commons/feedback.php">get information</a> about this accident.';
                var ScrollTop = document.body.scrollTop;
                if (ScrollTop == 0) {
                    if (window.pageYOffset)
                        ScrollTop = window.pageYOffset;
                    else
                        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
                }
                var ScrollLeft = document.body.scrollLeft;
                if (ScrollLeft == 0) {
                    if (window.pageXOffset)
                        ScrollLeft = window.pageXOffset;
                    else
                        ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
                }
                var div_top = event.clientY + ScrollTop + 20;
                var div_left = event.clientX + ScrollLeft + 10;
                tt_window.style.display = '';
                var div_width = (tt_window.style.pixelWidth || tt_window.offsetWidth);
                var wnd_width = (document.body.clientWidth || window.innerWidth);
                if (div_left + div_width > wnd_width)
                    div_left = wnd_width - div_width;
                tt_window.style.top = div_top + 'px';
                tt_window.style.left = div_left + 'px';
                last_tooltip = id;
                just_shown_tooltip = true;
            }
        }
        else {
            tt_window.style.display = 'none';
            last_tooltip = '';
        }
    }
}

function hide_tooltip() {
    var elem = document.getElementById("tooltip");
    if (elem) {
        elem.style.display = 'none';
        last_tooltip = '';
    }
}

function toggle_table(id) {
    var img_elem_name = "expand-img" + id;
    var elem_img = document.getElementById(img_elem_name);
    var tbl = document.getElementById('ft_table');
    var rows = tbl.getElementsByTagName('tr');
    var start_id=4;
    var max_id = 9;
    if( id == '2' ) {
        start_id=10;
        max_id = 15;
    }
    else if( id == '3' ) {
        start_id=16;
        max_id = 22;
    }

    if (elem_img) {
        var img_src = elem_img.getAttribute('src');
        var to_show = (img_src == "../images/status_expand.png");

        if (to_show) {
            elem_img.setAttribute('src', '../images/status_collapse.png');
            elem_img.setAttribute('alt', '[&lt;&lt;]');
        }
        else {
            elem_img.setAttribute('src', '../images/status_expand.png');
            elem_img.setAttribute('alt', '[&gt;&gt;]');
        }
    }

    for (var row=0; row<rows.length;row++) {
        var tds = rows[row].getElementsByTagName('td');
        if( tds[max_id-2] ) {
            cur_max_id = max_id-2;
            cur_start_id = start_id-2;
            if( to_show ) {
                for (var pos=cur_start_id+1; pos<=cur_max_id; pos++) {
                    tds[pos].style.display = "";
                }
                tds[cur_start_id].style.display = "none";
            }
            else {
                for (var pos=cur_start_id+1; pos<=cur_max_id; pos++) {
                    tds[pos].style.display = "none";
                }
                tds[cur_start_id].style.display = "";
            }
        }
        else {
            var ths = rows[row].getElementsByTagName('th');
            if( ths[max_id] ) {
                if( to_show ) {
                    for (var pos=start_id+1; pos<=max_id; pos++) {
                        ths[pos].style.display = "";
                    }
                    ths[start_id].style.display = "none";
                }
                else {
                    for (var pos=start_id+1; pos<=max_id; pos++) {
                        ths[pos].style.display = "none";
                    }
                    ths[start_id].style.display = "";
                }
            }
        }
    }

    var data_elem_name = "phase" + id;
    var elem_data = document.getElementById(data_elem_name);
    var colspan = to_show ? 9 : 5;
    if( id == '2' ) {
        var colspan = to_show ? 5 : 1;
    }
    else if( id == '3' ) {
        var colspan = to_show ? 6 : 1;
    }
    elem_data.setAttribute('colspan', colspan);

}

function check_all_distros(allvers) {
    var elem = document.getElementById('check-all-distros' );
    if (elem) {
        var checked = elem.checked;

        var boxes = document.getElementsByName('SelectDistr[]');

        for (var box_idx=0; box_idx<boxes.length;box_idx++) {
            box = boxes[box_idx];
            if( checked ) {
                box.checked = true;
            }
            else {
                box.checked = false;
            }
        }

        var latest_elem = document.getElementById('check-latest-distros' );
        if( latest_elem ) {
            if( checked ) {
                latest_elem.checked = true;
            }
            else {
                latest_elem.checked = false;
            }
        }

        for(var other_ver in oc(allvers)) {
            var latest_elem = document.getElementById('check-'+other_ver+'-distros' );
            if( latest_elem ) {
                if( checked ) {
                    latest_elem.checked = true;
                }
                else {
                    latest_elem.checked = false;
                }
            }
        }

    }
}

//~ make hash with empty values from plain array
function oc(a)
{
    var o = {};
    for(var i=0;i<a.length;i++) {
        o[a[i]]='';
    }
    return o;
}

function check_custom_distros(latest_distros,ver,allvers) {
    var elem;
    if( ver != '' ) {
        elem = document.getElementById('check-'+ver+'-distros' );
    }
    else {
        elem = document.getElementById('check-latest-distros' );
    }

    if (elem) {
        var checked = elem.checked;

        var boxes = document.getElementsByName('SelectDistr[]');

        for (var box_idx=0; box_idx<boxes.length;box_idx++) {
            box = boxes[box_idx];
            if( box.value in oc(latest_distros) ) {
                if( checked ) {
                    box.checked = true;
                }
                else {
                    box.checked = false;
                }
            }
        }

        //~ If we uncheck some flag, then let's uncheck all of them
        if (!checked) {
            if( ver != '' ) {
                var other_elem = document.getElementById('check-all-distros' );
                if( other_elem ) {
                    other_elem.checked = false;
                }

                other_elem = document.getElementById('check-latest-distros' );
                if( other_elem ) {
                    other_elem.checked = false;
                }

                for(var other_ver in oc(allvers)) {
                    if( ver != other_ver ) {
                        other_elem = document.getElementById('check-'+other_ver+'-distros' );

                        if( other_elem ) {
                            other_elem.checked = false;
                        }
                    }
                }
            }
            else {
                var other_elem = document.getElementById('check-all-distros' );
                if( other_elem ) {
                    other_elem.checked = false;
                }

                for(var other_ver in oc(allvers)) {
                    other_elem = document.getElementById('check-'+other_ver+'-distros' );

                    if( other_elem ) {
                        other_elem.checked = false;
                    }
                }
            }
        }

    }
}

// ]]>

