﻿function Podyplomowe_show() {
    if ($("#LoadInfo").css("visibility") == 'visible') return null;
    Load_info();
    $.ajax({
        data: {},
        dataType: 'html',
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("Operacja nie została wykonana.");
            $("#LoadInfo").css("visibility", "hidden");
        },
        success: function(data) {
            $("#Panel").attr('innerHTML', data);
            Szw_podypl_select(0);
            //RemoveItemAll();
            //JSonToListBox();
            $("#LoadInfo").css("visibility", "hidden");
            $("#Panel_rkl").css('visibility', 'hidden');
            ShowPanel_menu_list();
        },
        url: "szw_podypl",
        cache: false
    });
}

function Set_studia_podyplomowe_porcja_stron() {
    JObj_cfg.studia_podyplomowe_porcja_stron = $("#view_str option:selected").val();
    Szw_podypl_select(1);
}

function Szw_podypl_select(startRow) {
    if (startRow == '-1') {
        startRow = $("#numer_strony").attr('value');
    }
    Load_info();
    $.ajax({
        data: { search: $("#tbSearch").attr('value'), strona: startRow,
            studia_podyplomowe_porcja_stron: JObj_cfg.studia_podyplomowe_porcja_stron
        },
        dataType: 'JSON',
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("Operacja nie została wykonana.");
            $("#LoadInfo").css('visibility', 'hidden');
        },
        success: function(data) {
            var str_start = 0;
            var str_end = 0;
            var jsonObj = eval("(" + data + ")");
            if (jsonObj.Ilosc_stron > 11) {
                if (jsonObj.Numer_strony <= 6) {
                    str_start = 1;
                    str_end = 11;
                }
                else {
                    str_start = jsonObj.Numer_strony;
                    str_end = jsonObj.Numer_strony + 10;
                }
            }
            else {
                str_start = 1;
                str_end = jsonObj.Ilosc_stron;
            }

            if (str_start < 0) {
                str_start = 0;
                str_end = 11;
            }
            if (str_end >= jsonObj.Ilosc_stron) {
                str_end = jsonObj.Ilosc_stron;
                str_start = str_end - 11;
                if (str_start < 0) str_start = 1;
            }
            if (jsonObj.Ilosc_stron > 1) {
                var inner = '<table id="studia" style="width: 100%;"><tbody  id="tbody_podypl">';
                for (i = 0; i < jsonObj.Lista_podyplomowe.length; i++) {
                    inner += '<tr style="cursor:pointer;" onclick="Grid_Selected(this);" ondblclick="AddItem();"><td>';
                    inner += '<input type="hidden" name="kier_id" id="' + jsonObj.Lista_podyplomowe[i].ID + '" value="' + jsonObj.Lista_podyplomowe[i].NAZWA + '" />' + jsonObj.Lista_podyplomowe[i].NAZWA;
                    inner += '</td></tr>';
                }
                inner += '</tbody></table>';
                $("#div_tbl_studia").attr('innerHTML', inner);
                var innerPaging = '<table width="100%"><tr valign="middle"><td width="90%" align="center">';

                innerPaging += '<a href="#" onclick="Szw_podypl_select(1);"><<</a>&nbsp;';
                if (jsonObj.Numer_strony > 1)
                    innerPaging += '&nbsp;<a href="#" onclick="Szw_podypl_select(' + (jsonObj.Numer_strony - 1) + ');"><</a>&nbsp;';
                else
                    innerPaging += '&nbsp;<&nbsp;';
                for (i = str_start; i <= str_end; i++) {
                    if (i == jsonObj.Numer_strony)
                        innerPaging += '<b>' + (jsonObj.Numer_strony) + '</b>';
                    else
                        innerPaging += '<a href="#" onclick="Szw_podypl_select(' + (i) + ');">' + (i) + '</a>&nbsp;';
                }
                if (jsonObj.Ilosc_stron > 11) {
                    innerPaging += '&nbsp;<a href="#" onclick="Szw_podypl_select(-1);">przejdź do</a>&nbsp;';
                    innerPaging += '<input id="numer_strony" type="text" value="" style="width:25px;"/>&nbsp; z ' + jsonObj.Ilosc_stron + '&nbsp;';
                }
                if (jsonObj.Numer_strony < jsonObj.Ilosc_stron)
                    innerPaging += '&nbsp;<a href="#" onclick="Szw_podypl_select(' + (jsonObj.Numer_strony + 1) + ');">></a>&nbsp;';
                else
                    innerPaging += '&nbsp;>&nbsp;';

                innerPaging += '&nbsp;<a href="#" onclick="Szw_podypl_select(' + jsonObj.Ilosc_stron + ');">>></a>&nbsp;';
            } else {
                var inner = '<table id="studia" style="width: 100%;"><tbody>';
                for (i = 0; i < jsonObj.Lista_podyplomowe.length; i++) {
                    inner += '<tr style="cursor:pointer;" onclick="Grid_Selected(this);" ondblclick="AddItem();"><td>';
                    inner += '<input type="hidden" name="kier_id" id="' + jsonObj.Lista_podyplomowe[i].ID + '" value="' + jsonObj.Lista_podyplomowe[i].NAZWA + '" />' + jsonObj.Lista_podyplomowe[i].NAZWA;
                    inner += '</td></tr>';
                }
                inner += '</tbody></table>';
                $("#div_tbl_studia").attr('innerHTML', inner);
                var innerPaging = '<table width="100%"><tr valign="middle"><td width="90%" align="center">ilość znalezionych rekordów: ' + jsonObj.Lista_podyplomowe.length;
            }
            innerPaging += '</td><td width="10%" align="right"><select id="view_str" size=1 style="cursor:pointer;" onchange="Set_studia_podyplomowe_porcja_stron();">';
            innerPaging += '<option value="20">20</option>';
            innerPaging += '<option value="50">50</option>';
            innerPaging += '<option value="100">100</option>';
            innerPaging += '<option value="0">wszystkie</option>';
            innerPaging += '</select></td></tr></table>';

            $("#szw_kk_strona").attr('innerHTML', innerPaging);
            $("#view_str").val(JObj_cfg.studia_podyplomowe_porcja_stron);
            $("#LoadInfo").css('visibility', 'hidden');
            Disabled("dodaj", "../../content/image/minfo/dodaj_disabled.jpg");
            $("#tbSearch").focus();
            Set_buttonWyczysc();

            //zabezpieczenie przed zaznaczaniem
            if (IsIE() != true) {
                var elem = document.getElementById('tbody_podypl');
                elem.onmousedown = function(e) {
                    return false;
                } 
            }
        },
        url: "szw_podypl_select",
        cache: false
    });
}

function Wyczysc_podyplomowe() {
    if ($("#btWyczysc").css("cursor") != "default") {
        $("#tbSearch").attr("value", "");
        Szw_podypl_select(1);
    }
}
