/*****************************************************************************
ajax08.js
  getMethod('url',['params','fnct','obj']);
	params:		'name=val1&name2=val2&etc';
	func:		function name. If this function is included in
				an object you MUST include the obj name.
				Optionally use obj.fnct, skipping obj (new version)

  postMethod('url',['df','fnct','obj']);
	df:         form to post.
	func:		function name. If this function is included in
				an object you MUST include the obj name.
				Optionally use obj.fnct, skipping obj (new version)

  function <fnct>(recvd) {...}
	This function MUST be added to process the asynchronous Ajax return.
	The function name defaults to response();

 Possible m$ objects: var activex_ids = ['MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
*****************************************************************************/
var Ajax = ({
	busy: false,
	xmlObj: (typeof window.ActiveXObject != 'undefined') ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(),


	getMethod: function(url,params,fnct,obj) {
		if (Ajax.busy) { return; }
		Ajax.busy = true; 
		if (!fnct) { fnct = 'response'; }
		if (/\./.test(fnct)) {
			obj = fnct.split('.')[0];
			fnct = fnct.split('.')[1];
		}
		Ajax.xmlObj.open("GET", url+'?'+params, true);
		Ajax.xmlObj.onreadystatechange=function() {
			if (Ajax.xmlObj.readyState==4) {
				Ajax.busy = false;
				(obj) ? window[obj][fnct](Ajax.xmlObj.responseText) : window[fnct](Ajax.xmlObj.responseText);
			}
		}
		Ajax.xmlObj.send(null);
	},

	postMethod: function(url, df, fnct, obj) {
		if (Ajax.busy) return;
		var params = '';
		for (var i=0; i<df.length; i++) {			// build a param list
 			if (df[i].name) {						// need to deal with radio ?
				if (params) { params += '&' }
				params += df[i].name+'='+df[i].value;
			}
		}
		Ajax.busy = true;  
		if (!fnct) { fnct = 'response'; }
		if (/\./.test(fnct)) {
			obj = fnct.split('.')[0];
			fnct = fnct.split('.')[1];
		}
		Ajax.xmlObj.open("POST", url, true);
		Ajax.xmlObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		Ajax.xmlObj.setRequestHeader("Content-length", params.length);
		Ajax.xmlObj.setRequestHeader("Connection", "close");
		Ajax.xmlObj.onreadystatechange=function() {
			if (Ajax.xmlObj.readyState==4) {
				Ajax.busy = false; 
				(obj) ? window[obj][fnct](Ajax.xmlObj.responseText) : window[fnct](Ajax.xmlObj.responseText);
			}
		}
		Ajax.xmlObj.send(params);
	}
});