// World Cup    2 0 0 6
//
// make this NGO specific to your competition by choosing how it sorts and processes the data
function NonGenericObject(snapShotObj,model,txt){
this._txt=txt;
this._model = model;
this._snapShotObj = snapShotObj;
this._counter = 0;
this.numScoresFilled=0;
this._so={"rC":[],"rD":[]};
// reset won, drawn, lost and against values....
this.clearValues();
//this.matchFixtureNamesToResultNames();
this.matchThem();
//this.orderTable();
}
NonGenericObject.prototype.matchThem = function(){
var id = this._snapShotObj.id;
// iterative processing...
for(var i=1;i<=this._snapShotObj[id].fm.rowCount;i++){
	for(var j=1;j<=this._snapShotObj[id].fm.numRowResults;j++){
		// match names for the teams on the LHS of the fixtures list
		if(this._snapShotObj[id].i_itemNameLeft[i] == this._snapShotObj[id].o_tablerow[j][1]){
			this.updateResults(i,j);
			}
		}
	}
// 'one shot' processing...
this.sortResults();	
this._model.transmit(this._snapShotObj);	
}
// modify results rows one by one
NonGenericObject.prototype.updateResults = function(i,j){
// get row number of results table for rhs fixtures by matching team name
this.RightRowNum = this.matchFixturesOnRight(i);
var mirrorValue = this.checkMirrors(i);

this.modifyGamesWonLost(i,j,mirrorValue); // value of 6...
this.modifyGamesDrawn(i,j,mirrorValue); // value of 7...
this.modifyPlayed(i,j,mirrorValue);
this.modifyGoalDifference(i,j,mirrorValue);
this.modifyPoints(i,j,mirrorValue);
this.modifyGoalsFor(i,j,mirrorValue);
this.modifyGoalsAgainst(i,j,mirrorValue);

}
NonGenericObject.prototype.sortResults = function(){
this.createSortArray();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// the SECOND argument sent to 'sortThese()' below is the category you want to sort by...
// 1 = team name
// 2 = played
// 3 = goal difference
// 4 = points 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Here is the format for this sort
// rule a)  greater number of points obtained in all the group matches;
// rule b)  greater number of points obtained in the group matches between the teams concerned;
// rule c)  goal difference resulting from the group matches between the teams concerned;
// rule d)  greater number of goals scored in the group matches between the teams concerned;
// rule e)  goal difference in all the group matches;
// rule f)  greater number of goals scored in all the group matches;
// rule g)  drawing lots 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////	


this.sortArray=this.sortThis(this.sortArray,this.sortArray.length,3,"A");
// rule A
this.orderLikePointsResults((this.sortArray.length-1));
this.sortMinis(this.miniArray.length,2,"A");
this.putMinisBack(this.miniArray.length);
// Rule B
this.filterPreB();

this.putMinisBack(this.miniArray.length);

//this.orderLikeGoalDifferenceResults((this.sortArray.length-1));
//this.sortMinis(this.miniArray.length,4,"A");
//this.putMinisBack(this.miniArray.length);
//this.orderLikeGoalsForResults((this.sortArray.length-1));
//this.sortMinis(this.miniArray.length,0,"B");
//this.putMinisBack(this.miniArray.length);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this.putSortedDataBack();
}

///////////////////////////////////////////////////////////////////////////////////////////// S O R T    P R O C E S S I N G    B E G I N S  //////////////////////////////////////
// Get data out of _snapShotObj - it needs to be put into a 'sort friendly' array...
NonGenericObject.prototype.createSortArray = function(){
var id = this._snapShotObj.id;
this.sortArray = new Array();
// convert results values into useful arrays temporarily for sorting...
this.sortArray[0] = new Array("buffer","no value","no value","no value","no value","no value")
for(var i=1;i<=this._snapShotObj[id].fm.numRowResults;i++){
	this.sortArray[i] = new Array(this._snapShotObj[id].o_tablerow[i][1],
												this._snapShotObj[id].o_tablerow[i][2],
												this._snapShotObj[id].o_tablerow[i][3],
												this._snapShotObj[id].o_tablerow[i][4],
												this._snapShotObj[id].o_tablerow[i][5],
												this._snapShotObj[id].o_tablerow[i][6],
												this._snapShotObj[id].o_tablerow[i][7],
												this._snapShotObj[id].o_tablerow[i][8],
												this._snapShotObj[id].o_tablerow[i][9])
	}
}
// see what we've got...
NonGenericObject.prototype.filterPreB = function(){
switch(true){
	case this.miniArray[1].length == 5:
	this.ruleB(4,1,1);
	break;
	case this.miniArray[1].length == 4:
	// three teams all ahead with same points - last team trailing with fewer...
	this.ruleB(3,1,1);
	break;
	case this.miniArray[2].length == 4:
	// first team out in front with more points - remaining three all have the same points...
	this.ruleB(3,2,2);
	break;
	case this.miniArray[1].length == 3 && this.miniArray[2].length == 3:
	// ruleB called twice - once for each pairing...
	this.ruleB(2,1,1);
	this.ruleB(2,2,3);
	break;
	case this.miniArray[1].length == 3 && this.miniArray[2].length != 3:
	// two leading teams have same points - two trailing teams have different points
	this.ruleB(2,1,1);
	break;
	case this.miniArray[1].length == 2 && this.miniArray[2].length == 3:
	// leading team has most points - 2 teams follow with identical points - one team trails with fewest points...
	this.ruleB(2,2,2);
	break;
	case this.miniArray[1].length == 2 && this.miniArray[2].length == 2 && this.miniArray[3].length == 3:
	// leading team has most points - second team has different points - third and fourth tied on points...
	this.ruleB(2,3,3);
	break;
	default:
	break;
	}
}
// isMultiCall...called x2 max
// sort by GD in ALL group matches...
// teamNum - number of teams (in this call) to be processed...
// maNum - which element of miniArray are we dealing with...
NonGenericObject.prototype.ruleB = function(teamNum,maNum,index){
this.miniArray[maNum]=this.sortThis(this.miniArray[maNum],this.miniArray[maNum].length,2,"A");
this.putMinisBack(this.miniArray.length);
this.filterPreC(teamNum,maNum,index);
}
NonGenericObject.prototype.filterPreC = function(teamNum,maNum,index){
// FilterPreC can be called twice - make sure the first pass is not overwritten - use maNum to increment arrays in _so.rC
var m=maNum;
var profile="p0";
var p;
var gate=true;
var len=this.miniArray[m].length-1; 
this._so.rC[m]=[];
this._so.rC[m][0]=0;
this._so.rC[m][1]=[];
this._so.rC[m][1][0]=this.miniArray[m][1];
if(this.miniArray[m][1][2]==this.miniArray[m][2][2]){p=0}else{p=1;}
var k=1;
// split teams with like GD into arrays in the Sorting object
for(var i=1;i<len;i++){
	if(this.miniArray[m][i][2]==this.miniArray[m][(i+1)][2]){
		profile+=p+"";
		this._so.rC[m][k].push(this.miniArray[m][(i+1)]);
		}
		else{
		k++;
		p++;
		this._so.rC[m][k]=[];
		this._so.rC[m][k].push(this.miniArray[m][(i+1)]);
		profile+=p+"";
		}
	}
var localprofile="lp";
for(x=1;x<4;x++){
if(this._so.rC[m][x]){
	localprofile+=""+this._so.rC[m][x].length;
	}
}
// get rid of any team on its own in an array(doesn't need further sorting)
for(x=4;x>0;x--){
	if(this._so.rC[m][x]&&this._so.rC[m][x].length==1){
		this._so.rC[m].splice(x,1);
		}
	}
if(this._so.rC[m][1]){	
	switch(true){
		case localprofile=="lp121":
			this._so.rC[m][1].index=2;
		break;
		case localprofile=="lp12":
			this._so.rC[m][1].index=2;
		break;
		case localprofile=="lp112":
			this._so.rC[m][1].index=3;
		break;
		case localprofile=="lp22":
			this._so.rC[m][1].index=1;
			this._so.rC[m][2].index=3;
		break;
		default:// local profile must be: 'lp4','lp211','lp3','lp2' or 'lp21'
			this._so.rC[m][1].index=1;
		break;
		}	
	}	
// ******************* START DIAGNOSTICS *************************
/*
alert(profile);
if(this._so.rC[m][1])alert(this._so.rC[m][1].index);
alert(this._so.rC[m][1])
if(this._so.rC[m][2]){alert(this._so.rC[m][2]);alert(this._so.rC[m][2].index);}
*/
// ******************* END DIAGNOSTICS *************************
this.MAIndex=index;
if(!this._so.rC[m][1])gate=false;
if(gate){this.ruleC(profile,m);}else{return;}
}
// isMultiCall...called x2 max
// sort by total goals from ALL group matches...
NonGenericObject.prototype.ruleC = function(profile,maNum){
var m=maNum;
for(var i=1;i<this._so.rC[m].length;i++){
	// sortThis requires a buffer in order to work so add one...
	this._so.rC[m][i].unshift('b');
	this._so.rC[m][i]=this.sortThis(this._so.rC[m][i],this._so.rC[m][i].length,4,"A");
	// get rid of the buffer...
	this._so.rC[m][i].shift();
	var idx=this._so.rC[m][i].index;
	var rcNum=i;
	var len=this._so.rC[m][i].length;
	var x=0;
	for(var k=idx;k<(idx+len);k++){
		this.miniArray[m][k]=this._so.rC[m][i][x];
		x++;
		}
	}
//this.putMinisBack(this.miniArray.length);
this.filterPreD(m,rcNum);
}
////////////    END OF SORTING BY RULE A, B and C    //////////////////////////////////////////////////////////////////////////////////////////
NonGenericObject.prototype.filterPreD = function(maNum,rcNum){
var p=rcNum;
var m=maNum;
this._so.rD[m]=[];
this._so.rD[m][0]=0;
this._so.rD[m][1]=[];
switch(true){
	case this._so.rC[m][p].length==4:
	// a case for rule G ************************************************* !!!    ... (_ (_ '(_/'v'\/'v'\_)' _) _) ...
	return;
	break;
	case this._so.rC[m][p].length==3:
	// sort on 3 x teams using rule D
	this.prepareDThrees(m,p);
	break;
	case this._so.rC[m][p].length==2:
	// sort on 2 x teams using rule D
	if(this._so.rC[m][p][0][4]==this._so.rC[m][p][1][4]){
		this._so.rD[m][1]=this._so.rC[m][p];
		//this._so.rD[m][1].index=1;
		this.rcIndex=1;
		this.RuleD2T(m,p);
		}
	break;
	default:
	break;
	}
}
NonGenericObject.prototype.prepareDThrees = function(m,rcNum){
var p=rcNum;
switch(true){
	case this._so.rC[m][p][0][4]==this._so.rC[m][p][1][4]:
	this.rcIndex=1;
	this._so.rD[m][1].push(this._so.rC[m][p][0],this._so.rC[m][p][1]);
	if(this._so.rC[m][p][1][4]==this._so.rC[m][p][2][4]){
		if(this._so.rC[m][p][0][4]!=this._so.rC[m][p][1][4]){this._so.rD[m][1].push(this._so.rC[m][p][1]);this.rcIndex=2;}
		this._so.rD[m][1].push(this._so.rC[m][p][2]);
		}
	break;
	case this._so.rC[m][p][0][4]!=this._so.rC[m][p][1][4]:
	if(this._so.rC[m][p][1][4]==this._so.rC[m][p][2][4]){
		this.rcIndex=2;
		this._so.rD[m][1].push(this._so.rC[m][p][1],this._so.rC[m][p][2]);
		}
	break;
	default:
	break;
	}
if(this._so.rD[m][1].length==3){this.RuleD3T(m,p);}else{if(this._so.rD[m][1].length==2){this.RuleD2T(m,p);}}
}	
NonGenericObject.prototype.RuleD2T = function(m,rcNum){
var p=rcNum;
var id = this._snapShotObj.id;
for(var i=1;i<=6;i++){
	var a=this._snapShotObj[id].i_itemNameLeft[i];
	var b=this._snapShotObj[id].i_itemNameRight[i];
	var c=this._so.rD[m][1][0][0];
	var d=this._so.rD[m][1][1][0];
	var e=this._snapShotObj[id].i_itemLeft[i];
	var f=this._snapShotObj[id].i_itemRight[i];
	if(a==c&&b==d){
		this._so.rD[m][1]=this.assessIt(e,f,m,this._so.rD);
		}
	if(a==d&&b==c){
		this._so.rD[m][1]=this.assessIt(f,e,m,this._so.rD);
		}	
	}
this._so.rC[m][p].splice((this.rcIndex-1),2,this._so.rD[m][1][0],this._so.rD[m][1][1])
switch(true){
	case this._so.rC[m][p].length==3:
	this.miniArray[m].splice(this._so.rC[m][p].index,3,this._so.rC[m][p][0],this._so.rC[m][p][1],this._so.rC[m][p][2]);
	break;
	case this._so.rC[m][p].length==2:
	this.miniArray[m].splice(this._so.rC[m][p].index,2,this._so.rC[m][p][0],this._so.rC[m][p][1]);
	break;
	default:
	break;
	}
}
NonGenericObject.prototype.assessIt = function(a,b,m,obj){
switch(true){
	case Number(a)>Number(b):
	// leave as is...
	return this._so.rD[m][1];
	break;
	case Number(a)<Number(b):
	var dummy=obj[m][1][1];
	obj[m][1][1]=obj[m][1][0];
	obj[m][1][0]=dummy;
	return obj[m][1];
	break;
	default:
	// a case for rule G ************************************************* !!!    ... (_ (_ '(_/'v'\/'v'\_)' _) _) ...
	return this._so.rD[m][1];
	break;
	}
}
NonGenericObject.prototype.RuleD3T = function(m,rcNum){
var p=rcNum;
if(this.MAIndex==2){
	// three trailing teams to sort
	}
	else{
	// three leading teams to sort
	}

var id = this._snapShotObj.id;
var t1pts=0;
var t2pts=0;
var t3pts=0;
var t1GD=0;
var t2GD=0;
var t3GD=0;
var t1totG=0;
var t2totG=0;
var t3totG=0;
for(var i=1;i<=6;i++){
	var a=this._snapShotObj[id].i_itemNameLeft[i];
	var b=this._snapShotObj[id].i_itemNameRight[i];
	var c=this.miniArray[m][1];
	var d=this.miniArray[m][2];
	var e=this.miniArray[m][3];
	var f=Number(this._snapShotObj[id].i_itemLeft[i]);
	var g=Number(this._snapShotObj[id].i_itemRight[i]);
	if(a==c[0]){// t1 on left
		if(b==d[0]){t1totG+=f;t2totG+=g;t1GD+=(f-g);t2GD+=(g-f);}
		if(b==e[0]){t1totG+=f;t3totG+=g;t1GD+=(f-g);t3GD+=(g-f);}
		}
	if(a==d[0]){
		if(b==c[0]){t2totG+=f;t1totG+=g;t2GD+=(f-g);t1GD+=(g-f);}
		if(b==e[0]){t2totG+=f;t3totG+=g;t2GD+=(f-g);t3GD+=(g-f);}
		}
	if(a==e[0]){
		if(b==c[0]){t3totG+=f;t1totG+=g;t3GD+=(f-g);t1GD+=(g-f);}
		if(b==d[0]){t3totG+=f;t2totG+=g;t3GD+=(f-g);t2GD+=(g-f);}
		}	
	}	
var arr=[];
arr[0]=0;
arr[1]=t1GD;
arr[2]=t2GD;
arr[3]=t3GD;
for (var i=1; i<3; i++){
	for (var j=i+1; j<4; j++){
		if(Number(arr[j]) > Number(arr[i])){
			var dummy = arr[i];
			var d=this.miniArray[m][i]
			arr[i] = arr[j];
			this.miniArray[m][i]=this.miniArray[m][j]
			arr[j] = dummy;
			this.miniArray[m][j]=d;
			}
		}	
	}
var start=1;
var end=3
switch(true){
	case arr[1]==arr[2]&&arr[2]==arr[3]:// all the same
	break;
	case arr[1]==arr[2]:// first 2 the same
	end=2
	break;
	case arr[2]==arr[3]:// last 2 the same
	start=2
	break;
	default:
	start=0;
	end=0;
	break;
	}
var arr=[];
arr[0]=0;
arr[1]=t1totG;
arr[2]=t2totG;
arr[3]=t3totG;	
for (var i=start; i<end; i++){
	for (var j=i+1; j<(end+1); j++){
		if(Number(arr[j]) > Number(arr[i])){
			var dummy = arr[i];
			var d=this.miniArray[m][i]
			arr[i] = arr[j];
			this.miniArray[m][i]=this.miniArray[m][j]
			arr[j] = dummy;
			this.miniArray[m][j]=d;
			}
		}	
	}
}

// Mark for deletion please...






NonGenericObject.prototype.announce = function(msg){
	if(this.allowAnnouncements()>5){
		if(this._snapShotObj.call=="user"){
		alert(msg);
		}
	}
}
NonGenericObject.prototype.allowAnnouncements = function(){
// we only want alert boxes when six rows have been filled
this.numScoresFilled=0;
var i = 1;
while(i<7){
	if(this._snapShotObj[this._snapShotObj.id].i_itemLeft[i]!=""){this.numScoresFilled++}
	i++;
	}
	return this.numScoresFilled;
}
NonGenericObject.prototype.alerted = function(source,requester){
var arr = [];
arr[4]=[this._txt.msg[7],this._txt.msg[8]];
arr[5]=[this._txt.msg[9],this._txt.msg[10]];
arr[6]=[this._txt.msg[9],this._txt.msg[11]];
arr[7]=[this._txt.msg[12],this._txt.msg[10],this._txt.msg[11]];
switch(source){
	case 1:
	return arr[requester][0];
	break;
	case 2:
	return arr[requester][1];
	break;
	default:
	return arr[requester][2];
	break;
	}
}
NonGenericObject.prototype.locate000 = function(maNum,k,array){
var arr = [];
for(var i=1;i<array.length;i++){
	if(this.localFixtures[maNum][k].itemNameLeft == array[i][0]){arr[0] = i;}
	if(this.localFixtures[maNum][k].itemNameRight == array[i][0]){arr[1] = i;}
	}
return arr;	
}
NonGenericObject.prototype.createLocalFixtures000 = function(teamNum,maNum){
var id = this._snapShotObj.id;
var fixNum = this._snapShotObj[id].fm.fixtureRows;
this.localFixtures = new Object();
this.localFixtures[maNum] = [];
var h = 1;
var i = 1;
var num = 1;
while(i<=fixNum){
	for(var k=1;k<=teamNum;k++){
		if(this._snapShotObj[id].i_itemNameLeft[i] == this.miniArray[maNum][k][0]){
			for(var l=1;l<=teamNum;l++){
				if(this._snapShotObj[id].i_itemNameRight[i] == this.miniArray[maNum][l][0]){
					this.localFixtures[maNum][num] = [];
					this.localFixtures[maNum][num].itemNameLeft =  this._snapShotObj[id].i_itemNameLeft[i];
					this.localFixtures[maNum][num].itemLeft = this._snapShotObj[id].i_itemLeft[i];
					this.localFixtures[maNum][num].itemNameRight =this._snapShotObj[id].i_itemNameRight[i];
					this.localFixtures[maNum][num].itemRight = this._snapShotObj[id].i_itemRight[i];
					num++;					
					}
				}
			}
		}		
	i++;
	}
}
NonGenericObject.prototype.swap000 = function(a,b,arr){
var item1 = arr[a];
arr[a] = arr[b];
arr[b] = item1;
return arr;
}
NonGenericObject.prototype.showThis = function(object,length,element) {
    var output = '<table cellspacing="0" cellpadding="0" border="1" width="300"><tr>';
    for(var i=1; i<=length; i++) {
        for(var j=0; j<=element; j++) {
            output += '<td>'+object[i][j] + '</td>';
        }
    output += '</tr>';
    }
output +='</table>';
window.document.write(output + '<BR>');
}
// take all the rows that have the SAME goal difference value and put them into mini arrays...
NonGenericObject.prototype.orderLikeGoalsForResults000 = function(length){
this.miniArray[0]="buffer array";
var x = 1;
var y = 1;
this.miniArray[1] = new Array();
this.miniArray[1][0] = 1;
for (var i=1; i<=length; i++)
if(this.sortArray[(i+1)]!=null){
	if(this.sortArray[i][4] == this.sortArray[(i+1)][4]&&this.sortArray[i][2] == this.sortArray[(i+1)][2]&&this.sortArray[i][3] == this.sortArray[(i+1)][3]){
		this.miniArray[x][y] = this.sortArray[i]
		y++
		}
		else{
		this.miniArray[x][y] = this.sortArray[i];
		y=1;
		x++;
		this.miniArray[x] = new Array();
		this.miniArray[x][0] = i+1;
		}
	}
	else{this.miniArray[x][y] = this.sortArray[i];}
}
// sort whatever you want according to the options 'A' or 'B'
NonGenericObject.prototype.sortThis = function(arrayName,length,element,option){
    for (var i=1; i<(length-1); i++){
        for (var j=i+1; j<length; j++){
		// Option A is a sort for numbers - puts the highest value FIRST
			if(option=="A"){
	            if(Number(arrayName[j][element]) > Number(arrayName[i][element])) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
				}
			}	
			else{
		// Option B is a sort for strings - puts them alphebetically	
				 if (arrayName[j][element] < arrayName[i][element]) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
				}
            }
		}	
	}	
return arrayName;
}
// take all the rows that have the SAME points value and put them into mini arrays...
NonGenericObject.prototype.orderLikePointsResults = function(length){
// this.miniArray - Arrays of team info where each tema has the same points as the next...
this.miniArray = new Array();
this.miniArray[0]="buffer array";
var x = 1;
var y = 1;
this.miniArray[1] = new Array();
this.miniArray[1][0] = 1;
for (var i=1; i<=length; i++){
if(this.sortArray[(i+1)]!=null){
	if(this.sortArray[i][3] == this.sortArray[(i+1)][3]){
		this.miniArray[x][y] = this.sortArray[i];
		y++;
		}
		else{
		this.miniArray[x][y] = this.sortArray[i];
		y=1;
		x++;
		this.miniArray[x] = new Array();
		this.miniArray[x][0] = i+1;
		}
	}
	else{this.miniArray[x][y] = this.sortArray[i];}
	}
}
// a general sorter for mini arrays - passes them to 'sortThis' based upon option
NonGenericObject.prototype.sortMinis = function(length,element,option){
for (var i=1; i<length; i++){
	var len = this.miniArray[i].length;
	this.miniArray[i]=this.sortThis(this.miniArray[i],len,element,option);
	}
}
// mini arrays must be put back in the right place in the main array...
NonGenericObject.prototype.putMinisBack = function(length){
	for (var j=1; j<length; j++) {
		for (var k=1; k<this.sortArray.length; k++) {
			if(k == this.miniArray[j][0]){
				for(var n=1;n<this.miniArray[j].length;n++){
					this.sortArray[k] = this.miniArray[j][n]
					k++;
				}
			}
		}
	}
}
// take all the rows that have the SAME goal difference value and put them into mini arrays...
NonGenericObject.prototype.orderLikeGoalDifferenceResults000 = function(length){
this.miniArray[0]="buffer array";
var x = 1;
var y = 1;
this.miniArray[1] = new Array();
this.miniArray[1][0] = 1;
for (var i=1; i<=length; i++)
if(this.sortArray[(i+1)]!=null){
	if(this.sortArray[i][2] == this.sortArray[(i+1)][2]&&this.sortArray[i][3] == this.sortArray[(i+1)][3]){
		this.miniArray[x][y] = this.sortArray[i]
		y++;
		}
		else{
		this.miniArray[x][y] = this.sortArray[i];
		y=1;
		x++;
		this.miniArray[x] = new Array();
		this.miniArray[x][0] = i+1;
		}
	}
	else{this.miniArray[x][y] = this.sortArray[i];}
}
// After sorting is completed, all the data needs to be put back into _snapShotObj ready for updating the View
NonGenericObject.prototype.putSortedDataBack = function(){
var id = this._snapShotObj.id;
for(var i=1;i<=this._snapShotObj[id].fm.numRowResults;i++){
	this._snapShotObj[id].o_tablerow[i][1] = this.sortArray[i][0];
	this._snapShotObj[id].o_tablerow[i][2] = this.sortArray[i][1];
	this._snapShotObj[id].o_tablerow[i][3] = this.sortArray[i][2];
	this._snapShotObj[id].o_tablerow[i][4] = this.sortArray[i][3];
	this._snapShotObj[id].o_tablerow[i][5] = this.sortArray[i][4];
	this._snapShotObj[id].o_tablerow[i][6] = this.sortArray[i][5];
	this._snapShotObj[id].o_tablerow[i][7] = this.sortArray[i][6];
	this._snapShotObj[id].o_tablerow[i][8] = this.sortArray[i][7];
	this._snapShotObj[id].o_tablerow[i][9] = this.sortArray[i][8];
	}
}
///////////////////////////////////////////////////////////////////////////////////////////// S O R T    P R O C E S S I N G    E N D S  //////////////////////////////////////
// find out whether the number of games played should be updated...
NonGenericObject.prototype.modifyPlayed = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
if(mirrorValue == 0){playedValue=0}// no data entered into row - played not updated
else if(mirrorValue == 1){playedValue=1}// first data entered into row - played updated
else if(mirrorValue == 2){playedValue=-1}// no data entered (but data entered before) - played updated by -1
else if(mirrorValue == 3){playedValue=0}// data entered - but not for the first time - played not updated
this._snapShotObj[id].o_tablerow[j][2] = Number(this._snapShotObj[id].o_tablerow[j][2]) + playedValue;
this._snapShotObj[id].o_tablerow[this.RightRowNum][2] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][2]) + playedValue;
}
NonGenericObject.prototype.modifyGoalDifference = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
// Goal difference values must be adjusted under certain conditions ...
if(mirrorValue == 2 || mirrorValue == 3){
	if(Number(this._snapShotObj[id].i_itemLeftMirror[i]) > Number(this._snapShotObj[id].i_itemRightMirror[i])){
	// if boxes HAVE been edited before and the old left value was greater than the right, reset the local GD ...
	this._snapShotObj[id].o_tablerow[j][3] = Number(this._snapShotObj[id].o_tablerow[j][3]) - (Number(this._snapShotObj[id].i_itemLeftMirror[i]) - Number(this._snapShotObj[id].i_itemRightMirror[i]));
	this._snapShotObj[id].o_tablerow[this.RightRowNum][3] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][3]) + (Number(this._snapShotObj[id].i_itemLeftMirror[i]) - Number(this._snapShotObj[id].i_itemRightMirror[i]));
	}
	else{
	// if boxes HAVE been edited before and the old right value was greater than the left, reset the local GD ...
	this._snapShotObj[id].o_tablerow[j][3] = Number(this._snapShotObj[id].o_tablerow[j][3]) + (Number(this._snapShotObj[id].i_itemRightMirror[i]) - Number(this._snapShotObj[id].i_itemLeftMirror[i]));
	this._snapShotObj[id].o_tablerow[this.RightRowNum][3] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][3]) - (Number(this._snapShotObj[id].i_itemRightMirror[i]) - Number(this._snapShotObj[id].i_itemLeftMirror[i]));
	}
}
if(this._snapShotObj[id].i_itemLeft[i] == this._snapShotObj[id].i_itemRight[i]){
	// a draw - GD does not change...
	}
	else{
		if(Number(this._snapShotObj[id].i_itemLeft[i]) > Number(this._snapShotObj[id].i_itemRight[i])){
		// left team wins
		var goalDifference = (this._snapShotObj[id].i_itemLeft[i] - this._snapShotObj[id].i_itemRight[i]);
		this._snapShotObj[id].o_tablerow[j][3] = Number(this._snapShotObj[id].o_tablerow[j][3]) + goalDifference;
		this._snapShotObj[id].o_tablerow[this.RightRowNum][3] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][3]) - goalDifference;
		}
		else{
		// right team wins
		var goalDifference = (this._snapShotObj[id].i_itemRight[i] - this._snapShotObj[id].i_itemLeft[i]);
		this._snapShotObj[id].o_tablerow[j][3] = Number(this._snapShotObj[id].o_tablerow[j][3]) - goalDifference;
		this._snapShotObj[id].o_tablerow[this.RightRowNum][3] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][3]) + goalDifference;
		}
	}
}
NonGenericObject.prototype.modifyGoalsFor = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
	if(mirrorValue == 2 || mirrorValue == 3){
		this._snapShotObj[id].o_tablerow[j][5] = Number(this._snapShotObj[id].o_tablerow[j][5]) - Number(this._snapShotObj[id].i_itemLeftMirror[i]);
		this._snapShotObj[id].o_tablerow[this.RightRowNum][5] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][5]) - Number(this._snapShotObj[id].i_itemRightMirror[i]);
		this._snapShotObj[id].o_tablerow[j][5] = Number(this._snapShotObj[id].o_tablerow[j][5]) + Number(this._snapShotObj[id].i_itemLeft[i]);
		this._snapShotObj[id].o_tablerow[this.RightRowNum][5] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][5]) + Number(this._snapShotObj[id].i_itemRight[i]);
	}
	else{
		if(mirrorValue != 0){
		this._snapShotObj[id].o_tablerow[j][5] = Number(this._snapShotObj[id].o_tablerow[j][5]) + Number(this._snapShotObj[id].i_itemLeft[i]);
		this._snapShotObj[id].o_tablerow[this.RightRowNum][5] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][5]) + Number(this._snapShotObj[id].i_itemRight[i]);
		}
	}
}
NonGenericObject.prototype.modifyGoalsAgainst = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
if(this._snapShotObj[id].i_itemLeft[i]!=""){
	this._snapShotObj[id].o_tablerow[this.RightRowNum][9]=Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][9])+Number(this._snapShotObj[id].i_itemLeft[i]);
	this._snapShotObj[id].o_tablerow[j][9]=Number(this._snapShotObj[id].o_tablerow[j][9])+Number(this._snapShotObj[id].i_itemRight[i]);
	}
}
NonGenericObject.prototype.modifyGamesWonLost = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
if(Number(this._snapShotObj[id].i_itemLeft[i]) > Number(this._snapShotObj[id].i_itemRight[i])){
this._snapShotObj[id].o_tablerow[j][6]++;this._snapShotObj[id].o_tablerow[this.RightRowNum][8]++;}
if(Number(this._snapShotObj[id].i_itemLeft[i]) < Number(this._snapShotObj[id].i_itemRight[i])){this._snapShotObj[id].o_tablerow[this.RightRowNum][6]++;this._snapShotObj[id].o_tablerow[j][8]++;}
}
NonGenericObject.prototype.modifyGamesDrawn = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
if(this._snapShotObj[id].i_itemLeft[i]!=""&&this._snapShotObj[id].i_itemLeft[i] == this._snapShotObj[id].i_itemRight[i]){this._snapShotObj[id].o_tablerow[j][7]++;this._snapShotObj[id].o_tablerow[this.RightRowNum][7]++;}
}
NonGenericObject.prototype.modifyPoints = function(i,j,mirrorValue){
var id = this._snapShotObj.id;
	if(mirrorValue == 2 || mirrorValue == 3){
		if(Number(this._snapShotObj[id].i_itemLeftMirror[i]) > Number(this._snapShotObj[id].i_itemRightMirror[i])){
		// if boxes HAVE been edited before and the old left value was greater than the right, change each by 3 points...
		this._snapShotObj[id].o_tablerow[j][4] = Number(this._snapShotObj[id].o_tablerow[j][4]) - 3;
		}
		else if(Number(this._snapShotObj[id].i_itemLeftMirror[i]) < Number(this._snapShotObj[id].i_itemRightMirror[i])){
		// if boxes HAVE been edited before and the old right value was greater than the left, change each by 3 points...
		this._snapShotObj[id].o_tablerow[this.RightRowNum][4] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][4]) - 3;
		}
		else{
		// old values were a draw - so subtract 1 from each...
		this._snapShotObj[id].o_tablerow[j][4] = Number(this._snapShotObj[id].o_tablerow[j][4]) - 1;
		this._snapShotObj[id].o_tablerow[this.RightRowNum][4] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][4]) - 1;
		}
	}
	if(mirrorValue != 0){
		if(this._snapShotObj[id].i_itemLeft[i] == this._snapShotObj[id].i_itemRight[i] && this._snapShotObj[id].i_itemLeft[i]!=''){
		// a draw ...
		this._snapShotObj[id].o_tablerow[j][4] = Number(this._snapShotObj[id].o_tablerow[j][4]) + 1;
		this._snapShotObj[id].o_tablerow[this.RightRowNum][4] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][4]) + 1;
		}
		else if(this._snapShotObj[id].i_itemLeft[i] == ''){
		// user emptied the text box...do nothing
		}
		else if(Number(this._snapShotObj[id].i_itemLeft[i]) > Number(this._snapShotObj[id].i_itemRight[i])){
		// left team wins
		this._snapShotObj[id].o_tablerow[j][4] = Number(this._snapShotObj[id].o_tablerow[j][4]) + 3;
		this._snapShotObj[id].o_tablerow[this.RightRowNum][4] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][4]);
		}
		else{
		// right team wins
		this._snapShotObj[id].o_tablerow[j][4] = Number(this._snapShotObj[id].o_tablerow[j][4]);
		this._snapShotObj[id].o_tablerow[this.RightRowNum][4] = Number(this._snapShotObj[id].o_tablerow[this.RightRowNum][4]) + 3;
		}	
	}
}
NonGenericObject.prototype.clearValues = function(){
var id = this._snapShotObj.id;
for(var i=1;i<=this._snapShotObj[id].fm.numRowResults;i++){
	this._snapShotObj[id].o_tablerow[i][6]=0;
	this._snapShotObj[id].o_tablerow[i][7]=0;
	this._snapShotObj[id].o_tablerow[i][8]=0;
	this._snapShotObj[id].o_tablerow[i][9]=0;
	}
}
NonGenericObject.prototype.checkMirrors = function(i){
var id = this._snapShotObj.id;
// check the mirror values to see if both check boxes are empty - 
// if they are - it means that scores have been entered for the first time         
if(this._snapShotObj[id].i_itemLeftMirror[i] == ""){
	if(this._snapShotObj[id].i_itemLeft[i] == ""){
		// no data entered into row
		return 0;
		}
		else{
		// first data entered into row
		return 1;
		}
	}
	else{
		if(this._snapShotObj[id].i_itemLeft[i] == ""){
		// no data entered (but data entered before)
		return 2;
		}
		else{
		// data entered - but not for the first time
		return 3;
		}
	}
}
NonGenericObject.prototype.matchFixturesOnRight = function(i){
var id = this._snapShotObj.id;
for(var j=1;j<=this._snapShotObj[id].fm.numRowResults;j++){
		// match names for the teams on the LHS of the fixtures list
	if(this._snapShotObj[id].i_itemNameRight[i] == this._snapShotObj[id].o_tablerow[j][1]){
		return j;
		}
	}
}
NonGenericObject.prototype.orderTable = function(){
//alert('orderTable')
}
