function jRecordset()

{

	this.recordCount=-1;
	this.fieldCount=-1;
	this.position=-1;
	this.fieldPos= new Array();
	this.arr=new Array();
	this.tag=""
	
}

jRecordset.prototype.load=jRecordsetLoad;
jRecordset.prototype.eof=jRecordsetEof;
jRecordset.prototype.bof=jRecordsetBof;
jRecordset.prototype.moveNext=jRecordsetMoveNext;
jRecordset.prototype.movePrevious=jRecordsetMovePrevious;
jRecordset.prototype.moveFirst=jRecordsetMoveFirst;
jRecordset.prototype.moveLast=jRecordsetMoveLast;
jRecordset.prototype.movePrevious=jRecordsetMovePrevious;
jRecordset.prototype.writeTable=jRecordsetWriteTable;
jRecordset.prototype.create=jRecordsetCreate;
jRecordset.prototype.addNew=jRecordsetAddNew;
jRecordset.prototype.setFieldValue=jRecordsetSetFieldValue;
jRecordset.prototype.pack=jRecordsetPack;
jRecordset.prototype.createFromADO=jRecordsetCreateFromADO;
jRecordset.prototype.createFromObject=jRecordsetCreateFromObject


jRecordset.prototype.fieldValue=jRecordsetFieldValue;
jRecordset.prototype.fieldName=jRecordsetFieldName;


function jRecordsetFieldName(pos) 
{
	return this.arr[2+pos];
}




function jRecordsetWriteTable(tableClass)
{
	this.moveFirst();
	
	var n

	st="";
	
	st+='<TABLE class="'+tableClass+'">'
	
	for(n=0;n<this.fieldCount;n++)
	{
		st+='<th>'+ this.fieldName(n) + '</th>'
	}
	
	
	while (!this.eof())
	{
			st+="<tr>";
			for(n=0;n<this.fieldCount;n++)
			{
				st+='<td>' + this.fieldValue(n) + '</td>'
			}
			st+="</tr>"
			
			this.moveNext();
	
	}


	st+="</table>"

	return st;
}


function jRecordsetFieldValue(fld) 
{
	x=""+fld;
	pos=this.fieldPos[x.toUpperCase()];
	
	n=2+this.fieldCount+this.position*this.fieldCount+pos;
	
	
	return this.arr[n];

}

function jRecordsetEof()
{
	return this.position >= this.recordCount || this.recordCount==-1;
}

function jRecordsetBof()
{
	return this.position<0 || this.recordCount==-1;
}

function jRecordsetMoveNext()
{
	if (this.eof())
		jRecordsetError("MoveNext past end of recordset.");
	else
		this.position++;
}


function jRecordsetMovePrevious()
{
	if (this.bof())
		jRecordsetError("MovePrevious past begining of recordset.");
	else
		this.position--;
	
}
		
function jRecordsetMoveFirst()
{
	this.position=0;	
}

function jRecordsetMoveLast()
{
	this.position=this.recordCount-1;	
}
	


function jRecordsetLoad(pck)
{
	if(!pck)
		{
			this.recordCount=-1
			this.arr=new Array();
			return;
		}
		
	
	this.arr=pck.split("");
	if (this.arr.length<2)
	{
		this.recordCount=-1
		return;
	}
	else
		{
			this.recordCount=parseInt(this.arr[0]);
			this.fieldCount=parseInt(this.arr[1]);
			this.tag=this.arr[this.arr.length-1];
		}

	var n;
	
	for (n=0;n<this.fieldCount;n++)
		{
		this.fieldPos[(this.arr[2+n]).toUpperCase()]=n;
		this.fieldPos[n]=n;
		}
	
	this.position=0;
	
	
}

function jRecordsetCreate()
{

	this.arr=new Array()
	this.arr[0]=0
	this.arr[1]=arguments.length
	this.position=-1
	this.recordCount=0;
	this.fieldCount=parseInt(this.arr[1]);

	for(n=0;n<arguments.length;n++)
	{
		this.arr[n+2]=(arguments[n]).toUpperCase()
	}

	
	for (n=0;n<this.fieldCount;n++)
		{
		this.fieldPos[(this.arr[2+n]).toUpperCase()]=n;
		this.fieldPos[n]=n;
		}


}

function jRecordsetCreateFromADO(ado)
{
	var n

	this.arr=new Array()
	this.arr[0]=0
	this.arr[1]=ado.fields.count
	this.position=-1
	this.recordCount=0;
	this.fieldCount=parseInt(this.arr[1]);

	for(n=0;n<this.fieldCount;n++)
	{
		this.arr[n+2]=(""+ado.fields(n).name).toUpperCase()
	}

	
	for (n=0;n<this.fieldCount;n++)
		{
		this.fieldPos[(this.arr[2+n]).toUpperCase()]=n;
		this.fieldPos[n]=n;
		}

	if(!ado.eof)
	{
		ado.moveFirst()
	}
	
	while(!ado.eof)
	{
		this.addNew()
		for (n=0;n<this.fieldCount;n++)
		{
			this.setFieldValue(ado.fields(n).name,ado.fields(n).value)
		}
		ado.moveNext()
	}
		
	this.moveFirst()
	
}

function jRecordsetCreateFromObject(obj)
{
	var n
	var v
	
	

	this.arr=new Array()
	this.arr[0]=0
	this.position=-1
	this.recordCount=0;

	n=0
	for(v in obj)
	{
		this.arr[n+2]=v.toUpperCase()
		n++
	}


	this.arr[1]=n
	this.fieldCount=n;	

	
	for (n=0;n<this.fieldCount;n++)
		{
		this.fieldPos[(this.arr[2+n]).toUpperCase()]=n;
		this.fieldPos[n]=n;
		}

		this.addNew()

		for (v in obj)
			this.setFieldValue(v,obj[v])

		
	this.moveFirst()



}




function jRecordsetPack()
{
this.arr[0]=this.recordCount
this.arr[1]=this.fieldCount
this.arr[this.arr.length]=this.tag

return this.arr.join("")
}


function jRecordsetAddNew()
{
this.position=this.recordCount
this.recordCount++;

for(n=0;n<this.fieldCount;n++)
	this.arr[this.position*this.fieldCount+n+this.fieldCount+2]


}

function jRecordsetSetFieldValue(fld,newValue) 
{
	x=""+fld;
	pos=this.fieldPos[x.toUpperCase()];
	
	n=2+this.fieldCount+this.position*this.fieldCount+pos;
	
	
	this.arr[n]=newValue;

}



