//	[nds]

function fn_get_items(id, param_id, sel_id)
{
	$('#'+id).attr('disabled', 'disabled');
	var res_ids = new Array();
	var block_ids = new Array();
	var bl_ids = '';
	$("div[id^='find_wheel_alloy']").each(function (i) {
		res_ids[i] = $(this).attr('id');
		block_id = parseInt(res_ids[i].replace('find_wheel_alloy_',''))
		if (!isNaN(block_id)) {
			block_ids[i] = block_id;
		}
	});
	result_ids = res_ids.join(',');
	bl_ids = block_ids.join(',');
	bl_ids = (bl_ids != '') ? ('&block_ids=' + bl_ids) : '';
	if (sel_id == 'carmake_id') {
		$("select[id^='r_n_r_size']").attr('disabled', 'disabled');
		if (param_id != '') {
			jQuery.ajaxRequest(index_script + '?dispatch=filter&carmake_id=' + param_id + bl_ids, {
						result_ids: result_ids,
						caching: true,
						callback: function() {
							$('#'+id).removeAttr('disabled');
						}
			});
		}
	} else {
		if (param_id != '') {
			jQuery.ajaxRequest(index_script + '?dispatch=filter&model_id=' + param_id + bl_ids, {
							result_ids: result_ids,
							caching: true,
							callback: function() {
								$('#'+id).removeAttr('disabled');
							}
			});
		}
	}
	var filter_form = new form_handler($('#'+id).parents('form:first').attr('name'));
	filter_form.fill_requirements();
	filter_form.check_fields();
}
function fn_change_selectbox_name(obj_id, product_id)
{
	if (product_id != 0) {
		$('#tyres_selectbox').attr('name', 'product_data['+product_id+'][product_id]');
		$('#button_cart_'+obj_id).attr('name', 'dispatch[checkout.add]');
		$('.cm-tyre-cur-item').removeClass('cm-tyre-cur-item');
		$('#added_tyres_'+obj_id).text(lang['fitted_with_tyres'].str_replace('[tyre_name]', $('#tyres_selectbox option:selected').text()));
		$('#det_img_mini_'+product_id).addClass('cm-tyre-cur-item');

	} else {
		$('#button_cart_'+obj_id).attr('name', 'dispatch[checkout.add..'+obj_id+']');
		$('#added_tyres_'+obj_id).text(lang['without_tyres']);
		$('.cm-tyre-cur-item').removeClass('cm-tyre-cur-item');
	}
}

//	Use this function for CS-Cart 2.0.9 and more
function fn_race_and_road_check_exceptions(data)
{

	id = data.id;
	if (exclude_from_calculate[id]) {
		return false;
	}

	var modifiers = {};

	var original_price = parseFloat(price[id]); // Original product price
	var sec_original_price = 0; // Original price (secondary currency)
	var product_price = 0; // Product price with discounts and taxes
	var sec_product_price = 0; // Product price with discounts and taxes (secindary currency)
	var modifiers_price = 0; // Product price with discounts and taxes (secindary currency)

	var qty = document.getElementById('qty_count_' + id) ? parseInt(document.getElementById('qty_count_' + id).value) : 1;

	qty = isNaN(qty) ? 1 : qty;

	if (typeof(qty_discounts[id]) != 'undefined') {
		for (q in qty_discounts[id]) {
			if (q <= qty) {
				original_price = qty_discounts[id][q];
			}
		}
	}


	var list_pr = (typeof(list_price[id]) != 'undefined') ? parseFloat(list_price[id]) : 0; // List price

	original_price *= qty;
	list_pr *= qty;

	// Apply option modifiers

	for (i in pr_o[id]) {
		if (!document.getElementById(pr_o[id][i]['id']) || document.getElementById(pr_o[id][i]['id']).disabled == true) {
			continue;
		}
		modifiers[i] = pr_o[id][i]['m'][pr_o[id][i]['selected_value']];
		if (typeof(modifiers[i]) == 'undefined') {
			continue;
		}

		if (modifiers[i].substring(0, 1) == 'A') {
			modifiers_price += parseFloat(jQuery.formatPrice(modifiers[i].substring(1, modifiers[i].length-1), decplaces));
//			original_price += parseFloat(jQuery.formatPrice(modifiers[i].substring(1, modifiers[i].length-1), decplaces));
			list_pr += parseFloat(jQuery.formatPrice(modifiers[i].substring(1, modifiers[i].length-1), decplaces));
		} else if(modifiers[i].substring(0, 1)  == 'P') {
 			modifiers_price += parseFloat(jQuery.formatPrice(modifiers[i].substring(1, modifiers[i].length-1), decplaces));
//			original_price += parseFloat(jQuery.formatPrice(price[id] * parseFloat(modifiers[i].substring(1, modifiers[i].length-1))/100, decplaces));
			list_pr += parseFloat(jQuery.formatPrice(price[id] * parseFloat(modifiers[i].substring(1, modifiers[i].length-1))/100, decplaces));
		}
	}

	if (script_location != 'checkout') {
		original_price += modifiers_price;
	}

	var tyre_id = document.getElementById('tyres_selectbox') ? parseInt(document.getElementById('tyres_selectbox').value) : 0;

	tyre_price = 0;

	if (tyre_products[id]) {
		if (tyre_products[id][tyre_id] && tyre_products[id][tyre_id]['prices']) {
			for (_t in tyre_products[id][tyre_id]['prices']) {
				tyre_price = (_t <= qty) ? parseFloat(tyre_products[id][tyre_id]['prices'][_t]) : tyre_price;
			}
		}
	}

	original_price += (tyre_price * qty);
	list_pr += (tyre_price * qty);



	updated_price[id] = jQuery.formatNum(original_price, decplaces, true);
	sec_original_price = parseFloat(jQuery.formatPrice(original_price / currencies.secondary.coefficient, decplaces));
	sec_list_pr = parseFloat(jQuery.formatPrice(list_pr / currencies.secondary.coefficient, decplaces));

	// If we have discounts, skip list price calculations
	var discount_value = 0; // absolute discount
	var prc_discount_value = 0; // percent discount
	var discounted_price = original_price; // discounted price, equals pure price by default
	var sec_discounted_price = original_price / currencies.secondary.coefficient; // discounted price for secondary currency

	// Discounts
	if (pr_d[id] && (pr_d[id]['A'] || pr_d[id]['P'])) {
		// Discount value (for unit)
		discount_value = parseFloat(jQuery.formatPrice(original_price * pr_d[id]['P']/100 + pr_d[id]['A'], decplaces));
		if (discount_value > original_price) {
			discount_value = original_price;
		}
		// Discount percent value
		prc_discount_value = parseFloat(jQuery.formatPrice((original_price * pr_d[id]['P']/100 + pr_d[id]['A'])/original_price*100, 0));
		if (prc_discount_value > 100) {
			prc_discount_value = 100;
		}

		// Discounted price (unit)
		discounted_price = jQuery.formatPrice(original_price - discount_value);
		// Discounted price (unit) - secondary currency
		sec_discounted_price = jQuery.formatPrice(discounted_price / currencies.secondary.coefficient, decplaces);

	// List price
	} else if (typeof(list_price[id]) != 'undefined') {
		discount_value = parseFloat(jQuery.formatPrice(list_pr - original_price, decplaces));
		prc_discount_value = parseFloat(jQuery.formatPrice((list_pr - original_price)/ list_pr * 100, 0));
	}
	list_pr = list_pr / currencies.primary.coefficient;
	discounted_price = discounted_price / currencies.primary.coefficient;

	qty = document.getElementById('amount_' + id) ? parseInt(document.getElementById('amount_' + id).value) : 1;

	// Discount value (unit) - secondary currency
	sec_discount_value = jQuery.formatPrice(discount_value / currencies.secondary.coefficient, decplaces);
	product_price = original_price - ((pr_d[id] && (pr_d[id]['A'] || pr_d[id]['P'])) ? discount_value : 0); // correct resulting product price
	sec_product_price = sec_original_price - ((pr_d[id] && (pr_d[id]['A'] || pr_d[id]['P'])) ? sec_discount_value : 0); // correct resulting product price
	var tx_price = discounted_price; // base price for taxation with discount (if exist)
	var alt_tx_price = sec_discounted_price; // base price for taxation for secondary currency
	discount_value = discount_value / currencies.primary.coefficient;

	// Taxes
	var tax_subtotal = tax_excluded = 0;
	var sec_tax_subtotal = sec_tax_excluded = 0;

	if (tax_data[id]) {
		// Tax value (unit)
		fn_calculate_tax_rates(id, discounted_price);
		for (_k in tax_data[id]) {
			tax_subtotal += parseFloat(tax_data[id][_k]['tax_subtotal']);
			if (tax_data[id][_k]['price_includes_tax'] != 'Y') {
				tax_excluded += parseFloat(tax_data[id][_k]['tax_subtotal']);
			}
		}

		// Tax value (unit) - secondary currency
		fn_calculate_tax_rates(id, sec_discounted_price);
		for (_k in tax_data[id]) {
			sec_tax_subtotal += parseFloat(tax_data[id][_k]['tax_subtotal']);
			if (tax_data[id][_k]['price_includes_tax'] != 'Y') {
				sec_tax_excluded += parseFloat(tax_data[id][_k]['tax_subtotal']);
			}
		}
	}

	product_price = (cart_prices_w_taxes == true) ? product_price + tax_excluded : product_price;
	product_price = product_price / currencies.primary.coefficient;
	sec_product_price = (cart_prices_w_taxes == true) ? sec_product_price + sec_tax_excluded : sec_product_price;
	var product_subtotal = product_price * qty;
	var sec_product_subtotal = sec_product_price * qty;
	original_price = original_price / currencies.primary.coefficient;

	update_ids[id] = {
		'original_price': {P: original_price, S: sec_original_price}, // original price with modifiers
		'old_price': {P: original_price, S: sec_original_price}, // original price with modifiers
		'discounted_price': {P: discounted_price, S: sec_discounted_price}, // original_price - discount_value
		'list_price' : {P: list_pr, S: sec_list_pr}, // list price for the product
		'tax_value': {P: tax_subtotal, S: sec_tax_subtotal},
		'discount_value': {P: discount_value, S: sec_discount_value},
		'prc_discount_value': {E: prc_discount_value},
		'prc_discount_value_label': {E: prc_discount_value},
		'product_price': {P: product_price, S: sec_product_price}, // original_price - discount_value + tax_value
		'tax_subtotal': {P: tax_subtotal * qty, S: sec_tax_subtotal * qty},
		'discount_subtotal': {P: discount_value * qty, S: sec_discount_value * qty},
		'product_subtotal': {P: product_subtotal, S: sec_product_subtotal},
		'product_subtotal_2': {P: product_subtotal, S: sec_product_subtotal}
	};

	fn_update_product_prices_block(update_ids[id], id);

	// If all product prices eq 0 than show standart price block
	if (!(parseFloat(discounted_price) && parseFloat(original_price) && parseFloat(product_price)) && document.getElementById('line_zero_price_' + id)) {
		document.getElementById('line_zero_price_' + id).style.display = '';
	} else if (document.getElementById('line_zero_price_' + id)) {
		document.getElementById('line_zero_price_' + id).style.display = 'none';
	}

	return true;

}

function fn_open_popup(id, obj_id)
{
	var color_id = $('#selected_color_' + obj_id + ' option:selected').attr('title');
	href = $('#'+id).attr('rel');
//	$('#'+id).attr('href', '');
	href = href + "&color_id=" + color_id;
	window.open(href,'popupwindow','width=850,height=900,toolbar=no,status=no,scrollbars=yes,resizable=no,menubar=no,location=no,direction=no');
}
/*
function fn_race_and_road_check_exceptions(id)
{

//	id = data.id;
	if (exclude_from_calculate[id]) {
		return false;
	}

	var modifiers = {};

	var original_price = parseFloat(price[id]); // Original product price
	var sec_original_price = 0; // Original price (secondary currency)
	var product_price = 0; // Product price with discounts and taxes
	var sec_product_price = 0; // Product price with discounts and taxes (secindary currency)

	var qty = document.getElementById('qty_count_' + id) ? parseInt(document.getElementById('qty_count_' + id).value) : 1;

	var list_pr = (typeof(list_price[id]) != 'undefined') ? parseFloat(list_price[id]) : 0; // List price

	original_price *= qty;
	list_pr *= qty;

	// Apply option modifiers

	for (i in pr_o[id]) {
		if (!document.getElementById(pr_o[id][i]['id']) || document.getElementById(pr_o[id][i]['id']).disabled == true) {
			continue;
		}
		modifiers[i] = pr_o[id][i]['m'][pr_o[id][i]['selected_value']];
		if (typeof(modifiers[i]) == 'undefined') {
			continue;
		}

		if (modifiers[i].substring(0, 1) == 'A') {
			original_price += parseFloat(jQuery.formatPrice(modifiers[i].substring(1, modifiers[i].length-1), decplaces));
			list_pr += parseFloat(jQuery.formatPrice(modifiers[i].substring(1, modifiers[i].length-1), decplaces));
		} else if(modifiers[i].substring(0, 1)  == 'P') {
			original_price += parseFloat(jQuery.formatPrice(price[id] * parseFloat(modifiers[i].substring(1, modifiers[i].length-1))/100, decplaces));
			list_pr += parseFloat(jQuery.formatPrice(price[id] * parseFloat(modifiers[i].substring(1, modifiers[i].length-1))/100, decplaces));
		}
	}


	var tyre_id = document.getElementById('tyre_' + id) ? parseInt(document.getElementById('tyre_' + id).value) : 0;

	tyre_price = 0;

	if (tyre_products[id]) {
		if (tyre_products[id][tyre_id] && tyre_products[id][tyre_id]['prices']) {
			for (_t in tyre_products[id][tyre_id]['prices']) {
				tyre_price = (_t <= qty) ? parseFloat(tyre_products[id][tyre_id]['prices'][_t]) : tyre_price;
			}
		}
	}

	original_price += (tyre_price * qty);
	list_pr += (tyre_price * qty);



	updated_price[id] = jQuery.formatNum(original_price, decplaces, true);
	sec_original_price = parseFloat(jQuery.formatPrice(original_price / currencies.secondary.coefficient, decplaces));
	sec_list_pr = parseFloat(jQuery.formatPrice(list_pr / currencies.secondary.coefficient, decplaces));

	// If we have discounts, skip list price calculations
	var discount_value = 0; // absolute discount
	var prc_discount_value = 0; // percent discount
	var discounted_price = original_price; // discounted price, equals pure price by default
	var sec_discounted_price = original_price / currencies.secondary.coefficient; // discounted price for secondary currency

	// Discounts
	if (pr_d[id] && (pr_d[id]['A'] || pr_d[id]['P'])) {
		// Discount value (for unit)
		discount_value = parseFloat(jQuery.formatPrice(original_price * pr_d[id]['P']/100 + pr_d[id]['A'], decplaces));
		if (discount_value > original_price) {
			discount_value = original_price;
		}
		// Discount percent value
		prc_discount_value = parseFloat(jQuery.formatPrice((original_price * pr_d[id]['P']/100 + pr_d[id]['A'])/original_price*100, 0));
		if (prc_discount_value > 100) {
			prc_discount_value = 100;
		}

		// Discounted price (unit)
		discounted_price = jQuery.formatPrice(original_price - discount_value);
		// Discounted price (unit) - secondary currency
		sec_discounted_price = jQuery.formatPrice(discounted_price / currencies.secondary.coefficient, decplaces);

	// List price
	} else if (typeof(list_price[id]) != 'undefined') {
		discount_value = parseFloat(jQuery.formatPrice(list_pr - original_price, decplaces));
		prc_discount_value = parseFloat(jQuery.formatPrice((list_pr - original_price)/ list_pr * 100, 0));
	}
	list_pr = list_pr / currencies.primary.coefficient;
	discounted_price = discounted_price / currencies.primary.coefficient;

	qty = document.getElementById('amount_' + id) ? parseInt(document.getElementById('amount_' + id).value) : 1;

	// Discount value (unit) - secondary currency
	sec_discount_value = jQuery.formatPrice(discount_value / currencies.secondary.coefficient, decplaces);
	product_price = original_price - ((pr_d[id] && (pr_d[id]['A'] || pr_d[id]['P'])) ? discount_value : 0); // correct resulting product price
	sec_product_price = sec_original_price - ((pr_d[id] && (pr_d[id]['A'] || pr_d[id]['P'])) ? sec_discount_value : 0); // correct resulting product price
	var tx_price = discounted_price; // base price for taxation with discount (if exist)
	var alt_tx_price = sec_discounted_price; // base price for taxation for secondary currency
	discount_value = discount_value / currencies.primary.coefficient;

	// Taxes
	var tax_subtotal = tax_excluded = 0;
	var sec_tax_subtotal = sec_tax_excluded = 0;

	if (tax_data[id]) {
		// Tax value (unit)
		fn_calculate_tax_rates(id, discounted_price);
		for (_k in tax_data[id]) {
			tax_subtotal += parseFloat(tax_data[id][_k]['tax_subtotal']);
			if (tax_data[id][_k]['price_includes_tax'] != 'Y') {
				tax_excluded += parseFloat(tax_data[id][_k]['tax_subtotal']);
			}
		}

		// Tax value (unit) - secondary currency
		fn_calculate_tax_rates(id, sec_discounted_price);
		for (_k in tax_data[id]) {
			sec_tax_subtotal += parseFloat(tax_data[id][_k]['tax_subtotal']);
			if (tax_data[id][_k]['price_includes_tax'] != 'Y') {
				sec_tax_excluded += parseFloat(tax_data[id][_k]['tax_subtotal']);
			}
		}
	}

	product_price = (cart_prices_w_taxes == true) ? product_price + tax_excluded : product_price;
	product_price = product_price / currencies.primary.coefficient;
	sec_product_price = (cart_prices_w_taxes == true) ? sec_product_price + sec_tax_excluded : sec_product_price;
	var product_subtotal = product_price * qty;
	var sec_product_subtotal = sec_product_price * qty;
	original_price = original_price / currencies.primary.coefficient;

	update_ids[id] = {
		'original_price': {P: original_price, S: sec_original_price}, // original price with modifiers
		'old_price': {P: original_price, S: sec_original_price}, // original price with modifiers
		'discounted_price': {P: discounted_price, S: sec_discounted_price}, // original_price - discount_value
		'list_price' : {P: list_pr, S: sec_list_pr}, // list price for the product
		'tax_value': {P: tax_subtotal, S: sec_tax_subtotal},
		'discount_value': {P: discount_value, S: sec_discount_value},
		'prc_discount_value': {E: prc_discount_value},
		'prc_discount_value_label': {E: prc_discount_value},
		'product_price': {P: product_price, S: sec_product_price}, // original_price - discount_value + tax_value
		'tax_subtotal': {P: tax_subtotal * qty, S: sec_tax_subtotal * qty},
		'discount_subtotal': {P: discount_value * qty, S: sec_discount_value * qty},
		'product_subtotal': {P: product_subtotal, S: sec_product_subtotal},
		'product_subtotal_2': {P: product_subtotal, S: sec_product_subtotal}
	};

	fn_update_product_prices_block(update_ids[id], id);

	// If all product prices eq 0 than show standart price block
	if (!(parseFloat(discounted_price) && parseFloat(original_price) && parseFloat(product_price)) && document.getElementById('line_zero_price_' + id)) {
		document.getElementById('line_zero_price_' + id).style.display = '';
	} else if (document.getElementById('line_zero_price_' + id)) {
		document.getElementById('line_zero_price_' + id).style.display = 'none';
	}

	return true;

}
*/
