var size = 800;
var tresc = '';
var loading = false;


if(document.location.pathname.length > 1)
{ 
  path = document.location.pathname.replace('.html', '');
  path = path.slice( path.lastIndexOf('/') + 1 );
  document.location.hash = '#'+path;
}
if(navigator.appVersion.indexOf('MSIE 6.0', 0) == -1)
   hasz = document.location.hash.slice(1);
else
   hasz = '';

if(hasz == '')
   location.hash = 'home';

   
function stats()
{
  x = document.location.hash.slice(1);;
  
  var f=top.document.referrer;
  f=escape(f);
  f=f.replace(/&/g,'%A7%A7');
  if((f=='null') || (f=='unknown') || (f=='undefined')) f='';
  var w=screen.width;
  var h=screen.height;
  var rand=Math.round(100000*Math.random());
  var browser=navigator.appName;
  var t=escape(document.title)+" ("+x+")";
  var NS_url="";
  if(browser!="Netscape") c=screen.colorDepth; else  c=screen.pixelDepth;
  NS_url=document.URL + x;
  NS_url=escape(NS_url);
  NS_url=NS_url.replace(/&/g,"%A7%A7");
  var sc1="<img src='http://www.ndesign.pl/stats/php-stats.php?&w="+w+"&h="+h +"&c="+c+"&k="+rand+"&f="+f+"&NS_url="+NS_url+"&t="+t+"' alt='' width='1' height='1' />";
  document.getElementById('staty').innerHTML = sc1;
}   
   
   
   
   
   
   
   
function zwin()
{
  if(size > 24)
  {
    size = size - 25;
    document.getElementById('text').style.clip = 'rect(0px 768px ' + size + 'px 0px)';
    window.setTimeout("zwin();", 1);
  }
  else
    pokaz();
}
function rozwin()
{
  if(size < 800)
  {
    size = size + 25;
    document.getElementById('text').style.clip = 'rect(0px 768px ' + size + 'px 0px)';
    window.setTimeout("rozwin();", 1);
  }
  else
  {
    loading = false;
    document.getElementById('container').style.cursor = 'default';
    if(navigator.appVersion.indexOf('MSIE 6.0', 0) == -1)
      hasz = document.location.hash.slice(1);
  }
}


function pokaz( strona ){
  if(typeof strona == "undefined")
    strona = loading;
  else
    loading = strona;

  if(loading && strona != top)
  {
    if(navigator.appVersion.indexOf('MSIE 6.0', 0) == -1)
      location.hash = '#'+ loading;  

  
  advAJAX.get({
    url: 'ajax.php',
    parameters : {
      "link" : strona
    },
    onSuccess : function(obj) 
    { 
      document.getElementById('text').innerHTML = obj.responseText;
      rozwin();
      linki();
      stats();
    }
  });
  }
}


function laduj( ls )
{    
  if(!loading && hasz != ls)
  {
    loading = ls;
    document.getElementById('container').style.cursor = 'wait';

      zwin();
  }  
}


function ladujStrone()
{
  sznur = this.getAttribute('href');
  sznur = sznur.slice( sznur.lastIndexOf('/') + 1 );
  laduj( sznur.replace('.html', '').replace('#', '') );
  return false;
}

function popup( )
{
  ls = this.getAttribute('href').replace('popup,', '');
  ls = ls.replace('.html','');
  if(document.all)ls = ls.slice(ls.lastIndexOf('/')+1);
  advAJAX.get({
    url: "popup.php",
    parameters : {
      "link" : ls
    },
    onSuccess : function(obj) 
    { 
      document.getElementById('popup').innerHTML = obj.responseText; 
      document.getElementById('popup').style.display = 'block';
      linki();
    }
  });
  return false;
}

function opinia(){
  o = document.getElementById('feedbackForm');
  advAJAX.assign(o, {
        url: "ajax.php?link=kontakt&opinia",
        onInitialization : function()
          {
            o.submit.value = "wysyłanie...";
          },
        onSuccess : function(obj) 
          { 
            o.submit.value = "wysłane";
            document.getElementById('feedThank').style.display = 'none';
          }
     });
}

function formularz(c){
   c.onsubmit = function()
   {
     err = document.getElementById('contactError');
     var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
     if(c.name.value == '')
     {
       err.innerHTML = 'Podaj imie i nazwisko<br />';
       return false;
     }
     else if(c.email.value == '' || c.email.value.indexOf('@') == -1)
     {
       err.innerHTML = 'Podaj poprawny adres email<br />';
       return false;
     }
     c.submit.value = "wysyłanie...";
    }
    advAJAX.assign(c, {
        url: "ajax.php?link=kontakt&ajax",
        onSuccess : function(obj) 
          { 
            if(obj.responseText == 'ok')
            {
              document.getElementById('form').innerHTML = '<br /><br />Formularz został wysałny.<br /><br />Dziękujemy.'
            }
            else
            {
               err.innerHTML = 'Wystąpił błąd przy wysyłaniu formularza.<br />' + obj.responseText;
               c.submit.value = "wyślij ponownie";
            }
          }
     });
   return false;
}

function linki()
{  
  var linki = document.getElementsByTagName('a');
  ile = linki.length;
  for(var i = 0; i < ile; i++)
  {
     rel = linki[i].getAttribute('rel');
     var kupa = linki[i];
     if(rel == 'popup')
     {
       linki[i].onclick = popup;
     }
     else if('mail' == rel)
     {
       linki[i].setAttribute('href', linki[i].getAttribute('href').replace('_N0SPAM(at)','@') );
       linki[i].innerHTML = linki[i].getAttribute('href').replace('mailto:', '');
     }
     else if(rel == 'opinia')
       linki[i].onclick = function(){ document.getElementById('feedback').style.display = 'block'; return false; }
     else if(rel == 'opiniaC')
       linki[i].onclick = function(){ document.getElementById('feedback').style.display = 'none'; return false; }
     else if(rel == 'out')
       linki[i].onclick = function(){ window.open(this.getAttribute('href'), 'nxd'); return false; }
     else if(rel == 'popupC')
       linki[i].onclick = function(){ document.getElementById('popup').style.display = 'none'; return false; }
     else if(!rel)
     {
       linki[i].onclick = ladujStrone;
       sznur = linki[i].getAttribute('href');
       sznur = sznur.slice( sznur.lastIndexOf('/') + 1 );
     }
       
  }
  
  c = document.getElementById('contactForm');
  if(c)
  {
     formularz(c);
  }

  
}
function onloader()
{
  advHistory.create(pokaz);
  
  opinia();  
  linki();
  
  f = document.getElementById('loginForm');
  inp = f.getElementsByTagName('input');
  ile = inp.length;
  

  
  for(i = 0; i < ile; i++)
  {
    val = inp[i].getAttribute('name');
    if(val == 'login' || val == 'pass')
    {
       inp[i].onfocus = function(){ if(this.value==this.name)this.value = ''; }
       inp[i].onblur = function(){ if(this.value=='')this.value = this.name; }       
    }
     
  }
  f.onsubmit = function()
    {
      f.submit.value = "logowanie...";
      advAJAX.post({
        url: "admin.php",
        parameters : {
         "login" : f.login.value,
         "pass" : f.pass.value
        },
         onSuccess : function(obj) 
          { 
            if(obj.responseText == 'ok')
               location.href = 'admin.php';
            else
            {
               document.getElementById('formError').innerHTML = obj.responseText;
               document.getElementById('formError').className = "error";
               f.submit.value = "zaloguj mnie";
            }
          }
      });
      return false;
    }
}





window.onload = onloader;