<!--
/********************************************************************************
 ・Wikiモード用 ボタン操作用外部スクリプト
 
 ※（主には入力支援用）
 ※ libフォルダに保存されている editor_sub.htm ファイルと連携。
 ********************************************************************************/

	// ============================================================
	// *
	//   入力支援用
	// *
	// ============================================================
	function SettingPaturnTag( VsTag1, VsTag2, VsSetting, VsMode ){
		var Vo_Target = ( document.getElementById('body_form') ) ? document.getElementById('body_form').Edit_Page_Body : document.body_form.Edit_Page_Body;
		//var Vo_Target = ( document.getElementById('body_form') ) ? document.getElementById('body_form').Editor_WikiBody : document.forms[0].Editor_WikiBody;

		Vo_Target.focus();
		if (document.selection != null){
			var VsSelText = document.selection.createRange().text;
			
			if( VsMode == 'box' ){
				VsSelText = VsSelText.replace(/\n/g, "\n ");
				VsSelText = " " + VsSelText;
				VsSelText = VsSelText.replace(/ $/g, "");
				VsSelText += "\n";
			}else if( VsMode == 'indent' ){
				VsSelText = VsSelText.replace(/\n/g, "\n>");
				VsSelText = ">" + VsSelText;
				VsSelText = VsSelText.replace(/>$/g, "");
				VsSelText += "\n";
			}else if( VsMode == 'info' ){
				VsSelText = VsSelText.replace(/\n/g, "\n!");
				VsSelText = "!" + VsSelText;
				VsSelText = VsSelText.replace(/\!$/g, "");
				VsSelText += "\n";
			}
			
			if( VsSelText ){
				document.selection.createRange().text = VsTag1 + VsSelText + VsTag2;
			}else{
				document.selection.createRange().text = VsTag1 + VsSetting + VsTag2;
			}
	
		}else if(Vo_Target.selectionStart || Vo_Target.selectionStart == '0'){
			
			var Vi_StartPosition = Vo_Target.selectionStart;
			var Vi_EndPosition   = Vo_Target.selectionEnd;
			var VsSelText        = Vo_Target.value.substring(Vi_StartPosition, Vi_EndPosition);
	
			if( VsMode == 'box' ){
				VsSelText = VsSelText.replace(/\\n/g, "\n ");
				VsSelText = " " + VsSelText;
				VsSelText = VsSelText.replace(/ $/g, "");
				VsSelText += "\n";
			}else if( VsMode == 'indent' ){
				VsSelText = VsSelText.replace(/\\n/g, "\n>");
				VsSelText = ">" + VsSelText;
				VsSelText = VsSelText.replace(/>$/g, "");
				VsSelText += "\n";
			}else if( VsMode == 'info' ){
				VsSelText = VsSelText.replace(/\\n/g, "\n!");
				VsSelText = "!" + VsSelText;
				VsSelText = VsSelText.replace(/\!$/g, "");
				VsSelText += "\n";
			}
	
			if (VsSelText){
				Vo_Target.value = Vo_Target.value.substring(0, Vi_StartPosition) + VsTag1 + VsSelText  + VsTag2 + Vo_Target.value.substring(Vi_EndPosition, Vo_Target.value.length);
			}else{
				Vo_Target.value = Vo_Target.value.substring(0, Vi_StartPosition) + VsTag1 + VsSetting  + VsTag2 + Vo_Target.value.substring(Vi_EndPosition, Vo_Target.value.length);
			} Vo_Target.focus();
			
		}else{
			Vo_Target.value += VsTag1 + VsSetting + VsTag2;
		}
	}
	
	// ============================================================
	// *
	//   入力支援用　ダイアログ
	// *
	// ============================================================
	function sizeWindowOpen( Mode, Line ){
		var self = new Object();
		self.mode = Mode;
		if( Mode == 'option' && Line == '' ) return;
	
		if( Line != null ) Line = eval("Line" + Line);
	
		var VsWinRet = showModalDialog("lib/editor_sub.htm", self, "dialogWidth : 280px; dialogHeight : " + ( Mode == 'img' ? 250: (Mode == 'font' || Mode == 'other' ? 150 : 140 ) ) +"px");
		if( typeof(VsWinRet) == 'object' ){
			switch( Mode ){
				case 'size':
					SettingPaturnTag('&size(' + VsWinRet.value1 + '){', '};', 'テキスト');
					break;
				case 'color':
					SettingPaturnTag('&color(' + VsWinRet.value1 + '){', '};', 'テキスト');
					break;
				case 'ruby':
					SettingPaturnTag('&ruby(' + VsWinRet.value1 + '){', '};', 'テキスト');
					break;
				case 'bgcolor':
					SettingPaturnTag('&bgcolor(' + VsWinRet.value1 + '){', '};', 'テキスト');
					break;
				case 'font':
					SettingPaturnTag('&font(' + ( VsWinRet.value1 == '' ? '' : 'size='+VsWinRet.value1 ) + ( VsWinRet.value2 == '' ? '' : ' color=' + VsWinRet.value2) + ( VsWinRet.value3 == '' ? '' : ' bgcolor=' + VsWinRet.value3 ) + '){', '};', 'テキスト');
					break;
				case 'other':
					SettingPaturnTag('&' + VsWinRet.value1 + ( VsWinRet.value2 == '' ? '' : '(' + VsWinRet.value2 + '){'), '};', 'テキスト');
					break;
				case 'link':
					SettingPaturnTag('[[', ( VsWinRet.value1 == '' ? '': '>' + VsWinRet.value1 ) + ']]', 'テキスト');
					break;
				case 'img':
					SettingPaturnTag('&img(' + VsWinRet.value1 + ( VsWinRet.value2 == '' ? '': ',' + VsWinRet.value2 ) + ')' + ( VsWinRet.value3 == '' ? '': '(' + VsWinRet.value3 + ')' ) + ';' , '', '');
					break;
				case 'option':
					Line = Line.replace(/__VALUE1__/, VsWinRet.value1);
					Line = Line.replace(/__VALUE2__/, VsWinRet.value2);
					Line = Line.replace(/__VALUE3__/, VsWinRet.value3);
					SettingPaturnTag(Line, '', '');
					break;
			}
		}
	}
	
	// ============================================================
	// *
	//   簡易プレビュー
	// *
	// ============================================================
	function settingTextPreview( Vs_Text ){
		Vs_Text = Vs_Text.replace(/''([^']+?)''/g, "<b>$1</b>");
		Vs_Text = Vs_Text.replace(/""([^"]+?)""/g, "<u>$1</u>");
		Vs_Text = Vs_Text.replace(/##([^#]+?)##/g, "<i>$1</i>");
		Vs_Text = Vs_Text.replace(/\$\$([^\$]+?)\$\$/g, "<s>$1</s>");

		Vs_Text = Vs_Text.replace(/&br;/ig, "<BR>");

		Vs_Text = Vs_Text.replace(/\[\[([^>]+)>(.+)\]\]/ig, "<A Href='#'>$1</A>");
		Vs_Text = Vs_Text.replace(/\[\[([^\]]+)\]\]/ig, "<A Href='#'>$1</A>");

		//Vs_Text = Vs_Text.replace(/(.+)\r\n/g, "$1<BR>\n");
		//Vs_Text = Vs_Text.replace(/(.+)\r/g, "$1<BR>\n");
		Vs_Text = Vs_Text.replace(/^#h([1-6]) (.+)\n/mig, "<h$1>$2</h$1>");

		Vs_Text = Vs_Text.replace(/^(center|right|left):(.+)/mig, "<div align=$1>$2</div>");

		Vs_Text = Vs_Text.replace(/&size\((\d+?)\){([^{}]+?)};/ig, "<span style='font-size: $1pt'>$2<\/span>");
		Vs_Text = Vs_Text.replace(/&color\(([^(){}]+?)\){(.+?)};/ig, "<font color='$1'>$2</font>");
		Vs_Text = Vs_Text.replace(/&bgcolor\(([^(){}]+?)\){(.+?)};/ig, "<span style='background-color: $1'>$2</span>");

		Vs_Text = Vs_Text.replace(/&ruby\((.+?)\){(.+?)};/g, "<ruby><rp>(<\/rp><rb>$2<\/rb><rt>$1<\/rt><rp>)<\/rp><\/ruby>");

		Vs_Text = Vs_Text.replace(/~(\s*)<>/g, "<BR>");
		Vs_Text = Vs_Text.replace(/\n/g, "<BR>");
		Vs_Text = Vs_Text.replace(/^<>/mg, "");

/*
		$Ms_Line =~ s/&ruby\((.+?)\){(.+?)};/<ruby><rp>(<\/rp><rb>$2<\/rb><rt>$1<\/rt><rp>)<\/rp><\/ruby>/ig;

		$Ms_Line =~ s/&font\(([^(){}]+?)\){([^{}]+?)};/wiki_font($1, $2)/eig;
		$Ms_Line =~ s/&size\((\d+?)\){(.+?)};/<span style='font-size: $1pt'>$2<\/span>/ig;
		#$Ms_Line =~ s/&size\((\d+?)\){([^{}]+?)};/<span style='font-size: $1pt'>$2<\/span>/ig;
		$Ms_Line =~ s/&color\(([^(){}]+?)\){(.+?)};/<font color='$1'>$2<\/font>/ig;
		#$Ms_Line =~ s/&color\(([^(){}]+?)\){(.+?)};/<span style='color: $1'>$2<\/span>/ig;
		#$Ms_Line =~ s/&color\(([^(){}]+?)\){([^{}]+?)};/<span style='color: $1'>$2<\/span>/ig;
		$Ms_Line =~ s/&bgcolor\(([^(){}]+?)\){(.+?)};/<span style='background-color: $1'>$2<\/span>/ig;
*/
		//Vs_Text = Vs_Text.replace(/\n/g, "<>");
		//Vs_Text = Vs_Text.replace(/#start(?:\s)absolute<BR>(.+)#end(?:\s)absolute/ig, "<div style='position : absolute; width : 97%'><div class=Wiki_Absolute style=''>$1</div></div>\n");

		return Vs_Text;
	}

	// ============================================================
	// *
	//   [ 共通 ] オブジェクトオープン用
	// *
	// ============================================================
	function objDisplayControl( obj ){
		var objLength = Number( obj.length );
		if( isNaN(objLength) ){
			obj.style.display = ( obj.style.display == 'none') ? 'block': 'none';
		}else{
			for( var i = 0; i < objLength; i++ )
				obj[i].style.display = ( obj[i].style.display == 'none') ? 'block': 'none';
		} return false;
	}
	
	// ============================================================
	// *
	//   [ 共通 ] Detailフィールドオープン用
	// *
	// ============================================================
	function DetailOpenMethod( objBaseName, Mode ){
		var objOpn = document.getElementById('div_' + objBaseName);
		var objCls = document.getElementById('span_' + objBaseName);
		objCls.style.display = (objCls.style.display == Mode) ? 'none' : Mode;
		objOpn.style.display = (objOpn.style.display == Mode) ? 'none' : Mode;
	}

	// ============================================================
	// *
	//   [ 共通 ] コメント更新用
	// *
	// ============================================================
	function CommentUpdField( Fobj, setYnikeID, setNames, setBodys){
		var self = new Object();
		self.YnikeID = setYnikeID;
		self.Names   = setNames;
		self.Message = setBodys;
		var VsWinRet = showModalDialog("lib/comment_upd.htm", self, "dialogWidth : 480px; dialogHeight : 220px");
		if( typeof(VsWinRet) == 'object' ){
			Fobj.Comment_PostedYnikeID.value = setYnikeID;
			Fobj.Comment_PostedName.value    = setNames;
			Fobj.Comment_PostedBody.value    = VsWinRet.Message;
			Fobj.submit();
		}

		return false;
	}
	
	// ============================================================
	// *
	//   [ 共通 ] バイト数カウント用
	// *
	// ============================================================
	function StringCounter( strValue ) {
		var Zen_strValue = strValue.replace(/[\x00-\xFF|\uFF61-\uFF9F]/g, "");
		var Han_Length   = strValue.length - Zen_strValue.length;
		var Zen_Length   = Zen_strValue.length;
		return Han_Length + Zen_Length * 2;
	}

//-->