$(document).ready(function(){

	/* admin */
	$('#admin_userid').keyup(function(){
		$.post('engine/ajax/admin.php',{action:'username',id:$(this).val()},function(data){
			$('#admin_username').html(data);
		});
	});
	$('#admin_image').change(function(){
		$.post('engine/ajax/admin.php',{action:'prefix',image:$(this).val()},function(data){
			$('#admin_prefix').val(data);
		});
	});
	$('#admin_prefix').blur(function(){
		$.post('engine/ajax/admin.php',{action:'prefix_save',image:$('#admin_image').val(),prefix:$(this).val()},function(data){
			$('#admin_prefix').css('border','#00aa00 1px solid');
			setTimeout(function(){
				$('#admin_prefix').css('border','#333 1px solid');
			},2000);
		});
	});
	$('#code_from').keyup(function(){
		$('#code_to').val($(this).val());
	});
	/**/

	$('.showMore a').toggle(function(){
		$('#rc_'+this.id).css('height','auto');
		$('#s1_'+this.id).hide();
		$('#s2_'+this.id).show();
		$('#desc_'+this.id).hide();
		return false;
	},function(){
		$('#rc_'+this.id).css('height','120px');
		$('#s1_'+this.id).show();
		$('#s2_'+this.id).hide();
		$('#desc_'+this.id).show();
		return false;
	});

	if (document.getElementById('caches'))
	{
		if (document.getElementById('caches').value!='')
		{
			$.post('/engine/ajax/coord.php',{trackable:document.getElementById('trackable').value,caches:document.getElementById('caches').value});
		}
	}

	$('#code_select').change(function(){
		$('#code').val(this.value);
	});

	$('#typeoflog').change(function(){
		//$('#code').show();
		$('#code_select').hide();
		if (this.value=='1' || this.value=='3' || this.value=='4' || this.value=='7')
		{
			$('#cache').removeAttr('disabled');
		}
		else
		{
			$('#cache').attr('disabled','disabled');
		}
		if ((this.value=='3' || this.value=='7') && document.getElementById('code_select'))
		{
			//$('#code').hide();
			$('#code_select').show();
		}
	});
	$('#code').keyup(function(){
		$.post('/engine/ajax/code.php',{code:this.value},function(data){
			$('.codeStatus').hide();
			if (data==1)
			{
				$('#codeStatus1').show();
			}
			else if(data==2)
			{
				$('#codeStatus2').show();
			}
			else if(data==3)
			{
				$('#codeStatus3').show();
			}
			else if(data==4)
			{
				$('#codeStatus4').show();
			}
			else if(data==5)
			{
				$('#codeStatus5').show();
			}
			else
			{
				$('#codeStatus0').show();
			}
		});
	});

	/************ mazani fotek ***********/
	$('.deletePhoto').click(function(){
		var elm=this;
		if (confirm($('#lang-delete_photo_confirmation').val()))
		{
			$.post('/engine/ajax/deletePhoto.php',{photo:$(this).html()},function(data){
				if (data!='1') {alert(data);}
				else
				{
					$(elm).parent('.photo').slideUp();
				}
			});
		}
	});
	/***********************/

	/************ mazani logu ***********/
	$('.deleteLog').click(function(){
		var elm=this;
		if (confirm($('#lang-delete_log_confirmation').val()))
		{
			var log=$(this).html();
			$.post('/engine/ajax/deleteLog.php',{log:$(this).html()},function(data){
				if (data!='1') {alert(data);}
				else
				{
					$('.log_'+log).fadeOut();
				}
			});
		}
	});
	/***********************/

	/*************** VOLBA typu ****************/
	//$('.type_gpo').hide();
	//$('.type_std').hide();

	if ($('#type_select').val()==0)
	{
		$('.type_gpo').hide();
		$('.type_std').show();
	}
	else
	{
		$('.type_std').hide();
		$('.type_gpo').show();
	}

	$('#type_select').change(function(){
		if ($(this).val()==0)
		{
			$('.type_gpo').hide();
			$('.type_std').show();
		}
		else
		{
			$('.type_std').hide();
			$('.type_gpo').show();
		}
	});
	/*******************************/
});
