/*  use ViewDom class for DOM compliant browsers */
function ViewDom(numberOfDays,rowCount,model,controller,error,numberOfColumnsOfResults,numberOfColumnsInResultsTable,numberOfRowsOfResults){
this._error = error;
this._numberOfColumnsOfResults = numberOfColumnsOfResults;
this._numberOfColumnsInResultsTable = numberOfColumnsInResultsTable;
this._numberOfRowsOfResults = numberOfRowsOfResults;
this._rowCount = rowCount;
this._numberOfDays = numberOfDays;
this._abstractview = new AbstractView(this,model,controller);
this._snapShotObj = new SnapShotObj(this._rowCount,this._numberOfColumnsOfResults,this._numberOfRowsOfResults);
this._validator = new Validator(this._abstractview,this._rowCount,this._error);
// initialise the styles for the results table (you can't dynamically change styles if they've been set in a stylesheet !)
//window.setStyles("#cccccc","#ffffff","#000000",this._numberOfColumnsOfResults,this._numberOfColumnsInResultsTable);
//this.aqquire();
}
ViewDom.prototype.aqquire = function(){
	this.modifyStyles();
	var c = 1;
	for(var d=0;d<this._numberOfDays;d++){
		var e = 0;
		while(document.getElementById("i_itemNameLeft"+d+"_"+e) != null){
			this._snapShotObj.i_itemLeft[c] = document.getElementById("i_itemLeft"+d+"_"+e+"").value;
			this._snapShotObj.i_itemNameLeft[c] = document.getElementById("i_itemNameLeft"+d+"_"+e+"").value;
			this._snapShotObj.i_itemRight[c] = document.getElementById("i_itemRight"+d+"_"+e+"").value;
			this._snapShotObj.i_itemNameRight[c] = document.getElementById("i_itemNameRight"+d+"_"+e+"").value;
			this._snapShotObj.i_itemLeftMirror[c] = document.getElementById("i_itemLeft"+d+"_"+e+"mirror").value;
			this._snapShotObj.i_itemRightMirror[c] = document.getElementById("i_itemRight"+d+"_"+e+"mirror").value;
			e++;
			c++;
		}
	}
	var numberOfColumnsOfResults = 2;
	for(var i=1;i<=this._snapShotObj._numberOfRowsOfResults;i++){
			for(var j=1;j<=this._numberOfColumnsOfResults;j++){
			this._snapShotObj.o_tablerow[i][j] = document.getElementById("o_a"+i+""+j).value;
			this._snapShotObj.o_tablerowMirror[i][j] = document.getElementById("o_a"+i+""+j+"mirror").value;
			}
		}
// delay the sending of the data using setTimeout() (notice the use of 'window' object with setTimeout()  )	
//delaySend = setInterval("delayIt(obj)",1200)
window.obj = this;	
//alert('go to delay send')	
var delaySend = setTimeout("delayIt(obj)",2000);
//this.send();
}
function delayIt(obj){
obj.send();
}
ViewDom.prototype.reset = function(){
this._abstractview.reset(this._snapShotObj);
}
ViewDom.prototype.update = function(updateObj){
this.decodeUpdateObj(updateObj);
}
ViewDom.prototype.send = function(){
this._validator.process(this._snapShotObj)
}
ViewDom.prototype.decodeUpdateObj = function(updateObj){
for(var i=1;i<=this._numberOfRowsOfResults;i++){
	for(var j=1;j<=this._numberOfColumnsOfResults;j++){
		document.getElementById("o_a"+i+""+j).value = updateObj.o_tablerow[i][j];
		document.getElementById("o_a"+i+""+j+"mirror").value = updateObj.o_tablerow[i][j];
		}
	}
/*for(var i=1;i<=this._rowCount;i++){
	// update mirrors so that they represent previous score entries
	document.getElementById("i_itemLeft"+i+"mirror").value = updateObj.i_itemLeft[i];
	document.getElementById("i_itemRight"+i+"mirror").value = updateObj.i_itemRight[i];
	}	
*/
var x=1;
for(var d=0;d<this._numberOfDays;d++){
	var e = 0;
	while(document.getElementById("i_itemLeft"+d+"_"+e+"mirror") != null){
		document.getElementById("i_itemLeft"+d+"_"+e+"mirror").value = updateObj.i_itemLeft[x];
		document.getElementById("i_itemRight"+d+"_"+e+"mirror").value = updateObj.i_itemRight[x];
		e++;
		x++;
		}
	}
// allow Update to be clicked again...
main._enable = true;
}
// show the user that the table has been updated by changing styles
ViewDom.prototype.modifyStyles = function(){
var numberOfColumnsOfResults = this._numberOfColumnsOfResults;
var numberOfColumnsInResultsTable = this._numberOfColumnsInResultsTable;
var numberOfRowsOfResults = this._numberOfRowsOfResults;
//var change = setTimeout("setStyles('#cc0000','#ffffff','#000000',numberOfColumnsOfResults,numberOfColumnsInResultsTable,numberOfRowsOfResults);",400);
//var change = setTimeout("setStyles('#cc0000','#ffffff','#333333',numberOfColumnsOfResults,numberOfColumnsInResultsTable,numberOfRowsOfResults);",800);
//var change = setTimeout("setStyles('#cc0000','#ffffff','#666666',numberOfColumnsOfResults,numberOfColumnsInResultsTable,numberOfRowsOfResults);",1200);
var change = setTimeout("setStyles('#cc0000','#ffffff','#000000',numberOfColumnsOfResults,numberOfColumnsInResultsTable,numberOfRowsOfResults);",1600);
var change = setTimeout("setStyles('#cc0000','#cc0000','#ffffff',numberOfColumnsOfResults,numberOfColumnsInResultsTable,numberOfRowsOfResults);",2000);
}
// I wanted 'setStyles' to be a method belonging to the ViewDOM class.
// It can't be, however, because it must be called from setTimeout()
function setStyles(col1,col2,col3,columnsInResults,columnsInTable,rowsInTable){
	for(var i=1;i<=rowsInTable;i++){
		for(var h=1;h<=columnsInResults;h++){
		if(i%2==0){
			this_row = document.getElementById("row"+i+h);
			//this_row.style.backgroundColor = col2;
			//this_row.style.borderColor = col2;
			this_row.style.color = col3;
			}
			else{
			this_row = document.getElementById("row"+i+h);
			//this_row.style.backgroundColor = col1;		
			//this_row.style.borderColor = col1;
			this_row.style.color = col3;
			}
		}
	for(var k=1;k<=columnsInResults;k++){
		if(i%2==0){
			this_row = document.getElementById("o_a"+i+k);
			//this_row.style.backgroundcolor = col2;
			//this_row.style.bordercolor = col2;
			this_row.style.color = col3;
			}
			else{
			this_row = document.getElementById("o_a"+i+k);
			//this_row.style.backgroundColor = col1;
			//this_row.style.borderColor = col1;
			this_row.style.color = col3;
			}
		}
	}
}
ViewDom.prototype.mailTo = function(obj){
this._sortQueryData = obj;
this._sortQueryData.saveString();
}
