/*/////////////////////////////////////////////////////////////////////////////////////////////////
	User's Guide
		Defalt JavaScript
 Modified : 2013-12-16
/////////////////////////////////////////////////////////////////////////////////////////////////*/


//form action 書き換え -------------------------------------
function searchAction(formAction){
	var searchAction = (!NotHTTP)? formAction.replace(/\.htm.?$/,".php") : formAction ;
	return searchAction;
}
// ---------------------------------------------------------


//桁揃え ----------------------------------------------------
function initAlign(n, digit) {
	var r = new String(n);
	var cnt = digit - r.length;
	if(cnt <= 0) return r;
	while (cnt-- > 0) r = "0" + r;
	return r;
}
// ---------------------------------------------------------


// ダイアログリサイズ幅 ------------------------------------
function dialogResizeMPW(t){
	var w = ($(t).css('padding-left').replace("px", "")*1)
		 + ($(t).css('padding-right').replace("px", "")*1)
		 + ($(t).css('margin-left').replace("px", "")*1)
		 + ($(t).css('margin-right').replace("px", "")*1);
	return w;
}
// ---------------------------------------------------------


// ダイアログリサイズ高さ -----------------------------------
function dialogResizeMPH(t){
	var h = ($(t).css('padding-top').replace("px", "")*1)
		 + ($(t).css('padding-bottom').replace("px", "")*1)
		 + ($(t).css('margin-top').replace("px", "")*1)
		 + ($(t).css('margin-bottom').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-titlebar').height())
		 + ($(t).parent().children('.ui-dialog-titlebar').css('padding-top').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-titlebar').css('padding-bottom').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-titlebar').css('margin-top').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-titlebar').css('margin-bottom').replace("px", "")*1)
		 + ($(t).parent().children('.dialogPbtn').height())
		 + ($(t).parent().children('.dialogPbtn').css('padding-top').replace("px", "")*1)
		 + ($(t).parent().children('.dialogPbtn').css('padding-bottom').replace("px", "")*1)
		 + ($(t).parent().children('.dialogPbtn').css('margin-top').replace("px", "")*1)
		 + ($(t).parent().children('.dialogPbtn').css('margin-bottom').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-buttonpane').height())
		 + ($(t).parent().children('.ui-dialog-buttonpane').css('padding-top').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-buttonpane').css('padding-bottom').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-buttonpane').css('margin-top').replace("px", "")*1)
		 + ($(t).parent().children('.ui-dialog-buttonpane').css('margin-bottom').replace("px", "")*1);
	return h;
}
// ---------------------------------------------------------


// プリント -----------------------------------------------
function printfnc(){
	headerTrim();//TipsなどのH5の中のスペース除去
	removeThead();//IE8のTHEAD削除
	setTimeout(function(){
		print();
	},500);
}
// ---------------------------------------------------------


// 左メニューツリー作成 ------------------------------------
function leftNaviFunc(target, level, collapsed){
	var treeLevel = level;
	var strlink = ', .opcl';//文字列も開閉動作させる
	if($(target).is('ul')){
		$(target).addClass('treeview');
	}else{
		$(target).children("ul").addClass('treeview');
	}
	if(collapsed==undefined) collapsed = true;
	excol = (collapsed)?'expandable':'collapsable';
	
	if((level+"").match(/[0-9]+/)){
		var tlevel = ''
		for(i=0; i<treeLevel; i++){
			$('ul.treeview > li'+tlevel).each(function(j){
				if($(this).children().is('ul')){
					$(this).children('span').addClass('opcl');
					$(this).addClass(excol).prepend('<div class="hitarea '+excol+'-hitarea"/>');
					$(this).filter(':last-child').addClass('last'+excol);
				}
			});
			tlevel += '>ul>li'
		}
	}else{
		var cLI = $('.treeview ul').closest("li");
		cLI.children('span').addClass('opcl');
		cLI.addClass(excol).prepend('<div class="hitarea '+excol+'-hitarea"/>');
		cLI.filter(':last-child').addClass('last'+excol);
	}
	
	var selmap = $('ul.treeview .selectedList').parents('li.expandable').map(function(){return this;}).get();
	for(i=0,len=selmap.length; i<len; i++){
		$(selmap[i]).removeClass('expandable').addClass('collapsable').removeClass('lastexpandable').addClass('lastcollapsable');
		$(selmap[i]).children('.hitarea').removeClass('expandable-hitarea').addClass('collapsable-hitarea');
		//$(selmap[i]).children('ul').show();
	}
	$('.hitarea'+strlink).click(function(){
		if($(this).parent('li').children().is('.expandable-hitarea')){
			$(this).parent('li').removeClass('expandable').addClass('collapsable');
			$(this).parent('li:last-child').removeClass('lastexpandable').addClass('lastcollapsable');
			$(this).parent('li').children('div').removeClass('expandable-hitarea').addClass('collapsable-hitarea');
			//$(this).nextAll('ul').show();
		}else{
			$(this).parent('li').removeClass('collapsable').addClass('expandable');
			$(this).parent('li:last-child').removeClass('lastCollapsable').addClass('lastexpandable');
			$(this).parent('li').children('div').removeClass('collapsable-hitarea').addClass('expandable-hitarea');
			//$(this).nextAll('ul').hide();
		}
	});
	$('#ExpandAll').click(function(){
		$('.treeview').find('.expandable').removeClass('expandable').addClass('collapsable');
		$('.treeview').find('.hitarea').removeClass('expandable-hitarea').addClass('collapsable-hitarea');
		$('.treeview').find('.lastexpandable').removeClass('lastexpandable').addClass('lastcollapsable');
	});
	$('#CollapseAll').click(function(){
		$('.treeview').find('.collapsable').removeClass('collapsable').addClass('expandable');
		$('.treeview').find('.hitarea').removeClass('collapsable-hitarea').addClass('expandable-hitarea');
		$('.treeview').find('.lastcollapsable').removeClass('lastcollapsable').addClass('lastexpandable');
	});
}
// ---------------------------------------------------------


// transLink -----------------------------------------------
function transLink(linkInfo){
	var messageText = confirm(textData.confirmLinkTxt);
	var path = linkInfo.load[0].page;
	if(messageText){
		//OK押下時の処理
		setTimeout(function(){location.href = path;},0);
	}else{
		//キャンセル押下時の処理
	}
}
// ---------------------------------------------------------




// hiligthKeyFunc -----------------------------------------------
function hiligthKeyFunc(targetEle){
	if(get['k']){
		var keyword = get['k'].split(' ');
		for(var i in keyword){
			if(keyword[i]){
				$(targetEle).keyHighlight(keyword[i]);
			}
		}
	}
}
// ---------------------------------------------------------

if(ua._isIE6){// IE6
	document.write('<script src="'+sharedPath+'/js/__default_ie6.js" type="text/javascript"></script>');
}else if(ua._isSafari1){// Safari 1
	document.write('<script src="'+sharedPath+'/js/__default_safari1.js" type="text/javascript"></script>');
}else if(ua._isSafari3_0low){// Safari 3.0以下
	document.write('<script src="'+sharedPath+'/js/__default_safari2.js" type="text/javascript"></script>');
}else{
	document.write('<script src="'+sharedPath+'/js/__default_latest.js" type="text/javascript"></script>');
}

$(function(){
	
	$('#crombsNavi > span:not(.frist)').before('<span class="toPrint">&gt;</span>');
	
	
//検索結果からページへ遷移したときキーをハイライト ----------------------------------------------------------------
	if(/^(id\d\d-|sh\d_|opkey_\d)/.test(thisFile)){
		//setTimeout(function(){
			hiligthKeyFunc('#container div.page, #opkey, #opkeyContents, #csCommonA');
		//}, 100);
	}
//-----------------------------------------------------------------------------------------------------------------
	
	
//検索窓 ----------------------------------------------------------------------------------
	if(!$('#searchKey').val()){
		$('#searchKey').val(textData.searchDefTxt);
	}
	$('#searchKey').after('<span id="searchBtn"></span>')
	  .focus(function(){
		if($(this).val() == textData.searchDefTxt){
			$(this).val('').addClass("keyIn");
		}else{
			$(this).addClass("keyIn");
		}
	  })
	  .blur(function(){
	  	$('#searchKey').val($(this).val().replace(/^\s+/, '').replace(/\s+$/,'').replace(/[　\s]+/g,' '));
		if(!$(this).val()){
			$('#searchKey').val(textData.searchDefTxt).removeClass("keyIn");
		}
	});
	
	$('#searchBtn').click(function(){ $('#search form').submit(); });
	$('#search form').submit(function(){
		var str = $('#searchKey').val();
		if((str==textData.searchDefTxt)||str==""){
			return false;
		}else{
			window.location =  searchAction($('#search form').attr('action')) +"?k="+encodeURIComponent($('#searchKey').val());
			return false;
		}
	});
	

	
//-----------------------------------------------------------------------------------------------------------------



//メニュー閉じ （表示外をクリックしたとき） ----------------------------------------------------------------------------------
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if(!$clicked.parents().is("#navigation")){
			$("#globalNavi .openList").removeShadow().hide().removeClass("openList");
			$('#globalNavi h3 span').removeClass("openMenu");
			mnInit = false;
		}
		if(!$clicked.children().parents().is("#c1style #leftNavi, #openBtn")){
			if($('#c1style #leftNavi').hasClass('open')) close_leftNavi();
		}
	});
//-----------------------------------------------------------------------------------------------------------------



//設定キーの説明 キーパスの表示非表示 ----------------------------------------------------------------------------------
	//if(/^sh3/i.test(thisFile)){
		$('div.keyPath h5').append('<span class="keyPathShow">&gt;&gt;'+textData.keyPathShow+'</span>');
		$('div.keyPath h5 span.keyPathShow').live('hover', function(){
				$(this).css('backgroundColor','#ffffcc');
			},function(){
				$(this).removeAttr('style');
			}
		).live('click', function(){
			if(ua._isIE6){
				pathShowHide(this);
			}else{
				$(this).parent('h5').next('.keyPathList').toggle();
			}
		});
		
		//if(ua._isIE6){
		//	$('span.keyPathShow').attr('onclick','');
		//}
	//}
//-----------------------------------------------------------------------------------------------------------------
	
	


//イラスト検索 ---------------------------------------------------------------------------------------------------
	if($('#contents').is(':has(#illustSearch)')){
		$('body').addClass('c1style');
		$('#searchType li, #isItem .item').hover(
			function(){ $(this).addClass('hover'); },
			function(){ $(this).removeClass('hover'); }
		);
		
		$('#searchType li .navi1').parent().addClass('active');
		isChengeItem('is1');
		$('#searchType > ul > li > span').click(function(){
			$('#searchType li').removeClass('active');
			$(this).parent().addClass('active');
			$(this).attr('class').match(/(^|\s+)(navi)(\d+)(\s+|$)/);
			isChengeItem('is'+RegExp.$3);
		});
		
		$('#isItem .item .dialog_link').click(function(){return false;});
		$('#isItem .item').click(function(){
			eval($(this).children('.image').children('.dialog_link').attr('onclick'));
			return false;
		});
		
	}
	
	function isChengeItem(i){
		$('#isItem > .pegeBreak').remove();
		$('#isItem > div').each(function(){
			if($(this).is('.'+i)){
				$(this).show();
			}else{
				$(this).hide();
			}
		});
		var fp,op;
		if(/^(ja|zh)/i.test(lang)){
			fp = 6;
			op = 8;
		}else{
			fp = 5;
			op = 7;
		}
		$('#isItem > div:visible').each(function(i,e){
			if((i==fp)||((i>fp)&&((i-fp)%op==0))){
				$(e).after("<div class='pegeBreak'>&nbsp;</div>");
			}
		});
	}
	
//-----------------------------------------------------------------------------------------------------------------





//ページトップへ ---------------------------------------------------------------------------------------------------
	$('#documentBody').append('<div id="returnToTop"><span title="' + textData.returnToTopTxt + '"></span></div>');
	$('#returnToTop span').click(function(){
		$(document).scrollTop(0);
	});
	$('#returnToTop span').hover(
		function(){ $(this).addClass('hover'); },
		function(){ $(this).removeClass('hover'); }
	)
	.mousedown(function(){ $(this).addClass('active'); })
	.mouseup(function(){ $(this).removeClass('active'); })
	.mouseout(function(){ $(this).removeClass('active'); });
//-----------------------------------------------------------------------------------------------------------------






//印刷ボタン ---------------------------------------------------------------------------------------------------
	if($('#container').is(':has(#faq), :has(#opkey)')){
		if(!thisFile.match(/^sh3_/)){
			$('#opkey .qitem > div.answer').each(function(e){
				if($(this).children('div').is('.dc')){
					$(this).children('.dc').children('p').children('.heading_sub').text(textData.detailPrintTxt).after('<span class="QaPrint"></span>');
				}else{
					$(this).append('<div class="thisPrint Item"><button class="disDetail" disabled="disabled"></button><button>' + textData.qaPrintTxt + '</button></div>');
					if(!$(this).is(':has(div[class=keyPath])')){
						if($(this).is(':has(div[class!=firstp] > a.dialog_link)')){
							$(this).children(".thisPrint").children("button:eq(1)").addClass('disQaPrint').attr('disabled',"disabled");
						}
					}
				}
			});
		}else{
			$('#opkey .qitem2 > div.answer > .accordion_contents').append('<div class="thisPrint Item"><button class="disDetail" disabled="disabled"></button><button>' + textData.qaPrintTxt + '</button></div>');
		}
		$('.dc .heading_sub').hover(
				function(){ $(this).addClass('heading_subhover'); },
				function(){ $(this).removeClass('heading_subhover'); }
		);
	}else if($('#container').is(':has(#csCommonA)')){
		//$('#container').prepend('<div id="thisPagePrint" class="thisPrint"><button>' + textData.pagePrintTxt + '</button></div>');
	}else{
		$('#container').prepend('<div id="thisPagePrint" class="thisPrint"><button>' + textData.pagePrintTxt + '</button></div>');
	}
	$('#illustSearch').prepend('<div id="thisPagePrint" class="thisPrint"><button>' + textData.pagePrintTxt + '</button></div>');
	$('#thisPagePrint button, .thisPrint button, .dc .QaPrint').hover(
		function(){ $(this).addClass('hover'); },
		function(){ $(this).removeClass('hover'); }
	);
	$('.thisPrint button:not(.disQaPrint), .dc .QaPrint, .dcbtn .QaPrint').live('click',function(){
		printfnc();
		return false;
	});

	
//-----------------------------------------------------------------------------------------------------------------






	if($("#documentBody").height() <= $(window).height()){
	//	$("#documentBody").css('min-height',  $(window).height()  + 'px');
	}




	//IE8のFixedがおかしいへの対応
	if(ua._isIE8){
		$(window).resize(function(){
			$('#returnToTop').removeAttr('style');
			$('#returnToTop').css('bottom', $('#returnToTop').css('bottom'));
		});
	}


});
///////////////////////////////////////////////////////////////////////////////////////////////////////








