//---
//添付ファイルD/L
function doDLFile(aNum)
{
	with(document.forms[0])//富士は検索フォームがないのでダウンロードはforms[0]
	{
		dlnum.value = aNum;
		command.value = 'download';
		submit();
	}
}



//==============
//google サイト内検索
//-------
var gGoogleSiteSeatchGuideStr= ' Google検索';//googlesearchのテキストフィールドのcolor/valueとおなじであること

function showHideGSGuide(txtFldObj,bShow)
{
	if(!txtFldObj){
		return;
	}
	if(bShow){
		if(txtFldObj.value == ''){
			document.getElementById('q').style.backgroundImage = 'url(img/common/search_window_bg.gif)';
		}
		else{
			document.getElementById('q').style.backgroundImage = 'none';
		}
	}
	else{
		if(txtFldObj.value == ''){
			document.getElementById('q').style.backgroundImage = 'none';
		}
	}
}

function doGSSubmit()
{
	if(!document.getElementById('q')){
		return;
	}
	if(document.getElementById('q').value ==gGoogleSiteSeatchGuideStr){
		document.getElementById('q').value ='';
		return true;
	}
	return true;
}

//==============
//文字サイズ変更
// 1:small 2:normal(m) 3:large
//-------
var gDefaultSizeVal = 2;
function initFontSize()
{
	//
	var aVal = gDefaultSizeVal;
	aVal = getTheCookie("fontsize");
	//
	switchFontSize(aVal);
}
function doOnLoadJGDACommon()
{
	//
	var aVal = gDefaultSizeVal;
	aVal = getTheCookie("fontsize");
	updateFontSizeBtnIcon(aVal);
	
	//--=========
	if(document.getElementById('q')){
		document.getElementById('q').blur();
	}
	showHideGSGuide(document.getElementById('q'),true);
}

//-------
function switchFontSize(aValStr)
{
	var aVal = parseInt(aValStr);
	var linkObj = document.getElementById('fontsizecssdef');
	if(!linkObj){
		return;
	}
	switch(aVal){
		case(1):
			linkObj.href="css/fontsize_s.css";
			break;
		case(2):
			linkObj.href="css/fontsize_m.css";
			break;
		case(3):
			linkObj.href="css/fontsize_l.css";
			break;
		default:
			linkObj.href="css/fontsize_m.css";//fail safe
			break;
	}
	//
	setCookie("fontsize", aValStr);
}

//
function updateFontSizeBtnIcon(aValStr)
{
	if(!document.getElementById('fontsizebtns')){
		return;
	}
	if(!document.getElementById('fontsizebtnm')){
		return;
	}
	if(!document.getElementById('fontsizebtnl')){
		return;
	}
	var aVal = parseInt(aValStr);
	var imgpath = "img/common/";
	var selectedSuffix = "_ov";
	var imgext = ".gif";
	switch(aVal){
		case(1):
	   		document.getElementById("fontsizebtns").src = imgpath + 'fontsize_btn_s' + selectedSuffix + imgext;
	    	document.getElementById("fontsizebtnm").src = imgpath + 'fontsize_btn_m' + imgext;
	    	document.getElementById("fontsizebtnl").src = imgpath + 'fontsize_btn_l' + imgext;
			break;
		case(2):
	   		document.getElementById("fontsizebtns").src = imgpath + 'fontsize_btn_s' + imgext;
	   		document.getElementById("fontsizebtnm").src = imgpath + 'fontsize_btn_m'+ selectedSuffix + imgext;
	   		document.getElementById("fontsizebtnl").src = imgpath + 'fontsize_btn_l'  + imgext;
			break;
		case(3):
	    	document.getElementById("fontsizebtns").src = imgpath + 'fontsize_btn_s' + imgext;
	    	document.getElementById("fontsizebtnm").src = imgpath + 'fontsize_btn_m' + imgext;
	    	document.getElementById("fontsizebtnl").src = imgpath + 'fontsize_btn_l' + selectedSuffix + imgext;
			break;
		default://fail safe
	   		document.getElementById("fontsizebtns").src = imgpath + 'fontsize_btn_s' + imgext;
	   		document.getElementById("fontsizebtnm").src = imgpath + 'fontsize_btn_m'+ selectedSuffix + imgext;
	   		document.getElementById("fontsizebtnl").src = imgpath + 'fontsize_btn_l'  + imgext;
			break;
	}
}

//=========================
//cookie
//----
function getIsCookieEnable()
{
	return window.navigator.cookieEnabled;
}

//----
function setCookie(aKey, aVal)
{
	if(!getIsCookieEnable()){
		return;
	}
	if(!aKey){
		return;
	}
	//
	var aStr = '';
	aStr += aKey + '=';
	aStr += escape(aVal);
	aStr += '; expires=' + 'Fri, 1-Jan-2038 00:00:00 GMT';//無期限
	aStr += '; path=/';//サイト全体に作用
	//
	document.cookie = aStr;
}

//----
function getTheCookie(aKey)
{
	if(!getIsCookieEnable()){
		return null;
	}
	if(!aKey){
		return null;
	}
	if(!document.cookie){
		return null;
	}
	var cookieInfo = document.cookie.split("; ");
	var aData = null;
	for(var aIndex=0;aIndex < cookieInfo.length;aIndex++){
		var dataInfo = cookieInfo[aIndex].split("=");
		if(dataInfo[0] == aKey){
			aData = unescape(dataInfo[1]);
			break;
		}
	}
	//
	return aData;
}

// init
//=========================
initFontSize();
//--append onload function
if (window.addEventListener){//NOT IE
	window.addEventListener("load", doOnLoadJGDACommon,false);
}
else{
	if (window.attachEvent){//IE
		window.attachEvent("onload", doOnLoadJGDACommon);
	}
}



