﻿function findObj(obj) {
    return document.getElementById(obj);
}

function preloadimages(images) {
    if (!images) {
        var images = new Array();
    }
    var img = new Array();
    for (i=0; i<images.length; i++) {
        img[i] = new Image();
        img[i].src = images[i];
    }
}

function swapImage(id, img) {
    o = findObj(id);
    if(o) {
        o.src = img;
    }
}

function SendTo(before, after, user, host, label) {
    label = label.replace(' // ', '@');
    document.write('<a' + before + 'href="mailto:' + user + '@' + host + '"' + after+'>' + label + '</a>');
}

// zdj�cie bez opisu
function showImage(src, w, h) {
    noweOkienko = null;
    if (window.screen) {
        aw = screen.availWidth;
        ah = screen.availHeight;
    } else {
        aw = 640;
        ah = 450;
    }
    if (noweOkienko==null || noweOkienko.closed) {
        ustawienia=
        "left=" + (aw-w)/2 + ","
        +"top=" + (ah-h)/2 + ","
        +"screenX=" + (aw-w)/2 + ","
        +"screenY=" + (ah-h)/2 + ","
        +"width=" + w + ","
        +"height=" + h + ","
        +"innerWidth=" + w + ","
        +"innerHeight=" + h + ","
        +"toolbar=no,"
        +"location=no,"
        +"directories=no,"
        +"status=yes,"
        +"menubar=no,"
        +"scrollbars=no,"
        +"resizable=no"
        noweOkienko = window.open(baseHref + "showImage.php?src="+src, 'obrazek', ustawienia);
    }
    try {
        noweOkienko.focus();
    }
    catch (e) {
    }
}

// zdj�cie z opisem
function showOImage(src, w, h, opis) {
    noweOkienko = null;
    if (window.screen) {
        aw = screen.availWidth;
        ah = screen.availHeight;
    } else {
        aw = 640;
        ah = 450;
    }
    if (noweOkienko==null || noweOkienko.closed) {
        w = w + 32;
        oldH = h;
        h = h + 45;
        ustawienia=
        "left=" + (aw-w)/2 + ","
        +"top=" + (ah-h)/2 + ","
        +"screenX=" + (aw-w)/2 + ","
        +"screenY=" + (ah-h)/2 + ","
        +"width=" + w + ","
        +"height=" + h + ","
        +"innerWidth=" + w + ","
        +"innerHeight=" + h + ","
        +"toolbar=no,"
        +"location=no,"
        +"directories=no,"
        +"status=yes,"
        +"menubar=no,"
        +"scrollbars=yes,"
        +"resizable=no"
        noweOkienko = window.open(baseHref + "showImage.php?src="+src+":"+opis, 'obrazek', ustawienia);
    }
    try {
        noweOkienko.focus();
    }
    catch (e) {
    }
}


// pogoda
function showOImage2(src, w, h, opis) {
    noweOkienko = null;
    if (window.screen) {
        aw = screen.availWidth;
        ah = screen.availHeight;
    } else {
        aw = 640;
        ah = 450;
    }
    if (noweOkienko==null || noweOkienko.closed) {
        w = w + 32;
        oldH = h;
        h = h + 45;
        ustawienia=
        "left=" + (aw-w)/2 + ","
        +"top=" + (ah-h)/2 + ","
        +"screenX=" + (aw-w)/2 + ","
        +"screenY=" + (ah-h)/2 + ","
        +"width=" + w + ","
        +"height=" + h + ","
        +"innerWidth=" + w + ","
        +"innerHeight=" + h + ","
        +"toolbar=no,"
        +"location=no,"
        +"directories=no,"
        +"status=no,"
        +"menubar=no,"
        +"scrollbars=yes,"
        +"resizable=no"
        noweOkienko = window.open(baseHref + "showImage_pog.php?src="+src+":"+opis, 'obrazek', ustawienia);
    }
    try {
        noweOkienko.focus();
    }
    catch (e) {
    }
}

// popup
function popUpWindow(src, w, h) {
    noweOkienko = null;
    if (window.screen) {
        aw = screen.availWidth;
        ah = screen.availHeight;
    } else {
        aw = 640;
        ah = 450;
    }
    if (noweOkienko==null || noweOkienko.closed) {
        ustawienia=
        "left=" + (aw-w)/2 + ","
        +"top=" + (ah-h)/2 + ","
        +"screenX=" + (aw-w)/2 + ","
        +"screenY=" + (ah-h)/2 + ","
        +"width=" + w + ","
        +"height=" + h + ","
        +"innerWidth=" + w + ","
        +"innerHeight=" + h + ","
        +"toolbar=no,"
        +"location=no,"
        +"directories=no,"
        +"status=yes,"
        +"menubar=no,"
        +"scrollbars=yes,"
        +"resizable=no"
        var url = baseHref + src;
        noweOkienko = window.open(url, 'plik', ustawienia);
		
    }
    try {
        noweOkienko.focus();
    }
    catch (e) {
    }
}

// drukuj
function printWindow(src) {
    popUpWindow(src, 640, 450);
}

// base64 decode script
function decode64(input) {
    var output = "";
    var chr1, chr2, chr3 = "";
    var enc1, enc2, enc3, enc4 = "";
    var i = 0;
    var keyStr = 	"ABCDEFGHIJKLMNOP" +
    "QRSTUVWXYZabcdef" +
    "ghijklmnopqrstuv" +
    "wxyz0123456789+/" +
    "=";

    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    var base64test = /[^A-Za-z0-9\+\/\=]/g;
    if (base64test.exec(input)) {
        alert("There were invalid base64 characters in the input text.\n" +
            "Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='\n" +
            "Expect errors in decoding.");
    }
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
        }

        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

    } while (i < input.length);

    return output;
}

// rozwijanie listy wynikow w wyszukiwarce
function showResult(id) {
    o = document.getElementById(id);
    if (o.style.display == 'none') {
        o.style.display = 'block';
    } else {
        o.style.display = 'none';
    }
}

function limiter(obj, limit) {
    if (obj.value.length > limit) {
        obj.value = obj.value.substring(0,limit);
    }
}

// obliczanie pozostalych znakow w textarea
function limit(obj, limit, msg) {
    if (obj.value.length > limit) {
        obj.value = obj.value.substring(0,limit);
        alert(msg);
    }
}

function getCookie(name)
{
    var dc = document.cookie;
    var cname = name + "=";
    var clen = dc.length;
    var cbegin = 0;
	
    while (cbegin < clen)
    {
        var vbegin = cbegin + cname.length;
	
        if (dc.substring(cbegin, vbegin) == cname)
        {
            var vend = dc.indexOf (";", vbegin);
            if (vend == -1) vend = clen;
	
            return unescape(dc.substring(vbegin, vend));
        }
	
        cbegin = dc.indexOf(" ", cbegin) + 1;
	
        if (cbegin== 0) break;
    }
    return null;
}

function setCookie(name, value, expires, path, domain, secure)
{
    path = '/';
    document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function showHide1(d)
{
    if(d.length < 1) {
        return;
    }
    if(document.getElementById(d).style.display == "none") {
        document.getElementById(d).style.display = "block";
    }
    else {
        document.getElementById(d).style.display = "none";
    }
}

function showHide2(ch, d)
{
    if(d.length < 1) {
        return;
    }
    if(document.getElementById(ch).checked) {
        document.getElementById(d).style.display = "block";
    }
    else {
        document.getElementById(d).style.display = "none";
    }
}


function showHide(d)
{
    if(d.style.display == "none") {
        d.style.display = "block";
    }
    else {
        d.style.display = "none";
    }
}

function showHideDates()
{
    var select = document.getElementById("search_record_emissiondate_range");
    if (select.value=="0") {
        document.getElementById("dfromn").style.display="block";
        document.getElementById("dfrom").style.display="block";
        document.getElementById("dton").style.display="block";
        document.getElementById("dto").style.display="block";
        document.getElementById("bto").style.display="block";
        document.getElementById("bfrom").style.display="block";
        document.getElementById("dtor").className = "empty_row";
        document.getElementById("dfromr").className = "empty_row";
    }
    else {
        document.getElementById("dfromn").style.display="none";
        document.getElementById("dfrom").style.display="none";
        document.getElementById("dton").style.display="none";
        document.getElementById("dto").style.display="none";
        document.getElementById("bto").style.display="none";
        document.getElementById("bfrom").style.display="none";
        document.getElementById("dtor").className = "empty_row0";
        document.getElementById("dfromr").className = "empty_row0";
    }
}

function clearAdvForm() {
    document.MainForm['search.Record.title'].value='';
    document.MainForm['search.Record.Person._id'].value='';
    document.MainForm['search.Record.Person.firstname1'].value='';
    document.MainForm['search.Record.Content._Count'].checked=false;
    document.MainForm['search.Record.emissiondate_frommonth'].value='';
    document.MainForm['search.Record.emissiondate_fromyear'].value='';
    document.MainForm['search.Record.emissiondate_fromday'].value='';
    document.MainForm['search.Record.emissiondate_tomonth'].value='';
    document.MainForm['search.Record.emissiondate_toyear'].value='';
    document.MainForm['search.Record.emissiondate_today'].value='';
    document.MainForm['search.Record.emissiondate_range'].value='';
    document.MainForm['search.Record.Sort.name'].value='';
    document.MainForm['search.Record.Topic.name'].value='';
}

function clearForm(what) {
    document.MainForm[what].value='';

}

function bodyScrollValueUpdate() {
    var div   = document.getElementById('main.bodyScroll');
    var input = document.getElementById('main.scrollValue');
    input.value=div.scrollTop;
    helpTipTimer = setTimeout('bodyScrollValueUpdate()',100);
}
function initBodyScrollValueUpdate() {
    var div   = document.getElementById('main.bodyScroll');
    var input = document.getElementById('main.scrollValue');
    div.scrollTop = input.value;
    helpTipTimer = setTimeout("bodyScrollValueUpdate()",100);
}

function goArchiwum() {
    document.firstPage.submit();
}

function order(what, how) {
    document.MainForm['order.Record'].value = what;
    document.MainForm['orderType.Record'].value = how;
    document.MainForm.submit();
}
function showMenu() {
//                switchMenu(document.getElementById('m2'));
}

function menuClick(id, menu) {
    document.MainForm['newsearch'].value="Record";
    document.MainForm['search.Record.Sort.id'].value='';
    document.MainForm['search.Record.Person.id'].value=id;
    document.MainForm['page.activemenu'].value=menu;
    document.MainForm['search.Record._all'].value='';
    document.MainForm.submit();
}
function menuClickG(id, menu) {
    document.MainForm['newsearch'].value="Record";
    document.MainForm['search.Record.Person.id'].value='';
    document.MainForm['search.Record.Sort.id'].value=id;
    document.MainForm['page.activemenu'].value=menu;
    document.MainForm['search.Record._all'].value='';
    document.MainForm.submit();
}

function czyUsunac(tekst,linkNaTak) {
    if(confirm(tekst))
        location.href=linkNaTak;
}
      
