function classSender(opt)
{
var root  = this;
this.req  = null;
//this.opt    = {};
this.func = {};
this.func.log = null;

/*
this.serializeForm(form)
	{
	var enc         = function(data)	{return (window.encodeURIComponent) ? encodeURIComponent(data) : ( (window.escape) ? escape(data) : data );}
	var collect     = function(tags,func)	{var n,i,j,v; n=new Array(); j=0; for(i=0;i<tags.length;i++) {v=func(tags[i]); if (v!=null) {n[j]=v; j++;}}; return n};
	var getN        = function(tagname)	{return form.getElementsByTagName(tagname);};
	var namevalue   = function(el)		{return ((el.name) ? enc(el.name)+"="+enc(el.value) : "");};
	var namevalue2  = function(inp)		{return (((inp.type!="radio" && inp.type!="checkbox") || inp.checked) ? namevalue(inp) : null);};
	var namevalue3  = function(sel)		{sel.value = sel.options[sel.selectedIndex]; return namevalue(sel);}
	var i,s,t;
	i = collect(getN("INPUT"),namevalue2);
	s = collect(getN("SELECT"),namevalue3);
	t = collect(getN("TEXTAREA"),namevalue);
	return ((i.concat(s)).concat(t)).join("&");
	};
*/

this.func.cbRequest = function()
	{
	root.func.log('cbRequest: Request reading...');
	var str = root.req.responseText;	// pro text/csv
	if (!str)
		{
		root.func.log('cbRequest: Chyba, prazdna odpoved.');
		return;
		}
	root.func.log('cbRequest: File writing end.');
	root.func.cbEnd(str);
	}

this.func.cbRequestError = function ()
	{
/*
	alert('cbRequestError: '+
		'status = ' + root.req.status + ' ' + status_text +
		'readyState = ' + root.req.readyState
		,'error'
		);
*/
	var status_text = '';
/*
	switch (root.req.status)
		{
		case 0:  status_text = 'Soubor nelze otevrit. "' + root.req.error_path + '"'; break;	// UNSENT
		case 1:  status_text = 'OPENED'; break;
		case 2:  status_text = 'HEADERS_RECEIVED'; break;
		case 3:  status_text = 'LOADING'; break;
		case 4:  status_text = 'DONE'; break;
		default: status_text = 'unknown'; break;
		}
*/
	SCREEN.func.message('cbRequestError: code=' + root.req.status + '. ' + status_text, 'error');
	}

/*
ajax.req_native.sendGet = function(url,args,func)
	{
	ajax.funcInit(func);
	var z = ajax.req_native.newRequest();
	if (args!=="") {url+= ((url.indexOf("?")>-1) ? "&" : "?") + args;}
	z.open("GET",url,true);
	z.send(null);
	};
*/
this.func.sendPost = function(path, arg, func_CB)
	{
	root.func.log('strToUrl: File writing start...');
	root.req = new XMLHttpRequest();
	root.req.responseType = 'text';	// pro posilani text/csv
	root.req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	root.req.onload  = isFunction(func_CB) ? func_CB : root.func.cbRequest;
	root.req.onerror = root.func.cbRequestError;
	root.req.error_path = path;
	root.req.open('POST', path, true);
	root.req.send(arg);
	}

this.func.init = function(opt)
	{
	if (!isObject(opt)) {return;}
	root.func.log       = isFunction(opt.log)       ? function (str) {opt.log('classSender.func.' + str);} : null;
	root.func.cbRequest = isFunction(opt.cbRequest) ? opt.cbRequest : root.func.cbRequest;
	root.func.cbRequestError = isFunction(opt.cbRequestError) ? opt.cbRequestError : root.func.cbRequestError;
	root.func.cbEnd     = isFunction(opt.cbEnd)     ? opt.cbEnd     : null;
	}

this.func.init(opt);
}

SENDER = new classSender({log:SCREEN.log, cbEnd:SCREEN.log});

