$(document).ready(function(){
	var mapfirsopen = false;
	var cityfirsopen = false;
	
	$("#sf_select_metro_msk").click(function(){ 
		if (mapfirsopen == false) { 
			mapfirsopen = true;
			$.post("/map/metro.php", function(data){
			  $("#metro-map").html(data);		  
			});
		}
		$("#metro-map").fadeIn();		
	});
	
	$("#sf_select_metro_spb").click(function(){ 
		if (mapfirsopen == false) { 
			mapfirsopen = true;
			$.post("/map/metro-spb.php", function(data){
			  $("#metro-map").html(data);		  
			});
		}
		$("#metro-map").fadeIn();		
	});
			
	$("#sf_change_city").click(function(){
		if (cityfirsopen == false) { 
			cityfirsopen = true;
			$.get("/citylist-utf.txt", function(data){
			  $("#list-cityes").prepend(data);		  
			});	
		}
		$("#list-cityes").fadeIn();	
	});
});

function listCityesClose(){ 
	$("#list-cityes").fadeOut(); 
}


function set_var(vars) {
	var varsisset = $.cookie(vars);
	if (varsisset != "checked") {
		$.cookie(vars,"checked");
	//	$.cookie(vars,"checked",{expires: 7, path: '/', domain: '.egent.ru'});
	} else {
		$.cookie(vars,null);
	}
}



$(document).ready(function(){
    $(".vip_button").click(function() {
		$(".sms-info").toggle("slow");
	});
    $("#vipclose").click(function() {
		$(".sms-info").toggle("slow");
	});	
	
	jumpingtext = $("#jumping").html();
	$('#fromjumping').append(jumpingtext);
	$("#jumping").remove();	
	
	//google_banner = $("#start_google_banner").html();
	//$('#google_banner').append(google_banner);
	
	
});




$(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-form22222").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");
 	});
 
 
 
 
 $('#zhaloba-form').submit(function() {
	sendform = $(this);
	
	var opt = { 
		target:     '#divToUpdateZ', 
		dataType:	'json',
		success:    function(response, statusText, xhr, $form) { 
			if (response.status == 'ok') {
				alert(response.msg);
				sendform.clearForm();
				sendform.parent().hide();			
			} else {
				alert(response.msg);
				return false;
			}
		} 
	}; 
	 
    sendform.ajaxSubmit(opt); 
    return false; 	
});
 
 $('#addNewCity').submit(function() {
	sendform = $(this);	
	var opt = { 
		dataType:	'json',
		success:    function(response, statusText, xhr, $form) { 
			if (response.status == 'ok') {
				alert(response.msg);
				sendform.clearForm();
				sendform.parent().hide();			
			} else {
				alert(response.msg);
				return false;
			}
		} 
	}; 
    sendform.ajaxSubmit(opt); 
    return false; 	
}); 
 
 
 
 
 });

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);
}




$(document).ready(function(){

	var citylist_box_open = false;
	
	$('#city_changer').click(function(){
		if (citylist_box_open == false) {
			citylist_box_open = true;
			$('#citylist_box').slideDown();
		} else {
			citylist_box_open = false;
			$('#citylist_box').slideUp();
		}		
	});
		

	$('#citylist_box_close').click(function(){
		$('#citylist_box').slideUp();
		citylist_box_open = false;
	});


	$(".city_items ul li").mouseenter(function () {
		$(this).addClass("hover");
	}).mouseleave(function () {
		$(this).removeClass("hover");	
	});
	
	$("#back_to_regions").click(function () {
		$(this).slideUp();
		$("#city_items").slideDown();
		$("#cityes").html('').slideUp();		
	});
	
	
	$(".city_items ul li").click(function () {
		id = $(this).attr("id");
		
		$("#city_items").slideUp();
		
		$("#cityes").slideUp('fast', function(){
			$.post("/ajax/get_city_list/"+id+"/", { "id_region": id },
			 function(data){
				$("#cityes").html(data).slideDown();
				$("#back_to_regions").slideDown();
			 });
		});
	});
	
});
