$(function() {
	
	$("#region").bind("change", function() {
		$('#hotel').find('option').remove().end();
		$.ajax({
			type: "GET",
			url: "ajax.php?region="+$(this).val(),
			dataType: "json",
			success: function(data) {
				$("#hotel").addItems(data);
		   }
		});
	});
});

$.fn.addItems = function(data) {
	return this.each(function() {
        $.each(data, function(index, itemData) {
			var thisValue = itemData;
			var thisText  = itemData;
			var thisOpt   = document.createElement('option');
			thisOpt.value = thisValue;
			thisOpt.appendChild(document.createTextNode(thisText));
			$("#hotel").append(thisOpt);
    	});
	});
};

function redirect ()
{
	$.ajax({
		type: "GET",
		async: false,
		url: "send_visite.php?id="+$('#hotel').val()+'&region='+$('#region').val()+'&langue='+$('#langue').val(),
		success: function(data) {
			window.open (data, '', config='height=700, width=900, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes, location=yes, directories=no, status=no');
		}
	});
	
	return false;
}
