///////////////////////////////////////////
//■左メニューのカレント設定（第四階層まで）
///////////////////////////////////////////

/* --------------------------- */
/* ●動作可能チェック          */
/* --------------------------- */
//JavaSctiptやFlashが動作可能か調べる（古いブラウザは左メニューアクションをしない）
function JSorFlashError(){
 var flg = 0;
	var browser = navigator.appName;
	var version = navigator.appVersion;
	//Netscape（Safariは除外）
	if(browser.indexOf("Netscape") != -1){
		if((version.indexOf("Safari") == -1) && ((version.indexOf("3.") != -1)||(version.indexOf("4.") != -1))){
			flg = 1;
		}
	//Internet Explorer
	}else if(browser.indexOf("Explorer") != -1){
		if((version.indexOf("MSIE 5") != -1)||(version.indexOf("MSIE 4") != -1)||(browser.indexOf("MSIE 3") != -1)){
			flg = 1;
		}
	}else if(browser.indexOf("Opera") != -1){
		if((version.indexOf("Opera 5") != -1)||(browser.indexOf("Opera 6") != -1)){
			flg = 1;
		}
	}
	return(flg);
}
ScriptError = JSorFlashError();//動作可能環境判断

/*/////////////////////////////////////////
//左メニューの現在開いているページのボタンのスタイル変更
//開いているページに該当する左メニューの項目の背景色を変更
/////////////////////////////////////////*/
window.onload = function(){
	if(ScriptError == 0){
		submenuAction();
	}
}

/*/////////////////////////////////////////
現在開いているURLと同一の、#SIDEBAR内のliタグのスタイルを変更する。
/////////////////////////////////////////*/


//現在開いているページに該当する左メニューの背景色を変更
function submenuAction() {
	
	var thisURLpath = document.location.pathname;//開いているページのURL（パス）
	var thisURLhost = document.location.hostname;//開いているページのURL（ホスト）

	// パスの末尾がindex.htmlの時は、末尾を「/」にそろえる
	if(thisURLpath.indexOf("index.html") != -1){
		thisURLpath = thisURLpath.substring(0, thisURLpath.indexOf("index.html"));
	}
	
	//検索対象のID*************************************************************************
	var idname = 'SIDEBAR';
	
	// IDのSIDEBARがある場合
	if(document.getElementById(idname) != null){
		
		// #SIDEBAR内の該当するリンクがある親のLIを抽出
		var list = document.getElementById(idname).getElementsByTagName("li");
		
		// #SIDEBAR内のliタグの中のリンクを比較していく、該当するものが合った場合スタイルを変更
		for(i=0; i<list.length; i++){
			
			//liタグの中のリンクURLを抽出
			var href = list[i].getElementsByTagName("a")[0].getAttribute("href");
			
			/* リンクはブラウザによって出力結果が異なるのでまとめる */
			//リンクを補正：hrefはMozillaだとルートパスで返すが、IEはURLを返すのでMozilla形式にまとめる
			if(href.indexOf("/") != 0){
				href = href.substring(href.indexOf(thisURLhost) + thisURLhost.length, href.length);
			}
			
			//末尾が「/」ではない場合、末尾を「/」にそろえる
			if(href.lastIndexOf("/") != (href.length -1)){
				
				// URLパスの末尾がindex.htmlの時は、末尾を「/」にそろえる
				if(href.lastIndexOf("index.html") != -1){
					href = href.substring(0, href.indexOf("index.html"));
				}
				// ファイルの時（.がない時）は、末尾を「/」にそろえる
				else if(href.indexOf(".") == -1){
					href += "/";
				}
			}
			
			//URLとリンクを比較
			if(href == thisURLpath){
				
				// URLと一致したLIオブジェクト
				var this_li = list[i];
				
				// URLと一致したAオブジェクト
				var this_a = list[i].getElementsByTagName("a")[0];
				
				// URLと一致したSPANオブジェクト
				var this_span = list[i].getElementsByTagName("span")[0];
				
				
				/* liタグのスタイルを変更 */
				//if(thisURLpath.indexOf("/m_service/") != -1){
				//	alert(list[i].parentNode.parentNode.tagName);
				//}
				//カテゴリ内の第2階層以降のスタイルを変更
				if(! list[i].parentNode.parentNode.tagName.match(/DIV/i)){
					this_a.style.color = "#000000";
					this_a.style.textDecoration = "none";
					this_span.style.backgroundColor = "#ffffff";			
/*					this_span.style.backgroundImage = "url(/eda/image/sidbar_link_sub_this.gif)";*/
					this_span.style.backgroundRepeat = "no-repeat";
					//↓マウスアクションを表示させないようにするためのスタイル
					this_a.style.backgroundPositionX = "200px";	//IE用
					this_a.setAttribute("class", "sidebarthis");  //Mozilla用
				}
				
				//カテゴリ内の第1階層のスタイルを変更
				else{
					this_a.style.color = "#000000";
					this_a.style.textDecoration = "none";
					this_span.style.backgroundColor = "#ffffff";
/*					this_span.style.backgroundImage = "url(/eda/image/sidbar_link_this.gif)";*/
					this_span.style.backgroundRepeat = "no-repeat";
					//↓マウスアクションを表示させないようにするためのスタイル
					this_a.style.backgroundPositionX = "200px";	//IE用
					this_a.setAttribute("class", "sidebarthis");  //Mozilla用
				}
				//alert(	list[i].parentNode.innerHTML);
				
				break;
			}
			
		}
	}

	//検索対象のID グローバルメニュー：項目５個版*************************************************************************
	idname = 'MENU';
	// IDのMENUがある場合
	if(document.getElementById(idname) != null){
		
		// #MENU内の該当するリンクがある親のLIを抽出
		list = document.getElementById(idname).getElementsByTagName("li");
		
		// #MENU内のliタグの中のリンクを比較していく、該当するものが合った場合スタイルを変更
		for(i=0; i<list.length; i++){

			//liタグの中のリンクURLを抽出
			href = list[i].getElementsByTagName("a")[0].getAttribute("href");

			/* リンクはブラウザによって出力結果が異なるのでまとめる */
			//リンクを補正：hrefはMozillaだとルートパスで返すが、IEはURLを返すのでMozilla形式にまとめる
			if(href.indexOf("/") != 0){
				href = href.substring(href.indexOf(thisURLhost) + thisURLhost.length, href.length);
			}
			
			//末尾が「/」ではない場合、末尾を「/」にそろえる
			if(href.lastIndexOf("/") != (href.length -1)){
	
				// URLパスの末尾がindex.htmlの時は、末尾を「/」にそろえる
				if(href.lastIndexOf("index.html") != -1){
					href = href.substring(0, href.indexOf("index.html"));
				}
				// ファイルの時（.がない時）は、末尾を「/」にそろえる
				else if(href.indexOf(".") == -1){
					href += "/";
				}
			}
			
//			var page = thisURLpath;
			
			//URLとリンクを比較
//			if(href == thisURLpath){
			if(thisURLpath.indexOf(href) != -1){
				
				// URLと一致したLIオブジェクト
				this_li = list[i];
				
				// URLと一致したAオブジェクト
				this_a = list[i].getElementsByTagName("a")[0];

				// URLと一致したSPANオブジェクト
//				this_span = list[i].getElementsByTagName("span")[0];
				
				
				/* liタグのスタイルを変更 */
				//if(thisURLpath.indexOf("/m_service/") != -1){
				//	alert(list[i].parentNode.parentNode.tagName);
				//}
				//カテゴリ内の第2階層以降のスタイルを変更
				if(! list[i].parentNode.parentNode.tagName.match(/DIV/i)){
					this_a.style.color = "#000000";
					this_a.style.textDecoration = "none";
		//			this_span.style.backgroundColor = "#ffffff";
					this_a.style.backgroundImage = "url(/eda/image/menu_background_hover.gif)";
					this_a.style.backgroundRepeat = "no-repeat";
					//↓マウスアクションを表示させないようにするためのスタイル
//					this_a.style.backgroundPositionX = "200px";	//IE用
					this_a.setAttribute("class", "menuthis");  //Mozilla用
				}
				
				//カテゴリ内の第1階層のスタイルを変更
				else{
					this_a.style.color = "#000000";
					this_a.style.textDecoration = "none";
		//			this_a.style.fontWeight = "bold";
		//			this_span.style.backgroundColor = "#ffffff";
					this_a.style.backgroundImage = "url(/eda/image/menu_background_hover.gif)";
					this_a.style.backgroundRepeat = "no-repeat";
					//↓マウスアクションを表示させないようにするためのスタイル
//					this_a.style.backgroundPositionX = "200px";	//IE用
					this_a.setAttribute("class", "menuthis");  //Mozilla用
				}
				//alert(	list[i].parentNode.innerHTML);
				
				break;
			}
			
		}
	}


	//検索対象のID グローバルメニュー：項目６個版*************************************************************************
	idname = 'MENU2';
	// IDのMENUがある場合
	if(document.getElementById(idname) != null){
		
		// #MENU内の該当するリンクがある親のLIを抽出
		list = document.getElementById(idname).getElementsByTagName("li");
		
		// #MENU内のliタグの中のリンクを比較していく、該当するものが合った場合スタイルを変更
		/* for(i=0; i<list.length; i++){  //PRD修正 */ 
		for(i=(list.length - 1); i>=0; i--){

			//liタグの中のリンクURLを抽出
			href = list[i].getElementsByTagName("a")[0].getAttribute("href");

			/* リンクはブラウザによって出力結果が異なるのでまとめる */
			//リンクを補正：hrefはMozillaだとルートパスで返すが、IEはURLを返すのでMozilla形式にまとめる
			if(href.indexOf("/") != 0){
				href = href.substring(href.indexOf(thisURLhost) + thisURLhost.length, href.length);
			}
			
			//末尾が「/」ではない場合、末尾を「/」にそろえる
			if(href.lastIndexOf("/") != (href.length -1)){
	
				// URLパスの末尾がindex.htmlの時は、末尾を「/」にそろえる
				if(href.lastIndexOf("index.html") != -1){
					href = href.substring(0, href.indexOf("index.html"));
				}
				// ファイルの時（.がない時）は、末尾を「/」にそろえる
				else if(href.indexOf(".") == -1){
					href += "/";
				}
			}
			
//			var page = thisURLpath;
			
			//URLとリンクを比較
//			if(href == thisURLpath){
			if(thisURLpath.indexOf(href) != -1){
				
				// URLと一致したLIオブジェクト
				this_li = list[i];
				
				// URLと一致したAオブジェクト
				this_a = list[i].getElementsByTagName("a")[0];
				
				// URLと一致したSPANオブジェクト
//				this_span = list[i].getElementsByTagName("span")[0];
				
				
				/* liタグのスタイルを変更 */
				//if(thisURLpath.indexOf("/m_service/") != -1){
				//	alert(list[i].parentNode.parentNode.tagName);
				//}
				//カテゴリ内の第2階層以降のスタイルを変更
				if(! list[i].parentNode.parentNode.tagName.match(/DIV/i)){
					this_a.style.color = "#000000";
					this_a.style.textDecoration = "none";
		//			this_span.style.backgroundColor = "#ffffff";
					this_a.style.backgroundImage = "url(/eda/image/menu_background_hover2.gif)";
					this_a.style.backgroundRepeat = "no-repeat";
					//↓マウスアクションを表示させないようにするためのスタイル
//					this_a.style.backgroundPositionX = "200px";	//IE用
					this_a.setAttribute("class", "menuthis");  //Mozilla用
				}
				
				//カテゴリ内の第1階層のスタイルを変更
				else{
					this_a.style.color = "#000000";
					this_a.style.textDecoration = "none";
		//			this_a.style.fontWeight = "bold";
		//			this_span.style.backgroundColor = "#ffffff";
					this_a.style.backgroundImage = "url(/eda/image/menu_background_hover2.gif)";
					this_a.style.backgroundRepeat = "no-repeat";
					//↓マウスアクションを表示させないようにするためのスタイル
//					this_a.style.backgroundPositionX = "200px";	//IE用
					this_a.setAttribute("class", "menuthis");  //Mozilla用
				}
				//alert(	list[i].parentNode.innerHTML);
				
				break;
			}
			
		}
	}
}
