$(function() {
	
	/************* Report a Problem *****************/
	$('a#report_link').click(function(e)
	{
		e.preventDefault();
		$('p.err').text('');
		$('#fname').val('');
		$('textarea[name=problem_desc]').val('');
		$('textarea[name=problem_steps]').val('');
		$('#email').val('');
		$('div#report_form').dialog({modal: true, width: 600});
	});
	
	$('a.close_dialog').click(function(e)
	{
		e.preventDefault();
		$(this).parent().dialog('close');
	});
	
	$('select.comment_option').change(function()
	{
		//alert( $(this).val() );
		if( $(this).val() == "Comments and Ideas")
		{
			$('li.comments_box').slideDown();
			$('li.problem_box').slideUp();
		}
		else
		{
			$('li.comments_box').slideUp();
			$('li.problem_box').slideDown();
		}
	});
	
	$('input#submit_problem').click(function(e)
	{
		e.preventDefault();
		var fname = encodeURIComponent($('input#fname').val());
		var pr_desc = encodeURIComponent($('#problem_desc').val());
		var email = encodeURIComponent($('input#email').val());
		var pr_type = encodeURIComponent($('#problem_type').val());
		var pr_steps = encodeURIComponent($('#problem_steps').val());
		var chan_num = 0;
		
		if($('input#chan_num').length) {
			chan_num = $('input#chan_num').val();
		}
		
		if(email == "")
		{
			$('p.err').slideDown('slow').html('Your email address is required.');
		}
		else if(pr_desc == "")
		{
			$('p.err').slideDown('slow').html('Description is required.');
		}
		else
		{
			var link = "fname="+fname+"&pr_desc="+pr_desc+"&email="+email+"&pr_type="+pr_type+"&pr_steps="+pr_steps+"&chan_num="+chan_num;
			$.ajax({
				url: '/library/ajax_calls.php',
				data: 'task=submit_problem&'+link,
				type: 'POST',
				success: function(data) 
				{
				  $('div#report_form p.err').slideDown('slow').html('Message has been successfully sent.');
				  $('input#fname, #problem_desc, #problem_steps').val('');
				  var d_timeout = setTimeout('close_dialog()', 2000);
				}
			});
		}
	});
});

function close_dialog()
{
	$('a.close_dialog').trigger('click');
}

