var g_activeEl;
var g_ID_COUNT = 0;
var g_modalChild;
var g_lastOpenedWnd = null;

function getAutoId()
{
	g_ID_COUNT++;
	return "JSID_"+g_ID_COUNT;
}

function openHelpWnd(url)
{
 window.open(url,'help','resizable=yes,scrollbars=yes,menubar=no,status=no,toolbar=no,left=0,top=0,width=800,height=600');
}

function openCenterWnd(url,name,w,h,size,scroll)
{
  var str ="width=100,height=100";
	str+=",left=4000";
	str+=",top=4000";
	str+=",resizable=" + ((size) ? "yes" : "no");
	str+=",scrollbars=" + ((scroll) ? "yes" : "no");
	str +=",menubar=no,status=no,toolbar=no";
	g_lastOpenedWnd = window.open(url,name,str);
  g_lastOpenedWnd.opener = window;

  return centerWindow(g_lastOpenedWnd);
}

function centerWindow(wnd)
{
	var mh = 100;           // default height
	var mw = 100;           // default width
  var timeout = 50000;
  var timer = 0;

  if( wnd == null )       // work with g_lastOpenedWnd
    wnd = g_lastOpenedWnd;

  if( wnd == null )
    return null;

  // wait for window creation
  while( wnd.document.body == null )
  {
    timer++;
    if( timer > timeout )
      break;
  }

  timer = 0;
  while( wnd.document.readyState != 'complete' )
  {
    timer++;
    if( timer > timeout )
      break;
  }

  // window border size
	var scrollWidth = wnd.document.body.offsetWidth-wnd.document.body.clientWidth;
	var scrollHeight = wnd.document.body.offsetHeight-wnd.document.body.clientHeight;
	scrollWidth = scrollWidth + scrollWidth/2;

	if( scrollHeight < 38 )				// 38 = Scroolbar value under Windows XP
		scrollHeight = 38;

	if( scrollWidth < 29 )				// 29 = Scroolbar value under Windows XP
		scrollWidth = 29;

	var oContainer = wnd.document.body.firstChild;
	if( oContainer != null )
	{
	  mh = oContainer.offsetHeight + scrollHeight;
	  mw = oContainer.offsetWidth + scrollWidth;
  }
  else   // no container...maybe a post, we need to wait a little more
  {
    setTimeout("centerWindow();", 500);
  }

	if( mh > screen.height )
		mh = screen.height;

	if( mw > screen.width )
		mw = screen.width;

	wnd.resizeTo(mw,mh);
	wnd.moveTo((screen.width/2)-(mw/2) ,(screen.height/2)-(mh/2));

	return wnd;
}

function heritFrom(obj)
{
	var fromObj = obj;
	var toObj = heritFrom.caller;
	toObj.prototype.Super = fromObj;
	for(var i in fromObj.prototype)
		if(!eval("toObj.prototype."+i))
				eval("toObj.prototype."+i+"=fromObj.prototype."+i);
		else
				eval("toObj.prototype.Super_"+i+"=fromObj.prototype."+i);
}

//generic component initialization
function NPComponentInit(lstFct)
{
	var elm;
	var fct;
	var param;

	for(var i=0;i<lstFct.size();i++)
	{
		elm = lstFct[i];

		if(elm && elm.size() == 2)
		{
			fct = elm[0];
			param = elm[1];
			if(fct) fct(param);
		}
	}
}
