function logout(){
	$('body').append(
'<form action="/" id="logout" method="post">'+
'<input type="hidden" name="entersite" value="logout" />'+
'</form>'
			);
	$('#logout').submit();
}

function addCommentForm(extId, docId, parentId){
	var parent = $('#comments_'+parentId);
	if (parent.children('.share_inn').html() != null)
		parent.children('.share_inn').remove();
	else
		parent.append("<dl class='share_inn'><div class='share'><textarea id='"+extId+"_"+docId+"_"+parentId+"' class='comment-post'></textarea><br /><input class='comment-btn' type='button' value='Publish comment' onclick='addComment("+extId+", "+docId+", "+parentId+")' /></div></dl>");
}

function addComment(extId, docId, parentId){
	var text = $("#"+extId+"_"+docId+"_"+parentId).val();
	$("#"+extId+"_"+docId+"_"+parentId).parent().html("<div style='padding-left: 10px;'><img src='/img/ajax-loader.gif' /></div>");
	
	
	$.ajax({
	      url: "/user/?&act=comment",
	      type: "POST",
	      data: {text : text, extId : extId, docId : docId, parentId : parentId, ext_act : 'insert_data'},
	      async:true,
	      success: function(msg){
	    	  $('#comments').html(msg);
	      }
	   });
}

function addVote(action, commentId){
	$.ajax({
	      url: "/user/?&act=vote",
	      type: "POST",
	      data: {action : action, comment_id : commentId},
	      async:true,
	      success: function(msg){
	    	  $('#vote_'+commentId).html(msg);
	      }
	   });
}

function resetPassword(){
	var login = $("#ch_input_login", $('#modal-window')).val();
	if (login == "Login" || login == "login")
		login = "";
	if (login == ""){
		$("#change_pass", $('#modal-window')).css("color", "red");
		$("#change_pass", $('#modal-window')).html("Enter your login!");
		return;
	}
	var capcha = $("#capcha", $('#modal-window')).val();
	$.ajax({
	      url: "/user/?&act=resetpass",
	      type: "POST",
	      data: {login : login, capcha : capcha},
	      async:true,
	      success: function(msg){
	    	  //alert(msg);
	    	  eval("var result = "+msg);
	    	  //eval("var result = {status : 'found', message 'Password changed! Check your e-mail.'}");
	    	  //alert(result);
	    	  if (result.status == 'notfound'){
	    		  $("#change_pass", $('#modal-window')).css("color", "red");
	    	  } else if (result.status == 'awrong') {
	    		  $("#change_pass", $('#modal-window')).css("color", "red");
	    	  } else if (result.status == 'found'){
	    		  $("#change_pass", $('#modal-window')).css("color", "green");
	    	  }
	    	  $("#change_pass", $('#modal-window')).html(result.message);
	      }
	   });
}

function showListLang(){
	$('#list_lang').toggle('fast', function() {
		if ($('#list_lang').is(':visible')){
			$('body').unbind('click');
			$('body').bind('click', function(){
				$('#list_lang').hide('fast', function(){ $('body').unbind('click'); });
			});
		} else {
			$('body').unbind('click');
		}
			
	});
}

function updateNewsBottom(){
	var data = null;
	$.ajax({
		url: "/news/?&act=loadlastnews",
		type: "POST",
		data: {},
		async: false,
		success: function(msg){
			eval(msg);
			data = lastNewsOject;
		}
	});
	
	var maxIndex = 0;
	var index = 0;
	for(var newsItemIndex in data){
		maxIndex = newsItemIndex;
	}
	
	$("#accordeon_news_menu").html(data[index].menu);
	$("#accordeon_news_article").html(data[index].news);
	$("#accordeon_news_menu").attr("href", "/news/"+data[index].menu_url);
	$("#accordeon_news_article").attr("href", "/news/"+data[index].news_url);
	
	index++;
	setInterval(function(){
		if (index > newsItemIndex)
			index = 0;
		//$("#accordeon_news_menu, #accordeon_news_article").animate({ display:"none" }, 500 , function(){
			$("#accordeon_news_menu").html(data[index].menu);
			$("#accordeon_news_article").html(data[index].news);
			$("#accordeon_news_menu").attr("href", "/news/"+data[index].menu_url);
			$("#accordeon_news_article").attr("href", "/news/"+data[index].news_url);
			//$("#accordeon_news_menu, #accordeon_news_article").animate({ display:"block" }, 500);
		//});
		index++;
	}, 7000);
}
$(document).ready(function(){
	updateNewsBottom();
});
