var max_width = 320;		//ポップアップ画面の最大横幅[px]

var help = new Array();
function helpObject( help_c, help_t, help_d, help_u ) {
	this.code   = help_c;	//コード
	this.title  = help_t;	//タイトル
	this.desc   = help_d;	//詳細
	this.url    = help_u;	//ＵＲＬ
}

//タグ生成
function createHelp(key) {
	var title = '';
	var desc  = '';
	var url   = '';
	var flg   = '';
	for( i=0; i<help.length ; i++ ) {
		if( help[i].title == key ) {
			title = help[i].title;
			desc  = help[i].desc;
			url   = help[i].url;
			flg   = help[i].flg;
			break;
		}
	}

	var zOut = '';
	zOut += '<div id="HELP_POP" style="position:absolute; top:0px; left:0px; z-index:2" align=left>\n'
	zOut += '<table class="help_tbl">\n';

	//タイトル
	zOut += '<tr><th id="help_caption">';
	zOut += '<em>- ' + title + '</em>';
	zOut += '</th></tr>';

	//詳細
	zOut += '<tr><td height="" valign="top" style="text-align:left; padding:3px 3px 3px 3px;">';
	zOut += desc;
	zOut += '</td></tr>\n';

	zOut += '</table>'
	zOut += '</div>'

	return zOut;
}

//ヘルプ画面表示
function showHelp() {

	//ヘルプ画面を表示
	document.getElementById('help').style.display = "block";
	var ua = navigator.userAgent;
	if( ua.indexOf("MSIE 5.5") >= 0 || ua.indexOf("MSIE 6") >= 0 || ua.indexOf("MSIE 7") >= 0 || ua.indexOf("MSIE 8") >= 0){
		document.getElementById('HELP_POP').style.width = 0;
	} else {
		document.getElementById('HELP_POP').style.width = max_width;
		document.getElementById('HELP_POP').style.width = parseInt(document.getElementById('help_caption').offsetWidth) + 6;
	}
	//横幅調整
	if (parseInt(document.getElementById('HELP_POP').offsetWidth) > max_width) {
		document.getElementById('HELP_POP').style.width = max_width;
	}
	//IFRAMEサイズをヘルプ画面に追従
	window.parent.document.getElementById('help_iframe').style.width  = parseInt(document.getElementById('HELP_POP').offsetWidth);
	window.parent.document.getElementById('help_iframe').style.height = parseInt(document.getElementById('HELP_POP').offsetHeight);
	//IFRAMEを表示
	window.parent.document.getElementById('help_iframe').style.display = "block";

	//ヘルプ画面の各プロパティ取得
	var win_height  = parseInt(document.body.clientHeight);
	var scroll_top  = parseInt(document.body.scrollTop);
	var top         = parseInt(window.parent.document.getElementById('help_iframe').style.top.replace("px",""));
	var pop_height  = parseInt(window.parent.document.getElementById('help_iframe').style.height.replace("px",""));
	var pop_top     = top - scroll_top;
	var win_width   = parseInt(document.body.clientWidth);
	var scroll_left = parseInt(document.body.scrollLeft);
	var left        = parseInt(window.parent.document.getElementById('help_iframe').style.left.replace("px",""));
	var pop_width   = parseInt(window.parent.document.getElementById('help_iframe').style.width.replace("px",""));
	var pop_left    = left - scroll_left;

	//2008.04.04 bi
	//ヘルプ画面の表示位置調整
	if (pop_top + pop_height > win_height) {
		//下方向にはみ出る場合
		top = top - (pop_top + pop_height - win_height);
		if (top < scroll_top) {
			top = scroll_top;
		}


		//bi追加 2008.04.04 bi
		//下にはみ出て・右にもはみ出る時
		//左にずらす（画面の幅＋隙間）
		if (pop_left + pop_width > win_width) {
		left = left-pop_width-12;
		}


	} else {
		if (pop_left + pop_width > win_width) {
			//右方向にはみ出る場合
			left = left - (pop_left + pop_width - win_width);
			if (left < scroll_left) {
				left = scroll_left;
			}
		}
	}

	document.getElementById('help').style.top = top;
	document.getElementById('help').style.left = left;
	window.parent.document.getElementById('help_iframe').style.top = top;
	window.parent.document.getElementById('help_iframe').style.left = left;
}

//ヘルプ画面非表示
function hideHelp() {
	document.getElementById('help').style.display = "none";
	window.parent.document.getElementById('help_iframe').style.display = "none";
}

//【？画像】のonMouseOverイベントを取得
function viewHelp(key) {
	//ブラウザチェック
	if(document.getElemetById || document.style){
		return;
	}
	
	var str = createHelp(key);
	document.getElementById('help').innerHTML  = str;
	showHelp();
}

//【画面全体】のonMouseMoveイベントを取得
window.document.onmousemove = setHelpPos;

function setHelpPos(evt) {
	
	if (!document.getElementById('help')) {
		//helpオブジェクトが読み込まれるまでは処理しない
		return;
	}
	if (document.getElementById('help').style.display == "block"){
		//help画面表示中は処理しない
		return;
	}
	
	//ヘルプ画面の表示位置を取得
	var ua = navigator.userAgent;
	var top  = 0;
	var left = 0;
	if( ua.indexOf("MSIE 5.5") >= 0 || ua.indexOf("MSIE 6") >= 0 || ua.indexOf("MSIE 7") >= 0 || ua.indexOf("MSIE 8") >= 0){
		top  = document.body.scrollTop  + window.event.clientY - window.event.offsetY + 13;
		left = document.body.scrollLeft + window.event.clientX - window.event.offsetX - 2 + 14;
	} else {
		top  = evt.pageY + 13;
		left = evt.pageX -  0 + 14;
	}

	document.getElementById('help').style.top  = top;
	document.getElementById('help').style.left = left;
	window.parent.document.getElementById('help_iframe').style.top  = top;
	window.parent.document.getElementById('help_iframe').style.left = left;
}

