// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Zapisuje ciasteczka z ustawieniami font, window size
//
  
function setCookieUser(name, value)
{
  if(name == '' || name == null) return false;
  
  value = escape(value);
  document.cookie = name + "=" + value + ';path=/' + BIP_ROOT_DIR;
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Odczytuje ciasteczka z ustawieniami font, window size
//
function getCookieUser(name)
{
  name += "=";
  
  startCookie = document.cookie.indexOf(name);
  
  if(startCookie==-1)
  {
    return DefaultFontSize;
  }
  
  startCookie += name.length;
  
  if(document.cookie.indexOf(";", startCookie) == -1) endCookie = document.cookie.length;
  else                                                endCookie = document.cookie.indexOf(";", startCookie);

  textCookie = document.cookie.substring(startCookie, endCookie);

  textCookie = unescape(textCookie);
  
  return textCookie;
  
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Skrypty odpowiedzialne za skalowanie szerokośći strony
// 
function WindowWidthSize(element, size)
{
  setCookieUser('windowSize',  size);
  document.getElementById(element).style.width = size;
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Skrypty odpowiedzialne za ustawienie fonta
//
var DefaultFontSize = 0.7;
var MaxFontSize     = 1.6;
var MiniFontSize    = 0.6;
var StepFontSize    = 0.1;
var JmFontSize      = 'em';

function WindowFontSize(element, type)
{
  oldFontSize = document.getElementById(element).style.fontSize;
  oldFontSize = oldFontSize.replace(JmFontSize, '');
  
  if(oldFontSize == '' || oldFontSize == null) 
  {
    oldFontSize = DefaultFontSize;
  }
  
  oldFontSize = oldFontSize * 1;
  
  if(type == 'z') newFontSize = DefaultFontSize;
  if(type == 'm') newFontSize = oldFontSize - StepFontSize;
  if(type == 'd') newFontSize = oldFontSize + StepFontSize;
  
  if(newFontSize <= MiniFontSize) newFontSize = MiniFontSize;
  if(newFontSize >= MaxFontSize)  newFontSize = MaxFontSize;
  
  setCookieUser('fontSize', newFontSize);
  
  document.getElementById(element).style.fontSize = newFontSize + JmFontSize;
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Ustawia domyslny lub z cookie font
//
function setWindowFontSize(element)
{
  userFont = getCookieUser('fontSize');
  userFont = userFont * 1;
  
  if(userFont >= MiniFontSize && userFont <= MaxFontSize) document.getElementById(element).style.fontSize = userFont + JmFontSize;
  else                                                    document.getElementById(element).style.fontSize = DefaultFontSize + JmFontSize;
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Ustawia zapisany rozmiar okna
//
function setWindowSize(element)
{
  userWindow = getCookieUser('windowSize');
  
  if(userWindow != '' && userWindow != null )
  {
    if(userWindow == '70%' || userWindow == '80%' || userWindow == '90%' || userWindow == '95%' || userWindow == '100%' || userWindow == '770px') {
      document.getElementById(element).style.width = userWindow;
    }
  }
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Wczytuje ustawienia użytkownika
//
function setUserConfig()
{
   //setWindowSize('ViewContent');
   //setWindowFontSize('ViewText')
}
