//Browser detection code*********************************************************
				var IE4 = (document.all && !document.getElementById) ? true : false;
		        var NS4 = (document.layers) ? true : false;
		        var IE5 = (document.all && document.getElementById) ? true : false;
		        var N6 = (document.getElementById && !document.all) ? true : false;
//********************************************************************************

	var initcallcount=0;
	var firsttimegoingtofindfunction="true";
	var rownum=0;
	var cellnum=0;
	var cols=0;	
	

function init()
{
initcallcount+=1;
//Stores title values***************************************************************************
				for ( d = 0;d <= document.getElementById( globobject ).rows[0].cells.length-1;d++ )
				{
					if ( document.getElementById( globobject ).rows[0].cells[d].lastChild.nodeType == 1 )
					{
	titleArray[d]=document.getElementById( globobject ).rows[0].cells[d].lastChild;			
					}
					else
					{
	titleArray[d]=document.getElementById( globobject ).rows[0].cells[d].lastChild.nodeValue;
					}
				}
//**********************************************************************************************

if ( document.getElementById ( "toolbarmaintable" ) == null )
{
}
else
{
			for ( i = 0;i <= document.getElementById( "toolbarmaintable" ).rows[1].cells.length-1;i++ )
				{
				if ( document.getElementById( "toolbarmaintable" ).rows[1].cells[i].innerHTML.indexOf( "split" ) == "-1" )
					{
					cols=cols+1;
					}
				}
				var tempimg=document.getElementById( "remainingtd" ).getElementsByTagName( "IMG" );
}
				if ( sortswitch == 0 )
				{
				storecolumnnames( globobject, titleArray );
//create anchor tag for title row**************************************************************
				for ( g = 0;g <= document.getElementById( globobject ).rows[0].cells.length-1;g++ )
				{
					newtanchor=document.createElement( "A" );
					if ( initcallcount == 1 )
	{
						if ( document.getElementById( globobject ).rows[0].cells[g].lastChild.nodeType == 1 )
						{
	newtanchor.setAttribute( "href","javascript:sortTable('"+globobject+"','"+g+"')" );										
						newText=titleArray[g];
						newtanchor.appendChild( newText );
	document.getElementById( globobject ).rows[0].cells[g].appendChild( newtanchor );
						}
						else
						{
						document.getElementById(globobject).rows[0].cells[g].innerHTML="";
	newtanchor.setAttribute( "href","javascript:sortTable('"+globobject+"','"+g+"')" );										
						newText=document.createTextNode( titleArray[g] );
						newtanchor.appendChild( newText );
	document.getElementById( globobject ).rows[0].cells[g].appendChild( newtanchor );
						}
					}
				}
//**********************************************************************************************
				}
				
	temptitlerownode=document.createElement( "TR" );
			if ( IE4 || IE5 )
				{
				temptitlerownode.mergeAttributes( document.getElementById( globobject ).rows[0] );
				}
				else
				{
				//call the function which transfers attributes**********************
				transferattributes( document.getElementById( globobject ).rows[0],temptitlerownode );
				//******************************************************************
				}
	for( u = 0;u <= dupmaintable.rows[0].cells.length-1;u++ )
	{
	temptitlerownodecell=document.createElement("TD");
			if ( IE4 || IE5 )
				{
				temptitlerownodecell.mergeAttributes( document.getElementById( globobject ).rows[0].cells[u] );
				}
				else
				{
				//call the function which transfers attributes**********************
				transferattributes( document.getElementById( globobject ).rows[0].cells[u],temptitlerownodecell );
				//******************************************************************
				}
	temptitlerownode.appendChild( temptitlerownodecell );
	temptitlerownodecell.innerHTML=document.getElementById( globobject ).rows[0].cells[u].innerHTML;
	}
}

function storecolumnnames( objforfilter, titlearrayobj )
{
	var titlearray=titlearrayobj;
	for ( h = 0;h <= document.getElementById(objforfilter).rows[0].cells.length-1;h++ )
	{
				if ( document.getElementById( globobject ).rows[0].cells[h].lastChild.nodeType == 1 )
				{
columnnames[h]=titlearray[h].innerHTML;				
				}
				else
				{
columnnames[h]=titlearray[h];				
				}
	}
	
	for ( v = 0;v <= document.getElementById( "filtercol" ).options.length-1;v++ )
	{
	document.getElementById( "filtercol" ).options[v].value=columnnames[v];
	document.getElementById( "filtercol" ).options[v].innerHTML=columnnames[v];
	}
}

function hideotherdivs( divobj )
{
	for ( u = 0;u <= document.getElementById("alldivs").childNodes.length-1;u++ )
	{
		if ( ( document.getElementById( "alldivs" ).childNodes[u].nodeType == 1 ) && document.getElementById( "alldivs" ).childNodes[u].nodeName=="DIV" )
		{
		document.getElementById( "alldivs" ).childNodes[u].style.display="none";
		}
	}
	document.getElementById( divobj ).style.display="";
	
//Initialisations for find function************************************************	
		if ( rownum != 0 )
		{
		document.getElementById( globobject ).rows[rownum].cells[cellnum].innerHTML=tempval;
document.getElementById( "tdholdingtables" ).getElementsByTagName( "TABLE" )[0].rows[rownum].cells[cellnum].innerHTML=tempval;
		}
		if ( divobj == "finddiv" )
		{
		document.getElementById( "downdirection" ).setAttribute( "checked", "true" );
		}
		cellstartref=-1;
}


function refresh()
{
//Refreshes the cell with fresh original table when the user changes the column and opts to groupby again on that column*******************************************************************************
document.getElementById("tdholdingtables").replaceChild(dupmaintable,document.getElementById("tdholdingtables").getElementsByTagName("TABLE")[0]);
//*************************************************************************************************
	for ( s = 0; s<= document.getElementById("tdholdingtables").getElementsByTagName("TABLE")[0].rows[0].cells.length-1;s++ )
	{
	document.getElementById( "tdholdingtables" ).getElementsByTagName( "TABLE" )[0].rows[0].cells[s].innerHTML=temptitlerownode.getElementsByTagName( "TD" )[s].innerHTML;
	}
	for (t = 0;t <= document.getElementById( "tdholdingtables" ).getElementsByTagName("TABLE")[0].rows.length-1;t++ )
	{
	document.getElementById( "tdholdingtables" ).getElementsByTagName( "TABLE" )[0].rows[t].style.display="";
	}
	for ( u = 0;u <= document.getElementById( "alldivs" ).childNodes.length-1;u++ )
	{
		if ( ( document.getElementById( "alldivs" ).childNodes[u].nodeType == 1 ) && document.getElementById( "alldivs" ).childNodes[u].nodeName == "DIV" )
		{
		document.getElementById( "alldivs" ).childNodes[u].style.display="none";
		}
	}
}
