var m_req = null;
var m_url;
var m_method;
var m_id;
var m_load_id;

function FreaksAjax_XMLHttpRequest(url, method, id)
{
  m_url = url;
  m_method = method;
  m_id = id;
  m_load_id = 'load_' + id;

  if (m_req != null && m_req.readyState != 0 && m_req.readyState != 4)
  {
    m_req.abort();
  }

  try
  {
    m_req = new XMLHttpRequest();
  }
  catch (error)
  {
    try
    {
      m_req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (error)
    {
      m_req = null;

      return false;
    }
  } 

  m_req.onreadystatechange = FreaksAjax_processReqChange;
  m_req.open("GET", m_url, true);
  m_req.send(null);
}

function FreaksAjax_toggle_on()
{
  if ($(m_load_id) != undefined && $(m_load_id) != null)
  {
    if ($(m_load_id).style.display == "none")
    {
      $(m_load_id).style.display = "";
    }
  }
}

function FreaksAjax_toggle_off()
{
  if ($(m_load_id) != undefined && $(m_load_id) != null)
  {
    if ($(m_load_id).style.display == "")
    {
      $(m_load_id).style.display = "none";
    }
  }
}

function FreaksAjax_processReqChange() 
{
  FreaksAjax_toggle_on();
  
  if (m_req.readyState == 4) 
  {
    // only if "200 OK"
    if (m_req.status == 200) 
    {
      responseText = m_req.responseText;
      m_method( m_id, responseText );
      
      FreaksAjax_toggle_off();
    }
  }
}

