<!--

/**
* 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=auto'
	
		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;
	}
}

function TextAreaMax(o,max,text){
	if(o.value.length>=max){
		alert(text);
		o.value=o.value.substring(0,(max-1));
	}
}
/*
var debug_window=false;
function qdebug(para){
	if(!debug_window.document){
		debug_window=window.open("","debug_widow","width=800,height=640,scrollbars=yes");
	}
	debug_window.document.body.appendChild(Builder.node("div",["sss"]));
	Insertion.Top(debug_window.document.body,Builder.node("div",["sss"]));
}
*/
var shortcut_go;
var sc=false;
var sc_container=false;

function shortcut(url,ur2){
	/*qdebug(url);*/
	if(!sc){
		width=300;
		height=100;
		left=(screen.width-width)/2;
		
		sc=Builder.node('div',{'id':'shortcut2'});
		
		sc_container=Builder.node('div',{
			'id': 'shortcut',
			'style' : 'position:absolute;top:150px;width:'+width+'px;left:'+left+'px;background:#CCC;border:2px outset #999;display:none;padding:0px 0px 5px 0px;'
		},[sc]);
		
		document.body.appendChild(sc_container);
	}
		
	shortcut_close();
		
	new Ajax.Updater(sc,url,{
		evalScripts:true,onComplete:function(a){
			Element.show(sc_container);
			shortcut_go=ur2;
			$("sc_search_str_str").focus();
		}
	});	
		
}

function sc_open_page(id){
	window.location=shortcut_go+id;
}

function shortcut_close(){
	Element.hide(sc_container);
}

var rpc_login_url;
var lg_container;
var lg_container2;
function rpc_login(url){
	rpc_login_url=url;
	width=300;
	height=100;
	left=(screen.width-width)/2;
	
	lg=Builder.node('div',{'id':'rpc_login2'});
	
	lg_container=Builder.node('div',{
		'style' : 'position:absolute;top:0;width:'+screen.width+'px;height:100%;left:0px;background:#fff;display:none;-moz-opacity:0.7 ;filter:alpha(opacity: 70);opacity: 0.7'
	});
	lg_container2=Builder.node('div',{
		'style' : 'position:absolute;top:150px;width:'+width+'px;left:'+left+'px;background:#CCC;border:2px outset #999;padding:0px 0px 5px 0px;'
	},[lg]);
	
	document.body.appendChild(lg_container);
	document.body.appendChild(lg_container2);

	new Ajax.Updater(lg,url,{
		evalScripts:true,onComplete:function(a){
			Element.show(lg_container);
			$("rpc_pw").focus();
		}
	});	
		
}

function rpc_login_do(){
	new Ajax.Request(rpc_login_url, {postBody:Form.serialize(document.rpc_login),onComplete:function(a){
			if(a.responseText=='1'){
				Element.remove(lg_container);
				Element.remove(lg_container2);
				top.index_middle.set_session_countdown();
				Element.hide("rpc_login_err");
			}
			else {
				Element.show("rpc_login_err");
			}
		}});
}



//-->

