

//-------------------------------------------------------------------------------
function objXMLHTTP() {
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
};

/****
This script is called after client-side xmlHTTPRequest returns responseText.
due to browsers implementing xml dom differently
I have chosen to return a javascript set of arrays representing a recordset
instead of XML, which would require massive amounts of browser detection
to parse. In theory, this will actually return a smaller response footprint,
but may carry more load when parsing (eval()) the string into javascript (who knows?).
NOTE:	for performance reasons, this is not meant to parse a large number
		of records, especially if rows have a large number of fields

array format:
	this.rows=n;
	this.cols=n;
	this.colnames={colname1:0,colname2:1,etc:2}; //object literal
	this.recordset=new Array();
	this.recordset[0]=["value1","value1","etc"];
	this.recordset[1]=["value1","value1","etc"]; //etc...
	this.err=false;
		//or
	this.err=true;
	this.errdesc="Error description.";

****/
	//the class
	function xmlhttpRecordset(js) {
		this.recordset = new Array();
		
		try {
			eval(js);
		} catch (e) {
			this.err = true;
			this.errdescr = e;
			return false;
		}
		this.iRow = 0;
		this.eof = getEOF; this.EOF = getEOF;
		this.bof = getBOF; this.BOF = getBOF;
		this.errdesc = this.errdescr; //I keep misspelling the variable
	};
	function getBOF() { return (this.iRow < 0); }
	function getEOF() { return (this.iRow >= this.rows); }
	xmlhttpRecordset.prototype.moveto = function(n) { this.iRow = (!isNaN(n) ? n : this.iRow); }
	xmlhttpRecordset.prototype.moveprevious = function() { this.iRow--; }
	xmlhttpRecordset.prototype.movefirst = function() { this.iRow = 0; }
	xmlhttpRecordset.prototype.movelast = function() { this.iRow = this.rows-1; }
	xmlhttpRecordset.prototype.movenext = function() { this.iRow++; }
	xmlhttpRecordset.prototype.fields = function(fieldRef) {
		var fieldVal = this.recordset[this.iRow][this.colnames[fieldRef]];
		if(fieldVal === undefined) { return false; }
		//return (isNaN(fieldVal) || fieldVal.length == 0 ? new String(fieldVal) : new Number(fieldVal));
		return fieldVal+'';
	};	
	
	
	