var ZINDEX=1;

function $(id)
{
	return document.getElementById(id);
}

function createElement(e /*html element*/, css /*css code*/, cls /* css class*/)
{
  var el=document.createElement(e);
	if (css) el.style.cssText=css;
	if (cls) el.className=cls;
	return el;
};
//Cria um objeto que dispara um evento onTimer, de tempos em tempos
function timer(tm)
{
  var me=this;
  var _initialized=false;

  this.interval=tm?tm:1000;
  this.isInitialized=function(){return _initialized}
  this.onTimer=function(owner){}

  this._onTimer=function()
  {
    if (!_initialized) return;
    me.onTimer();
    setTimeout(me._onTimer,me.interval);
  }

  //Inicializa o timer. flag indica se o evento onTimer será disparado de imediato ou será aguardado o intervalo definido
  this.start=function(flag /*boolean*/)
  {
    if (_initialized) return;
    _initialized=true;
    if (flag)
		  me._onTimer();
		else
		  setTimeout(me._onTimer, me.interval);
  }

  //Interrompe o timer
  this.stop=function()
  {
    _initialized=false;
  }
};
function rect(e,y,w,h)
{
  if (rect.arguments.length>1) return {left:e,top:y,width:w,height:h}
	var l=0, t=0, w=e.offsetWidth, h=e.offsetHeight, loff=0, toff=0;

	if (e.offsetParent)
	{
		while (e)
		{
			l += e.offsetLeft;
			t += e.offsetTop;
			//l -=e.scrollLeft;
			//t -=e.scrollTop
			e = e.offsetParent;			
		}
	}else{
    if (e.x) l += e.x;
    if (e.y) l += e.y;
  }
	if (parent!=window)
	{
	  //t -= toff;
		//l -= loff;
	}
	return {left:l,top:t,width:w,height:h}
}
String.prototype.replaceAll = function (token, newtoken){
	var s=this;
	while (s.indexOf(token)>=0)
	  s=s.split(token).join(newtoken);
	return s;
}
function addClass(el, cls)
{
	var s=el.className;
	s+='';
	s=s.replaceAll(cls, '');
	s=s+' '+cls;
	s=s.replaceAll('  ', ' ');
	el.className=s;
	return s;
}
function removeClass(el, cls)
{
	var s=''+el.className;
	s=s.replaceAll(cls, '');
	el.className=s;
	return s;
}
/*window.onload=function()
{  
	if (window.window_onload)
	  window_onload();
}*/
