function sendUploadForm() {
	$('#upload').submit();
}

function highlight(field) {
	field.focus();
	field.select();
}

function addComment(target)
{
	var form_data = $("#comments_add").serialize();

	$.post("/comments/add/", form_data, function(data)
	{
		$('#'+target).html(data);
	});
}

function editComment(target, comment_fk)
{
	var form_data = $("#comments_edit").serialize();

	$.post("/comments/edit/"+ comment_fk +"/", form_data, function(data)
	{
		$('#'+target).html(data);
	});
}

function deleteComment(target, comment_fk)
{
	var agree = confirm('Вы действительно хотите удалить данный комментарий?');

	if(target && agree)
	{
		$.post("/comments/delete/"+ comment_fk +"/", '', function(data)
		{
			$('#'+target).remove();
		});
	}
}

function changeUploadHost(value) {
	var value = parseInt(value);

	if(value == 0) {
		$('#upload_mb_size').html('20');
		$('#upload_temp_checkbox').attr('checked', 'checked');
	} else {
		$('#upload_mb_size').html('100');
		$('#upload_temp_checkbox').attr('checked', '');
	}
}

function changeButtonImage(target, type) {
	if(target) {
		if(type == 'def') {
			$('#'+ target).css('background', 'url(/public/images/browse.png) no-repeat 0px 0px');
		} else {
			$('#'+ target).css('background', 'url(/public/images/browse.png) no-repeat 0px -42px');
		}
	}
}

function changeUploaderTab(tab_value) {
	if(tab_value == 'html' || tab_value == 'flash' ||  tab_value == 'img' || tab_value == 'txt') {
		if(tab_value == 'html') {
			$('#flash_tab').attr('class', 'active');
			$('#flash_tab').html('Файл');
			$('#img_tab').attr('class', '');
			$('#img_tab').html('<a onClick="changeUploaderTab(\'img\')">Фото</a>');
			$('#txt_tab').attr('class', '');
			$('#txt_tab').html('<a onClick="changeUploaderTab(\'txt\')">Текст</a>');
			$('#inputfile').show();
			$('#uploaded_link').hide();
			$('#imagefile').hide();
			$('#flashfile').hide();	
			$('#text').hide();
		} 
		else if(tab_value == 'img'){
			$('#flash_tab').attr('class', '');
			$('#flash_tab').html('<a onClick="changeUploaderTab(\'flash\')">Файл</a>');
			$('#img_tab').attr('class', 'active');
			$('#img_tab').html('Фото');
			$('#txt_tab').attr('class', '');
			$('#txt_tab').html('<a onClick="changeUploaderTab(\'txt\')">Текст</a>');
			$('#inputfile').hide();
			$('#uploaded_link').hide();
			$('#imagefile').show();
			$('#flashfile').hide();	
			$('#text').hide();
		}
		else if(tab_value == 'txt'){
			$('#flash_tab').attr('class', '');
			$('#flash_tab').html('<a onClick="changeUploaderTab(\'flash\')">Файл</a>');
			$('#img_tab').attr('class', '');
			$('#img_tab').html('<a onClick="changeUploaderTab(\'img\')">Фото</a>');
			$('#txt_tab').attr('class', 'active');
			$('#txt_tab').html('Текст');
			$('#inputfile').hide();
			$('#uploaded_link').hide();
			$('#imagefile').hide();
			$('#flashfile').hide();	
			$('#text').show();
		}
		else {
			$('#flash_tab').attr('class', 'active');
			$('#flash_tab').html('Файл');
			$('#img_tab').attr('class', '');
			$('#img_tab').html('<a onClick="changeUploaderTab(\'img\')">Фото</a>');
			$('#txt_tab').attr('class', '');
			$('#txt_tab').html('<a onClick="changeUploaderTab(\'txt\')">Текст</a>');
			$('#inputfile').hide();
			$('#uploaded_link').hide();
			$('#imagefile').hide();
			$('#flashfile').show();	
			$('#text').hide();
		}
	}
}

function changeCarma(id, vote, type){
	if(type == 'down') var znak = '-';
	if(type == 'up') var znak = '+';
	
	$.post("/files/rating/", {golos: znak+vote, id: id}, function(data)
	{
		$('#file_'+id).html(data);
	});
}

function showUserPage(id){
	$('.uspage').hide();
	$('#pagika').show();
	$('#'+id).show();
}

function saveTxtFile(){
	var txtfile = $('#txtfile').val();
	
	$.post("/files/savetxt/", {savetxt: txtfile}, function(data)
	{
		if(data == ''){
			alert('abu');
		}
		else{
			$('#link_box').val('http://onemove.ru/' + data + '/');
			$('#text').hide();
			$('#uploaded_link').show();
		}
		$('#text').html();
	});
}
