

<!--
var swfMenu = 'false';
var swfQuality = 'auto';

function BuildFlash(path, w, h, bckgColor, vars, name, live) {
    var str = '';
    var wmode = 'transparent';
    if ((path != '') && (path != undefined))  {
        str = '<object type="application/x-shockwave-flash" data="'+ path +'" width="'+ w +'" height="'+ h +'" id="'+ name +'">' +
        '<param name="movie" value="'+ path +'"/>' +
        '<param name="quality" value="' + swfQuality + '"/>' +
        '<param name="bgcolor" value="'+ bckgColor +'"/>' +
        '<param name="wmode" value="'+ wmode +'"/>' +
        '<param name="menu" value="' + swfMenu + '"/>' +
        '<param name="flashvars" value="' + vars + '"/>' +
        '<param name="allowScriptAccess" value="sameDomain" />' +
        '</object>';
    }
    document.write(str);
}

function BuildFlashOld(path, w, h, bkg, vars, name, live) {
var str;
if (path!='') str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  WIDTH="'+ w +'" HEIGHT="'+ h +'" id="'+ name +'" ALIGN="">' +
 '<param name="movie" value="'+ path +'"><param name="quality" value="high"><param name="bgcolor" value="'+ bkg +'"><param name="menu" value="false">' +
 '<param name="flashvars" value="' + vars + '">' +
 '<EMBED src="'+ path +'" FlashVars="' + vars + '" quality="high" bgcolor="'+ bkg +'" WIDTH="'+ w +'" HEIGHT="'+ h +'" NAME="'+ name +'" swLiveConnect='+ live +' ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>' +
 '</object>' ;
  //return str;
  document.write(str);
}
function escapeURI(str) {
  str = str.replace(/=/g, '%3D'); 
  str = str.replace(/&/g, '%26');
  str = str.replace(/"/g, '%22');
  return str;
}
function test() {
  alert('test');
}
function getQuerryStringByName(name){
  url = new String(window.location);
  var xx=String(document.location.search);
  str_tmp = url.split("?");
  
  if( str_tmp.length < 2 ) return "";
  querry = str_tmp[1];
  
  if (xx.match(/%20\w+=/)) // haszcz
  { 
    element = querry.split(escape("&"));
  }
  else // bez haszcza
  {
    element = querry.split("&");
  }  
  i=0;
  while(i<element.length){
      e = element[i];
      _item =  e.split("=");
      if(_item[0] == name){
        return _item[1];
      }
      i++;
  }
  return "";
}


function mouseOver(n,pathOver)
{
document[n].src=pathOver;
}
function mouseOut(pathOut)
{
document[n].src=pathOut;
}


var pWin = null;
function popUpZT(src,x,y) {
    if (src == '') return;
    var str = '<ht'+'ml><he'+'ad><title>AVIKO Spotkajmy się przy stole</title></he'+'ad><bo'+'dy bgcolor="#FFFFFF" topmargin="0" leftmargin="0"><a href="javascript:self.close()"><img src='+src+' border="0"></a></bo'+'dy></ht'+'ml>';
 if (!pWin || pWin.closed) {
  pWin = window.open('','pWin','dependent=yes,resizable=no,scrollbars=no,statusbar=no,toolbar=no,width='+eval(x)+',height='+eval(y)+',menubar=no,left=0,top=0')
 }
 pWin.document.open();
 pWin.document.write(str);
 pWin.document.close();
 pWin.focus();
}

function authorEmail(s){
        var s2 = '';
        for(var i = 0; i < s.length; i++){
                s2 += String.fromCharCode(s.charCodeAt(i) + 1 );
        }
        document.location.href="mailto:" + s2;
}

function writeEmail(encodedEmail, label) {
var str = '<a href="javascript:authorEmail(\''+encodedEmail+'\')">'+label+'</a>';
document.write(str);
}


$(document).ready(function(){
  
  var activePage = 1;
  function recepturaSearch(form, d, header){
   $.ajax({
    url: form.attr("action"),
    dataType: "json",
    type: "GET",
    data: d + "&mode=get",
    success: function(json){
     if ($("#receptura_list").length > 0) {
      var div = $("#receptura_list");
     } else if ($("#receptura_main").length > 0) {
      var div = $("#receptura_main");
     }
     if (json.count !== 0) {
         
      var content = "";
      jQuery.each(json.result, function(id, val) {
       content +=
       '<div class="receptura_list_item"><img src="/_images/receptury_lista_top.gif" alt="" />' +
       '<img class="mini" src="' + val.obrazek + '" alt="" />' +
       '<h2><span>' + val.tytul1 + '</span> ' + val.tytul2 + '</h2>' +
       '<div class="link"><a href="' + val.link + '"><img src="/_images/btn_receptura_pokaz.gif" alt="" /></a></div>' +
       '<img src="/_images/receptury_lista_bottom.gif" alt="" />' +
       '</div>'
      });
         
      var arr = [];
      $("form#f_receptury_boxes select option:selected[value!=0]").each(function(){
       arr[arr.length] = $(this).text();
      });
         
      var pages = "";
      if (json.pages > 1) {
       for (var x = 1; x <= json.pages; x++) {
        pages += (x === activePage) ? '<li id="active">' + x + '</li>' : '<li>' + x + '</li>';
       }
       pages = '<li id="prev">&laquo;</li>' + pages + '<li id="next">&raquo;</li>';
      }
      div.fadeOut(function(){
       var h = (header) ? header : arr.join(", ");
       $(this).html('<h1 class="cat">' + h + '</h1>' + content);
       $.cookie("aviko_actionBack", $("h1.cat").text() + "?#" + form.attr("id") + "?" + d, {path: '/', expires: 1});
       if (json.pages > 1) {
        $(this).append('<div id="receptura_pages"><ul>' + pages + '</ul></div>').show();
        $(this).find("#receptura_pages ul li:not(:first,:last)").click(function(){
         $(this).attr("id","active").siblings("#active").removeAttr("id");
         
         var temp_d = d.split("&");
         for (var x = 0; x < temp_d.length; x++) {
      if (temp_d[x].match("page=")) {
      temp_d.splice(x, 1);
      }
         }
     d = temp_d.join("&");
         
         activePage = parseInt($(this).text());
         d = d + "&page=" + activePage;
         recepturaSearch(form, d, h);
         
         
        });
           
        $(this).find("#receptura_pages ul li#prev").click(function(){
         if (activePage > 1) {
          div.find("#receptura_pages ul li#active").prev().click();
         }
        });
           
        $(this).find("#receptura_pages ul li#next").click(function(){
         if (activePage < json.pages) {
          div.find("#receptura_pages ul li#active").next().click();
         }
        });
       } else {
        $(this).show();
       }
         
      });
     } else {
      div.html('<h1 class="cat">Wyniki wyszukiwania</h1><p>Niestety nic nie znaleziono, spróbuj zmienić wyszukiwane hasło.</p>')
      return false;
     }
    }
   });
  }
  $("#receptura_list div.receptura_list_item a").click(function(){
    $.cookie("aviko_actionBack", null, {path: '/', expires: 1});
  });

function toUnicode(theString) {
 var unicodeString = '';
 for (var i=0; i < theString.length; i++) {
  switch(theString.charCodeAt(i)) {
  case 261:
  case 225:
  case 263:
  case 269:
  case 281:
  case 233:
  case 283:
  case 237:
  case 322:
  case 324:
  case 243:
  case 246:
  case 337:
  case 345:
  case 347:
  case 353:
  case 357:
  case 250:
  case 252:
  case 369:
  case 367:
  case 253:
  case 380:
  case 378:
  case 382:
  case 260:
  case 193:
  case 262:
  case 268:
  case 280:
  case 201:
  case 282:
  case 205:
  case 321:
  case 323:
  case 211:
  case 214:
  case 336:
  case 344:
  case 346:
  case 352:
  case 356:
  case 218:
  case 220:
  case 368:
  case 366:
  case 221:
  case 379:
  case 377:
  case 381:
  case 45:
   var theUnicode = theString.charCodeAt(i).toString(16).toUpperCase();
   while (theUnicode.length < 4) {
    theUnicode = '0' + theUnicode;
   }
   theUnicode = '\\u' + theUnicode;
   unicodeString += theUnicode;
   break;
  default:
   unicodeString += theString.charAt(i);
  }
 }
 return unicodeString;
}

  
  $("form#f_search").submit(function(){
    if ($.cookie("aviko_actionBack")) $.cookie("aviko_actionBack", null, {path: '/', expires: 1});
    $("form#f_receptury_boxes select").each(function(){
        $(this).children("option:first").attr("selected","selected");
    });
        var d = "search=" + toUnicode($(this).find("input[name=search]").val());
        activePage = 1;
  
        recepturaSearch($(this), d, $(this).find("input[name=search]").val());
        return false;
    });
    $("form#f_receptury_boxes").submit(function(){
    if ($.cookie("aviko_actionBack")) $.cookie("aviko_actionBack", null, {path: '/', expires: 1});
    $("form#f_search").find("input[name=search]").val("").blur();
        var d = "";
        activePage = 1;
        $(this).find("select").each(function(){
        d += $(this).attr("name") + "=" + $(this).children(":selected").val() + "&";
        });
        d = d.slice(0, d.length - 1);
        
        recepturaSearch($(this), d);
        return false;
    });
    if ($("#f_search").length > 0) {
      $("#f_search input[type=text]:eq(0)").click(function(){
       if ($(this).val() === "Wpisz szukaną frazę") $(this).val("");
      });
      $("#f_search input[type=text]:eq(0)").blur(function(){
       if ($(this).val() === "") $(this).val("Wpisz szukaną frazę");
      });
     }
   
   
   $("#receptura_main ul li:eq(0) img").click(function(){
  window.print();
   });
$("#receptura_main ul li:eq(2) a").click(function(){
  if ($.cookie("aviko_actionBack")) {
   var t = $.cookie("aviko_actionBack").split("?");
   if (t[2].match("page=")) {
    activePage = parseInt(t[2].slice(t[2].indexOf("page=") + 5, t[2].length), 10);
   }
   
   var filter = t[2].split("&");
   for (var x = 0; x < filter.length; x++) {
  filter[x] = filter[x].split("=");
    if (filter[x][0] === "search") {
   $("#f_search input[type=text]:eq(0)").val(filter[x][1]);
  } else {
   $("form#f_receptury_boxes select[name=" + filter[x][0] + "] option[value=" + filter[x][1] + "]").attr("selected", "selected");
  }
   }
   
   recepturaSearch($(t[1]), t[2], t[0]);
   return false;
   } else {
   history.back();
   }
  return false;
  });
   
   $("#receptura_dodaj").click(function(){
   var cookie = "";
   var title1 = $("#receptura_main h2 span").text();
   var title2 = $("#receptura_main h2").html();
   title2 = title2.slice(title2.replace(/SPAN>/gi,"span>").indexOf("</span>") + 7, title2.length);
   var url = window.location.pathname;
   var img = $("#receptura_main #img_mini").text();
   if ($.cookie("avikocart")) {
    if ($.cookie("avikocart").match(escape(img + "\\" + title1 + "\\" + title2 + "\\" + url))) {
     alert("Przepis już wcześniej dodano do koszyka.");
     return false;
    }
    cookie = unescape($.cookie("avikocart")) + "|" + img + "\\" + title1 + "\\" + title2 + "\\" + url;
   } else {
    cookie = img + "\\" + title1 + "\\" + title2 + "\\" + url;
   }
   
   $.cookie("avikocart", escape(cookie), {path: '/', expires: 730});
   $(this).children().attr("src","/_images/koszyk/btn_receptura_dodaj_2.gif");
   
   return false;
   });
   
   $("#receptura_cart").click(function(){
   if ($.cookie("avikocart")) {
  $(this).parents("#receptura_main").addClass("view_cart");
    var arr = unescape($.cookie("avikocart")).split("|");
    var content = "";
    for (var x = 0; x < arr.length; x++) {
     arr[x] = arr[x].split("\\");
     content +=
     '<div class="koszyk_item"><img class="koszyk_top" src="/_images/koszyk/bkg_receptura_koszyk_top.gif" alt="" />' +
     '<img class="mini" src="' + arr[x][0] + '" alt="" />' +
     '<h2><a href="' + arr[x][3] + '"><span>' + arr[x][1] + '</span>' + arr[x][2] + '</a></h2>' +
     '<div class="link"><img src="/_images/koszyk/btn_usunp.gif" alt="" /></div>' +
     '<img class="koszyk_bottom" src="/_images/koszyk/bkg_receptura_koszyk_bottom.gif" alt="" />' +
     '</div>'
    };
    $("#receptura_main").fadeOut(function(){
     $(this).html('<h1 class="cat">Mój koszyk</h1>' + content + '<div id="koszyk_buttons">' +
     '<img id="koszyk_print" src="/_images/koszyk/btn_receptura_drukuj_koszyk.gif" alt="" />' +
     '<img id="koszyk_back" src="/_images/btn_powrot.gif" alt="" /></div>');
     $(this).show();
     
   $("#koszyk_print").click(function(){
   $("#receptura_main #print").remove();
   var print = $('<div id="print"></div>');
   $("#receptura_main").append(print);
   
    $("div.koszyk_item").each(function(){
     var d = $(this);
     $.ajax({
      url: $(this).find("h2 a").attr("href"),
      type: "GET",
      async: "false",
      success: function(html){
       print.append($(html).find("#receptura_main").html());
      },
      complete: function(){
       if ($("div.koszyk_item").index(d) === $("div.koszyk_item").length - 1) {
       window.print();
       }
      }
     });
    })
    
    
   
   });
     
     $("div.koszyk_item div.link img").click(function(){
      $(this).parents("div.koszyk_item:eq(0)").fadeOut(function(){
       var temp = "";
       var title1 = $(this).find("h2 span").text();
       var title2 = $(this).find("h2 a").html();
       title2 = title2.slice(title2.replace(/SPAN>/gi,"span>").indexOf("</span>") + 7, title2.length);
       var url = $(this).find("h2 a").attr("href");
       var img = $(this).find("img.mini").attr("src");
       
       var l = "http://" + window.location.hostname;
       if (img.match(l)) img = img.slice(l.length, img.length);
       if (url.match(l)) url = url.slice(l.length, url.length);
       
       $(this).remove();
       for (var x = 0; x < arr.length; x++) {
        if (arr[x].join("\\") == img + "\\" + title1 + "\\" + title2 + "\\" + url) {
         arr.splice(x, 1);
         if (arr.length === 0) {
          $("#koszyk_buttons").remove();
          $.cookie("avikocart", null, {path: '/', expires: 730});
          window.location = window.location;
          return false;
         }
         
         }
       }
       var foo = [];
       for (y in arr) {
        foo[y] = arr[y].join("\\");
       }
       temp = foo.join("|");
       $.cookie("avikocart", escape(temp), {path: '/', expires: 730});
      });
     });
     
     
     $(this).find("#koszyk_buttons #koszyk_back").click(function(){
      window.location = window.location;
     });
    
    
    });
        
    
   } else {
    alert("Twój koszyk jest pusty.");
    return false;
   }
   });

  $("div.flag a").click(function(){
   var loc = document.location.pathname.substr(1, document.location.pathname.length).split("/")[0];
   var lang = $(this).attr("href").substr(1, $(this).attr("href").length).split("/")[0];
   
   if (loc !== lang) {
    if ($.cookie("aviko_actionBack")) $.cookie("aviko_actionBack", null, {path: '/', expires: 1});
    if ($.cookie("avikocart")) $.cookie("avikocart", null, {path: '/', expires: 730});
   }
  });
   
   
});
//-->

