  var dp_count = 0;
  function ajaxDayPlanner(action, type, id, sid, subtype, exbtnid, ob)
  {
   var tickbox = ob;
   var request_uri = '/siteapp/ajax/' + exbtnid + ';dayplanner?action=' + action + '&type=' + type + '&sid=' + sid + '&item_id=' + id + '&subtype=' + subtype;

   //jQuery('#ajax_'+id+' td.ajaxme').effect('highlight', {color:'#0000ff'} , 1000);
   jQuery('#ajax_'+id+' td.ajaxme').addClass('processing');

   jQuery('#followmouse').show(); // Show the 'updating day planner' div that follows the mouse
   // Set the curosr style to the hourglass
   document.body.style.cursor = 'wait';
   //$('input').each(function(e){e.style.cursor='wait'});
   // Track how many times we have been called. Then we know when reset the hourglass and hide the 'update day planner' div.
   dp_count++;

   jQuery.ajax({
     type     : "GET",
     url      : request_uri,
     success  : function(msg){handle_valid_response(tickbox, msg)},
     error    : function(msg){alert('AJAX request failed '+msg)},
     complete : function(ob){handle_end_ajax(ob)}
    });
  }

  function handle_end_ajax(ob)
  {
   dp_count--;
   if( !dp_count ) reset_ajax_feedback();
  }

  function handle_valid_response(tickbox, msg)
  {
   if( msg.match(/OK/) ) {
    var exbtr_id = msg.substr(3);
    if( exbtr_id && exbtr_id > 0 ){
     jQuery('#ajax_'+exbtr_id+' td.ajaxme').removeClass('processing');

     if(jQuery('#ajax_'+exbtr_id).is('.chosen')){
      jQuery('#ajax_'+exbtr_id).removeClass('chosen').addClass('unchosen');
      jQuery('#ajax_'+exbtr_id+' td').removeClass('chosen').addClass('unchosen');
     }
     else {
      jQuery('#ajax_'+exbtr_id).removeClass('unchosen').addClass('chosen');
      jQuery('#ajax_'+exbtr_id+' td').removeClass('unchosen').addClass('chosen');
     }

    }
    // Nothing to do.. ?
   }
   else {
    undo_click(tickbox);
    var is_error = msg.substr(0,6);
    var err_mess = msg.substr(6);
    if( is_error == 'ERROR|' ){
     alert('Error updating: '+err_mess);
    }
    else {
     alert('Day Planner update failed.');
    }
   }
  }

  function reset_ajax_feedback()
  {
   document.body.style.cursor = 'auto';
   //$$('input').each(function(e){e.style.cursor='auto'});
   jQuery('#followmouse').hide();
  }
  

 function undo_click(ob)
 {
  ob.checked = ob.checked ? false : true;
 }

 function dp( ob, type, sid, id, subtype, exbtnid )
 {
  //alert(ob + ':' + type + ':' + sid + ':' + id + ':' + subtype + ':' + exbtnid);
  var action = 'del';
  if( ob.checked )
   action = 'add';
  var dpaction = ajaxDayPlanner(action, type, id, sid, subtype, exbtnid, ob);
  return;
 }

