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=" + w;
	str += ",height=" + h;
	str+=",left=" + (screen.width-w)/2;
	str+=",top=" + (screen.height-h)/2;
	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, w, h);
}

function centerWindow(wnd, w, h)
{
	var mh = 100;           // default height
	var mw = 100;           // default width
  var timeout = 5000;
  var timer = 0;

  if( wnd == null )       // work with g_lastOpenedWnd
    wnd = g_lastOpenedWnd;

  if( wnd == null )
    return null;

  // wait for window creation
  try
  {
		while( wnd.document.readyState != 'complete' )
	  {
	    timer++;
	    if( timer > timeout )
	      return null;
	  }

		timer = 0;
		while( wnd.document.body == null )
	  {
	    timer++;
	    if( timer > timeout )
	      return null;
	  }
	}
	catch(e)
	{
	 return null;
	}

  // 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;
	  mw = oContainer.offsetWidth;

	  if( ("" + parseInt(w)) == w ) 		// we got a width
	  {
	  	if( w > mw )										// greatest than thes we computed ?
		  	mw = w;
	  }

		if( ("" + parseInt(h)) == h )
		{
			if( h > mh )
		  	mh = h;
		}

    mh = parseInt(mh) + parseInt(scrollHeight);
	  mw = parseInt(mw) + parseInt(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);
		}
	}
}
