﻿function smartRollover() {
	if (document.getElementsByTagName) {
		var bodyID = document.body.id;
		var images = document.getElementsByTagName("img");
		for (var i=0; i < images.length; i++) {
			if (bodyID && bodyID != ""
				&& images[i].getAttribute("src").match("/common/src/(ch|eng|jp)/images/g/" + bodyID + "[a-z]*_off.(jpg|gif)")) {
				images[i].setAttribute("src", images[i].getAttribute("src").replace("_off.", "_on."));
				break;
			}
		}
		for (var i=0; i < images.length; i++) {
			if (images[i].getAttribute("src").match("_off.(jpg|gif)"))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}
/*
function menuItemSelected(){
	var str = document.URL;
	var url = str.split("/");
	var lasturl = url[url.length-1] == "" ? url[url.length-2] : url[url.length-1];
	
	var id = lasturl.split(".");
	var lastId = id[0];
	if (lastId == "index") {
		lastId = url[url.length-2];
	}

	var item = document.getElementById(lastId);
	if (item) {
		item.className = "current";
		item.innerHTML = item.innerHTML.replace(/<.+?>/gim,'');
	}
}
*/

if (window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
	window.addEventListener("load", menuItemSelected, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", smartRollover);
	window.attachEvent("onload", menuItemSelected);
}


function menuItemSelected(){
	var str=document.URL;
	//首先拆分带参的		
	var middle=str.split("?");
	var param=middle[middle.length-1];

	if(document.getElementById(param)){
		document.getElementById(param).className="current";
		document.getElementById(param).innerHTML=document.getElementById(param).innerHTML.replace(/<.+?>/gim,'');
		return;	
	}

	if(param.indexOf("&")>-1){
		
		var finalParam=param.split("&");
		if(document.getElementById(finalParam[0])){
			document.getElementById(finalParam[0]).className="current";
			document.getElementById(finalParam[0]).innerHTML=document.getElementById(finalParam[0]).innerHTML.replace(/<.+?>/gim,'');
			return;
		}
	}else{
		var url=str.split("/");
		if(url[url.length-1].indexOf(".")>1){
			//如果截取的字符串是文件名		
			var lasturl = url[url.length-1];
			var id=url[url.length-1].split(".");
			var lastId=id[0];
	
			//判断链接过来的页面是如果是   index.html 或者 solution/XXX/XXX.html
			if(lastId=="index" || (!isNaN(lastId) && document.URL.match("(\\s|\\S)*/solution/\\w+/\\d+.html"))){
				var nextId=url[url.length-2];
				if(document.getElementById(nextId)){
					//设置该 li 为当前样式
					document.getElementById(nextId).className="current";
					//去掉该 li 的超链接
					document.getElementById(nextId).innerHTML=document.getElementById(nextId).innerHTML.replace(/<.+?>/gim,'');
					return;
				}
			}
			// 判断链接过来的页面是否在/solution/globalservices/case/ 下的，则选中id="case"的菜单项
			else if(document.URL.match("(\\s|\\S)*/solution/globalservices/case/(\\w+.html)?")){
				if(document.getElementById("case")){
					//设置该 li 为当前样式
					document.getElementById("case").className="current";
					//去掉该 li 的超链接
					document.getElementById("case").innerHTML=document.getElementById("case").innerHTML.replace(/<.+?>/gim,'');		
					return;
				}			
			}
			//链接过来的页面如果是目录的话
			else{
				if(document.getElementById(lastId)){
					//设置该 li 为当前样式
					document.getElementById(lastId).className="current";
					//去掉该 li 的超链接
					document.getElementById(lastId).innerHTML=document.getElementById(lastId).innerHTML.replace(/<.+?>/gim,'');		
					return;
				}			
			}
		}else{
			//如果截取的字符串是目录名
			var lasturl = url[url.length-2];
			var id=lasturl.split(".");
			var lastId=id[0];
			
			if(document.getElementById(lastId)){
				//设置该 li 为当前样式
				document.getElementById(lastId).className="current";
				//去掉该 li 的超链接
				document.getElementById(lastId).innerHTML=document.getElementById(lastId).innerHTML.replace(/<.+?>/gim,'');	
				return;
			}			
		}			
	}	
}