
//====================================================================
// Nav.js 页面导航部分客户端脚本
//=====================================================================
//
// 函数列表
//
// 1) getCookie					- 获取 Cookie 变量
// 2) setCookie					- 设置 Cookie 变量
// 3) subMenuOnclick			- 子菜单单击事件
// 4) MenuOnclick				- 主菜单单击事件
// 5) hidePageSubMenu			- 隐藏子菜单
// 6) showPageSubMenu			- 显示子菜单
// 7) MenuMouseOut				- 按钮在光标移出时
// 8) MenuMouseOver				- 按钮在光标悬停时
// 9) SetSelectedMenuBar		- 根据参数设置当前选中的菜单



//-------------------------------------------
// 全局变量
//-------------------------------------------

// 全路径
var BaseUrl = document.URL.substring(0,document.URL.lastIndexOf("/")+1);
// 当前选中的主菜单
var SelectedHeightLightTD = "";



//-------------------------------------------
// 获取 Cookie 变量
// c_name - Cookie 的名称
//-------------------------------------------
//
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		var c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 ;
			var c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}



//----------------------------------------------
// 设置 Cookie 变量
// c_name - Cookie 的名称
// value  - Cookie 的值
// expiredays - Cookie 的过期时间
//----------------------------------------------
//
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	//alert(c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()));
}


	
//----------------------------------------------
// 子菜单单击事件
// oA - HTML连接对象
//----------------------------------------------
//
function subMenuOnclick(event,oA)
{
	event = event || window.event;
	if (oA == null) {oA = event.srcElement || event.target;}
	if (oA.tagName != "A") return;
	if (oA.parentNode.parentNode.getAttribute("isSubMenu") != "1") return;

	//alert(oA.id.substring(6) + " " + oA.href);

	// 在HREF的后面添加 MENUBARID
	if (oA.href.indexOf("?") > 0)
	{
		oA.href = oA.href + "&MENUBARID=" + oA.id.substring(6);
	}
	else
	{
		oA.href = oA.href + "?MENUBARID=" + oA.id.substring(6);
	}
	
	//oA.target = "iframeContainer";		
}



//----------------------------------------------
// 主菜单单击事件
// oTD - HTML TD对象
//----------------------------------------------
//
function MenuOnclick(event, oTD)
{
	event = event || window.event;
	if (oTD == null){oTD = event.srcElement || event.target;}
	if (oTD.tagName!="TD" )return;
	if (oTD.parentNode.getAttribute("isMenu") != "1") return;
	if (oTD.getAttribute("href") == null || oTD.getAttribute("href")=="") return;
	
	//显示页面
	document.location.href = oTD.getAttribute("href");

}
	


//----------------------------------------------
// 隐藏子菜单
// oTD - HTML TD对象
//----------------------------------------------
//
function hidePageSubMenu(oTD)
{
	//隐藏子菜单
	var sSubMenuID = oTD.getAttribute("subMenuID");
	if (sSubMenuID == null || sSubMenuID =="") return;
	var oSubMenu = document.getElementById(sSubMenuID);
	if (oSubMenu==null)
	{
		alert("SubMenu:" + sSubMenuID + " is not found.");
	}
	else
	{
		oSubMenu.style.display = "none";
	}
}



//----------------------------------------------
// 显示子菜单
// oTD - HTML TD对象
//----------------------------------------------
//
function showPageSubMenu(oTD)
{
	//显示子菜单
	var sSubMenuID = oTD.getAttribute("subMenuID");
	if (sSubMenuID == null || sSubMenuID =="") return;
	var oSubMenu = document.getElementById(sSubMenuID);
	if (oSubMenu==null)
	{
		alert("SubMenu:" + sSubMenuID + " is not found.");
		return;
	}
	else
	{
		//oSubMenu.style.display = "";
		oSubMenu.className = "subMenuShow";
	}

}



//----------------------------------------------
// 按钮在光标移出时
// oTD - HTML TD对象
//----------------------------------------------
//
function MenuMouseOut(event,oTD)
{
	event = event || window.event;
	if (oTD == null){oTD = event.srcElement || event.target;}
	if (oTD.tagName!="TD") return;
	if (oTD.parentNode.getAttribute("isMenu") != "1") return;
	
	if (SelectedHeightLightTD == oTD) return;

	if (oTD.getAttribute("href")=="About China VentureDatabase.asp")//当该TD是HELP的导航时显示宽度为110的图片
	{
		oTD.className = "pMenuHelp";
	}
	else
	{	
		oTD.className = "pMenu";
	}
}



//----------------------------------------------
// 按钮在光标悬停时
// oTD - HTML TD对象
//----------------------------------------------
//
function MenuMouseOver(event,oTD)
{
	event = event || window.event;
	if (oTD == null){oTD = event.srcElement || event.target;}
	if (oTD.tagName!="TD") return;
	if (oTD.parentNode.getAttribute("isMenu") != "1") return;

	if (SelectedHeightLightTD == oTD) return;
	if (oTD.getAttribute("href")=="About China VentureDatabase.asp")//当该TD是HELP的导航时显示宽度为110的图片
	{
		oTD.className = "pMenuOnMouseOverHelp";
	}
	else
	{	
		oTD.className = "pMenuOnMouseOver";
	}

	if (oTD.title=="")
	{
		if (oTD.getAttribute("href")!=null)
		{
				oTD.title=oTD.getAttribute("href");
		}
	}
}


//----------------------------------------------
// 根据参数设定当前选中的菜单
// sMenuBarId - 当前选中的菜单ID
//----------------------------------------------
//
function SetSelectedMenuBar(sMenuBarId)
{

	if (sMenuBarId == null || sMenuBarId == "") return;

	// 获得主菜单ID 和 子菜单ID
	var sMainId = "mainbar" + sMenuBarId.substring(0, 2);
	var sSubId = "subbar" + sMenuBarId;
	
	// 获得主菜单对象
	var oMainBar = document.getElementById(sMainId);
	if (oMainBar == null) return;
	// 高亮显示主菜单
	SelectedHeightLightTD = oMainBar;
	oMainBar.className = "pMenuOnMouseClick";

	// 显示子菜单
	showPageSubMenu(oMainBar);

	// 获得子菜单对象
	var oSubBar = document.getElementById(sSubId);
	if (oSubBar == null) return;
	// 高亮显示子菜单
	oSubBar.className = "subMenuLinkH";

}
