function resize_textarea()
{
	if(this.rows == '' || this.rows < 1) {
		this.rows = 1;
	}
	while(this.clientHeight >= this.scrollHeight && this.rows > 1) {
		this.rows -= 1;
	}
	while(this.clientHeight < this.scrollHeight) {
		this.rows += 1;
	}
}

function $dialog(type,note,callback,input)
{
	$('body').append('<div id="overlay"></div>');
	$('#overlay').append('<div id="dialog"></div>');
	$('#dialog').append('<div class="title">'+$l[type]+'</div><div class="inner"></div>');
	output = '<form id="dialog_form">'+note;
	if(type == 'prompt') {
		output += '<div class="space_top"><input type="text" class="input text" value="'+input+'" />';
	}
	output += '<div class="space_top">';
	output += '<input type="submit" class="ok button" value="'+$l['ok']+'" />';
	if(type == 'confirm' || type == 'prompt') {
		output += '<input type="submit" class="cancel button" value="'+$l['cancel']+'" />';
	}	
	output += '</div></form>';
	$('#dialog .inner').html(output);
	$('#dialog').css('opacity','0.0');
	$('#dialog').animate({'opacity': 1.0},'fast');
	$('#dialog .ok').click(function() {
		if(type == 'confirm') {
			callback.call($(this),true);
		}
		if(type == 'prompt') {
			result = $('#dialog .input').val();
			callback.call($(this),result);
		}
	});
	$('#dialog .ok,#dialog .cancel,#overlay').click(function() {
		$('#overlay').remove();
	});
	$('#dialog').click(function() {
		return false;
	});
}

$(document).ready(function() {
	$('body').addClass('js_enabled');
	$('a.confirm,a.delete,a.uninstall').click(function() {
		var link = $(this).attr('href');
		$dialog('confirm',$l['dialog_question']+$l['question_mark'],function() { location.href = link });
		return false;
	});
	$('li.child').css('display','none');
	$('li.current,li.current li').css('display','block');
	$('li.current').siblings().css('display','block');
	$('li.toggle a,fieldset.toggle legend').click(function() {
		$(this).parent().siblings().children('.toggle ul').hide();
		$(this).siblings('ul').toggle();
	});
	$('textarea').css('overflow','hidden').css('resize','none');
	$('textarea').keyup(resize_textarea).keyup();
	$('form .meet').focus(function() {
		$('form .required').each(function() {
			if($(this).val() == '') {
				$(this).addClass('warning');
			}
		})
	});
	$('form .meet').click(function() {
		output = true;
		if($('form .warning').length > 0) {
			$(this).addClass('disabled').attr('disabled','disabled');
			output = false;
		}
		return output;
	});
	$('form .required').keyup(function() {
		if($(this).val()) {
			$(this).removeClass('warning');
			if($('form .warning').length == 0) {
				$('form .meet').removeClass('disabled').removeAttr('disabled');
			}
		}
	});
	$('#search_form input.text').focus(function() {
		value = $(this).val();
		$(this).attr('value','');
	});
	$('#search_form input.text').blur(function() {
		if($(this).val() == '') {
			$(this).val(value);
		}
	});
});