var xyz;
function createREQ() {
      xmlHttp=false;
      if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
            if (xmlHttp.overrideMimeType) {
                xmlHttp.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!xmlHttp) {
  			alert('Twoja przegladarka nie obsluguje technologii Ajax!');
            return false;
        }
        return xmlHttp;
}

function requestGET(url, query, req) {
	myRand = parseInt(Math.random()*99999999);
	req.open("GET", url + '?' + query + '&rand=' + myRand, true);
	req.send(null);
}
function requestPOST(url, query, req) {
	req.open("POST", url, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(query);
}
function doCallback(callback, item) {
	eval(callback + '(item)');
}
function doAjax(url, query, callback, reqtype, getxml) {
	xyz = query;
	
	var myreq = createREQ();
	myreq.onreadystatechange = function() {
		if(myreq.readyState == 4) {
			if(myreq.status == 200) {
				//usun_okienko('preload');

var item = myreq.responseText;
data = item.split("\n");
arraylen = data.length;
var i = 0;
while(i < arraylen)
{
	if( data[i].indexOf("script") > -1)
	{
		i++;
		while(data[i].indexOf("/script") < 0)
		{
			eval(data[i]);
			i++;
		}
	}
	i++;
}

				if(getxml == 1) {
					item = myreq.responseXML;
				}
				doCallback(callback, item);
			}
		}

	}
	if(reqtype == 'post'){
		requestPOST(url, query, myreq);
	}
	else {
		requestGET(url, query, myreq);
	}
}



//-----------------------------------------------------------------------------------------
//--------------------------------- D O   A J A X -----------------------------------------
//-----------------------------------------------------------------------------------------
function loguj() {
	doAjax('login.php', 'login='+document.getElementById('textLogin').value+'&pass='+document.getElementById('textPass').value, 'login_sprawdz', 'post', '0');
}

function loguj1() {
	doAjax('login.php', 'login='+document.getElementById('textLogin1').value+'&pass='+document.getElementById('textPass1').value, 'login_sprawdz', 'post', '0');
}

function wyloguj() {
        doAjax('login.php','logout=1','login_sprawdz', 'post', '0');
}


//-----------------------------------------------------------------------------------------
//------------------------------------- A C T I O N S -------------------------------------
//-----------------------------------------------------------------------------------------
//body=document.getElementsByTagName('body');


function login_sprawdz(responseText) {
        
        if(responseText == 'notlogged'){  //błd logowania
	 //window.alert('Logowanie błędne - zły login');
	 document.location.reload();
	}
	else if(responseText == 'log_ok') { //zalogowanie
         //window.alert('Logowanie poprawne - witamy.');
         //document.location.href="index.html";
         document.location.reload();
	}
	else if(responseText == 'log_out') { //zalogowanie
         //window.alert('Logowanie poprawne - witamy.');
         document.location.href="index.html";
	}

}



//-----------------------------------------------------------------------------------------
//----------------------------------- P O Z O S T A Ł E -----------------------------------
//-----------------------------------------------------------------------------------------
function IE() {//wywołanie fixed.js (naprawa possition: fixed w IE)
	head=document.getElementsByTagName('head');
	js = document.createElement('script');
	js.type = 'text/javascript';
	js.src = 'fixed.js'; 
	head[0].appendChild(js);
}


