// Declare our request variable.
var request = false;

// Define a function that will make our request for us:
function filterHotels(tip) {
    // Clear the curent request
    request = false;
	var tip = tip;
	//var checkbox_locatie = document.hotels.locatie;
	var checkbox_parcare = document.hotels.parcare;
	var checkbox_mic_dejun = document.hotels.mic_dejun;
	var checkbox_stele = document.hotels.stele;
	
	document.getElementById('loading_div').className = '';
	
	//alert(categ_id);
	//alert(getSelectedCheckboxValue(checkbox_stele)+"\n"+getSelectedCheckboxValue(checkbox_mic_dejun));
    //alert();
	
	// Generate the request object and handle different browsers:
    if (window.XMLHttpRequest) { // Mozilla & other compliant browsers
        request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // Internet Explorer
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }

    // If we don't have a request object, then error out.
    if (!request) {
        alert('Browser does not support AJAX!');
        return false;
    }

    // Ok, now we are ready.  Make the request, and tell it to run the
    // function 'updateDate' when it gets data back.
    request.onreadystatechange = updateHotels;

    // Open the connection, sending the current value of the form element:
   //alert('http://www.sibiul.ro/ajax-filtre-restaurante.php?tip=' + getSelectedCheckboxValue(checkbox_fields) + '&livrare=' + getSelectedCheckboxValue(checkbox_livrare));
   request.open('GET',
        'http://www.sibiul.ro/ajax-filtre-cazare.php?parcare=' + getSelectedCheckboxValue(checkbox_parcare)+ '&mic_dejun=' + getSelectedCheckboxValue(checkbox_mic_dejun)+ '&stele=' + getSelectedCheckboxValue(checkbox_stele)+'&tip=' + tip)
    request.send(null); //locatie=' + getSelectedCheckboxValue(checkbox_locatie) + '&
}

// The function that will accept the data, and update the page:
function updateHotels() {
    // Make sure that the state is '4', which means finished:
    if (request.readyState == 4) {
        // Make sure that the status is 200, or 'ok'
		//alert("ReadyStaste = 4");
        if (request.status == 200) {
            // And now, update the text on the page:
            var text = document.getElementById('filtred_hotels');
            //text.innerHTML = result.firstChild.data;
			
			text.innerHTML = request.responseText;
        } else {
            alert('Error performing request!' + request.status);
        }
    }
}

/*-----------------------------------------------------------+
 | addLoadEvent: Add event handler to body when window loads |
 +-----------------------------------------------------------*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	
	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

/*------------------------------------+
 | Functions to run when window loads |
 +------------------------------------*/
addLoadEvent(function () {
	initChecklist();
});

/*----------------------------------------------------------+
 | initChecklist: Add :hover functionality on labels for IE |
 +----------------------------------------------------------*/
function initChecklist() {
	if (document.all && document.getElementById) {
		// Get all unordered lists
		var lists = document.getElementsByTagName("ul");
		
		for (i = 0; i < lists.length; i++) {
			var theList = lists[i];
			
			// Only work with those having the class "checklist"
			if (theList.className.indexOf("checklist_filtre") > -1) {
				var labels = theList.getElementsByTagName("label");
				
				// Assign event handlers to labels within
				for (var j = 0; j < labels.length; j++) {
					var theLabel = labels[j];
					theLabel.onmouseover = function() { this.className += " hover"; };
					theLabel.onmouseout = function() { this.className = this.className.replace(" hover", ""); };
				}
			}
		}
	}
}


/*<script src="<?= $website_address;?>/ajax-news.js" type="text/javascript"></script>*/
