//Добрый день. Будьте так любезны не пиздить данный скрипт.

function addcomment(comment, news_id)
{
	var close = "<div align=\"right\"><a title=\"закрыть подсказку\" style=\"cursor:pointer\" onClick=\"document.getElementById('result').style.display = 'none';\">[X]</a></div>\n";
	var adc_req = ajax();
	if(adc_req)
	{
		adc_req.onreadystatechange = function()
		{
			if(adc_req.readyState == 4)
			{
				if(adc_req.status == 200)
				{
					document.getElementById('result').style.display = 'block';
					if(adc_req.responseText=='1')
					{
						document.getElementById('result').innerHTML = close + 'Комментарий успешно добавлен';
						document.comment_form.comment.value = '';
						getcomments(news_id);
					}
					else
					{
						document.getElementById('result').innerHTML = close + 'При добавлении комментария произошли следующие ошибки:<br />'+adc_req.responseText;
					}
				}
			}
		}
		adc_req.open('POST', 'ajax.php?do=addcomment', true);
		adc_req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
		adc_req.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
		adc_req.send('comment='+comment+'&news_id='+news_id);
	}
}


function getcomments(news_id)
{
	var gc_req = ajax();
	if(gc_req)
	{
		gc_req.onreadystatechange = function()
		{
			if(gc_req.readyState == 4)
			{
				if(gc_req.status == 200)
				{
					document.getElementById('div_com').innerHTML = gc_req.responseText;
				}
			}
		}
		gc_req.open('GET', 'ajax.php?do=getcomments&news_id='+news_id, true);
		gc_req.send(null);
	}
}

function getlinks(news_id)
{
	document.getElementById('div_links').innerHTML = "<img src='/forum/images/misc/progress.gif' width='16' height='16' align='texttop' alt='' /> Запрос ссылок на файл. Пожалуйста ждите...";
	var gl_req = ajax();
	if(gl_req){
		gl_req.onreadystatechange = function()
		{
			if(gl_req.readyState == 4)
			{
				if(gl_req.status == 200)
				{
					document.getElementById('div_links').innerHTML = gl_req.responseText;
				}
			}
		}
		gl_req.open('GET', 'ajax.php?do=getlinks&news_id='+news_id, true);
		gl_req.send(null);
	}
}

function disagree()
{
	document.getElementById('div_links').innerHTML = "В соответствии с предупреждением (Disclaimer), Вы обязаны покинуть данный сайт.";
}

function getsurvey()
{
	var gs_req = ajax();
	if(gs_req)
	{
		gs_req.onreadystatechange = function()
		{
			if(gs_req.readyState == 4)
			{
				if(gs_req.status == 200)
				{
					document.getElementById('div_survey').innerHTML = gs_req.responseText;
				}
			}
		}
		gs_req.open('GET', 'ajax.php?do=survey', true);
		gs_req.send(null);
	}
}

function vote(act)
{
	var v_req = ajax();
	if(v_req)
	{
		v_req.onreadystatechange = function()
		{
			if(v_req.readyState == 4)
			{
				if(v_req.status == 200)
				{
					document.getElementById('div_survey').innerHTML = v_req.responseText;
				}
			}
		}

		if(act == 1)
		{
			var radio_value;
			var radio_length = document.survey.questions.length;
			var survey_id = document.survey.survey_id.value;
			for(var i = 0; i < radio_length; i++)
			{
				if(document.survey.questions[i].checked == true)radio_value = i + 1;
			}
			if(radio_value > -1 && radio_value < radio_length + 1)
			{
				v_req.open('POST', 'ajax.php?do=survey&action=vote', true);
				v_req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
				v_req.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
				v_req.send('questions='+radio_value+'&survey_id='+survey_id);
			}
		}
		else
		{
			v_req.open('GET', 'ajax.php?do=survey&action=result', true);
			v_req.send(null);
		}
	}
}

function captcha()
{
	var nc = new Date().getTime();
	try
	{
		document.news_add.code.value = '';
		document.getElementById('captcha').innerHTML = '<a style="cursor:pointer" onClick="captcha()"><img src="/captcha.jpg?nc='+nc+'" width="180" height="60" alt="нажмите для смены картинки" class="captcha" /></a>';
	}
	catch(e)
	{

	}
}

function ajax()
{
	var aj = false;
	try
	{
		aj = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			aj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				aj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				aj = false;
			}
		}
	}
	return aj;
}


function pmalert(count)
{
	if(count > 0 && confirm('У Вас есть непрочитанные личные сообщения ('+count+' шт.)\nДля просмотра нажмите "OK".'))
	{
		window.location = '/forum/private.php';
	}
}

var news_error = new Array();
var news_error_count = 0;

function AddError(string)
{
	news_error.push(string);
	news_error_count++;
}

function DelError()
{
	news_error = new Array();
	news_error_count = 0;
}

function startUpload()
{
	var atlntx_news = document.news_add;

	if(atlntx_news.original.value == '')
	{
		AddError('Не указано оригинальное название');
	}

	if(atlntx_news.cat.value == 0)
	{
		AddError('Не указан раздел');
	}
	
	if(atlntx_news.genre.value == '')
	{
		AddError('Не указан жанр');
	}

	if(atlntx_news.author.value == '')
	{
		AddError('Не указан режиссер');
	}
	
	if(atlntx_news.casts.value == '')
	{
		AddError('Не указан список актеров');
	}

	if(atlntx_news.reldate.value == '')
	{
		AddError('Не указана дата выхода');
	}

	if(atlntx_news.about.value == '')
	{
		AddError('Отсутствует описание');
	}

	if(atlntx_news.length.value == '')
	{
		AddError('Не указана продолжительность');
	}

	if(atlntx_news.translate.value == '')
	{
		AddError('Отсутствует информация о переводе');
	}

	if(atlntx_news.quality.value == '')
	{
		AddError('Не указано качество');
	}

	if(atlntx_news.format.value == '')
	{
		AddError('Не указан формат');
	}

	//if(atlntx_news.video.value == '')
	//{
	//	AddError('Отсутствует информация о качестве видео');
	//}

	//if(atlntx_news.audio.value == '')
	//{
	//	AddError('Отсутствует информация о качестве аудио');
	//}

	if(atlntx_news.size.value == '')
	{
		AddError('Не указан размер фильма');
	}

	if(atlntx_news.links.value == '')
	{
		AddError('Не указаны ссылки');
	}
	
	if(news_error_count == 0)
	{
		var atlntx_title = '';
		var atlntx_short_text = '';
		var atlntx_full_text = "\n";

		if(atlntx_news.name.value != '')
		{
			atlntx_title += atlntx_news.name.value + " / ";
			atlntx_short_text += "[b]Название:[/b] " + atlntx_news.name.value + "\n";
		}

		atlntx_title += atlntx_news.original.value + " ("+ atlntx_news.quality.value +") (" + atlntx_news.reldate.value + ")";

		atlntx_short_text += "[b]Оригинальное название:[/b] " + atlntx_news.original.value + "\n";
		atlntx_short_text += "[b]Год выпуска:[/b] " + atlntx_news.reldate.value + "\n";
		atlntx_short_text += "[b]Жанр:[/b] " + atlntx_news.genre.value + "\n";
		atlntx_short_text += "[b]Режиссер:[/b] " + atlntx_news.author.value + "\n";
		atlntx_short_text += "[b]В ролях:[/b] " + atlntx_news.casts.value + "\n\n";
		atlntx_short_text += "[b]О фильме:[/b]\n" + atlntx_news.about.value + "\n";

		if(atlntx_news.imdb.value != '')
		{
			atlntx_full_text += "[b]IMDB User Raiting:[/b] " + atlntx_news.imdb.value + "\n";
		}

		if(atlntx_news.country.value != '')
		{
			atlntx_full_text += "[b]Выпущено:[/b] " + atlntx_news.country.value + "\n";
		}

		atlntx_full_text += "[b]Продолжительность:[/b] " + atlntx_news.length.value + "\n";
		atlntx_full_text += "[b]Перевод:[/b] " + atlntx_news.translate.value + "\n\n";
		atlntx_full_text += "[b]Формат:[/b] " + atlntx_news.format.value + "\n";
		atlntx_full_text += "[b]Качество:[/b] " + atlntx_news.quality.value + "\n";
		atlntx_full_text += "[b]Видео:[/b] " + atlntx_news.video.value + "\n";
		atlntx_full_text += "[b]Аудио:[/b] " + atlntx_news.audio.value + "\n";
		atlntx_full_text += "[b]Размер:[/b] " + atlntx_news.size.value + "\n";

		document.news_add.title.value = atlntx_title;
		document.news_add.short_text.value = atlntx_short_text;
		document.news_add.full_text.value = atlntx_full_text;
	
		showUpload();
	
		return true;	

	}
	else
	{
		var atlntx_errors = '';
		
		for(i = 0; i < news_error_count; i++)
		{
			atlntx_errors += " - " + news_error[i] + "<br />";
		}
		
		DelError();
				
		captcha();

		document.getElementById('progress').innerHTML = "<div class=\"quote\"><b>Допущены следующие ошибки:</b><br />" + atlntx_errors + "</div><br />";
		document.getElementById('progress').style.display = 'block';
		return false;
	}
}

function showUpload()
{
	document.getElementById('progress').innerHTML = '<center><img src="/media/images/loader.gif" alt="loading..." width="220" height="19" border="0" /></center>';
	document.getElementById('progress').style.display = 'block';
	document.getElementById('upload_result').style.display = 'none';
}

//escape overload
var transq = [];
for(var tq = 0x410; tq <= 0x44F; tq++)
{
	transq[tq] = tq - 0x350;
}
transq[0x401] = 0xA8;
transq[0x451] = 0xB8;

var t_escape = window.escape;

window.escape = function(search_string)
{
	var retq = [];
	for(var tq = 0; tq < search_string.length; tq++)
	{
		var nq = search_string.charCodeAt(tq);
		if(typeof transq[nq] != 'undefined')
		{
			nq = transq[nq];
		}
		if(nq <= 0xFF)
		{
			retq.push(nq);
		}
	}
	return t_escape(String.fromCharCode.apply(null, retq));
}
