// --- BEGIN ajax ---
var ajax = new Object();
ajax.func = null;
ajax.funcInit = function(func)
	{
	if (window[func]!=null)
		{ajax.func = func;}
	}
ajax.req_native = new Object();
ajax.req_native.newRequestMoz = function(func)
	{
	var req = null;
	try		{req = new XMLHttpRequest();}
	catch (e)	{req = null;}
	if (req!=null)
		{
		req.onreadystatechange = function()
			{
			if (req.readyState==4)
				{
				if (req.status==200) {window[ajax.func](req.responseText);} else {alert(req.status+": "+req.statusText);} //POST server
//				if (ajax.func!=null) {window[ajax.func](req.responseText);}	//string
				}
			}
//		req.onprogress = ajax.req.fce_progress;
//		req.onerror    = ajax.req.fce_error;
		}
	return req;
	}

ajax.req_native.IEtype = null;
ajax.req_native.newRequestIE = function(func)
	{
	var req = null;
	try		{req = new ActiveXObject(ajax.req_native.IEtype);}
	catch (e)	{req = null;}
	if (req!=null)
		{
		req.onreadystatechange = function()
			{
			if (req.readyState==4)
				{
				if (req.status==200) {window[ajax.func](req.responseText);} else {alert(req.status+": "+req.statusText);} //POST server
//				if (ajax.func!=null) {window[ajax.func](req.responseText);}	//string
				}
			}
//		req.onprogress = ajax.req.fce_progress;
//		req.onerror    = ajax.req.fce_error;
		}
	return req;
	}

ajax.req_native.newRequest = null;

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);
	};
ajax.req_native.sendPost = function(url,args,func)
	{
	ajax.funcInit(func);
	var z = ajax.req_native.newRequest();
	z.open("POST",url,true);
	z.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	z.send(args);
	};




//Iframe ajax emulation ... response = HTML page !
ajax.req_iframe = new Object();

ajax.req_iframe.htmlHead = "\
\n<html>\
\n<head>\
\n\t<meta http-equiv=\"content-language\"\tcontent=\"cz\"\/>\
\n\t<meta http-equiv=\"content-type\"\t\tcontent=\"text\/html; charset=windows-1250\"\/>\
\n\t<title>AjaxIframe<\/title>\
\n<\/head>\
\n<body>\
";
ajax.req_iframe.htmlFoot = "\
<\/body>\
<\/html>\
";

ajax.req_iframe.newRequest = function(name,url,args,method,enc)
{
var o,e, d,htmlBody,i,j,x,arr;
var req = window[name];
if (req==null)
	{
	o   = document.getElementsByTagName('BODY')[0];
	req = document.createElement("IFRAME");
	req.name = name;
	req.id   = name;
	req.src  = "";	//Opera bug
	req.style.visibility = "hidden";
	req.style.width      = 0;
	req.style.height     = 0;
	req.style.position   = "absolute";
	o.appendChild(req);
	}

enc = (enc) ? " enctype=\""+enc+"\"" : "";
j = 0;
//iframe body
htmlBody = new Array();
htmlBody[j++] = "<form name=\"f\" action=\""+url+"\" method=\""+method+"\""+enc+"\">";
arr = (args!=="") ? ((/&/.test(args)) ? args.split("&") : new Array(args)) : new Array();
if (ajax.func!=null)
	{arr[arr.length] = 'ajaxonload='+ajax.func;}
for (i=0;i<arr.length;i++)
	{
	x = arr[i].split("=");
	htmlBody[j++] = "<input type=\"hidden\" name=\""+x[0]+"\" value=\""+x[1]+"\"/>";
	}
htmlBody[j++] = "<\/form>";
alert(htmlBody);
//iframe add
d = window[name].document;
d.open('text/html');
d.write(ajax.req_iframe.htmlHead + "\n" + htmlBody.join("\n") + "\n" + ajax.req_iframe.htmlFoot);
d.close();
d = window[name].document;	//Opera bug
d.f.submit();
}

ajax.req_iframe.sendGet = function(url,args,func)
	{
	ajax.funcInit(func);
	ajax.req_iframe.newRequest("AjaxIFrame",url,args,"GET","");
	}
ajax.req_iframe.sendPost = function(url,args,func)
	{
	ajax.funcInit(func)
	ajax.req_iframe.newRequest("AjaxIFrame",url,args,"POST","multipart\/form-data");
	}



ajax.sendGet  = null;
ajax.sendPost = null;
ajax.init = function()
	{
	var req = null;
	if (window.XMLHttpRequest)	//Moz1.5 / IE7 / Op7.6+ / Saf
		{
		if (req = ajax.req_native.newRequestMoz(null))
			{ajax.req_native.newRequest = ajax.req_native.newRequestMoz;}
		}
	else {if (window.ActiveXObject)	//IE5.x+
		{
		var i,msX;
		msX = new Array(
		'Msxml2.XMLHTTP',
		'Msxml2.XMLHTTP.7.0',
		'Msxml2.XMLHTTP.6.0',
		'Msxml2.XMLHTTP.5.0',
		'Msxml2.XMLHTTP.4.0',
		'Msxml2.XMLHTTP.3.0',
		'Microsoft.XMLHTTP');
		for (i=0;i<msX.length;i++)
		 {
		ajax.req_native.IEtype = msX[i];
		try 	  {req = new ajax.req_native.newRequestIE(null); if (req!=null) {break;}}
		catch (e) {req = null;}
		 }
		if (req!=null) {ajax.req_native.newRequest = ajax.req_native.newRequestIE;}
		}}
//	else if (window.createRequest)		//old browsers JavaApplet + add function createRequest()
//		{
//		try	  {req = window.createRequest();}
//		catch (e) {req = null;}
//		}

	if (req!=null)		// native request
		{
		ajax.sendGet    = ajax.req_native.sendGet;
		ajax.sendPost   = ajax.req_native.sendPost;
		}
	else	{		// iframe request emulation

		ajax.sendGet    = ajax.req_iframe.sendGet;
		ajax.sendPost   = ajax.req_iframe.sendPost;
		}
	}

ajax.init();
// --- END ajax ---



function 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("&");
	};



// v IE funguje request jen z inetu.
// pouzivam jen text response, protoze je spolehlivejsi
// Iframe potrebuje vedet func, jinak nevi, co ma delat.