// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Ajax call to remove a task
function DeleteTaskHandler(task_id, is_recurring)
{
 if (confirm('Are you sure to remove this task?')) 
	 {
	 del_recurring = 'false';
	 if (is_recurring && confirm('This is a recurring task.\n\nDo you want to also delete all other instances of this one?\n\nClick "OK" to delete all instances. \nClick "Cancel" to delete this task only.'))
		 {
			del_recurring = 'true';
		 }
	  new Ajax.Request('/task/remove/'+task_id, {parameters:'&del_recurring='+del_recurring, asynchronous:true, evalScripts:true}); 
	 }; 

  return false;
}

// Subgoal toggle handler functions
function toggleSubgoals(goal_id)
{
  sg_visible = $('subgoals_'+goal_id).visible();
  $('icon_expand_'+goal_id).src = sg_visible  ? '/images/icon_expand.gif':'/images/icon_collapse.gif'; 
  Effect.toggle('subgoals_'+goal_id, 'appear', { duration: 0.1 }); 

  exp_date = new Date();
  exp_date.setTime(exp_date.getTime()+(365*24*3600*1000));

  visible = sg_visible ? "false" : "true";

  document.cookie = "subgoals_visible_"+ goal_id + "="+visible+"; expires="+exp_date.toGMTString()+"; path=/" ;

  return false;
	  
}

