var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


//JavaScript Document   	
function DataTable( parentId, Rows, Cols) {						
	
	//private functions and data	
	this.dataTableId = "dt" + parentId;			
	this.parentId = parentId;
	
	this.cols = Cols;
	this.rows = 0;
	this.selectedRow = 0;		
	
	this.columns = new Array(this.cols);
	for(var i=0; i<this.cols; ++i ){
		this.columns[i] = new Array();
		this.columns[i]["maxLength"] = 0;
		this.columns[i]["show"] = true;
		this.columns[i]["width"] = "100px";
		this.columns[i]["text-align"] = "left";	
	}
	
	this.internalData = new Array();
		
		
	//private
	this.initialNumOfRows = Rows;
	this.maintainInitialNumOfRows = true;
	this.getDefaultRowData = getDefaultRowData;
	
	this.firstBlankRowIndex= -1;			
	this.updateFirstBlankRowIndex = updateFirstBlankRowIndex;		
	
	this.rowStateBlank = -1;
	this.rowStateUnmodifiedData = 0;
	this.rowStateNew = 1;
	this.rowStateModified = 2;
	this.rowStateDeleted = 3;
			
	this.insertNewRow = insertNewRow;		
	this.addRowHelper = addRowHelper;
	this.updateRowByIndex = updateRowByIndex;		
	this.clearRowByIndex = clearRowByIndex;			
	this.deleteRowByIndex = deleteRowByIndex;	
	
	this.insertInternalData = insertInternalData;
	this.updateInternalData = updateInternalData;
	this.deleteInternalData = deleteInternalData;
	this.getInternalData = getInternalData;	
	
	this.cellSeparator = ",";
	this.rowSeparator = ";";
	this.convertArrayToString = convertArrayToString;
	this.convertArrayToStringRecur = convertArrayToStringRecur;
	
	this.defaultRowColor = "#FFFFFF";	
	this.highlightRow = false;
	this.hightlightRowColor = "#CCCCCC";
	this.selectionRowColor = "#E7F8FE";
		
	this.selectRowByIndex = selectRowByIndex;	
	this.clearSelection = clearSelection;	
		
	//public methods and properties	
	this.initializeTable = initializeTable;
	this.insertBlankRows = insertBlankRows;
	this.insertBlankRow = insertBlankRow;
	this.addRow = addRow;
	this.addRows = addRows;	//add multiple rows
	this.insertRow = insertRow;
	
	this.updateRow = updateRow;	
	
	this.deleteRow = deleteRow;	
	
	this.clearRow = clearRow;		
	this.clearAllRows = clearAllRows;
	this.clearTable = clearTable;	
		
	this.getRowData = getRowData;
	this.getRowDataString = getRowDataString;
	this.getRowDataAll = getRowDataAll;
	this.getRowDataAllString = getRowDataAllString;
	
	this.getTableData = getTableData;	
	this.getTableDataString = getTableDataString;
	this.getNumOfRows = getNumOfRows;
	this.getNumOfColumns = getNumOfColumns;
		
	this.allowDelete = false;
	
	this.backButton = null;
	this.nextButton = null;	
	this.setStateBackNextButtons = setStateBackNextButtons;
	this.setBackNextButtonsState = setBackNextButtonsState;
	this.totalRecords = 0;
	this.pageSize = this.initialNumOfRows;
	this.currentPageNumber = 0;
	this.pageCount = 0;	
	
	this.onRowSelectionChange = null;
	this.onDblClick = null;
	
    // this.onRowDoubleClick = null;
    // this.onRowKeyDown = null;
    // this.onRowKeyUp = null;    
     this.getHTMLRow = getHTMLRow;
	this.getHTMLCell = getHTMLCell;
	
	this.createTable = createTable;
} 


//display the table with rows
function createTable(display){	

	if( display == undefined )
		display = "";		
	
	var col_str = "";
	var total_width	= 0;
	for(var i=0; i<this.cols; ++i){
	//alert(i);
		// col_str += "<col width='" + this.columns[i]["width"] + "px' ";
		// col_str += "align=" + this.columns[i]["text-align"] + " />";
		// total_width += parseFloat( this.columns[i]["width"] );
	
		if( this.columns[i]["show"] == true){
			col_str += "<col width='" + this.columns[i]["width"] + "px' ";
			col_str += "align=" + this.columns[i]["text-align"] + " />";
			total_width += parseFloat( this.columns[i]["width"] );
		}
	}	
	
	var strTable = "";		
	strTable += "<table id=" + this.dataTableId + " width='" + total_width + "px' border=1px class='DataTable' style='display:" + display + ";' cellspacing='0' cellpadding='3'>";					
	strTable += col_str;

	/*	
	if( BrowserDetect.browser=="Firefox"){	
		strTable += "<thead style=display:none;>";
		strTable += "<tr>";
		for(var i=0; i<this.cols; ++i){
			strTable += "<td height=0px width='" + this.columns[i]["width"] + "px'></td>";
		}
		strTable += "</tr>";	
		strTable += "</thead>";
	}
	else {
		strTable += "<thead>";
		strTable += "</thead>";	
	}		
	*/
	
	strTable += "<tbody>";	
	strTable += "</tbody>";
	
	strTable += "<tfoot>";	  		 		
	strTable += "</tfoot>";	
	strTable += "</table>";
	
	var parent = document.getElementById(this.parentId);	
	parent.innerHTML = strTable;	
	parent.style.width = (total_width + 19) + "px";
	this.insertBlankRows(this.initialNumOfRows);	
}


//public : initialize table with initial values row data
function initializeTable( rowDataArray ){
	this.clearTable();
	
	if( ( rowDataArray != null && rowDataArray!=undefined )  && rowDataArray.length>0){
		for(var i=0; i<rowDataArray.length; ++i){
			if( rowDataArray[i]["rowState"] == this.rowStateDeleted ){
				this.insertInternalData( rowDataArray[i], -1, rowDataArray[i]["rowState"]);
			}
			else if( rowDataArray[i]["rowState"]==this.rowStateModified ){
				this.addRowHelper(rowDataArray[i], this.rowStateModified);
			}
			else if( rowDataArray[i]["rowState"]==this.rowStateNew ){
				this.addRowHelper(rowDataArray[i], this.rowStateNew);
			}
			else{
				this.addRowHelper(rowDataArray[i], this.rowStateUnmodifiedData);
			}	
		}
	}

	//TODO: //this should be called in clearRowByIndex or some clear function when multi row selection will be implemented for DataTable JS.
	this.onRowSelectionChange(null);

	this.setBackNextButtonsState();	
}

//public : insert new blank rows at specified index
function insertBlankRows(numOfRows, rowIndex){
	for( var i=0; i<numOfRows; ++i){		
		this.insertBlankRow(rowIndex);			
	}
}

//public : insert a single blank row at specified index
function insertBlankRow(rowIndex){
	this.insertNewRow(this.getDefaultRowData(), rowIndex, this.rowStateBlank );	
}

//public : add data to first blank row or  insert a new row and add data to it 
function addRow(rowData){   						
	this.addRowHelper( rowData, this.rowStateNew);	
}

//public : add rows
function addRows( rowDataArray ){   						
	if( rowDataArray != null && rowDataArray.length>0){
		for(var i=0; i<rowDataArray.length; ++i){
			this.addRowHelper(rowDataArray[i], this.rowStateNew);
		}
	}	
}

//private : add row helper , new rows may be added with initial values or new data
function addRowHelper(rowData, rowState){
	if( this.firstBlankRowIndex < this.rows ){					
		this.updateRowByIndex(rowData, this.firstBlankRowIndex, rowState);	// useFirstBlankRow(rowData);		
	}
	else{
		this.insertNewRow(rowData, -1, rowState);			
	}
}

//public : insert a new row at specified index with the data sent by user
function insertRow(rowData, rowIndex){
	this.insertNewRow(rowData, rowIndex, this.rowStateNew);	
}

//private : atrribute 0 when blank row or 1 when called with actual data
function insertInternalData(rowData, rowIndex, rowState ){	
	var newData = new Array();
		
	rowData["rowState"] = rowState;	
	
    newData["rowData"] = rowData;	
    newData["rowIndex"] = rowIndex;	
	newData["rowState"] = rowState;
	this.internalData.push(newData);	
}

function insertNewRow(rowData, rowIndex, rowState){	
	var newRow;
	var newCell;		
	tableObj=document.getElementById(this.dataTableId)

	if( rowIndex >= 0 ){
		tbody=tableObj.tBodies[0];	  
		newRow=tbody.insertRow(rowIndex);				
		this.insertInternalData( rowData, rowIndex, rowState);			
	} 
	else {
		tbody=tableObj.tBodies[0];	  
		newRow=tbody.insertRow(-1);				
		this.insertInternalData( rowData, newRow.rowIndex, rowState);			
	}	
			
	newRow.setAttribute("id", rowState);
	//newRow.style.overflow = "hidden";
	for( var i=0; i<this.cols ; ++i){
		newCell=newRow.insertCell(i);
		
		var cellData = new String(rowData[i]);
		if( cellData == "")	cellData = "&nbsp;";
		if( this.columns[i]["maxLength"] > 0 && cellData.length>this.columns[i]["maxLength"]){												
			cellData = cellData.substring(0, this.columns[i]["maxLength"]) + "...";						
		}
		
		if( this.columns[i]['show']==false){			
			newCell.style.display = "none";
		}
		
		newCell.innerHTML =  cellData;
	}   		
								
	newRow.onclick = selectRow;    
	newRow.onmouseover = changeRowColorOnMouseOver;
	newRow.onmouseout= changeRowColorOnMouseOut;
	newRow.onkeydown = selectRowOnKeyDown;	
	newRow.selectRow = selectRow;
	
    //newRow.ondoubleclick = rowDoubleClick; this.onRowDoubleClick;
    
    
	++this.rows;
	this.updateFirstBlankRowIndex();	
}

// function rowDoubleClick(){

// }

//private
function getDefaultRowData(){
	var dummyArray = new Array(this.cols);	
	for(var j=0; j<this.cols; ++j ){					
		dummyArray[j] = "" ;					
	}	
	return dummyArray;
}

//private : update first blank row index
function updateFirstBlankRowIndex(){
	var tbody = document.getElementById(this.dataTableId).tBodies[0];
	for( var i=0; i< tbody.rows.length; ++i){
		if( (tbody.rows[i]).getAttribute("id")==this.rowStateBlank){
			this.firstBlankRowIndex = i;
			return;
		}
	}
	
	this.firstBlankRowIndex = i;
}





//public : update row by index or selected row
function updateRow(rowData, rowIndex){
	if( rowIndex>=0 ){
		return this.updateRowByIndex(rowData, rowIndex, this.rowStateModified);	
	}
	else{
		return this.updateRowByIndex(rowData, -1, this.rowStateModified);	
	}
}

//private : update row by index
function updateInternalData(rowData, rowIndex, rowState){
	var updatedData = new Array();
	
	for( var i=0; i<this.internalData.length; ++i){
		if( rowIndex==this.internalData[i]["rowIndex"] && this.internalData[i]["rowState"]!=this.rowStateDeleted){						
			//newly added data cannot have modified state
			if( this.internalData[i]["rowState"]==this.rowStateNew && rowState==this.rowStateModified ){	
				rowData["rowState"] = this.rowStateNew;
				updatedData["rowState"] = this.rowStateNew;				
			}
			else{				
				rowData["rowState"] = rowState;
				updatedData["rowState"] = rowState;
			}			
			updatedData["rowIndex"] = rowIndex;
			updatedData["rowData"] = rowData;	
		
			this.internalData[i] = updatedData;			
			break;
		}
	}
}

function updateRowByIndex(rowData, rowIndex, rowState ){
	if( rowIndex>=0){
		if( rowIndex>=0 && this.rows>0 && rowIndex<this.rows){
			tBody=document.getElementById(this.dataTableId).tBodies[0];
			var currRow, columns;		
		
			currRow = tBody.rows.item(rowIndex);				
			currRow.setAttribute("id", rowState);
						
			this.updateInternalData(rowData, rowIndex, rowState);
						
			for( var i=0; i<this.cols ; ++i){			
				var cellData = new String(rowData[i]);
				if( cellData == "")	cellData = "&nbsp;";
				if( this.columns[i]["maxLength"] > 0 && cellData.length>this.columns[i]["maxLength"]){												
					cellData = cellData.substring(0, this.columns[i]["maxLength"]) + "...";						
				}
				currRow.cells[i].innerHTML = cellData;				
			}
			
			this.updateFirstBlankRowIndex();		
			return true;
		}
		else
			return false;	
	}
	else{
		if( !this.selectedRow ) {		
			return false;
		}
		
		var rowIndex = this.selectedRow.rowIndex;		
		return this.updateRowByIndex(rowData, rowIndex, rowState );
	}
}






//public : delete row
function deleteRow(rowIndex){
	if( rowIndex>=0 ){
		return this.deleteRowByIndex(rowIndex);	
	}
	else{
		return this.deleteRowByIndex(-1);	
	}
}

//private : delete data
function deleteInternalData( rowIndex ){
	for( var i=0; i<this.internalData.length; ++i){
		if( this.internalData[i]["rowState"] != this.rowStateDeleted ){
			if( this.internalData[i]["rowIndex"]>rowIndex ){
				--this.internalData[i]["rowIndex"];			
			}
			else if( this.internalData[i]["rowIndex"]==rowIndex){
				this.internalData[i]["rowState"] =this.rowStateDeleted;
				this.internalData[i]["rowData"]["rowState"] =this.rowStateDeleted;	
			}			
		}	
	}
}

//private : delete row by index
function deleteRowByIndex(rowIndex){
	if( rowIndex >=0){
		if( rowIndex>=0 && this.rows>0 && rowIndex<this.rows){
			tbody=document.getElementById(this.dataTableId).tBodies[0];
			
			if( this.selectedRow!=null && this.selectedRow.rowIndex==rowIndex ){  
				this.selectedRow.style.backgroundColor = this.defaultRowColor;
				this.selectedRow = null;
				this.onRowSelectionChange(null);
			}
			
			this.deleteInternalData(rowIndex);
			
			tbody.deleteRow( rowIndex );
			--this.rows;
			
			if( this.maintainInitialNumOfRows ){				
				if( this.rows < this.initialNumOfRows){				
					this.insertBlankRow();				
				}	
			}			
			
			this.updateFirstBlankRowIndex();		
			return true;
		}
		else
			return false;
	}
	else{
		if( !this.selectedRow ) {		
			return false;
		}
		
		var rowIndex = this.selectedRow.rowIndex;		
		return this.deleteRowByIndex( rowIndex );
	}	
}	

//private : clear row by index
function clearRowByIndex(rowIndex){
	if( rowIndex>=0 ){
		if( rowIndex>=0 && this.rows>0 && rowIndex<this.rows){		
			if( this.selectedRow != null && (this.selectedRow.rowIndex==rowIndex) ){  
				this.selectedRow.style.backgroundColor = this.defaultRowColor;
				this.selectedRow = null;
			}		
			
			return this.updateRowByIndex( this.getDefaultRowData(), rowIndex, this.rowStateBlank );
		}
		else
			return false;
	}
	else{
		if( !this.selectedRow ) {		
			return false;
		}
		
		var rowIndex = this.selectedRow.rowIndex;		
		return this.clearRowByIndex(rowIndex);
	}	
}

//public : clear row
function clearRow(rowIndex){
	if(rowIndex)
		this.clearRowByIndex(rowIndex);
	else
		this.clearRowByIndex(-1);
}

//public : clear all rows
function clearAllRows(){	
	for( var i=0; i<this.rows; ++i){
		this.clearRowByIndex(i);
	}								
}

function clearTable(){	
	for( var i=this.rows-1; i>this.initialNumOfRows-1; --i){		
		this.deleteRowByIndex(i);		
	}
    
	this.clearAllRows();	
	
	var clearedInternalData = new Array();
	for( var i=0; i<this.internalData.length; ++i){		
		if( this.internalData[i]["rowState"] != this.rowStateDeleted )
			clearedInternalData.push( this.internalData[i] );
	}
    
	this.selectedRow = null;	
	this.internalData = clearedInternalData;
}

	


//private
function getInternalData( rowIndex ){	
	for(var i=0; i<this.internalData.length; ++i){
		var rowData = this.internalData[i];					
		if( (rowData["rowIndex"]==rowIndex) && (rowData["rowState"]!=this.rowStateBlank) && (rowData["rowState"]!=this.rowStateDeleted) ){
			return rowData["rowData"];
		}
	}
	
	return null;
}

//private : for conversion from array to string
function convertArrayToString( rowData ){
	var rowDataString = "";	
	if ( rowData != null ){
		for(var i=0; i<rowData.length; ++i){
			rowDataString += (rowDataString==""?rowData[i]: this.cellSeparator + rowData[i]);
		}
		return rowDataString;
	}
	else
		return "";
}

function convertArrayToStringRecur( rowData, level ){
	var separator;	
	var arrayLevel;
	
	if( typeof(level)==undefined){
		arrayLevel = 1;
		separator = "X1Y";
	}	
	else{
		arrayLevel = level;
		separator = "X" + arrayLevel + "Y";
	}	
	
	var rowDataString = "";	
	if ( rowData != null ){
		for(var i=0; i<rowData.length; ++i){
			if( typeof(rowData[i])=="object" ){
				rowDataString += ( rowDataString==""? this.convertArrayToStringRecur(rowData[i], arrayLevel+1): separator + this.convertArrayToStringRecur(rowData[i], arrayLevel+1) );
			}	
			else{
				rowDataString += ( rowDataString==""? rowData[i]: separator + rowData[i] );
			}		
		}
		return rowDataString;
	}
	else
		return "";
}
	
//public : get row data based on index or selected row
function getRowData(rowIndex){
	if( rowIndex>=0 ){		
		if( rowIndex>=0 && this.rows>0 && rowIndex<this.rows){			
			return this.getInternalData(rowIndex);
		}	
	}
	else{
		if( !this.selectedRow ) {		
			return null;
		}
		
		var rowIndex = this.selectedRow.rowIndex;		
		return this.getInternalData(rowIndex);
	}	
}

//public : get row data in string format
function getRowDataString(rowIndex){	
	return this.convertArrayToString( this.getRowData(rowIndex) );
}

//public: return all data entered
function getRowDataAll(){
	var rowDataAll = new Array();
	
	for(var i=0; i<this.internalData.length; ++i){
		var rowData = this.internalData[i];			
		if( rowData["rowState"]!=this.rowStateBlank && rowData["rowState"]!=this.rowStateDeleted){					
			rowDataAll.push( rowData["rowData"]);			
		}
	}
	
	return rowDataAll;
}

//public : get row data all in string format
function getRowDataAllString(){
	var rowDataAll = this.getRowDataAll();		
	var rowDataAllString = "";
	
	if( rowDataAll.length>0 ){	
		for( var i=0; i<rowDataAll.length; ++i){			
			rowDataAllString += (rowDataAllString==""? this.convertArrayToString(rowDataAll[i]): (this.rowSeparator + this.convertArrayToString(rowDataAll[i])) );			
		}
		
		return 	rowDataAllString;
	}
	else
		return "";
}

//public : get table data all
function getTableData(){
	var rowDataAll = new Array();
	
	for(var i=0; i<this.internalData.length; ++i){
		var rowData = this.internalData[i];	        
		if( rowData["rowState"] != this.rowStateBlank ){
            var data = new Array();
            for( var j=0; j<rowData["rowData"].length; ++j ){
                data.push( rowData["rowData"][j] );
            }			
            data.push( rowData["rowState"] );    
            rowDataAll.push( data );	           			
		}
	}
	
	return rowDataAll;	
}

function getTableDataString(){
	var rowDataAll = this.getTableData();
	return this.convertArrayToStringRecur( rowDataAll, 0 );
}


//select row on click or by calling from object
function selectRow(){
	var objDataTable = eval((this.parentNode.parentNode).id);	 			
			
	if( objDataTable.selectedRow )
		objDataTable.selectedRow.style.backgroundColor=objDataTable.defaultRowColor;
		 
	objDataTable.selectedRow=this;	
	
	if( objDataTable.onRowSelectionChange ){
		if(	objDataTable.selectedRow.getAttribute("id")!=objDataTable.rowStateBlank){			
			objDataTable.onRowSelectionChange(objDataTable.getRowData());
		}	
		else
			objDataTable.onRowSelectionChange(null);
	}		
		 
	this.style.backgroundColor = objDataTable.selectionRowColor;
}


//select row on key down
function selectRowOnKeyDown(){
	var objDataTable = eval((this.parentNode.parentNode).id);	
	var currentTable = eval(this.parentElement.parentElement.id);
	
	if(event.keyCode==40 && currentTable.selectedRow.nextSibling){
		if(currentTable.selectedRow)
			currentTable.selectedRow.style.backgroundColor=objDataTable.defaultRowColor;
	
		currentTable.selectedRow=currentTable.selectedRow.nextSibling;
		currentTable.selectedRow.style.backgroundColor=objDataTable.selectionRowColor;
		if( currentTable.onRowSelectionChange ) 
			currentTable.onRowSelectionChange(objDataTable.getRowData());
	}
	else {
		if(event.keyCode==38 && currentTable.selectedRow.previousSibling){
			if(currentTable.selectedRow) 
				currentTable.selectedRow.style.backgroundColor=objDataTable.defaultRowColor;
			
			currentTable.selectedRow=currentTable.selectedRow.previousSibling;
			currentTable.selectedRow.style.backgroundColor=objDataTable.selectionRowColor;
			if( currentTable.onRowSelectionChange ) 
				currentTable.onRowSelectionChange(objDataTable.getRowData());
		}
	}	
}      		





//select row by index
function selectRowByIndex(rowIndex){
	//TODO : add code for validation of rowIndex here
	
	tableObj=document.getElementById(this.dataTableId)
	tbody=tableObj.tBodies[0];	  
	var row = tbody.rows.item(rowIndex);
	row.selectRow();
}


// debug  : clear selection  
function clearSelection(){
	if( !this.selectedRow )
		return false;	
		
	this.selectedRow.style.backgroundColor = this.defaultRowColor;
	this.selectedRow=null;
	
	return true;
}



//get number of rows in the data table
function getNumOfRows(){	
	return this.rows;
}

//get number of columns in the data table
function getNumOfColumns(){	
	return this.cols;
}

//call event handler for double click on row
function rowDoubleClick(){
	var objDataTable = eval((this.parentNode.parentNode).id);	
	
	if( objDataTable.selectedRow )
		if( objDataTable.doubleClick ) 
			objDataTable.doubleClick();
}


//change row color to highlight color on mouse over
function changeRowColorOnMouseOver(){
	var objDataTable = eval((this.parentNode.parentNode).id);	
	
	if( objDataTable.highlightRow )
		this.style.backgroundColor = objDataTable.hightlightRowColor;			 
}

//change row color back to default on mouse out
function changeRowColorOnMouseOut(){
	var objDataTable = eval((this.parentNode.parentNode).id);	
	
	if(this!=objDataTable.selectedRow)
		this.style.backgroundColor = objDataTable.defaultRowColor;
	else
		this.style.backgroundColor = objDataTable.selectionRowColor;		
}

//back next button state to be used with datatable
function setStateBackNextButtons( currentPage, pageCount){				
	if( currentPage <= 1) 
		this.backButton.disabled =true;
	else
		this.backButton.disabled =false;
			
	if( currentPage < pageCount )								
		this.nextButton.disabled =false;
	else
		this.nextButton.disabled =true;
}

//back next button state to be used with datatable
function setBackNextButtonsState(){
	if( this.backButton!=null ){				
		if( this.currentPageNumber <= 1) 
			this.backButton.disabled =true;
		else
			this.backButton.disabled =false;
	}
	
	if( this.nextButton!=null ){
		this.pageCount = this.totalRecords / this.pageSize;
		if( this.currentPageNumber < this.pageCount )								
			this.nextButton.disabled =false;
		else
			this.nextButton.disabled =true;
	}
}


function getHTMLRow( rowIndex ){	
	return document.getElementById(this.dataTableId).tBodies[0].rows.item(rowIndex);
}


function getHTMLCell( rowIndex, colIndex ){
	return document.getElementById(this.dataTableId).tBodies[0].rows[rowIndex].cells[colIndex];
}
