﻿window.onload = choosePic;

var adImages = new Array("images/daro/mini1.jpg", "images/daro/mini2.jpg","images/daro/mini3.jpg","images/daro/mini4.jpg");
var thisAd;
function rotate2(){

thisAd++;
if(thisAd == adImages.length){
thisAd = 0;
}
document.getElementById("adBanner").src = adImages[thisAd];
setTimeout("rotate2()", 9 * 1000);

}

function choosePic(){

thisAd = Math.floor((Math.random() * adImages.length));
document.getElementById("adBanner").src = adImages[thisAd];

rotate2();

}



var http_request = false;


 function edytuj_aktualnosci() {
     var zmiennaaa = "tresc=" + encodeURI( document.getElementById("id_aktualnosci").value )+ "&id_aktualnosci=" + encodeURI(document.getElementById("id_act").value);
     makePOSTRequest('./ajax/edytuj_aktualnosci.inc.php',zmiennaaa);
 }
//usuwanie aktualnosci
function usun_aktualnosci(id_produktu) {
	
     var usuwaniee = "id=" + encodeURI(id_produktu);
     makePOSTRequest('./ajax/usun_aktualnosci.inc.php',usuwaniee);
        
}

function usun_wpis_goscia(id_produktu) {
	
     var usuwaniee2 = "id=" + encodeURI(id_produktu);
     makePOSTRequest('./ajax/usun_wpisy.inc.php',usuwaniee2);
        
}
function edytuj_wpisy() {
     var zmiennaaa2 = "tresc=" + encodeURI( document.getElementById("tresc_wpisu").value )+ "&id_wpisu=" + encodeURI(document.getElementById("id_wpisu").value)+ "&dodal=" + encodeURI(document.getElementById("dodal").value);
     makePOSTRequest('./ajax/edytuj_wpisy.inc.php',zmiennaaa2);
 }
 
 function edytuj_start() {
     var editstart = "miejsce=" + encodeURI( document.getElementById("miejsce").value )+ "&id_startu=" + encodeURI(document.getElementById("id_startu").value)+ "&data=" + encodeURI(document.getElementById("data").value)+ "&rezultat=" + encodeURI(document.getElementById("rezultat").value) + "&dystans=" + encodeURI(document.getElementById("dystans").value)+ "&komentarz=" + encodeURI(document.getElementById("komentarz").value);
     makePOSTRequest('./ajax/edytuj_start.inc.php', editstart);
 }
 
 function usun_starty(id_produktu) {
	
     var usun_start = "id=" + encodeURI(id_produktu);
     makePOSTRequest('./ajax/usun_start.inc.php',usun_start);
        
}

function edytuj() {
     var zmiennaaa2 = "imie=" + encodeURI( document.getElementById("imie").value )+ "&id_usera=" + encodeURI(document.getElementById("id_usera").value)+ "&data=" + encodeURI(document.getElementById("data").value)+ "&nazwisko=" + encodeURI(document.getElementById("nazwisko").value)+ "&dyscyplina=" + encodeURI(document.getElementById("dyscyplina").value)+ "&avatar=" + encodeURI(document.getElementById("avatar").value);
     makePOSTRequest('./ajax/edytuj_profil.inc.php',zmiennaaa2);
 }
 
 
//logowanie
function zaloguj() {
     var poststr2 = "email=" + encodeURI( document.getElementById("email").value ) + "&haslo=" + encodeURI( document.getElementById("haslo").value);
     makePOSTRequest('./ajax/logowanie.inc.php',poststr2);
	setTimeout("location.reload()",1000);
        
}

//rejestracja
function rejestruj() {
     var poststr = "email=" + encodeURI( document.getElementById("email1").value) +"&haslo1=" +encodeURI( document.getElementById("pass1").value) + "&haslo2="+encodeURI( document.getElementById("pass21").value);
     makePOSTRequest2('./ajax/rejestracja.inc.php',poststr);
        
}


function makePOSTRequest(url, parameters) {
        http_request = false;
		if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/html');
            }
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

	http_request.onreadystatechange = function(){
           
		   if (http_request.readyState == 4) {
                if (http_request.status == 200) {
                    result = http_request.responseText;
                    document.getElementById('odpowiedz_serwera').innerHTML = result;
										
                }
                else {
                    document.getElementById('odpowiedz_serwera').innerHTML = "Wystąpił błąd!";
                }
            }
        };
        
        http_request.open('POST', url, true);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http_request.send(parameters);

}


function makePOSTRequest2(url, parameters) {
        http_request = false;
		if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/html');
            }
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

	http_request.onreadystatechange = function(){
           
		   if (http_request.readyState == 4) {
                if (http_request.status == 200) {
                    result = http_request.responseText;
                    document.getElementById('odpowiedz_serwera2').innerHTML = result;
										
                }
                else {
                    document.getElementById('odpowiedz_serwera2').innerHTML = "Wystąpił błąd!";
                }
            }
        };
        
        http_request.open('POST', url, true);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http_request.send(parameters);

}



