/**
 * AJAX code to reload boxes
 */

var box1_div, box_sid;
var req; 
var cur_box;
var box_run = 0;


function mainboxes_change(box1, sid)
{
  mainboxes_init(box1, sid);

  setTimeout("mainboxes_fetch()", 5000);
}


/**
 * send request
 */
function mainboxes_fetch()
{
  cur_box = box1_div;
  box_run++;

  if( box_run < 30 )
  {
    //req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');    // needed in case of POST (not GET) only
    req.open('GET','http://www.dud.de/mainboxes_change.php?run=' + box_run + '&sid=' +  box_sid, true);
    req.onreadystatechange = process_mb;   // call it AFTER open() to make it work in f**king IE
    req.send(null);

    setTimeout("mainboxes_fetch()", 10000);
  }
}


/**
 * handle response
 */
function process_mb()
{
  if( req.readyState == 4 )   // XHR-state 'complete'
  {
    if( req.status == 200 )   // want HTTP status code 'OK' only
    {
      cur_box.innerHTML = req.responseText;
      fade_in(0, cur_box.id);    
    }  
    //else
    //  alert("There was a problem retrieving the XML data:\n" + req.statusText);
  }
}



/**
 * init funcs
 */
function mainboxes_init(box1, sid)
{
  if( typeof box1_div == 'undefined' )      
    box1_div = document.getElementById(box1);
  if( typeof box_sid == 'undefined' )      
    box_sid = sid;
  if( typeof req == 'undefined' )      
    req = createXMLHttpRequest();
}

function createXMLHttpRequest()
{
  var myreq = null;

  if( window.XMLHttpRequest )      // Mozilla, Safari, ...
    myreq = new XMLHttpRequest();
  else if( window.ActiveXObject )  // IE
    myreq = new ActiveXObject("Microsoft.XMLHTTP");

/*  var req = null;
  try 
  {
    req = new ActiveXObject("MSXML2.XMLHTTP");
  }
  catch( err_MSXML2 )
  {
    try
    {
      req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch( err_Microsoft )
    {
      if( typeof XMLHttpRequest != "undefined" ) 
        req = new XMLHttpRequest;
    }
  } */

  return myreq;
}




