























































function http_simple(url, options) {
	options = options||{};
  options.args = options.args || {};

	// Convert the args to a POST string
	var post_content = "";
	for(var i in options.args) {
		if(options.args[i] === undefined) continue;
		if(options.args[i] instanceof Array) {
			for(var j=0; j<options.args[i].length; j++)
        
				post_content += i + "=" + encodeURIComponent(options.args[i][j]) + ";";
		} else {
			post_content += i + "=" + encodeURIComponent(options.args[i]) + ";";
		}
	}

	// Allocate the object
	var xmlhttp_o;
	if(broken_windows_browser) {
		xmlhttp_o = new ActiveXObject("MsXml2.XmlHttp");
	} else {
		xmlhttp_o = new XMLHttpRequest();
	}
  var detect_success = options.detectSuccess || function() {return true};
  var on_success = options.onSuccess || function() {return true};
  var on_failure = options.onFailure || function() {return false};
  var http_error_handling = options.httpErrorHandling || "both";
  var return_type = options.returnType || "xml";
  var method = post_content ? "post" : "get";

	var on_load_fired = false;
	function on_load() {
		on_load_fired = true;
		if(xmlhttp_o.status == 200) { 
      if(return_type == "text") {

        if(detect_success(xmlhttp_o.responseText))
          on_success(xmlhttp_o.responseText);
        else
          on_failure(xmlhttp_o.responseText);

      } else {

        var xmldoc=xmlhttp_o.responseXML;
        if(!xmldoc)
          on_failure();
        else if(!xmldoc.lastChild)
          on_failure(xmldoc.lastChild);
        else if(detect_success(xmldoc.lastChild))
          on_success(xmldoc.lastChild);
        else
          on_failure(xmldoc.lastChild);

      }
		} else if(xmlhttp_o.status && http_error_handling != "none") {
      if(! ( http_error_handling == "fail" && options.onFailure ) ) {
        alert_l("HTTP error: " + xmlhttp_o.status);
      }
      on_failure();
		}
	}
  var partial_load_failed = false;
	xmlhttp_o.onreadystatechange = function() {
		// if LOADED
		if(xmlhttp_o.readyState == 4) {
      // MSIE has to catch up here.
      if(partial_load_failed && options.onPartialLoad) options.onPartialLoad(xmlhttp_o.responseText);
      on_load();
    }
    // if partly loaded
		if(options.onPartialLoad && xmlhttp_o.readyState == 3 && ! partial_load_failed) {
      try {
        options.onPartialLoad(xmlhttp_o.responseText);
      } catch(e) {
        // Do nothing - MSIE will just have to wait.
        partial_load_failed = true;
      }
    }
	};
  if(method == "get") {
    xmlhttp_o.open("GET", url+"?"+post_content, options.sync ? false : true);
    xmlhttp_o.send();
  } else {
    xmlhttp_o.open("POST", url, options.sync ? false : true);
    xmlhttp_o.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    if(!navigator.userAgent.match(/AppleWebKit/)) {
      // WebKit hates this, but some other browsers may need it.
      xmlhttp_o.setRequestHeader("Content-length", post_content.length);
      xmlhttp_o.setRequestHeader("Connection", "close");
    }
    xmlhttp_o.send(post_content);
  }
	if(options.sync && ! on_load_fired) on_load();
	return xmlhttp_o;
}

