jq.profile.proceed={
	init: function(){
		jq.jQuery(document).ready(function(){
			jq.jQuery("#select_country").change(jq.profile.proceed.select_country_regions);
			if (jq.jQuery("select#select_country").attr("title")){
				jq.jQuery("select#select_country").trigger("change");
			}
			jq.jQuery("#select_region").live("change",jq.profile.proceed.select_country_cities);
			jq.jQuery("#usernote_inner").hover(jq.profile.proceed.hover_usernote);
			jq.jQuery("#usernote_inner").live("click",jq.profile.proceed.show_note_textarea);
			jq.jQuery("#note_save").live("click",jq.profile.proceed.submit_note_form);
			jq.jQuery("#note_reset").live("click",jq.profile.proceed.reset_note_form);
			jq.jQuery("#profile_vote").click(jq.profile.proceed.vote_for_user);
			jq.jQuery("#profile_to_friends").click(jq.profile.proceed.add_to_friends);
			jq.jQuery("#profile_from_friends").click(jq.profile.proceed.remove_from_friends);
			jq.jQuery("#profile_to_cumirs").click(jq.profile.proceed.add_to_cumirs);
			jq.jQuery("#profile_from_cumirs").click(jq.profile.proceed.remove_from_cumirs);
			jq.jQuery("#writefrm").click(jq.profile.proceed.toggle_forum_form);
			jq.jQuery("#write_forum_remove").click(jq.profile.proceed.hide_forum_form);
			jq.jQuery("#write_forum_save").click(jq.profile.proceed.submit_forum_form);
			jq.jQuery("#alch").click(jq.profile.proceed.check_messages);
			jq.jQuery("#submitff").click(jq.profile.proceed.submit_form);
			jq.jQuery("#write_news_save").click(jq.profile.proceed.submit_news_form);
			jq.jQuery("#write_event_save").click(jq.profile.proceed.submit_event_form);
			jq.jQuery("#new_profiles_selector").change(jq.profile.proceed.update_new_persons_block);
			jq.jQuery("#psess_vote").click(jq.profile.proceed.vote_for_photosession);
			jq.jQuery("#assign_to_funclub").click(jq.profile.proceed.assign_to_funclub);
			jq.jQuery("#write_psess_save").click(jq.profile.proceed.submit_psess_form);
			jq.jQuery(".profile_week_vote").click(jq.profile.proceed.vote_week);
			jq.jQuery(".profile_month_vote").click(jq.profile.proceed.vote_month);
			jq.jQuery(".profile_y_vote").click(jq.profile.proceed.vote_y);
			jq.jQuery(".rs_user").click(jq.profile.proceed.show_suggested_item);
			jq.jQuery("#toggle_male").live("click",jq.profile.proceed.user_toggle_male);
			jq.jQuery("#toggle_female").live("click",jq.profile.proceed.user_toggle_female);
		});
	},

	select_country_regions: function(){
		var id = jq.jQuery(this).val();
		jq.jQuery(this).attr("disabled","disabled");
		jq.jQuery("#select_region").empty();
		jq.jQuery("#select_city").empty();
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/get_regions/",
			data: 'id='+id,
			dataType:'json',
			success: function(msg){
				jq.jQuery("#select_region").append(msg.msg);
				jq.jQuery("#select_region").removeAttr("disabled");
				jq.jQuery("#select_country").removeAttr("disabled");

				if (msg.u !== ''){
					jq.jQuery("#select_city").append(msg.u);
					jq.jQuery("#select_city").removeAttr("disabled");
				}
			}
		});
	},

	select_country_cities: function(){
		var id = jq.jQuery(this).val();
		jq.jQuery(this).attr("disabled","disabled");
		jq.jQuery("#select_city").empty();
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/get_cities/",
			data: 'id='+id,
			dataType:'json',
			success: function(msg){
				jq.jQuery("#select_city").append(msg.msg);
				jq.jQuery("#select_region").removeAttr("disabled");
				jq.jQuery("#select_city").removeAttr("disabled");
			}
		});
	},

	hover_usernote : function(){
		jq.jQuery("#usernote_inner")
			.animate(
				{ backgroundColor: "rgb(247,255,157)" },
				{duration: 900,complete : function(){
					jq.jQuery("#usernote_inner").animate({ backgroundColor: "rgb(217,217,217)" },900);
				}}
			);
	},

	show_note_textarea : function(){
		var html = jq.jQuery("#abstract_container").html();
		jq.jQuery("#usernote_inner").empty().append(html);
		var txt = jq.jQuery("#usernote_inner").find("textarea");
		txt.attr("id","usernote_text");
		jq.jQuery("#usernote_text").val('Напишите все, что захочется');
		jq.jQuery("#usernote_inner").css("background-color","#D9D9D9");
		jq.jQuery("#usernote_inner").removeAttr("id");
	},

	submit_note_form : function(){
		var txt = jq.jQuery(this).parent().parent().parent().children().find("#usernote_text");
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/update_usernote/",
			data: 'text='+txt.val(),
			dataType:'json',
			success: function(msg){
				jq.jQuery("#usernote_text").parent().parent().parent().html('<div id="usernote_inner">'+txt.val()+'</div>');

			}
		});
	},

	reset_note_form : function(){
		var txt = jq.jQuery(this).parent().parent().parent().children().find("#usernote_text");
		txt.val('');
	},

	vote_for_user : function(e){
		e.preventDefault();
		var id = jq.jQuery("#uid").val();
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/vote_for_user/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#figures_profile_rating").html(data.msg);
				jq.jQuery("#profile_vote").remove();
			}
		});
	},

	add_to_friends : function(e){
		e.preventDefault();
		var id = jq.jQuery("#uid").val();
		jq.jQuery("#profile_to_friends").removeAttr("id");
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/add_to_friends/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#friends_button_title").text('из друзей');
			}
		});
	},

	remove_from_friends : function(e){
		e.preventDefault();
		var id = jq.jQuery("#uid").val();
		jq.jQuery("#profile_to_friends").removeAttr("id");
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/remove_from_friends/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#friends_button_title").text('в друзья');
			}
		});
	},

	add_to_cumirs : function(e){
		e.preventDefault();
		var id = jq.jQuery("#uid").val();
		jq.jQuery("#profile_to_cumirs").removeAttr("id");
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/add_to_cumirs/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#cumirs_button_title").text('из кумиров');
			}
		});
	},

	remove_from_cumirs : function(e){
		e.preventDefault();
		var id = jq.jQuery("#uid").val();
		jq.jQuery("#profile_from_cumirs").removeAttr("id");
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/remove_from_cumirs/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#cumirs_button_title").text('в кумиры');
			}
		});
	},

	toggle_forum_form: function(e){
		e.preventDefault();
		jq.jQuery("#button_container").hide();
		jq.jQuery("#form_container").show();
	},

	hide_forum_form : function(e){
		e.preventDefault();
		jq.jQuery("#button_container").show();
		jq.jQuery("#form_container").hide();
	},

	submit_forum_form : function(e){
		e.preventDefault();
		var id = jq.jQuery("#usr").val();
		var text = jq.jQuery("#text").val();
		if (text == ''){
			alert('Вы не ввели текст сообщения!');
			return;
		}
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/submit_forum_message/",
			data: 'id='+id+'&text='+text,
			dataType:'json',
			success: function(data){
				window.location = '/user/'+id;
			}
		});
	},

	submit_news_form : function(e){
		e.preventDefault();
		var id = jq.jQuery("#usr").val();
		var text = jq.jQuery("#text").val();
		if (text == ''){
			alert('Вы не ввели текст сообщения!');
			return;
		}
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/submit_news_message/",
			data: 'id='+id+'&text='+text,
			dataType:'json',
			success: function(data){
				window.location = '/news/id/'+id;
			}
		});
	},

	submit_event_form : function(e){
		e.preventDefault();
		var id = jq.jQuery("#usr").val();
		var text = jq.jQuery("#text").val();
		if (text == ''){
			alert('Вы не ввели текст сообщения!');
			return;
		}
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/submit_event_message/",
			data: 'id='+id+'&text='+text,
			dataType:'json',
			success: function(data){
				window.location = '/events/id/'+id;
			}
		});
	},

	check_messages : function(){
		jq.jQuery(".ch").each(function(){
			if (jq.jQuery(this).attr("checked")){
				jq.jQuery(this).removeAttr("checked");
			}else{
				jq.jQuery(this).attr("checked","checked");
			}
		});
	},

	submit_form : function(e){
		e.preventDefault();
		jq.jQuery(".myform").submit();
	},

	update_new_persons_block : function(){
		var id = jq.jQuery(this).val();
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/update_new_persons_block/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#new_persons_block").empty();
				jq.jQuery("#new_persons_block").append(data.msg);
			}
		});
	},

	vote_for_photosession : function(e){
		e.preventDefault();
		var id = jq.jQuery(this).parent().children("#pid").val();
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/vote_for_photosession/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#photosession_value").empty().append(data.rate);
			}
		});
	},

	assign_to_funclub : function(e){
		e.preventDefault();
		var id = jq.jQuery(this).parent().children("#pid").val();
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/assign_to_funclub/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				jq.jQuery("#friends_button_title").empty().append('вы вступили');
			}
		});
	},

	submit_psess_form : function(e){
		e.preventDefault();
		var id = jq.jQuery("#pid").val();
		var text = jq.jQuery("#text").val();
		if (text == ''){
			alert('Вы не ввели текст сообщения!');
			return;
		}
		jq.jQuery.ajax({
			type: "POST",
			url: "/content/submit_psession_message/",
			data: 'id='+id+'&text='+text,
			dataType:'json',
			success: function(data){
				window.location = '/content/photosession/'+id;
			}
		});
	},

	vote_week : function(){
		var id = jq.jQuery(this).parent().children("#index").val();

		jq.jQuery.ajax({
			type: "POST",
			url: "/content/week_vote/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				if (data.error == ''){
					jq.jQuery("#upd_week_"+id).empty().append(data.data);
				}else{
					alert(data.error);
				}
			}
		});
	},

	vote_month : function(){
		var id = jq.jQuery(this).parent().children("#index").val();

		jq.jQuery.ajax({
			type: "POST",
			url: "/content/month_vote/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				if (data.error == ''){
					jq.jQuery("#upd_month_"+id).empty().append(data.data);
				}else{
					alert(data.error);
				}
			}
		});
	},

	vote_y : function(){
		var id = jq.jQuery(this).parent().children("#index").val();

		jq.jQuery.ajax({
			type: "POST",
			url: "/content/y_vote/",
			data: 'id='+id,
			dataType:'json',
			success: function(data){
				if (data.error == ''){
					jq.jQuery("#upd_month_"+id).empty().append(data.data);
				}else{
					alert(data.error);
				}
			}
		});
	},

	show_suggested_item : function(e){
		e.preventDefault();

		var id = jq.jQuery(this).parent().children("#uid").val();

		jq.jQuery.ajax({
			type: "POST",
			url: "/content/show_suggested/",
			data: 'id='+id,
			dataType:'json',
			success: function(msg){
					jq.jQuery.nyroModalManual({
					bgColor: '#eee',
					content: msg.html
				});
			}
		});
	},

	user_toggle_male : function(e){
		e.preventDefault();

		var id = jq.jQuery(this).parent().children("#uid").val();

		jq.jQuery.ajax({
			type: "POST",
			url: "/content/toggle_male/",
			data: 'id='+id,
			dataType:'json',
			success: function(msg){
				alert('пол пользователя изменен на мужской');
			}
		});
	},

	user_toggle_female : function(e){
		e.preventDefault();

		var id = jq.jQuery(this).parent().children("#uid").val();

		jq.jQuery.ajax({
			type: "POST",
			url: "/content/toggle_female/",
			data: 'id='+id,
			dataType:'json',
			success: function(msg){
				alert('пол пользователя изменен на женский');
			}
		});
	}
}
jq.profile.proceed.init();
