var xmlHttp = getXmlHttpObject( );

if( !window.event ) {
  /**
   * firefox => not ie
   * initialisiere event-manager :: wird im ie bereits automatisch geladen, im ff muss dass jedoch haendisch geschehen
   *
   */
  var xcoord = ycoord = 0;

  function getCoords(e) {
    xcoord = e.clientX;
    ycoord = e.clientY;
  }
}

/**
 * lade kalender nach
 *
 */
function getCalendar( ) {
  if( xmlHttp == null ) {
    document.getElementById( 'dWidgetCalendar' ).innerHTML = "Ihr Browser unterstützt kein AJAX.";
    return;
  }
  var url = "./inc_ajax/widget.calendar.php";
  if( arguments.length>0 ) {
    url += '?' + arguments[0];
  }
  xmlHttp.onreadystatechange = handle_getCalendar;
  xmlHttp.open( "GET", url, true );
  xmlHttp.send( null );
}

/**
 * handler fuer nachladen des kalanders
 *
 */
function handle_getCalendar( ) {
  if( xmlHttp.readyState == 4 ) {
    if( xmlHttp.status == 200 ) {
      document.getElementById( 'dWidgetCalendar' ).innerHTML = xmlHttp.responseText;
    }
  }
}

/**
 * hole termine u.a. fuer bestimmtes datum und positioniere div entsprechend
 *
 */
function getEvents( y, m, d )
{
  if( xmlHttp == null ) { return; }

  var url = "./../jax_calendar/modules/ajax.eventlist.inc.php";
  url += '?Y=' + y;
  url += '&m=' + m;
  url += '&d=' + d;
  url += '&cal_id=0&language=german&gmt_ofs=-1&view=d1';
  xmlHttp.onreadystatechange = handle_getEvents;
  xmlHttp.open( "GET", url, true );
  xmlHttp.send( null );

  document.getElementById( 'dCalEventTooltip' ).style.display = 'inline';
  document.getElementById( 'dCalEventTooltip' ).innerHTML = '<p >Termine werden geladen ..</p>';

  if( window.event ) {
    // IE
    document.getElementById( 'dCalEventTooltip' ).style.top = window.event.y + document.body.scrollTop + 15;
  }
  else {
    // FF
    var iTopOffset = window.pageYOffset + ycoord;
    document.getElementById( 'dCalEventTooltip' ).style.top = iTopOffset + 'px';
  }
}

/**
 * handler terminliste
 *
 */
function handle_getEvents( )
{
  if( xmlHttp.readyState == 4 ) {
    if( xmlHttp.status == 200 ) {
      document.getElementById( 'dCalEventTooltip' ).innerHTML = xmlHttp.responseText;
      document.getElementById( 'the_content' ).style.width = 400;
      if( document.getElementById( 'the_content' ).style.width!='400px') { document.getElementById( 'the_content' ).style.width = '400px'; }
    }
  }
}

/**
 * verstecke terminliste des kalenders
 *
 */
function hideEventlist( )
{
  document.getElementById( 'dCalEventTooltip' ).style.display = 'none';
}

/*************************************************************************************
 * kern-funktionen AJAX
 ************************************************************************************/

/**
 * initialisiere AJAX bzw dessen Request-Objekt
 *
 */
function getXmlHttpObject( )
{
  var xmlHttp = null;
  try {
    xmlHttp = new XMLHttpRequest( );
  }
  catch( e ) {
    try {
      xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
    }
    catch( e ) {
      xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
  }
  return xmlHttp;
}