function hidePopup(popup){
    $(popup).css('display','none');
    $(document.getElementById('black-sprite')).css('display','none');
    parent.history.back();
    $(document).unbind('keydown');
}

function showPopup(popup){
    $(popup).fadeIn();
	
    centerizePopup($(popup));
    $(document.getElementById('black-sprite')).css('display','block');
}

function hidePopup(popup){
    $(popup).css('display','none');
    $(document.getElementById('black-sprite')).css('display','none');
}


function centerizePopup(item){
    item.css('margin-left',(-item.outerWidth()/2));
    if($(window).height() > item.outerHeight()){
        item.css('margin-top',-item.outerHeight()/2);
        item.css('top','50%');
        item.css('position','fixed');
    } else {
        item.css('margin-top',0);
        item.css('top',0);
        item.css('position','absolute');
        $(document).scrollTop(0);
    }
}
$(document).ready(function() {
	
	var timer = 1;
	var tet;
	var spect;
	var val;
	// всплывающее окно, напомнить о спекстакле
	$("a.dot_bot").click(function() {
 		$(".step1").show();
		$(".step2").hide();
        showPopup($("#popup1"));
			
	});
	
	$(".close, .close2").click(function () {
		$(".popup").hide();
		$("#black-sprite").hide();
		$(".step1").fadeIn(100);
		$(".step2").fadeOut(100);
	}); 
	$("#black-sprite").click(function () {
		$(".popup").hide();
		$("#black-sprite").hide();
	}); 

		$("input[name='f_spect']").val($(".mem_name").text());
		$("input[name='f_teatr']").val($(".mem_teatr").text());
	if($('.memberTime').length > 0){
		$("a.memberTime:eq(0)").addClass('mActive');
		var data = $(".mActive").children("strong").text();
		var date = $(".mActive").children("span").text();
		$("input[name='f_date']").val(data+" "+date);
		$("a.memberTime").click(function(){
			$("a.memberTime").removeClass("mActive");
			$(this).addClass("mActive");
			var data = $(this).children("strong").text();
			var date = $(this).children("span").text();
			$("input[name='f_date']").val(data+" "+date);
		});
	}else{
		$("input[name='f_date']").val($(".nodate").text());
	}
	// проверка полей
	$(".mName").keyup(function(){
		if($(this).val().length > 1)
			$(this).next().fadeOut(300);
	});
	$(".sms").keyup(function(){
		if($(this).val().length > 1)
			$(".sms").parent().parent().find(".error").fadeOut(300);
	});
	// отправка данных
	$(".mSend").click(function(){
		if( $("input.sms").val() == 'например +79261112233'){
			$("input.sms").val("");
		}
	    var error = 0;
		$error = 2;
		if($(".sms").val().length < 2){
			$(".sms").parent().parent().find(".error").fadeIn(300);
			$error = 1;
		}
		if($(".mName").val().length < 2){
			$(".mName").next().fadeIn(300);
			$error = 1;
		}
		if($error == 2){
			$("#mem_cont input").hide();
			$("#mem_cont p").html("<img src='/images_bileti-v-teatr/ajax-loader.gif' alt='' \>");
			$.post("/netcat/add.php", $("#membForm").serialize(),
				function(data){
					if (data.result == "ok"){
						$(".step1").hide();
						$(".step2").fadeIn(10);
						$("#mem_cont p").html("");
						$("#mem_cont input").show();
					}
				}, "json"
			);
		}else{
			if( $("input.sms").val() == ""){
				$("input.sms").val("например +79261112233").css('color','#aaa');
			}
		}
	});
	
	//переход к открытой форме заказа билета
	if(location.hash){
		if (location.hash == "#order_form"){
			$("li.t3, li.t1").removeClass("tab-current");
			$("li.t2").addClass("tab-current");
			$("div.t3").hide();
			$("div.t1").hide();
			$("div.t2").show();
		};
	}
    $("a.buy_now").click(function () {
		var a_rel = $(this).attr("rel");
		$("select[name='f_date'] option").each(function(){
			if($(this).attr("rel") == a_rel){
				$(this).attr('selected','selected');
			}
		});
		var a = $(this);
		$('#dataMest').next().show();
		$.get(location.href,{Date:a.attr('name'), template:123},function(data){
			if(data){
				data = data.replace(/[\s\S]*? id='mestaBiletov'>/, "").replace(/<\/table><!--mestaBiletov-->[\s\S]*/, "");
				$('#mestaBiletov').html(data);
				$('#dataMest').next().hide();
			}
		})

		$("li.t3, li.t1").removeClass("tab-current");
		$("li.t2").addClass("tab-current");
		$("div.t3").hide();
		$("div.t1").hide();
		$("div.t2").show();
    });
	
// показать ещё	
	$("a.before_get").click(function(){
		var $this = $(this);
		$("span.stope").css('display','block');
		$this.hide();
		var cur_pos = $("#tip .for_num").length;
		if($("input.nextLink:last").val().length < 1){
			return false;
		}else{
			var curPos = $("input.nextLink:last").attr("curPos");
			var month = $("input.nextLink:last").attr("month");
			if($(".actual").length > 0){
				var month2 = $(".actual").attr("rel"); 
			}
			if($("input.spectinp").attr("name") == "ok"){
				var spect = $("input.spectinp").val();
			}else{
				var spect = "";
			}
			if($("input.tetinp").attr("name") == "ok"){
				var tet = $("input.tetinp").val();
			}else{
				var tet = "";
			}
			if($("input.act_search").length > 0){
				var act_search = $("input.act_search").val();
			}else{
				var act_search = "";
			}
			//if($("input.spectinp").val().length > 0) var spect = $("input.spectinp").val();
			$.get(location.href ,{isNaked:1,json:1, spect:spect, month2:month2, curPos:curPos, month:month, tet:tet, act_search:act_search} , function(data) {
				if(data){
					data = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
					$('#tip').append(data);
					if($("input.nextLink").length > 1){
						if($("input.nextLink:last").val().length < 1){
							$("span.stope").hide();							
						}else{
							$("span.stope").hide();
							$this.show();
						}
					}
				}
			});
		}
	}); 
	
	

	// Фильтр репертуаров
	if($(".inpFil").length > 0){
	
		if($("input.spectinp").val() != "Начните вводить название спектакля"){
			$("input.spectinp").css('color','#555');
		}else{
			$("input.spectinp").css('color','#aaa');
		}
		$("input.spectinp").focus(function(){
			if($(this).val() == "Начните вводить название спектакля"){
				$(this).val("");
				$(this).css('color','#555');
			}
		});
		$("input.spectinp").blur(function(){
			if($(this).val() == ""){
				$(this).val("Начните вводить название спектакля");
				$(this).css('color','#aaa');
			}else{
				$(this).css('color','#555');
			}
		});
		$("input.spectinp").keyup(function(){
			if($(this).val().length > 0){
				$(this).attr('name','ok');
			}else{
				$(this).attr('name','no');
			
			}
		});
		
		if($("input.tetinp").val() != "Начните вводить название театра"){
			$("input.tetinp").css('color','#555');
		}else{
			$("input.tetinp").css('color','#aaa');
		}
		$("input.tetinp").focus(function(){
			if($(this).val() == "Начните вводить название театра"){
				$(this).val("");
				$(this).css('color','#555');
		}
		});
		$("input.tetinp").blur(function(){
			if($(this).val() == ""){
				$(this).val("Начните вводить название театра");
			$(this).css('color','#aaa');
		}else{
			$(this).css('color','#555');
		}
		});
		$("input.tetinp").keyup(function(){
			if($(this).val().length > 0){
				$(this).attr('name','ok');
			}else{
				$(this).attr('name','no');
			
			}
		});
	}
	$(".this_m").click(function(){
		if($(this).hasClass("actual")){
			return false;
		}
		if($("input.tetinp").attr("name") == "ok"){
			var tet = $("input.tetinp").val();
		}else{
			var tet = "";
		}
		if($("input.spectinp").attr("name") == "ok"){
			var spect = $("input.spectinp").val();
		}else{
			var spect = "";
		}
		var month2 = $(this).attr("rel");
		$("#how_num b").html("<img src='/images_bileti-v-teatr/ajax-loader.gif' alt='' \>");
		$.get(location.href,{isNaked:1, month2:month2, json:1, spect:spect, tet:tet},function(data) {
			if(data){
				num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
				num_is = num.replace(/[\s\S]*? style='color:red;'>/, "").replace(/<\/b>[\s\S]*/, "");
				if(num_is == 0){
					$.get(location.href,{isNaked:1, month2:0, json:1, spect:spect, tet:tet, no_row:1},function(data) {
						if(data){
							num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
							data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
							$('#tip').html(data2);
							$('#how_num').html(num);
							if($("input.nextLink").length > 1){
								if($("input.nextLink:last").val().length < 1){
									$("span.stope").hide();							
									$(".before_get").hide();							
								}else{
									$(".before_get").show();							
									$("span.stope").hide();							
								}	
							}else{
									$(".before_get").hide();							
									$("span.stope").hide();							
							}	
						}
					});
				}else{
					data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
						$('#tip').html(data2);
						$('#how_num').html(num);
					if($("input.nextLink").length > 1){
						if($("input.nextLink:last").val().length < 1){
							$("span.stope").hide();							
							$(".before_get").hide();							
						}else{
							$(".before_get").show();							
							$("span.stope").hide();							
						}	
					}else{
							$(".before_get").hide();							
							$("span.stope").hide();							
					}	
				}
			}
		});		
	});
	$(".allm").click(function(){
		if($(this).hasClass("actual")){
			return false;
		}
		if($("input.tetinp").attr("name") == "ok"){
			var tet = $("input.tetinp").val();
		}else{
			var tet = "";
		}
		if($("input.spectinp").attr("name") == "ok"){
			var spect = $("input.spectinp").val();
		}else{
			var spect = "";
		}
		var month2 = $(this).attr("rel");
		$("#how_num b").html("<img src='/images_bileti-v-teatr/ajax-loader.gif' alt='' \>");
		$.get(location.href,{isNaked:1, month2:month2, json:1, spect:spect, tet:tet},function(data) {
			if(data){
				num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
				num_is = num.replace(/[\s\S]*? style='color:red;'>/, "").replace(/<\/b>[\s\S]*/, "");
				if(num_is == 0){
					$.get(location.href,{isNaked:1, month2:0, json:1, spect:spect, tet:tet, no_row:1},function(data) {
						if(data){
							num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
							data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
							$('#tip').html(data2);
							$('#how_num').html(num);
							if($("input.nextLink").length > 1){
								if($("input.nextLink:last").val().length < 1){
									$("span.stope").hide();							
									$(".before_get").hide();							
								}else{
									$(".before_get").show();							
									$("span.stope").hide();							
								}	
							}else{
									$(".before_get").hide();							
									$("span.stope").hide();							
							}	
						}
					});
				}else{
					data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
						$('#tip').html(data2);
						$('#how_num').html(num);
					if($("input.nextLink").length > 1){
						if($("input.nextLink:last").val().length < 1){
							$("span.stope").hide();							
							$(".before_get").hide();							
						}else{
							$(".before_get").show();							
							$("span.stope").hide();							
						}	
					}else{
							$(".before_get").hide();							
							$("span.stope").hide();							
					}	
				}
			}
		});		
	});
	$("input.spectinp, input.tetinp").keyup(function(){
		var now = $(this).val();
		var $this = $(this);
		if(timer){
			clearInterval(timer);
			timer = setTimeout(function(){
				if(now != val){
					send_get();
					val = $this.val();
				}
			}, 750);
		}
	});
	
	function send_get(){
		var month2 = $(".actual").attr("rel"); 
		if($("input.tetinp").attr("name") == "ok"){
			tet = $("input.tetinp").val();
		}else{
			tet = "";
		}
		if($("input.spectinp").attr("name") == "ok"){
			spect = $("input.spectinp").val();
		}else{
			spect = "";
		}
		$("#how_num b").html("<img src='/images_bileti-v-teatr/ajax-loader.gif' alt='' \>");
		$.get(location.href,{isNaked:1, month2:month2, json:1, spect:spect, tet:tet},function(data) {
			if(data){
				num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
				num_is = num.replace(/[\s\S]*? style='color:red;'>/, "").replace(/<\/b>[\s\S]*/, "");
				if(num_is == 0){
					$.get(location.href,{isNaked:1, month2:0, json:1, spect:spect, tet:tet, no_row:1},function(data) {
						if(data){
							num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
							data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
							$('#tip').html(data2);
							$('#how_num').html(num);
							if($("input.nextLink").length > 1){
								if($("input.nextLink:last").val().length < 1){
									$("span.stope").hide();							
									$(".before_get").hide();							
								}else{
									$(".before_get").show();							
									$("span.stope").hide();							
								}	
							}else{
									$(".before_get").hide();							
									$("span.stope").hide();							
							}	
						}
					});
				}else{
					data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
						$('#tip').html(data2);
						$('#how_num').html(num);
					if($("input.nextLink").length > 1){
						if($("input.nextLink:last").val().length < 1){
							$("span.stope").hide();							
							$(".before_get").hide();							
						}else{
							$(".before_get").show();							
							$("span.stope").hide();							
						}	
					}else{
							$(".before_get").hide();							
							$("span.stope").hide();							
					}	
				}
			}
		});	
	}
	if($(".filter span").length > 0){
		$(".filter span").click(function(){
			$(".filter span").removeClass("actual");
			$(this).addClass("actual");
		});
	}
	// фильтр актёров
	if($(".inpfil").length>0){
		$("input.act_search").keyup(function(){
			var now = $(this).val();
			var $this = $(this);
			if(timer){
				clearInterval(timer);
				timer = setTimeout(function(){
					if(now != val){
						actor_get();
						val = $this.val();
					}
				}, 750);
			}
		});
	}
	
	function actor_get(){
		var act_search = $("input.act_search").val()
		$("#how_num b").html("<img src='/images_bileti-v-teatr/ajax-loader.gif' alt='' \>");
		$.get(location.href,{isNaked:1, act_search:act_search},function(data) {
			if(data){
				data2 = data.replace(/[\s\S]*? id='tip'>/, "").replace(/<\/div><!-- \.tip -->[\s\S]*/, "");
				num = data.replace(/[\s\S]*? id='how_num'>/, "").replace(/<\/div>[\s\S]*/, "");
					$('#tip').html(data2);
					$('#how_num').html(num);
				if($("input.nextLink").length > 1){
					if($("input.nextLink:last").val().length < 1){
						$("span.stope").hide();							
						$(".before_get").hide();							
					}else{
						$(".before_get").show();							
						$("span.stope").hide();							
					}	
				}else{
						$(".before_get").hide();							
						$("span.stope").hide();							
				}	
			}
		});	
	}
	// поиск очищаем поле при клике
	if($("input.search_inp").val() != "Введите название спектакля"){
		$("input.search_inp").css('color','#555');
	}else{
		$("input.search_inp").css('color','#aaa');
	}
	
	$("input.search_inp").focus(function(){
		if($(this).val() == "Введите название спектакля"){
			$(this).val("");
			$(this).css('color','#444');
		}
	});
	$("input.search_inp").blur(function(){
		if($(this).val() == ""){
			$(this).css('color','#c4c4c4');
			$(this).val("Введите название спектакля");
		}
	});
	
	$(".submit_search").click(function(){
		if($(this).parent().find("input.search_inp").val() == "Введите название спектакля"){
			return false;
		}
	});
	
	$("#change").click(function(){
		var kod = $("input#cap_inp").val();
		$("#change").html("<img src='/images_bileti-v-teatr/ajax-loader.gif' alt='' \>");
		$.post(location.href,{nc_captcha_code:kod, isNaked:1},function(data) {
			if(data){
				data = data.replace(/[\s\S]*? id='cap'>/, "").replace(/<\/div>[\s\S]*/, "");
				$('#cap').html(data);
				$("#change").html('Обновить');
			}
		});	
	});
	
	$("#button").click(function(){
		var o = $(this);
		var check = 0;
			o.closest(".adminForm").find('.valid').each(function(index,value){
				if(value != undefined){
					if ($(value).attr('value') != ""){
						$(this).css('border','');
					} else {
						$(this).css('border','1px solid red');
						check = check+1;
					}
				}
			});
		if(check == 0){
			$.post("/netcat/add.php", o.closest(".adminForm").serialize(),
			//обработка рез-та
				function(data){
					if (data == "no"){
						$(".cap_inp").css('border','1px solid red').val("");
						$.post(location.href,{nc_captcha_code:$("input#cap_inp").val(), isNaked:1},function(data) {
							if(data){
								data = data.replace(/[\s\S]*? id='cap'>/, "").replace(/<\/div>[\s\S]*/, "");
								$('#cap').html(data);
								$("#change").html('Обновить');
							}
						});	
						return false
					}
					$("div.t2").html(data);
					yaCounter1141752.reachGoal('ORDERACCEPTED');

				}
			);	
		}
	});
	
	$(".a_margin a").click(function(){
		$(".a_margin a").removeClass("vip");
		$(this).addClass("vip");
		$("input#place").val($(this).text());
	});
	$(".marginBiletov a").click(function(){
		$(".marginBiletov a").removeClass("vip");
		$(this).addClass("vip");
		$("input#dostavkaBiletov").val($(this).text());
		if($(this).hasClass('clearNextTextarea')){
			$(this).closest('tr').next().next().hide();
			$(this).closest('tr').next().show();
		} else {
			$(this).closest('tr').next().next().show();
			$(this).closest('tr').next().hide();
		}
	});
	$(".sortirovka a").click(function(){
		if($(this).hasClass('vip')){
			return false
		} else {
			$(".sortirovka a").removeClass("vip");
			var $this = $(this);
			$this.addClass("vip");
			
			
			var a = $('#dataMest option:selected').val();
			var rev='';
			var b = a.slice(0,1);
			if(b==" "){
				rev = a.slice(1);
			} else {
				rev = a;
			}
			 $this.parent().find('img').show();
			$.get(location.href,{Date:rev, Sorting:$this.attr('rel'), template:123},function(data){
				if(data){
					data = data.replace(/[\s\S]*? id='mestaBiletov'>/, "").replace(/<\/table><!--mestaBiletov-->[\s\S]*/, "");
					$('#mestaBiletov').html(data);
					$this.parent().find('img').hide();
				}
			});
		}
	});
	
		$("input.sms").blur(function(){
			if($(this).val() == ""){
				$(this).val("например +79261112233").css('color','#aaa');
			}
		});
		$("input.sms").focus(function(){
			if($(this).val() == "например +79261112233"){
			$(this).val("").css('color','#555');
			}
		});
		if($("input.sms").val() != "например +79261112233"){
			$("input.sms").css('color','#555');
		}else{
			$("input.sms").css('color','#aaa');
		}
		
		$('#forMetrika').click(function(){
			$.get("/",{metrika:1},function(data){
				if(data){
					$('#forMetrika').fadeOut();
					yaCounter1141752.reachGoal('TARGETCALL');
					return true;
				}
			});
		});
	
	
	$('select#dataMest').change(function(){
		var a = $(this);
		var b = a.val().slice(0,1);
		if(b==" "){
			a = a.val().slice(1);
		}
		a.next().show();
		$.get(location.href,{Date:a.val(), template:123, Sorting:1},function(data){
			if(data){
				data = data.replace(/[\s\S]*? id='mestaBiletov'>/, "").replace(/<\/table><!--mestaBiletov-->[\s\S]*/, "");
				$('#mestaBiletov').html(data);
				a.next().hide();
			}
		})
	});
		$("#buttonBiletov").click(function(){
		var o = $(this);
		var check = 0;
			o.closest(".adminForm").find('.valid').each(function(index,value){
				if(value != undefined){
					if ($(value).attr('value') != ""){
						$(this).css('border','');
					} else {
						$(this).css('border','1px solid red');
						check = check+1;
					}
				}
			});
		if(check == 0){
		
		
			var body = '';
			$('#mestaBiletov a.place_active').each(function(){
				a = $(this);
				body = body+" "+a.attr('name')+", "+a.attr('rev')+", место "+a.text()+" ("+a.attr('rel')+")\n";
			})
			if(body){
				body = body+"Итого: выбрано билетов "+$('#kolichestvoBiletov').text()+" на сумму "+$('#summaBiletov').text()+" руб.";
			}
			$('#infoBiletov').text(body);
			
			if($('#mestaBiletov td').length>0){
				$('#place').val("");
			} else {
				$('#place').val($('.t2 .a_margin .vip').text());
			}
	// руслан 18.01.2012
			$('#dataMest option:selected').val($('#dataMest option:selected').text());
			o.hide();
			o.next().show();
			$.post("/netcat/add.php", o.closest(".adminForm").serialize(),
			//обработка рез-та
				function(data){
					if (data == "no"){
						$(".cap_inp").css('border','1px solid red').val("");
						$.post(location.href,{nc_captcha_code:$("input#cap_inp").val(), isNaked:1},function(data) {
							if(data){
								data = data.replace(/[\s\S]*? id='cap'>/, "").replace(/<\/div>[\s\S]*/, "");
								$('#cap').html(data);
								$("#change").html('Обновить');
							}
						});	
						return false
					}
					$('#help_no_ticket').remove();
					$('#help_mess').remove();
					$("div.t2").html(data);
					yaCounter1141752.reachGoal('ORDERACCEPTED');
					o.next().hide();
					o.show();
				}
			);	
		}
	});
	$('ul.tabs.tabs1 li').click(function(){
		var thisClass = this.className.slice(0,2);
		$('div.t1').hide();
		$('div.t2').hide();
		$('div.t3').hide();
		$('div.t4').hide();
		$('div.' + thisClass).show();
		$('ul.tabs.tabs1 li').removeClass('tab-current');
		$(this).addClass('tab-current');
	});
	
	//CRM-------------------------------------------------------------------------
	// открываем/закрываем подробно заказы
	$('#newOrders .podrobno').closest('tr').prev().click(function(){
		$(this).next().find('.podrobno').slideToggle();
		$(this).next().toggleClass('now_open');
	});
	
	$('.hideOrderForm').click(function(){
		$(this).closest('.podrobno').slideUp();
	});
	
// --- Автозаполнение ---

	function liFormat (row, i, num) {
		var result = row[1];
		return result;
	}
	function selectItem(li) {
		if( li == null ) var sValue = '';
		if( !!li.extra ) var sValue = li.extra[1];
		else var sValue = li.selectValue;
	}
	$(".N_Spektakl_ID").autocomplete("/netcat/modules/default/autocomplete.php", {
		delay:400,
		minChars:1,
		matchSubset:1,
		autoFill:false,
		matchContains:1,
		cacheLength:10,
		selectFirst:true,
		formatItem:liFormat,
		maxItemsToShow:10,
		onItemSelect:selectItem
	}); 
// --- Автозаполнение конец ---

	$('.N_Change_Spektakl').click(function(){
		$(this).hide();
		$(this).prev().hide();
		$(this).next().show().focus().val(''); 
		
	});
	
	
// ОФОРМЛЕНИЕ КОНТАКТА

	$('.N_Contact_Info_Change_Link').click(function(){
		$(this).prev().hide();
		$(this).next().slideDown('fast');
		$(this).hide();
	});

	$('.N_Contact_Info_Save').click(function(){
		$(this).closest('.N_Contact_Info_Change').slideUp('fast');
		$(this).closest('.N_Contact_Info_Change').prev().show();
		$(this).closest('.N_Contact_Info_Change').prev().prev().show();			
	});

// Присваиваем Статусы	
	$('.N_Oformlenie_zakaza').click(function(){
		var N_Row = $(this).closest('.N_Contact_Table').attr('id');
		if($(this).hasClass('act')){
			return false;
		}
		$.get('/netcat/modules/default/autocomplete.php',{Status_Zayavki:6,row_id:N_Row});
		$(this).closest('table').next().slideDown();
		$(this).addClass('act');
	});
	
	$('.N_Ojidanie_zakaza').click(function(){
		var N_Row = $(this).closest('.N_Contact_Table').attr('id');
		if($(this).hasClass('act')){
			return false;
		}
		$.get('/netcat/modules/default/autocomplete.php',{Status_Zayavki:7,row_id:N_Row});
		$(this).addClass('act');
	});
	
	$('.N_Perezvonit').click(function(){
		var N_Row = $(this).closest('.N_Contact_Table').attr('id');
		if($(this).hasClass('act')){
			return false;
		}
		$.get('/netcat/modules/default/autocomplete.php',{Status_Zayavki:8,row_id:N_Row});
		$(this).addClass('act');
	});
	
	$('.N_Net_Biletov').click(function(){
		var N_Row = $(this).closest('.N_Contact_Table').attr('id');
		if($(this).hasClass('act')){
			return false;
		}
		$.get('/netcat/modules/default/autocomplete.php',{Status_Zayavki:9,row_id:N_Row});
		$(this).addClass('act');
	});
	
	$('.N_Dozvonilsya_Ne_Zakazali').click(function(){
		var N_Row = $(this).closest('.N_Contact_Table').attr('id');
		if($(this).hasClass('act')){
			return false;
		}
		$.get('/netcat/modules/default/autocomplete.php',{Status_Zayavki:10,row_id:N_Row});
		$(this).addClass('act');
	});
	
	
});


// изменяем дату 
 function N_Change_Date(o){
	var Date = o.find('option:selected').val();
	var N_Row = o.closest('.N_Contact_Table').attr('id');
	$.get('/netcat/modules/default/autocomplete.php',{Date:Date,row_id:N_Row});
 }


// изменяем Выбранные метста
 function Places(o){
	var N_Row = o.closest('table').prev('.N_Contact_Table').attr('id');
	var Places = o.val();
	$.get('/netcat/modules/default/autocomplete.php',{Places:Places,row_id:N_Row});
 }

 // изменяем Примечание к сделке
 function change_Prim_k_Sdelke(o){
	var Prim_k_Sdelke = o.val();
	var N_Row = o.closest('.N_Contact_Table').attr('id');
	$.get('/netcat/modules/default/autocomplete.php',{Prim_k_Sdelke:Prim_k_Sdelke,row_id:N_Row});
 }

// изменяем способ доставки
function Take_Away(o,c){
	var N_Row = o.closest('table').prev('.N_Contact_Table').attr('id');
	$.get('/netcat/modules/default/autocomplete.php',{Take_Away:c,row_id:N_Row});
}
 

// изменяем суммы доставки
function Cost_of_Delivery(o){
	var N_Row = o.closest('table').prev('.N_Contact_Table').attr('id');
	var Cost_of_Delivery = o.val();
	$.get('/netcat/modules/default/autocomplete.php',{Cost_of_Delivery:Cost_of_Delivery, row_id:N_Row},function(data){
		if(data){
			o.closest('table').find('.N_Total_Price').text(data);
		}
	});
}
 

// изменяем дату доставки
function Date_Sale(o){
	var N_Row = o.closest('table').prev('.N_Contact_Table').attr('id');
	var Date_Sale = o.val();
	$.get('/netcat/modules/default/autocomplete.php',{Date_Sale:Date_Sale,row_id:N_Row});
}
 
 
// изменяем время доставки
function Time_Sale(o){
	var N_Row = o.closest('table').prev('.N_Contact_Table').attr('id');
	var Time_Sale = o.val();
	$.get('/netcat/modules/default/autocomplete.php',{Time_Sale:Time_Sale,row_id:N_Row});
}
 
 
 
// изменяем Стоимость/Общая билетов
function Ticket_Price(o){
	var N_Row = o.closest('table').prev('.N_Contact_Table').attr('id');
	var Ticket_Price = o.val();
	var Cost_of_Delivery2 = o.closest('table').find('.N_Cost_of_Delivery').val();
	$.get('/netcat/modules/default/autocomplete.php',{Ticket_Price:Ticket_Price, row_id:N_Row, Cost_of_Delivery2:Cost_of_Delivery2},function(data){
		if(data.Cnt){
			o.closest('table').find('.N_Ticket_Total_Price').text(data.Total);
			o.closest('table').find('.N_Ticket_Total_Count').text(data.Cnt);
			o.closest('table').find('.N_Total_Price').text(data.Cost);
		}
	}, "json");
}
 
 
 
 
 
 
 
 
 
