/* 
  ------------------------------------------------
  Skrypty javascript użyte w www.eczytelnia.pl

  ------------------------------------------------
*/
/* Start Bitstream WebFont Player support */

if (navigator.appName == "Microsoft Internet Explorer" &&
    navigator.appVersion.indexOf("Windows", 0) != -1 &&
    navigator.appVersion.substring(0,1) >= 4)
{
    document.writeln("<OBJECT");
    document.writeln("classid=\"clsid:0246ECA8-996F-11D1-BE2F-00A0C9037DFE\"");
    document.writeln("codebase=\"http://www.bitstream.com/wfplayer/tdserver.cab#version=1,0,0,10\"");
    document.writeln("id=\"TDS\" width=0 height=0");
    document.writeln(">");
    document.writeln("</OBJECT>");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  }
  
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}


function MM_showHideLayers() { //v3.0

  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 poczta(user,site) {

document.write('<a href=\"mailto:' + user + '@' + site + '\">');
document.write(user + '@' + site + '</a>');

}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}


// Copyright (c) May 2002 by Michał Nazarewicz (mina86@tlen.pl)
// Idea by Michał Jazłowiecki (michalj@prioris.mini.pw.edu.pl)
// This software is free; It's distributed under terms of GNU General Public License

var theDoc=document, theAll=(theDoc.all)?theDoc.all:null;
function ShowHideLayer(name, state) {
	if (theAll==null) return;
	if (arguments.length<2) state=theAll[name].style.display=="none";
	theAll[name].style.display=(state)?"block":"none";
}
function ButtonClick(but, name, desc1, desc2) {
	var state=but.value==desc1;
	but.value=(state)?desc2:desc1;
	ShowHideLayer(name,!state);
}
function addShowHideButton(name, desc1, desc2, state) {
	if (theAll==null) return;
	theDoc.write('<form><input type="button" value="'+(state?desc1:desc2)+
	'" onclick="ButtonClick(this, \''+name+'\',\''+desc1+'\',\''+desc2+'\');" /></form>');
}

// Dodaj do ulubionych
   var urlAddress = "http://www.eczytelnia.pl/";
   var pageName = "e-czytelnia Wydawnictwa 'e media'";

 function addToFavorites(urlAddress,pageName)
 {
  if (window.external)
  {
   window.external.AddFavorite(urlAddress,pageName)
  }
  else
  { 
   alert("Wybacz! Twoja przeglądarka nie rozumie tej funkcji.");
  }
 }

// Skrypt otwierania okna 
// Copright by Marek Niedostatkiewicz, 2003
// 
// This notice must stay intact for use

 function okno(adres_dokumentu,tytul_okna,atrybuty_okna){
   //var adres_dokumentu="index.html"  //adres strony
   //var tytul_okna='entry"'   //nazwa okna e-czytelni
   //var atrybuty_okna="fullscreen=yes" // pelny ekran


//if (typeof okno=="undefined" || okno.closed) 
	okno=window.open(adres_dokumentu,tytul_okna,atrybuty_okna)
// else 
	okno.focus();
}

// Ukrywanie obiektu na stronie
// Przyklad: onmouseoout="hideObject();"

function hideObject() {
      document.getElementById('n1').style.visibility = "hidden";
}

// Pokazanie obiektu na stronie
// przyklad: onmouseover="showObject(event,'Tutaj jakiś tekst [może być z kodem html] do pokazania po najechaniu kursorem na myszkę.');"
// parametry opcjonalne: przezunięcie x i przesunięcie y

function showObject(e,txt,osetx,osety)
{
	if (osetx) {offsetx=osetx;} else {offsetx=20;}
	if (osety) {offsety=osety;} else {offsety=0;}
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	document.getElementById("text").innerHTML=txt;
	document.getElementById('n1').style.left = (posx+offsetx);
	document.getElementById('n1').style.top = (posy+offsety);
	document.getElementById('n1').style.visibility = "visible";
}

function toggleDisplay(target) {
	if (document.getElementById){
		var togglin = document.getElementById( target );
		if(togglin.style.display == ""){
			togglin.style.display = "none";
		}else{
			togglin.style.display = "";
		}
	}
};

function toggleDisplayDivs(target) {
	if (document.getElementById){
		var togglin = document.getElementById( target );
		if(togglin.className == "ukryty"){
			togglin.className = "widoczny";
		}else{
			togglin.className = "ukryty";
		}
	}
};

function expandCollapseBoxes(){
	if(!document.getElementsByTagName) {return;}
	var divs = document.getElementsByTagName("div");
	for (var i=0; i < divs.length; i++) {
		if(divs[i].className == "ukryty") {
		divs[i].className = "widoczny";
		}
	}
};

/*------------------------------------------------------------------------------
Function:       footnoteLinks()
Author:         Aaron Gustafson (aaron at easy-designs dot net)
Creation Date:  8 May 2005
Version:        1.3
Homepage:       http://www.easy-designs.net/code/footnoteLinks/
License:        Creative Commons Attribution-ShareAlike 2.0 License
                http://creativecommons.org/licenses/by-sa/2.0/
Note:           If you change or improve on this script, please let us know by 
                emailing the author (above) with a link to your demo page.
Note (MarekN):	This script has been translated a bit into Polish language.
------------------------------------------------------------------------------*/
function footnoteLinks(containerID,targetID) {
  if (!document.getElementById || 
      !document.getElementsByTagName ||
      !document.createElement) return false;
  if (!document.getElementById(containerID) ||
      !document.getElementById(targetID)) return false;
  var container = document.getElementById(containerID);
  var target    = document.getElementById(targetID);
  var h2        = document.createElement('h4');
  addClass.apply(h2,['printOnly']);
  var h2_txt    = document.createTextNode('Zestawienie odnośników'); /* added by M. Niedostatkiewicz */
  h2.appendChild(h2_txt);
  var coll = container.getElementsByTagName('*');
  var ol   = document.createElement('ol');
  addClass.apply(ol,['printOnly']);
  var myArr = [];
  var thisLink;
  var num = 1;
  for (var i=0; i<coll.length; i++) {
    var thisClass = coll[i].className;
    if ( (coll[i].getAttribute('href') ||
          coll[i].getAttribute('cite')) &&
          (thisClass == '' ||
           thisClass.indexOf('ignore') == -1)) { 
      thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
      var note = document.createElement('sup');
      addClass.apply(note,['printOnly']);
      var note_txt;
      var j = inArray.apply(myArr,[thisLink]);
      if ( j || j===0 ) {
        note_txt = document.createTextNode(j+1);
      } else {
        var li     = document.createElement('li');
        var li_txt = document.createTextNode(thisLink);
        li.appendChild(li_txt);
        ol.appendChild(li);
        myArr.push(thisLink);
        note_txt = document.createTextNode(num);
        num++;
      }
      note.appendChild(note_txt);
      if (coll[i].tagName.toLowerCase() == 'blockquote') {
        var lastChild = lastChildContainingText.apply(coll[i]);
        lastChild.appendChild(note);
      } else {
        coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
      }
    }
  }
  target.appendChild(h2);
  target.appendChild(ol);
  addClass.apply(document.getElementsByTagName('html')[0],['noted']);
  return true;
}

/*------------------------------------------------------------------------------
Filename:       jsUtilities Library
Author:         Aaron Gustafson (aaron at easy-designs dot net)
                unless otherwise noted
Creation Date:  4 June 2005
Version:        2.1
Homepage:       http://www.easy-designs.net/code/jsUtilities/
License:        Creative Commons Attribution-ShareAlike 2.0 License
                http://creativecommons.org/licenses/by-sa/2.0/
Note:           If you change or improve on this script, please let us know by 
                emailing the author (above) with a link to your demo page.
------------------------------------------------------------------------------*/
// ---------------------------------------------------------------------
//                      array.push (if unsupported)
// ---------------------------------------------------------------------
if(Array.prototype.push == null) {
  Array.prototype.push = function(item) {
    this[this.length] = item;
    return this.length;
  };
};
// ---------------------------------------------------------------------
//                      array.shift (if unsupported)
// ---------------------------------------------------------------------
if (Array.prototype.shift == null) {
  Array.prototype.shift = function() {
    var response = this[0];
    for (var i=0; i < this.length-1; i++) {
      this[i] = this[i + 1];
    };
    this.length--;
    return response;
  };
};
// ---------------------------------------------------------------------
//                  function.apply (if unsupported)
//           Courtesy of Aaron Boodman - http://youngpup.net
// ---------------------------------------------------------------------
if (!Function.prototype.apply) {
  Function.prototype.apply = function(oScope, args) {
    var sarg = [];
    var rtrn, call;
    if (!oScope) oScope = window;
    if (!args) args = [];
    for (var i = 0; i < args.length; i++) {
      sarg[i] = "args["+i+"]";
    };
    call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
    oScope.__applyTemp__ = this;
    rtrn = eval(call);
    oScope.__applyTemp__ = null;
	return rtrn;
  };
};
// ---------------------------------------------------------------------
//                               inArray()
//                           [Port from PHP]
//               Hunts for a value in the specified array
// ---------------------------------------------------------------------
function inArray(needle) {
  for (var i=0; i < this.length; i++) {
    if (this[i] === needle) {
      return i;
    }
  }
  return false;
}
Array.prototype.inArray = inArray;
// ---------------------------------------------------------------------
//                               isArray()
//                           [Port from PHP]
//                  verifies if something is an array
// ---------------------------------------------------------------------
function isArray() {
  return (typeof(this.length)=="undefined") ? false : true;
};
Array.prototype.isArray = isArray;
// ---------------------------------------------------------------------
//                               ksort()
//                           [Port from PHP]
//                     sorts an array by key names
// ---------------------------------------------------------------------
function ksort() {
  var sArr = [];
  var tArr = [];
  var n = 0;
  for (i in this)
    tArr[n++] = i+"|"+this[i];
  tArr = tArr.sort();
  for (var i=0; i<tArr.length; i++) {
    var x = tArr[i].split("|");
    sArr[x[0]] = x[1];
  }
  return sArr;
}
Array.prototype.ksort = ksort;
// ---------------------------------------------------------------------
//                             addClass()
//                 appends the specified class to the object
// ---------------------------------------------------------------------
function addClass(theClass) {
  if (this.className != '') {
    this.className += ' ' + theClass;
  } else {
    this.className = theClass;
  }
}
Object.prototype.addClass = addClass;
// ---------------------------------------------------------------------
//                           removeClass()
//                 removes the specified class to the object
// ---------------------------------------------------------------------
function removeClass(theClass) {
  var oldClass = this.className;
  var regExp = new RegExp('\\s?'+theClass+'\\b');
  if (oldClass.indexOf(theClass) != -1) {
    this.className = oldClass.replace(regExp,'');
  }
}
Object.prototype.removeClass = removeClass;


// ---------------------------------------------------------------------
//                      lastChildContainingText()
//  finds the last block-level text-containing element within an object
// ---------------------------------------------------------------------
function lastChildContainingText() {
  var testChild = this.lastChild;
  var contentCntnr = ['p','li','dd'];
  while (testChild.nodeType != 1) {
    testChild = testChild.previousSibling;
  } 
  var tag = testChild.tagName.toLowerCase();
  var tagInArr = inArray.apply(contentCntnr, [tag]);
  if (!tagInArr && tagInArr!==0) {
    testChild = lastChildContainingText.apply(testChild);
  }
  return testChild;
}
Object.prototype.lastChildContainingText = lastChildContainingText;



