
function SearchRecord(search,field){ with (this)
{
	try
	{		
	for (var i = 0; i < this.myrecords; ++i) {
		if (this.data[i][field-1]==search) return (i+1);
	}
	return (0);
	}
	catch (Error){return (0);}
}}


function GetVar(record,field){ with (this)
{
	try
	{
	return (this.data[record-1][field-1]);
	}
	catch (Error){return ('');}

}}

function SetVar(record,field,newdata){ with (this)
{
	try
	{
	this.data[record-1][field-1]=newdata;
	return (true);
	}
	catch (Error){return (false);}

}}

function GetFields(){ with (this)
{
	try
	{
	return (this.myfields);
	}
	catch (Error){return (0);}

}}

function GetRecords(){ with (this)
{
	try
	{
	return (this.myrecords);
	}
	catch (Error){return (0);}

}}


function DoASort(fnum,dorev){ with (this)
{
	try
	{
	var mysort =  new Array(this.myrecords);
	for (var s = 0; s < this.myrecords; ++s)mysort[s]=this.data[s][fnum-1]+"<--SORT-->" +s;
	mysort.sort();
	if (dorev==true)mysort.reverse();

	var newdata = new Array(this.myrecords);
 	for (var i = 0; i < this.myrecords; ++i) {
	 newdata[i]= new Array(this.myfields);
	 
	 var rsnum=Number(mysort[i].split('<--SORT-->')[1]);
	
	 for (var j = 0; j < this.myfields; ++j) {
		newdata[i][j]=this.data[rsnum][j]
	 }
 	}

	this.data=newdata;
	}
	catch (Error){}	
}}

function Numsort (as, bs) {
  var a=Number(as.split('<--SORT-->')[0]);
  var b=Number(bs.split('<--SORT-->')[0]);
  return a - b;
}


function DoNSort(fnum,dorev){ with (this)
{
	try
	{
	var mysort =  new Array(this.myrecords);
	for (var s = 0; s < this.myrecords; ++s)mysort[s]=this.data[s][fnum-1]+"<--SORT-->" +s;
	mysort.sort(Numsort);
	if (dorev==true)mysort.reverse();

	var newdata = new Array(this.myrecords);
 	for (var i = 0; i < this.myrecords; ++i) {
	 newdata[i]= new Array(this.myfields);
	 
	 var rsnum=Number(mysort[i].split('<--SORT-->')[1]);
	
	 for (var j = 0; j < this.myfields; ++j) {
		newdata[i][j]=this.data[rsnum][j]
	 }
 	}

	this.data=newdata;
	}
	catch (Error){}	
}}

function DataArray(myName, htmldata)
{
 this.myrecords = 0;
 this.myfields = 0;

 this.myrecords=Number(htmldata.split('<--ANZD-->')[1]);
 this.myfields=Number(htmldata.split('<--ANZF-->')[1]);

 if (this.myrecords>0){
 if (this.myfields>0){

 this.data = new Array(this.myrecords);
 for (var i = 0; i < this.myrecords; ++i) {	
	var dta =htmldata.split('<--DTA-' + (i+1)  + '-->')[1];
	this.data[i]= dta.split('|');
 }


 }}

 this.myName = myName;
 
 this.getvar = GetVar;
 this.setvar = SetVar;
 this.fields = GetFields;
 this.records = GetRecords;
 this.asort = DoASort;
 this.nsort = DoNSort;
 this.searchrecord = SearchRecord;
}


