
function manipulate_search_cuisines (fieldName, changedValue, allSelectedValue, checkedStatus) {
	if (typeof (changedValue) == 'undefined')
		return;

//	var temp = get_object (fieldName);
	var temp = document.getElementsByName(fieldName);


	// if a particular cuisine has 2 checkboxes, make sure both the checkbox's checked status is the same
	for (var i in jsCuisineLinks)
	{
		if (i == changedValue)
		{
			for (var i2 in jsCuisineLinks[i])
			{
				if (checkedStatus == true)
					temp[jsCuisineLinks[i][i2]].checked = true;
				else
					temp[jsCuisineLinks[i][i2]].checked = false;
			}
		}
	}


	// find out if "all cuisine" has been selected
	var allCusineWasSelected = false;
	var changedValueWasSelected = false;
	var allOthersAreUnselected = true;

	// find out what has been checked
	if (temp.length) {
		for (var count = 0; count < temp.length; count++) {
			if ((temp[count].value == allSelectedValue)) {
				if (temp[count].checked == true)
					allCusineWasSelected = true;
			}
			else {
				if (temp[count].checked == true)
					allOthersAreUnselected = false;
			}
			if ((temp[count].checked == true) && (temp[count].value == changedValue))
				changedValueWasSelected = true;
		}
	}
	else {
		if ((temp.checked == true) && (temp.value == allSelectedValue))
			allCusineWasSelected  = true;
		if ((temp.checked == true) && (temp.value == changedValue))
			changedValueSelected = true;
	}

	// work out what to do about it
//	alert ('"' + changedValue + '" "' + allSelectedValue + '" "' + allCusineWasSelected + '"');

	if ((changedValue == allSelectedValue) && (allCusineWasSelected)) {
//		alert ('must unset all others');

		if (temp.length) {
			for (count = 0; count < temp.length; count++) {
				if (temp[count].value != allSelectedValue)
					temp[count].checked = false;
			}
		}
		else if (temp.value != allSelectedValue)
			temp.checked = false;
	}
	else if ((changedValue != allSelectedValue) && (changedValueWasSelected)) {
//		alert ('must unset "all cuisines"');

		if (temp.length) {
			for (count = 0; count < temp.length; count++) {
				if (temp[count].value == allSelectedValue)
					temp[count].checked = false;
			}
		}
		else if (temp.value == allSelectedValue)
			temp.checked = false;
	}
	if (allOthersAreUnselected) {
//		alert ('must set "all cuisines"');

		if (temp.length) {
			for (count = 0; count < temp.length; count++) {
				if (temp[count].value == allSelectedValue)
					temp[count].checked = true;
			}
		}
		else if (temp.value == allSelectedValue)
			temp.checked = true;
	}
}




function update_comparison_restaurant (area, restaurantId, set) {
	if (set)
		return add_comparison_restaurant (area, restaurantId);
	return remove_comparison_restaurant (area, restaurantId);
}

function add_comparison_restaurant (area, restaurantId) {
//	set_cookie ('compareIds_' + area, '', 0, '/');	// remove the restaurants altogether
	valueString = get_cookie ('compareIds_' + area);
	if (valueString === null)
		valueString = '';
	values = valueString.split ('_');
	values.remove ('');



	foundRestaurant = false;
	for (count = 0; count < values.length; count++) {
		if (values[count] == restaurantId)
			foundRestaurant = true;
	}

	if (!foundRestaurant) {
		if (values.length >= 5) {
			alert ('You have 5 restaurants in your list already.\nPlease remove some before adding new ones.\n\nYou may do this inside the compare section.');
			return false;
		}

		values[values.length] = restaurantId;
	}

//	alert ('restaurant list after add: ' + values.join ('_'));

	set_cookie ('compareIds_' + area, values.join ('_'), 0, '/');
	return true;
}

function remove_comparison_restaurant (area, restaurantId) {
	valueString = get_cookie ('compareIds_' + area);
	values = valueString.split ('_');
	values.remove ('');

	values.remove (restaurantId);

//	alert ('restaurant list after remove: ' + values.join ('_'));

	set_cookie ('compareIds_' + area, values.join ('_'), 0, '/');
	return true;
}