 function changeProvince() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('cities.php?province_id='+pr.value,'cities');
    }

 function changeProvinceByRestaurants() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('citiesRestaurants.php?province_id='+pr.value,'cities');
    }   

 function changeProvinceByHotels() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('citiesHotels.php?province_id='+pr.value,'cities');
    }   
 function changeProvinceByOthers() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('citiesOthers.php?province_id='+pr.value,'cities');
    }  
 function changeProvinceByOthersByRoutes() {
    // Funkcja dla selecta wyszukiwarki w dziale na rower
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        //alert('citiesOthers.php?province_na_rower_id='+pr.value);
        makeRequestCities('citiesOthers.php?province_na_rower_id='+pr.value,'cities');
 }      
 function changeProvinceByAttractions() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('citiesAttractions.php?province_id='+pr.value,'cities');
    }   
 function changeProvinceByEvents() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('citiesEvents.php?province_id='+pr.value,'cities');
    }   
 function changeProvinceByPartners() {
        if (document.getElementById) pr = document.getElementById('province');
        else if (document.all) pr = document.all['province'];
        else return;
        makeRequestCities('cities_partners.php?province_id='+pr.value,'cities');
    }    

 function changeRegion() {
        if (document.getElementById) pr = document.getElementById('region');
        else if (document.all) pr = document.all['region'];
        else return;
        makeRequestCities('cities.php?region_id='+pr.value,'cities');
    }
    function displayCities(cities) {
        if (document.getElementById) cityDiv = document.getElementById('cityd');
        else if (document.all) cityDiv = document.all['cityd'];
        else return;
        newDiv =  document.createElement("div");
        newDiv.setAttribute("id", "citys");
        newDiv.innerHTML = cities;
        if (document.getElementById) citysDiv = document.getElementById('citys');
        else if (document.all) citysDiv = document.all['citys'];
        else return;
        cityDiv.removeChild(citysDiv);
        cityDiv.appendChild(newDiv);


    }
    function makeRequestCities(url,type) {
        var httpRequest;

        if (window.XMLHttpRequest) {
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                  httpRequest.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Nie można wykonać połączenia.');
            return false;
        }
        httpRequest.onreadystatechange = function() {
            displayResponseCities(httpRequest,type);
        };
        httpRequest.open('GET', url, true);
        httpRequest.send(null);

    }

    function displayResponseCities(httpRequest,type) {
        //alert('ok');
        if (httpRequest.readyState == 4) {
            //alert('httpRequest.status: ' + httpRequest.status + ' text: ' + httpRequest.responseText);
            if (httpRequest.status == 200) {
                if (type == 'cities')  displayCities(httpRequest.responseText);
            } else {
                alert('Wystąpił problem z połączeniem -  status: ' + httpRequest.status);
            }
        }

    }
    
function makeRequest(url,type) {
     var httpRequest;

     if (window.XMLHttpRequest) {
         httpRequest = new XMLHttpRequest();
         if (httpRequest.overrideMimeType) {
               httpRequest.overrideMimeType('text/xml');
         }
     } else if (window.ActiveXObject) {
         try {
             httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
             try {
                 httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
         }
     }

     if (!httpRequest) {
         alert('Nie można wykonć połączenia.');
         return false;
     }
     httpRequest.onreadystatechange = function() {
         displayResponse(httpRequest,type);
     };
     httpRequest.open('GET', url, true);
     httpRequest.send(null);
     
     return httpRequest.responseText;

 }

 function displayResponse(httpRequest,type) {

     if (httpRequest.readyState == 4) {
         if (httpRequest.status == 200) {
         	 //location.reload(true);
         }
     }

 }    
