//==============================================================================
//[name]	画像切替処理：ie用
//[outline]	複数の画像を切替る場合、srcの値の変更だけだと正常に動作しないため、imgタグを挿入しなおす。
//[parameters]
// 		pObjImg			(in) imgオブジェクト
// 		pImgId			(in) 属性値：id
// 		pImgSrc			(in) 属性値：src
// 		pImgAlt			(in) 属性値：alt
// 		pHeight			(in) 属性値：height
// 		pWidth			(in) 属性値：width
// 		pAlign			(in) 属性値：align
//[histories]
// time stamp version		operator		content
// ---------- ------------	------------	------------------------------------
// 2006.10.31 rev 1.0.0.0	pam				初版
//==============================================================================
function jfncSetImg_ie( pObjImg, pImgId, pImgSrc, pImgAlt, pHeight, pWidth, pAlign ) {

	sInnerHTML = '<img src="' + pImgSrc + '"';
	if ( pImgId  != "" && pImgId  != null ) sInnerHTML += ' id="'		+ pImgId  + '"';
	if ( pImgAlt != "" && pImgAlt != null ) sInnerHTML += ' alt="'		+ pImgAlt + '"';
	if ( pHeight != "" && pHeight != null ) sInnerHTML += ' height="'	+ pHeight + '"';
	if ( pWidth  != "" && pWidth  != null ) sInnerHTML += ' width="'	+ pWidth  + '"';
	if ( pAlign  != "" && pAlign  != null ) sInnerHTML += ' align="'	+ pAlign  + '"';
	sInnerHTML += ' border="0">';

	pObjImg.parentElement.innerHTML = sInnerHTML;
}

//==============================================================================
//[name]	画像切替処理：ie以外
//[outline]	
//[parameters]
// 		pObjImg			(in) imgオブジェクト
// 		pImgId			(in) 属性値：id
// 		pImgSrc			(in) 属性値：src
// 		pImgAlt			(in) 属性値：alt
//[histories]
// time stamp version		operator		content
// ---------- ------------	------------	------------------------------------
// 2006.10.31 rev 1.0.0.0	pam				初版
//==============================================================================
function jfncSetImg_nn( pObjImg, pImgId, pImgSrc, pImgAlt ) {
	pObjImg.src = pImgSrc;
	pObjImg.alt = pImgAlt;
	pObjImg.id  = pImgId;
}
//==============================================================================

//**************************************************************************
// 画像切替
//**************************************************************************
function jfncCom_ChangeImg( pOkImgExtList, pImgPath, pImgId ) {
	var sImgPath = pImgPath;
	var aryFileNm = sImgPath.split( "." );

	if ( pImgPath == "" ) {

	} else if ( aryFileNm.length != 2 ) {
		alert( "ファイル名が不正です。" );
		sImgPath = "";
	} else if ( ("," + pOkImgExtList.toLowerCase() + ",").indexOf( ",." + aryFileNm[1].toLowerCase() + "," ) < 0 ) {
		alert( "ファイルの拡張子が無効です。" );
		sImgPath = "";
	}

	//画像表示
	document.getElementById( pImgId ).src = sImgPath;
}

//**************************************************************************
// 画像を別ウィンドウで表示（画像に合わせてサイズ調整する）
//**************************************************************************
var gWinImg;
function jfncCom_OpenImgJustSize( pImgPath ) {
	var aryRet;
	var nWidth;
	var nHeight;

	//画像サイズを取得
	aryRet = jfncCom_GetImgSize( pImgPath );

	//JUSTサイズで、画像を別ウィンドウでOPEN（画面中央に表示）
	nWidth		= aryRet[0] + 20;		//widow内の余白分調整
	nHeight		= aryRet[1] + 30;		//widow内の余白分調整
	var nTop	= ( window.screen.height / 2 ) - ( nHeight / 2 );
	var nLeft	= ( window.screen.width  / 2 ) - ( nWidth  / 2 );

	gWinImg = window.open( pImgPath, "", "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight + ",resizable=yes" );
	if ( gWinImg ) gWinImg.focus();

	return false;
}

//**************************************************************************
// 画像サイズを取得
//**************************************************************************
var gRetryCnt = 0;
function jfncCom_GetImgSize( pImgPath ) {
	var aryRet = new Array(1);

	//画像生成
	var objImg = document.createElement( "img" );
	objImg.setAttribute( "src", pImgPath );

	//サイズ取得
	aryRet[0] = objImg.width;
	aryRet[1] = objImg.height;

	//サイズ取得チェック
	if ( ( !aryRet[0] ) || ( aryRet[0] <= 0 ) ) {
		//１回目で取得できない場合の回避策。２回リトライ。
		if ( gRetryCnt < 3 ) {
			gRetryCnt = gRetryCnt + 1;
			setTimeout( "jfncCom_GetImgSize();", 500 );	//リトライ
			return aryRet;
		} else {
			gRetryCnt = 0;
			return aryRet;
		}
	}

	return aryRet;
}

//**************************************************************************
// 画像が指定サイズと同じかどうかチェック
//**************************************************************************
function jfncCom_CheckImgSizeSame( pImgPath, pWidth, pHeight ) {
	var aryRet = new Array(1);
	var nWidth;
	var nHeight;

	//指定サイズのチェック
	if ( ( !pWidth )
	  || ( !pHeight )
	  || ( isNaN( pWidth ) )
	  || ( isNaN( pHeight ) )
	  || ( parseFloat( pWidth )  <= 0 )
	  || ( parseFloat( pHeight ) <= 0 )
	) {
		return true;
	}

	//画像サイズを取得
	aryRet = jfncCom_GetImgSize( pImgPath );

	//画像サイズをチェック
	if ( ( pWidth  != aryRet[0] )
	  || ( pHeight != aryRet[1] )
	) {
		return false;
	}

	return true;
}

//**************************************************************************
// 画像サイズチェック処理
//**************************************************************************
function jfncCom_CheckImgSize( pTxtFileUpName, pImgId, pWidth, pHeight ) {
	var sImgPath = document.getElementById( pImgId ).src;

	var aryImgPath = sImgPath.split( "/" );

	//画像サイズをチェック
	if ( ( aryImgPath[ aryImgPath.length - 1 ] != "dummy.gif" )
	  && ( sImgPath.slice(-1) != "/" )
	  && ( document.getElementsByName( pTxtFileUpName + "_up" )[0].value != "" )
	) {
		if ( !jfncCom_CheckImgSizeSame( sImgPath, pWidth, pHeight ) ) {
			return false;
		}
	}
	return true;
}

//**************************************************************************
// 画像が指定サイズと同じかどうかチェック
//**************************************************************************
function jfncCom_CheckImgSizeMax( pImgPath, pMaxWidth, pMaxHeight ) {
	var aryRet = new Array(1);
	var nWidth;
	var nHeight;

	//指定サイズのチェック
	if ( ( !pMaxWidth )
	  || ( !pMaxHeight )
	  || ( isNaN( pMaxWidth ) )
	  || ( isNaN( pMaxHeight ) )
	  || ( parseFloat( pMaxWidth )  <= 0 )
	  || ( parseFloat( pMaxHeight ) <= 0 )
	) {
		return true;
	}

	//画像サイズを取得
	aryRet = jfncCom_GetImgSize( pImgPath );

	//画像Maxサイズをチェック
	if ( ( aryRet[0] > pMaxWidth )
	  || ( aryRet[1] > pMaxHeight )
	) {
		return false;
	}

	return true;
}

//**************************************************************************
// 画像サイズの最大値チェック処理
//**************************************************************************
function jfncCom_CheckImgUpSizeMax( pTxtFileUpName, pImgId, pMaxWidth, pMaxHeight ) {
	var sImgPath = document.getElementById( pImgId ).src;

	var aryImgPath = sImgPath.split( "/" );

	//画像サイズをチェック
	if ( ( aryImgPath[ aryImgPath.length - 1 ] != "dummy.gif" )
	  && ( sImgPath.slice(-1) != "/" )
	  && ( document.getElementsByName( pTxtFileUpName )[0].value != "" )
	) {
		if ( !jfncCom_CheckImgSizeMax( sImgPath, pMaxWidth, pMaxHeight ) ) {
			return false;
		}
	}
	return true;
}

//**************************************************************************
