// ポップアップ表示------------------------------------------------------------
var global_x;
var global_y;

function showToolTip(e, days){
	if(document.all)e = event;
	
	// 日付分割
	day_list = days.split("|");
	
	out_width = 270;	//外枠
	pop_font  = 10;		//ポップアップ 棒グラフフォントサイズ

	// ポップアップのインナーHTML作成
	var obj  = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj.style.width = (out_width * (arguments.length - 2)) + 'px';

	str_html = '';
	
	for (var table_index = 2; table_index < arguments.length; table_index++) {

		//渋滞情報があったら
		if ( arguments[table_index].length > 0 ) {
			//ヘッダ描画
			str_html = str_html
			+'<div style="padding:0; float:left; width:' + out_width + 'px;">'
			+'<img src="images/bubble_top.gif" style="vertical-align:bottom;">'
			+'<div style="background-image: url(\'images/bubble_middle.gif\'); background-repeat:repeat-y; position:relative; font-family:"ＭＳ Ｐゴシック"; height:0px;" />';
			
			// 引数を分離
			list_str = arguments[table_index].split("|");
			str_html = str_html
			+'<div id="pt" style="text-align:center; font-size:13px;">' + list_str[0] + '</div>'
			+'<table align="center" style="border:1px solid black; border-collapse:collapse; font-size:11px; width:250px;">'
			+'<tr><td style="background-color:#D6D6D6; border:1px solid black; text-align:right; width:90px;">道路名&nbsp;</td><td style="border:1px solid black; width:150px; table-layout: fixed;"">&nbsp;' + list_str[1] + '</td></tr>'
			+'<tr><td style="background-color:#D6D6D6; border:1px solid black; text-align:right; width:90px;">区間&nbsp;</td><td style="border:1px solid black; width:150px; table-layout: fixed;"">&nbsp;' + list_str[2] + '</td></tr>'
			+'<tr><td style="background-color:#D6D6D6; border:1px solid black; text-align:right; width:90px;">ボトルネック箇所&nbsp;</td><td style="border:1px solid black; width:150px; table-layout: fixed;">&nbsp;' + list_str[3] + '</td></tr>'
			+'</table>'
	
			// リスト用文字列処理
			for (var i = 4; i < list_str.length; i++) {
				if (list_str[i].length > 0) {

					//渋滞情報分離
					list_rec = list_str[i].split("/");
					var list_item_km = new Array();
					var list_item_tm = new Array();
					for(var j = 0; j < list_rec.length; j++) {
						str = list_rec[j];
						value = str.split(":");
						list_item_km[j] = value[0].substring(0, value[0].length-2);
						list_item_tm[j] = value[1];
					}
					
					//出力
					str_html = str_html
					+'<div style="text-align:center; font-size:' + pop_font + 'px; margin:3px 0 0 0px;">【&nbsp;' + day_list[i-4] + '&nbsp;】</div>';

					//時間帯レコード数ループ処理
					for(var j = 0; j < list_item_km.length; j++) {
						str = list_item_tm[j];
						str_km = list_item_km[j];
						str_bar = str_km * 4;
						if (str_bar > 200)
							str_bar = 200;
						if (str_km > 0)
							bar_name = 'graph_bar.jpg';
						else
							bar_name = 'graph_dummy.jpg';
						if ( str_km > 0 )
							str_km = str_km + 'km';
						else
							str_km = '&nbsp;';
					
						str_html = str_html
						   	+'<div style="position: relative;">'
							+'  <div style="font-size:' + pop_font + 'px; position: absolute; top: 1px; left: 5px; width: 60px; text-align:right;">' + str + '</div>'
							+'</div>';
				
						str_html = str_html
							+'<div style="position: relative; left:65px;">'
							+'  <img src="images/' + bar_name + '" width="' + str_bar + '" height="' + String(pop_font + 1) + '"><br />'
							+'  <div style="position: absolute; top: 1px; left: 5px; width: 30px; font-size:' + pop_font + 'px;">' + str_km + '</div>'
							+'</div>';
					}
				}
			}
			
			//フッタ描画
			str_html = 	str_html
			+'  </div>'
			+'  <img src="images/bubble_bottom.gif" style="vertical-align:top;">'
			+'</div>';
		}
	}

	//clipboardData.setData("Text", str_html); //クリップボードコピー
	obj2.innerHTML = str_html;
	obj.style.display = 'block';

	//stスクロールを加味した位置
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);

	clientWidth  = document.documentElement.clientWidth;
	clientHeight = document.documentElement.clientHeight;

	objWidth = obj.offsetWidth;
	objHeight = obj.offsetHeight;
	
	obj2.innerHTML =obj2.innerHTML

	//表示位置判定
	x = 20;
	y = 20;
	barSpace = 65; //スクロールバー用の隙間
	var viewPos; //1:下 2:上 3:右 4:左 0:0.0に表示
	var topPos;
	var leftPos;
	if ( (e.clientY + y + objHeight) < (clientHeight - barSpace) ) {
		topPos = e.clientY + y;
		viewPos = 1;
	} else if ( (e.clientY - y - objHeight) > 0 ) {
		topPos = e.clientY - y - objHeight;
		viewPos = 2;
	} else if ( (e.clientX + x + objWidth) < (clientWidth - barSpace) ) {
		leftPos = e.clientX + x;
		viewPos = 3;
	} else if ( (e.clientX - x - objWidth) > 0) {
		leftPos = e.clientX - x - objWidth;
		viewPos = 4;
	} else {
		leftPos = 0;
		topPos = 0;
		viewPos = 0;
	}

	if (viewPos > 2) {
		if ( (e.clientY + objHeight + barSpace) > clientHeight)
			topPos = (clientHeight - objHeight - barSpace);
		else
			topPos = e.clientY;
		if (topPos < 0) topPos = 0;
	}
	else if (viewPos > 0) {
		if ( (e.clientX + objWidth + barSpace) > clientWidth)
			leftPos = (clientWidth - objWidth - barSpace);
		else
			leftPos = e.clientX;
		if (leftPos < 0) leftPos = 0;
	}

	obj.style.top  = topPos + st + 'px';
	obj.style.left = leftPos + sl + 'px';
	
	global_x = e.clientX;
	global_y = e.clientY;
	
}

// ポップアップ消去------------------------------------------------------------
function hideToolTip(e)
{	
	if ((e.clientX != global_x) || (e.clientY != global_y)) {
		document.getElementById('bubble_tooltip').style.display = 'none';
		global_x = 0;
		global_y = 0;
	}
	
	//document.getElementById('bubble_tooltip').style.display = 'none';
}

// 文字列バイト数カウント
function countByte(str) {
    var count = 0;
    for(var i = 0; i < str.length; i++) {
       if (escape(str.charAt(i)).length < 4) {
          count++;
       }
       else {
          count += 2;
       }
    }
    return count;
}


// 路線選択時の画面遷移--------------------------------------------------------
function RosenSelect(date, disp) {

	rosen = document.RosenForm.RosenCmb.value;
	
	//左フレーム
	frm1 = parent.fleft.document.lPostForm;
	frm1.rosen.value = rosen;
	frm1.mapno.value = 'rhp0099';
	frm1.date.value  = date;
	frm1.disp.value  = disp;
	frm1.submit();
	
	//右フレーム
	frm2 = parent.fright.document.rPostForm;
	frm2.rosen.value = rosen;
	frm2.mapno.value = 'rhp0099';
	frm2.date.value  = date;
	frm2.disp.value  = disp;
	frm2.submit();
}
// その他の画面遷移------------------------------------------------------------
function PostClick(rosen, mapno, date, disp){

	// 左フレーム
	frm1 = parent.fleft.document.lPostForm;

	frm1.rosen.value = rosen;
	frm1.mapno.value = mapno;
	frm1.date.value  = date;
	frm1.disp.value  = disp;
	
	// 右フレーム
	frm2 = parent.fright.document.rPostForm;

	frm2.rosen.value = rosen;
	frm2.mapno.value = mapno;
	frm2.date.value  = date;
	frm2.disp.value  = disp;
	
	// submit
	frm1.submit();
	frm2.submit();
}

