var Jr = {};
Jr.http = {};
Jr.util = {};
//	==================================================================================
//	U T I L s
Jr.util.ge = function(id)  { return document.getElementById(id); }			//	document.getElementById
Jr.util.gt = function(id,tag) { return document.getElementById(id).getElementsByTagName(tag); }//	document.getElementsByTagName
Jr.util.createPos = function(x,y) { return {x: parseInt(x,10), y: parseInt(y,10) }; };
Jr.util.getLeft = function(o) { var x=0; while (o!=null) { x+=o.offsetLeft;/*-o.scrollLeft;*/ o=o.offsetParent; } return x; }
Jr.util.getTop = function(o)  { var y=0; while (o!=null) { y+=o.offsetTop;/*-o.scrollTop;*/   o=o.offsetParent; } return y; }
Jr.util.getPos = function(o) { x=Jr.util.getLeft(o);y=Jr.util.getTop(o); return { x: x, y: y }; }
Jr.util.movePos = function(o, from_o,x,y) 
{ 
	from_pos = Jr.util.getPos(from_o);
	from_pos.x  = from_pos.x + x; from_pos.y  = from_pos.y + y;
	Jr.util.setPos(o,from_pos);
};
Jr.util.setPos = function(o,options) { o.style.left=options.x+'px'; o.style.top=options.y+'px'; }
Jr.util.setDisplay = function(o,yn,type) { o.style.display = (yn ? (type || 'block'): 'none'); }
Jr.util.setHeight = function(o, height) { o.style.height=parseInt(height,10)+'px'; }
Jr.util.setWidth  = function(o, width)  { o.style.width=parseInt(width,10)+'px'; }
Jr.util.getHeight = function(o) { return parseInt(o.style.height, 10); }
Jr.util.getWidth  = function(o) { return parseInt(o.style.width, 10); }
Jr.util.getX = function(e)
{
	e = e || window.event;
	return e.pageX || e.clientX + document.body.scrollLeft;
}
Jr.util.getY = function(e)
{
	e = e || window.event;
	return e.pageY || e.clientY + document.body.scrollTop;
}
Jr.util.getStyle = function(elem, name)
{
	// If the property exists in style[], then it's been set recently (and is current)
	if (elem.style[name]) return elem.style[name];
	else 
		if (elem.currentStyle) 					// Otherwise, try to use IE's method
			return elem.currentStyle[name];
												// Or the W3C's method, if it exists
		else 
			if (document.defaultView && document.defaultView.getComputedStyle) 
			{
				// It uses the traditional 'text-align' style of rule writing, instead of textAlign
				name = name.replace(/([A-Z])/g,"-$1");
				name = name.toLowerCase();
				// Get the style object and get the value of the property (if it exists)
				var s = document.defaultView.getComputedStyle(elem,"");
				return s && s.getPropertyValue(name);
				// Otherwise, we're using some other browser
			} 
			else return null;
};
Jr.util.hidden = function(o) 
{ 
	curDisplay = o.style.display;
	if (curDisplay!='none') o.$oldDisplay=curDisplay;
	o.style.display='none';
}
Jr.util.show = function(o)   
{ 
	o.style.display = o.$oldDisplay || '';
}

Jr.util.bubbleStatus = 'off';	//	on / off / sleep
//Jr.util.bubbleTypeShow = 'mouseover';	//	mouseout / click
Jr.util.bubbleTypeClose = 'mouseout';	//	mouseout / click
Jr.util.createBubbleWindow = function() 	/*Call if DOM already loaded !!! */
{
	var o = document.createElement('div');
	o.id = 'Jr.id-Bubble';
	o.style.display='none';
	o.style.zIndex='999';
	o.style.position = 'absolute';
	o.style.border = 'solid 1px black';
	o.style.backgroundColor = '#f8fafd';
	o.innerHTML = '<div style="background-color:gray;height:10px;width:100%;"><div style="float:right;"><img src="../pic/box_yes.gif" alt="Close" style="cursor:pointer;"/></div></div><div id="Jr.id-BubbleText" style="margin:3px; "></div>';
	if(typeof document.body == 'object') document.body.appendChild(o);
	var bubble = Jr.util.ge('Jr.id-Bubble');
	var bubble_status = 'off';		//	on/off
	img = bubble.getElementsByTagName('img');
	img[0].onclick = function(e) { Jr.util.hidden(bubble); }
	bubble.onmouseout = function(e) { if (Jr.util.bubbleTypeClose!= 'mouseout') return; Jr.util.hiddeBubbleWindow(300); }
	bubble.onmouseover = function(e) { Jr.util.bubbleStatus='on'; }
}
Jr.util.hiddeBubbleWindow = function(timeout)
{
	if(typeof timeout == 'number')
	{
		Jr.util.bubbleStatus = 'sleep';
		setTimeout('Jr.util.hiddeBubbleWindow();',timeout);
		return;
	}
	if (Jr.util.bubbleStatus == 'sleep')
	{
		Jr.util.bubbleStatus = 'off';
		Jr.util.hidden(Jr.util.ge('Jr.id-Bubble'));
	}
}
Jr.util.getBubbleWindow = function(bubbleTypeClose) { Jr.util.bubbleTypeClose=bubbleTypeClose; if (Jr.util.ge('Jr.id-Bubble')==null) Jr.util.createBubbleWindow(); return Jr.util.ge('Jr.id-Bubble'); };
Jr.util.showBubbleWindow = function(parentObj, typeClose, txt,moveX,moveY,width,height)
{												//		showBubble(parentObj, 'click', +5,+10, 100,200);
						
	//alert(getTop(parentObj));
	if (parentObj.style.position=='') parentObj.style.position='relative';
	if (parentObj.style.left=='') parentObj.style.left='0px';
	if (parentObj.style.top=='') parentObj.style.top='0px';
	parentPos = Jr.util.getPos(parentObj);
	parentPos.x = parentPos.x + moveX;
	parentPos.y = parentPos.y + moveY;   

	var o = Jr.util.getBubbleWindow(typeClose);
	o.style.height = parseInt(height,10)+'px';
	o.style.width = parseInt(width,10)+'px';
	Jr.util.setPos(o,parentPos);
	
	//Jr.util.getPos()
	Jr.util.ge('Jr.id-BubbleText').innerHTML = txt;
	Jr.util.show(o);
	Jr.util.bubbleStatus = 'on';
	
	
}




Jr.util.date2 = function(txtDate)
{
	d = txtDate.split('.');
	t = new Date();
	t.setFullYear(d[2]); t.setMonth(0); t.setDate(1); 
	t.setFullYear(d[2]); t.setMonth(d[1]-1); t.setDate(d[0]); 
	return t;
};
Jr.util.date = function(oDate)
{
	return oDate.getDate()+'.'+(oDate.getMonth()+1)+'.'+oDate.getFullYear();
};
Jr.util.checkDate = function(txtDate)
{
	a = txtDate.split('.');
	den = parseInt(a[0],10); mes = parseInt(a[1],10); rok = parseInt(a[2],10);
	x1 = Jr.util.date2(den+'.'+mes+'.'+rok);
	x2 = Jr.util.date(x1)
	b = x2.split('.');
	den2 = parseInt(b[0],10); mes2 = parseInt(b[1],10); rok2 = parseInt(b[2],10);
	if (den==den2 && mes==mes2 && rok==rok2) return true;
	return false;
};
Jr.util.fixEvent = function(e) 
{
	// Make all the IE-centric parameters be W3C-like
	if (!e) 
	{
		e = window.event;
		e.target = e.srcElement;
		e.layerX = e.offsetX;
		e.layerY = e.offsetY;
	}
	return e;
};
Jr.util.getIE = function()
{
	if (navigator.userAgent.indexOf('MSIE') >=0 )
		return true;
	return false;
}
Jr.IE = Jr.util.getIE();

Jr.MDATE = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
Jr.util.mdate2 = function(germanDate)
{
	var pattern = /^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/;
	a = pattern.exec(germanDate);
	if (a==null) return '';
	den  = parseInt(a[1],10); mes  = parseInt(a[2],10); rok  = parseInt(a[3],10);
	return den+Jr.MDATE[mes-1]+rok;
	
}
Jr.util.stopBubble = function(e)
{
	// If an event object is provided, then this is a non-IE browser
	if ( e && e.stopPropagation )
		// and therefore it supports the W3C stopPropagation() method
		e.stopPropagation();
	else
		// Otherwise, we need to use the Internet Explorer way of cancelling event bubbling
		window.event.cancelBubble = true;
}
/* Function called in document.body.onload (!!!) */
Jr.util.domReady = new Function();
/* Function called in document.body.unonload (!!!) */
Jr.util.domClose = new Function();
/*
	<div id='idA'><div id='idB'>schovavajuci text text text</div>aaa bbb cccc</div>
*/
Jr.floatHTML = function(idA, idB, x, y)
{
	oObj = Jr.util.ge(idB);
	Jr.util.ge(idA).onmouseover = function(e) { e=Jr.util.fixEvent(e); Jr.util.ge(this.floatHtmlId)._open(e); }
	Jr.util.ge(idA).onmouseout = function(e)  { Jr.util.ge(this.floatHtmlId)._close(500); }
	oObj._open = function(e)
	{
		Jr.util.movePos(this, Jr.util.ge(this.fromID), this.posunx, this.posuny);
		Jr.util.setDisplay(this, true);
		this.myFocus(e);
		this.fHstatus = 1;
		
	}
	oObj._close = function(time)
	{
		this.fHstatus = -1;
		setTimeout('Jr.util.ge("'+this.id+'")._closeA();', time);
	}
	oObj._closeA = function()
	{
		if (this.fHstatus==1) return;
		Jr.util.setDisplay(this, false);
		this.fHstatus=0;
	}
	oObj.myFocus = new Function();
	oObj.onmouseover = function(e) { this.fHstatus = 1; }
	oObj.onmouseout = function(e)  { this._close(250); 	}
	Jr.util.ge(idA).floatHtmlId = idB;
	oObj.posunx = x;	oObj.posuny = y;	oObj.fHstatus = 0;		oObj.fromID = idA;
	aItems = Jr.util.gt(idB, '*');
	for (var i=0; i<aItems.length; i++)
	{
		aItems[i].parentFloatItemId = idB;
		aItems[i].onmouseover = function(e) { Jr.util.ge(this.parentFloatItemId).fHstatus = 1; }
	}
}

//function mdate2($mdate)
//{
//	global $MDATE;
//	preg_match('/^([0-9]{1,2})([a-zA-Z]{3})([0-9]{4})$/', $mdate, $z);
//	$r=str_pad((int)$z[3], 4, "0", STR_PAD_LEFT);
//	$m=str_pad((int)array_search(strtolower($z[2]),$MDATE), 2, "0", STR_PAD_LEFT);
//	$d=str_pad($z[1], 2, "0", STR_PAD_LEFT);
//	return "$r-$m-$d";
//}
//
Jr.util.trace = function(txt)
{
	debugInfo = Jr.util.ge('debug-info');
	d = new Date();
	try { debugInfo.value = '['+d.getMilliseconds()+'] '+txt+'\r\n'+debugInfo.value; }
	catch (e) {}
	
}


//	==================================================================================
//	E L E M E N T S

//	==================================================================================
//	L i s t B o x
//	~~~~~~~~~~~~~
Jr.listBox = {}
Jr.listBox.boxs = new Array();
Jr.listBox.defaultTimeout = 400;
Jr.listBox.defaultMinChars = 1;
Jr.listBox.defaultUrl = 'none';
Jr.listBox.blurStatus = 0;		//	0 - ziadna akcia, -1 - za 500 ms urobim blur, 1 - moznost urobit blur (zapina sa na focus)
Jr.listBox.controlStatus = 0;	//	0 - vypnute zobrazenie Result, 1 - zapnute
Jr.listBox.htmlLoading = '<img src=\"/i/loading_blue.gif\" />';
Jr.listBox.packetId = 0;
Jr.listBox.navigationResult = -1;
Jr.listBox.init = function(o, minChars, Url)
{
	o.listBoxOldValue = '';
	o.listBoxTimeout = Jr.listBox.defaultTimeout;
	o.listBoxMinChars = minChars || Jr.listBox.defaultMinChars;
	o.listBoxUrl = Url || Jr.listBox.defaultUrl;
	o.listBoxTdStyleColor = '#0066B2';
	o.listBoxTdStyleBgColor = '#F4F7FA';
	o.listBoxTdStyleColor2 = '#F4F7FA';
	o.listBoxTdStyleBgColor2 = '#0066B2';
	o.listBoxNoResultText = 'No result';
	o.listBoxTdWidth = new Array();
	o.listBoxValues = new Array();
	Jr.listBox.actualBoxId = null;
	Jr.listBox.boxs[Jr.listBox.boxs.length] = o;
	o.listBoxSetColor = function(hexColor) { this.listBoxTdStyleColor = hexColor; }
	o.listBoxSetColor2 = function(hexColor) { this.listBoxTdStyleColor2 = hexColor; }
	o.listBoxSetBgColor = function(hexColor) { this.listBoxTdStyleBgColor = hexColor; }
	o.listBoxSetBgColor2 = function(hexColor) { this.listBoxTdStyleBgColor2 = hexColor; }
	o.listBoxSetWidth = function(row,width) { this.listBoxTdWidth[row]=width; }
	o.listBoxSetNoResultText = function(txt) { this.listBoxNoResultText = txt; }

	o.listBoxId = Jr.listBox.boxs.length-1;
	o.onfocus = Jr.listBox.focus;
	o.onblur = Jr.listBox.blur;
	o.onkeyup = Jr.listBox.keyUp;
	o.onkeydown = Jr.listBox.keyDown;
	o.listBoxOnSuccess = new Function();

	if (typeof document.JrListBoxObject == 'undefined')
		Jr.listBox.createHTMLObject();
}
//	Control on INPUT object: onfocus and onblur
Jr.listBox.focus = function(e)
{
	Jr.listBox.switchBox(this, e);
	Jr.listBox.blurStatus = 1;
	Jr.util.trace('urobil som focus '+Jr.listBox.actualBoxId);
	//if (Jr.listBox.)
	
}
Jr.listBox.blur = function(e)
{
	Jr.listBox.blur2(500);
}
Jr.listBox.blur2 = function(timeout)
{
	if (timeout != 0 && Jr.listBox.blurStatus == 1 ) 
	{ 
		Jr.listBox.blurStatus = -1; 
		Jr.util.trace('idem robit blur '+Jr.listBox.actualBoxId);
		setTimeout('Jr.listBox.blur2(0);',timeout); 
		return false; 
	}
	if (timeout == 0 && Jr.listBox.blurStatus == -1)
	{
		Jr.listBox.blurStatus = 0;
		Jr.listBox.actualBoxId = null;
		Jr.util.trace('urobil som blur '+Jr.listBox.actualBoxId);
		if (Jr.listBox.controlStatus == 1)
		{
			Jr.listBox.controlStatus = 0;
			Jr.listBox.closeResult();
		}
	}
}
Jr.listBox.setTdColor = function(oRows, type)
{
	if (type=='')
	{
		oTR = oRows[Jr.listBox.navigationResult].getElementsByTagName('td');	
		for (i=0; i<oTR.length; i++)
		{
		    oTR[i].style.backgroundColor=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleBgColor;
		    oTR[i].style.color=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleColor;
		}
	}
	if (type=='active')
	{
		oTR = oRows[Jr.listBox.navigationResult].getElementsByTagName('td');	
		for (i=0; i<oTR.length; i++)
		{
		    oTR[i].style.backgroundColor=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleBgColor2;
		    oTR[i].style.color=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleColor2;
		}
	}
	
}
Jr.listBox.keyDown = function(e)
{
	if (Jr.listBox.actualBoxId == null) 
	{
		Jr.listBox.switchBox(this, e);
		Jr.listBox.blurStatus = 1;
		Jr.util.trace('urobil som focus '+Jr.listBox.actualBoxId);
		return e;
	}
	e = Jr.util.fixEvent(e);
	Jr.util.trace('keyDown:'+e.keyCode+' ControlStatus='+Jr.listBox.controlStatus+' navRes:'+Jr.listBox.navigationResult);
	if (Jr.listBox.controlStatus != 1) return e;
	
	if ((e.keyCode == 40 || e.keyCode == 38) && Jr.listBox.controlStatus == 1) // sipka dole, hore
	{
		if (Jr.util.ge('Jr-listBox-object').getElementsByTagName('table').length < 1)
			return e;
		table = Jr.util.ge('Jr-listBox-object').getElementsByTagName('table')[0];
		rows = table.rows;
		if (Jr.listBox.navigationResult == -1)
		{
			if (rows.length>0) 
			{
				Jr.listBox.navigationResult = 0;
				Jr.listBox.setTdColor(rows, 'active');
			}
		}
		else
		{
			if (e.keyCode == 40)
			{
				if (Jr.listBox.navigationResult < (rows.length-1))
				{
					Jr.listBox.setTdColor(rows, '');
					Jr.listBox.navigationResult++;
					Jr.listBox.setTdColor(rows, 'active');
				}
			}
			if (e.keyCode == 38)
			{
				if (Jr.listBox.navigationResult > 0)
				{
					Jr.listBox.setTdColor(rows, '');
					Jr.listBox.navigationResult--;
				    Jr.listBox.setTdColor(rows, 'active');
				}
			}
		}
	}
	if (e.keyCode == 13 && Jr.listBox.navigationResult >=0 && Jr.listBox.blurStatus == 1)
	{
		Jr.util.trace('Result:'+Jr.listBox.navigationResult+' BlurSt:'+Jr.listBox.blurStatus);
		val = Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxValues[Jr.listBox.navigationResult];
		Jr.listBox.boxs[Jr.listBox.actualBoxId].value=val;
		
		Jr.listBox.navigationResult = -1;
		Jr.listBox.closeResult();
		return false;
	}
//	if (e.keyCode == 13 && Jr.listBox.controlStatus == 1 && Jr.listBox.navigationResult != -1 && Jr.listBox.blurStatus == 1) // enter (13) 
//	{
//		
//		return; 
//		
//	}
	
	//return e;
}
Jr.listBox.keyUp = function(e)
{
	//if (Jr.listBox.actualBoxId == null) return false;
	if (Jr.listBox.actualBoxId == null) return e;
	//
	e = Jr.util.fixEvent(e);
	Jr.util.trace('keyUP:'+e.keyCode);
	if (e.keyCode==16 || e.keyCode==17 || e.keyCode==18) return false; // Ctrl,Shif,Alt
	if (e.keyCode==37 || e.keyCode==40 || e.keyCode==39 || e.keyCode==38) return false; // Arrows
	if (e.keyCode==34 || e.keyCode==35 || e.keyCode==36 || e.keyCode==35) return false; // Home,End,PgUp,PgDw
	if (e.keyCode==46 || e.keyCode==45) return false; // Ins,Del
	if (e.keyCode==13) return false; // ?
	if (this.value.length < this.listBoxMinChars)
	{
		Jr.listBox.controlStatus = 0;
		Jr.listBox.closeResult();
		return false;
	}
	if (Jr.listBox.controlStatus == 0)
	{
		Jr.listBox.controlStatus = 1;
		Jr.listBox.openResult(this, e);
	}
	if (Jr.listBox.controlStatus == 1)
	{
		Jr.listBox.packetId++;
		Jr.listBox.loadData(Jr.listBox.packetId, this.listBoxId, this.value, 500);
	}
	return e;
}
Jr.listBox.innerResult = function(httpData)
{
	color = Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleColor;
	bgcolor = Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleBgColor;
	noresulttext = Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxNoResultText;
	Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxValues = new Array();
	style='style=\"color:'+color+';background-color:'+bgcolor+';\"';
	//style='';
	table='';
	rows = httpData.getElementsByTagName('row').length;
	for( i=0; i<rows; i++)
	{
		table+='<tr>';
		
		value = httpData.getElementsByTagName('row')[i].getElementsByTagName('value')[0].childNodes[0].nodeValue;		
		table+='<td class=\"JrListBoxHideValue\">'+value+'</td>';
		Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxValues[i]=value;
		cols = httpData.getElementsByTagName('row')[i].getElementsByTagName('col');
	    for (c=0; c<cols.length; c++)
	    {
	        table+='<td onmouseover=\"Jr.listBox.tdOver(this,'+i+');\" '+style+' onmouseout=\"Jr.listBox.tdOut(this,'+i+');\" nowrap onclick=\"Jr.listBox.tdClick(this);\">'+cols[c].childNodes[0].nodeValue+'</td>';
	    }
		table+='</tr>';
	}
	if (rows==0 && noresulttext!='') table='<td>'+noresulttext+'</td>';
	//alert(table);
	Jr.util.ge('Jr-listBox-object').innerHTML='<table class=\"JrListBoxTable\" cellspacing=\"0\" cellpadding=\"0\">'+table+'</table>';
}
Jr.listBox.tdClick = function(oTD)
{
	val = oTD.parentNode.getElementsByTagName('td')[0].innerHTML;
	if (val.length == 0) return false;
	Jr.listBox.boxs[Jr.listBox.actualBoxId].value=val;
}
Jr.listBox.tdOver = function(oTD,c)
{
	try {
		if (Jr.listBox.navigationResult != c && Jr.listBox.navigationResult != -1)
		{
			oTR=Jr.util.ge('Jr-listBox-object').getElementsByTagName('table')[0].rows[Jr.listBox.navigationResult].getElementsByTagName('td');
			for (i=0; i<oTR.length; i++)
			{
			    oTR[i].style.backgroundColor=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleBgColor;
			    oTR[i].style.color=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleColor;
			}
		}
		Jr.listBox.navigationResult = c;
		oTR = oTD.parentNode.getElementsByTagName('td');	
		for (i=0; i<oTR.length; i++)
		{
		    oTR[i].style.backgroundColor=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleBgColor2;
		    oTR[i].style.color=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleColor2;
		}
	} 
	catch(err) 
	{ 
		txt="There was an error on this page.\n\n";
		txt+="Error description: " + err.description + "\n\n";
		txt+="Click OK to continue.\n\n";
		alert(txt);
	}
}
Jr.listBox.tdOut = function(oTD,c)
{
	try
	{
		oTR = oTD.parentNode.getElementsByTagName('td');
		for (i=0; i<oTR.length; i++)
		{
		    oTR[i].style.backgroundColor=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleBgColor;
		    oTR[i].style.color=Jr.listBox.boxs[Jr.listBox.actualBoxId].listBoxTdStyleColor;
		}
	} 
	catch(err) {}
}
Jr.listBox.loadData = function(packetId, listBoxId, value, iTimeout)
{
	if (packetId != Jr.listBox.packetId) return;
	if (Jr.listBox.actualBoxId != listBoxId) return;
	//
	if (iTimeout !=0)
	{
		Jr.util.trace('volam packet = '+packetId);
		setTimeout('Jr.listBox.loadData('+packetId+','+listBoxId+',\"'+value+'\",0)', iTimeout);
		return false;
	}
	if (iTimeout == 0)
	{
		//Jr.util.ge('Jr-listBox-object').innerHTML = '<img src=\"/i/loading_blue.gif\" />';

		if (Jr.listBox.boxs[listBoxId].listBoxOldValue == Jr.listBox.boxs[listBoxId].value)
			return;
			
		Jr.listBox.boxs[listBoxId].listBoxOldValue = Jr.listBox.boxs[listBoxId].value;
		
		Jr.listBox.navigationResult = -1;
		Jr.util.trace('DOTAZ NA SIET '+packetId+':'+listBoxId+':'+value);
		Jr.util.trace('URL: '+Jr.listBox.boxs[listBoxId].listBoxUrl);
		options = { asynchronous: true,
					type: 'POST',
					url: Jr.listBox.boxs[listBoxId].listBoxUrl,
					onSuccess: Jr.listBox.innerResult,
					data: 'listBoxId='+listBoxId+'&name='+Jr.listBox.boxs[listBoxId].name+'&id='+Jr.listBox.boxs[listBoxId].id+'&c='+value
				  };
		
		Jr.http.request(options)
	}
	
	
	
}
Jr.listBox.switchBox = function(oInput,e)
{
	if (Jr.listBox.actualBoxId != oInput.listBoxId)
	{
		Jr.listBox.actualBoxId = oInput.listBoxId;
		Jr.util.trace('--- switch : '+Jr.listBox.actualBoxId+' ---');
		if (Jr.listBox.controlStatus == 1)
		{
			Jr.listBox.closeResult();
			Jr.listBox.controlStatus = 0;
		}
		oInput.listBoxOldValue = '';
	}
}
Jr.listBox.openResult = function(oInput,e)			//	open result - div
{
	oDiv = Jr.util.ge('Jr-listBox-object');
	oDiv.innerHTML = Jr.listBox.htmlLoading;

	//Jr.util.setWidth(oDiv, Jr.util.getWidth(oInput));
	Jr.util.movePos(oDiv, oInput, 0, 15);
	Jr.util.show(oDiv);
}
Jr.listBox.closeResult = function()				//	close result - div 
{
	Jr.util.hidden(Jr.util.ge('Jr-listBox-object'));
}

Jr.listBox.createHTMLObject = function()
{
	div = document.createElement('div');
	div.id = 'Jr-listBox-object';
	div.style.position='absolute';
	div.style.top='0px';
	div.style.left='0px';
	div.style.border='1px #0066B2 solid';
	div.style.display = 'none';
	div.style.zIndex = 521;
	div.style.backgroundColor = 'white';
	div.$oldDisplay = 'block';
	div.innerHTML = Jr.listBox.htmlLoading;
	document.body.appendChild(div);
}

//	==================================================================================
//	D a t e   p i c k e r
//	~~~~~~~~~~~~~~~~~~~~~
Jr.datePicker = {};
Jr.datePicker.obj = null;
Jr.datePicker.iTimeout = 300;
Jr.datePicker.language = 'sk';
Jr.datePicker.init = function(o)
{
	o.root = o;
	o.style.border='1px solid gray';
	o.onclick = Jr.datePicker.show;
	o.onblur = function() { Jr.datePicker.close(Jr.datePicker.iTimeout); };
	o.onmouseout = function(e) { Jr.datePicker.onmouseout(e); };
	o.onkeydown = function(e) { Jr.datePicker.onmouseout(e); };
};
Jr.datePicker.show = function()
{
	var o = Jr.datePicker.obj = this;
	if (typeof document.JrDatePickerObject == 'undefined')
		Jr.datePicker.createHTMLObject();
	var oDate = Jr.util.ge('Jr-datePicker-object');
	document.JrDatePickerObject.status = 1;
	Jr.util.movePos(oDate, this, 0, 20);
	Jr.util.show(oDate);
	if (Jr.util.checkDate(o.value))
	{
		oDate.setDate(o.value);
		a = o.value.split('.');
		o.den = a[0]; o.mes = a[1]; o.rok = a[2];
	}
	else
	{
		now = new Date();
		oDate.setDate(Jr.util.date(now));
		a = Jr.util.date(now).split('.');
		o.den = a[0]; o.mes = a[1]; o.rok = a[2];
	}
};
Jr.datePicker.getMonth = function(mes)
{
	mes=mes-1;
	if (Jr.datePicker.language == 'sk')
		months = new Array('Január','Február','Marec','Apríl','Máj','Jún','Júl','August','September','Október','November','December');
	else
		months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	return months[mes];
};
Jr.datePicker.getDay = function(day)
{
	if (Jr.datePicker.language == 'sk')
	{
		if (day==1) return "Po"; if (day==2) return "Ut"; if (day==3) return "St"; if (day==4) return "Št"; 
		if (day==5) return "Pi"; if (day==6) return "So"; if (day==7) return "Ne";
	}
	if (day==1) return "Mo"; if (day==2) return "Tu"; if (day==3) return "We"; if (day==4) return "Th";
	if (day==5) return "Fr"; if (day==6) return "Sa"; if (day==7) return "Su"; 
};
Jr.datePicker.setDate = function(new_date, flag_month)
{
	picker = this;
	a = new_date.split('.');
	den = parseInt(a[0],10); mes = parseInt(a[1],10); rok = parseInt(a[2],10);
	//picker.setTitle(den,mes,rok,den+' '+picker.getMonth(mes)+' '+rok);
	picker.setTitle(den,mes,rok,picker.getMonth(mes)+' '+rok);
	picker.setBody(den,mes,rok);
	if (flag_month==1) document.JrDatePickerObject.status=1;
};
Jr.datePicker.setBody = function(den,mes,rok)
{
	first_day = Jr.util.date2('1.'+mes+'.'+rok).getDay();
	if (first_day == 0) first_day=7;
	last_day = -1;
	if (last_day==-1) {  if (Jr.util.checkDate('31.'+mes+'.'+rok)) last_day=31; }
	if (last_day==-1) {  if (Jr.util.checkDate('30.'+mes+'.'+rok)) last_day=30; }
	if (last_day==-1) {  if (Jr.util.checkDate('29.'+mes+'.'+rok)) last_day=29; }
	if (last_day==-1) {  if (Jr.util.checkDate('28.'+mes+'.'+rok)) last_day=28; }
	body='<div class="JrDPDH">'+picker.getDay(1)+'</div>';
	body+='<div class="JrDPDH">'+picker.getDay(2)+'</div>';
	body+='<div class="JrDPDH">'+picker.getDay(3)+'</div>';
	body+='<div class="JrDPDH">'+picker.getDay(4)+'</div>';
	body+='<div class="JrDPDH">'+picker.getDay(5)+'</div>';
	body+='<div class="JrDPDH">'+picker.getDay(6)+'</div>';
	body+='<div class="JrDPDH">'+picker.getDay(7)+'</div>';
	body+='<div class="JrDPDx"></div>';
	pc = 1;
	prep=0;
	for (x=1; x<=42; x++)
	{
		if (prep == 1) continue;
		if (x<first_day)
			body+='<div class="JrDPD">&nbsp;</div>';
		else
		{
			if (pc <= last_day)
				body+='<div class="JrDPDa" onmousedown="Jr.datePicker.click('+pc+','+mes+','+rok+')">'+pc+'</div>';
			else
			{ 
				if (x==36) { prep=1; continue; }
				body+='<div class="JrDPD">&nbsp;</div>';
			}
			pc++;
		}
	}
	body+='<div class="JrDPDx"></div>';
	Jr.util.ge('Jr-datePicker-body').innerHTML = body;
};
Jr.datePicker.setTitle = function(den,mes,rok,new_title)
{
	Rden=1; Rmes=mes+1; Rrok=rok;
	if (Rmes>12) { Rmes=1; Rrok=Rrok+1; };
	Lden=1; Lmes=mes-1; Lrok=rok;
	if (Lmes<1) { Lmes=12; Lrok=Lrok-1; };
	title = Jr.util.ge('Jr-datePicker-title');
	title.innerHTML = '<div class="JrDPTaR" onmousedown="Jr.datePicker.setDate(\''+Rden+'.'+Rmes+'.'+Rrok+'\',1);"></div><div class="JrDPTaL" onmousedown="Jr.datePicker.setDate(\''+Lden+'.'+Lmes+'.'+Lrok+'\',1);"></div>'+new_title;
};
Jr.datePicker.click = function(den,mes,rok)
{
	this.obj.value = den+'.'+mes+'.'+rok;
};
Jr.datePicker.createHTMLObject = function()
{
	div = document.createElement('div');
	div.id = 'Jr-datePicker-object';
	div.style.position='absolute';
	div.style.top='0px';
	div.style.left='0px';
	div.style.border='1px #0066B2 solid';
	if (Jr.IE)	div.style.width='134px';
	else		div.style.width='135px';
	div.style.display = 'none';
	div.style.backgroundImage = 'url(../i/cal/bg.jpg)';
	div.style.zIndex = 521;
	div.innerHTML = '<div id="Jr-datePicker-title"></div><div id="Jr-datePicker-body" style="margin:1px;margin-bottom:0px;"></div>';
	div.setDate = Jr.datePicker.setDate;
	div.setTitle = Jr.datePicker.setTitle;
	div.getMonth = Jr.datePicker.getMonth;
	div.getDay = Jr.datePicker.getDay;
	div.setBody = Jr.datePicker.setBody;
	div.den = 0;
	div.mes = 0;
	div.rok = 0;
	div.onmouseover = Jr.datePicker.onmouseover;
	div.onmouseout = Jr.datePicker.onmouseout;
	document.body.appendChild(div);
	document.JrDatePickerObject = new Object();
	document.JrDatePickerObject.status = 0;			//	0-hidden, 1-show, 2-closed by
};
Jr.datePicker.close = function(time)
{
	if (typeof document.JrDatePickerObject == 'undefined')	Jr.datePicker.createHTMLObject();
	if (time>100)
	{
		document.JrDatePickerObject.status = 2;
		setTimeout('Jr.datePicker.close()', time);
		return;
	};
	if (document.JrDatePickerObject.status != 1)
	{
		Jr.util.hidden(Jr.util.ge('Jr-datePicker-object'));
		document.JrDatePickerObject.status = 0;
	};
};
Jr.datePicker.onmouseover = function(e)
{
	e = Jr.util.fixEvent(e);
	if (typeof document.JrDatePickerObject == 'undefined') return;
	document.JrDatePickerObject.status=1;
};
Jr.datePicker.onmouseout = function(e)
{
	e = Jr.util.fixEvent(e);
	if (typeof document.JrDatePickerObject == 'undefined') return;
	document.JrDatePickerObject.status = 2;
	Jr.datePicker.close(Jr.datePicker.iTimeout);
};


//	==================================================================================
//	H T T P   r e q u e s t
Jr.http.oHttpObject = function()
{
	if (typeof XMLHttpRequest == 'undefined')
		return new ActiveXObject( navigator.userAgent.indexOf("MSIE 5") >= 0 ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
	else
		return new XMLHttpRequest();
}
 

Jr.http.request = function(options)
{
	// Load the options object with defaults, if no values were provided by the user
	options = { 
		asynchronous: options.asynchronous || false,
		type: options.type || "POST",
		url: options.url || "",
		contentType: options.contentType || 'text/html',
		timeout: options.timeout || 5000,
		onComplete: options.onComplete || function(){},
		onError: options.onError || function(){},
		onSuccess: options.onSuccess || function(){},
		// The data type that'll be returned from the server the default is simply to determine what data was returned from the
		// and act accordingly.
		data: options.data || null
	};
	if (options.url.indexOf('?')>=1) options.url=options.url+'&ts='+(new Date().getTime());
	if (options.url.indexOf('?')==-1) options.url=options.url+'?ts='+(new Date().getTime());
	var oHttp = new Jr.http.oHttpObject();
	oHttp.open(options.type, options.url, options.asynchronous);
	
	if (options.type=='POST' && options.data.length>0)
	{
		oHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		oHttp.setRequestHeader("Content-length", options.data.length);
		oHttp.setRequestHeader("Connection", "close");
		
	}
	var timeoutLength = options.timeout;
	var requestDone = false;
	setTimeout( function() { requestDone = true; }, timeoutLength);		//	turn on - timeout
	
	oHttp.onreadystatechange = function()
	{
		// Wait until the data is fully loaded, and make sure that the request hasn't already timed out
		if ( oHttp.readyState == 4 && !requestDone ) 
		{
			
			// Check to see if the request was successful
			if (httpSuccess(oHttp)) 
			{
				// Execute the success callback with the data returned from the server
				
				options.onSuccess( httpData(oHttp) );
				//options.onSuccess( 'ddddddddddd' );
			} 
			else 
			{ 
				options.onError(); 
			}
			options.onComplete();
			// Clean up after ourselves, to avoid memory leaks
			oHttp = null;
		}
	};
	oHttp.send(options.data);
	// Determine the success of the HTTP response
	function httpSuccess(r) 
	{
		try 
		{
			// If no server status is provided, and we're actually requesting a local file, then it was successful
			return !r.status && location.protocol == "file:" ||
							// Any status in the 200 range is good
				   ( r.status >= 200 && r.status < 300 ) ||
							// Successful if the document has not been modified
				   r.status == 304 ||
							// Safari returns an empty status if the file has not been modified
				   navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
		} catch(e){}
		// If checking the status failed, then assume that the request failed too
		return false;
	}
		
	// Extract the correct data from the HTTP response
	function httpData(r) 
	{
		// Get the content-type header
		var ct = r.getResponseHeader("content-type");
		// If no default type was provided, determine if some form of XML was returned from the server
		if (ct.indexOf('xml')>=0) return r.responseXML;
		if (ct.indexOf('text/javascript') >= 0) { eval.call( window, r.responseText ); return ''; } 
		
		return r.responseText;
	}
}


var SortTable = function(tableEl) 
{
	this.tbody = tableEl.getElementsByTagName('tbody');
    this.thead = tableEl.getElementsByTagName('thead');
    this.tfoot = tableEl.getElementsByTagName('tfoot');

	this.getInnerText = function(el) 
	{
//		if (typeof(el.textContent) != 'undefined') return el.textContent;
//		if (typeof(el.innerText) != 'undefined') return el.innerText;
		if (typeof(el.innerHTML) == 'string') return el.innerHTML.replace(/<[^<>]+>/g,'');
	}
	this.getParent = function(el, pTagName) 
	{
		if (el == null) return null;
		else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
			return el;
		else
			return this.getParent(el.parentNode, pTagName);
    }
    this.sort = function(cell)
	{
		var column = cell.cellIndex;
		var itm = this.getInnerText(this.tbody[0].rows[1].cells[column]);
		var sortfn = this.sortCaseInsensitive;

		if (itm.match(/\d\d[-]+\d\d[-]+\d\d\d\d/)) sortfn = this.sortDate; // Date format mm-dd-yyyy
		if (itm.replace(/^\s+|\s+$/g,"").match(/^[\d\.]+$/)) sortfn = this.sortNumeric;

        this.sortColumnIndex = column;

        var newRows = new Array();
        for (j = 0; j < this.tbody[0].rows.length; j++) 
        {
			newRows[j] = this.tbody[0].rows[j];
		}

        newRows.sort(sortfn);

        if (cell.getAttribute("sortdir") == 'down') {
            newRows.reverse();
            cell.setAttribute('sortdir','up');
        } else {
            cell.setAttribute('sortdir','down');
        }
		
        for (i=0;i<newRows.length;i++) {
            this.tbody[0].appendChild(newRows[i]);
        }

    }

    this.sortCaseInsensitive = function(a,b) {
        aa = thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]).toLowerCase();
        bb = thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]).toLowerCase();
        if (aa==bb) return 0;
        if (aa<bb) return -1;
        return 1;
    }

    this.sortDate = function(a,b) {
        aa = thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]);
        bb = thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]);
        date1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
        date2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
        if (date1==date2) return 0;
        if (date1<date2) return -1;
        return 1;
    }

    this.sortNumeric = function(a,b) {
        aa = parseFloat(thisObject.getInnerText(a.cells[thisObject.sortColumnIndex]));
        if (isNaN(aa)) aa = 0;
        bb = parseFloat(thisObject.getInnerText(b.cells[thisObject.sortColumnIndex]));
        if (isNaN(bb)) bb = 0;
        return aa-bb;
    }

    // define variables
    var thisObject = this;
    var sortSection = this.thead;

    // constructor actions
    if (!(this.tbody && this.tbody[0].rows && this.tbody[0].rows.length > 0)) return;

    if (sortSection && sortSection[0].rows && sortSection[0].rows.length > 0) {
        var sortRow = sortSection[0].rows[0];
    } else {
        return;
    }

    for (var i=0; i<sortRow.cells.length; i++) {
        sortRow.cells[i].sTable = this;
        sortRow.cells[i].onclick = function () {
            this.sTable.sort(this);
            return false;
        }
    }

}