/* 
 * システム共通ライブラリ
 * 
 * (C)SmartRams Co.,Ltd. 2009 All Rights Reserved．
 * 
 * 本技術情報には当社の機密情報が含まれておりますので、当社の
 * 書面による承諾がなく第３者に開示することはできません。
 * また、当社の承諾を得た場合であっても、本技術情報は外国為替
 * 及び外国貿易管理法に定める特定技術に該当するため、非居住者
 * に提供する場合には、同法に基づく許可を要することがあります。
 *                                          有限会社 スマート・ラムズ
 *-------------------------------------------------------------------
 * 
 * @package  
 * @author   岡本 順子
 * @language JavaScript
 * @version  1.0
 * @since   2003/11/01 ver1.0 初版作成 岡本順子
 * @info     
 */


/*****************************
  システム独自関数
******************************/
//@@@@@ ページ遷移アンカーの描写
function writePageMove() {
	if (!window.document.MAINFORM["P"])    return;
	if (!window.document.MAINFORM["ALLP"]) return;

	var span = 5;		// 現在ページを基準に前後何ページ分まで表示するか
	var nowp = eval(window.document.MAINFORM["P"].value);		// 現在ページ番号
	var allp = eval(window.document.MAINFORM["ALLP"].value);	// 総ページ数

	// 現在ページ番号を基準にMAXで前後N件ずつ表示
	var min = (nowp > span) ? nowp - span : 1;
	var max = (allp < nowp + span) ? allp : nowp + span;
	var disp = "　";
	if (min > 1) disp += "...　";
	for (i=min;i<=max;i++) {
		if (i == nowp) {
			disp += "<font color=\"red\"><b>" + i + "</b></font>";
		} else {
			disp += "<a href=\"javascript:move_page(" + (i - nowp) + ");\">" + i + "</a>"
		}
		disp += "　"
	}
	if (max < allp) disp += "...　";
	if (allp == 1) disp = "";
	if (!!document.getElementById("PAGEMOVE_TOP")) changeInnerLAYER("PAGEMOVE_TOP", disp);		// 上部用レイヤー
	if (!!document.getElementById("PAGEMOVE_BTM")) changeInnerLAYER("PAGEMOVE_BTM", disp);		// 下部用レイヤー
}
//@@@@@ 並び替えアイコンの差替え
function sortImageActive() {
	if (!window.document.MAINFORM["ODR"]) return;
	var odr = window.document.MAINFORM["ODR"].value;
/*
	var obj = document.images[odr];
	if (!obj) return;
	var imagePath = obj.src;
	var arrayPath = obj.src.split(".");
	imagePath = arrayPath[0] + "_act." + arrayPath[1];
	obj.src = imagePath;
*/
	var obj;
	for (i=0;i<document.images.length;i++) {
		obj = document.images[i];
		if (obj.name == odr) {
			var imagePath = obj.src;
//			var arrayPath = obj.src.split(".");
//			imagePath = arrayPath[0] + "_act." + arrayPath[1];
			var pos = obj.src.lastIndexOf(".");
			imagePath = imagePath.substring(0, pos) + "_act" + imagePath.substring(pos, imagePath.length);
			obj.src = imagePath;
		}
	}
}

/*****************************
  項目クリア関数
******************************/
/*
 * NO・名称セット項目クリア
 * @access	public
 * @param	string		pos		対象項目名接頭句
 * @return	なし
 * @info    対象項目を持つフォーム名は[MAINFORM]固定
 * 			posで指定された接頭句を持つNO･NMの各項目の値をクリアします
 */
function clear_both(pos) {
	if (!window.document.forms["MAINFORM"]) return;
	var frm = window.document.MAINFORM;
	frm[pos + "NO"].value = "";
	frm[pos + "NM"].value = "";
}
/*
 * 単一項目クリア
 * @access	public
 * @param	string		pos		対象項目名
 * @return	なし
 * @info    対象項目を持つフォーム名は[MAINFORM]固定
 * 			posで指定された項目の値をクリアします
 */
function clear_one(pos) {
	var frm = window.document.MAINFORM;
	frm[pos].value = "";
}
/*
 * 選択項目クリア
 * @access	public
 * @param	string		pos		対象項目名
 * @return	なし
 * @info    対象項目を持つフォーム名は[MAINFORM]固定
 * 			posで指定されたSelect項目の値をクリアします
 */
function clear_select(pos) {
	var frm = window.document.MAINFORM;
	frm[pos].selectedIndex = -1;
}

/*****************************
  検索画面サブウィンドウ
******************************/




/*****************************
  文字列関数
******************************/
/*
 * テキストエリアの選択位置へ文字列挿入
 * @access	public
 * @param	string		item	対象項目名
 * @param	string		text	挿入文字列
 * @return	なし
 * @info    対象項目を持つフォーム名は[MAINFORM]固定
 */
function insert_text(pos, str){
	var target = window.document.MAINFORM[pos];
	target.focus();

	if (document.selection != null){
		var sel = document.selection.createRange().text;
		if (sel) {
			document.selection.createRange().text = str;
		} else {
			document.selection.createRange().text = str;
		}
	} else if (target.selectionStart || target.selectionStart == '0') {
		var s = target.selectionStart;
		var e = target.selectionEnd;
		var str2 = target.value.substring(s, e);
		if (str2) {
			target.value = target.value.substring(0, s) + str2 + target.value.substring(e, target.value.length);
		} else {
			target.value = target.value.substring(0, s) + str + target.value.substring(e, target.value.length);
		}
		target.focus();
	} else {
		target.value += str;
	}
}

