function listRecipeCatsUpdate(parentCatId, completeFunction, catId) {
  var pars = 'CoMeT_function=run_module&module=ModRecipes&function=list_recipe_categories&action=list_recipe_categories_update&cat_id=' + parentCatId;

  new Ajax.Request('?',
  {
    method: 'post',
    postBody: pars,
    encoding: 'ISO-8859-1',
    onComplete: function(resp) {
      if(completeFunction) {
        $('recipes_nav').innerHTML = resp.responseText;
        completeFunction(parentCatId, catId);
      } else {
        if (resp.status == 200) {
          $('recipes_nav').innerHTML = resp.responseText;
        }
      }
    }
  });
}

function updateRecipesList(parent_cat_id) {

  var pars = 'CoMeT_function=run_module&module=ModRecipes&function=list_recipes&action=update_recipes_list&parent_cat_id=' + parent_cat_id;

  new Ajax.Request('?',
  {
    method: 'post',
    postBody: pars,
    encoding: 'ISO-8859-1',
    onComplete: function(resp) {
      if (resp.status == 200) {
        $('recipes').innerHTML = resp.responseText;
      }
    }
  });
}

function catUpdateRecipesList(parent_cat_id) {

  var pars = 'CoMeT_function=run_module&module=ModRecipes&function=list_recipes&action=cat_update_recipes_list&parent_cat_id=' + parent_cat_id;

  new Ajax.Request('?',
  {
    method: 'post',
    postBody: pars,
    encoding: 'ISO-8859-1',
    onComplete: function(resp) {
      if (resp.status == 200) {
        $('recipes').innerHTML = resp.responseText;
      }
    }
  });
}



function listRecipesSubCategoriesUpdate(cat_id, parent_cat_id) {
  //alert('parent_cat_id: ' + parent_cat_id + ', cat_id: ' + cat_id);
  var pars = 'CoMeT_function=run_module&module=ModRecipes&function=list_recipe_categories&action=list_recipe_sub_categories_update&cat_id=' + cat_id + '&parent_cat_id=' + parent_cat_id;

  new Ajax.Request('?',
  {
    method: 'post',
    postBody: pars,
    encoding: 'ISO-8859-1',
    onComplete: function(resp) {
      if (resp.status == 200) {
        $('subcats_' + parent_cat_id).innerHTML = resp.responseText;
      }
    }
  });
}



function listRecipesUpdate(cat_id, parent_id) {

  var pars = 'CoMeT_function=run_module&module=ModRecipes&function=list_recipes&action=list_recipes_update&cat_id=' + cat_id;

  new Ajax.Request('?',
  {
    method: 'post',
    postBody: pars,
    encoding: 'ISO-8859-1',
    onComplete: function(resp) {
      if (resp.status == 200) {
        $('recipes').innerHTML = resp.responseText;
      }
    }
  });
}

function renderRecipe(recipe_id) {
  var pars = 'CoMeT_function=run_module&module=ModRecipes&function=list_recipes&action=render_recipe&recipe_id=' + recipe_id;

  new Ajax.Request('?',
  {
    method: 'post',
    postBody: pars,
    encoding: 'ISO-8859-1',
    onComplete: function(resp) {
      if (resp.status == 200) {
        $('recipes').innerHTML = resp.responseText;
      }
    }
  });
}



function rrListReipeCatsUpdate(parentCatId, catId) {

  $('#recipes').fadeOut('fast');

  listRecipeCatsUpdate(parentCatId, completeFunction, catId); //update menu

}

function completeFunction(parentCatId, catId) {

  updateRecipeMenu(parentCatId, catId);
  updateRecipeList(catId);

}

function updateRecipeMenu(parentCatId, catId) {
  //alert(parentCatId + '|' + catId);
  $('#subcats_' + parentCatId).children('ul').children('li').children('a').removeClass('current');
  $('#subcats_' + parentCatId).children('ul').children('#subcat_' + catId).children('a').addClass('current');
}

function updateRecipeList(catId) {
  //update recipes list
  doAjaxRequest('CoMeT_function=run_module&module=ModRecipes&function=list_recipes&action=update_recipes_from_path&cat_id=' + catId, '#recipes', rrListReipeCatsUpdateResponse);
}

function rrListReipeCatsUpdateResponse(html) {

	$('#recipes').html(html);
  $('#recipes').fadeIn('slow');
}

