function fedq(type) {
	if (type == 'yes') {
		$('#fedq').text($('#thanktext').text());
		$("#information_y").val("45Swks4");
		ajax_send_fedq();
	} else {
		$('#fedq').css('display', 'none');
		$('#fedq2').css('display', 'block');
	}

}
function store_poll(type) {
	//alert(type);
	if (type == 'yes' || type == 'no') {
		//$('#store_poll_div').text($('#thanktext').text());
		var infval = type == 'yes' ? "45Swks4" : "45Swks6";
		$("#infoSP").val(infval);
		ajax_send_store_poll();
	} else {
		$('#poll_store').css('display', 'none');
		$('#poll_store_idea').css('display', 'table-row-group');
		$('#poll_store_idea div.hide').css('display', 'block');
	}

}
function store_poll_idea_return() {
	$('#poll_store').css('display', 'table-row-group');
	$('#poll_store_idea').css('display', 'none');
}

$(document).ready(function(){
	$().keypress(function (e) {
		if ((e.which == 13 || e.which == 10) && e.ctrlKey == true) {
			show_send_spell_window(get_selected_text());
		}
	});
});
function get_selected_text() {
    var selText = "";
    if (document.getSelection)  { // Mozilla
        selText = document.getSelection();
    } else if (document.selection) { // IE
        selText = document.selection.createRange().text;
    } else if (window.getSelection){ // Safari
        selText = window.getSelection();
    }
    if(selText) {
       return selText;
    }
}
//send_spell_window
function show_send_spell_window(spell_text) {
	$("#send_spell_window").css("display", "block");
	$("#spell_text").text(spell_text);
	$("#loc_href").val(location.href);
	$("#spell_information").val(spell_text);
	$("#a_information").val("");
}
function hide_send_spell_window() {
	$("#send_spell_window").css("display", "none");
	$("#frame_send_spell_close").css("display", "none");
	$("#frame_send_spell").css("display", "block");
	$("#result_send_spell").text("");
	$("#loc_href").val("");
	$("#spell_information").val("");
	$("#spell_text").text("");
}

function change_model(group, id) {
	$("td[id ^= 'show_check_"+group+"']").css("display", "none");
	$("td[id ^= 'show_price_"+group+"']").css("display", "block");
	$("#show_check_"+group+"_"+id).css("display", "block");
	$("#show_price_"+group+"_"+id).css("display", "none");
	var sel_price = parseInt($("#price_"+group+"_"+id).text());
	$("label[id ^= 'price_"+group+"']").each(function() {
		str_delta = new String(Math.abs(parseInt($(this).text())-sel_price));
		if ((parseInt($(this).text())-sel_price) > 0) {
			str_delta = "+"+number_separator(str_delta, " ");
		} else {
			str_delta = "-"+number_separator(str_delta, " ");
		}
		$("#show_"+$(this).attr("id")).text(str_delta);
	});
	recalc_total();
}

function change_service(group, id) {
	if ($("#inp_"+group+"_"+id).attr("checked")) {
		$("#show_check_"+group+"_"+id).css("display", "block");
		$("#show_price_"+group+"_"+id).css("display", "none");
	} else {
		$("#show_check_"+group+"_"+id).css("display", "none");
		$("#show_price_"+group+"_"+id).css("display", "block");
	}
	recalc_total();
}

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 recalc_total() {
	var sum_a_price = 0;
	$("input[id ^= 'inp_a'][checked='1']").each(function() {
		sum_a_price += parseInt($("#price_"+$(this).attr("base")).text());
	});
	var str_sum_a_price = new String(sum_a_price);
	$("#total_accessories_price").text(number_separator(str_sum_a_price, " "));

	var sum_p_price = 0;
	$("input[id ^= 'inp_p'][checked='1']").each(function() {
		sum_p_price += parseInt($("#price_"+$(this).attr("base")).text());
	});
	var str_sum_p_price = new String(sum_p_price);
	if (sum_p_price > 0) {
		$("#total_perifiriya_price").text(number_separator(str_sum_p_price, " "));
		$("#total_perifiriya_price_valute").text(lang_tenge+".");
	} else {
		$("#total_perifiriya_price").html('<a href="javascript:change_dop_menu(\'data_two\', \'submenu_comps\');">'+lang_select+'</a>');
		$("#total_perifiriya_price_valute").text("");
	}

	var sum_s_price = 0;
	$("input[id ^= 'inp_s'][checked='1']").each(function() {
		sum_s_price += parseInt($("#price_"+$(this).attr("base")).text());
	});
	var str_sum_s_price = new String(sum_s_price);
	if (sum_s_price > 0) {
		$("#total_service_price").text(number_separator(str_sum_s_price, " "));
		$("#total_service_price_valute").text(lang_tenge+".");
	} else {
		$("#total_service_price").html('<a href="javascript:change_dop_menu(\'data_three\', \'submenu_comps\');">'+lang_select+'</a>');
		$("#total_service_price_valute").text("");
	}



	var str_sum_price = new String(sum_a_price+sum_p_price+sum_s_price);
	$("#total_price").text(number_separator(str_sum_price, " ")+" тнг");

}

function select_button() {
	sel = $("#submenu_comps div[class = 'uk1_activ']").attr("id");
	switch (sel) {
		case "data_one":
			$("#but_next").attr("src", "/images/but_res.png");
		    break;
		case "data_two":
			$("#but_next").attr("src", "/images/but_res.png");
		    break;
		case "data_three":
			$("#but_next").attr("src", "/images/but_res.png");
		    break;
	}
}

function next_dop_menu() {
	//sel = $("#submenu_comps div[class = 'uk1_activ']").attr("id");
	sel = 'data_three';
	switch (sel) {
		case "data_one":
	     	change_dop_menu('data_two', 'submenu_comps');
		    break;
		case "data_two":
	     	change_dop_menu('data_three', 'submenu_comps');
		    break;
		case "data_three":
	     	$("#form_models").submit();
		    break;
	}
}

function change_quan() {
	var total_price = 0;
	var total_count = 0;
	$("label[id ^= 'price_']").each(function() {
		p = parseInt($("#quan_"+$(this).attr("base")).val());
		$("#quan_two_"+$(this).attr("base")).text(p);
		total_price += parseInt($(this).text())*p;
		total_count += p;
	});
	str_total_price = new String(parseInt(total_price));
	$("#total_price").text(number_separator(str_total_price, " "));
	$("#total_two_price").text(number_separator(str_total_price, " "));
	$("#total_two_count").text(total_count);
}

function show_pay() {
	$("#div_korz").css("display", "none");
	$("#pay_left").css("display", "block");
	$("#order_itogo").css("display", "block");
}
function show_basket() {
	$("#div_korz").css("display", "block");
	$("#pay_left").css("display", "none");
	$("#order_itogo").css("display", "none");
}

function str_up(id) {
	$("#"+id).val((parseInt($("#"+id).val())+1));
}

function str_down(id) {
	var str = parseInt($("#"+id).val());
	str > 1 ? $("#"+id).val((parseInt($("#"+id).val())-1)) : '';
}

