$(document).ready(function(){
	$(".sf_digits li").click(function(){
		$(this).toggleClass("sf_select");
		
		if ($("#i_"+$(this).attr("id")).val() == 0) $("#i_"+$(this).attr("id")).val(1); else $("#i_"+$(this).attr("id")).val(0);
		
	});
	
	$(".sf_action").click(function(){		
		$(this).toggleClass("sf_select");
		
		if ($("#i_"+$(this).attr("id")).val() == 0) $("#i_"+$(this).attr("id")).val(1); else $("#i_"+$(this).attr("id")).val(0);
		
	});
	
	$('#sf_submit').click(function() {
  		$('#sf_form').submit();
	});
		
});


$(document).ready(function(){
	function resets(){
		$(".sender #username").attr("value","");
		$(".sender #email").attr("value","");
		$(".sender #text").attr("value","");

		$(".zhaloba #zh_username").attr("value","");
		$(".zhaloba #zh_email").attr("value","");
		$(".zhaloba #zh_text").attr("value","");

	}

	$("#form_cancel").click(function() {
		$(this).parent().fadeOut("50",function(){resets();});
		return;
	});

	$("#zhaloba_cancel").click(function() {
		$(this).parent().fadeOut("50",function(){resets();});
		return;
	});


   $(".content").find(".trigger_send").each(function(i) {
		$(this).click(function() {
			var id = $(this).attr('rel');
			$(".sender #id_notice").attr("value",id);
			$(".sender #n_number").text(id);
				$(".sender").fadeOut("50",
				function(){
					resets();
					$(".sender").fadeIn("50");
				});
		 });
	});

   $(".content").find(".zhaloba_send").each(function(i) {
		$(this).click(function() {
			var id = $(this).attr('rel');
			$(".zhaloba #zh_id_notice").attr("value",id);
			$(".zhaloba #zh_n_number").text(id);
				$(".zhaloba").fadeOut("50",
				function(){
					resets();
					$(".zhaloba").fadeIn("50");
				});
		 });
	});

});

$(document).ready(function() {
 	$("#ajax-form").submit(function(e) {
 		e.preventDefault();
		$.post("/sender/", {
			   username: $(".sender #username").val(),
			   email: $(".sender #email").val(),
			   text: $(".sender #text").val(),
			   id_notice: $(".sender #id_notice").val()

			   }, function (data) {
				  if (data.status == 'ok')  {
						$(".sender").fadeOut("50",function(){alert('Сообщение отправлено!');});
					  }
				  else {
		  			alert(data.msg);
					}
		}, "json");
 	});
 });

 $(document).ready(function() {
 	$("#zhaloba-form").submit(function(e) {
 		e.preventDefault();
		$.post("/sender/zhaloba/", {
			   username: $(".zhaloba #zh_username").val(),
			   email: $(".zhaloba #zh_email").val(),
			   text: $(".zhaloba #zh_text").val(),
			   id_notice: $(".zhaloba #zh_id_notice").val()

			   }, function (data) {
				  if (data.status == 'ok')  {
						$(".zhaloba").fadeOut("50",function(){alert('Сообщение отправлено!');});
					  }
				  else {
		  			alert(data.msg);
					}
		}, "json");
 	});
 });

function vote(id) {window.open ('http://egent.ru/vote.php?id='+id+'&typ=1', 'votes', 'width=400,height=250,status=0,toolbar=0');}
function maps(link) {window.open ('http://egent.ru/showmap.php?addr='+link, 'maps', 'width=620,height=420,status=0,toolbar=0');}


function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

