function getParams(el)
{
	var out = {};
	$(el)
	.find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
	.filter(":enabled")
	.each(function()
	{
		out[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
	}); 
	return out;
}

function szukaj(id) {
	//this.id = id;
	this.szukaj = function() {
		parametry = $.extend(getParams(this),{"page":0,"per_page":15,"className":"Produkt","funkcja":"szukajProduktow"});
		if (tSZ.page) {
			parametry.page = tSZ.page;
		}
    //alert(out.dane[1].id);
		$.post(this.getAttribute("action"),parametry,tSZ.znalezione,"json");

		//tSZ.startProgress();
		//this.SUBMIT("znalezione");
		return false;
	}

	this.znalezione = function(out) {
		//tSZ.stopProgress();
		if (out != -1) {

      var max_strony = 18;
      var max_count = max_strony;
      var c_start = 0;
      var a_str = parseInt(out.page) + 1;

      if(Math.ceil(out.count/out.per_page)>max_strony)
      {
        max_count = max_strony;

      }
      else max_count = Math.ceil(out.count/out.per_page);

      if(out.page-(max_strony/2)>0)
      {
        c_start = out.page-(max_strony/2);
        max_count = parseInt(out.page)+parseInt((max_strony/2));
      }

      if(max_count>Math.ceil(out.count/out.per_page))
        max_count = Math.ceil(out.count/out.per_page);
      //if((out.page+(max_strony/2)<Math.ceil(out.count/out.per_page)) && out.page>10)
      var pages = '<div id="koszykTresc" style="display: none;"> </div><div><p>Strona: '+a_str+' z '+Math.ceil(out.count/out.per_page)+'</p>';

      if(c_start>0)
        pages+='<a href="javascript:void(0);" onClick="tSZ.Strona(0);">&laquo;</a>&nbsp;&nbsp;<a href="javascript:void(0);" onClick="tSZ.Strona('+parseInt(out.page-1)+');"><</a>&nbsp;&nbsp;';

			for (i=c_start;i<max_count;i++) {
				if (i == out.page) {
					pages+='<strong>['+(i+1)+']</strong>';
				}
				else {
					pages+='<a href="javascript:void(0);" onClick="tSZ.Strona('+i+');">'+(i+1)+'</a>';
				}
				pages+='&nbsp;&nbsp;';
			}

      if(max_count<Math.ceil(out.count/out.per_page))
        pages+='&nbsp;&nbsp;<a href="javascript:void(0);" onClick="tSZ.Strona('+a_str+');">&gt;</a>&nbsp;&nbsp;<a href="javascript:void(0);" onClick="tSZ.Strona('+Math.ceil((out.count/out.per_page)-1)+');">&raquo;</a>';


			pages+="</div>";
			$("#produkty").html(pages+"<table width='100%' cellspacing='0' cellpadding='6'><tbody id='listaProduktow'><tr><td></td><td>Nazwa</td><td>Cena</td><td>Kup</td></tr></tbody></table>");
			for (var i=0;i<out.dane.length;i++) {
				var el = out.dane[i];
				var rzad = tSZ.tworzTR();
				path = '';
				if (el.path != -1) {
					path = '<a href="/activeshop24/Produkty/'+el.id+'_'+el.id_txt+'.html"><img src="/activeshop24/system/produkty/pliki/'+el.id+'/'+el.path.path+'_thumb.jpg"/></a>';
				}
				else
				{
  			  path = '<img src="/activeshop24/layout/rexel/img/nophoto.gif"/>';
  			}
        var cena_b = parseFloat(el.price)+(parseFloat(el.price)*0.23);
        var cena_brutto = Math.round(cena_b*Math.pow(10,2))/Math.pow(10,2);
        //var cena_brutto = Math.round(Math.round(cena_b*Math.pow(10,3))/Math.pow(10,1))/Math.pow(10,2);
				addTD(rzad,path);
				addTD(rzad,'<div><b><a href="/activeshop24/Produkty/'+el.id+'_'+el.id_txt+'.html">'+el.name+'</a></b></div><div>'+el.description.replace(/(<([^>]+)>)/ig,"").substring(0,150)+'</div>');
        if(el.telefon==1) {
          addTD(rzad,"<img src='/activeshop24/layout/default/img/49.png'>");
          addTD(rzad,"");
        } else {
          addTD(rzad,'Cena: '+cena_brutto+' PLN');
  				addTD(rzad,'<a href="javascript:void(0);" onClick="javascript:tF.quickAdd('+el.id+');"><img src="/activeshop24/layout/default/img/kosz.gif" border="0" /></a>');
        }
				tSZ.$$("listaProduktow").appendChild(rzad);
			}
		}
		else {
			$("#produkty").html("Niestety, niczego nie znaleziono");
		}
		tSZ.page = null;
	}

	this.Strona = function(x) {
		tSZ.page = x;
		//tSZ.szukaj();
    document.getElementById('szukajbutton').click();
	}
}

szukaj.prototype = new advAJAXwrapper();
var tSZ = new szukaj("tSZ");

