// #################### Parametry
// Autor: bert, bert@petrus.pl
// Data utworzenia: 2003-08-20, 21:29:17
// Data ostatniej modyfikacji: 2003-10-22, 16:40:36
// Przydatne funkcje JS.

var d = document;

function MM_findObj(n, d){
    var p, i, x;
    if(!d) d = document; 
    if((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; 
        n = n.substring(0,p);
    }
    if(!(x = d[n]) && d.all) x = d.all[n]; 
    for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for(i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if(!x && d.getElementById) x = d.getElementById(n);
    return x;
}

function MM_showHideLayers(){
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for(i = 0; i < (args.length-2); i += 3){
        if((obj = MM_findObj(args[i])) != null){
            v = args[i + 2];
            if(obj.style){
                obj = obj.style;
                v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v;
            }
            obj.visibility = v;
        }
    }
}

function MM_swapImage(){
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for(i = 0; i < (a.length - 2); i+=3){
        if ((x = MM_findObj(a[i])) != null){
            document.MM_sr[j++] = x;
            if(!x.oSrc) x.oSrc = x.src;
            x.src = a[i + 2];
        }
    }
}

function MM_swapImgRestore(){
    var i, x, a=document.MM_sr;
    for(i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src=x.oSrc;
}

function MM_preloadImages(){
    if(d.images){ 
        if(!d.imgs) d.imgs = new Array();
        var i, j = d.imgs.length, a = MM_preloadImages.arguments;
        for(i = 0; i < a.length; i++){
            if (a[i].indexOf("#") != 0){ 
                d.imgs[j] = new Image;
                d.imgs[j++].src = a[i];
            }
        }
    }
}

function VB_innerHTML(div, txt){
    if((obj = fObj(div)) != null){
        with(navigator){
            if((appName == "Netscape") && (parseInt(appVersion) == 4)){
                with(obj.document){
                    write(txt);
                    close();
                }
            }
            else{
                obj.innerHTML = txt;
            }
        }
    }
}

function VB_focus() {
    var amax = document.links.length;
    for(var a = 0; a < amax; a++) {
        d.links[a].onfocus = d.links[a].blur;
    }
}

function VB_favorite(){ window.external.AddFavorite(window.document.location.href, window.document.title); }

function VB_set_x(win_w) {
    var scr_w = screen.width;
    return Math.floor((scr_w - win_w) / 2);
}

function VB_set_y(win_h) {
    var scr_h = screen.height;
    return Math.floor((scr_h - win_h) / 2);
}

function VB_new_win(url,w,h) {
    var w = (w || 410);
    var h = (h || 270);
    var l = VB_set_x(w);
    var t = VB_set_y(h);
    var op = '';
    op += "toolbar=0, menubar=0, scrollbars=0, resizable=1, status=0, location=0, directories=0, ";
    op += "height=" + h + ", width=" + w + ", left=" + l + ", top=" + t;
    window.open(url,"",op);
}

function VB_new_win_(url,w,h) {
    var w = (w || 410);
    var h = (h || 270);
    var l = VB_set_x(w);
    var t = VB_set_y(h);
    var op = '';
    op += "toolbar=0, menubar=0, scrollbars=1, resizable=0, status=0, location=0, directories=0, ";
    op += "height=" + h + ", width=" + w + ", left=" + l + ", top=" + t;
    window.open(url,"",op);
}

function VB_zoom(foto,W,H,T){
    var z = "";
    var w = W + 15;
    var h = H + 50;
    var l = VB_set_x(w);
    var t = VB_set_y(h);
    var title = T;
    var tytul = "Agroma Sp. z o.o.";
    var opcje  = "toolbar=0,menubar=0,scrollbars=0,resizable=0,status=0,location=0,directories=0,";
        opcje += "height=" + h + ",width=" + w + ",left=" + l + ",top=" + t;
    var newz = window.open("", "", opcje);
    z += "<html>\n<head>\n<meta http-equiv=\"Content-type\" content=\"text/html; charset=iso-8859-2\">\n<title>";
    z += tytul + "</title>\n";
    z += "<link rel=\"stylesheet\" href=\"css/zoom.css\" type=\"text/css\">\n</head>\n";
    z += "<body>\n";
    z += "<table align=CENTER valign=TOP width=" + W + " cellspacing=3 cellpadding=0 border=0>\n";
    z += "<th align=right valign=middle width=" + W + ">" + title + "</th>\n</tr>\n";
    z += "<tr><td align=CENTER><a href=\"javascript:;\" onclick=\"window.parent.close()\" title=\" Zamknij to okno ... \">";
    z += "<img src=\"" + foto + "\" width=" + W + " height=" + H + " border=0>";
    z += "</a></td></tr></table></body></html>";
    newz.document.write(z);
    newz.focus();
}

function VB_close(){ window.close(); }

function VB_close_refresh(){
    window.opener.location.reload();
    window.close();
}

function VB_top() { window.scrollTo(0,0); }

function VB_back() { window.history.back(); }

function VB_replace_url(url){ window.location.replace(url); }

function VB_go_to_url(url){ eval("document.location.href = '" + url + "'"); }

// Zmiana class objektu.

var tab_click = new Array;
var tab_css = new Array;
var prefix_id = new Array;

function VB_set_css(new_css_id, new_css_out, new_css_over, new_css_down, new_css_up, new_css_curr) {
    tab_css[new_css_id] = new Array;
    tab_css[new_css_id][0] = new_css_out;
    tab_css[new_css_id][1] = new_css_over;
    tab_css[new_css_id][2] = new_css_down; // and focus and click
    tab_css[new_css_id][3] = new_css_up; // and blur
    tab_css[new_css_id][4] = new_css_curr; // aktualnie wybrana pozycja
}

function VB_set_prefix_id(css_id, new_prefix) {
    if(new_prefix) { prefix_id[css_id] = new_prefix; }
    else { prefix_id[css_id] = 'id'; }
}

function VB_change_class(css_id, obj_id, obj_action) {
    //var obj = (d.all ? d.all[prefix_id + obj_id] : d.getElementById(prefix_id + obj_id));
    var obj = MM_findObj(prefix_id[css_id] + obj_id);
    if (typeof(obj) != 'undefined') {
        switch(obj_action) {
            case 0: // out
                obj.className = tab_css[css_id][0]; break;
            case 1: // over
                obj.className = tab_css[css_id][1]; break;
            case 2: // down
                obj.className = tab_css[css_id][2]; break;
            case 3: // up
                obj.className = tab_css[css_id][3]; break;
            case 4: // curr
                obj.className = tab_css[css_id][4]; break;
            default: 
                obj.className = tab_css[css_id][0]; break;
        }
    }
}

function VB_change_class_ext(obj_id, obj_action) {
    //var obj = (d.all ? d.all[prefix_id + obj_id] : d.getElementById(prefix_id + obj_id));
    var obj = MM_findObj(prefix_id + obj_id);
    if (typeof(obj) != 'undefined') {
        switch(obj_action) {
            case 0: // out
                if (tab_click[obj_id]) { obj.className = tab_css[2]; }
                else { obj.className = tab_css[0]; } break;
            case 1: // over
                if (tab_click[obj_id]) { obj.className = tab_css[2]; }
                else { obj.className = tab_css[1]; } break;
            case 2: // focus || click
                var num = tab_click.length;
                obj.className = tab_css[2];
                for (var i = 0; i < num; i++) { tab_click[i] = null; }
                tab_click[obj_id] = true; break;
            case 3: // blur
                if (tab_click[obj_id]) { tab_click[obj_id] = null; }
                obj.className = tab_css[0]; break;
            default:
                obj.className = tab_css[0];
                for (var i = 0; i < num; i++) { tab_click[i] = null; } break;
        }
    }
}

// Zmiana koloru wiersza tabeli
var marked_row = new Array;
var colors_row = new Array;

function VB_set_colors_row(default_color, over_color, mark_color) {
    colors_row[0] = default_color;
    colors_row[1] = over_color;
    colors_row[2] = mark_color;
}

function VB_set_color_row(obj_row, nr_row, _action) { // _action { 0 - over, 1 - click, 2 - out }
    var obj_cells = null;

    if ((colors_row[1] == '' && colors_row[2] == '') || typeof(obj_row.style) == 'undefined') { return false; }

    if (typeof(document.getElementsByTagName) != 'undefined') { obj_cells = obj_row.getElementsByTagName('td'); }
    else if (typeof(obj_row.cells) != 'undefined') { obj_cells = obj_row.cells; }
    else { return false; }

    var num_cels = obj_cells.length;
    var isDOM = null;
    var color_cur = null;
    var color_new = null;
    if (typeof(window.opera) == 'undefined' && typeof(obj_cells[0].getAttribute) != 'undefined') {
        color_cur = obj_cells[0].getAttribute('bgcolor');
        isDOM = true;
    }
    else {
        color_cur = obj_cells[0].style.backgroundColor;
        isDOM = false;
    }
    
    if (color_cur == '' || color_cur.toLowerCase() == colors_row[0].toLowerCase()) {
        if (_action == 0 && colors_row[1] != '') { color_new = colors_row[1]; }
        else if (_action == 1 && colors_row[2] != '') {
            color_new = colors_row[2];
            marked_row[nr_row] = true;
        }
    }
    else if (color_cur.toLowerCase() == colors_row[1].toLowerCase() && (typeof(marked_row[nr_row]) == 'undefined' || !marked_row[nr_row])) {
        if (_action == 2) { color_new = colors_row[0]; }
        else if (_action == 1 && colors_row[2] != '') {
            color_new = colors_row[2];
            marked_row[nr_row] = true;
        }
    }
    else if (color_cur.toLowerCase() == colors_row[2].toLowerCase()) {
        if (_action == 1) {
            color_new = (colors_row[1] != '') ? colors_row[1] : colors_row[0];
            marked_row[nr_row] = (typeof(marked_row[nr_row]) == 'undefined' || !marked_row[nr_row]) ? true : null;
        }
    }

    if (color_new) {
        var c = null;
        if (isDOM) { for (c = 0; c < num_cels; c++) { obj_cells[c].setAttribute('bgcolor', color_new, 0); } }
        else { for (c = 0; c < num_cels; c++) { obj_cells[c].style.backgroundColor = color_new; } }
    }

    return true;
}

function VB_set_checkboxes(_form, _check_t_f) {
    var tab_check = (typeof(document.forms[_form].elements['selected_tab[]']) != 'undefined') ? document.forms[_form].elements['selected_tab[]'] : '';
    var num_check = (typeof(tab_check.length) != 'undefined') ? tab_check.length : 0;
    if (num_check) {
        for (var i = 0; i < num_check; i++) {
            tab_check[i].checked = (tab_check[i].disabled) ? false : _check_t_f;
        }
    } 
    else {
        tab_check.checked = (tab_check[i].disabled) ? false : _check_t_f;
    }
    return true;
}

function VB_set_action_form(_form, action) {
    document.forms[_form].action.value = action;
}

function msg(msg_id) {
    var t_msg = ['Dział w przygotowaniu.\n\nZapraszamy już niedługo!'];
    alert(t_msg[msg_id]);
}

