/* submit data to filter */
var do_select;
function saveparticipants(ajax_filter_url, select)
{
	// for each checkbox
	var formfields = new Object();
	
	$("#participants input[type=text]").each(function()
	{	
		formfields[this.name] = this.value;
	});
	
	/* for each hidden form field */
	$("#participants input[type=hidden]").each(function()
	{
		formfields[this.name] = this.value;
	});
	$("#participants textarea").each(function()
	{
		formfields[this.name] = this.value;
	});
	$("#participants select").each(function()
	{
		formfields[this.name] = this.value;
	});
	
	$("#participants input[type=checkbox]").each(function()
	{
		if  ( this.name == 'signupdata[signup][newsletter]' )
		{
			if ( this.checked )
			{
				formfields[this.name]=this.value;
			}
		}
		else
		{
			if(this.checked)
			{
				formfields[this.name] = '1';
			}
			else
			{
				formfields[this.name] = '0';
			}
		}
	});
	
	do_select = select;
	$.ajax({
	  type: 'post', 
	  url: ajax_filter_url,
	  data: formfields,
	  success: handleFilterResponseCourse
	});
	
}
function deleteparticipant( url )
{
	$.ajax({
		  type: 'post', 
		  url: url,
		  success: handleFilterResponseCourse
		});
}

/* handle filter response */
function handleFilterResponseCourse(data)
{
	$('#participants_list').html(data);
	if ( do_select )
	{
		setTimeout("document.getElementById(do_select).focus()", 100 );
	}
	var length = $('#deltakere').height();
	$('#deltakere').animate({scrollTop: 2000}, 1000);
	
}
$(document).ready(function () {
	   $("form#company").submit(function() {   
			   if (!$('#check-box-2').attr('checked'))
			   {
				   jAlert( $( "#forgot_condition" ).html(), $( "#forgot_condition_heading" ).html());
				   return false;
			   }
		});
	   
	   $("span#cancel_link").live("click", function(){
		   $.alerts.okButton = $( "#cancel_ok_button" ).html();
		   $.alerts.cancelButton = $( "#cancel_cancel_button" ).html();
		   jConfirm( $( "#cancel_dialog" ).html(), $( "#cancel_heading" ).html(), function(r) {
			    if ( r )
			    {
			    	window.location.href = $("#cancel_link").attr("title");
			    }
			});
	   });
	

	
	   
	   /* list for clicks on the newsletter signup */
	 /*  $("#newsletter").click(function() {
		   if(this.checked)
		   {
			   $("#newsletter-categories").css("display", "block");
			   $("#newsletter-categories").show('blind');
		   }
		   else
		   {
			   $("#newsletter-categories").hide('blind');
		   }
	   });
	   
	   
		*/
	   $("#newsletter").live("click", function(){
			if(this.checked)
			   {
				   $("#newsletter-categories").css("display", "block");
				   $("#newsletter-categories").show('blind');
			   }
			   else
			   {
				   $("#newsletter-categories").hide('blind');
			   }
		});
	   $("#newsletter-categories").hide();
	   

});

