/* Style, poczatek - zmiana stylu strony */

/* better event handling */
if (document.all && window.attachEvent) {
    // IE-Win
    window.attachEvent("onload", onPageLoad);
}
else if (window.addEventListener) {
    // Gecko, Safari, KDE
    window.addEventListener("load", onPageLoad, true);
    window.addEventListener("unload", onPageUnload, true);
}
else {
    // old others, like ie5-mac
}

/* modified version of a script once published in ALA http://www.alistapart.com/articles/alternate/ */

function setActiveStyleSheetProperty(title, property) {
    var i, a, main;
    for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf(property) != -1) {
            a.disabled = true;
            if (a.getAttribute("title") == title) a.disabled = false;
        }
    }
    return true;
}

function setActiveStyleSheetCol(title) {
      return setActiveStyleSheetProperty(title,"classiccolors");
}

function getActiveStyleSheetProperty(property) {
    var i, a;
    for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute('title') != undefined) {
            if (a.getAttribute("rel").indexOf("style") != -1 && !a.disabled && a.getAttribute("title").indexOf(property) != -1) {
                return a.getAttribute("title");
            }
        }
    }
    return null;
}

function getActiveStyleSheetCol() {
     return getActiveStyleSheetProperty("classiccolors");
}

function getPreferredStyleSheetProperty(property) {
    var i, a;
    for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") && a.getAttribute("title").indexOf(property)  != -1) {
            return a.getAttribute("title");
        }
    }
    return null;
}

function getPreferredStyleSheetCol() {
     return getPreferredStyleSheetProperty("classiccolors");
}


function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
    return true;
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function onPageLoad(e) {
    var cookie = readCookie("classic_colscheme");
    var title = cookie ? cookie : getPreferredStyleSheetCol();
    setActiveStyleSheetCol(title);
    return true;
}

function onPageUnload(e) {
    var title = getActiveStyleSheetCol();
    createCookie("classic_colscheme", title, 1);
}

/* Koniec */

/* Tekst, poczatek - zmiana rozwiaru czcionki */

function gEBI( objId ) {
    return document.getElementById( objId );
}

function createCookieText( sName, sValue, iDays ) {
    sValue = escape( sValue );
    if( iDays ) {
        var oDate = new Date();
        oDate.setTime( oDate.getTime() + ( iDays*24*60*60*1000 ) );
        var sExpires = "; expires="+oDate.toGMTString();
    }
    else
    var sExpires = "";
    document.cookie = sName+"="+sValue+sExpires+"; path=/";
}

function throwCookie( sName ) {
    var sNameEQ = sName + "=";
    var aCookies = document.cookie.split( ';' );
    for( var i=0; i < aCookies.length; i++ ) {
        var c = aCookies[i];
        while( c.charAt(0) == ' ' )
        c = c.substring( 1, c.length );
        if( c.indexOf( sNameEQ ) == 0 )
        return c.substring( sNameEQ.length, c.length );
    }
    return null;
}

function delCookieText( sName ) {
    createCookieText( sName, "", -1 );
}

function isset( sVar ) {
    return( typeof( window[sVar] ) != 'undefined' );
}

_bUa=navigator.userAgent.toLowerCase();
_bOp=(_bUa.indexOf("opera")!=-1?true:false);
_bIe=(_bUa.indexOf("msie")!=-1&&!_bOp?true:false);
_bIe4=(_bIe&&(_bUa.indexOf("msie 2.")!=-1||_bUa.indexOf("msie 3.")!=-1||_bUa.indexOf("msie 4.")!=-1)&&!_bOp?true:false)
isIe=function() {
    return _bIe;
}
isOldIe=function() {
    return _bIe4;
}
var olArray=[];

function AddOnload( f ) {
    if( isIe() && isOldIe() ) {
        window.onload = ReadOnload;
        olArray[olArray.length] = f;
    }
    else if( window.onload ) {
        if( window.onload != ReadOnload ) {
            olArray[0] = window.onload;
            window.onload = ReadOnload;
        }
        olArray[olArray.length] = f;
    }
    else
    window.onload=f;
}

function ReadOnload() {
    for( var i=0; i < olArray.length; i++ ) {
        olArray[i]();
    }
}

// h5 nie uzywane, do poprawki !!!
function txtSize( iSize ) {
    var aSizes = Array( '0.917em', '', '1.333em' );
    var aChange = Array( 'idFontSizeOne', 'idArtykulTresc' ); // tdbodyleft, tdfontsizetwo
    var aSizesDefault = Array( '1.083em', '1em' );
    for( var i = 0; i < aChange.length; i++ ) {
        if( !aSizes[iSize] )
        iSize = 1;
        if( gEBI( aChange[i] ) ) {
            gEBI( aChange[i] ).style.fontSize = ( iSize != 1 ) ? aSizes[iSize] : aSizesDefault[i];
        }
        else if( gEBI( 'content' ).getElementsByTagName( aChange[i] ) ) {
            aH5 = gEBI( 'content' ).getElementsByTagName( aChange[i] );
            for( var j = 0; j < aH5.length; j++ ) {
                aH5[j].style.fontSize = ( iSize != 1 ) ? aSizes[iSize] : aSizesDefault[i];
            }
        }
    }
}

/* Koniec */

/* Dodane */

//function ramkaOdswiez() {
 //idFrame = 'ramkaInformator';
 //if (document.getElementById(idFrame)) {
  //document.getElementById(idFrame).src = 'informator/index.php';
 //}
 // lub parent.tag.location.href = 'informator/index.php';
//}


// Parametr params mozna podac np. jako 'scrollbars=yes, status=yes, resizable=yes'
function PopUpWindow(href,target,width,height,params) {
 if(typeof(width) == 'undefined' ) {
  width = 750;
 }
 if(typeof(height) == 'undefined') {
  height = 550;
 }
 
 var left = (screen.width - width) / 2;
 var top = (screen.height - height) / 2;
 
 if(typeof(params) == 'undefined') {
  params = 'scrollbars=yes, status=yes, resizable=yes, menubar=yes';
 }
 
 params = 'width=' + width + ', height=' + height + ', ' + 'left=' + left + ', top=' + top + ', ' + params;
 
 // Open window:
 opened = window.open( href, target, params );
 
 // Bring to front!
 opened.focus();
 if(typeof(openedWindows) == 'undefined') {
  openedWindows = new Array(opened);
 }
 else {
  openedWindows.push(opened);
 }
 
 // Tell the caller there is no need to process href="":
 return false;
}

function ElementShowHidden(whichLayer) {
 var elem, vis;
 if (document.getElementById) // this is the way the standards work
 elem = document.getElementById(whichLayer); 
 else if (document.all) // this is the way old msie versions work
 elem = document.all[whichLayer];
 else if (document.layers) // this is the way nn4 works
 elem = document.layers[whichLayer];
 
 vis = elem.style;
 // if the style.display value is blank we try to figure it out here
 if(vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight !=undefined)
 vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0 ) ?'block':'none';
 vis.display = (vis.display == '' || vis.display == 'block') ?'none':'block';
}

function DymekVisible(nazwa) {
 var div = document.getElementById(nazwa);
 div.style.display = 'block';
}

function DymekHidden(nazwa) {
 var div = document.getElementById(nazwa);
 div.style.display = 'none';
}

function LiczZnaki(znaki,ile) {
 var ilemax = ile;
 dlugosc=znaki.value.length;
 
 if (dlugosc == 1 && znaki.value.substring(0,1) == ' ') {
  znaki.value='';
  dlugosc=0;
 }
 if (dlugosc > ilemax ){
  znaki.value=znaki.value.substring(0,ilemax);
  pozostalo=0;
 }
 else {
  pozostalo=ilemax-dlugosc;
 }
 document.formularz.licz.value=pozostalo;
}

function DodajUlubione(url,title) {
 if (window.sidebar) { // firefox
  window.sidebar.addPanel(title, url, '');
 }
 else if(window.opera && window.print) { // opera, cos nie tak?
  var elem = document.createElement('elem');
  elem.setAttribute('href',url);
  elem.setAttribute('title',title);
  elem.setAttribute('rel','sidebar');
  elem.click();
 } 
 else if(document.all) { // ie
  window.external.AddFavorite(url, title);
 }
 else { // inne przegladarki
   alert('Przegladarka nie obsluguje polecenia! Musisz recznie dodac strone do ulubionych.');
 }
}

var StronaStartowa = function(page,url) { // dziala tylko w ie
 if(document.all) { // ie
  page.style.behavior='url(#default#homepage)';
  page.setHomePage(url);
 }
 else { // inne przegladarki
   alert('Polecenie dziala automatycznie tylko w przegladarce Internet Explorer!' + '\nW innych przgladarkach mozna ustawic strone recznie, w FireFox wystarczy przeciagnac ikone strony z paska adresu przegladarki na ikone domek przegladarki.');
 }
}
