$(document).ready(function() {
	$("#videoconf-form").submit(function() {
		if($(".error", this).length == 0)
			{
			var submit = $("input[type=submit]", this).attr('disabled', true);
			
			var inputs = $("input[name][type!=checkbox],input[name][type=checkbox][checked],textarea[name],select[name]", this);
			var values = Object();
			inputs.each(function(i) {
				values[$(this).attr('name')] = $(this).val();
				});
			values['ajax'] = true;
			
			var form = this;
			
			$.post(location.href, values, function() {
				submit.removeAttr('disabled');
				form.reset();
				$("#your-question-ok").fadeIn(600, function() {
					$(this).animate({opacity:1}, 5000, function() {
						$(this).fadeOut(600);
						});
					});
				});
			
			return false;
			}
		});
	
	$("a.delete-videoconf-question, a.approve-videoconf-question").live('click', function() {
		var current = $(this);
		if(confirm(current.attr('confirm'))) {
			current.parents("li:first").remove();
			$.post(this.href, {ajax: true});
			}
		return false;
		});
	
	$("ul.refresh-list").bind('refresh-list', function() {
		var oUl = $(this);
		$.post(location.href,{refreshlist: true}, function(data) {
			oUl.html(data).trigger('refresh-wait');
			});
		}).bind('refresh-wait', function() {
			$(this).animate({opacity:1}, 5000, function() {
				$(this).trigger('refresh-list');
				});
			}).trigger('refresh-wait');
	
	var editdialog = $("#edit-videoconf-question").dialog({autoOpen: false, width:600, minWidth: 600, modal: true});
	$("a.edit-videoconf-question").live('click', function() {
		var current = $(this);
		$("form", editdialog).attr('action', current.attr('href'));
		$("input[name=sender_name]", editdialog).val($(current).parents("li:first").find("p.asks").html());
		$("textarea[name=sender_question]", editdialog).val($(current).parents("li:first").find("div.q").html());
		editdialog.dialog('open');
		return false;
		});
	
	$("#form-moderate-videoconference").submit(function() {
			var inputs = $("input[name][type!=checkbox],input[name][type=checkbox][checked],textarea[name],select[name]", this);
			var values = Object();
			inputs.each(function(i) {
				values[$(this).attr('name')] = $(this).val();
				});
			values['ajax'] = true;
			
			var form = this;
			
			editdialog.dialog('close');
			
			$.post(form.action, values, function(data) {
				$("ul.refresh-list").trigger('refresh-list').trigger('refresh-wait');
				});
			
			return false;
		
		});
	
	});
