// -*- c++ -*-
// Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.
// This is free software with ABSOLUTELY NO WARRANTY.
// You can redistribute it and/or modify it under the terms of the GNU GPL2.
// reference: http://nais.to/~yto/tools/contenteditablewiki/

function Editor(xp) {
  this.xp = xp;
}

// global
var g_editor = new Editor(g_xp);

function save() {
  var t = document.getElementById('text');
  var e = document.getElementById('weditor');
  var f = document.getElementById('form');

  t.value = e.innerHTML;
  f.submit();
}

function command(com) { document.execCommand(com); }
function image() { document.execCommand("InsertImage", true); }
function markup(tag) {
  var range = document.selection.createRange();
  range.pasteHTML("<"+tag+">"+range.text+"</"+tag+">");
}
function deleteTags() {
  var range = document.selection.createRange();
  range.pasteHTML(range.text.replace("<[^>]+>", " "));
}

// ref. http://blade.nagaokaut.ac.jp/
function chk() {
  var name = navigator.appName;
  var ver = navigator.appVersion;
  if (name.charAt(0) == "M") {
    if (ver.charAt(0) >= 5 ||
        ver.indexOf(" 5.5") >= 0 ||
        ver.indexOf(" 6") >= 0
	)
      return(true);
    return(false);
  } else if (name.charAt(0) == "N") {
    if (ver.charAt(0) >= 5)
      return(true);
    return(false);
  } else {
    return(false);
  }
}

function hilight(x) {
  if (!chk()) return;
  if (parent) {
    try {
      parent.frames[0].hilight(x);
    } catch(e) {
      //alert(e);
    }
  }
}

function inspectAllProp(e) {
  var str = "";
  for (k in e) {
    var v = e[k];
    if (v) {
      var vs = ""+v;
      if (!vs.match(/function/)) {
	str += "["+k+":"+vs+"]";
      }
    }
  }
  return str;
}

//Navigation Bar
var IE = document.all;
var PosTimer;

function stickNavi() {
  var y = document.body.scrollTop;
  var s = document.getElementById('toolbar').style;
  s.top  = "0"+y+"px";
  s.right = "0"+"px";
}

function stickNaviLoop() {
  if (PosTimer) { clearTimeout(PosTimer); }
  stickNavi();
  PosTimer = setTimeout("stickNaviLoop()", 20);
}

function setNavi() {
  alert("setNavi");
  stickNaviLoop();
}
