/* ~~~~ kookschrift.js ~~~~ */


/*
 * Dropdowns in search results lists:
 */

gFilterTimeoutHandle = false;

function filterPoll(selectBox)
{
  if (gFilterTimeoutHandle) clearTimeout(gFilterTimeoutHandle)
  gFilterTimeoutHandle = setTimeout(doFilter, 700)
}


function doFilter()
{
  var node = document.getElementById('filter')
  if (node) node.submit()
  gFilterTimeoutHandle = false;
}


/*
 * Enhanced alert dialog after (adding) a recipe to the cookbook:
 * - with links back to recipe and recipe subhome
 * - with 'close' button instead of 'ok'
 */
function createflowconfirm (msg, title) {
    var dialog = new AHDialog();
    if (title) {
      dialog.addTitle(title);
    } else {
      dialog.addTitle("Recept toegevoegd");
    }
    dialog.setText(msg);
    dialog.addDestroyer('Sluiten');
    dialog.build();
}

/*
Refine cookbook pages
Set the primary div as large as the cookbookwrapperbackground
*/
function refineCookbookPage() {
  var cookbookWrapper = $("body.size_xl div#cookbook_wrapper");
  if (cookbookWrapper.size()==0) return;
  var primary = $("#primary")[0];
  if (cookbookWrapper && primary && ua.ie6) {
    primary.style.height = cookbookWrapper.height() + "px";
  } else if (cookbookWrapper && primary) {
    primary.style.minHeight = cookbookWrapper.height() + "px";
  }
}


// Add delete confirms to the X buttons.
function setupRecipeDeleteConfirm () {
  var nl = $('.recipe_delete');
  nl.each( function (i,elm) {
    $(elm).bind('click', function (evt) {
      var d = new AHDialog();
      d.addText('Weet u zeker dat u dit recept wilt verwijderen?');
      d.addAction('Ja', function (e) {
          location.href = elm.href;
          return false;
        });
      d.addDestroyer('Nee');
      d.build();
      return false;
    });
  });
}


/* DOM enhancements only applicable for recipepages */
if (loader) {
  // the confirm needs to be loaded early on,
  // otherwise you can delete without confirm before
  // all the init's are handled.
  loader.schedule('setupRecipeDeleteConfirm',
    setupRecipeDeleteConfirm, Loader.priority.NORMAL);
  loader.schedule("Setting up cornered and dotted boxes", function() {
    // set up dotted borders in IE6
    DottedBox.setup($("ul#own_rec_list li"));
    DottedBox.setup($("ul#own_rec_list_ah li"));
    DottedBox.setup($("div#rc_top li"));
    DottedBox.setup($("div#rc_new li"));
  });
  loader.schedule("refineCookbookPage", refineCookbookPage);
}



/* ~~~~ kookschrift.js ~~~~ */
// vim: set ts=2 sw=2 expandtab

