//Browser Support Code
function ajaxFunction(funkcja){
	var ajaxRequest;  // The variable that makes Ajax possible!	
		
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("AJAX nie jest obsługiwany :(");
				return false;
			}
		}
    }
    // Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
	       if (funkcja == "updateWybor")
	       {	
	          var ilosc_zdj = document.getElementById("IloscZdj").innerHTML		
		      if (wybrany == false)
		      {
		          opis = "Zdjęcie usunięto z listy wybranych";
		          ilosc_zdj--;
              }else{
                    opis = "Zdjęcie dodano do listy wybranych";
                    ilosc_zdj++;
              }
              document.getElementById("IloscZdj").innerHTML = ilosc_zdj;
		      document.getElementById("wynik_zapisu").innerHTML = opis;
		      setTimeout("wyczysc_opis()" , 5000) ;
            }else if (funkcja == "sprawdzWybor"){
                document.form_wybor.zdj_wybrane.checked = ajaxRequest.responseText;
                document.form_wybor.zdj_wybrane.style.visibility = "visible";
                document.getElementById("wyborLab").innerHTML = WyborOpis;//"Wybieram";
            }else if (funkcja == "TylkoWybrane"){
                Album_js.tab_zdjecia = ajaxRequest.responseText.split(",");
                ilosc_zdj = document.getElementById("IloscZdj").innerHTML;
                Album_js.max_zdjec = ilosc_zdj;
                if (ilosc_zdj < 1)
                {
                    Album_js.koniec = 1;
                }
                Album_js.WyswietlZdjecie(0);

            }
        }
    }
    if (funkcja == "updateWybor")
    {
        var wybrany = document.form_wybor.zdj_wybrane.checked;
        var zdj = document.form_wybor.zdjecie_id.value;
        var wyb_name = document.form_wybor.album_name.value;
        var queryString = "?id=" + zdj + "&wybor=" + wybrany+"&fun=updateWybor&name="+wyb_name;
        //alert (queryString);
	    ajaxRequest.open("GET", "zdj_wybor.php" + queryString, true);
	    ajaxRequest.send(null);	
    }else if (funkcja == "sprawdzWybor"){
        document.form_wybor.zdj_wybrane.style.visibility = "hidden";
        WyborOpis = document.getElementById("wyborLab").innerHTML;
        document.getElementById("wyborLab").innerHTML = "Sprawdzam ...";
        var wybrany = document.form_wybor.zdj_wybrane.checked;
        var zdj = document.form_wybor.zdjecie_id.value;
        var wyb_name = document.form_wybor.album_name.value;
        var queryString = "?id=" + zdj + "&fun=sprWybor&name="+wyb_name;
	    ajaxRequest.open("GET", "zdj_wybor.php" + queryString, true);
	   // alert("zdj_wybor.php" + queryString);
	    ajaxRequest.send(null);	
    }else if (funkcja == "TylkoWybrane"){
        var wyb_name = document.form_wybor.album_name.value;
        wybrany = document.form_wybor.TylkoWybranChkBox.checked;
        if (wybrany)
        {
            Album_tab_all = Album_js.tab_zdjecia;
            Album_all_max = Album_js.max_zdjec;
            //Album_js.tab_zdjecia = new Array();
            queryString = "?fun=TylkoWybrane&name="+wyb_name;
       	    ajaxRequest.open("GET", "zdj_wybor.php" + queryString, true);
    	    ajaxRequest.send(null);	
        }
        else{
            Album_js.tab_zdjecia = Album_tab_all;
            Album_js.max_zdjec = Album_all_max;
            Album_js.WyswietlZdjecie(0);
        }
    }
}
function wyczysc_opis()
{
    document.getElementById("wynik_zapisu").innerHTML = "";
}

function test(){
    var wybrany = document.form_wybor.zdj_wybrane.checked;
    var zdj = document.form_wybor.zdjecie_id.value;
    alert(zdj);
}




