N = navigator.userAgent;
N = N.toLowerCase();
isIE      = ((N.indexOf("msie") != -1) && (N.indexOf("opera") == -1));
isOpera   = (N.indexOf("opera") != -1);
isMac     = (N.indexOf("mac") != -1);
isFireFox = (N.indexOf("firefox") != -1);
isSafari  = (N.indexOf("safari") != -1);
isGecko   = (navigator.product == "Gecko");
isIE6     = (N.indexOf("msie 6") != -1);  
isIE7     = (N.indexOf("msie 7") != -1);
isIE8     = (N.indexOf("msie 8") != -1);

function editBlur(sender, defValue)
{
    if (_trim(sender.value)=='')
       sender.value = defValue;
}
function editFocus(sender, defValue)
{
    if (_trim(sender.value)==defValue)
       sender.value = '';
}

function editEmptyFocus(sender)
{            
    sender.className = sender.className.replace('empty', '');
}              
function editEmptyBlur(sender)
{            
    if (_trim(sender.value)=='') 
       sender.className += ' empty';
    else 
       editEmptyFocus(sender);
}


function _trim(text)
{
    text = text.replace(/^\s+/, '');
    return text.replace(/\s+$/, '');
}

function clearIfZero(sender)
{
    stopCalk = true;
    if (trim(sender.value) == 0)
        sender.value = '';
}
function realFormat(sender)
{
    if (trim(sender.value) == '')
        sender.value = 0;
    sender.value = sender.value.replace(/^\s+/, '');
    sender.value = sender.value.replace(/\s+$/, '');
    sender.value = sender.value.replace(',','.');
}


function pageInit()
{                  
    setTimeout("hideMessageBox()", 5000);
    if (typeof jQuery == "undefined")
    {    

    }
    else
        $(".lightbox").lightbox();
}

function createBookmarkLink()
{                   
   _url = location.href;    
   _title = document.title;                                                         
   document.write('<a id="favorite-link"');
   if (window.sidebar) 
   {
      document.write(' href="'+_url+'" onclick="window.sidebar.addPanel(\''+_title+'\', \''+_url+'\', \'\'); return false;" ');
      document.write(' title="Dodaj do zakładek [Ctrl+D]">Dodaj do zakładek');
   } 
   else                                       
   if (window.external) 
   {                   
      document.write(' href="" onclick="window.external.AddFavorite(\''+_url+'\', \''+_title+'\'); return false;" ');
      document.write('>Dodaj do Ulubionych');
   } 
   else  
   if (window.opera && window.print) 	
   {
      document.write(' href="'+_url+'" title="'+_title+'" target="_search" ');
      document.write(' rel="sidebar">Dodaj do zakładek'); 
   }    
   else  
      document.write('>');
   document.write('</a>'); 
}            

function hideElement(idElement)
{                            
    if (typeof jQuery == "undefined")
    {    
       _mb = document.getElementById(idElement);
       _mb.className += ' disabled';
    }
    else
       $('#'+idElement).slideUp('slow');
}     
function showElement(idElement)
{                            
    if (typeof jQuery == "undefined")
    {    
       _mb = document.getElementById(idElement);
       _mb.className = _mb.className.replace('disabled', '');
    }
    else
       $('#'+idElement).slideDown('slow');
}

/* menu */

var currSubMenuId = false

function showSubmenu(sender, subMenuId)
{
   if (currSubMenuId != subMenuId)
   {
      hideSubmenu();
      var position = $(sender).position();    
      $('#'+subMenuId).css({
            'left': position.left+'px',
            'top': (position.top + $(sender).outerHeight(true))
      });
      currSubMenuId = subMenuId; 
   }               
   showElement(subMenuId);
}
function hideSubmenu()
{                           
   currSubMenuId = false;
   $('ul.submenu').fadeOut();  
}        
            
/* messageBox */

function hideMessageBox()
{                            
    hideElement('message-box');
}

/* comments */

function commentClick(sender, idc)
{
   cmm_emement =document.getElementById('comment-'+idc);
   if (cmm_emement)
   {
       cmm_emement.style.display = 'block';  
       cmm_emement.className = '';
   }
   sender.style.display = 'none';      
}   
function commentDblClick(sender)
{
   sender.className = ((sender.className == 'large')?'':'large');
   sender.focus();
}
     
var contCommentForm = false     
var activeCommentButton = false   
var active_idc = false        

function sendComment()
{     
   if (typeof active_idc == "number")
   {
      _f  = document.getElementById('comment-sendform-'+active_idc);           
      _h  = document.getElementById('comment-header-'+active_idc);    
      _e1 = document.getElementById('comment-error-text-'+active_idc);    
      _e2 = document.getElementById('comment-error-author-'+active_idc);
      _e3 = document.getElementById('comment-error-email-'+active_idc);    
      _e4 = document.getElementById('comment-error-unknow-'+active_idc);   
      if (_e1)
          _e1.innerHTML = '';   
      if (_e2)
          _e2.innerHTML = '';
      if (_e3)
          _e3.innerHTML = '';  
      if (_e4)
          _e4.innerHTML = '';   
      if (_h)
          ht = _h.innerHTML;
      advAJAX.submit(_f,
      {      
          parameters : {          
             "save_comment": "true",
             "location": location.protocol+'//'+location.host+location.pathname,
             "idc" : active_idc
         },     
          onSuccess:
              function(obj)
              {
                  eval(obj.responseText);  
                  if (typeof ret['errors'] == "object")
                  {
                     if (ret['errors']['text'])
                     {
                        if (_e1)
                            _e1.innerHTML = ret['errors']['text'];
                     }   
                     if (ret['errors']['author'])
                     {
                        if (_e2)
                            _e2.innerHTML = ret['errors']['author'];
                     }
                     if (ret['errors']['email'])
                     {
                        if (_e3)
                            _e3.innerHTML = ret['errors']['email'];
                     } 
                     if (ret['errors']['unknow'])
                     {
                        if (_e4)
                            _e4.innerHTML = ret['errors']['unknow'];
                     }
                  }       
              },  
          onInitialization:
              function(obj)
              {
                 if (_h)
                 {
                     _h.innerHTML = 'Proszę czekać...';
                     _h.className = 'wait-inline';
                 }
              },        
          onFinalization:
              function(obj)
              {
                 if (_h)      
                 {
                     _h.innerHTML = ht; 
                     _h.className = '';
                 }
              },                                                                                   
          onError:
              function(obj)
              {
                  hideCommentForm();
                  alert( 'Error: ' + obj.status );
              }
      });        
   }             
   return false;
}                            

function sendCommentAlert(objId, ide, idc)
{                  
   obj = document.getElementById(objId);
   if (obj && (confirm("Czy chcesz zgłosić naruszenie regulaminu?")))
   {
      advAJAX.post(
      {      
          url: '/ajax/',
          parameters : {          
             "send_comment_alert" : "true",
             "location" : location.protocol+'//'+location.host+location.pathname,
             "text" : obj.innerHTML,
             "ide" : ide,
             "idc" : idc
         },     
          onSuccess:
              function(obj)
              {                   
                  hideCommentForm();
                  r = obj.responseText;  
                  if (r == 1)
                     alert('Zgłoszenie zostało wysłane');  
                  else
                     alert('Wystąpił błąd - Zgłoszenie nie zostało wysłane');
              },                                                                       
          onError:
              function(obj)
              {
                  hideCommentForm();
                  alert( 'Error: ' + obj.status );
              }
      });        
   }             
   return false;
}                  
function hideCommentForm()
{
   if (contCommentForm)
       contCommentForm.innerHTML = '';
   if (activeCommentButton)
       activeCommentButton.className = '';
   active_idc = false;
}
function createCommentForm(sender, ide, idc, isParent, formTitle, showEmail)
{       
   hideCommentForm();
   active_idc          = idc;
   contCommentForm     = document.getElementById('comment-form-'+idc);  
   activeCommentButton = sender; 
   activeCommentButton.className = 'selected';
   if (contCommentForm)
   {
      _f = document.createElement('form');      
      _f.action    = '/ajax/';           
      _f.method    = 'post';     
      _f.className = 'comment-sendform';             
      _f.id        = 'comment-sendform-'+idc;        
      _f.onsubmit  = function () {                                
                          return sendComment();
                     }   
      contCommentForm.appendChild(_f); 
          
      _d = document.createElement('div');      
      _d.className = 'clear';   
      contCommentForm.appendChild(_d);      
      
              if (formTitle)
              { 
                  _h = document.createElement('h4'); 
                  _h.innerHTML = formTitle;   
                  _h.id = 'comment-header-'+idc;
                  _f.appendChild(_h);   
              }             
              _h = document.createElement('input');    
              _h.type  = 'hidden';   
              _h.name  = 'comment-ide';
              _h.value = ide;    
              _f.appendChild(_h);   
      
              _lc = document.createElement('label'); 
              _lc.htmlFor = 'comment-text-'+idc;
              _lc.innerHTML = 'Treść komentarza:';
              _f.appendChild(_lc);     
              
              _c = document.createElement('textarea');      
              _c.id   = 'comment-text-'+idc;
              _c.name = 'comment-text';
              _c.rows = 5;           
              _c.cols = 45;        
              _c.className = 'comment-edit edit';   
              _f.appendChild(_c);
              _c.focus();   
              
              _ec = document.createElement('div');      
              _ec.id   = 'comment-error-text-'+idc;
              _ec.innerHTML = '';       
              _ec.className = 'comment-error error';   
              _f.appendChild(_ec);
      
              _la = document.createElement('label'); 
              _la.htmlFor = 'comment-author-'+idc;
              _la.innerHTML = 'Twój podpis:';
              _f.appendChild(_la);
      
              _a = document.createElement('input');   
              _a.id   = 'comment-author-'+idc;
              _a.name = 'comment-author';    
              _a.type = 'text';
              _a.size = 45;        
              _a.className = 'comment-edit edit';    
              _f.appendChild(_a); 
              
              _ea = document.createElement('div');      
              _ea.id   = 'comment-error-author-'+idc;
              _ea.innerHTML = '';       
              _ea.className = 'comment-error error';   
              _f.appendChild(_ea);
                                
              if (showEmail)
              {              
                 _le = document.createElement('label'); 
                 _le.htmlFor = 'comment-email-'+idc;
                 _le.innerHTML = 'Twój e-mail:';
                 _f.appendChild(_le);
                       
                 _e = document.createElement('input');     
                 _e.id   = 'comment-email-'+idc;
                 _e.name = 'comment-email';
                 _e.type = 'text';
                 _e.size = 45;       
                 _e.className = 'comment-edit edit';          
                 _f.appendChild(_e);  
                        
                 _ee = document.createElement('div');      
                 _ee.id   = 'comment-error-email-'+idc;
                 _ee.innerHTML = '';       
                 _ee.className = 'comment-error error';   
                 _f.appendChild(_ee);  
              }                            
              if (isParent)
              {
                 _p = document.createElement('input');    
                 _p.type  = 'hidden';   
                 _p.name  = 'comment-parent';
                 _p.value = idc;    
                 _f.appendChild(_p);
              }        
              
              _ee = document.createElement('div');      
              _ee.id   = 'comment-error-unknow-'+idc;
              _ee.innerHTML = '';       
              _ee.className = 'comment-error error';   
              _f.appendChild(_ee);         
              
              _d = document.createElement('div');    
              _d.className = 'ta_right';          
              _f.appendChild(_d);    
              
                 _s = document.createElement('input');    
                 _s.name = 'comment-send';
                 _s.type = 'submit';
                 _s.value = 'Wyślij'; 
                 _s.className = 'comment-button button';          
                 _d.appendChild(_s);      
              
                 _r = document.createElement('input');    
                 _r.type = 'reset';
                 _r.value = 'Wyczyść';       
                 _r.className = 'comment-button button';          
                 _d.appendChild(_r);      
              
                 _a = document.createElement('input');    
                 _a.type = 'button';
                 _a.value = 'Anuluj';
                 _a.onclick = hideCommentForm;      
                 _a.className = 'comment-button button';          
                 _d.appendChild(_a);    
   }
}                

function showComments(ide)
{                      
   _c  = document.getElementById('comments');   
   if (typeof ide == "number")
   {
      advAJAX.post(
      {               
          url: '/ajax/',
          parameters : {          
             "get_comments": "true",
             "ide" : ide
          },     
          onSuccess:
              function(obj)
              {                                   
                 if (_c)
                     _c.innerHTML = obj.responseText;
              },               
          onLoading:
              function(obj)
              {                    
                 if (_c)
                     _c.innerHTML = '<div class="wait">Proszę czekać... <br />Trwa pobieranie listy komentarzy</div>';
              },                       
          onInitialization:
              function(obj)
              {                    
                 if (_c)
                     _c.innerHTML = '<div class="wait">Proszę czekać...</div>';
              },                                                                                   
          onError:
              function(obj)
              {
                  alert( 'Error: ' + obj.status );
              }
      });        
   }             
}

//webcard  
                
var active_webCard = false        
                
function hideWebCard()
{
   if (active_webCard)
       active_webCard.innerHTML = '';
   active_webCard = false;
}
function createWebCard(webCardElement, pageUrl, defTitle)
{       
   hideWebCard();
   webCard = document.getElementById(webCardElement);    
   active_webCard = webCard;
   if (webCard)
   {
      advAJAX.post(
      {               
          url: '/ajax/',
          parameters : {          
             "www_card": "true",  
             "url": pageUrl,
             "title" : defTitle
          },     
          onSuccess:
              function(obj)
              {                                   
                 if (webCard)
                     webCard.innerHTML = obj.responseText;
              },               
          onLoading:
              function(obj)
              {                    
                 if (webCard)
                     webCard.innerHTML = '<div class="wait">Proszę czekać... <br />Trwa pobieranie informacji o stronie...</div>';
              },                       
          onInitialization:
              function(obj)
              {                    
                 if (webCard)
                     webCard.innerHTML = '<div class="wait">Proszę czekać...</div>';
              },                                                                                   
          onError:
              function(obj)
              {
                  alert( 'Error: ' + obj.status );
              }
      });        
   }
}   

/* super-large-box*/

var slbImage = false;       
var slbTitle = false;      
var slbArea  = false;   
var canRunEffect = true; 
var currentLargeBoxItem = 0;  
var lastLargeBoxItem = 0;    

function showSuperLargeBoxItem(itemIndex)
{      
    if (!slbArea)
       slbArea  = document.getElementById("super_large_box_area");  
    if (!slbImage)
       slbImage = document.getElementById("super_large_box_image");        
    if (!slbTitle)
       slbTitle = document.getElementById("super_large_box_title");        
    function runEffect()
    {     
        if (canRunEffect)
        {   
            canRunEffect = false; 
                                          
            $("#super_large_box_title").hide();
            var options = {};
            if (super_large_box_effect == 'scale')
                options = {percent: 100}; 
            else 
            if (super_large_box_effect == 'size')
                options = {to: {width: 280,height: 185} };            
            $("#super_large_box_area").hide(super_large_box_effect, options, 500, runEffectPartII);
        }   
    };
    function runEffectPartII()
    {                                 
        var options = {};
        if (super_large_box_effect == 'scale')
            options = {percent: 100}; 
        else 
        if (super_large_box_effect == 'size')
            options = {to: {width: 280,height: 185} };            
        slbImage.style.backgroundImage = 'url('+super_large_box_items[currentLargeBoxItem][2]+')';
        $("#super_large_box_area").show(super_large_box_effect, options, 500, 
                                               function () 
                                               {
                                                 $("#super_large_box_title").show();   
                                                 canRunEffect = true;
                                               }
                                            );
    };                                                    
    if ((lastLargeBoxItem != itemIndex)) 
    {                                                 
       if (slbArea && slbImage && slbTitle)
       {                      
           currentLargeBoxItem = itemIndex;   
           if (lastLargeBoxItem>0)    
           {
               if (canRunEffect)     
                   runEffect(); 
               else
                   slbImage.style.backgroundImage = 'url('+super_large_box_items[itemIndex][2]+')';
           }
           slbTitle.innerHTML = super_large_box_items[itemIndex][0];
           if (lastLargeBoxItem>0)         
           {            
              slbLink = document.getElementById('super_large_box_link_'+lastLargeBoxItem);   
              slbLink.className = slbLink.className.replace('selected', '');  
           }    
       
           slbLink = document.getElementById('super_large_box_link_'+itemIndex);   
           slbLink.className += ' selected';   
           slbArea.style.cursor = 'pointer';
           slbArea.onclick = function () {
                                location = super_large_box_items[itemIndex][1];   
                             }
           lastLargeBoxItem = itemIndex;   
       }
    }
}    
