function tAjaxHelper() {
	this.formDEFAULT = "/activeshop24/index_ajax.php";
	this.pobierzDaneRekordu = function(id,funkcja) {
		this.parametry = {"funkcja":"getByPK","id":id};
		this.GETPOST(funkcja)
	}
	this.displayAll = function() {
		tAHP.setElement(this.listElement);
		tAHP.setPerPage(this.perPage);
		this.id = this.idKlasy;
		this.form = this.formDEFAULT;
		this.parametry = {"funkcja":this.grabDatafun,"per_page":tAHP.perPage,"page":tAHP.startPage};
		if (this.params && this.params["grabData"]) {
			this.parametry.param = this.params["grabData"];
		}
		this.GETPOST("doScaffold");
	}
	
	this.doScaffold = function(dane) {
		this.wyczyscTabele($(this.listElement));
		if (dane.out != -1) {
			for (i=0;i<dane.out.length;i++) {
				var item = dane.out[i];
				var rzad = this.tworzTR();
				if (this.complex == null) {
				if (this.nieNumeruj == null) {
					addTD(rzad,(i+1));
				}
				for (j in item) {
					if (j != "id") {
					if (this.scaffold && this.scaffold[j] != null) {
						addTD(rzad,this.scaffold[j][item[j]]);
					}
					else {
					addTD(rzad,item[j]);
					}
					}
				}
				if (this.nieEdytuj == null) {
					addTD(rzad,'<a href="javascript:'+this.idKlasy+'.Edytuj('+item.id+');"><img src="/activeshop24/layout/default/img/b_edit.png" /></a>',1);
				}
				if (this.nieCheckBox == null) {
					addTD(rzad,this.utworzCheckBoxa(this.idRekordu,item.id,(i-1)),1);
				}
				if ($(this.listElement)[0]) {
					$(this.listElement)[0].appendChild(rzad);
				}
				else {
					$(this.listElement).appendChild(rzad);
				}
				}
				else {
					this.doOwnScaffold(rzad,item,i);
				}
			}
		}
		var al = eval("this.after_scaffold");
		if (typeof(al) == "function") {
			eval("this.after_scaffold(dane);");
		}
	}
	
	this.otworzOkno = function(id_okna) {
		if (!this.Okna || !this.Okna[id_okna]) {
			o = this.windowParams[id_okna];
			if (!this.Okna) {
				this.Okna = {};
			}
			this.Okna[id_okna] = this.Okno(o);
		}
		this.Okna[id_okna].show();
		var ao = eval("this."+id_okna+"_after_open");
		if (typeof(ao) == "function") {
			eval('this.'+id_okna+'_after_open();');
		}		
		eval('this.'+id_okna+' = this.Okna["'+id_okna+'"];');
		tS.okno = id_okna;
	}
	
	this.Dodaj = function(id) {
		this.otworzOkno(id);
		if (this.afterWinOpen && this.afterWinOpen[id] != null) {
			eval('this.'+this.afterWinOpen[id]+'();');
		}
	}
	
	this.submitForm = function(form_id) {
		tS.id = this.idKlasy;
		return $(form_id).onsubmit();
	}
	
	this.uploadStart = function() {
		eval(tS.id+'.startProgress();');
		return true;
	}
	
	this.uploadComplete = function(odp) {
		alert(odp);
		eval(tS.id+'.stopProgress();');
		eval("o = "+odp+";");
		var po = eval(tS.id+'.'+tS.okno+'_after_upload');
		if (typeof(po) != "function" && (!this.postUploadFunctions || !this.postUploadFunctions[tS.okno] || this.postUploadFunctions[tS.okno] == null)) {
			if (o.status == 1) {
				eval(tS.id+'.Okna["'+tS.okno+'"].hide();');
				eval(tS.id+'.displayAll();');
			}
			else ERROR_BOX('Błąd!',o.blad);
		}
		else {
			if (typeof(po) != "function") {
				eval(tS.id+'.'+this.postUploadFunctions[tS.okno]+'();');
			}
			else {
				eval(tS.id+'.'+tS.okno+"_after_upload(o)");
			}
		}
	}
	
	this.Usuwanie = function(l) {
		if (l && l != -1) {
			if (confirm("Czy napewno usunąć zaznaczone rekordy?")) {
				this.form = this.formDEFAULT;
				this.parametry = {"funkcja":"usunRekordy",do_us:l[1]};
				this.GETPOST("displayAll");
			}
		}
		else ERROR_BOX("Błąd","Proszę zaznaczyć rekordy do usunięcia!");
	}
	
	this.Edytuj = function(id) {
		this.parametry = {"funkcja":"getByPK","id":id};
		this.GETPOST("pobralemDaneRekordu");
	}
	
	this.pobralemDaneRekordu = function(out) {
		if ($(this.editWindow)) {
			this.otworzOkno(this.editWindow);
		}
		for (pole in out) {
			if ((this.scaffold && this.scaffold.edit &&  !this.scaffold.edit[pole]) || (!this.scaffold)) {
				if ($(this.className+'['+pole+']')) {
					$(this.className+'['+pole+']').value = out[pole];
				}
			}
			else {
				if (this.scaffold && this.scaffold.edit && this.scaffold.edit[pole] == "checkbox") {
					if ($(this.className+'['+pole+']')) {
						if (out[pole] == 1) {
							$(this.className+'['+pole+']').checked = true;
						}
					}
				}
			}
		}
		var ae = eval("this."+this.editWindow+"_after_edit");
		if (typeof(ae) == "function") {
			eval('this.'+this.editWindow+'_after_edit(out)');
		}
		var ae_leg = eval("this.after_edit");
		if (typeof(ae_leg) == "function") {
			eval("this.after_edit(out);");
		}
	}
}

var tS = {};

tAjaxHelper.prototype = new advAJAXwrapper();

var tAHP = new tPaginator("tAHP");
tAHP.perPageOptions = [1,2,5,10,20,50,100];
//tAHP.doWithDatafun = "this.doScaffold";
tAHP.setMode("pure");
tAHP.outMode = "tr";

