function show_edit() {
	document.getElementById('window_edit').style.display = "block";
	document.getElementById("window_preview").style.display = "none";
	document.getElementById("window_title").style.display = "none";

	document.getElementById("navi1").className = "current";
	document.getElementById("navi2").className = "";
	document.getElementById("navi3").className = "";

}

function show_preview() {
	
	document.getElementById("window_edit").style.display = "none";
	document.getElementById("window_preview").style.display = "block";
	document.getElementById("window_title").style.display = "none";

	document.getElementById("navi1").className = "";
	document.getElementById("navi2").className = "current";
	document.getElementById("navi3").className = "";
	
	body = $("body").value;
	getPreview(body);
}

function show_title() {
	
	document.getElementById("window_edit").style.display = "none";
	document.getElementById("window_preview").style.display = "none";
	document.getElementById("window_title").style.display = "block";

	document.getElementById("navi1").className = "";
	document.getElementById("navi2").className = "";
	document.getElementById("navi3").className = "current";

}


function getPreview(html)
{
	d = new Date();
	var rnd = d.getTime();
	
	var url = 'preview.php';
	var pars = $("form").serialize();
    $.ajax( {
        type : "POST",
        url : url,
        data : pars,
        success : function(txt) {
              document.getElementById("ajax_preview").innerHTML = txt;
          },
          error : function() {
            reportError();
          }
      });
	
//	var myAjax = new Ajax.Updater(
//				{success: 'ajax_preview'}, 
//				url, 
//				{
//					method: 'post', 
//					parameters: pars, 
//					onFailure: reportError
//				});
}

function reportError(request)
{
	alert('プレビュー表示に失敗しました');
}

function showTabbar() {
	document.writeln('<div id="tabsJ">');
	document.writeln('<ul>');
	document.writeln('<li id="navi1" class="tab current"><a href="#" onclick="javascript:show_edit();return false;" id="a_edit"><span id="span_edit">本文編集</span></a></li>');
	document.writeln('<li id="navi2"><a href="#" onclick="javascript:show_preview();return false;" id="a_preview"><span id="span_preview">プレビュー表示</span></a></li>');
	document.writeln('<li id="navi3"><a href="#" onclick="javascript:show_title();return false;" id="a_title"><span id="span_title">タイトル編集</span></a></li>');
	document.writeln('</ul>');
	document.writeln('</div>');
}



function showWikiToolbar() {
  document.writeln("<div id='wiki_toolbar'>");
  document.write('<img src="./editor/head1.gif" onclick="fstins(\'*\');return false;" alt="見出し1" />');
  document.write('<img src="./editor/head2.gif" onclick="fstins(\'**\');return false;" alt="見出し2" />');
  document.write('<img src="./editor/head3.gif" onclick="fstins(\'***\');return false;" alt="見出し3" />');
  document.write('<img src="./editor/sepa.gif" alt="|" />');
  document.write('<img src="./editor/bold.gif" onclick="enclose(\'' + '<[B]>' + '\', \''+ '<[/B]>' +'\');return false;" alt="太字" />');
  document.write('<img src="./editor/strikeline.gif" onclick="enclose(\'' + '<[S]>' + '\', \''+ '<[/S]>' +'\');return false;" alt="打ち消し線" />');
  document.write('<img src="./editor/sepa.gif" alt="|" />');
  document.write('<img src="./editor/outside_link.gif" onclick="addLink();  return false;" alt="リンク" />');
  document.write('<img src="./editor/sepa.gif" alt="|" />');
  document.write('<img src="./editor/unordered_list1.gif" onclick="fstins(\'-\');  return false;" alt="番号無しリスト1" />');
  document.write('<img src="./editor/unordered_list2.gif" onclick="fstins(\'--\'); return false;" alt="番号無しリスト2" />');
  document.write('<img src="./editor/unordered_list3.gif" onclick="fstins(\'---\');return false;" alt="番号無しリスト3" />');
  document.write('<img src="./editor/ordered_list1.gif" onclick="fstins(\'+\');  return false;" alt="番号付きリスト1" />');
  document.write('<img src="./editor/ordered_list2.gif" onclick="fstins(\'++\'); return false;" alt="番号付きリスト2" />');
  document.write('<img src="./editor/ordered_list3.gif" onclick="fstins(\'+++\');return false;" alt="番号付きリスト3" />');
  document.write('<img src="./editor/sepa.gif" alt="|" />');
  document.write('<img src="./editor/quotation.gif" onclick="fstins(\'&gt;\');return false;" alt="引用" />');
  document.write('<img src="./editor/pre.gif" onclick="fstins(\' \');return false;" alt="整形済みテキスト" />');
  document.write('<img src="./editor/horizontal_rule.gif" onclick="enclose(\'----\', \'\');return false;" alt="水平線" />');
  document.writeln("</div>");
}
