var xmlHttp = createXmlHttpRequestObject2();

function menu2(id_menu){
	element = document.getElementById('drugi_poziom2_'+id_menu);
	przycisk = document.getElementById('drugi_poziom_'+id_menu);
	if(element.style.display == 'block'){
		$("div#drugi_poziom2_"+id_menu).slideUp("slow");
		przycisk.style.background='url(gfx/plus.png) no-repeat top right';
	}
	else {
		$("div#drugi_poziom2_"+id_menu).slideDown("slow");
		przycisk.style.background='url(gfx/minus.png) no-repeat top right';
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
		xmlHttp.open("POST", "files/set_session_variable.php", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = session_insert;
		xmlHttp.send('id_menu='+id_menu);
	}
}

function session_insert()
{

	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200){
			/*
			TO ZOSTAWIAM NA WYPADEK JEZELI CHCIALBYS PRZECHWYCIC COS ZWROTNEGO
			*/
			xmlResponse = xmlHttp.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;

			kom = xmlDocumentElement.childNodes[0].firstChild.data;
			alert(kom);

		}
		else {
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}

function createXmlHttpRequestObject2()
{
	var xmlHttp;
	try
	{
		// próba utworzenie uchwytu dla różnych przegladarek
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		// dla IE6 i starszych wykrywamy najnowsza wersje ActiveX
		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0',	'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP');
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				// próba utworzenie uchwytu dla IE
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {} // ignorujemy błędy
		}
	}
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
}
