var NS4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var IE4 = (document.all && !document.getElementById)? true : false;
var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;

function get_page_part(url,nazwafunkcji,content_id)
{
  var xmlHttp = false;
  if (window.XMLHttpRequest)
  {
    xmlHttp = new XMLHttpRequest();
    if (xmlHttp.overrideMimeType) { xmlHttp.overrideMimeType('text/xml'); }
  }
  else if (window.ActiveXObject)
  {
     try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
     catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {;}; }
  }

  xmlHttp.onreadystatechange = function ()
  {
    if (xmlHttp.readyState == 4)
    {
      if (xmlHttp.status == 200)
      {
        if (window.XMLHttpRequest)
        {
          var xmldoc = xmlHttp.responseText;
        }
        else if (window.ActiveXObject)
        {
          var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
          //xmldoc.loadXML(xmlHttp.responseText);
          xmldoc=xmlHttp.responseText;
        }
        if(content_id.length>0) document.getElementById(content_id).innerHTML=xmldoc;
        if(nazwafunkcji.length>0) eval(nazwafunkcji+'(xmldoc);');
      }
      else
      {
        if(content_id.length>0) document.getElementById(content_id).innerHTML='';
        if(nazwafunkcji.length>0) eval(nazwafunkcji+'(false);');
        //eval(nazwafunkcji+'(false);');
      }
    }
  }

  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);

}

function load_drzewko_cid(cid)
{
   get_page_part('index.php?action=get_drzewko&cid='+cid,'show_drzewko','category_tree');
}

function load_drzewko_cmid(cmid)
{
   get_page_part('index.php?action=get_drzewko&cmid='+cmid,'show_drzewko','category_tree');
}


function show_drzewko()
{
   eval(document.getElementById('categories_js').innerHTML);
   koloruj();
   get_page_part('index.php?action=get_filter','show_filter','');
   get_page_part('index.php?action=get_curr_cat','','categories_main');
   get_page_part('index.php?action=get_products','','product_listing_main');
}

function show_filter(xmldoc)
{
   //document.getElementById('filter').style.display='none';
   document.getElementById('filter').innerHTML=xmldoc;

   eval(document.getElementById('attributes_js').innerHTML);
   hide_all();
   document.getElementById('filter').style.display='';
}

function show_products(page,ipr)
{
   if(page>0)
      get_page_part('index.php?action=get_products&page='+page,'','product_listing_main');
   else if(ipr>0)
      get_page_part('index.php?action=get_products&ipr='+ipr,'','product_listing_main');
}

function klikniecie(id,pm,ggg)
{
   var hihi;
   for(i=0,n=cdata.length;i<n;i++)
      if(cdata[i][0]==id) hihi=i;
   if(cdata[hihi+1][1]==id&&document.getElementById('kat'+cdata[hihi+1][0]).style.display=='none')
   {
      odkryj(id);
      document.getElementById('img_'+id).src='images/system/tree_m'+pm+ggg+'.gif';
   }
   else
   {
      ukryj(id,ggg);
      document.getElementById('img_'+id).src='images/system/tree_p'+pm+ggg+'.gif';
   }
   //koloruj();
}

function czy_je_pa(id)
{
   var i,hihi=0,n;
   for(i=0,n=cdata.length;i<n;i++)
      if(cdata[i][1]==id) hihi=1;
   if(hihi==1) return true;
   else return false;
}

function odkryj(id)
{
   var i,hihi=0,n;
   for(i=0,n=cdata.length;i<n;i++)
      if(cdata[i][1]==id) document.getElementById('kat'+cdata[i][0]).style.display='';
}

function ukryj(id,ggg)
{
   var i,hihi=0,n;
   for(i=0,n=cdata.length;i<n;i++)
      if(cdata[i][1]==id)
      {
         document.getElementById('kat'+cdata[i][0]).style.display='none';
         if(document.getElementById('img_'+cdata[i][0]))
         {
            pm='l';
            for(j=i+1;j<n;j++) if(cdata[i][1]==cdata[j][1]) pm='e';
               document.getElementById('img_'+cdata[i][0]).src='images/system/tree_p'+pm+ggg+'.gif';
         }
         ukryj(cdata[i][0]);
      }
}

function koloruj()
{
   var i,hihi=0,n;
   for(i=0,n=cdata.length;i<n;i++)
      if(document.getElementById('kat'+cdata[i][0]).style.display!='none')
      {
         if(hihi==0) document.getElementById('kat'+cdata[i][0]).style.background='#f5f5f5';
         else document.getElementById('kat'+cdata[i][0]).style.background='#ffffff';;
         if(hihi==0)hihi=1;
         else hihi=0;
      }
}

function popup_image(url)
{
   window.open('popup.php?url='+url,'popup_image','width=100,height=100,location=no,menubar=no,scrollbars=no,resizable=yes,directory=no,status=no');
   return;
}

function popup_rma(act)
{
   window.open('rma.php?'+act,'popup_rma','width=800,height=600,location=no,menubar=no,scrollbars=no,resizable=yes,directory=no,status=no');
   return;
}

function check_attrib(id)
{
   var naco='',i,n,j,m;
   if(document.getElementById('a_'+id).checked) naco='';
   else naco='none';

   for(i=0,n=attributes.length;i<n;i++)
      if(attributes[i][0]==id) for(j=0,m=attributes[i][1].length;j<m;j++) document.getElementById(attributes[i][1][j]).style.display=naco;
   return;
}

function check_attribByForm(id, tf)
{
   var naco='',i,n,j,m;
   if(tf.elements['a_'+id].checked) naco='';
   else naco='none';

   for(i=0,n=attributes.length;i<n;i++)
      if(attributes[i][0]==id) for(j=0,m=attributes[i][1].length;j<m;j++) document.getElementById(attributes[i][1][j]).style.display=naco;
   return;
}


function hide_all()
{
   var i,n,j,m,naco;
   for(i=0,n=attributes.length;i<n;i++) check_attrib(attributes[i][0]);
   return;
}

function waduj_pl()
{
   var i=0;
   document.getElementById('przeslona').style.height=document.getElementById('main_products').offsetHeight-4;
   document.getElementById('przeslona').style.width=document.getElementById('main_products').offsetWidth-4;
   if(IE4||IE5)document.getElementById('przeslona').style.filter='alpha(opacity=90)';
   if(NS6)document.getElementById('przeslona').style.MozOpacity=90/100;
}










function kliknieciecms(id,pm)
{
   var hihi;
   for(i=0,n=cmsdata.length;i<n;i++)
      if(cmsdata[i][0]==id) hihi=i;
   if(cmsdata[hihi+1][1]==id&&document.getElementById('cms_kat'+cmsdata[hihi+1][0]).style.display=='none')
   {
      odkryjcms(id);
      document.getElementById('cms_img_'+id).src='images/system/tree_m'+pm+'.gif';
   }
   else
   {
      ukryjcms(id);
      document.getElementById('cms_img_'+id).src='images/system/tree_p'+pm+'.gif';
   }
   kolorujcms();
}

function czy_je_pacms(id)
{
   var i,hihi=0,n;
   for(i=0,n=cmsdata.length;i<n;i++)
      if(cmsdata[i][1]==id) hihi=1;
   if(hihi==1) return true;
   else return false;
}

function odkryjcms(id)
{
   var i,hihi=0,n;
   for(i=0,n=cmsdata.length;i<n;i++)
      if(cmsdata[i][1]==id) document.getElementById('cms_kat'+cmsdata[i][0]).style.display='';
}

function ukryjcms(id)
{
   var i,hihi=0,n;
   for(i=0,n=cmsdata.length;i<n;i++)
      if(cmsdata[i][1]==id)
      {
         document.getElementById('cms_kat'+cmsdata[i][0]).style.display='none';
         if(document.getElementById('cms_img_'+cmsdata[i][0]))
         {
            pm='l';
            for(j=i+1;j<n;j++) if(cmsdata[i][1]==cmsdata[j][1]) pm='e';
               document.getElementById('cms_img_'+cmsdata[i][0]).src='images/system/tree_p'+pm+'.gif';
         }
         ukryjcms(cmsdata[i][0]);
      }
}

function kolorujcms()
{
   var i,hihi=0,n;
   for(i=0,n=cmsdata.length;i<n;i++)
      if(document.getElementById('cms_kat'+cmsdata[i][0]).style.display!='none')
      {
         if(hihi==0) document.getElementById('cms_kat'+cmsdata[i][0]).style.background='#f5f5f5';
         else document.getElementById('cms_kat'+cmsdata[i][0]).style.background='#ffffff';;
         if(hihi==0)hihi=1;
         else hihi=0;
      }
}

function popup(akcja)
{
  var Win = window.open('index.php?'+akcja,'okno','width=430,height=500,resizable=1,top=100,left=350,scrollbars=yes,menubar=no,status=yes');
  Win.focus()
}

function popupZam(akcja)
{
  var Win = window.open('zamowienie.php?'+akcja,'okno','width=430,height=500,resizable=1,top=100,left=350,scrollbars=yes,menubar=no,status=yes');
  Win.focus()
}

function checkUwagi(tt)
{
 var maxChar=160;
 var ileZnakZ=document.getElementById('ileZnak');

 this.chColor = function (bgcolor)
 {
   tt.style.backgroundColor=bgcolor;
 }

 var self = this;
 if(tt.value.length>maxChar)
 {
   setTimeout( function () {self.chColor('red');},1);
   setTimeout( function () {self.chColor('white');},300);
   setTimeout( function () {self.chColor('red');},500);
   setTimeout( function () {self.chColor('white');},800);
   tt.value = tt.value.substr(0,maxChar);
 }
 if (tt.value.length == maxChar) ileZnakZ.innerHTML = '<span style="color:red">MAX</span>';
 else ileZnakZ.innerHTML = '('+tt.value.length+'/'+maxChar+')';
}

function set_panel_id()
{
  document.cookie='panel_id='+panel_id+'';
}

function showFull(obj_id, maxW, maxH)
{
  var win = window;

  if (maxW=='auto')
  {
    if(typeof win.pageXOffset != 'undefined')
    {
      maxW = parseInt(parseInt(win.innerWidth)/2);
    }
    else
    {
      var obj = (win.document.compatMode && win.document.compatMode == "CSS1Compat")?win.document.documentElement:win.document.body || null;
      maxW = parseInt(parseInt(obj.clientWidth)/2);
    }
  }

  if (maxH=='auto')
  {
    if(typeof win.pageXOffset != 'undefined')
    {
      maxH = parseInt(parseInt(win.innerHeight)/2);
    }
    else
    {
      var obj = (win.document.compatMode && win.document.compatMode == "CSS1Compat")?win.document.documentElement:win.document.body || null;
      maxH = parseInt(parseInt(obj.clientHeight)/2);
    }
  }

/*
  if (maxW=='auto')
    maxW = parseInt(parseInt(document.getElementsByTagName('body').item(0).clientWidth)/2);
  if (maxH=='auto')
    maxH = parseInt(parseInt(document.getElementsByTagName('body').item(0).clientHeight)/2);
*/
  this.maxW = maxW;
  this.maxH = maxH;
  this.fImg = document.getElementById(obj_id);
  this.xImg = this.fImg.getElementsByTagName('img').item(0);
  this.image = document.createElement('img');
  this.h=0;
  this.w=0;
  this.start_xImg=false;
  this.start_fImg=false;
  this.start=false;

  this.timer = null;
  var self = this;

  this.xImg.onmouseout = function ()
   {
     self.start_xImg=false;
     self.timer=setTimeout(function () {self.off()}, 100);
   }

  this.xImg.onmouseover = function ()
   {
     self.start_xImg=true;
   }
/*
  this.fImg.onmouseout = function ()
   {
     self.start_fImg=false;
     self.timer=setTimeout(function () {self.off()}, 100);
   }
  this.fImg.onmouseover = function ()
   {
     self.start_fImg=true;
   }
*/

  this.show=function (srcc)
   {
     if (self.start==false&&self.start_xImg==false&&self.start_fImg==false)
     {
       self.start=true;
       self.xImg.style.display='none';
       self.xImg.src = 'images/system/ajax_loader.gif';
       self.xImg.style.width=10;
       self.xImg.style.height=10;
       self.xImg.style.display='';

       var win = window;
       if(typeof win.pageXOffset != 'undefined')
       {
         self.fImg.style.top = (parseInt(win.pageYOffset)+5)+'px';
       }
       else
       {
         var obj = (win.document.compatMode && win.document.compatMode == "CSS1Compat")?win.document.documentElement:win.document.body || null;
         self.fImg.style.top = (parseInt(obj.scrollTop)+5)+'px';
       }
       
       self.fImg.style.left = 5+'px';
       self.fImg.style.display = '';
       self.image.src=srcc;
       if (self.image.complete) self.image.onload();
     }
   }

  this.image.onload=function ()
   {
     self.w = parseInt(self.image.width);
     self.h = parseInt(self.image.height);

     if (self.w>self.maxW||self.h>self.maxH)
     {
       if (self.w>self.maxW)
       {
         var prop = self.maxW/self.w;
         self.w=self.maxW;
         self.h=parseInt(self.h*prop);
       }
     
       if (self.h>self.maxH)
       {
         var prop = self.maxH/self.h;
         self.h=self.maxH;
         self.w=parseInt(self.w*prop);
       }

     }
     self.image.style.width=self.w+'px';
     self.image.style.height=self.h+'px';
     self.fImg.style.display='none';
     self.xImg.style.display='none';
     self.xImg.style.width=self.w+'px';
     self.xImg.style.height=self.h+'px';
     self.xImg.src=self.image.src;
     self.xImg.style.display='';
     self.fImg.style.display='';
   }
   
  this.hide=function ()
   {
     self.start=false;
     self.timer=setTimeout(function () {self.off()}, 200);
   }

  this.off=function ()
   {
     if (self.start==false&&self.start_xImg==false&&self.start_fImg==false)
     {
       self.fImg.style.display = 'none';
       self.xImg.style.width=0+'px';
       self.xImg.style.height=0+'px';
     }
   }
}

function pprint(str)
{
  document.title=str;
}

function print_r(input) {
var ret;
  for(var i in input) {
   ret += "["+i+"] = "+input[i]+"<br>\n";
  }
  document.write(ret);

}

function zagiel_raty_calcx(sn,tb,pid) {

  var sil = undefined;
  var min_s=200;
  if (document.getElementById('p_kile_'+pid))
    sil = document.getElementById('p_kile_'+pid).value;

  if (typeof(sil)!='undefined' && parseInt(sil)>1) tb*=sil;

  if (tb>min_s)  
    window.open('http://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+sn+'&goodsValue='+tb, 'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
  else
   alert(langV.getLV('zagel_info')+min_s);
}

function zagiel_raty_calc_bsk(sn) {
  var min_s=200;
  if (document.getElementById('k_suma_x'))
    tb = parseFloat(document.getElementById('k_suma_x').innerHTML);

  if (tb>min_s)  
    window.open('http://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+sn+'&goodsValue='+tb, 'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
  else
   alert(langV.getLV('zagel_info')+min_s);
}


window.onbeforeunload=new Function("set_panel_id();");
