if (typeof cUdf == 'undefined') var cUdf = 'undefined';
function createXMLHttp() {
	if (typeof XMLHttpRequest != cUdf) return new XMLHttpRequest();
	else if (window.ActiveXObject)  {
		var aVersions = ['MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp', 'Microsoft.XMLHttp'];
		for (var i=0; i<aVersions.length; i++) {
			try {
				return new ActiveXObject(aVersions[i]);
			} catch (oError) {}
		}
	}
	throw new Error('XMLRequest object could not be created.');
	return null;
}
function cCancelRequest(XMLobj) {
	if (XMLobj) XMLobj.abort();
}
/* 
	Type => 		Request type - POST or GET
	aStateChng => Function which handles state changes, specify NULL if there is none
					
					This function should be written to accept a single input parameter, the XMLhttp object.
	
	aUrl => 		the server program name that will return data.
	aQry => 		the Query string, either a semi-colon separated list of name=value pairs or a simple
					XML-encoded string.
					
					On a GET request if the aUrl parameter already contains a Query string value,
					this value is set to null else it will be appended to the aUrl value.
	
	aSynch =>   If true, then request is done asynchronously otherwise it is done synchronously, i.e.,
					it waits for the response before going on.
					
	aExtraArguments => Extra arguments to be passed to the function 'aStateChang', if this is an
							 array then it must be passed in array notation and the function defined by
							 'aStateChang' must handle it properly.
					
	Function returns the XMLRequest object created so that a user may have more than one at a
	time open.
*/ 
function cAjax(Type,aStateChng,aUrl,aQry,aSynch) {
	var cHttp=null,i,eMsg='',cArgs=new Array(),j=0;
	Type = (!Type) ? 'GET' : Type;
	aSynch = (typeof aSynch == 'object' && !aSynch) ? true : aSynch;
	if (!/get|post/i.test(Type)) throw new Error('The cAjax function only handles GET or POST types of requests.');
	if (aStateChng && typeof aStateChng != 'function') throw new Error('The aStateChng argument to cAjax must be a function reference.');
	if (Type=='GET') {
		if (/^\?/.test(aQry)) aQry = aQry.replace(/^\?/,'');
		aQry += '&amp;ts=' + new Date().getTime();
		aUrl += 	(!/\?/.test(aUrl) ? '?' : '&amp;') + aQry; 
		aQry=null;
	}
	if (cHttp = new createXMLHttp()) {
		try {
			cHttp.open(Type,aUrl,aSynch);
			if (aQry && Type == 'POST') cHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			if (aSynch) {
				if (cAjax.arguments.length <= 5) cHttp.onreadystatechange = function () { aStateChng(cHttp); }
				else {
					for (var k=5; k < cAjax.arguments.length; k++) cArgs[j++] = cAjax.arguments[k];
					cHttp.onreadystatechange = function () { aStateChng(cHttp,cArgs); }
				}
			}
			cHttp.send(aQry);
			return cHttp;
		} catch (e) {
			throw new Error(Type + ' - Cross-domain access not permitted!');
		}
	}
}
/* 
	aRequest => Head request required
					
	aUrl => 		the server file that information is needed for.
*/ 
function cHeadContent(aRequest, aUrl) {
	var rTxt = '';
	aRequest = (!aRequest) ? "*" : aRequest;
	if (aUrl && (cHttp = new createXMLHttp())) {
		try {
			cHttp.open("HEAD",aUrl,false);
			cHttp.send(null);
			if (cHttp.readyState == 4 && cHttp.status == 200) {
				if (/^all(.*)|\*/.test(aRequest)) rTxt = cHttp.getAllResponseHeaders();
				else {
					try {
						rTxt = cHttp.getResponseHeader(aRequest);
					} catch (e) {
						alert('Error fetching "' + aRequest + '";   ' + e.description);
						rTxt = '';
					}
				}
				cHttp.abort();  // abort this request since got information
			}
		} catch (e) {
			throw new Error('Cross-domain access is not permitted!');
		}
	}
	return rTxt;
}
