var xhttp;
var banner_count = 0;
var exclude = new Array();

function createXMLHttpRequest() { 
  if (window.ActiveXObject) {  
    try {  
      // IE 6 and higher 
      xhttp = new ActiveXObject("MSXML2.XMLHTTP"); 
    } catch (e) { 
      try { 
        // IE 5 
        xhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
      } catch (e) { 
        xhttp=false; 
      } 
    } 
  } 
  else if (window.XMLHttpRequest) { 
    try { 
      // Mozilla, Opera, Safari ... 
      xhttp = new XMLHttpRequest(); 
    } catch (e) { 
      xhttp=false; 
    } 
  } 
}  

function sendRequest(param) { 
  if (!xhttp) {
    createXMLHttpRequest();
    if (!xhttp) {
      alert("An Error occured when trying to initialize XMLHttpRequest!"); 
      return; // exit 
    }
  }
  if (!param) param = null; 

  xhttp.open("POST", "/addons/banner/ajax_banner.php", true);
  xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhttp.onreadystatechange=sendRequest_callback; 
  xhttp.send(param); 
}  

function sendRequest_callback() { 
  if (xhttp.readyState == 4 && xhttp.status == 200) {
    if (!xhttp.responseText) alert('nothing to do');
    else eval(xhttp.responseText); 
  }
}

function bb_fill() {
  var bb_container_width = document.getElementById('bb_container').offsetWidth;
  var bb_table_width = document.getElementById('bb_table').offsetWidth;
  var bb_banner_width = banner_count ? (bb_table_width / banner_count) : bb_table_width;
  if ((bb_table_width + bb_banner_width) <= bb_container_width) sendRequest(exclude.join('&'));
  else bb_finish();
}

function bb_finish() {
  document.getElementById('bb_table').style.width = '100%';
  document.getElementById('bb_table').style.visibility = 'visible';
}
