//============
//  TDataSet
//============

TDataSet.prototype.fDataSet  = null;
TDataSet.prototype.fRegistro = 0;


TDataSet.prototype.DataSet = function (Grupo, Tabla)
{
	var Aux = this.fDataSet [this.fRegistro].getElementsByTagName (Grupo);
	
	return (new TDataSet (Aux [0], Tabla));
}


TDataSet.prototype.Eof = function ()
{
	return (this.fRegistro >= this.fDataSet.length);
}


TDataSet.prototype.FieldAsBoolean = function (Campo)
{
	var Result = false;
	var Field  = this.FieldByName (Campo);
	var Tipo   = typeof Field;
	
	if (Tipo == "string")
	{	Field = Field.toUpperCase ();
		Result = Field == 'S' || Field == 'Y' || Field == '1';
	} else if (Tipo == 'number') Result = Field != 0;
	else if (Tipo == 'boolean') Result = Field;
	
	return (Result);
}


TDataSet.prototype.FieldAsFloat = function (Campo)
{
	return (parseFloat (this.FieldByName (Campo)));
}


TDataSet.prototype.FieldAsInteger = function (Campo)
{
	return (parseInt (this.FieldByName (Campo)));
}


TDataSet.prototype.FieldByName = function (Campo)
{
	var Field = null;
	
	if (this.fDataSet [this.fRegistro])
		Field = this.fDataSet [this.fRegistro].getElementsByTagName (Campo);

	if (Field && Field.length > 0 && Field [0].childNodes.length > 0) return (Field [0].childNodes [0].data);
	else return ('');
}


TDataSet.prototype.Fields = function ()
{
	if (! this.Eof ()) return (this.fDataSet [this.fRegistro].childNodes);
	else return (null);
}


TDataSet.prototype.First = function ()
{
	this.fRegistro = 0;
}


TDataSet.prototype.Locate = function (Campo, Valor)
{
	if (! this.Eof () && this.FieldByName (Campo) == Valor) return (true);
	this.First ();
	while (! this.Eof () && this.FieldByName (Campo) != Valor) this.Next ();
	return (! this.Eof ())
}


TDataSet.prototype.Next = function ()
{
	this.fRegistro++;
}


TDataSet.prototype.NumRegistros = function ()
{
	if (this.fDataSet) return (this.fDataSet.length);
	else return (0);
}


TDataSet.prototype.Registro = function (Valor)
{
	if (typeof Valor == 'undefined') return (this.fRegistro + 1);
	else if (Valor > 0 && Valor <= this.fDataSet.length) this.fRegistro = Valor - 1;
}


function TDataSet (XML, Tabla)
{
	if (XML) this.fDataSet = XML.getElementsByTagName (Tabla);
	else this.fDataSet = null;
	this.fRegistro = 0;
}


//=============
//  TRegistro
//=============

TRegistro.prototype.fField  = 1;
TRegistro.prototype.fFields = 0;


TRegistro.prototype.Eof = function ()
{
	return (this.fField > this.fFields.length);
}


TRegistro.prototype.FieldName = function ()
{
	if (this.fField <= this.fFields.length) return (this.fFields [this.fField - 1].nodeName);
	else return (null);
}


TRegistro.prototype.FieldValue = function ()
{
	if (this.fField <= this.fFields.length && this.fFields [this.fField - 1].childNodes [0]) 
		return (this.fFields [this.fField - 1].childNodes [0].data);
	else return ('');
}


TRegistro.prototype.First = function ()
{
	this.fField = 1;
}


TRegistro.prototype.Next = function ()
{
	this.fField++;
}


function TRegistro (DataSet)
{
	this.fFields = DataSet.Fields ();
	this.fField  = 1;
}

//=====================================================================================
//=====================================================================================
//=====================================================================================
//=====================================================================================




