///////////////////////////////////// CHANGE FONT SIZE /////////////////////////////////////

var defaultTags = new Array( 'a','p','div','span','table','th','td','em','h1','h2','h3','pre','sub','ul','ol','li','font');
var formTags = new Array( 'a','p','div','span','table','th','td','em','h1','h2','h3','pre','sub','ul','ol','li','font','input','button','select','textarea');
var tags = defaultTags;
var noChange = new RegExp('(select.termin_wydarzen|null|sunday|today|empty|link_f|calendar_month_name|table.tabela1 th|table.tabela1 td|table.tabela1 td.nochange|table.tabela1 a|span.nochange|#wysz_top span)','i');

var minPoint = 1; // zakres zmiany rozmiarow fontow (jednostkowa +/-) od - do
var maxPoint = 5;

var defaultPoint = 1; // stan poczatkowy
var currPoint = defaultPoint;

var difference = 1; // o ile ma sie zmienic rozmiar fontu
//var spacingRadio = 2/15;  // wspolczynik zmian odstepow miedzy wierszami i znakami proporcjonalnie do rozmiaru fontu 

var defaultFontSize = 8; // domyslny rozmiar
var currFontSize = defaultFontSize;

function changeFont(change){

  if( (change + currPoint <= maxPoint) && (change + currPoint >= minPoint) ){

    if( change=='0' ){
      change = ( defaultPoint-currPoint ) * difference;
      currPoint = defaultPoint;
      currFontSize = defaultFontSize;
    }
    else{
      currPoint = currPoint + change;
      change = change * difference; // roznica rozmiaru
      currFontSize = currFontSize + change; // domyslny rozmiar
    }
    cookieValue = currFontSize - defaultFontSize; 
    SetCookie('fontSize',cookieValue,365);
    fontSizer(change);
  }  
}

function pobierzArkuszIlosc(){
  return(document.styleSheets.length);
}

function pobierzStylIlosc(i){
  if( navigator.appName=="Microsoft Internet Explorer" )
    return(document.styleSheets[i].rules.length);
  else
    return(document.styleSheets[i].cssRules.length);
}

function pobierzStyl(i,j){
  if( navigator.appName=="Microsoft Internet Explorer" )
    return(document.styleSheets[i].rules[j]);
  else
    return(document.styleSheets[i].cssRules[j]);
}

function ustalRozmiar(obiekt,change){

  //alert(obiekt.selectorText+" "+noChange.test(obiekt.selectorText));  
  if( (obiekt.selectorText!='' && !noChange.test(obiekt.selectorText)) || obiekt.selectorText=='' ){
    if( obiekt.style.fontSize )
      font = parseInt(obiekt.style.fontSize.slice(0,-2)) + parseInt(change);
    else
      font = defaultFontSize + parseInt(change);
    obiekt.style.fontSize = font+'px';
    obiekt.style.lineHeight = 'normal';
    obiekt.style.wordSpacing = 'normal';
  }
//  else
  //  {alert('|'+obiekt.selectorText+'|');return false;}
}

function fontSizer(change) {
  
  if( !document.getElementById )
    return;
  else{
    var i,j;
    var arkuszIlosc=pobierzArkuszIlosc();
    //alert("Arkuszy:"+arkuszIlosc);
    for(i=0;i<arkuszIlosc;i++){
      
      var stylIlosc=pobierzStylIlosc(i);
      //alert("Styli:"+stylIlosc);
      for(j=0;j<stylIlosc;j++){

        var obiekt=pobierzStyl(i,j);
        if(obiekt.style.fontSize)
          ustalRozmiar(obiekt,change);
      }
    }
  }
}

function fontSizeInit(){

  var cookie = ReadCookie('fontSize');
  if( cookie ){
    cookie = parseInt(cookie);
    currFontSize = currFontSize + cookie;
    currPoint = currPoint + cookie;
    fontSizer(cookie);
  }
  return true;
}
