var isNav, isIE, isNN6;
var MenuWidth = 200 ; 

if(parseInt(navigator.appVersion)>=4)
{
	if(navigator.appName=="Netscape")
	{
		isNav=true;
		if(document.getElementById) isNN6=true;
		else isNN6=false;
		
	}
	else isIE=true;
}



/**
	add by : hocnv@ssp.com.vn : 0908.411.811
	Xu ly : phần menu hide, show... 
*/
	function showMenuCommon(obj1)
	{	
		my_setcookie( obj1, 1, 1); 
		//alert( my_getcookie(obj1) );
		if (isIE) 
		{
			document.all[obj1].style.display = "inline";
		}
		else
		{
			document.getElementById([obj1]).style.display = "inline";
		}
		return;
	}
	function hideMenuCommon(obj1)
	{
		my_setcookie( obj1, 0, 1); 
		if (isIE) 
		{
			document.all[obj1].style.display = "none";			
		}
		else
		{
			document.getElementById([obj1]).style.display = "none";			
		}
	}


function initMenuCommon(obj1, menu_control_param )
{
		if (isIE) 
		{
			document.all[obj1].style.display = "inline";
		}
		else
		{
			document.getElementById([obj1]).style.display = "inline";
		}
		return;
	}

/**
	Kết thúc xử lý 
*/

var menuItems=new Array();
var menuItemProps=new Array();

var rootMenu=null;				// rootMenu
var timer;						// Timer.  Gives a pause before collapsing all menus.
var holdtime=0;					// Pause time before collapsing all menus.
var image;
var imageName;
//
function collapseRootMenu()
{

	if(rootMenu)
	{
		rootMenu.hide();
		rootMenu=null;
		collapseRootMenu()
		showStatus('')
	}
}
//
function openRootMenu(menu,left,top,z_index,image)
{
	if(rootMenu) collapseRootMenu();
	if(timer) clearTimeout(timer);

	if(menu)
	{
		rootMenu=menu;
		rootMenu.expand(left,top,z_index,image);
		rootMenu.show(image);
		imageName=image	
	}
}

function menuItemProp(width,bgcolor,highlightcolor,borderwidth,css_attributes)
{

	var id=menuItemProps.length;
	this.id=id;
	this.className="menuProp" + id;
	this.width=width;
	this.bgcolor=bgcolor;
	this.highlightcolor=highlightcolor;
	this.borderwidth=borderwidth;

	var styleStr="\n\n<STYLE TYPE='text/css'>\n";
	styleStr += "<!--\n";
	styleStr += "." + this.className + " {\n";
	for(var i in css_attributes)
	{
		styleStr += i + ": " + css_attributes[i] + ";\n";
	}
	styleStr += "}\n";
	styleStr += "// -->\n";
	styleStr += "</STYLE>\n";
 
	document.write(styleStr);
	
	menuItemProps[id]=this;// Add to global list of menuItemProps.
	
	return this;
}
function menuItem(label,onclick,props,sub_menu)
{
	var id=menuItems.length;
	var objTag="";

	if(isIE || isNN6)
	{
		objTag += "<div id=\"" + id + "\"";
		objTag += " class=\"" + props.className + "\"";
		objTag += " style=\"";
		objTag += " position: absolute;";
		objTag += " visibility: hidden;";
		objTag += " left: 20;";
		objTag += " top: 0;";
		objTag += " width: " + props.width + ";";
		objTag += " background-color: " + props.bgcolor +";";
		objTag += " filter: alpha(opacity=100)";
		objTag += " z-index: 0;";
		objTag += "\"";
		objTag += " onmouseover=\"menuItem_mouseover('" + id + "');\"";
		objTag += " onmouseout=\"menuItem_mouseout('" + id + "');\"";
		if(onclick)
		{
			objTag += " onclick=\"collapseRootMenu();" + onclick + "\"";
		}
		objTag += ">";
		if(sub_menu)
		{
			 objTag += "<img src=\"" + props.imagesrc + "\" border=\"0\" align=\"right\" width=\"" + props.imagewidth + "\" vspace=\"2\">"
		}
		objTag += label
		objTag += "</nobr></div>";
	}
	else
	if(isNav)
	{
		objTag += "<layer id=\"" + id + "\"";
		objTag += " class=\"" + props.className + "\"";
		objTag += " visibility=\"hidden\"";
		objTag += " left=0";
		objTag += " top=0";
		objTag += " width=" + props.width;
		objTag += " bgcolor=" + props.bgcolor;
		objTag += " z-index=0";
		objTag += " onmouseover=\"menuItem_mouseover('" + id + "');\"";
		objTag += " onmouseout=\"menuItem_mouseout('" + id + "');\"";
		if(onclick)
		{
			objTag += " onfocus=\"collapseRootMenu();" + onclick + "\"";
		}
		objTag += ">";
		if(sub_menu)
		{
			 objTag += "<img src=\"" + props.imagesrc + "\" border=\"0\" align=right width=\"" + props.imagewidth + "\" vspace=\"2\">"
		}
		objTag += "&#160;" + label
		objTag += "</layer>";
	}
	
	// Create object.
	document.write(objTag);

	this.obj=getMenuItem(id);	// Store a handle to the object we just created.
	this.id =id;
	this.menu=null;				// The menu that the menuItem belongs to.
	this.subMenu=sub_menu;		// A subMenu to display beneath the menuItem.
	
	// Save the display properties that we need.
	this.bgcolor=props.bgcolor;
	this.highlightcolor=props.highlightcolor;
	this.borderwidth=props.borderwidth;

	menuItems[id]=this;			// Add to global list of menuItems.
	return this;
}
function getMenuItem(id)
{
	if(isIE) return eval("document.all(\"" + id + "\")");
	else
	if(isNav)
	{
		if(isNN6) return document.getElementById(''.concat(id));
		else return eval("document.layers[\"" + id + "\"]");
	}
	return null;
}
function menuItem_mouseover(id)
{
	clearTimeout(timer);

	var currMenuItem=menuItems[id];
	var currMenu=currMenuItem.menu;
	var obj=currMenuItem.obj;

	currMenu.setActiveMenuItem(currMenuItem);
	// If another subMenu is open for the current menu, close it.
	if(currMenu.openSubMenu)
	{
		currMenu.openSubMenu.hide();
		currMenu.openSubMenu=null;
	}
	// If there is a subMenu associated with this menuItem, open it.
	if(currMenuItem.subMenu)
	{
		if(currMenuItem.subMenu.width <= 0 || currMenuItem.subMenu.height <= 0)
		{
			currMenuItem.subMenu.calculateDimensions();
		}
		// Determine position for subMenu based on position of menuItem and current menu's direction.
		var left, top, z_index;
		var objLeft, objTop, objWidth, objHeight, objZIndex;
		var pageLeft, pageRight, pageTop, pageBottom;
		if(isIE)
		{
			objLeft=obj.style.pixelLeft;
			objTop=obj.style.pixelTop;
			objWidth=obj.offsetWidth;
			objHeight=obj.offsetHeight;
			objZIndex=obj.style.zIndex;
			pageLeft=document.body.scrollLeft;
			pageRight=document.body.clientWidth + document.body.scrollLeft;
			pageTop=document.body.scrollTop;
			pageBottom=document.body.clientHeight + document.body.scrollTop;
		}
		else
		if(isNav)
		{
			objLeft=obj.left;
			objTop=obj.top;
			objWidth=obj.clip.width;
			objHeight=obj.clip.height;
			objZIndex=obj.zIndex;
			pageLeft=pageXOffset;
			pageRight=window.innerWidth + pageXOffset;
			pageTop=pageYOffset;
			pageBottom=window.innerHeight + pageYOffset;
		}
		//if (currMenu.direction == "right" && (objLeft + objWidth - 4 + currMenuItem.subMenu.width > pageRight)) {
		if(currMenu.direction == "right" && (objLeft + 80 + currMenuItem.subMenu.width > pageRight) && (objLeft - 80 + objWidth - currMenuItem.subMenu.width >= pageLeft))
		{
			currMenu.direction="left";
		}
		else
		if(currMenu.direction == "left" && (objLeft -80 < pageLeft) && (objLeft + 80 + currMenuItem.subMenu.width <= pageRight))
		{
			currMenu.direction="right";
		}
		currMenuItem.subMenu.direction=currMenu.direction;
		if(currMenu.direction == "right")
		{
			left=objLeft + 80;
		}
		else
		{
			left=objLeft - 80 + objWidth - currMenuItem.subMenu.width;
		}
		
		top=objTop + 20;
		while (top + currMenuItem.subMenu.height > pageBottom && top - objHeight + currMenuItem.borderwidth > pageTop) {
			top -= objHeight - currMenuItem.borderwidth;
		}
		z_index=objZIndex + 1;
		currMenuItem.subMenu.expand(left, top, z_index);
		currMenuItem.subMenu.show();
		currMenu.openSubMenu=currMenuItem.subMenu;
	}
}
function menuItem_mouseout()
{
	timer=setTimeout("collapseRootMenu();", holdtime);
}
function menu()
{
	this.menuItems=new Array();
	for(var i=0; i < menu.arguments.length; i++)
	{
		this.menuItems[i]=menu.arguments[i];
		menu.arguments[i].menu=this;
	}
	this.width=0;				// Overall width of menu.
	this.height=0;				// Overall height of menu.
	this.direction="right";		// Initially, all menus should go to the right.
	this.openSubMenu=null;		// Handle to any open subMenus.
	this.activeMenuItem=null;	// Handle to menuItem under cursor.
	this.show=menu_show;		// Method to display the menu.
	this.hide=menu_hide;		// Method to hide the menu.
	this.expand=menu_expand;	// Method to place menu at a specific position.
	
	this.calculateDimensions=menu_calculateDimensions;
	this.setActiveMenuItem=menu_setActiveMenuItem;

	return this;
}
function menu_calculateDimensions()
{
	var menuItemWidth=0;
	var menuItemHeight=0;
	
	for(var i=0; i < this.menuItems.length; i++)
	{
		var borderwidth=this.menuItems[i].borderwidth;
		var obj=this.menuItems[i].obj;
		if(isIE)
		{
			menuItemWidth=obj.offsetWidth;
			menuItemHeight=obj.offsetHeight - borderwidth;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				menuItemWidth=obj.offsetWidth;
				menuItemHeight=obj.offsetHeight - borderwidth;
			}
			else
			{
				menuItemWidth=obj.clip.width;
				menuItemHeight=obj.clip.height - borderwidth;
			}
		}
		this.width=menuItemWidth > this.width ? menuItemWidth : this.width;
		this.height += menuItemHeight;
	}
	if(isIE)
	{
		for(var i=0; i < this.menuItems.length; i++)
		{
			this.menuItems[i].obj.style.width=this.width;
		}	
	}
}
function menu_setActiveMenuItem(menuItem)
{
	if(this.activeMenuItem)
	{
		var obj=this.activeMenuItem.obj;
		var bgcolor=this.activeMenuItem.bgcolor;
		if(isIE)
		{
			obj.style.backgroundColor=bgcolor;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj= document.getElementById(''.concat(this.activeMenuItem.id));
				obj.style.backgroundColor=bgcolor;
			}
			else
			{
				obj.bgColor=bgcolor;
			}
		}
		this.activeMenuItem=null;
	}
	if(menuItem)
	{
		var obj=menuItem.obj;
		var highlightcolor=menuItem.highlightcolor
		if(isIE)
		{
			obj.style.backgroundColor=highlightcolor;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj= document.getElementById(''.concat(menuItem.id));
				obj.style.backgroundColor=highlightcolor;
			}
			else
			{
				obj.bgColor=highlightcolor;
			}
		}
		this.activeMenuItem=menuItem;
	}
}
function menu_expand(left, top, z_index)
{
	if(this.width <= 0 || this.height <= 0)
	{
		this.calculateDimensions();
	}
	for(var i=0; i < this.menuItems.length; i++)
	{
		var obj=this.menuItems[i].obj;
		var borderwidth=this.menuItems[i].borderwidth
		if(isIE)
		{
			obj.style.zIndex=z_index;
			obj.style.pixelLeft=left;
			obj.style.pixelTop=top;

			top += obj.offsetHeight - borderwidth;
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				obj.style.zIndex=z_index;
				obj.style.left=left;
				obj.style.top=top;
				top += obj.offsetHeight - borderwidth;
			}
			else
			{
				obj.zIndex=z_index;
				obj.moveTo(left, top);
				top += obj.clip.height - borderwidth;
			}
		}
	}
}
function menu_show()
{
	for(var i=0; i < this.menuItems.length; i++)
	{
		var obj=this.menuItems[i].obj;
		if(isIE)
		{
			obj.style.visibility="visible";
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				obj.style.visibility="visible";
			}
			else
			{
				obj.visibility="visible";
			}
		}
	}
}
function menu_hide()
{
	if(this.openSubMenu)
	{
		this.openSubMenu.hide();
		this.openSubMenu=null;
	}
	this.setActiveMenuItem(null);
	this.direction="right";
	for(var i=0; i < this.menuItems.length; i++)
	{
		var obj=this.menuItems[i].obj;
		if(isIE)
		{
			obj.style.visibility="hidden";
		}
		else
		if(isNav)
		{
			if(isNN6)
			{
				var obj=document.getElementById(''.concat(this.menuItems[i].id));
				obj.style.visibility="hidden";
			}
			else
			{
				obj.visibility="hidden";
			}
		}
	}
}
function showStatus(msg)
{
	window.status = msg;
	return true;
}

//--------------------------------------------------------------
/*
var isNav, isIE;
var MenuWidth = 160 ; 
if(parseInt(navigator.appVersion) >= 4)
{
	if(navigator.appName=="Netscape") isNav=true;
	else isIE=true;
}
*/

var msi_corp_website_style=new Array();
msi_corp_website_style["width"]= MenuWidth ;
msi_corp_website_style["color"]="#0066CC";
msi_corp_website_style["font-size"]="11px";
msi_corp_website_style["font-weight"]="normal";
msi_corp_website_style["font-style"]="normal";
msi_corp_website_style["font-family"]="Arial";
msi_corp_website_style["border-width"]=1;
msi_corp_website_style["border-color"]="#D4D5D6";
msi_corp_website_style["border-style"]="solid";
msi_corp_website_style["line-height"]="normal";
msi_corp_website_style["cursor"]="hand";
if(isIE) msi_corp_website_style['padding']=3;
else if(isNav) msi_corp_website_style['padding']=3;

var msi_corp_website_prop=new menuItemProp(
	MenuWidth ,									// width
	"#E6E6E6",								// bgcolor
	"#FFFFFF",								// highlightcolor
	1,										// borderwidth
	msi_corp_website_style
);

function getIExko(obj)
{
	if(obj==document.body) return obj.offsetLeft
	else return obj.offsetLeft+getIExko(obj.offsetParent);
}
function getIEyko(obj)
{
	if(obj==document.body) return obj.offsetTop
	else return obj.offsetTop+getIEyko(obj.offsetParent);
}
function Show(Name,MenuName)
{
	var MItem=document.getElementById('IDM_'.concat(Name));
	var width;
	if(isIE) width=MItem.offsetWidth;
	else if(isNav)
	{
		if(isNN6)
		{
			width=MenuWidth;
		}
		else
		{
			width=MenuWidth ;
		}
	}
	openRootMenu(MenuName,getIExko(MItem)+width+1,getIEyko(MItem)-23,0,Name);
}
function gotolink(str)
{
	window.location=str;
	window.status=str;
}


