$(document).ready(function(e){
	$('a.orderLink').bind('click', function(){
		$('#orderForm').fadeIn();
		return false;
	});

	var loc = location.href;
	if(loc.indexOf('prices')>-1 && loc.indexOf('describe')>-1){
		var mlink = $('div.subsub').children('div#activ').text();
		var href = loc.substring(0, loc.indexOf('?'));
		$('div.subsub').children('div#activ').html('<a href="'+href+'">'+mlink+'</a>');
	}
});





/*
function ajax_send_subscribe()
{


var email = $('#email').val();
var pattern = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i;

if (!pattern.test(email)) 
{
alert('Неверно введен email');
return;
}

$.post(
	 "ajax_send_subscribe.php",
	 { email: $('#email').val() },
	 function(data)
	 {     
	 },
	 "json");
	
}
 */



// cv - current value
function ajax_counter(dec_inc, good_item)
{
try {

		$.post
		(
		"/ajax_counter.php", 
		{dec_inc:dec_inc, good_item:good_item}, 
		function(data)
		{	
					
			$('span.'+'cv'+good_item).html(data.curr_value.toString()).fadeIn();
			$('div.total').html(data.total.toString()).fadeIn();			
			//alert(data.curr_value);
			
			//$('span.'+'cv'+good_item).html('0').fadeIn();
			
		},
		"json"
		);
		
		} catch (e) { console.log(e) }
		

//alert("df");

}


function ajax_send_order(){
    var errors = new Boolean(false);
    if($('#uname').val()==''){
       $('#uname_err').text('*');
       errors = true;
    }else{
       $('#uname_err').text('');
    }
    if($('#uemail').val()==''){
       $('#uemail_err').text('*');
       errors = true;
    }else{
    	$('#uemail_err').text('');
    }
    if($('#uphone').val()==''){
       $('#uphone_err').text('*');
       errors = true;
    }else{
       $('#uphone_err').text('');
    }
	if($('#ushop').children("option:selected").val()==0){
       $('#ushop_err').text('*');
       errors = true;
    }else{
       $('#ushop_err').text('');
    }

    if(errors.valueOf()){
    	return !errors.valueOf();
    }else{

		try {
		$.ajax({
					type: "POST",
					url: "/ajax_send_order.php",
					data: $('form#orderIt').serialize(),
					dataType: 'json',
					error: function(){
                        $('form#orderIt').hide();
                        $('div.success').html('<b>Сервис в данный момент не доступен</b>').fadeIn();
					},
					success: function(info){
						$('form#orderIt').hide();
						if(info.mailsent==1){
							$('div.success').text(info.reason).fadeIn();
							urchinTracker("/ru/prices/order");
						}else{
							$('div.success').text(info.reason).fadeIn();
						}
					}
				});
		} catch (e) { console.log(e) }
			return false;
    }
}

function change_dop_menu(id, div)	{
	var div_menu = $("#" + div),
		div = $("div", div_menu);

	if ($("#" + id).attr("class") != "uk1_activ")
		{
		for (var i=0; i<div.length; i++ )
			{
			$(div[i]).attr("class")=='uk1_activ' || $(div[i]).attr("class")=='uk1' ? $(div[i]).attr("class", "uk1") : '';
			div_id = $(div[i]).attr("id");
			$("#div_" + div_id).css("display", "none");
			$("#" + id).attr("class", "uk1_activ");
			$("#div_" + id).css("display", "block");
			}
		}
	select_button();
}

var id_open = '', flag_click = 1;
function display_dop_win(id)	{
	if ($("#"+id).css("display")=='none')	{
		$("#"+id_open).css("display", "none");
		$("#"+id).css("display", "block");
		flag_click = 2;
		id_open=id;
	} else {
		$("#"+id).css("display", "none");
		id_open='';
		flag_click = 1;
	}
}

function hide_dop_win(id)	{
	flag_click == 1 ? $("#"+id).css("display", "none") : flag_click = 1;
}

function movieItogo()	{
	data = document.getElementsByTagName('body')[0].scrollTop;
	if (data > 390)	{
		$("#smith").css("position", "fixed");
		$("#smith").css("margin", "0 0 0 392px");
	} else	{
		$("#smith").css("position", "absolute");
		$("#smith").css("margin", "390px 0 0 392px");
	}
}

function change_text(id, text)	{
	if ($("#"+id).val() == text) {
		$("#check_"+id).attr("checked", "checked");
		$("#"+id).attr("value", '');
	}
	else if ($("#"+id).val() == '') {
		$("#check_"+id).attr("checked", "");
		$("#"+id).attr("value", text);
	}
}

function change_city() {
	var adres_id = $("#city_combo").val();
	div_menu = $(".city" + adres_id);
	sel = $("#shop");
	if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
		$("#shop").css('width', "auto");
	}
	$("#shop").html('');
	for (var i=0; i<div_menu.length; i++ ) {
		//$("<option></option>").attr("value", $(div_menu[i]).html()).html($(div_menu[i]).html()).appendTo(sel);
		$("<option></option>").attr("value", $(div_menu[i]).attr('id').substring(4)).html($(div_menu[i]).html()).appendTo(sel);
	}
	if (div_menu.length == 0) {
		$("#shop").css('width', "158px");
		$("<option></option>").attr("value", "").html("Выберите магазин").appendTo(sel);
	}
}

function display_promos(id) {
	if ($("#"+id).css("display") == "none") {
		$("#"+id).css("display", "block");
	} else {
		$("#"+id).css("display", "none");
	}
}

function show_form_price(id) {
	$("#error_message_price").html("");
	$("#prod_name").attr("value", "");
	$("#where").attr("value", "");
	$("#how").attr("value", "");
	prod_name = $("#"+id).html();
	$("#prod_name").attr("value", prod_name);
	$("#div_form_price").show();
}

function ajax_send_form_price() {
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_send_form_price.php";
	sr.form_tag = "form_price";
	sr.accept_tag = "form_price";
	sr.error_tag = "error_message_price";
	sr.type_res = "obj";

	//Переопределим стадартную функцию
	sr.add_accept_function_obj = function(xml) {
		$("#error_message_price").html($("glob_message", xml).text());
	}
	sr.send();
}