var isMSIE = /*@cc_on!@*/false;						// IE判定

// グローバル変数の定義
var g_CallbackFunction		= null;
var g_PrevDomRequest		= null;
var g_waitflag				= false;

var FIREFOX_COLOR_INFO			= "rgb(";			// FireFoxブラウザの色情報保持チェック

/***********************************************************
* autoGetParam
* ----------------------------------------------------------
* 画面内に定義されているオブジェクトと、その型情報を収集
* しGETパラメータ形式で返却する。
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function autoGetParam()
{
	// フォーム内の値でPOSTパラメータを自動生成する(prototype.jsを使用)
	var param = Form.serialize("inputform");

	// フォーム内の値の型一覧POSTパラメータを自動生成する
	var type_param = makeInputTypeParameter("inputform");

	// パラメータの連結処理
	if (param.length != 0)
	{
		type_param = "&" + type_param;
	}
	param = param + type_param;

	return param;
}

/***********************************************************
* makeInputTypeParameter
* ----------------------------------------------------------
* 指定したIDを持つForm内の入力項目の全ての型をパラメータとし
* て生成します。
*
* [引数]
*  対象FormのID
* 
* [戻り値]
*  パラメータ
* 
*****************************************[FutureSoftware]**/
function makeInputTypeParameter(formid)
{
	// 戻り値を格納する領域を定義
	var ret = "";

	// id属性からformを取得する
	var formobj =  document.getElementById(formid);

	// formが取得できたかチェックする
	if (formobj == undefined )
	{
		// formが取得できなかった場合は現状の戻り値(つまり空)を返す
		return ret;
	}

	// 同一の名称リストを返却しないように、それを格納しておく連想配列を作成
	var ass_names = new Object();

	// formが取得できた場合、その中の要素を抽出する
	for (var cnt = 0 ; cnt < formobj.length ; cnt++ )
	{
		// 最初に要素の型と名前を取得
		var type = formobj[cnt].type;
		var name = formobj[cnt].name;

		// 処理対象で絞る
		if (type == "text" || type == "password" || type == "checkbox" || type == "hidden"|| type == "radio" || type == "select-one" || type == "select-multiple" || type == "textarea")
		{
			// 既に存在している名称かどうかの判断
			if (ass_names[name] == undefined)
			{
				// 存在していない名称の場合は配列に登録
				ass_names[name] = name;

				// 名前の生成(名前のルールは元々の名前+"__type"である
				name = name.replace("[]","");
				name = name + "__type";

				// 既になんらかの戻り値が設定されているかをチェック
				if (ret.length > 0 )
				{
					// 結合子を付与
					ret += "&";
				}

				// 名前=値の形でパラメータを生成していく
				ret += name + "=" + type;
			}
		}
	}

	// 作成したパラメータの返却
	return ret;
}

/***********************************************************
* validateServerSubmit
* ----------------------------------------------------------
* サーバーサイドで指定されたXMLファイルをベースにエラーチェ
* ックを行う。
* 
* [引数]
*  action 処理モード
*  callbackFunction コールバック関数(処理正常時にコールされる)
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function validateServerSubmit(action,callbackFunction,validateXmlName)
{
	g_CallbackFunction = callbackFunction;

	// フォーム内の値でPOSTパラメータを自動生成する(prototype.jsを使用)
	var param = Form.serialize("inputform");

	// フォーム内の値の型一覧POSTパラメータを自動生成する
	var type_param = makeInputTypeParameter("inputform");

	// パラメータの連結処理
	if (param.length != 0){type_param = "&" + type_param;}
	param = param + type_param;

	// action情報を渡す
	param = param + "&" + "__action=" + action;

	// 現在のURL(act)を渡す
	var act				= "";
	if (validateXmlName == undefined)
	{
		var act_index		= location.href.indexOf("?act=");
		if(act_index == -1){act = "index";}
		else{act = location.href.substr(act_index + "?act=".length);}
		// GETパラメータが存在する可能があるから、それは削除する
		if(act.indexOf("&") != -1)
		{
			act = act.substr(0,act.indexOf("&"));
		}
	}
	else
	{
		act		= validateXmlName;
	}
	param = param + "&" + "__act=" + act;

	// 作成したパラメータでエラーチェック処理PHPをコールする
	var validate = new Ajax.Request(
				'./ValidateControl.php',
				{
					method:"post",
					parameters:param,
					onComplete:validateServerSubmitProc,
					asynchronous:false
				});
}

/***********************************************************
* validateServerSubmitProc
* ----------------------------------------------------------
* サーバーサイドで指定されたXMLファイルをベースにエラーチェ
* ックを行う。(後続処理)
* 
* [引数]
*  request 処理結果
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function validateServerSubmitProc(request)
{
	// alert(request.responseText);

	// 入力値の判定を行う
	var resultXmlObj = request.responseXML;

	var allResult = true;
	var message = "";

	for (var cnt = 0 ; cnt < resultXmlObj.getElementsByTagName("item").length ; cnt++ )
	{
		var itemObj = resultXmlObj.getElementsByTagName("item").item(cnt);

		var name_value			= getTextContent(itemObj.getElementsByTagName("name"));
		var value_value			= getTextContent(itemObj.getElementsByTagName("value"));
		var validateresult_value= getTextContent(itemObj.getElementsByTagName("validateresult"));
		var message_value		= getTextContent(itemObj.getElementsByTagName("message"));
		var type_value			= getTextContent(itemObj.getElementsByTagName("type"));
		var func_value			= getTextContent(itemObj.getElementsByTagName("func"));

		if (validateresult_value == "false")
		{
			// 入力値チェックでエラーの場合
			allResult = false;
			message += message_value + "\r\n";
		}
		else
		{
			// 正常の場合
		}
	}

	// 最後の実行
	if (allResult)
	{
		if (g_CallbackFunction != undefined ){g_CallbackFunction();}
	}
	else
	{
		myAlert(message.replace(/\n/g,"<br>"));
		// alert(message);
	}
}

/***********************************************************
* ComDomCall
* ----------------------------------------------------------
* サーバ側DOM処理の起動
* 
* [引数]
*  waiflag ウェイト画面を表示するか否か
*  domName 呼出すDOM処理
*  callbackFunction DOM処理終了後に呼ばれる関数
*  myparam 画面上の入力値以外を渡す場合に使用
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function ComDomCall(waitflag,domName,callbackFunction,myparam)
{
	if (waitflag == true)
	{
		var ajax_waitObj				= document.getElementById("__ajax_wait");
		if (ajax_waitObj != null)
		{
			ajax_waitObj.style.display		= "block";
		}
	}
	g_waitflag		= waitflag;

	if(callbackFunction != undefined)
	{
		g_CallbackFunction = callbackFunction;
	}
	else
	{
		g_CallbackFunction = undefined;
	}

	var makeParam = "";
	if (myparam == undefined)
	{
		makeParam = autoGetParam();
	}
	else
	{
		makeParam = myparam;
	}

	var ajaxrequest = new Ajax.Request('./DomControl.php' + '?domName=' + domName,
									{
										method:"post",
										parameters:makeParam,
										onComplete:ComDomCall_proc,
										asynchronous:waitflag
									});
}

/***********************************************************
* ComDomCall_proc
* ----------------------------------------------------------
* サーバ側DOM処理の起動(内部処理)
* 
* [引数]
*  request 処理結果
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function ComDomCall_proc(request)
{
	g_PrevDomRequest		= request;

	var resultXmlObj		= request.responseXML;

	var procObj				= resultXmlObj.getElementsByTagName("proc").item(0);

	var domName				= getTextContent(procObj.getElementsByTagName("domName"));
	var procResult			= getTextContent(procObj.getElementsByTagName("procResult"));
	var message				= getTextContent(procObj.getElementsByTagName("message"));
	var errorMessage		= getTextContent(procObj.getElementsByTagName("errorMessage"));

	if (procResult == "false")
	{
		myAlert(errorMessage);
	}
	else
	{
		if (message != "")
		{
			myAlert(message);
		}
	}

	if(g_waitflag == true)
	{
		var ajax_waitObj				= document.getElementById("__ajax_wait");
		if (ajax_waitObj != null)
		{
			ajax_waitObj.style.display		= "none";
		}
	}

	if(procResult == "true" && g_CallbackFunction != undefined)
	{
		g_CallbackFunction();
	}
}

function ComDomCallGetValue(key)
{
	var resultXmlObj		= g_PrevDomRequest.responseXML;

	var procObj				= resultXmlObj.getElementsByTagName("proc").item(0);
	var returnvalueObj		= procObj.getElementsByTagName("returnvalue").item(0)

	return getTextContent(returnvalueObj.getElementsByTagName(key));
}

/***********************************************************
* onResizeInner
* ----------------------------------------------------------
* デフォルトで定義されているdiv要素をウインドウのサイズ等変
* 更時に中央に寄るような制御を行う。
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function onResizeInner()
{
	// futuresoftware.jsで標準で用意している部分の調整を行なう
	var grayout = document.getElementById("__grayout");
	grayout.style.width=getWidth();
	grayout.style.height=getHeight() + getScrollY();

	var alert_grayout = document.getElementById("__alert_grayout");
	alert_grayout.style.width=getWidth();
	alert_grayout.style.height=getHeight() + getScrollY();

	var ajax_wait = document.getElementById("__ajax_wait");
	if (ajax_wait != null)
	{
		ajax_wait.style.width=getWidth();
		ajax_wait.style.height=getHeight() + getScrollY();
	}

	moveDivCenter('__sub_window');
	moveDivCenter('__alert_window');
}

/***********************************************************
* moveDivCenter
* ----------------------------------------------------------
* 引数で指定されたDIV要素の高さ等を調べ、画面の中央に配置する。
* 
*
* [引数]
*  divオブジェクトのID
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function moveDivCenter(divId)
{
	// IDからDIVオブジェクトを取得
	var divobj = $(divId);

	// DIVオブジェクトの基本情報を取得
	var divobj_width = divobj.style.width;
	var divobj_height = divobj.style.height;

	// 画面サイズの取得
	var divobj_setLeft = getWidth();
	var divobj_setTop = getHeight();

	// 不要な情報の削除
	divobj_width = divobj_width.replace('px','');
	divobj_height = divobj_height.replace('px','');

	divobj_width = divobj_width.replace('%','');
	divobj_height = divobj_height.replace('%','');

	// センター寄せ処理
	// 画面サイズの1/2の値から、モーダルサイズの1/2を引くことでモーダルを画面中央に配置する
	divobj_setLeft = divobj_setLeft / 2 - (divobj_width / 2);

	// 画面サイズがDIVオブジェクトのサイズを下回っている場合を考慮する
	if (divobj_setTop > divobj_height)
	{
		divobj_setTop = divobj_setTop / 2 - (divobj_height / 2);
		divobj.style.top=Math.round(divobj_setTop + getScrollY());
	}
	else
	{
		// 画面サイズが満たない場合は上に固定して動かさない
		divobj_setTop = 0;
	}

	// 算出した値をDIVオブジェクトに反映する
	divobj.style.left=Math.round(divobj_setLeft);
}

/***********************************************************
* openGrayout
* ----------------------------------------------------------
* 背景のグレーをオープンする(サブウインドウの背景となる)
* 
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function openGrayout()
{
	var grayout = document.getElementById("__grayout");
	grayout.style.width=getWidth();
	grayout.style.height=getHeight();
	grayout.style.display="block";
}

/***********************************************************
* closeGrayout
* ----------------------------------------------------------
* 背景のグレーをクローズする(サブウインドウの背景となる)
* 
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function closeGrayout()
{
	var grayout = document.getElementById("__grayout");
	grayout.style.display="none";
}

/***********************************************************
* openSubWindow
* ----------------------------------------------------------
* 指定されたHTMLを表示するサブウインドウを表示する
* 
*
* [引数]
*  url 表示したいHTMLのURL(自サーバーに格納してあるものに限る)
*  width 表示したいXサイズ
*  height 表示したいYサイズ
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function openSubWindow(url,width,height)
{
	openGrayout();

	var divobj = document.getElementById("__sub_window");

	divobj.style.width=width;
	divobj.style.height=height;
	divobj.style.display="none";

	var displayChild = new Ajax.Request(
					url,
					{
						method:"post",
						parameters:"",
						onComplete:openSubWindowProc,
						asynchronous:false
					});
}

/***********************************************************
* openSubWindowProc
* ----------------------------------------------------------
* openSubWindowの後続処理
* 
*
* [引数]
*  request
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function openSubWindowProc(request)
{
	var divobj = document.getElementById("__sub_window");

	divobj.innerHTML = request.responseText;

	onResizeInner();

	new Effect.Appear("__sub_window", {
		from:0.1, // 開始時透明度  
		to:1.0, // 終了時透明度  
		delay:0, // 開始までの秒数  
		fps:60, // フレームレート  
		duration: 0.5, // アニメーションする時間(秒)  
		beforeStartInternal: function(effect) {
		},
		afterFinishInternal: function(effect) {
		}
	});
}

/***********************************************************
* closeSubWindow
* ----------------------------------------------------------
* サブウインドウを閉じる
* 
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function closeSubWindow()
{
	new Effect.Fade("__sub_window", {   
		from:1.0, // 開始時透明度   
		to:0.0, // 終了時透明度   
		fps:60, // フレームレート   
		duration: 0.5, // アニメーションする時間(秒)   
		beforeStartInternal: function(effect) {   
		},   
		afterFinishInternal: function(effect) {   
		}  
	});

	setTimeout("closeSubWindowProc()", 800);
}

/***********************************************************
* closeSubWindowProc
* ----------------------------------------------------------
* closeSubWindowの後続処理
* 
*
* [引数]
*  request
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function closeSubWindowProc()
{
	var divobj = document.getElementById("__sub_window");
	divobj.style.display="none";
	closeGrayout();
}

/***********************************************************
* openAlertGrayout
* ----------------------------------------------------------
* 背景の警告表示用グレーをオープンする(警告用ウインドウの背景となる)
* 
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function openAlertGrayout()
{
	var alert_grayout = document.getElementById("__alert_grayout");
	alert_grayout.style.width=getWidth();
	alert_grayout.style.height=getHeight();
	alert_grayout.style.display="block";
}

/***********************************************************
* closeGrayout
* ----------------------------------------------------------
* 背景の警告用グレーをクローズする(警告用ウインドウの背景となる)
* 
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function closeAlertGrayout()
{
	var alert_grayout = document.getElementById("__alert_grayout");
	alert_grayout.style.display="none";
}

/***********************************************************
* myAlert
* ----------------------------------------------------------
* アラートボックスを表示する
* 
*
* [引数]
*  message アラートメッセージ
*  callbackFunction アラートメッセージの確認後に起動したい関数
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function myAlert(message,callbackFunction)
{
	var alert_messageObj		= document.getElementById("__alert_message");
	alert_messageObj.innerHTML	= message;

	var alert_buttonObj			= document.getElementById("__alert_button");
	if(callbackFunction == undefined)
	{
		setJavascriptFunction(alert_buttonObj,"onclick","closeAlert();");
	}
	else
	{
		setJavascriptFunction(alert_buttonObj,"onclick","closeAlert();" + callbackFunction);
	}

	openAlertGrayout();

	var divobj = document.getElementById("__alert_window");
	divobj.style.width=400;
	divobj.style.height=150;
	divobj.style.display="block";

	onResizeInner();
}

/***********************************************************
* closeAlert
* ----------------------------------------------------------
* アラートボックスを閉じる
* 
*
* [引数]
*  なし
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function closeAlert()
{
	var divobj = document.getElementById("__alert_window");
	divobj.style.display="none";
	closeAlertGrayout();
}

/***********************************************************
* getWidth
* ----------------------------------------------------------
* 現在のウインドウの横幅を求めます。
* 
* [引数]
*  なし
* 
* [戻り値]
*  ウインドウの横幅
* 
*****************************************[FutureSoftware]**/
function getWidth() 
{
     var ua = navigator.userAgent;							// ユーザーエージェント
     var nWidth, nHeight;									// サイズ
     var nHit = ua.indexOf("MSIE");							// 合致した部分の先頭文字の添え字
     var bIE = (nHit >=  0);								// IE かどうか
     var bVer6 = (bIE && ua.substr(nHit+5, 1) == "6");		// バージョンが 6 かどうか

     var bStd = (document.compatMode && document.compatMode=="CSS1Compat");

     // 標準モードかどうか
     if (bIE) {
          if (bVer6 && bStd) {
               nWidth = document.documentElement.clientWidth;
               nHeight = document.documentElement.clientHeight;
          } else {
               nWidth = document.body.clientWidth;
               nHeight = document.body.clientHeight;
          }
     } else {
          nWidth = window.innerWidth;
          nHeight = window.innerHeight;
     }

     return nWidth;
}

/***********************************************************
* getHeight
* ----------------------------------------------------------
* 現在のウインドウの高さを求めます。
* 
* [引数]
*  なし
* 
* [戻り値]
*  ウインドウの高さ
* 
*****************************************[FutureSoftware]**/
function getHeight() 
{
     var ua = navigator.userAgent;							// ユーザーエージェント
     var nWidth, nHeight;									// サイズ
     var nHit = ua.indexOf("MSIE");							// 合致した部分の先頭文字の添え字
     var bIE = (nHit >=  0);								// IE かどうか
     var bVer6 = (bIE && ua.substr(nHit+5, 1) == "6");		// バージョンが 6 かどうか

     var bStd = (document.compatMode && document.compatMode=="CSS1Compat");

     // 標準モードかどうか
     if (bIE) {
          if (bVer6 && bStd) {
               nWidth = document.documentElement.clientWidth;
               nHeight = document.documentElement.clientHeight;
          } else {
               nWidth = document.body.clientWidth;
               nHeight = document.body.clientHeight;
          }
     } else {
          nWidth = window.innerWidth;
          nHeight = window.innerHeight;
     }

     return nHeight;
}

/***********************************************************
* getScrollX
* ----------------------------------------------------------
* X軸のスクロール量を求めます
* 
* [引数]
*  なし
* 
* [戻り値]
*  ウインドウの高さ
* 
*****************************************[FutureSoftware]**/
function getScrollX()
{ 
	var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; 

	return scroll;
} 

/***********************************************************
* getScrollY
* ----------------------------------------------------------
* Y軸のスクロール量を求めます
* 
* [引数]
*  なし
* 
* [戻り値]
*  ウインドウの高さ
* 
*****************************************[FutureSoftware]**/
function getScrollY()
{
	var scrollY = document.documentElement.scrollTop || document.body.scrollTop; 

	return scrollY;
}

/***********************************************************
* getDivWidth
* ----------------------------------------------------------
* DIVオブジェクトの幅を求めます。
* 
* [引数]
*  DIVオブジェクト
* 
* [戻り値]
*  DIVオブジェクトの高さ
* 
*****************************************[FutureSoftware]**/
function getDivWidth (div)
{
  return document.layers?
         div.clip.width:(div.offsetWidth||div.style.pixelWidth||0);
}

/***********************************************************
* getDivHeight
* ----------------------------------------------------------
* DIVオブジェクトの高さを求めます。
* 
* [引数]
*  DIVオブジェクト
* 
* [戻り値]
*  DIVオブジェクトの高さ
* 
*****************************************[FutureSoftware]**/
function getDivHeight(div)
{
  return document.layers?
         div.clip.height:(div.offsetHeight||div.style.pixelHeight||0);
}

/***********************************************************
* replaceReturnToBR
* ----------------------------------------------------------
* 引数で指定された文字列の中から改行を抽出してBRタグに置換
* 
* [引数]
*  対象となる文字列
* 
* [戻り値]
*  BRタグに置換後の文字列
* 
*****************************************[FutureSoftware]**/
function replaceReturnToBR(str)
{
	str		= replaceAll(str,"\r\n","\n");
	str		= replaceAll(str,"\r","\n");
	str		= replaceAll(str,"\n","<br>");

	return str;
}

/***********************************************************
* replaceSpaceToNBSP
* ----------------------------------------------------------
* 引数で指定された文字列の中からスペースを抽出してnbspに置換
* 
* [引数]
*  対象となる文字列
* 
* [戻り値]
*  nbspに置換後の文字列
* 
*****************************************[FutureSoftware]**/
function replaceSpaceToNBSP(str)
{
	str		= replaceAll(str," ","&nbsp;");

	return str;
}

/***********************************************************
* replaceAll
* ----------------------------------------------------------
* 文字列全置換
* 
* [引数]
*  expression 対象となる文字列
*  org 置換対象文字
*  dest 置換後文字
* 
* [戻り値]
*  置換後の文字列
* 
*****************************************[FutureSoftware]**/
function replaceAll(expression, org, dest)
{
    return expression.split(org).join(dest);
}

/***********************************************************
* setStyle
* ----------------------------------------------------------
* 引数で指定したオブジェクトに対してスタイルプロパティの適用
* 
* [引数]
*  obj スタイルプロパティを適用したいオブジェクト
*  style スタイルプロパティ
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function setStyle(obj,style)
{
		if (isMSIE)
		{
			obj.style.cssText = style;
		}
		else
		{
			obj.setAttribute("style",style);
		}
}

/***********************************************************
* setJavascriptFunction
* ----------------------------------------------------------
* 引数で指定したオブジェクトに対してイベントプロパティの適用
* 
* [引数]
*  obj イベントプロパティを適用したいオブジェクト
*  ontype イベント
*  style イベント時に実行される関数
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function setJavascriptFunction(obj,ontype,func)
{
		if (isMSIE)
		{
			obj.setAttribute(ontype,new Function(func));
		}
		else
		{
			obj.setAttribute(ontype,func);
		}
}

/***********************************************************
* removeJavascriptFunction
* ----------------------------------------------------------
* 引数で指定したオブジェクトからイベントプロパティの消去
* 
* [引数]
*  obj イベントプロパティを消去オブジェクト
*  ontype イベント
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function removeJavascriptFunction(obj,ontype)
{
		if (isMSIE)
		{
			obj.setAttribute(ontype,new Function(""));
		}
		else
		{
			obj.removeAttribute(ontype);
		}
}

/***********************************************************
* getTextContent
* ----------------------------------------------------------
* XML内のタグに囲まれた値を取得します。
* 
* [引数]
*  タグ名
* 
* [戻り値]
*  タグに囲まれた値
* 
*****************************************[FutureSoftware]**/
function getTextContent(node)
{
	if(window.ActiveXObject)
	{
		try
		{
			//MSXML2以降用
			return node.item(0).firstChild.nodeValue;
		}
		catch (e)
		{
			try
			{
				//旧MSXML用
				return node.item(0).firstChild.nodeValue;
			}
			catch (e2)
			{
				return "";
			}
		}
	}
	else if(window.XMLHttpRequest)
	{
		//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
		return node.item(0).textContent;
	}
	else
	{
		return "";
	}

	return (node.firstChild.textContent ? node.item(0).textContent : node.firstChild.nodeValue);
}

/***********************************************************
* getExp
* ----------------------------------------------------------
* 引数で渡したファイルの拡張子を返す
*
* [引数]
*  画像ソースファイルパス
* 
* [戻り値]
*  拡張子
* 
*****************************************[FutureSoftware]**/
function getExp(src)
{
	// 最後のピリオドを検索する
	var lastindex = src.lastIndexOf(".");

	// もしピリオドが見つからなかったら・・・
	if (lastindex == -1){return "";}

	return(src.substring(lastindex + 1 ,src.length));
}

/***********************************************************
* getDir
* ----------------------------------------------------------
* 引数で渡したファイルが格納されているディレクトリを返す
*
* [引数]
*  画像ソースファイルパス
* 
* [戻り値]
*  ディレクトリパス
* 
*****************************************[FutureSoftware]**/
function getDir(src)
{
	var lastindex_yen = src.lastIndexOf("\"");
	var lastindex_slu = src.lastIndexOf("/");

	if (lastindex_yen == -1 && lastindex_slu == -1){return "";}

	var lastindex = lastindex_yen;
	if (lastindex < lastindex_slu)
	{
		lastindex = lastindex_slu;
	}

	return(src.substring(0,lastindex + 1));
}

/***********************************************************
* onButtonAuto
* ----------------------------------------------------------
* マウスオーバーで画像を変化させたいところでこれをコールする
*
* [引数]
*  画像のオブジェクト
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function onButtonAuto(obj)
{
	// まずは拡張子を取得しておく
	var exp = getExp(obj.src);
	var dir = getDir(obj.src);
	var mode = true;

	if (obj.src.indexOf("_off." + exp) == -1){mode = true;}
	if (obj.src.indexOf("_on." + exp) == -1) {mode = false;}

	// 次にidからファイル名のベースとなる名称を取得する
	var filenamebase = "";
	if (mode)
	{
		filenamebase = obj.src.substring(obj.src.lastIndexOf("/",obj.src.length) + 1).replace("_on."+exp,"");
	}
	else
	{
		filenamebase = obj.src.substring(obj.src.lastIndexOf("/",obj.src.length) + 1).replace("_off."+exp,"");
	}

	// ファイル名のベースと拡張子から予想できるファイル名を生成する
	var imgfilename = "";
	if (mode)
	{
		imgfilename = dir + filenamebase + "_off" + "." + exp;
	}
	else
	{
		imgfilename = dir + filenamebase + "_on" + "." + exp;
	}

	obj.src = imgfilename;

	if (mode)
	{
		document.body.style.cursor = "default";
	}
	else
	{
		document.body.style.cursor = "pointer";
	}
}

/***********************************************************
* imageFitting
* ----------------------------------------------------------
* 画像を指定されたサイズ内にフィッティングさせる
*
* [引数]
*  imgObj 対象画像オブジェクト
*  width 画像の幅
*  height 画像の高さ
*  fix_width 調整したい幅
*  fix_height 調整したい高さ
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function imageFitting(imgObj,width,height,fix_width,fix_height)
{
	var fix_rate		= fix_width / fix_height;
	var rate			= width     / height;

	if (fix_rate >= rate)
	{
		imgObj.width	= width * fix_height / height;
		imgObj.height	= fix_height;
	}
	else
	{
		imgObj.width	= fix_width;
		imgObj.height	= height * fix_width / width;
	}
}

/***********************************************************
* getMyApp
* ----------------------------------------------------------
* Flexからjsを呼出す場合に使用
*
* [引数]
*  
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function getMyApp(appName)
{
    if (navigator.appName.indexOf ("Microsoft") !=-1) {
        return window[appName];
    } else {
        return document[appName];
    }
}

/***********************************************************
* isBackgroundColor
* ----------------------------------------------------------
* 背景色の判定
*
* [引数]
*  obj 背景色を判定したいオブジェクト
*  targetcolor 判定したい色
* 
* [戻り値]
*  判定結果
* 
*****************************************[FutureSoftware]**/
function isBackgroundColor(obj,targetcolor)
{
	// IEか否かを判別する
	if(isMSIE)
	{
		// IEの場合
		if (obj.style.backgroundColor == targetcolor)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		// FIrefox Safariの場合

		// まずは、styleに定義された色情報を小文字変換しながら取得する
		var background = obj.style.backgroundColor.toLowerCase();
		var color = obj.style.color.toLowerCase();

		// その結果から色情報の位置を取得する
		var background_idx = background.indexOf(FIREFOX_COLOR_INFO);
		var color_idx = color.indexOf(FIREFOX_COLOR_INFO);

		// 取得できなかった場合はエラーだが、選択されていないとして処理する
		if(background_idx == -1 || color_idx == -1){return false;}

		// 色情報の出現以降に出てくる括弧閉じの位置を検索し、その中に挟まれた情報を色情報として取得する
		var background_rgb = background.substring(background_idx + FIREFOX_COLOR_INFO.length,background.indexOf(")",background_idx));
		var color_rgb = color.substring(color_idx + FIREFOX_COLOR_INFO.length,color.indexOf(")",color_idx));

		// 色情報はカンマで区切られているので、分断する
		var background_rgb_split = background_rgb.split(",");
		var color_rgb_split		 = color_rgb.split(",");

		// 分断した結果を16進数に変換し色情報として取得する
		var background_color	= "#"
								 + parseInt(background_rgb_split[0]).toString(16)
								 + parseInt(background_rgb_split[1]).toString(16)
								 + parseInt(background_rgb_split[2]).toString(16);
		var color_color			= "#"
								 + parseInt(color_rgb_split[0]).toString(16)
								 + parseInt(color_rgb_split[1]).toString(16)
								 + parseInt(color_rgb_split[2]).toString(16);

		// 色情報の比較により、選択値か否かをチェックする
		if (background_color == targetcolor)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

/***********************************************************
* imageupload_upload_complete
* ----------------------------------------------------------
* Flexを使った画像ファイルアップロード後続処理
*
* [引数]
*  Flexから自動的ｂに引き渡されます
* 
* [戻り値]
*  なし
* 
*****************************************[FutureSoftware]**/
function imageupload_upload_complete(image_id,table1,table2,key,width,height,image_controlObjName)
{
	var now					= new Date();
	var imageObj			= document.getElementById(image_id);

	setStyle(imageObj,"display:none;");
	imageFitting(imageObj,width,height,400,300);
	imageObj.src			= "./imageview.php?image_info=" + table1 + "/" + table2 + "/" + key + "&" + now.getHours() + now.getMinutes() + now.getSeconds();
	imageObj.onload = function() {setStyle(imageObj,"display:block;");}

	var image_controlObj		= document.getElementById(image_controlObjName);
	image_controlObj.value		= "update";
}

/***********************************************************
* addFigure
* ----------------------------------------------------------
* 3桁カンマ区切り
*
* [引数]
*  引数で指定された値に対して、3桁カンマ区切りを実施
* 
* [戻り値]
*  3桁カンマ区切り後の数値
* 
*****************************************[FutureSoftware]**/
function addFigure(str)
{
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}

function completeImageupload(table_category,table_name,key_values,extension)
{
	// システム日付の取得
	var now					= new Date();

	// 画像オブジェクト
	var imgobjObj					= document.getElementById("__imgobj_" + table_category + "_" + table_name + "_" + key_values);
	var widthObj					= document.getElementById("__img_width_" + table_category + "_" + table_name + "_" + key_values);
	var heightObj					= document.getElementById("__img_height_" + table_category + "_" + table_name + "_" + key_values);
	imgobjObj.src					= "./imageview.php?image_info=" + table_category + "/" + table_name + "/" + key_values + "&max_width=" + (widthObj.value - 20) + "&max_height=" + (heightObj.value -128) + "&extension=" + extension + "&mode=temp" + "&" + now.getHours() + now.getMinutes() + now.getSeconds();
	imgobjObj.style.display			= "block";

	// 拡張子
	var img_extObj					= document.getElementById("__img_ext_" + table_category + "_" + table_name + "_" + key_values);
	img_extObj.value				= extension;

	// 画像が登録されていませんオブジェクト
	var imgobj_nothingObj			= document.getElementById("__imgobj_nothing_" + table_category + "_" + table_name + "_" + key_values);
	imgobj_nothingObj.style.display	= "none";

	// 削除ボタン表示
	var img_deleteObj				= document.getElementById("__img_delete_" + table_category + "_" + table_name + "_" + key_values);
	img_deleteObj.style.display		= "block";

	// 削除ボタンにチェックがある場合は強制的に外す
	var img_delete_checkObj			= document.getElementById("__img_delete_check_" + table_category + "_" + table_name + "_" + key_values);
	img_delete_checkObj.checked		= false;

	// アップデートフラグを立てる
	var img_updateObj				= document.getElementById("__img_update_" + table_category + "_" + table_name + "_" + key_values);
	img_updateObj.value				= "true";

	// 上記で確保した画像のファイル名を保持しておく
	var img_filenameObj				= document.getElementById("__img_filename_" + table_category + "_" + table_name + "_" + key_values);
	img_filenameObj.value			= "./imageview.php?image_info=" + table_category + "/" + table_name + "/" + key_values + "&max_width=" + (widthObj.value - 20) + "&max_height=" + (heightObj.value -128) + "&extension=" + extension + "&mode=temp";
}

function errorImageupload(errormessage)
{
	myAlert(errormessage);
}

function deleteImage(delete_checkObj,key_value)
{
	// 画像オブジェクト
	var imgobjObj					= document.getElementById("__imgobj_" + key_value);

	// 画像が登録されていませんオブジェクト
	var imgobj_nothingObj			= document.getElementById("__imgobj_nothing_" + key_value);

	// チェック状態によって画像の表示・非表示を判定
	if(delete_checkObj.checked)
	{
		// 画像オブジェクト
		imgobjObj.style.display			= "none";
	
		// 画像が登録されていませんオブジェクト
		imgobj_nothingObj.style.display	= "block";
	}
	else
	{
		// 画像オブジェクト
		imgobjObj.style.display			= "block";
	
		// 画像が登録されていませんオブジェクト
		imgobj_nothingObj.style.display	= "none";
	}
}

function isCheck(name)
{
	var checkObj		= document.getElementById(name + "_value");
	if (checkObj == null){return false;}

	if (checkObj.value == 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function sendErrorMessage()
{
	ComDomCall(false,"sendErrorMessage",sendErrorMessageafter);
}

function sendErrorMessageafter()
{
	myAlert(ComDomCallGetValue("message"),"location.href='./?act=index';");
}

function readCookie(key)
{
	var sCookie = document.cookie;			// Cookie文字列
	var aData = sCookie.split(";");			// ";"で区切って"キー=値"の配列にする
	var oExp = new RegExp(" ", "g");		// すべての半角スペースを表す正規表現
	key = key.replace(oExp, "");			// 引数keyから半角スペースを除去

	var i = 0;
	while (aData[i])						/* 語句ごとの処理 : マッチする要素を探す */
	{
		var aWord = aData[i].split("=");					// さらに"="で区切る
		aWord[0] = aWord[0].replace(oExp, "");				// 半角スペース除去
		if (key == aWord[0]) return unescape(aWord[1]);		// マッチしたら値を返す
		if (++i >= aData.length) break;						// 要素数を超えたら抜ける
	}
	return "";												// 見つからない時は空文字を返す
}

