jQuery(function()
{
	
	$('a.delete').click(function()
	{
		if (!confirm('This will be deleted permanently!'))
		{ return false; }
	});
	
	$('#search_text').live('click', function()	
	{
		$.post('/reports/search/text', function(data) {
		  $('#search_params').html(data);
		});
	});

	$('#search_date').live('click', function()	
	{
		$.post('/reports/search/date', function(data) {
		  $('#search_params').html(data);
		});
	});
		
	$('a#new-contact').click(function()
	{
		$.get('/reports/contacts/' + $('.contact_name').size(), function(data)
		{
			$(data).insertBefore($('#new-contact-tr'));
		});
		return false;
	});
	
	$('input#rrnco_pres').change(function()
	{
		if ($('input#rrnco_pres').val() > 0)
		{ $('input#rrnco_name').removeAttr('disabled'); }
		else
		{ $('input#rrnco_name').attr('disabled', true); }
	});
	
	$('input#school_visit').click(function() {$('span#school-visit-attendees').toggle();});
	$('input#conference').click(function() {$('span#conference-attendees').toggle();});
	$('input#outreach_event').click(function(){$('span#outreach-event-attendees').toggle();});
	
	$('input#asvab').change(function()
	{
		if ($(this).val() > 0)
		{ $('span#asvab_new_exists').show(); }
		else
		{ $('span#asvab_new_exists').hide(); }
	});

	$('a.tooltip').click(function()
	{
		tip = $(this).attr('id');
		if ($('#tool' + tip).css('display') == 'none')
		{ $('span.tooltip').hide(); $('#tool' + tip).show(); }
		else
		{ $('span.tooltip').hide(); }
		return false;
	});
	
	$('input#school.textfield, input#topic_title.textfield, input#rrnco_name.textfield, input#host_educator.textfield').change(function()
	{
		if ($(this).val().length > 50)
		{
			alert('You can only enter 50 characters');
		}
		while ($(this).val().length > 50) {
			$(this).val($(this).val().replace(/(\s+)?.$/, ""));
		}
	});

	$('#new-topic-btn').click(function()
	{
		$(this).hide();
		$('#new-topic').show();
		return false;
	});

});

