var url = location.href;
var baseURL = url.substring(0, url.indexOf('/', 14))+'/';

function includeJavaScript(jsFile)
 {
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></script>'); 
 }

var Cookie = {
  set: function(name, value, daysToExpire) {
    var path= ';  path=/';
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire + path);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};


function toggleMenu(cat) {

  if (menuclickable==false) return false;

  if ($(cat).style.display == "none") 
	 {
    menuclickable=false;
    $('m'+cat).className = 'kat_rozwinieta';
    Effect.BlindDown($(cat),{duration:0.5});
    catMenuCookie[catMenuCookie.size()]=cat.substr(1);
    Cookie.set('catMenu',catMenuCookie);
    setTimeout("menuclickable=true",500);
   } else {
    menuclickable=false;
    $('m'+cat).className = 'kat_zwinieta';
    Effect.BlindUp($(cat),{duration:0.5});
    catMenuCookie=catMenuCookie.without(cat.substr(1));
    Cookie.set('catMenu',catMenuCookie);
    setTimeout("menuclickable=true",500);
   }
}

function $RF(form, radioGroup) 
 {
  var checked = $(form).getInputs('radio', radioGroup).find(
    function(re) {return re.checked;}
   );
  return (checked) ? $F(checked) : null;
 }

function doListy (pid,wid,listyDivId)
 {
  if ($('lista_id')) lista_id=$F('lista_id'); else lista_id=0;
  if ($('lista_nazwa')) lista_nazwa=$F('lista_nazwa'); else lista_nazwa='';
  
  new Ajax.Updater(listyDivId,baseURL+'Listy-dodaj-produkt.html', 
  {
   parameters: { lista_id: lista_id, lista_nazwa: lista_nazwa, pid: pid, wid: wid},
   method: 'post',
   evalScripts: true,
   asynchronous: true
  });
  return false;
 }

function wyswietlStrefe(strefa_id,div_id,kid,mid)
 {
  if (!kid) var kid=0;
  if (!mid) var mid=0;

  if (typeof(Horinaja) == "undefined") includeJavaScript('http://static.intelishop.pl/js/horinaja/horinaja.js');
  
  document.observe("dom:loaded", function() {
    new Ajax.Updater(div_id,baseURL+'Bannery-strefa.html?id='+strefa_id+'&kid='+kid+'&mid='+mid,
     {
      method: 'get',
      asynchronous: true,
      evalScripts: true
     } );
   } );
 }

function zagielPoliczRate(numerSklepu,koszyk) 
 { 
  window.open('https://www.eraty.pl/symulator/oblicz.php?numerSklepu='+numerSklepu+'&wariantSklepu=1&typProduktu=0&wartoscTowarow='+koszyk, 'Policz_rate', 'width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no'); 
 }
 
function zagielValidate() 
 { 
  if ($('ratyDiv').visible()==false)
   {
    return true;
   }
  else if ($('ratyZgoda').checked==false)
   { 
    alert ("Zanim złożysz zamówienie, zapoznaj się z procedurą udzielenia kredytu ratalnego eRaty Żagiel."); 
    return false; 
   } 
  else 
   { 
    return true; 
   } 
 } 

