function toggleAuthorDisclosure (id) {
	if (!id) {
		return false;
	}
	if (!$('disclosure_' + id)) {
		return false;
	}
	Effect.toggle('disclosure_' + id, 'appear', {duration: 0.5});
	//$('disclosure_' + id).toggle('appear', {duration: 1.0})
}

function getAuthors (number_a, number_b) {
	var url = '/inc/disclosures/get_authors_ajax.php';
	var div_id = 'authors_container';
	var myAjax = new Ajax.Updater (
		div_id,
		url,
		{
			evalScripts: true,
			method: 'get',
			parameters: {number_a: number_a, number_b: number_b}
		}
	);
}

function toggleMainForm () {
	/*
	var opacity = $('main_form_container').getStyle('opacity');
	if (opacity == 1) {
		new Effect.Opacity('main_form_container', {to: 0.25, duration: 0.5});
	} else {
		new Effect.Opacity('main_form_container', {to: 1.0, duration: 0.5});
	}
	*/
	if ($('main_form_container').visible()) {
		$('main_form_container').fade({duration: 1.0});
	} else {
		$('main_form_container').appear({duration: 1.0});
	}
}

function showContainer (el) {
	if (!$(el)) {
		return false;
	}
	if (!$(el).visible()) {
		$(el).appear({duration: 1.0});
	}
}

function hideContainer (el) {
	if (!$(el)) {
		return false;
	}
	if ($(el).visible()) {
		$(el).fade({duration: 1.0});
	}
}

function toggleContainer (el) {
	if (!$(el)) {
		return false;
	}
	if ($(el).visible()) {
		hideContainer(el);
	} else {
		showContainer(el);
	}
}

function addAgencyRow () {
	var num_existing_rows = 0;
	var rows_selector = $('grant_support_rows').select('input[id^="agency["]');
	num_existing_rows = rows_selector.length;
	next_num = num_existing_rows + 1;
	
	var url = '/inc/disclosures/agency_rows_ajax.php';
	var div_id = 'new_agency_rows';
	var myAjax = new Ajax.Updater (
		div_id,
		url,
		{
			evalScripts: true,
			method: 'get',
			parameters: {action: 'add', row_num: next_num},
			insertion: 'bottom',
			onComplete: addAgencyRowComplete
		}
	);
}

function addAgencyRowComplete (xhr) {
	setNumAgencies();
	$('agency[' + next_num + ']').focus();
}

function setNumAgencies () {
	var rows_selector = $('grant_support_rows').select('input[id^="agency["]');
	$('num_agencies').value = rows_selector.length;
}

function checkNumAgencies () {
	var rows_selector = $('grant_support_rows').select('input[id^="agency["]');
	alert(rows_selector.length);
}

function removeAgencyRow (row_num) {
	if ($('agency_row_' + row_num)) {
		$('agency_row_' + row_num).fade({duration: 0.25});
		setTimeout("$('agency_row_" + row_num + "').remove(); setNumAgencies();", 500);
	}
	
}