/*
  The file is part of the mod_calendar, needed for the ajax support
  Copyright: (C) 2006-2007 Sven Kauber. All rights reserved.
  License: http://www.gnu.org/copyleft/gpl.html GNU/GPL
  Depends on: calendar_ajax.js
*/


function do_ajax(request,target){
    var ao = new AjaxObject101(); 
    ao.sndReq('post','index2.php?option=com_ab_calendar_ajax&no_html=1',request+'&target='+target);
}


function get_item(params,item){
  /*
    finds an item's value from params
    params is like this: http://yoururl.com/index.php?option=com_contact&month=1&year=2007
  */

  var result = false;
  var item_found = false;
  var params_line = params.split(item)[1];
  var result = params_line.split('=')[1].split('&')[0];  
  return result;
}


function get_month(params,target,link){
  /*
    params has the parameters in this way: option=com_contact&Itemid=28&month=11&year=2006
    this is fed to the ajax function
    target is the target td for calendar, this will be renewed
    months_forward and months_backward are the counters that are incremented each time a month is clicked forward or backward
  */

  var month = get_item(params,'month');
  var year = get_item(params,'year');

  if(month && year){ 
    var post_string = 'month='+month+'&year='+year+'&act=browse_months';
    do_ajax(post_string,target);
  } else 
    return false;
}


function get_day(params,target){
  /*
    Gets the day from html part and then calls the ajax file to update
    the content area with the texts from that day 
    params can contain the link, so it will also have the day,month,year
    target has the id of the div that is to be updated with the content from the Ajax request
  */
  var month = get_item(params,'month');
  var year = get_item(params,'year');
  var day = get_item(params,'day');

  if(month && day && year){
    post_string = 'day='+day+'&month='+month+'&year='+year+'&act=show_day';
    do_ajax(post_string,target);
  } else 
    return false;
}

