var ecomFolder = '';

function TItem() {
  this.id       = 0;
  this.SubItem  = new Array();
  this.caption  = "";
  this.url      = "";
  this.objLayer = "";
  this.timeout  = "";
  // indica se é titulo
  this.title    = false;

//  this.AddSubItem = AddSubItem;
  this.ShowSubMenu = ShowSubMenu;
  this.HideSubMenu = HideSubMenu;
//  this.CreateSubMenu = CreateSubMenu;
}

/*function TSubItem() {
  this.id        = 0;
  this.caption   = "";
  this.url       = "";
}*/

function TMenu(t) {
  this.Item = new Array();
  this.AddItem = AddItem;
  this.AddTitle = AddTitle;
  this.Build   = Build;
//  this.ReloadPositions = ReloadPositions;
  this.type = t;  // tipo, que determina a cor do menu
  this.w    = null;
//  this.SetSubMenuWidth = SetSubMenuWidth;
}

function AddItem(caption, url) {
//  this.Item.push(new TItem());
  this.Item[this.Item.length] = new TItem();

  this.Item[this.Item.length - 1].id      = this.Item.length - 1;
  this.Item[this.Item.length - 1].caption = caption;
  this.Item[this.Item.length - 1].url     = url;
  this.Item[this.Item.length - 1].parentMenu = this;  // Guarda o objeto "pai" (parent) deste TItem (que é um objeto do tipo TMenu)
}

function AddTitle(caption) {
//  this.Item.push(new TItem());
  this.Item[this.Item.length] = new TItem();

  this.Item[this.Item.length - 1].id      = this.Item.length - 1;
  this.Item[this.Item.length - 1].caption = caption;
//  this.Item[this.Item.length - 1].url     = url;
  this.Item[this.Item.length - 1].title     = true;
  this.Item[this.Item.length - 1].parentMenu = this;  // Guarda o objeto "pai" (parent) deste TItem (que é um objeto do tipo TMenu)
}

/*function AddSubItem(caption, url) {
//  this.SubItem.push(new TSubItem());
  this.SubItem[this.SubItem.length] = new TSubItem();

  this.SubItem[this.SubItem.length - 1].id      = this.SubItem.length - 1;
  this.SubItem[this.SubItem.length - 1].caption = caption;
  this.SubItem[this.SubItem.length - 1].url     = url;
}*/

/*function CreateSubMenu(menu_id, submenu) {
  var tam = '';
  if (this.parentMenu.w != null) tam = 'width:' + this.parentMenu.w + 'px; ';
  
  document.writeln('<DIV id="' + menu_id + '" class="shadow_menu" style="position:absolute; z-index:1; ' + tam + 'left:0px; top:0px; visibility: hidden;">');
  document.writeln('<TABLE id="table_submenu" width="100%" class="submenu" border="0" cellpadding="4" cellspacing="1" bgcolor="#FFFFFF">');

  for (i = 0; i < this.SubItem.length; i++) {
    document.writeln('  <TR>');
    document.writeln('    <TD id="td_sub_' + (this.id+1) + '_' + (i+1) + '" bgcolor="#DBEEFF" class="menu_' + this.parentMenu.type + '_td_normal" OnMouseOver="SubOver(' + this.id + ', ' + i + ', \'menu_' + this.parentMenu.type + '_td_over\')" OnMouseOut="SubOut(' + this.id + ', ' + i + ', \'menu_' + this.parentMenu.type + '_td_normal\')" OnClick="document.location.href=\'' + this.SubItem[i].url + '\'">');
    document.writeln('      <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">');
    document.writeln('        <TR>');
    document.writeln('          <TD width="4"><IMG src="/img/spacer.gif"></TD>');
    document.writeln('          <TD><FONT class="font-small"><A href="' + this.SubItem[i].url + '" class="menu_' + this.parentMenu.type + '_lnk">' + this.SubItem[i].caption + '</A></FONT></TD>');
    document.writeln('        </TR>');
    document.writeln('      </TABLE>');
    document.writeln('    </TD>');
    document.writeln('  </TR>');
  }
  
  document.writeln('</TABLE>');
  document.writeln('</DIV>');

}*/

function SubOver(id_item, id_sub, cl) {
  var td;
  clearTimeout(menu.Item[id_item].timeout);
  td = document.getElementById('td_sub_' + (id_item+1) + '_' + (id_sub+1));
  //td.bgColor = '#CAE0FF';
  td.className = cl;
  td.style.cursor = 'hand';
}

function SubOut(id_item, id_sub, cl) {
  var td;
  menu.Item[id_item].HideSubMenu(id_item);
  td = document.getElementById('td_sub_' + (id_item+1) + '_' + (id_sub+1));
  //td.bgColor = '#E1EDFF';
  td.className = cl;
  td.style.cursor = 'default';
}

function ShowSubMenu(idx) {
  if (this.timeout != '') clearTimeout(this.timeout);
  this.timeout = setTimeout(('menu.Item[' + idx + '].objLayer.style.visibility="visible"'), 300);
}

function HideSubMenu(idx) {
  if (this.timeout != '') clearTimeout(this.timeout);
  this.timeout = setTimeout(('menu.Item[' + idx + '].objLayer.style.visibility="hidden"'), 300);
}

function MenuOver(td, cl) {
  td.className = cl;
  td.style.cursor = 'hand';
}

function MenuOut(td, cl) {
  td.className = cl;
  td.style.cursor = 'default';
}

function Build() {
  var i, m_over, m_out, src_seta, actions, label, css_class;

  document.writeln('<table width="158" border="0" cellpadding="0" cellspacing="0">');
  
  for (i = 0; i < this.Item.length; i++) {
    // Eventos mouse-over e mouse-out dos menus
    m_over = 'MenuOver(document.getElementById(\'td_menu_' + (i+1) + '\'), \'menu_left_td_over\')';
    m_out  = 'MenuOut(document.getElementById(\'td_menu_' + (i+1) + '\'), \'menu_left_td_normal\')';
    src_seta = 'spacer.gif';
	if (this.Item[i].SubItem != null) {
		if (this.Item[i].SubItem.length > 0) {
		  src_seta = 'seta_menu_left.gif';
		  m_over += ';menu.Item[' + i + '].ShowSubMenu(' + i + ')';
		  m_out  += ';menu.Item[' + i + '].HideSubMenu(' + i + ')';
		}
	}
	
	if (!this.Item[i].title) {
		actions = ' onMouseOver="' + m_over + '" onMouseOut="' + m_out + '" onClick="document.location.href=\'' + this.Item[i].url + '\'"';
		label   = '<A href="' + this.Item[i].url + '" class="menu_left_lnk">' + this.Item[i].caption + '</A>';
		css_class = 'menu_left_td_normal';
	} else {
		label   = '<FONT color="#FFFFFF"><B>' + this.Item[i].caption + '</B></FONT>';
		css_class = 'menu_left_td_title';
	}

    /*document.writeln('  <TR>');
	document.writeln('    <TD id="td_menu_' + (i+1) + '" class="' + css_class + '"' + actions + '>');
    document.writeln('      <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">');
    document.writeln('        <TR>');
    document.writeln('          <TD>');
	document.writeln('            <TABLE width="100%" border="0" cellspacing="0" cellpadding="0">');
    document.writeln('              <TR>');
    document.writeln('                <TD width="4"><IMG src="/ec/img/spacer.gif"></TD>');
    document.writeln('                <TD><FONT class="font-small">' + label + '</FONT></TD>');
    document.writeln('                <TD id="td_seta_' + (i+1) + '" width="1"><IMG name="seta_' + (i+1) + '" id="seta_' + (i+1) + '" src="/ec/img/' + src_seta + '"></TD>');
    document.writeln('              </TR>');
	document.writeln('            </TABLE>');
    document.writeln('          </TD>');
    document.writeln('        </TR>');
    document.writeln('  <TR>');
    document.writeln('    <TD><IMG src="/ec/img/pontilhado_menu_left.gif"></TD>');
    document.writeln('    </TD>');
    document.writeln('  </TR>');
    document.writeln('      </TABLE>');
    document.writeln('    </TD>');
    document.writeln('  </TR>');*/
	document.writeln('  <tr>');
	document.writeln('    <TD id="td_menu_' + (i+1) + '" class="' + css_class + '"' + actions + '><table width="100%"  border="0" cellspacing="0" cellpadding="5">');
	document.writeln('      <tr>');
	document.writeln('        <td width="6" align="right" valign="top"><img src="' + ecomFolder + '/ec/img/seta_menu_left.gif" width="3" height="9"></td>');
	document.writeln('        <td class="font-small"><a href="#" class="menu_left_lnk">' + label + '</a></td>');
	document.writeln('        <td width="2" align="right"><img src="' + ecomFolder + '/ec/img/spacer.gif" width="1" height="1"></td>');
	document.writeln('      </tr>');
	document.writeln('    </table></td>');
	document.writeln('  </tr>');
	document.writeln('  <tr>');
	document.writeln('    <td><img src="' + ecomFolder + '/ec/img/pontilhado_menu_left.gif" width="158" height="1"></td>');
	document.writeln('  </tr>');

	
  }

  document.writeln('</TABLE>');
  
  // Cria todos os layers de submenus:
  for (i = 0; i < this.Item.length; i++) {
    if (this.Item[i].SubItem != null) {
	if (this.Item[i].SubItem.length > 0) {
	  this.Item[i].CreateSubMenu('ly_submenu_' + (i+1), this.Item[i].SubItem);
	  this.Item[i].objLayer = document.getElementById('ly_submenu_' + (i+1));
	}
    }
  }

  document.close();
}
/*function Build() {
	var i, m_over, m_out, src_seta, actions, label, css_class;
	
	document.writeln('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#E7F0FF">');
	for (i = 0; i < this.Item.length; i++) {
		// Eventos mouse-over e mouse-out dos menus
		m_over = 'MenuOver(document.getElementById(\'td_menu_' + (i+1) + '\'), \'menu_left_td_over\')';
		m_out  = 'MenuOut(document.getElementById(\'td_menu_' + (i+1) + '\'), \'menu_left_td_normal\')';
		
		if (!this.Item[i].title) {
			actions = ' onMouseOver="' + m_over + '" onMouseOut="' + m_out + '" onClick="document.location.href=\'' + this.Item[i].url + '\'"';
			label   = '<A href="' + this.Item[i].url + '" class="menu_left_lnk">' + this.Item[i].caption + '</A>';
			css_class = 'menu_left_td_normal';
		} else {
			label   = '<FONT color="#FFFFFF"><B>' + this.Item[i].caption + '</B></FONT>';
			css_class = 'menu_left_td_title';
		}
		
		document.writeln('  <tr>');
		document.writeln('    <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">');
		document.writeln('      <tr>');
		document.writeln('        <td id="td_menu_' + (i+1) + '" ' + actions + ' width="6" align="right"><img src="/ec/img/seta_menu_left.gif" width="3" height="6"></td>');
		document.writeln('        <td class="font-small"><a href="#" class="menu_left_lnk">Terminologia</a></td>');
		document.writeln('      </tr>');
		document.writeln('    </table></td>');
		document.writeln('  </tr>');
		document.writeln('  <tr>');
		document.writeln('    <td><img src="/ec/img/pontilhado_menu_left.gif" width="158" height="1"></td>');
		document.writeln('  </tr>');
	}
	document.writeln('  <tr>');
	document.writeln('    <td>&nbsp;</td>');
	document.writeln('  </tr>');
	document.writeln('</table>');
}*/

/*function ReloadPositions() {
  for (i = 0; i < this.Item.length; i++) {
    if (this.Item[i].SubItem.length > 0) {
	  //document.getElementById('ly_submenu_' + (i+1)).style.left = GetSubMenuLeft(i+1);
  	  //document.getElementById('ly_submenu_' + (i+1)).style.top  = GetSubMenuTop(i+1);
	  this.Item[i].objLayer.style.left = GetSubMenuLeft(i+1);
  	  this.Item[i].objLayer.style.top  = GetSubMenuTop(i+1);
	}
  }
}*/

/*function GetSubMenuLeft(td_id) {
  var r_left = 0;
  r_left = document.getElementById('table_menu').offsetLeft;
//  r_left = r_left + document.getElementById('td_aux').offsetLeft;
//  r_left = r_left + document.getElementById('td_menu_' + td_id).offsetLeft;
  r_left = r_left + document.getElementById('td_seta_' + td_id).offsetLeft;
  r_left = r_left + 11;
  return r_left;
}

function GetSubMenuTop(td_id) {
  var r_top = 0;
//  alert(document.getElementById('td_content').offsetTop);
  r_top = r_top + document.getElementById('td_content').offsetTop;
//  r_top = r_top + document.getElementById('table_main').offsetTop;
//  r_top = r_top + document.getElementById('table_menu').offsetTop;
  r_top = r_top + document.getElementById('td_menu_' + td_id).offsetTop;
  r_top = r_top + 3;
  return r_top;
}*/

/*function SetSubMenuWidth(w) {
  this.w = w;
}*/