	// Functions.js
	
	/* START Pop-up Windows Script */

	function popup ( url, name, width, height, features, posx, posy )	{
		if ( posx.toLowerCase ( ) == "center" )
			posx = ( screen.width - width ) / 2;
		else if ( posx.toLowerCase ( ) == "right" )
			posx = (screen.width - width - 30);
		else if ( posx < 0 )
			posx = screen.width - width + posx;
		else 
			posx = 0;
	
		if ( posy.toLowerCase ( ) == "middle" )
			posy = ( screen.height - height ) / 2;
		else if ( posy.toLowerCase ( ) == "bottom" )
			posy = ( screen.height - height - 60 );
		else if ( posy < 0 )
			posx = screen.height - height - posy - 30;
		else 
			posy = 0;
	
		if ( features && features[0] != ',')
			features = ',' + features;
	
		newWindow = open ( url, name, 'width=' + width + ',height=' + height + ', screenX=' + posx + ',left=' + posx + ',screenY=' + posy + ',top=' + posy + features );

		return newWindow;
	}
	
	/* END Pop-up Windows Script */
	
	/* START SortTable Script */

	function sortTable ( column )	{
		var table = findParentNode ( column, 'table' );
		if ( table == null )
			return;
		var groups = table.getElementsByTagName ( 'tbody' );
		
		for ( var i = 0; i < groups.length; i++ )	{
			sortTableRows ( groups[i], column.parentNode.cellIndex );
		}
	}
	
	function sortTableRows ( group, col )	{
		var oRows = new Array ( );	//set the rows to be removed as an array of cloneNodes
		var iRows = new Array ( );	//set those rows' indexes as array

		for ( var c = 0; c < group.rows.length; c++ )	{
			oRows[c] = group.rows[c].cloneNode ( true );
			iRows[c] = group.rows[c].sectionRowIndex;
		}
		var oCol = new Array ( );			//set the string content of column cells as array
		var vCol = new Array ( );			//set the "compare" array for a future sort/reverse

		for ( c = 0; c < iRows.length; c++ )
			vCol[c] = oCol[c] = [group.rows[c].cells[col].firstChild.nodeValue,iRows[c]];

		oCol.sort ( );	//sorts the content array

		if ( vCol.toString ( ) == oCol.toString ( ) )
			oCol.reverse ( );	//if the content was already sorted, reverse

		for ( c = 0; c < group.rows.length; c++ )	{
			group.replaceChild ( oRows[oCol[c][1]], group.rows[c] );	//writes the rows in a sorted/reversed order
		}
	}

	/* END SortTable Script */

	/**********************************/
	/* BEGIN General Functions Script */
	/**********************************/
	
	function jumpTo ( url )	{
		document.location.href = url;
	}
	
	function anime ( id )	{
		if ( document.getElementById(id).style.display == 'none' )
			show ( id );
		else
			hide ( id );
	}
	
	function hide ( id )	{
		document.getElementById(id).style.display = 'none';
	}
	
	function show ( id )	{
		 document.getElementById(id).style.display = 'block';
	}
	
	function textChange ( id, text )	{
		var elem = document.getElementById ( id );
		if ( elem )
			elem.innerHTML = text;
	}
	
	function findParentNode ( el, parentName )	{
		while ( el.parentNode.nodeName.toLowerCase ( ) != parentName.toLowerCase ( ) && el.parentNode.nodeName.toLowerCase ( ) != 'body' )
			el = el.parentNode;

		if ( el.parentNode.nodeName.toLowerCase ( ) != parentName.toLowerCase ( ) )
			return null;
		else
			return el.parentNode;
	}
	
	/* END General Functions Script */
