function togglePrice(searchIn, needToAdd, value, value_no_tax) {
	value = Math.max(0, value);
	value_no_tax = Math.max(0, value_no_tax);
	$("span.js_price, span.js_price_tax", searchIn).each(function(){
		title = $(this).attr("title");
		if (title == null || title == '') return;
		newvalue = parseFloat(title) + (needToAdd ? 1 : -1) * (this.className == 'js_price' ? value_no_tax : value);
		$(this).attr("title", Math.max(0, newvalue));
		$(this).html(currency(newvalue));
	});
}

function toInt(value) {
	value = parseInt(value);
	if (!value) value = 0;
	return value;
}

function toggleReadOnly(id) {
	obj = document.getElementById(id);
	if (!obj) return;
	obj.readOnly = !obj.readOnly;
	obj.style.background = obj.readOnly ? '#EEE' : '#FFF';
}

function validateBundles(bundle_id) {
	if (!window.required_products) return true;
	var bundles = $("*[name^='bundle_id["+bundle_id+"]']").get();
	var unsatisfied = clone(window.required_products);
	for (name in bundles) {
		for (i in unsatisfied) {
			if (!unsatisfied[i]) continue;
			for (k in unsatisfied[i]) {
				if (bundles[name].value == unsatisfied[i][k]) {
					if (bundles[name].type == 'checkbox' && bundles[name].checked) {
						delete unsatisfied[i];
						break;
					}
					if (bundles[name].type == 'select-one') {
						delete unsatisfied[i];
						break;
					}
				}
			}
		}
	}
	var error = '';
	for (i in unsatisfied) {
		error += "\n- " + window.categories[i];
	}
	if (error) {
		alert(window.i18n.errorRequiredCategories + error);
		return false;
	}
	return true;
}