function setTravelType(id, name, country) {

	// visualisations
	var itemArray = $(".traveltypes_checkbox");
	if (id == 0) { // clicked on all types
		if ($("#traveltype\\[0\\]:checked").length) { // all types selected
			uncheckAll(itemArray, 1);
		} else {
			uncheckAll(itemArray, 0);
		}
	} else { // clicked on other type
		var otherSelected = false;
		for (var i = 1; i < itemArray.length; i++) {
			if (itemArray[i].checked) {
				otherSelected = true;
				break;
			}
		}
		if (!otherSelected) {
			$("#traveltype\\[0\\]").attr("checked", true);
			uncheckAll(itemArray, 1);
		} else {
			$("#traveltype\\[0\\]").attr("checked", false);
		}
	}

	// ajax
	getFirms(country);

}

function setGuarantees(id, name, country) {

	// visualisations
	var itemArray = $(".guarantees_checkbox");
	if (id == 0) { // clicked on all types
		if ($("#guarantees\\[0\\]:checked").length) { // all types selected
			uncheckAll(itemArray, 1);
		} else {
			uncheckAll(itemArray, 0);
		}
	} else { // clicked on other type
		var otherSelected = false;
		for (var i = 1; i < itemArray.length; i++) {
			if (itemArray[i].checked) {
				otherSelected = true;
				break;
			}
		}
		if (!otherSelected) {
			$("#guarantees\\[0\\]").attr("checked", true);
			uncheckAll(itemArray, 1);
		} else {
			$("#guarantees\\[0\\]").attr("checked", false);
		}
	}

	// ajax
	getFirms(country);

}

function getFirms(country) {

	$.ajax({
		type: "POST",
		url: "ajax_controller/getFirms",
		data: $("#selectForm").serialize() + "&country=" + country + "&sort=" + $("#firmSort").val(),
		success: function(data, textStatus){
			$("#firms_list").html(data);
		}
	});

}

function checkAll(field, i) {
	if (i == undefined) {
		i = 0;
	}
	for (i = 0; i < field.length; i++) {
		field[i].checked = true;
	}
}

function uncheckAll(field, i) {
	if (i == undefined) {
		i = 0;
	}
	for (i; i < field.length; i++) {
		field[i].checked = false;
	}
}

/*
function js_array_to_php_array (a) {
    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
    return a_php;
}
*/