/**
* xhr by Fabian Grutschus a.k.a crash
*
* Example:
* function callback_function(xhrObject, parameter1, parameter2) { ... }
* xhr('get', 'file.html', 'foo=bar&bar=foo', callback_function, [parameter1, parameter2]);
* @param string Method [get/post]
* @param string URL
* @param string data
* @param string Callback-function (optional)
* @param array Callback-function parameters (optional)
* @return nodelist The elements with the specified class name
*/


/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/
function xhr(method, url, data, cb, apply_para) {
  method = method.toLowerCase();
  var req;
  req = new XMLHttpRequest();
  if(!req) { return false; }
  req.open(method, url + (data && method == 'get' ? '?' + data : ''), true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  if (method == 'post') {
      req.setRequestHeader("Method", "POST " + url + " HTTP/1.1");
      req.setRequestHeader("Content-Length", data.length);
  }
  req.onreadystatechange = function() {
      if (req.readyState == 4 && req.status == 200) {
              if (cb) {
              cb.apply(null, [req].concat(apply_para));
          }
      }
  }
  req.send(data);
  return true;
} 
