function checked_data(id) {
	var len = $("#"+id).val();
	var re = /[^0-9]/g;
	end = len.replace(re, "");
	$("#"+id).attr("value", end);
}

function change_but(id, par) {
	$("#"+id).css("backgroundPosition", par);
}

function set_quan(id, type) {
	quan_a = $("#"+id).val();
	if (quan_a == 0 && type == 1) {
	} else {
		quan_a == '' || quan_a == undefined ? quan_a = 0 : '';
		type == 1 ? $("#"+id).attr("value", (parseInt(quan_a)-1)) : $("#"+id).attr("value", (parseInt(quan_a)+1));
	}
}

function set_data_value(id, value) {
	$("#"+id).attr("value", value);
	$("#span_"+id).html(value);
}

function select_vesh(id) {
	if ($("#"+id).attr("checked") == true) {
		$("<span>"+$("#"+id).attr("value")+", </span>").appendTo("#select_vesh");
	} else {
		html_a = $("#select_vesh").html();
		html_a = html_a.replace("<span>"+$("#"+id).attr("value")+", </span>", "");
		html_a = html_a.replace("<SPAN>"+$("#"+id).attr("value")+", </SPAN>", "");
		$("#select_vesh").html(html_a);
	}
}

function display_faq(id) {
	if ($("#text_"+id).css("display") == "none") {
		$("#text_"+id).animate({height: "show"}, 300);
		//$("#text_"+id).css("display", "block");
		$("#"+id).text("Свернуть ответ");
	} else {
		$("#text_"+id).animate({height: "hide"}, 300);
		//$("#text_"+id).css("display", "none");
		$("#"+id).text("Развернуть ответ");
	}
}

function change_color(id, text) {
	$("#"+id).attr("class", "input");
	if ($("#"+id).val() == text) {
		$("#"+id).attr("value", "");
	} else if ($("#"+id).val() == ''){
		$("#"+id).attr("value", text);
	}
}
function select_img(small, big) {
	$('#big_preview').html('<div/><a href="'+big+'" target="_blank"><img src="'+small+'"/></a>');
}

function insert_good(num, dop_param) {
	var sr = new sendForm_symp;
	if (dop_param) {
		sr.sever_file_name = "/ajax_get_good_param.php?size="+$("select[base='arr_basket_size_"+num+"']").val();
	} else {
		sr.sever_file_name = "/ajax_get_good_param.php";
	}
	sr.form_tag = "form_shop_good";
	sr.error_tag = "shop_good_error";
	sr.type_res = "obj";

	sr.add_accept_function_obj = function(xml) {
		var description = $("data", xml).text();
		var xml_obj = $.xslt.textToXML(description);
		var html = $.xslt({xml: xml_obj, xslUrl: '/_symp/_xslt/_spec/insert_good.xsl', xmlCache: false, xslCache: false});
		$("#add_shop_good_frame").append(html);
		$("#shop_good_error").text("");
		var num_in_basket = parseInt($("#num_in_basket").val());
		num_in_basket += 1;
		$("#num_in_basket").val(num_in_basket);
		recalc_total();
	}
	sr.send();
}

function clear_good(num) {
	$("#frame_basket_shop_good_"+num).empty();
	recalc_total();
}


function recalc_total() {
	var good_price = parseInt($("#good_price").text());
	var good_discount = parseInt($("#good_discount").text());

	var total_count = 0;
	$("input[base ^= 'arr_basket_quan_']").each(function() {
		total_count += parseInt($(this).val());
	});
	if (good_discount) {
		price = new String(total_count*good_price - (good_discount/100)*good_price*total_count);
	} else {
		price = new String(total_count*good_price);
	}
	$("#total_price").text(number_separator(price, " "));
}

function Round(n,d) {
	return new Number(n.toFixed(d))
}

function number_separator(number, separator) {
	var tmp_number = new Array();
	for(var i = number.length, j = 0; i > 0; i -= 3)
	{
		var pos = i > 0 ? i - 3 : i;
		tmp_number[j++] = number.substring(i, pos);
	}
	number = tmp_number.reverse().join(separator);
	return number;
}

function show_good_edit_in_basket(config_uniq) {
	$("#type_a_quan_"+config_uniq).css("display", "none");
	$("#type_f_quan_"+config_uniq).css("display", "block");
	$("#type_a_size_"+config_uniq).css("display", "none");
	$("#type_f_size_"+config_uniq).css("display", "block");
	$("#type_a_colors_"+config_uniq).css("display", "none");
	$("#type_f_colors_"+config_uniq).css("display", "block");

	$("#but_edit_"+config_uniq).css("display", "none");
	$("#but_save_"+config_uniq).css("display", "block");
}

function save_good_edit_in_basket(config_uniq) {
	$("#form_edit_"+config_uniq).submit();
}

function change_vkl(div, id) {
	divs = $("DIV", "#"+div);
	for (i=0; i<divs.length; i++) {
		$(divs[i]).attr("class", "");
		$("#"+$(divs[i]).attr("id")+"_text").hide();
	}
	$("#"+id).attr("class", "activ");
	$("#"+id+"_text").show();
}
