// Fuking ajax file :)

function ajax_topic_delete(postid, urlwsid)
{
$.ajax({
url: siteurl+urlwsid,
type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
		if (xhr.responseText=='sucess')	{
		$('#forumtopic_'+postid).html('');
		}

	}
						}				
});
}

function ajax_topic_delete2(postid, urlwsid, redir)
{
$.ajax({
url: siteurl+urlwsid,
type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
		if (xhr.responseText=='sucess')	{
		location.href = siteurl+redir;
		}

	}
						}				
});
}

function ajax_post_delete(postid, urlwsid, redir)
{
$.ajax({
url: siteurl+urlwsid,
type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
		if (xhr.responseText=='sucess')	{
		location.href = siteurl+redir;
		}

	}
						}				
});
}


function ajax_torrent_reg_unreg(urlwsid, postid)
{
$.ajax({
url: siteurl+urlwsid,
type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
	$('#torrentbodyattach'+postid).html(xhr.responseText);
	}
						}				
});
}




function ajax_bookmark(topicid,dois)
{
$.ajax({
url: siteurl+'additionalajax.php?act=bookmark&do='+dois+'&id='+topicid,
type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
		$('#do_bookmark').html(xhr.responseText);
	}
						}
});
}


function ajax_watch(topicid,dois)
{
$.ajax({
url: siteurl+'additionalajax.php?act=watchtopics&do='+dois+'&id='+topicid,

type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
		$('#do_watch').html(xhr.responseText);
	}
						}
});
}



// rating
var litevote = new Object();
litevote.get = function(id) {
	return document.getElementById(id);
};
litevote.ratingStars = function(rating) {
if( rating==0 )
	return '<img src="'+siteurl+'misc/img/rate/icon_blocked_blue.png" height="12" width="12" border="0" />';
var s = '';
for( var i=0; i<rating; i++ ) {
	s += '<img src="'+siteurl+'misc/img/rate/icon_star_blue.png" height="12" width="12" border="0" />';
}
return s;
};

litevote.emptyStar = new Image();
litevote.emptyStar.src = siteurl+"misc/img/rate/icon_star_grey.png";
litevote.ratedStar = new Image();
litevote.ratedStar.src = siteurl+"misc/img/rate/icon_star_red.png";
litevote.emptySpam = new Image();
litevote.emptySpam.src = siteurl+"misc/img/rate/icon_blocked_gray.png";
litevote.ratedSpam = new Image();
litevote.ratedSpam.src = siteurl+"misc/img/rate/icon_blocked_red.png";


litevote.mouseover = function(n) {
	for( i=1; i<=n; i++ ) {
		this.get('litevote.star'+i).src = this.ratedStar.src;
	}
	for( ; i<=5; i++ ) {
		this.get('litevote.star'+i).src = this.emptyStar.src;
	}
	status = n == -1 ? null : this.get('litevote.star'+n).alt;
	this.get("litevote.descriptor").innerHTML =
		[
			"", 
			"Отстой",
			"Так себе",
			"Средне",
			"Хорошо",
			"Супер",
		][n];
};

litevote.mouseout = function() {

	for( i=1; i<=this.ratedStars; i++ ) {
		this.get('litevote.star'+i).src = this.ratedStar.src;
	}
	for( ; i<=5; i++ ) {
		this.get('litevote.star'+i).src = this.emptyStar.src;
	}
	status = defaultStatus;
	this.get("litevote.descriptor").innerHTML = 'Оцените торрент.';
}

function topic_lock_unl(topicid,type,sid)
{
var link='';
if (type=='lock_topic') link=siteurl+'additionalajax.php?act=lock_topic&t='+topicid+'&sid='+sid;
else if (type=='unlock_topic') link=siteurl+'additionalajax.php?act=unlock_topic&t='+topicid+'&sid='+sid;
$.ajax({
url: link,
type: 'GET',
complete: function (xhr) {
if (xhr.responseText!='') 
	{
		$('#topic_lock_unl').html(xhr.responseText);
	}
						}
});
}

function call_seed(topicid, sid)
{
$.ajax({
url: siteurl+'ajax.php?mode=call_seeds&t='+topicid+'&sid='+sid,
type: 'GET',
dataType: 'script'
});
}
function topic_thank(postid, sid)
{
$.ajax({
url: siteurl+'ajax.php?mode=thank&p='+postid+'&sid='+sid,
type: 'GET',
complete: function (xhr) {if (xhr.responseText!='') {if (xhr.responseText=='true')	$('#topic_thanks'+postid).html(''); }}	
});
}


function post_approve(postid, sid, username, usercolour, userid, totalmark, totalapproval, mode)
{
$.ajax({
url: siteurl+'ajax.php?mode='+mode+'&p='+postid+'&sid='+sid,
type: 'GET',
complete: function (xhr) 
	{
		if (xhr.responseText!='') 
		{
			if (xhr.responseText=='true')
			{
				$('#'+mode+postid).html(''); 

				var user_temp = '<a href="http://amc.normaplus.com/profile.php?mode=viewprofile&u='+userid+'"><span style="color:'+usercolour+';">'+username+'</span></a>';
				var sign = (mode=='approve_plus')? '+':'-';
				var user = user_temp + '<span style="vertical-align:super;font-size:5px;">'+sign+'</span>';

				if (totalapproval==0)
				{
					var approver_status='Оценили: [<span style="color:blue;font-weight:bold;">1</span>]';
					$('#appr_info'+postid).replaceWith('<span class="genmed" style="font-style:italic;cursor:help" onclick="document.getElementById(\'name'+postid+'\').style.display = (document.getElementById(\'name'+postid+'\').style.display==\'inline\')? \'none\':\'inline\'">'+approver_status+'</span><div id="name'+postid+'" style="display:inline;"> '+user+'</div><img src="/templates/amc_style/images/appr-info.png" title="Информация">');
				}
				if ((totalapproval>0 && totalmark<4) || (totalapproval>0 && mode=='approve_minus'))
				{
					var approver_status='<span style="color:blue;font-weight:bold;">'+(parseInt(totalapproval)+1)+'</span>';
					$('#as'+postid).replaceWith(approver_status);
					$('#name'+postid).append(', ' + user);
				}

				if (totalmark==4 && mode=='approve_plus')
				{
					var approver_status='<span style="color:green;font-weight:bold;">'+(parseInt(totalapproval)+1)+'</span>';
					$('#as'+postid).replaceWith(approver_status);
					$('#name'+postid).append(', ' + user);
					var appr_users = $('#name'+postid).html();
					$('#appr_info'+postid).replaceWith('<span class="genmed" style="font-style:italic;cursor:help" onclick="document.getElementById(\'name'+postid+'\').style.display = (document.getElementById(\'name'+postid+'\').style.display==\'inline\')? \'none\':\'inline\'">Зачислен бонус за коментарий.</span> <img src="/templates/amc_style/images/appr-add.png" title="Зачислен бонус"><br><div id="name'+postid+'" style="display:none;">'+'Оценили: ['+approver_status+'] ' +appr_users+'</div>');
				}
			}
		}
	}	
});
}

function return_pass(login, email, sid)
{
$.ajax({
url: siteurl+'ajax.php?mode=return_pass&l='+login+'&e='+email+'&sid='+sid,
type: 'GET',
dataType: 'script'
});
}

function return_emailslogin()
{
$.ajax({
url: siteurl+'ajax.php?mode=return_emailslogin',
type: 'GET',
dataType: 'script'
});
}

function send_return_emailslogin()
{

var username = document.getElementById('return_le_login').value;
var email = document.getElementById('return_le_email').value;

$.ajax({
url: siteurl+'ajax.php?mode=return_pass&l='+username+'&e='+email,
beforeSend: function()
{
if (username=='' || email=='') alert('Не все поля заполнено'); 
},
type: 'GET',
dataType: 'script'
});
}

function load_medalinfo(id)
{
$.ajax({
url: siteurl+'ajax.php?mode=medalinfo&id='+id,
type: 'GET',
complete: function (xhr) {if (xhr.responseText!='') {
body = document.getElementById('popchieldbody');
body.innerHTML=xhr.responseText; }}	
});

}


