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;
		}
		$.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 pages = '<div>Strony: ';
			for (i=0;i<Math.ceil(out.count/out.per_page);i++) {
				if (i == out.page) {
					pages+=(i+1);
				}
				else {
					pages+='<a href="#" onClick="tSZ.Strona('+i+');">'+(i+1)+'</a>';
				}
				pages+='&nbsp;&nbsp;';
			}
			pages+="</div>";
			$("#produkty").html(pages+"<table id='listaProduktow' width='100%' cellspacing='0' cellpadding='6'><tr><td></td><td>Nazwa</td></tr></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 = '<img src="/activeshop/system/produkty/pliki/'+el.id+'/'+el.path.path+'_thumb.jpg"/>';
				}
				else
				{
  			  path = '<img src="/activeshop/layout/rexel/img/nophoto.gif"/>';
  			}
				addTD(rzad,path);
				addTD(rzad,'<div><b><a href="/activeshop/Produkty/'+el.id+'_'+el.id_txt+'.html">'+el.name+'</a></b></div><div>'+el.description.replace(/(<([^>]+)>)/ig,"").substring(0,150)+'</div><div><p align="right"><a href="/activeshop/Produkty/'+el.id+'_'+el.id_txt+'.html">szczegóły &raquo;</a></p></div>');
				//addTD(rzad,'<a href="#" onClick="javascript:tF.quickAdd(84);"><img src="/activeshop/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();
	}
}

szukaj.prototype = new advAJAXwrapper();
var tSZ = new szukaj("tSZ");

