<!--

/**
* Common functions. 
*
* 'browser.js' should be included already.
*
* @package Api
* @subpackage JavaScript
*/

/*
* Shows text in statusbar of window.
*/
function statusText( txt )
{
	window.status = txt;
	
	return true;
}

/*
* Sets source of image.
*/
function setImg( img, newsrc )
{
	document.images[img].src = newsrc;
}

/*
* Sets HTML of some object.
*/
function setHTML( targetframe, obj_id, html )
{
	if ( ! IS_MOZ && ! IS_IE ) return;
	if ( ! targetframe ) return;
	
	var obj = targetframe.document.getElementById( obj_id );
	if ( ! obj ) return;
	
	obj.innerHTML = html;
}

function addScript( src ) 
{
	var script = document.createElement('script');
	script.setAttribute('src', src );
	script.setAttribute('language','Javascript');
	script.setAttribute('type','text/javascript');
	document.getElementsByTagName('head').item(0).appendChild(script);
}

function doReloadPage() 
{
	window.location = window.location;
}

function execRPC( url ) 
{
	addScript( url );
}

function toggle_div ( id ) 
{
	var obj = document.getElementById ( id );
	if ( !obj ) return;
	
	obj.style.visibility = ( obj.style.visibility == 'visible' ) ? 'hidden' : 'visible';
	obj.style.display = ( obj.style.display == 'block' ) ? 'none' : 'block';
}

/*
* Highlights/unhighlights cells of given table row.
*/
function setHighlight( row, state )
{
	if (( ! IS_MOZ && ! IS_IE ) || ! row ) return;
	
	// don't do anything if given row is selected already
	if ( row.cells[0].className.indexOf( 'selected' ) == -1 ) {
	
		// go through cells of row
		for ( var i = 0; i < row.cells.length; i++ ) {
			var className = row.cells[i].className;
			
			// highlight/unhighlight cell
			row.cells[i].className = ( 
				state == true ? 
				( className.indexOf( 'highlight' ) == -1 ? ( className + ' highlight' ) : className ) :
				className.replace( / highlight/, "" )
			);
		}
	}
}

if ( typeof openPopup == "undefined") {
	/*
	* Opens popup window in center of the screen.
	*/
	function openPopup( url, name, width, height, prop )
	{
		var left = Math.floor( screen.availWidth / 2 ) - Math.floor( width / 2 );
		var top = Math.floor( screen.availHeight / 2 ) - Math.floor( height / 2 );
		if ( ! prop ) prop = 'location=no,resizable=yes,menubar=no,status=yes,scrollbars=yes,dependent=yes'
	
		if ( typeof SID != "undefined" ) {
			url = url + (( url.indexOf ('?') > -1 ) ? '&' : '?') + SID;
		}
		
		var win = window.open( url, name, 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',' + prop );
			
		if ( win ) win.focus();
		
		return win;
	}
}

//-->
