var xmlHttp = createXmlHttpRequestObject(); 

// zwraca obiekt XMLHttpRequest
function createXmlHttpRequestObject() {
	var xmlHttp = false;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch (trymicrosoft) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				xmlHttp = false;
			}  
		}
	}
	// zwraca utworzony obiekt lub wyswietla komunikat o błędzie
	if (!xmlHttp)
		alert("Błąd inicjalizacji obiektu XMLHttpRequest!");
	else
		return xmlHttp;
}

function switchProjekty(strona,ln) {
	//console.info("napis = %s",napis);
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		xmlHttp.open("GET", "./funkcje/ajax_wiecej_projektow.php?strona="+strona+"&ln="+ln, true);  
		xmlHttp.onreadystatechange = switchProjektyKomunikat;
		xmlHttp.send(null);
	} else {
		setTimeout('switchProjekty(strona,ln)', 1000);
		//console.info("nie zainicjowano xmlHttp");
	}
}


function switchProjektyKomunikat() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseText;
//console.info(xmlResponse);
//alert(xmlResponse);		
document.getElementById('prawiznaKontener').innerHTML = xmlResponse;
//document.getElementById('prawiznaKontener').innerHTML = '123';

			var foo = document.getElementById('wiecej');
			var ln = document.getElementById('ln');
			//alert(ln.firstChild.nodeValue);
			if(ln.firstChild.nodeValue==1) {//angielski
				if(foo.firstChild.nodeValue=='back') {
					foo.firstChild.nodeValue = 'more projects';
					foo.onclick = function() {switchProjekty(1, 1); return false;}
					foo.href="/?more=1";
				} else {
					foo.firstChild.nodeValue = 'back';
					foo.onclick = function() {switchProjekty(2, 1); return false;}
					foo.href="/";
				}	
			} else {
				if(foo.firstChild.nodeValue=='wróć') {
					foo.firstChild.nodeValue = 'więcej projektów';
					foo.onclick = function() {switchProjekty(1, 0); return false;}
					foo.href="/?more=1";
				} else {
					foo.firstChild.nodeValue = 'wróć';
					foo.onclick = function() {switchProjekty(2, 0); return false;}
					foo.href="/";
				}
			}
			//ln.firstChild.nodeValue = "1";
		}
		else {
			alert('Wystąpił błąd podczas uzyskiwania dostępu do serwera');
		}
	}
}
