// В рот мне ноги!!!1

function setcookie (name, value, the_time) {
	var expDate = new Date();
	expDate.setTime (expDate.getTime() + (the_time * 1000));
	document.cookie = name + "=" + escape (value) + "; expires=" + expDate.toGMTString ();
}
function element_slide (elementId) {
	var element = document.getElementById(elementId);
	if (element.style.display == 'none') $('#'+elementId).slideDown('slow');
	else $('#'+elementId).slideUp('slow');
}
function fast_search () {
	if (document.getElementById('fast_search').style.display=='none') {
		$('#fast_search').slideDown('fast');
	}
	if ($('#srch').attr('value') != '') {
		$.post(
			"/ajax/articles_search/",
			{ "text": $('#srch').attr('value') },
			function(res) { $("#fast_search_cont").html(res); }
		);
	}
}
function close_fast_search () {
	$('#fast_search').slideUp('fast');
}
function add_art_rating (the_id, the_value){
	$.post(
	   	"/ajax/articles_rating/",
		{ "id": the_id, "value": the_value },
		function(ret) { $("#rating_" + the_id).html(ret); }
	);
}
function add_com_rating (the_id, the_value){
	$.post(
	   	"/ajax/comments_rating/",
		{ "id": the_id, "value": the_value },
		function(ret) { $("#comm_rating_" + the_id).html(ret); }
	);
}
function add_answer (the_id, module, idi){
	var the_form = "<form name='answer' id='answer_form_" + the_id + "' action='' onsubmit=\"update_comments('" + module + "', " + the_id +", " + idi + "); return false;\" method=post><input type=hidden name=parent value='" + the_id + "'><textarea name=com_body id='textarea_" + the_id + "' rows=3 style='width:90%'></textarea>"+
		 "<br><input type=button value='скрыть' onclick='close_answer(" + the_id + ")'> <input type=submit value='добавить'></form>";
	var the_element = document.getElementById('answer_' + the_id);
	if (the_element.style.display == "none") {
		the_element.innerHTML = the_form;
		$('#answer_'+the_id).slideDown('slow');
		document.answer.com_body.focus();
	}
	else {
		$('#answer_'+the_id).slideUp('slow');
		the_element.innerHTML = "";
	}
}
function update_comments (the_module, the_id, idi){
	$.post(
	   	"/ajax/comments_update/",
		{
			"content": idi,
			"parent": the_id,
			"module": the_module,
			"com_body": $("#textarea_" + the_id).attr("value")			
		},
		function(ret) { $("#comments_div").html(ret); $("#textarea_" + the_id).attr("value", ""); }
	);
}
function reload_captcha () {
	var rndval = new Date().getTime(); 
	document.getElementById('captcha_image').innerHTML = "<img src='/image.php?mod=bot&rnd=" + rndval + "' align='absmiddle' />";
}
function add_friend (the_id){
	$.post(
	   	"/ajax/users_friends/",
		{ id: the_id },
		function(ret) { $("#friends_list_false").html(ret); }
	);
}
function change_karma (the_id, the_value){
	$.post(
	   	"/ajax/users_karma/",
		{ "user_id": the_id, "value": the_value },
		function(ret) { $("#karma_value").html(ret); }
	);
}
function vote_blog_karma (the_value, the_id){
	setcookie ("blog_" + the_id, "1", 36000);
	$.post(
	   	"/ajax/articles_blog_karma/",
		{ "blog_name": the_id, "value": the_value },
		function(ret) { $("#karma_value").html(ret); }
	);
}
function blog (the_id, type){
	var the_type = "exit";
	if (type == "join") the_type = "join";
	$.post(
	   	"/ajax/articles_join_blog/",
		{ "blog_id": the_id, "type": the_type },
		function(ret) { $("#blog_options").html(ret); }
	);
}
$(document).ready(function () {
	$("#logo").corner("10px tl tr");
	$("#menu").corner("10px bl br");
	$("#footer").corner("10px");
	$("#main_table").corner("10px");
	$("#user_karma").corner("10px");
	$(".block").corner("10px tl bl");
	$(".site_message").corner("8px");
	$(".site_error").corner("8px");
	$("#second_navigation li").corner("8px tl tr");
	$("#second_navigation").corner("8px bl br");
	$("#block_last_user_arts").corner("10px");
	$("#block_users_top").corner("10px");
	$("#loading-layer").ajaxStart(function(){ $(this).show(); });
	$("#loading-layer").ajaxStop(function(){ $(this).hide(); });
});
function close_answer (the_id) {
	$('#answer_'+the_id).slideUp('slow');
}
function check_name(what, layer){
	var requestFile = "/ajax/users_check_reg/";
	if (what == 'name') {
		$.get(
			requestFile,
			{ "mod": what, "username": document.regist.name.value },
			function(ret) { $("#"+layer).html(ret); }
		);
	}
	if (what == 'login') {
		$.get(
			requestFile,
			{ "mod": what, "userlogin": document.regist.login.value },
			function(ret) { $("#"+layer).html(ret); }
		);
	}
	if (what == 'email') {
		$.get(
			requestFile,
			{ "mod": what, "usermail": document.regist.email.value },
			function(ret) { $("#"+layer).html(ret); }
		);
	}
}