function init_sample_message_tab(level) {
	var adjustPath = get_adjust_path(level);
	var tabURLs = Array();
	tabURLs[1] = "/api/test/sample_message.php?type=1&no=1";
	tabURLs[2] = "/api/test/sample_message.php?type=1&no=2";
	tabURLs[3] = "/api/test/sample_message.php?type=1&no=3";
	tabURLs[4] = "/api/test/sample_message.php?type=1&no=4";
	tabURLs[5] = "/api/test/sample_message.php?type=1&no=5";

	var preload = new Image();
	preload.src = adjustPath+"/img/assist/message/tab_wedding_act.gif";
	preload.src = adjustPath+"/img/assist/message/tab_nyusotsu_act.gif";
	preload.src = adjustPath+"/img/assist/message/tab_event_act.gif";
	preload.src = adjustPath+"/img/assist/message/tab_election_act.gif";
	preload.src = adjustPath+"/img/assist/message/tab_etc_act.gif";

	$.each(tabURLs, function(fragIndex, url) {
		var tabID = "#tab"+fragIndex;

		url = adjustPath+url;

		// タブクリック
		$(tabID).click(function() {
			var categoryID	= "#bunrei_body #category";
			var listID		= "#bunrei_list_body #list";
			var objCategory	= $(categoryID);
			var objList		= $(listID);

//			objCategory.empty();	// 設定値のクリア
			objList.empty();		// 設定値のクリア

			var url1 = url + "&" + new Date().getTime();

			// IE6 で、jQuery.ajax() が使えなかった
			$.get(url1, get_hashed_param(url1), function(xml) {
				$(xml).find("item").each(function() {
					var xIndex = $(this).find("index").text();
					var label= $(this).find("label").text();
					var url2 = adjustPath+decodeURIComponent($(this).find("url").text()) + "&" + new Date().getTime();
					label = label.replace(/\r|\n/g,'');

					var cid = "list"+fragIndex+"_"+xIndex;

					if (is_line_exists(label)) {
						var contents = $("<a>").html(label);

						contents.attr("href", "#_"+cid);

						// 文例クリック
						contents.click(function(){
							// 非表示
							$(listID + " > div:visible").css("display","none");
							// クリックされたタブに対応するものだけを表示させる
							$(listID + " > #"+cid).css("display","block");
							// タイトルの設定
							$("#bunrei_title_font").text(label);
						});

						var tmp = $("<div id='category"+fragIndex+"_"+xIndex+"'>");
						if(xIndex==0){
							tmp.addClass("category_contents");
							tmp.addClass("category_contents_over");
						}else{
							tmp.addClass("category_contents");
						}
						tmp.html(contents);
						tmp.click(function(){
							//選択された色設定
							$(this).parent().children().removeClass("category_contents");
							if($(this).parent().children().hasClass("category_contents_over")){
								$(this).parent().children().removeClass("category_contents_over");
							}

							$(this).parent().children().addClass("category_contents");

							//tmp.removeClass("category_contents");
							tmp.addClass("category_contents_over");

						});

						$("#cc"+fragIndex).append(tmp);
//						objCategory.append(cc);
					}

					// 文例リストの初期値設定と非表示設定
					var div = $("<div id='"+cid+"'>");
					$.get(url2, get_hashed_param(url2), function(xml2) {
						$(xml2).find("item").each(function() {
							var mIndex = $(this).find("index").text();
							var msg = $(this).find("message").text(); // ここでは、unescapeしない！

							msg = msg.replace(/\r|\n/g,'');

							if (is_line_exists(msg)) {
								var tmp = $("<div>");
								tmp.addClass("category_contents");
								tmp.html(get_message_table(msg, mIndex, adjustPath));
								div.append(tmp);
							}
						});

						objList.append(div);

						// 枠線設定（実行する位置に注意）
						$(listID + ' > div > div:last').removeClass("category_contents");
						$(listID + ' > div > div:last').addClass("category_contents_last");
					},'xml'); // End of $.get()

					// タブ選択時、1番目はデフォルトで表示とする
					if (0 == xIndex) {
						div.css({display:"block"});

						// タイトルの初期値設定
						$("#bunrei_title_font").text(label);
					} else {
						div.css({display:"none"});
					}
				}); // end of $.each()

				// 枠線設定
				if (5 == fragIndex) {
					$(categoryID + ' > div > div:last').removeClass("category_contents");
					$(categoryID + ' > div > div:last').addClass("category_contents_last");
				}
			},'xml'); // end of $.get

			// 非表示
			$(categoryID + " > div > div:visible").css("display","none");
			// クリックされたタブに対応するものだけを表示させる
			$(categoryID + " > #cc"+fragIndex).css("display","block");

			// タブ5クリックの場合は、枠線追加
			if (5 == fragIndex) {
				$("#cp5").removeClass("category_p_contents_last");
				$("#cp5").addClass("category_p_contents");
			} else {
				$("#cp5").removeClass("category_p_contents");
				$("#cp5").addClass("category_p_contents_last");
			}

			// タブ画像
			set_tab_images(fragIndex, adjustPath);
		}); // enf of $(tabID).click
	}); // end of $.each(tabURLs)

	// デフォルトで読み込ませておくため、clickイベントを発行
	$('#tab1').click();
}

function set_tab_images(fragIndex, adjustPath) {
	// IE6
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
		// IE6だと、attr("onMouseOver", ".....") が効かなかった
		document.getElementById("tab_img1").src = adjustPath+"/img/assist/message/tab_wedding_off.gif";
		document.getElementById("tab_img2").src = adjustPath+"/img/assist/message/tab_nyusotsu_off.gif";
		document.getElementById("tab_img3").src = adjustPath+"/img/assist/message/tab_event_off.gif";
		document.getElementById("tab_img4").src = adjustPath+"/img/assist/message/tab_election_off.gif";
		document.getElementById("tab_img5").src = adjustPath+"/img/assist/message/tab_etc_off.gif";

		$("#tab_img1").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_wedding_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_wedding_off.gif");});
		$("#tab_img2").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_nyusotsu_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_nyusotsu_off.gif");});
		$("#tab_img3").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_event_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_event_off.gif");});
		$("#tab_img4").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_election_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_election_off.gif");});
		$("#tab_img5").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_etc_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_etc_off.gif");});

		if (1 == fragIndex) {
			document.getElementById("tab_img1").src = adjustPath+"/img/assist/message/tab_wedding_act.gif";
			$("#tab_img1").unbind("mouseenter").unbind("mouseleave");
		}
		if (2 == fragIndex) {
			document.getElementById("tab_img2").src = adjustPath+"/img/assist/message/tab_nyusotsu_act.gif";
			$("#tab_img2").unbind("mouseenter").unbind("mouseleave");
		}
		if (3 == fragIndex) {
			document.getElementById("tab_img3").src = adjustPath+"/img/assist/message/tab_event_act.gif";
			$("#tab_img3").unbind("mouseenter").unbind("mouseleave");
		}
		if (4 == fragIndex) {
			document.getElementById("tab_img4").src = adjustPath+"/img/assist/message/tab_election_act.gif";
			$("#tab_img4").unbind("mouseenter").unbind("mouseleave");
		}
		if (5 == fragIndex) {
			document.getElementById("tab_img5").src = adjustPath+"/img/assist/message/tab_etc_act.gif";
			$("#tab_img5").unbind("mouseenter").unbind("mouseleave");
		}
	} else {
		$("#tab_img1").attr({"src":adjustPath+"/img/assist/message/tab_wedding_off.gif","alt":"結婚", "onMouseOver":"document.getElementById('tab_img1').src='"+adjustPath+"/img/assist/message/tab_wedding_on.gif';", "onMouseOut":"document.getElementById('tab_img1').src='"+adjustPath+"/img/assist/message/tab_wedding_off.gif';","border":0});
		$("#tab_img2").attr({"src":adjustPath+"/img/assist/message/tab_nyusotsu_off.gif","alt":"入学・卒業", "onMouseOver":"this.src='"+adjustPath+"/img/assist/message/tab_nyusotsu_on.gif';", "onMouseOut":"this.src='"+adjustPath+"/img/assist/message/tab_nyusotsu_off.gif';","border":0});
		$("#tab_img3").attr({"src":adjustPath+"/img/assist/message/tab_event_off.gif","alt":"年間行事", "onMouseOver":"this.src='"+adjustPath+"/img/assist/message/tab_event_on.gif';", "onMouseOut":"this.src='"+adjustPath+"/img/assist/message/tab_event_off.gif';","border":0});
		$("#tab_img4").attr({"src":adjustPath+"/img/assist/message/tab_election_off.gif","alt":"選挙", "onMouseOver":"this.src='"+adjustPath+"/img/assist/message/tab_election_on.gif';", "onMouseOut":"this.src='"+adjustPath+"/img/assist/message/tab_election_off.gif';","border":0});
		$("#tab_img5").attr({"src":adjustPath+"/img/assist/message/tab_etc_off.gif","alt":"その他", "onMouseOver":"this.src='"+adjustPath+"/img/assist/message/tab_etc_on.gif';", "onMouseOut":"this.src='"+adjustPath+"/img/assist/message/tab_etc_off.gif';","border":0});

		if (1 == fragIndex) {	$("#tab_img1").attr({"src":adjustPath+"/img/assist/message/tab_wedding_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
		if (2 == fragIndex) {	$("#tab_img2").attr({"src":adjustPath+"/img/assist/message/tab_nyusotsu_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
		if (3 == fragIndex) {	$("#tab_img3").attr({"src":adjustPath+"/img/assist/message/tab_event_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
		if (4 == fragIndex) {	$("#tab_img4").attr({"src":adjustPath+"/img/assist/message/tab_election_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
		if (5 == fragIndex) {	$("#tab_img5").attr({"src":adjustPath+"/img/assist/message/tab_etc_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
	}
}

function init_sample_message_tab_okuyami(level) {
	var adjustPath = get_adjust_path(level);
	var tabURLs = Array();
	tabURLs[1] = "/api/test/sample_message.php?type=1&no=1";
	tabURLs[2] = "/api/test/sample_message.php?type=1&no=2";

	var preload = new Image();
	preload.src = adjustPath+"/img/assist/message/tab_wedding_act.gif";
	preload.src = adjustPath+"/img/assist/message/tab_event_act.gif";

	$.each(tabURLs, function(fragIndex, url) {
		var tabID = "#tab"+fragIndex;

		url = adjustPath+url;

		// タブクリック
		$(tabID).click(function() {
			var categoryID	= "#bunrei_body #category";
			var listID		= "#bunrei_list_body #list";
			var objCategory	= $(categoryID);
			var objList		= $(listID);

//			objCategory.empty();	// 設定値のクリア
			objList.empty();		// 設定値のクリア

			var url1 = url + "&" + new Date().getTime();

			// IE6 で、jQuery.ajax() が使えなかった
			$.get(url1, get_hashed_param(url1), function(xml) {
				$(xml).find("item").each(function() {
					var xIndex = $(this).find("index").text();
					var label= $(this).find("label").text();
					var url2 = adjustPath+decodeURIComponent($(this).find("url").text()) + "&" + new Date().getTime();
					label = label.replace(/\r|\n/g,'');

					var cid = "list"+fragIndex+"_"+xIndex;

					if (is_line_exists(label)) {
						var contents = $("<a>").html(label);

						contents.attr("href", "#_"+cid);

						// 文例クリック
						contents.click(function(){
							// 非表示
							$(listID + " > div:visible").css("display","none");
							// クリックされたタブに対応するものだけを表示させる
							$(listID + " > #"+cid).css("display","block");
							// タイトルの設定
							$("#bunrei_title_font").text(label);
						});

						var tmp = $("<div id='category"+fragIndex+"_"+xIndex+"'>");
						if(xIndex==0){
							tmp.addClass("category_contents");
							tmp.addClass("category_contents_over");
						}else{
							tmp.addClass("category_contents");
						}

						tmp.html(contents);
						tmp.click(function(){
							//選択された色設定
							$(this).parent().children().removeClass("category_contents");
							if($(this).parent().children().hasClass("category_contents_over")){
								$(this).parent().children().removeClass("category_contents_over");
							}

							$(this).parent().children().addClass("category_contents");

							//tmp.removeClass("category_contents");
							tmp.addClass("category_contents_over");

						});

						$("#cc"+fragIndex).append(tmp);
//						objCategory.append(cc);
					}

					// 文例リストの初期値設定と非表示設定
					var div = $("<div id='"+cid+"'>");
					$.get(url2, get_hashed_param(url2), function(xml2) {
						$(xml2).find("item").each(function() {
							var mIndex = $(this).find("index").text();
							var msg = $(this).find("message").text(); // ここでは、unescapeしない！

							msg = msg.replace(/\r|\n/g,'');

							if (is_line_exists(msg)) {
								var tmp = $("<div>");
								tmp.addClass("category_contents");
								tmp.html(get_message_table(msg, mIndex, adjustPath));
								div.append(tmp);
							}
						});

						objList.append(div);

						// 枠線設定（実行する位置に注意）
						$(listID + ' > div > div:last').removeClass("category_contents");
						$(listID + ' > div > div:last').addClass("category_contents_last");
					},'xml'); // End of $.get()

					// タブ選択時、1番目はデフォルトで表示とする
					if (0 == xIndex) {
						div.css({display:"block"});

						// タイトルの初期値設定
						$("#bunrei_title_font").text(label);
					} else {
						div.css({display:"none"});
					}
				}); // end of $.each()

				// 枠線設定
				if (5 == fragIndex) {
					$(categoryID + ' > div > div:last').removeClass("category_contents");
					$(categoryID + ' > div > div:last').addClass("category_contents_last");
				}
			},'xml'); // end of $.get

			// 非表示
			$(categoryID + " > div > div:visible").css("display","none");
			// クリックされたタブに対応するものだけを表示させる
			$(categoryID + " > #cc"+fragIndex).css("display","block");

			// タブ1クリックの場合は、枠線追加
			if (1 == fragIndex) {
				$("#cp1").removeClass("category_p_contents_last");
				$("#cp1").addClass("category_p_contents");
			}

			// タブ画像
			set_tab_images_okuyami(fragIndex, adjustPath);
		}); // enf of $(tabID).click
	}); // end of $.each(tabURLs)

	// デフォルトで読み込ませておくため、clickイベントを発行
	$('#tab1').click();
}

function set_tab_images_okuyami(fragIndex, adjustPath) {
	// IE6
	if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
		// IE6だと、attr("onMouseOver", ".....") が効かなかった
		document.getElementById("tab_img1").src = adjustPath+"/img/assist/message/tab_okuyami_off.gif";
		document.getElementById("tab_img1").src = adjustPath+"/img/assist/message/tab_hoyo_off.gif";

		$("#tab_img1").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_okuyami_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_okuyami_off.gif");});
		$("#tab_img2").hover( function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_hoyo_on.gif");
							},function () { $(this).attr("src", adjustPath+"/img/assist/message/tab_hoyo_off.gif");});


		if (1 == fragIndex) {
			document.getElementById("tab_img1").src = adjustPath+"/img/assist/message/tab_okuyami_act.gif";
			$("#tab_img1").unbind("mouseenter").unbind("mouseleave");
		}
		if (2 == fragIndex) {
			document.getElementById("tab_img2").src = adjustPath+"/img/assist/message/tab_hoyo_act.gif";
			$("#tab_img2").unbind("mouseenter").unbind("mouseleave");
		}

	} else {
		$("#tab_img1").attr({"src":adjustPath+"/img/assist/message/tab_okuyami_off.gif","alt":"お悔やみ", "onMouseOver":"document.getElementById('tab_img1').src='"+adjustPath+"/img/assist/message/tab_okuyami_on.gif';", "onMouseOut":"document.getElementById('tab_img1').src='"+adjustPath+"/img/assist/message/tab_okuyami_off.gif';","border":0});
		$("#tab_img2").attr({"src":adjustPath+"/img/assist/message/tab_hoyo_off.gif","alt":"法要", "onMouseOver":"document.getElementById('tab_img2').src='"+adjustPath+"/img/assist/message/tab_hoyo_on.gif';", "onMouseOut":"document.getElementById('tab_img2').src='"+adjustPath+"/img/assist/message/tab_hoyo_off.gif';","border":0});

		if (1 == fragIndex) {	$("#tab_img1").attr({"src":adjustPath+"/img/assist/message/tab_okuyami_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
		if (2 == fragIndex) {	$("#tab_img2").attr({"src":adjustPath+"/img/assist/message/tab_hoyo_act.gif", "onMouseOver":"", "onMouseOut":"","border":0});}
	}
}


function is_line_exists(line) {
	if ('#' != line.charAt(0) && 0 != line.length) {
		return true;
	}

	return false;
}

//「文例を選択する」ボタンのためのテーブルを構築して返す
function get_message_table(msg, idx, adjustPath) {
	var sampleText = "";
	sampleText += "<table border=\"0\" width=\"100%\"><tbody>";
	if (0 < idx) {
		sampleText += "<tr><td align=\"left\" height=\"30\" colspan=\"3\"><img src=\""+adjustPath+"/img/assist/message/dotline_w.gif\" width=\"571\" height=\"1\" alt=\"破線\"></td></tr>";
	}
	sampleText += "<tr><td style=\"padding:8px 0 8px 0;\"><span style=\"color:#363636;\">"+decodeURIComponent(msg)+"</span></td>";
	sampleText += "<td width=\"1\">&nbsp;</td>";
	sampleText += "<td align=\"right\" valign=\"middle\">";
	sampleText += "<input type=\"image\" src=\""+adjustPath+"/img/order/step2/btn_inyou_off.gif\""
	sampleText += " onMouseOver=\"this.src='"+adjustPath+"/img/order/step2/btn_inyou_on.gif';\" onMouseOut=\"this.src='"+adjustPath+"/img/order/step2/btn_inyou_off.gif';\"";
	sampleText += " onClick=\"set_sample_message('"+msg+"'); return false;\"";	// 改行コードを含まないような形で渡すこと（IE8 や Firefox3.6.7でスクリプトが正常動作しなくなる）
	sampleText += " alt=\"文例を引用する\" />";
	sampleText += "</td>";
	sampleText += "</tr></tbody></table>";

	return sampleText;
}

// 文例を設定する
function set_sample_message(orgText) {
	orgText = decodeURIComponent(orgText);
	var text = orgText.replace(/\r|\n/g,'');	// 改行コード除去
	text = text.replace(/<br ?\/>/g,'\n');		// 改行コードに変換
	text = text.replace(/<\/?[^>]+>/gi, '');	// タグ除去

	// テキストの設定
	//tinyMCE.get('msg').setContent(text);
	document.form.msg.value = text;
	// フォーカスの移動
	//tinyMCE.get('msg').focus();
	document.form.msg.focus();
	// thickboxのウィンドウを閉じる（thickboxの関数を直接コール）
	tb_remove();
}

