function openCalendarWindow(nameField, nameForm)
{
	width = 200;
	height = 200;
	posLeft = parseInt(screen.width / 2 - width / 2);
	posTop = parseInt(screen.height / 2 - height / 2);
	window.open('index.php?m=System&f=Calendar&name='+nameField+'&name_form='+nameForm,'Orion','top='+posTop+',left='+posLeft+',toolbar=no,scrollbars=no,directories=no,status=no,menubar=no,resizable=no,width='+width+',height='+height);
}

function openCase(id, options)
{
	width = 500;
	height = 400;
	posLeft = parseInt(screen.width / 2 - width / 2);
	posTop = parseInt(screen.height / 2 - height / 2);
	if (options == null)
		var WindowName = 'Webton'+id;
	else
		var WindowName = 'Webton'+id+'x'+options;
	window.open('index.php?m=Admin&f=CaseView&id='+id+'&options='+options,WindowName,'top='+posTop+',left='+posLeft+',toolbar=no,scrollbars=yes,directories=no,status=no,menubar=no,resizable=no,width='+width+',height='+height);
}

function getElement(id)
{
	with (document) var element = getElementById ? getElementById(id) : all ? all[id] : layer[id];
	if(!element.style) element.style = element;
	return element;
}

function hideElement(name)
{
	getElement(name).style.display = 'none';
}

function viewElement(name)
{
	getElement(name).style.display = 'block';
}

function elementOnOff(name)
{
	if (getElement(name).style.display == 'none')
		getElement(name).style.display = 'block';
	else
		getElement(name).style.display = 'none';
}

function exeAjax(url, params)
{
	url = url + '&x=' + parseInt(Math.random()*99999999) + '&ajaxparam=' + params;
	myRequest.open('GET', url, true);
	myRequest.onreadystatechange = responseAjax;
	myRequest.send(null);
}

function getRequest()
{
	var req = false;
	try
	{
		req = new XMLHttpRequest();
	}
	catch(err1)
	{
		try
		{
			req = new ActiveXObkect("Msxml2.XMLHTTP");
		}
		catch(err2)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(err3)
			{
				req = false;
			}
		}
	}
	return req;
}

function responseAjax()
{
	if (myRequest.readyState == 4)
	{
		if (myRequest.status == 200)
		{
			var xml = myRequest.responseXML;
			var status = xml.getElementsByTagName('status')[0].childNodes[0].nodeValue;
			if (status == 'ok')
			{
				//alert(myRequest.responseText);
				var action = xml.getElementsByTagName('action')[0].childNodes[0].nodeValue;
				var comment = xml.getElementsByTagName('comment')[0].childNodes[0].nodeValue;
				var option = xml.getElementsByTagName('option')[0].childNodes[0].nodeValue;
				switch (action)
				{
					case 'none':
					{
						//alert('ajax: none');
						break;
					}
					case 'getNewCase':
					{
						//alert(myRequest.responseText);
						openCase(comment, option);
						break;
					}
					default:
					{
						alert('brak komendy (js): ' + action);
						break;
					}
				}
			}
			else
			{
				var comment = xml.getElementsByTagName('comment')[0].childNodes[0].nodeValue;
				alert(comment);
			}
		}
		else
		{
			alert('AjaxError: ' + myRequest.status);
		}
	}
}
var myRequest = getRequest();
