if (typeof QQ === "undefined") {
  var QQ = {};
} 
QQ.Ajax = function(){
  
  return {
  	// load contents from path into div
		update: function (path,divID,settings){
			var addresponse;
			if (settings !== undefined) addresponse = settings.additionalResponseFunction; else settings = {};
			function response(req){
				if (obj(divID) != null){
				  obj(divID).innerHTML = req.responseText;
				}else alert(divID+"not found");
				if (addresponse !== undefined) addresponse();
			}
			settings.responseFunction = response;
			this.request(path,settings);			
		},
  	request: function (path,settings){
			
			if (settings === undefined) settings = {}
			
			var method = settings.method;
			var data = settings.data;
			var responseFunction = settings.responseFunction;
			var asynchronous = settings.asynchronous;
			var progressCallback = settings.progressCallback;
			
			// handle defaults
			if (method === undefined) method = "get";
			if (data === undefined) data = "";
			if (asynchronous === undefined) asynchronous = true;
	
			// keep req global or pass it to response function
			var req = this.getRequestObject();	
			
			if (progressCallback !== undefined)	req.onprogress = progressCallback;
			if (data == undefined) data = "";
			if (method == undefined) method = "get";
			
			if (method == "get") req.open("get", path+data, asynchronous);
			else req.open("post", path, asynchronous);
			
			//if (responseFunction != undefined) req.onreadystatechange = responseFunction;
			req.onreadystatechange = function() {
				if (req.readyState == 4 && responseFunction !== undefined) responseFunction(req);
			}
			
			if (method == "get") req.send(null);
			else {
				req.setRequestHeader("Pragma", "no-cache");
				req.setRequestHeader("Cache-Control", "must-revalidate");
				req.setRequestHeader("If-Modified-Since", document.lastModified);			
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
				req.setRequestHeader("Content-length", data.length);
				req.send(data);	
			}
		},
		getRequestObject: function(){
			var req = null;
			try {
				req = new XMLHttpRequest();
			}catch (ms){
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (nonms) {
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (failed) {
						req = null;
					}
				}  
			}
			return req;
		}
  };
}();