var kport_ajax = new Class({
	options: {
		url:"",
		update:"",
		async:true,
		js:"",
		next_js:"",
		wait_msg:"<img src=\""+tmpl_dir+"img/ajax-loader.gif\" style=\"vertical-align:middle\" alt=\"\" />&nbsp;Attendere...",
		put_wait:true,
		method:"post",
		link: "cancel",
		cycle:0
	},
	loadURL: function(options) {
		this._r.setOptions(options);
		this._r.send();
	},
	initialize: function(options) {
		this.setOptions(options);
		this._r = new Request({
						onRequest:function(){
								if (this.options.put_wait)
								{ $(this.options.update).set('html',this.options.wait_msg);
								}
							},
						onSuccess:function(responseText, responseXML){
								var frm = false;
								var dest = $(this.options.update);
								if ($chk(responseXML))
								{ if ($chk(responseXML.getElement('result_msg')))
								   $("msgs").set("html",unescape(responseXML.getElement('result_msg').get('text')));
								  if ($chk(responseXML.getElement('result_body')))
								   dest.set('html',responseXML.getElement('result_body').get('text'));
								  if ($chk(responseXML.getElement('page_reload_flg')))
								  { if (responseXML.getElement('page_reload_flg').get('text')  == "true")
								    { frm = $$("form")[0];
								    }
							      }
								}
								else
								 if (responseText)
								  dest.set('html',responseText);
								$exec(this.options.js);
								$exec(this.options.next_js);
								if (frm)
								 frm.submit();
								//top.history.go(0);
								if (this.options.cycle)
								 (function(){this.send();}.bind(this)).delay(this.options.cycle);
							}
						});
		this._r.setOptions(this.options);
		this._r.options.evalScripts = function(script){
							this.options.js = script;
						}.bind(this._r);
	}
});
kport_ajax.implement(new Events, new Options);

