/******************************************************************************/
/******************************** NOVA VERSÃO *********************************/
var timerID = 0;
var tStart  = null;

function Start()
{
   tStart   = new Date();

   document.theTimer.Timer.value = "00:000";

   timerID  = setTimeout("UpdateTimer()", 500);
}

function Stop() 
{
   if(timerID) {
      clearTimeout(timerID);
      timerID  = 0;
	  document.theTimer.Timer.value = "00:000";
   }

   tStart = null;
}

function UpdateTimer() 
{
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }

   if(!tStart)
      tStart   = new Date();

   var   tDate = new Date();
   var   tDiff = tDate.getTime() - tStart.getTime();

   tDate.setTime(tDiff);

   document.theTimer.Timer.value = "" 
                                   + tDate.getSeconds() + ":" 
                                   + tDate.getMilliseconds();
                                   
   timerID = setTimeout("UpdateTimer()", 500);
}

/******************************************************/

function EM( obj )
{}

function AbrePrimeiroNivel( objLink, NomeDiv, GrupoConteudos )
{

	var arrGrupoConteudo = GrupoConteudos.split(',');
	
	for ( var i=0; i<arrGrupoConteudo.length; i++ )
	{
		var conteudo = "DivMenu" + arrGrupoConteudo[i];
		
		if ( conteudo != "" && conteudo != NomeDiv)
		{
			var classelk = 	conteudo.replace('DivMenu','lk');
			eval(classelk).className = eval(classelk).className.replace('Open','Closed');
			document.getElementById(conteudo).style.display='none';
		}
	}

	if ( NomeDiv != "" )
	{
		if ( document.getElementById(NomeDiv).style.display == 'block' || document.getElementById(NomeDiv).style.display == 'inline' )
		{	
			document.getElementById(NomeDiv).style.display='none';
			eval(objLink).className = eval(objLink).className.replace('Open','Closed');
		}
		else
		{	
			document.getElementById(NomeDiv).style.display='block';
			eval(objLink).className = eval(objLink).className.replace('Closed','Open');
		}
	}
	
}

/***********************************************************************************/

if(window.addEventListener)
{
    window.addEventListener("load",mladdevents,false);
}
else if(window.attachEvent)
{
    window.attachEvent("onload",mladdevents);
}
else
{
	window.onload = mladdevents;
}

function mladdevents()
{
	if(!window.mlrunShim)
	{
		window.mlrunShim = false;
	}

	var effects_a = new Array();
	var divs = document.getElementsByTagName('div');
	for(var j=0;j<divs.length;j++)
	{
		if(divs[j].className.indexOf('mlmenu') != -1)
		{
			divs[j].className = divs[j].className.replace('mlmenu','mlmenujs');
			divs[j].getElementsByTagName('ul')[0].className = divs[j].className;//just for reference
			var lis = divs[j].getElementsByTagName('li');
			for(var i =0;i<lis.length;i++)
			{
				lis[i].onmouseover = mlover;
				lis[i].onmouseout  = mloutSetTimeout;
				
				lis[i].getElementsByTagName('a')[0].className += 'first';
				
				var uls = lis[i].getElementsByTagName('ul');
				for(var k=0;k<uls.length;k++)
				{
					var found = 'no';
					for(var z=0;z<effects_a.length;z++)
					{
						if(effects_a[z] == uls[k])
						{
							found = 'yes';
						}
					}
					if(found == 'no')
					{
						effects_a[effects_a.length] = uls[k];
						uls[k].style.zIndex = '100';
						mlEffectLoad(uls[k]);
					}
				}
			}
		}
	}
}

function mloutSetTimeout(e)
{
	if(!e)
	{
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.toElement;
	if(reltg)
	{
		var under = ancestor(reltg,this);
		if(under === false && reltg != this)
		{
			window.mlLast = this;
			var parent = this.parentNode;
			while(parent.parentNode && parent.className.indexOf('mlmenujs') == -1)
			{
				parent = parent.parentNode;
			}
			if(parent.className.indexOf('delay') != -1)
			{
				window.mlTimeout = setTimeout(function(){mlout()},1000);
			}
			else
			{
				mlout();
			}
		}
	}
}

function mlout()
{
	if(window.mlLast==null)return false;
	var links = window.mlLast.getElementsByTagName('a');
	for(var i = 0;i<links.length;i++)
	{
		links[i].className = links[i].className.replace('hover','');
	}
	var uls = window.mlLast.getElementsByTagName('ul');
	var sib;
	for(var i=0;i<uls.length;i++)
	{
		mlEffectOut(uls[i]);
		window.mlLast.className += ' hide';
		window.mlLast.className = window.mlLast.className.replace('hide hide','hide');
		
	}
	window.lastover = null;
	return true;
}

function mlover(e)
{
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	the_e.cancelBubble = true;
	if(the_e.stopPropagation)
	{
		the_e.stopPropagation();
	}
	clearTimeout(window.mlTimeout);
	if(window.mlLast && window.mlLast != this && ancestor(this,window.mlLast) === false)
	{
		mlout();
	}
	else
	{
		window.mlLast = null;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.fromElement;
	var under = ancestor(reltg,this);
	if(under == false)
	{
		var hovered = byClass(this.parentNode,'hover','a');
		for(var i=0;i<hovered.length;i++)
		{
			if(ancestor(this,hovered[i].parentNode) == false){
				window.mlLast = hovered[i].parentNode;
				mlout();
			}
		}
		var ob = this.getElementsByTagName('ul');
		var link = this.getElementsByTagName('a')[0];
		link.className += ' hover';
		if(ob[0])
		{
			if(window.lastover != ob[0])
			{
				this.className = this.className.replace(/hide/g,'');
				mlEffectOver(ob[0],this);
				window.lastover = ob[0];
			}
		}
	}
}

function mlSetOpacity(ob,level)
{
	if(ob){
		var standard = level/10;
		var ie = level*10;
		ob.style.opacity = standard;
		ob.style.filter = "alpha(opacity="+ie+")"
	}
}

function mlEffectOver(ob,parent)
{
	setTimeout(function(){ob.style.display = 'block'},500);
	setTimeout(function(){ob.style.filter = ''},500);
	PosicionaDiv(ob);
}

function PosicionaDiv( ob )
{
	var windowedge = ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
	var TamJanela  = windowedge;
	var TamDiv	 = ob.offsetHeight;
	var PosicaoDiv = ob.offsetTop;
}

function mlEffectOut(ob)
{
	clearTimeout(window.fadeTime);
	setTimeout(function(){mlSetOpacity(ob,0)},500);
	setTimeout(function(){ob.style.display = 'none'},500);
	//mlSetOpacity(ob,0);
	//ob.style.display = 'none';
}

function mlEffectLoad(ob)
{
	var parent = ob.parentNode;
	while(parent.parentNode && parent.className.indexOf('mlmenu') == -1)
	{
		parent = parent.parentNode;
	}
	ob.style.display = 'none';
	mlSetOpacity(ob,0);
	ob.style.display = 'none';
}

function ancestor(child, parent)
{
	try
	{
		if(child==null)return false;
		for(; child.parentNode; child = child.parentNode){
				if(child.parentNode === parent) return true;
			}
		return false;
	}
	catch(error)
	{
		return false;
	}
}

function byClass(parent,c,tag)
{
	var all = parent.getElementsByTagName(tag);
	var returna = new Array();
	for(var i=0;i<all.length;i++)
	{
		if(all[i].className.indexOf(c) != -1)
		{
			returna[returna.length] = all[i]
		}
	}
	return returna;
}
