//
// Unless otherwise stated:
// Copyright (C) 2005-2006  ASAHI Net, Inc.  ALL RIGHTS RESERVED
//

// Compatibility

var manaba = new Object;
manaba.option = new Object;
manaba.alert = function(msg) {
 alert(msg + "(error reported by $Id: default.js,v 1.19 2009/01/21 07:15:57 admin Exp $)");
}

manaba.color = new Object;
manaba.color.inputblur = '#ffffff';
manaba.color.inputfocus = '#EAF9FA';

// BrowserInfo - ブラウザ情報
function BrowserInfo() {
 var ua = navigator.userAgent.toLowerCase();
 var info = new Object();
 info.isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1);
 info.isGecko = (navigator.product == "Gecko");
 info.isOpera = window.opera;
 if (navigator.userAgent.match (/Safari/)) {
   info.isSafari = true;
 } else {
  info.isSafari = false;
 }
 if (info.isGecko) {
  info.isNetscape = (ua.indexOf("netscape") != -1);
 }
 info.rteditable = false;
 if (info.isIE && navigator.appVersion.match(/MSIE (\d+\.\d+)/)) {
  info.rteditable = (RegExp.$1 >= 5.5);
 } else if (info.isSafari) {
  info.rteditable = true;
 } else if (info.isOpera) {
  try {
   if (window.opera.version () >= 9) {
    info.rteditable = true;
   }
  } catch (e) {}
 } else if (info.isGecko) {
  info.rteditable = (navigator.productSub >= 20030210);
 }
 return info;
}

var gBrowser = BrowserInfo();

/* 汎用関数 */
manaba.escapeEntity = function (text) {
 text = text
  .replace (/&/g, "&amp;")
  .replace (/</g, "&lt;")
  .replace (/>/g, "&gt;")
  .replace (/\"/g, "&quot;");
 return text;
}

manaba.addevent = function(o, type, fn) {
 if ("addEventListener" in o) {
  o.addEventListener(type, fn, false);
  return true;
 } else if ("attachEvent" in o) {
  var r = o.attachEvent("on" + type, fn);
  return r;
 } else {
  return false;
 }
};

manaba.removeevent = function(o, type, fn) {
 if ("removeEventListener" in o) {
  o.removeEventListener(type, fn, false);
  return true;
 } else if ("detachEvent" in o) {
  var r = o.detachEvent("on" + type, fn);
  return r;
 } else {
  return false;
 }
};

manaba.findParentNode = function (node, nodeName) {
 while (node) {
  if (node.nodeName.toLowerCase () == nodeName) {
   return node;
  }
  node = node.parentNode;
 }
 return null;
};

// DOM互換性ライブラリ- insertAdjacentHTML
if (! (document.body && document.body.insertAdjacentHTML) || ! HTMLElement) {
 try {
  if (! HTMLElement) {
   document.createElement('html');
   HTMLElement = { prototype: window["[[DOMElement.prototype]]"] || {}};
  }
  HTMLElement.prototype.insertAdjacentHTML = function(where, text) {
   var r = this.ownerDocument.createRange();
   if (where == 'afterBegin' || where == 'beforeEnd') {
    r.selectNodeContents(this);
    r.collapse(where == 'afterBegin');
   } else {
    r.selectNode(this);
    r.collapse(where == 'beforeBegin');
   }
   r.insertNode(r.createContextualFragment(text));
  }
  if (!gBrowser.isSafari) {
   HTMLElement.prototype.addEventListener = function(name,func,dir) {
    this.attachEvent(name, func);
   }
  }
 } catch(err) {
 }
}

// nullfunc
function nullfunc() { return false; }

// getEventPageX - イベント発生時のXポジション
function getEventPageX(e,winpos){
 if (! e) var e = window.event;
 if (window.opera) {     // Opera
  return (document.documentElement ? window.pageXOffset : 0) + e.clientX;
 } else if (e.pageX) {
  return e.pageX + (winpos ? window.screenX - window.pageXOffset : 0);   // Mozilla, NN4, Safari
 } else if (e.clientX) { // IE, others
  var sl = 0;
  if (document.documentElement && document.documentElement.scrollLeft) {
   sl = document.documentElement.scrollLeft;
  } else if (document.body && document.body.scrollLeft) {
   sl = document.body.scrollLeft;
  } else if (window.scrollX || window.pageXOffset)  {
   sl = (window.scrollX || window.pageXOffset);
  }
  if (winpos) sl += window.screenLeft;
  return sl + e.clientX;         
 }
 return 0;
}

// getEventPageY - イベント発生時のYポジション
function getEventPageY(e,winpos){
 if (! e) var e = window.event;
 if (window.opera) {     // Opera
  return (document.documentElement ? window.pageYOffset : 0) + e.clientY;
 } else if (e.pageY) {
  return e.pageY + (winpos ? window.screenY - window.pageYOffset : 0);   // Mozilla, NN4, Safari
 } else if (e.clientY) { // IE, others
  var st = 0;
  if (document.documentElement && document.documentElement.scrollTop) {
   st = document.documentElement.scrollTop;
  } else if (document.body && document.body.scrollTop) {
   st = document.body.scrollTop;
  } else if (window.scrollY || window.pageYOffset) {
   st = (window.scrollY || window.pageYOffset);
  }
  if (winpos) st = window.screenTop;
  return st + e.clientY;         
 }
 return 0;
}

// nextSiblingNT - テキストノードのない nextSibling
function nextSiblingNT(e) {
 while (e.nextSibling.nodeType == 3) {
  e = e.nextSibling;
 }
 return e.nextSibling;
}

// previousSiblingNT - テキストノードのない previousSibling
function previousSiblingNT(e) {
 while (e.previousSibling.nodeType == 3) {
  e = e.previousSibling;
 }
 return e.previousSibling;
}

// getElementsByClass - クラスでエレメントを探索 (Copyright Dustin Diaz 2005)
function getElementsByClass(searchClass, node, tag) {
 var classElements = new Array();
 if ( node == null ) node = document;
 if ( tag == null ) tag = '*';
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
 for (i = 0, j = 0;  i < elsLen;  i++) {
  if ( pattern.test(els[i].className) ) {
   classElements[j] = els[i];
   j++;
  }
 }
 return classElements;
}

// naturalSize - 画像の元のサイズを naturalWidth, naturalHeight に取得
function naturalSize(o) {
 var naturalwidth  = -1;
 var naturalheight = -1;
 if (o.naturalWidth != null) {
  return true;  // naturalWidth is supported, return immediately
 } else if (o.runtimeStyle) {
  o.runtimeStyle.width= 'auto';
  o.runtimeStyle.height= 'auto';
  o.runtimeStyle.borderWidth= '0';
  o.runtimeStyle.padding= '0';
  naturalwidth = o.offsetWidth;
  naturalheight = o.offsetHeight;
  o.runtimeStyle.width= '';
  o.runtimeStyle.height= '';
  o.runtimeStyle.borderWidth= '';
  o.runtimeStyle.padding= '';
 } else  {
  var oclone = o.cloneNode(true);
  o.className = '';
  o.style.width = 'auto !important';
  o.style.height = 'auto !important';
  o.style.borderWidth= '0 !important';
  o.style.padding= '0 !important';
  o.removeAttribute('width');
  o.removeAttribute('height');
  naturalwidth = o.width;
  naturalheight = o.height;
  o.setAttribute('width', oclone.getAttribute('width'));
  o.setAttribute('height', oclone.getAttribute('height'));
  o.style.width = oclone.style.width;
  o.style.height = oclone.style.height;
  o.style.padding = oclone.style.padding;
  o.style.borderWidth = oclone.style.borderWidth;
  o.style.className = oclone.style.className;
 }

 if (naturalwidth > 0) {
  o.naturalWidth = naturalwidth;
  o.naturalHeight = naturalheight;
  return true;
 } else {
  return false;  // not supported on this platform
 } 
}

// 画像自動リサイズ
function ImageResize(o, width) {
 if (naturalSize(o) && o.naturalWidth > width) {
  o.style.width = width + 'px';
  o.style.height = Math.floor(width / o.naturalWidth * o.naturalHeight) + 'px';
 } else {
  ; // not supported on this platform, or size is small enough
 }
}

// タイマライブラリ
var gTimer = new Array;
var gTimerOffset = 0;

// SetTimeoutEvent - タイムアウトイベントを設定する
function SetTimeoutEvent(func, arg, value, count) {
 var o = new Object;
 o.func = func;
 o.arg = arg;
 o.count = count || 1;
 o.id = setTimeout("TimeoutEvent(" + gTimerOffset + ")", value);
 gTimer[gTimerOffset++] = o;
}

// TimeoutEvent - タイムアウトイベント
function TimeoutEvent(arg) {
 var o = gTimer[arg];
 if (o) {
  o.func(o.arg);
  if (--o.count <= 0) {
   clearInterval(o.id);
   gTimer[arg] = null;
  }
 }
}

// イベントターゲット
function evtarget(e) {
 var targ;

 if (! e) var e = window.event;
 if (e.target) {
  targ = e.target;
 } else if (e.srcElement) {
  targ = e.srcElement;
 }
 if (targ.nodeType == 3) targ = targ.parentNode;
 return targ;
}

// タグ
function tagString(s, tag) {
 return '<' + tag + '>' + s + '</' + tag + '>';
}

/* button up/down */
function ButtonDown(e) {
 e.style.borderStyle = 'inset';
}

function ButtonUp(e) {
 e.style.borderStyle = 'outset';
}

/* language */
var Lang = 'ja';

function SetLang(n) {
 if (n == 'en' /* || n == 'de' */ ) {
  Lang = n;
 } else {
  Lang = 'ja';
 }
}

function TestLoc(e) {
 var t = "Left: " + e.scrollLeft+ "\n" +
  "Top: " + e.offsetY + "\n" +
  "Style left: " + e.style.left + "\n" +
  "Style top: " + e.style.top ;
 alert(t);
}

var prevfocus, prevhilite;

function texthilite(element) {
 var e;

 e = document.getElementById('t' + element);
 if (prevhilite && prevfocus != prevhilite) {
   if (prevhilite.className == 'row0') {
    prevhilite.style.backgroundColor = '#F8F8F8'
   } else {
    prevhilite.style.backgroundColor = '#FFFFFF'
   }
 }
 if (e != prevfocus) {
  e.style.backgroundColor = '#e8f0ff'
 }
 prevhilite = e
}

function textfocus(element) {
 var e;

 e = document.getElementById('t' + element);
 if (! e) return;
 if (prevfocus != e && prevfocus != prevhilite) {
  prevfocus.style.backgroundColor = '#FFFFFF'
 }
 e.style.backgroundColor = '#e8f0ff'
 prevfocus = e
 document.getElementById(element).focus()
}

function textunfocus(element) {
 document.getElementById('t' + element).style.backgroundColor = '#FFFFFF'
 document.getElementById('b' + element).style.visibility = 'hidden';
}

function highlight(element) {
 document.getElementById(element).style.color = '#FF0000'
}

function dim(element) {
 document.getElementById(element).style.color = '#000000'
}

function bgcolor(object, color) {
 object.style.backgroundColor = color;
}

function scrolldown() {
 window.scrollBy(0,400)
}

var prevhilite;

function hiliteById(id) {
 var e = document.getElementById(id);
 if (e) hilite(e, 1);
}

// hilite - most used highlight function
function hilite(element, dontmark, next) {
 if (prevhilite) {
  if (prevhilite.className.match(/row1/)) {
   prevhilite.style.backgroundColor = '#fff';
   if (next) nextSiblingNT(prevhilite).style.backgroundColor = '#fff';
  } else {
   prevhilite.style.backgroundColor = '#f5f6fe'
   if (next) nextSiblingNT(prevhilite).style.backgroundColor = '#f5f6fe';
  }
 }
 var el = document.getElementsByTagName("body");
 for (var i = 0;  i < el.length;  i++) {
  if (el[i].className.match("teacherview")) {
   element.style.backgroundColor = '#f2f9fc';
   if (next) nextSiblingNT(element).style.backgroundColor = '#f2f9fc';
  } else if (el[i].className.match("adminview")) {
   element.style.backgroundColor = '#fee';
   if (next) nextSiblingNT(element).style.backgroundColor = '#fee';
  } else {
   element.style.backgroundColor = '#e8f0ff';
   if (next) nextSiblingNT(element).style.backgroundColor = '#e8f0ff';
  }
 }
 prevhilite = element;
 if (! dontmark) {
  SetTimeoutEvent(MarkAsRead, element, 300, 1)
 }
}

// メンバーリスト用
function hilitemblsit(element, dontmark, next) {
 if (prevhilite) {
  if (prevhilite.className.match(/row1/)) {
   prevhilite.style.backgroundColor = '#fff'
   if (next) nextSiblingNT(prevhilite).style.backgroundColor = '#fff';
  } else {
   prevhilite.style.backgroundColor = '#fafafa'
   if (next) nextSiblingNT(prevhilite).style.backgroundColor = '#fafafa';
  }
 }
 var el = document.getElementsByTagName("body");
 for (var i = 0;  i < el.length;  i++) {
  if (el[i].className.match("teacherview")) {
   element.style.backgroundColor = '#f2f9fc';
   if (next) nextSiblingNT(element).style.backgroundColor = '#f2f9fc';
  } else if (el[i].className.match("adminview")) {
   element.style.backgroundColor = '#fee';
   if (next) nextSiblingNT(element).style.backgroundColor = '#fee';
  } else {
   element.style.backgroundColor = '#eaeaea';
   if (next) nextSiblingNT(element).style.backgroundColor = '#eaeaea';
  }
 }
 prevhilite = element;
 if (! dontmark) {
  SetTimeoutEvent(MarkAsRead, element, 300, 1)
 }
}





function unhilite(element) {
 /* no longer necessary */
}

var gArticleHilite = new Object();
gArticleHilite.o = null;
gArticleHilite.ahnode = null;
gArticleHilite.asnode = null;
gArticleHilite.abnode = null;
gArticleHilite.h3node = null;

// findnode
function findnode(x) {
 var h3node, ahnode;

 var o = x.object;
 for (o = o.firstChild;  o;  o = o.nextSibling) {
  if (o.tagName == 'H3' && o.className.match(/articlenumber/)) x.h3node = o;
  if (o.tagName == 'DIV') {
   if (o.className.match(/articleheader/)) x.ahnode = o;
   if (o.className.match(/articlesubject/)) x.asnode = o;
   if (o.className.match(/articlebody/)) x.abnode = o;
   x.object = o;
   findnode(x);
  }
 }
}

// HiliteArticle - high light an article
function HiliteArticle(o) {
 if (gArticleHilite.o == o) return false;
 if (! o.className.match(/articlecontainer/)) return false;
 var x = new Object();
 x.object = o;
 findnode(x);
 o.style.backgroundColor = '#e8f0ff';
 x.ahnode.style.backgroundColor = '#e8f0ff';
 x.ahnode.style.borderColor = '#4660f2';
 x.abnode.style.borderColor = '#4660f2';
 x.asnode.style.color = '#3851d8';
 x.h3node.style.backgroundColor = '#4660f2';
 if (gArticleHilite.o) {
  gArticleHilite.o.style.backgroundColor = '#fff';
  gArticleHilite.ahnode.style.backgroundColor = '#c8d2e9';
  gArticleHilite.ahnode.style.borderColor = '#534b8f';
  gArticleHilite.abnode.style.borderColor = '#534b8f';
  gArticleHilite.asnode.style.color = '#221964';
  gArticleHilite.h3node.style.backgroundColor = '#534b8f';
 }
 gArticleHilite.o = o;
 gArticleHilite.ahnode = x.ahnode;
 gArticleHilite.asnode = x.asnode;
 gArticleHilite.abnode = x.abnode;
 gArticleHilite.h3node = x.h3node;
}

var prevhilite1, prevhilite2;

function hilite2(element1, element2) {
 if (prevhilite1) {
  if (prevhilite1.className == 'row0') {
    prevhilite1.style.backgroundColor = '#F8F8F8';
  } else {
    prevhilite1.style.backgroundColor = '#FFFFFF';
  }
 }
 if (prevhilite2) {
  prevhilite2.style.backgroundColor = '#FFFFFF';
  if (prevhilite2.className == 'row0') {
    prevhilite2.style.backgroundColor = '#F8F8F8';
  } else {
    prevhilite2.style.backgroundColor = '#FFFFFF';
  }
 }
 element1.style.backgroundColor = '#ddccff'
 element2.style.backgroundColor = '#ddccff'
 prevhilite1 = element1;
 prevhilite2 = element2;
}
 
function textarea_wider(id) {
 var e;

 e = document.getElementById(id);
 e.cols = e.cols + 10;
}

function textarea_narrower(id) {
 var e;

 e = document.getElementById(id);
 e.cols = (e.cols - 10 < 30 ? 30 : e.cols - 10);
}

function textarea_taller(id) {
 var e;

 e = document.getElementById(id);
 e.rows = e.rows + 10;
}

function textarea_shorter(id) {
 var e;

 e = document.getElementById(id);
 e.rows = (e.rows - 10 < 10 ? 10 : e.rows - 10);
}

function textarea_savesize(id) {
 var e, r, c;

 e = document.getElementById(id);
 r = document.getElementById('cTextArea_rows');
 c = document.getElementById('cTextArea_cols');
 if (r) r.value = e.rows;
 if (c) c.value = e.cols;
}

function makevisible(element) {
 document.getElementById(element).style.display = 'block';
 document.getElementById(element).style.visibility = 'visible';
 return false;
}

// MakeVisible
function MakeVisible(o) {
 o.style.visibility = 'visible';
} 

// SwitchVisibleElement - スイッチを押すと表示エレメントが変わる
function SwitchVisibleElement(swid, eid) {
 var o = document.getElementById(swid);
 if (o) o.style.display = 'none';
 o = document.getElementById(eid);
 if (o) {
  o.style.display = 'block';
  o.style.visibility = 'visible';
 }
 return false;
}

var currentactive = 'section0';

function activate(element) {
 var o;

 if (element == currentactive) {
  return;
 }
 o = document.getElementById(currentactive);
 o.style.visibility = 'hidden';
 o.style.display = 'none';
 o = document.getElementById(element);
 o.style.visibility = 'visible';
 o.style.display = 'block';
 currentactive = element;
 o = document.getElementById('input_' + currentactive);
 if (o) {
  o.focus();
 } else {
  alert();
 }
}

/* FlipDisplayById - flip display or none */
function FlipDisplayById(id) {
 var o = document.getElementById(id);
 if (o) {
  if (o.style.visibility == 'hidden' || o.style.visibility == "") {
   o.style.display = 'block';
   o.style.visibility = 'visible';
  } else {
   o.style.display = 'none';
   o.style.visibility = 'hidden';
  }
 }
 return false;
}

/* FlipDisplayAndHide - flip display and hide myself */
function FlipDisplayAndHide(o, id) {
 o.style.display = 'none';
 return FlipDisplayById(id);
}

/* FlipOnDemandHelp - flip on-deman help */
function FlipOnDemandHelp() {
 var list = getElementsByClass('ondemandhelp', document, 'div');

 for (var i = 0;  i < list.length;  i++) {
  var current = list[i].style.display;
  list[i].style.display = (current == 'none' || current == '' ? 'block' : 'none');
 }
}

/* Open - open a URL */
function Open(url) {
 window.open(url,"_self");
}

/* findchildanchor(e) - find anchor from descending elements */
function findchildanchor(e, sibling) {
 while (e) {
  if (e.tagName == 'A') return e.href;
  if (e.firstChild) return findchildanchor(e.firstChild, 1);
  if (sibling) e = e.nextSibling;  else break;
 }
 return false;
}

/* OpenChildAnchor - open URL of the first anchor in the child nodes */
function OpenChildAnchor(e) {
 var href = findchildanchor(e, 0);
 if (href) window.open(href, "_self");
 return false;
}

/* MarkAsRead - change color from unread to recently read */
function MarkAsRead(e) {
 var o = e.firstChild;

 while (o) {
  if (o.className == 'GRIunread') {
   if (o.id != 'marked') {
    bgs.src = '/marksound.wav';
    o.id = 'marked';
    o.style.borderLeftColor = '#FFCCCC';
   }
  } else {
   if (MarkAsRead(o)) return false;
  }
  o = o.nextSibling;
 }
 return false;
}

/* findobject */
function findobject(name) {
 var o;

 o = document.getElementById(name);
 if (o && ! o.disabled && o.style.display != "none" && o.focus) {
  return o;
 }
 return null;
}

/* FocusOnLoad - focus on load */
function FocusOnLoad() {
 var o;
 try {
  if (o = findobject('AFHasNext')) return o.focus();
  if (o = findobject('AFSkip')) return o.focus();
  if (o = findobject('AFGoBack')) return o.focus();
  if (o = findobject('AFShowDetail')) return o.focus();
  if (o = findobject('AFFirstInput')) return o.focus();
  if (o = findobject('Subject')) return o.focus();
  if (o = findobject('Text')) return o.focus();
  if (o = findobject('editbuffer')) return o.focus();
  if (o = findobject('AFReturn')) return o.focus();
 }
 catch(err) {
 }
 return true;
}

/* OnLoadHandler - on load handler */
function OnLoadHandler() {
 try {
  // copy ALT attributes of IMG elements to TITLE attributes
  var el = document.getElementsByTagName("img");
  for (var i = 0;  i < el.length;  i++) {
   el[i].title = el[i].alt;
  }
  // copy onclick handler of INPUT elements to onkeypress
  var el = document.getElementsByTagName("input");
  for (var i = 0;  i < el.length;  i++) {
   if (el[i].onclick && ! el[i].onkeypress) {
    el[i].onkeypress = el[i].onclick;
   }
  }
  // copy onclick handler of A elements to onkeypress
  var el = document.getElementsByTagName("a");
  for (var i = 0;  i < el.length;  i++) {
   if (el[i].onclick && ! el[i].onkeypress) {
    el[i].onkeypress = el[i].onclick;
   }
  }
 }
 catch(err) {
 }
 return true;
}

/* HiliteAsLink - highlight an element as link */
function HiliteAsLink(element) {
 element.style.backgroundColor = '#FFFFDD'
 element.style.cursor = 'hand';
}

/* UnhiliteAsLink - highlight an element as link */
function UnhiliteAsLink(element) {
 element.style.backgroundColor = '#FFFFFF'
 element.style.cursor = 'auto';
}

/* InputFocus / InputBlur - focus/blur of input area (text/textarea) */
function InputFocus(element) {
  element.style.backgroundColor = manaba.color.inputfocus;
  return true;
}

function InputBlur(element) {
  element.style.backgroundColor =manaba.color.inputblur;
  return true;
}

/* CourseFocus / CourseBlur - course card focus/blur */
function CourseFocus(e) {
 var bgc, bc;

 if (e.className.match(/coursecard/)) {
  bc = '#534B8F';  bgc = '#e8f0ff';
 }
 if (e.className.match(/communitycard/)) {
  bc = '#534B8F';  bgc = '#e8f0ff';
 }
 if (e.className.match(/studentstatus-c/)) {
  bc = '#b5b5b5';  bgc = '#f8f8f8'
 }
 if (e.className.match(/studentstatus-b/)) {
  bc = '#b5b5b5';  bgc = '#f8f8f8'
 }
 if (e.className.match(/studentstatus-a/)) {
  bc = '#b5b5b5';  bgc = '#f8f8f8'
 }
 e.style.backgroundColor = bgc;
 e.style.borderTop = 'solid ' + bc + ' 1px';
 e.style.borderRight = 'solid ' + bc + ' 1px';
 e.style.borderBottom = 'solid ' + bc + ' 1px';
}

function CourseBlur(e) {
 var bc;

 if (e.className.match(/coursecard/)) bc = '#534B8F';
 if (e.className.match(/communitycard/)) bc = '#534B8F';
 if (e.className.match(/studentstatus-a/)) bc = '#b5b5b5';
 e.style.backgroundColor = '#ffffff';
 e.style.borderTop = 'dotted ' + bc + ' 1px';
 e.style.borderRight = 'dotted ' + bc + ' 1px';
 e.style.borderBottom = 'dotted ' + bc + ' 1px';
}

/* MenuFocus / MenuBlur - menu focus/blur */
function MenuFocus(element) {
  element.style.backgroundColor = '#FFFFFF';
  element.style.borderTop = 'solid #CCCCCC 1px';
  element.style.borderLeft = 'solid #CCCCCC 1px';
  element.style.borderRight = 'solid #F8F8F8 1px';
  element.style.borderBottom = 'solid #FFFFFF 1px';
  return true;
}

function MenuBlur(element) {
  element.style.backgroundColor = '#F8F8F8';
  element.style.borderTop = 'solid #FFFFFF 1px';
  element.style.borderLeft = 'solid #FFFFFF 1px';
  element.style.borderRight = 'solid #FFFFFF 1px';
  element.style.borderBottom = 'solid #CCCCCC 1px';
  return true;
}

/* MenuBarFocus / MenuBarBlur - menubar focus/blur */
function MenuBarFocus(element) {
  element.style.backgroundColor = '#FFFFFF';
  return true;
}

function MenuBarBlur(element) {
  element.style.backgroundColor = '#EEEEEE';
  return true;
}

/* PsLinkFocus / PsLinkBlur - Pseudo Links (non anchor) */
function PsLinkFocus(element) {
  element.style.cursor = 'hand';
  element.style.textDecoration = 'underline';
  return true;
}

function PsLinkBlur(element) {
  element.style.cursor = 'auto';
  element.style.textDecoration = 'none';
  return true;
}

// ImageFocus / ImageBlur - image rollover functions
function ImageFocus(o) {
 var img = o.src;
 if (! img.match(/-focus\.gif/)) {
  var t = img.replace(/\.gif/, '-focus.gif');
  o.src = t;
 }
}

function ImageBlur(o) {
 var img = o.src;
 var t = img.replace(/-focus\.gif/, '.gif');
 o.src = t;
}

// BGFocus / BGBlur - background image rollover functions
function BGFocus(o,pixel) {
 o.style.backgroundPosition = 'bottom left';
}

function BGBlur(o) {
 o.style.backgroundPosition = 'top left';
}

function BGSelect(o) {
 o.style.backgroundPosition = 'top right';
}

function BGDisselect(o) {
 o.style.backgroundPosition = 'bottom right';
}

// TextKeyPress - key pressed
function TextKeyPress(buttonToClick,e) {
 var keycode;

 if (window.event) {
  keycode = window.event.keyCode;
 } else if (e) {
  keycode = e.which;
 } else {
  return true;
 }

 if (keycode == 13) {
  if (o = document.getElementById(buttonToClick)) {
   o.click();
   return false;
  }
 } else if (keycode == 33) {
  /* ESC is ignored */
  return false;
 }
 return true;
}

function EnterSubmit(form, e) {
 var keycode;

 if (window.event) {
  keycode = window.event.keyCode;
 } else if (e) {
  keycode = e.which;
 } else {
  return true;
 }

 if (keycode == 13) {
  form.submit();
  return false;
 } else {
  return true;
 }
}

function InnerHTMLEdit(e, ev) {
 var keycode;

 if (window.event) {
  keycode = window.event.keyCode;
 } else if (ev) {
  keycode = ev.which;
 } else {
  return true;
 }

 if (keycode >= 32) {
  e.innerHTML = e.innerHTML + "X";
 }
 return true;
}

var savedtext = new Array();

function FieldRecycle(element) {
 var o;

 o = document.getElementById(element); 
 if (o) {
  if (o.value == '') {
    if (savedtext[element]) {
     o.value = savedtext[element];
    }
  } else {
    savedtext[element] = o.value;
    o.value = '';
    o.focus();
  }
 }
}

var FormData = new Array;
var FormDataStatus = 0;

function FormDataRecycle(element) {
 var o = document.getElementById(element);
 var e = o.elements;

 if (FormDataStatus) {
  for (i = 0;  i < e.length;  i++) {
   if (FormData[e[i].name]) {
    e[i].value = FormData[e[i].name];
   }
  }
  FormDataStatus = 0;
 } else {
  for (i = 0;  i < e.length;  i++) {
   FormData[e[i].name] = e[i].value;
  }
  o.reset();
  FormDataStatus = 1;
 }
}

/* NextWhenFull - skip to next field when maxlength is reached */
function NextWhenFull(e, content)
{
 /* Usage:
 **  <input tabindex=1 maxlength=3 onkeyup="NextWhenFull(this, this.value)">
 */
 if (content.length == e.maxLength) {
  next = e.tabIndex;
  if (next < document.forms[0].elements.length) {
   document.forms[0].elements[next].focus()
  }
 }
}

/* CopyValue - copy a value into an object */
function CopyValue(value, id)
{
 var o;

 o = document.getElementById(id); 
 if (o) {
  o.value = value;
 }
}

/* CopyValueById - copy textarea */
function CopyValueById(srcid, dstid, append)
{
 var src = document.getElementById(srcid);
 if (! src) return false;

 var dst = document.getElementById(dstid);
 if (! dst) return false;

 if (append) {
  dst.value = dst.value + (dst.value ? "\n"  : "") + src.value;
 } else {
  dst.value = src.value;
 }
}

var gContextMenu = new Array;

/* ShowContextMenu(o,ev) - show menu */
function ShowContextMenu(o,ev) {
 var x, y, id;

 if (ev) {
  x = getEventPageX(ev,0);
  y = getEventPageY(ev,0);
 } else {
  x = o.style.left;
  y = o.style.top;
 }
 var id = showcontextmenu(o, 0, x, y);
 gContextMenu[id] = true;
 return false;
}

function showcontextmenu(o, recursive, x, y) {
 var id;

 while (o) {
  if (o.className == 'contextmenu') {
   if (gContextMenu[o.id]) return o.id;  /* already shown #1 */
   if (o.style.display == 'block') return o.id;  /* already shown #2 */
   o.style.position = 'absolute';
   o.style.top = y - 20;
   o.style.left = x - 20;
   o.style.display = 'block';
   return o.id;
  }
  if (id = showcontextmenu(o.firstChild, 1, x, y)) return id;
  if (recursive) o = o.nextSibling; else break;
 }
 return false;
}

/* HideContextMenu(element) - hide this menu */
function HideContextMenu(elem) {
 elem.style.display = 'none';
 SetTimeoutEvent(ClearContextMenu, elem, 100, 1);
}

/* ClearContextMenu(element) - hide this menu */
function ClearContextMenu(elem) {
 gContextMenu[elem.id] = false;
}

function CreateXMLHttpRequest () {
 try {
  if (window.XMLHttpRequest) {
   return new XMLHttpRequest ();
  }
 } catch (e) {}
 try {
  if (window.ActiveXObject) {
   return new ActiveXObject ('Microsoft.XMLHTTP');
  }
 } catch (e) {}
 try {
  if (window.ActiveXObject) {
   return new ActiveXObject('Msxml2.XMLHTTP');
  }
 } catch (e) {}
 return null;
}

/* QueryPanel */
manaba.panelFirst = true;
manaba.panel_getStringAction = function (o, action) {
 var oName = "";
 if (o) {
  oName = o.nodeName.toLowerCase ();
 }
 
 if (oName == "a") {
  var ok_url = action;
  if (!ok_url.match (/^https?:/)) {
   var base = document.location.href.replace (/\?.+$/, "").replace (/\/[^\/]*$/, "/");
   ok_url = base + ok_url;
  }
  return function () {
   if (ok_url) {
    document.location.href = ok_url;
   }
   try {
    var b = document.getElementById ("panel_blocker");
    var m = document.getElementById ("panel_modal");
    if (b && m) {
     b.parentNode.removeChild (b);
     m.parentNode.removeChild (m);
    }
   } catch (e) {}
  };
 }
 else if (oName == "input" && action == "_submit") {
  return function () {
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".x";
   node.value = "5";
   o.form.appendChild (node);
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".y";
   node.value = "5";
   o.form.appendChild (node);
   o.form.submit ();
   try {
    var b = document.getElementById ("panel_blocker");
    var m = document.getElementById ("panel_modal");
    if (b && m) {
     b.parentNode.removeChild (b);
     m.parentNode.removeChild (m);
    }
   } catch (e) {}
  };
 }
 else if (action == "_cancel") {
  return function () {
   try {
    var b = document.getElementById ("panel_blocker");
    var m = document.getElementById ("panel_modal");
    if (b && m) {
     b.parentNode.removeChild (b);
     m.parentNode.removeChild (m);
    }
   } catch (e) {}
  };
 }
 else if (action.match (/^_anchor:(.+)$/)) {
  var ok_url = RegExp.$1;
  if (!ok_url.match (/^https?:/)) {
   var base = document.location.href.replace (/\?.+$/, "").replace (/\/[^\/]*$/, "/");
   ok_url = base + ok_url;
  }
  return function () {
   document.location.href = ok_url;
   try {
    var b = document.getElementById ("panel_blocker");
    var m = document.getElementById ("panel_modal");
    if (b && m) {
     b.parentNode.removeChild (b);
     m.parentNode.removeChild (m);
    }
   } catch (e) {}
  };
 }
 else if (oName == "input" && action.match (/^\+(.+)$/)) {
  var name = o.name + RegExp.$1;
  return function () {
   o.name = name;
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".x";
   node.value = "5";
   o.form.appendChild (node);
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".y";
   node.value = "5";
   o.form.appendChild (node);
   o.form.submit ();
   try {
    var b = document.getElementById ("panel_blocker");
    var m = document.getElementById ("panel_modal");
    if (b && m) {
     b.parentNode.removeChild (b);
     m.parentNode.removeChild (m);
    }
   } catch (e) {}
  };
 }
 else if (oName == "input") {
  var name = action;
  return function () {
   o.name = name;
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".x";
   node.value = "5";
   o.form.appendChild (node);
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".y";
   node.value = "5";
   o.form.appendChild (node);
   o.form.submit ();
   try {
    var b = document.getElementById ("panel_blocker");
    var m = document.getElementById ("panel_modal");
    if (b && m) {
     b.parentNode.removeChild (b);
     m.parentNode.removeChild (m);
    }
   } catch (e) {}
  };
 }
 
 return function () {};
};

manaba.panelCancelFunc = function () {};
manaba.panel_close = function (o) {
 var b = document.getElementById ("panel_blocker");
 var m = document.getElementById ("panel_modal");
 if (b && m) {
  b.parentNode.removeChild (b);
  m.parentNode.removeChild (m);
 }
};
manaba.panel_submit = function (o) {
 var node = document.createElement ("input");
 node.type = "hidden";
 node.name = o.name + ".x";
 node.value = "5";
 o.form.appendChild (node);
 var node = document.createElement ("input");
 node.type = "hidden";
 node.name = o.name + ".y";
 node.value = "5";
 o.form.appendChild (node);
 o.form.submit ();
};
manaba.panel = function (o, type, message) {
 manaba.useHTMLPanel = true;
 
 if (!manaba.useHTMLPanel) {
  if (type == "alert") {
   return alert (message);
  }
  else if (type == "confirm") {
   return confirm (message);
  }
  else {
   return true;
  }
 }
 
 if (document.getElementById ("panel_blocker")) {
  return false;
 }
 var blocker = document.createElement ("span");
 blocker.id = "panel_blocker";
 document.body.appendChild (blocker);
 
 if (manaba.panelFirst) {
  manaba.panelFirst = false;
  var target = window;
  if (gBrowser.isIE) {
   target = document.body;
  }
  manaba.addevent
   (target, "keydown",
    function () {
     var event;
     if (gBrowser.isIE) {
      event = window.event;
     }
     else {
      event = arguments [0];
     }
     if (event.keyCode == 27) {
      var b = document.getElementById ("panel_blocker");
      if (b) {
       manaba.panelCancelFunc ();
      }
     }
    });
 }
 
 var base = document.location.href.replace (/\?.+$/, "").replace (/\/[^\/]*$/, "/");
 var panel_url = base + "panel_" + type;
 
 var modal = document.createElement ("div");
 modal.id = "panel_modal";
 modal.style.position = "absolute";
 modal.style.left = "0px";
 modal.style.top = "0px";
 modal.style.width = "100%";
 var height = 0;
 height = document.body.clientHeight;
 if (height < document.documentElement.clientHeight) {
  height = document.documentElement.clientHeight;
 }
 modal.style.height = height + "px";
 modal.style.zIndex = "100";
 
 var back = document.createElement ("div");
 back.id = "panel_back";
 back.style.position = "absolute";
 back.style.left = "0px";
 back.style.top = "0px";
 back.style.width = "100%";
 back.style.height = height + "px";
 modal.appendChild (back);
 
 var panel = document.createElement ("div");
 panel.id = "panel_frame";
 panel.style.visibility = "hidden";
 panel.style.position = "absolute";
 panel.style.left = "0px";
 var top = 0;
 if (document.body.scrollTop) {
  top = document.body.scrollTop;
 }
 else if (document.documentElement.scrollTop) {
  top = document.documentElement.scrollTop;
 }
 panel.style.top = top + "px";
 if ("cssFloat" in panel.style) {
  panel.style.cssFloat = "left";
 }
 else {
  panel.style.styleFloat = "left";
 }
 
 modal.appendChild (panel);
 
 document.body.appendChild (modal);
 
 var actions = {};
 var labels = {};
 if (type == "alert" || type == "confirm") {
  if (arguments.length >= 4) {
   if ((typeof arguments [3]) == "function") {
    var ok_func = arguments [3];
    actions ["ok"] = function () {
     ok_func ();
     try {
      blocker.parentNode.removeChild (blocker);
      modal.parentNode.removeChild (modal);
     } catch (e) {}
    };
   }
   else if ((typeof arguments [3]) == "string") {
    actions ["ok"] = manaba.panel_getStringAction (o, arguments [3]);
   }
  }
  else if (o) {
   if (o.nodeName.toLowerCase () == "a") {
    actions ["ok"] = function () {
     document.location.href = o.href;
     try {
      blocker.parentNode.removeChild (blocker);
      modal.parentNode.removeChild (modal);
     } catch (e) {}
    };
   }
   else if (o.nodeName.toLowerCase () == "input") {
    actions ["ok"] = function () {
     var node = document.createElement ("input");
     node.type = "hidden";
     node.name = o.name + ".x";
     node.value = "5";
     o.form.appendChild (node);
     var node = document.createElement ("input");
     node.type = "hidden";
     node.name = o.name + ".y";
     node.value = "5";
     o.form.appendChild (node);
     o.form.submit ();
     try {
      blocker.parentNode.removeChild (blocker);
      modal.parentNode.removeChild (modal);
     } catch (e) {}
    };
   }
   else {
    return false;
   }
  }
  else {
   return false;
  }
 }
 if (type == "confirm") {
  if (arguments.length >= 5) {
   if ((typeof arguments [4]) == "function") {
    var cancel_func = arguments [4];
    actions ["cancel"] = function () {
     cancel_func ();
     try {
      blocker.parentNode.removeChild (blocker);
      modal.parentNode.removeChild (modal);
     } catch (e) {}
    };
   }
   else if ((typeof arguments [4]) == "string") {
    actions ["cancel"] = manaba.panel_getStringAction (o, arguments [4]);
   }
  }
  else if (o) {
   if (o.nodeName.toLowerCase () == "a") {
    actions ["cancel"] = function () {
     try {
      blocker.parentNode.removeChild (blocker);
      modal.parentNode.removeChild (modal);
     } catch (e) {}
    };
   }
   else if (o.nodeName.toLowerCase () == "input") {
    actions ["cancel"] = function () {
     try {
      blocker.parentNode.removeChild (blocker);
      modal.parentNode.removeChild (modal);
     } catch (e) {}
    };
   }
   else {
    return false;
   }
  }
  else {
  return false;
  }
 }
 if (type == "reminder") {
  actions ["rem"] = function () {
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".x";
   node.value = "5";
   o.form.appendChild (node);
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".y";
   node.value = "5";
   o.form.appendChild (node);
   o.form.submit ();
   try {
    blocker.parentNode.removeChild (blocker);
    modal.parentNode.removeChild (modal);
   } catch (e) {}
  };
  actions ["norem"] = function () {
   try {
   o.name = o.name.replace (/_noreminder$/, "") + "_noreminder";
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".x";
   node.value = "5";
   o.form.appendChild (node);
   var node = document.createElement ("input");
   node.type = "hidden";
   node.name = o.name + ".y";
   node.value = "5";
   o.form.appendChild (node);
   o.form.submit ();
    blocker.parentNode.removeChild (blocker);
    modal.parentNode.removeChild (modal);
   } catch (e) {}
  };
  actions ["cancel"] = function () {
   try {
    blocker.parentNode.removeChild (blocker);
    modal.parentNode.removeChild (modal);
   } catch (e) {}
  };
 }
 
 var focusName = "";
 var queryString = "";
 if (type != "confirm" && type != "alert" && type != "reminder") {
  var j = 1;
  for (;;) {
   if (arguments.length - 5 >= j * 2) {
    labels ["button" + j]= arguments [5 + (j - 1) * 2];
    if ((typeof arguments [5 + (j - 1) * 2 + 1]) == "function") {
     actions ["button" + j] = arguments [5 + (j - 1) * 2 + 1];
    }
    else if ((typeof arguments [5 + (j - 1) * 2 + 1]) == "string") {
     actions ["button" + j] = manaba.panel_getStringAction (o, arguments [5 + (j - 1) * 2 + 1]);
    }
    if (queryString) {
     queryString += "&";
    }
    queryString += "button=" + j;
    j ++;
   }
   else {
    break;
   }
  }
  queryString = "?" + queryString;
 }
 
 if (type == "alert") {
  focusName = "ok";
  manaba.panelCancelFunc = actions ["ok"];
 }
 else if (type == "confirm") {
  focusName = "ok";
  manaba.panelCancelFunc = actions ["cancel"];
 }
 else if (type == "reminder") {
  focusName = "rem";
  manaba.panelCancelFunc = actions ["cancel"];
 }
 else {
  focusName = "button" + arguments [3];
  manaba.panelCancelFunc = actions ["button" + arguments [4]];
 }
 
 var request =  CreateXMLHttpRequest ();
 request.onreadystatechange = function () {
  if (request.readyState == 4
      && request.status == 200) {
   panel.innerHTML = request.responseText;
   var messageblock = document.getElementById ("panel_message");
   if (!messageblock) {
    return;
   }
   messageblock.innerHTML = manaba.escapeEntity (message);
   
   var focusNode = null;
   var node;
   for (var name in actions) {
    node = document.getElementById ("panel_" + name);
    if (!node) {
     return;
    }
    manaba.addevent (node,"click", actions [name]);
    if (name == focusName) {
     focusNode = node;
    }
    if (name in labels
         && labels [name] != null) {
     node.value = labels [name];
    }
   }
   
   var left = 0;
   if (document.body.scrollLeft) {
    left = document.body.scrollLeft;
   }
   else if (document.documentElement.scrollLeft) {
    left = document.documentElement.scrollLeft;
   }
   var width = document.documentElement.clientWidth;
   var height= document.documentElement.clientHeight;
   var x, y;
   x = left + (width - panel.offsetWidth) / 2;
   y = top + (height - panel.offsetHeight) / 2;
   panel.style.left = x + "px";
   panel.style.top = y + "px";
   panel.style.visibility = "visible";
   if (focusNode) {
    focusNode.focus ();
   }
  }
 };
 
 request.open ('GET', panel_url + queryString, true); 
 request.send (null);
 
 return false;
};

manaba.imageViewerStarted = false;
manaba.imageViewerDown = false;
manaba.imageViewerDownOutside = false;
manaba.imageViewerDrag = false;
manaba.imageViewerX = 0;
manaba.imageViewerY = 0;

/* OpenImageViewer() - open image viewer */
function OpenImageViewer(url,o,ev, comment) {
 var viewer = document.createElement ("div");
 viewer.id = "imageviewer_modal";
 viewer.style.position = "absolute";
 viewer.style.left = "0px";
 viewer.style.top = "0px";
 viewer.style.width = "100%";
 var height = 0;
 height = document.body.clientHeight;
 if (height < document.documentElement.clientHeight) {
  height = document.documentElement.clientHeight;
 }
 viewer.style.height = height + "px";
 viewer.style.zIndex = "100";
 manaba.addevent
  (viewer, "click",
   function () {
    if (!manaba.imageViewerStarted) {
     viewer.parentNode.removeChild (viewer);
    }
   });
 
 var back = document.createElement ("div");
 back.id = "imageviewer_back";
 back.style.position = "absolute";
 back.style.left = "0px";
 back.style.top = "0px";
 back.style.width = "100%";
 back.style.height = height + "px";
 viewer.appendChild (back);

 var imageDiv = document.createElement ("div");
 imageDiv.style.position = "absolute";
 imageDiv.style.left = "0px";
 var top = 0;
 if (document.body.scrollTop) {
  top = document.body.scrollTop;
 }
 else if (document.documentElement.scrollTop) {
  top = document.documentElement.scrollTop;
 }
 imageDiv.style.top = top+ 20 + "px";
 imageDiv.style.width = "100%";
 imageDiv.style.textAlign = "center";
 var close = document.createElement ("div");
 close.style.color = "white";
 close.style.fontWeight = "bold";
 close.style.marginBottom = "10px";
 close.innerHTML = "クリックで閉じる";
 imageDiv.appendChild (close);
 var loading = document.createElement ("div");
 loading.style.color = "white";
 loading.style.fontWeight = "bold";
 loading.style.marginTop = "10px";
 loading.style.marginBottom = "10px";
 loading.innerHTML = "loading...";
 imageDiv.appendChild (loading);
 var link = document.createElement ("div");
 link.style.marginTop = "10px";
 link.style.marginBottom = "10px";
 var anchor = document.createElement ("a");
 anchor.href = url;
 anchor.style.color = "#00ffff";
 anchor.innerHTML = "画像を開く";
 link.appendChild (anchor);
 imageDiv.appendChild (link);
 var image = document.createElement ("img");
 var enterDraggable = function () {
  manaba.imageViewerStarted = true;
  var x = 0; y = 0;
  var node = image;
  x += node.offsetLeft;
  y += node.offsetTop;
  image.style.cursor = "move";
  image.style.position = "absolute";
  image.style.left = x + "px";
  image.style.top = y + "px";
  manaba.addevent
   (viewer, "mousedown",
    function () {
     var event;
     var target;
     if (gBrowser.isIE) {
      event = window.event;
      target = event.srcElement;
     }
     else {
      event = arguments [0];
      target = event.target;
     }
     if (!gBrowser.isIE && event.button != 0) {
      return;
     }
     if (gBrowser.isIE && event.button != 1) {
      return;
     }
     var a = manaba.findParentNode (target, "a");
     if (a) {
      return;
     }
     var img = manaba.findParentNode (target, "img");
     if (!img) {
      manaba.imageViewerDownOutside = true;
      return;
     }
     manaba.imageViewerDown = true;
     manaba.imageViewerX = event.screenX;
     manaba.imageViewerY = event.screenY;
     
     try { event.preventBubble (); } catch (e) {}
     try { event.preventDefault (); } catch (e) {}
     try { event.stopPropagation (); } catch (e) {}
     return false;
    });
  manaba.addevent
   (viewer, "mousemove",
    function () {
     if (!manaba.imageViewerDown) {
      return;
     }
     var event;
     if (gBrowser.isIE) {
      event = window.event;
     }
     else {
      event = arguments [0];
     }
     manaba.imageViewerDrag = true;
     var x = parseInt (image.style.left);
     var y = parseInt (image.style.top);
     x += event.screenX - manaba.imageViewerX;
     y += event.screenY - manaba.imageViewerY;
     image.style.left = x + "px";
     image.style.top = y + "px";
     manaba.imageViewerX = event.screenX;
     manaba.imageViewerY = event.screenY;
     
     try { event.preventBubble (); } catch (e) {}
     try { event.preventDefault (); } catch (e) {}
     try { event.stopPropagation (); } catch (e) {}
     return false;
    });
  manaba.addevent
   (viewer, "mouseup",
    function () {
     var event;
     var target;
     if (gBrowser.isIE) {
      event = window.event;
      target = event.srcElement;
     }
     else {
      event = arguments [0];
      target = event.target;
     }
     if (!gBrowser.isIE && event.button != 0) {
      return;
     }
     if (gBrowser.isIE && event.button != 1) {
      return;
     }
     var a = manaba.findParentNode (target, "a");
     if (a) {
      return;
     }
     if (manaba.imageViewerDownOutside) {
      manaba.imageViewerDownOutside = false;
      viewer.parentNode.removeChild (viewer);
      manaba.imageViewerStarted = false;
      return;
     }
     if (!manaba.imageViewerDown) {
      return;
     }
     manaba.imageViewerDown = false;
     if (!manaba.imageViewerDrag) {
      viewer.parentNode.removeChild (viewer);
      manaba.imageViewerStarted = false;
     }
     manaba.imageViewerDrag = false;
     
     try { event.preventBubble (); } catch (e) {}
     try { event.preventDefault (); } catch (e) {}
     try { event.stopPropagation (); } catch (e) {}
     return false;
    });
 };
 manaba.addevent
  (image,
   "load",
   function () {
    try {
     loading.parentNode.removeChild (loading);
     setTimeout (function () {
       enterDraggable ();
      }, 100);
    } catch (e) {}
   });
 image.style.border = "8px solid white";
 image.style.margin = "0px";
 image.style.padding = "0px";
 image.src = url;
 //setTimeout (function () {image.src = url;}, 3000);
 imageDiv.appendChild (image);
 viewer.appendChild (imageDiv);
 
 document.body.appendChild (viewer);
 if (image.complete) {
  loading.parentNode.removeChild (loading);
  setTimeout (function () {
    enterDraggable ();
   }, 100);
 }

 return false;
}

/* OpenUsermemo() - open a user memo window */
function OpenUsermemo(url,o,ev,winname) {
 var x;
 var y;

 if (gBrowser.isIE) {
  window.event.cancelBubble = true;
  if (event.stopPropagation) event.stopPropagation();
 }
 if (! winname) winname = "_blank";
 if (! url) url = findchildanchor(o, 0);
 if (! url) return false;

 if (ev) {
  x = getEventPageX(ev,1);
  y = getEventPageY(ev,1);
 } else {
  x = o.style.left;
  y = o.style.top;
 }

 window.open(url,winname,"toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,titlebar=no,resizable=no,copyhistory=no,width=512,height=190,top=" + y + ",left=" + x);
 return false;
}

/* OpenCalendar() - open a calendar window */
function OpenCalendar(url,ev,winname) {
 var x;
 var y;

 if (! winname) winname = "_blank";
 if (ev) {
  x = window.screenLeft + ev.clientX;
  y = window.screenTop + ev.clientY;
 } else {
  x = window.screenLeft + 100;
  y = window.screenTop + 100;
 }

 window.open(url,winname,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,titlebar=no,resizable=no,copyhistory=no,width=150,height=120,top=" + y + ",left=" + x);
 return false;
}

/* CopyValueToOpener - copy a value into the specified element */
function CopyValueToOpener(v,id,winclose) {
 var tt;

 var te = window.opener.document.getElementById(id);  /* target element */
 if (! te) return false;  /* not found, do nothing */

 tt = te.type;
 if (tt == "DIV" || tt == "P" || tt == "A" || tt == "TEXTAREA") {
  /* replace innerHTML if <div <p <a <textarea */
  te.innerHTML = v;
 } else {
  /* otherwise replace value */
  te.value = v;
 }

 if (winclose) window.close();
 return false;
}

// selectoptionvalue - find option value
function selectoptionvalue(o, dv) {
 if (! o) return dv;
 for (var e = o.firstChild;  e;  e = nextSiblingNT(e)) {
  if (e.tagName != 'OPTION') continue;
  if (o.selectedIndex == e.index) return e.value;
 }
 return dv;
}

// TimeValue - construct time value from two id's
function TimeValue(idhour, idmin) {
 return selectoptionvalue(document.getElementById(idhour), '00') +
   ":" + selectoptionvalue(document.getElementById(idmin), '00');
}

// DateValue - construct date value
function DateValue(iddate) {
 var e = document.getElementById(iddate);
 if (! e) return '2001-01-01';
 if (e.tagName == 'DIV') {
  return e.innerHTML;
 } else if (e.tagName == 'INPUT') {
  return e.value;
 }
}

/* CopyValueToOutframe */
function CopyValueToOutframe(v,id) {
 var tt;

 var te = window.parent.document.getElementById(id);  /* target element */
 if (! te) return false;  /* not found, do nothing */

 tt = te.type;
 if (tt == "DIV" || tt == "P" || tt == "A" || tt == "TEXTAREA") {
  /* replace innerHTML if <div <p <a <textarea */
  te.innerHTML = v;
 } else {
  /* otherwise replace value */
  te.value = v;
 }

 var e = window.parent.document.getElementById(id + '_iframe');
 if (e) e.style.display = 'none';
 return false;
}

var selecteddate = null;

/* SelectDate */
function SelectDate(o,iddate,value) {
 var e = document.getElementById(iddate);
 if (selecteddate) {
  selecteddate.style.borderColor = '#fff';
 } else {
  var x = document.getElementById('initselected');
  if (x) x.style.borderColor = '#fff';
 }
 if (e.tagName == 'DIV') {
  e.innerHTML = value;
 } else if (e.tagName == 'INPUT') {
  e.value = value;
 }
 o.style.borderColor = '#800';
 selecteddate = o;
 return false;
}

var authFormEnabled = 0;

/* AuthFormEnable- enable authentication form */
function AuthFormEnable() {
 var e1, e2, e3;

 e1 = document.getElementById('huserid');
 e2 = document.getElementById('hpassword');
 e3 = document.getElementById('hlogin');
 e1.disabled = 0;
 e2.disabled = 0;
 e3.disabled = 0;
 if (! authFormEnabled) {
  e1.value = e2.value = '';
  e1.focus();
 }
 authFormEnabled = 1;
}

/* LinkWindow() - open a link window */
function LinkWindow(url,ev) {
 var x;
 var y;

 if (ev) {
  x = getEventPageX(ev,1);
  y = getEventPageY(ev,1);
 } else {
  x = window.screenLeft + 100;
  y = window.screenTop + 100;
 }

 window.open("link?url=" + url, "_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,titlebar=no,resizable=no,copyhistory=no,width=400,height=100,top=" + y + ",left=" + x);
 return false;
}

/* LinkWindowChildAnchor() - open a link window using an anchor in descending elements*/
function LinkWindowChildAnchor(o, ev) {
 var oo = o;
 var x, y;
 var url;

 if (o.tagName == 'A') {
  if (gBrowser.isIE) {
   url = o.getAttribute ("href", 2);
  }
  else {
   url = o.getAttribute ("href");
  }
 } else {
  o = o.firstChild;
  while (o) {
   if (o.tagName == 'A') {
    if (gBrowser.isIE) {
     url = o.getAttribute ("href", 2);
    }
    else {
     url = o.getAttribute ("href");
    }
    break;
   } else {
    if (OpenChildAnchor(o, ev)) return false;
   }
   o = o.nextSibling;
  }
 }
 if (! url) return false;

 url = escape(url);
 if (ev) {
  x = getEventPageX(ev,1);
  y = getEventPageY(ev,1);
 } else {
  x = oo.style.left;
  y = oo.style.top;
 }

 window.open("link?url=" + url, "_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,titlebar=no,resizable=no,copyhistory=no,width=400,height=100,top=" + y + ",left=" + x);
 return false;
}

/* LinkChildAnchor() - open a link using an anchor in descending elements*/
function LinkChildAnchor(o, ev) {
 var x, y;
 var url;

 if (o.tagName == 'A') {
  if (gBrowser.isIE) {
   url = o.getAttribute ("href", 2);
  }
  else {
   url = o.getAttribute ("href");
  }
 } else {
  o = o.firstChild;
  while (o) {
   if (o.tagName == 'A') {
    if (gBrowser.isIE) {
     url = o.getAttribute ("href", 2);
    }
    else {
     url = o.getAttribute ("href");
    }
    break;
   } else {
    if (OpenChildAnchor(o, ev)) return false;
   }
   o = o.nextSibling;
  }
 }
 if (! url) return false;

 window.open(url, "_self");
 return false;
}

/* PageTop() - jump to top of page */
function PageTop() {
 window.location.hash = "pagetop";
}

/* WindowClose() - window close */
function WindowClose() {
 window.close();
 return false;
}

/* OpenInParent() - open a URL in a opener window */
function OpenInParent(url) {
 window.opener.open(url, '_self');
 window.close();
 return false;
}

/* OpenInNew() - open a URL in a opener window */
function OpenInNew(url) {
 window.opener.open(url, '_blank');
 window.close();
 return false;
}

/* SetTitleColor() - set title colors */
function SetTitleColor(o,color) {
 o.style.color = color;
 o.style.borderBottomColor = color;
}

/* CopyTextToClipboard() - copy text to clipboard */
function CopyTextToClipboard(text) {
 window.clipboardData.setData('Text', text);
}

/* ImageURLToClipboard() - copy image URL to clipboard */
function ImageURLToClipboard(element) {
 window.clipboardData.setData('Text', element.src);
}

/*
  ラジオボタン(その他を input type=text または textarea で入力)

   <div id=RadioName1 onClick="RadioSelect(this)">
    <input type=button name=RadioName id=RadioName1Button onSelectStart="RadioWithoutText(this)">
   </div>
   <div id=RadioName1 onClick="RadioSelect(this)">
    <input type=button name=RadioName id=RadioName1Button onSelectStart="RadioWithText(this)">
   </div>
   <input type=text name=RadioNameText id=RadioNameText>
*/

/* RadioSelect(this) - select a radio button */
function RadioSelect(element) {
 var buttonid = element.id + 'Button';
 var e = getElementById(buttonid);
 if (e) e.select();
}

/* RadioWithoutText(this) - select a radio button */
function RadioWithoutText(element) {
 var textid = element.name + 'Text';
 var e = getElementById(textid);
 if (e) e.disabled = 1;
}

/* RadioWithText(this) - select a radio button */
function RadioWithText(element) {
 var textid = element.name + 'Text';
 var e = getElementById(textid);
 if (e) {
  e.disabled = 0;
  e.focus();
 }
}

/* EditStatus */
var EditStatus = 0;

/* EditInnerHTML(this) - edit inner HTML */
function EditInnerHTML(element) {
 var text = element.innerHTML;

 text = prompt("Enter text", text);
 text.replace(/&/g,'&amp;');
 text.replace(/</g,'&lt;');
 text.replace(/>/g,'&gt;');
 text.replace(/"/g,'&quot;');
 if (text) {
  element.innerHTML = text;
  EditStatus = 1;
 }
}

/* CheckEditStatus - check edit status */
function CheckEditStatus() {
 if (EditStatus) {
  var msg;

  if (Lang == 'en') {
   msg = "Reload/forward/backward is requested but text is being edited.  Proceed?";
  } else {
   /* default = 'ja' */
   msg = "リロードまたはページ移動が要求されましたが、テキストは編集中です。実行しますか？";
  }

  if (confirm(msg)) return;
 } else {
  return;
 }

 location = self.location;
}

/* CancelEditStatus() */
function CancelEditStatus() {
 EditStatus = 0;
}

/* TestFillMessage */
function TestFillMessage() {
 var s = document.getElementById('Subject');
 var t = document.getElementById('Text');

 s.value = "テストメッセージ";
 t.value = 
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n" +
"１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０１２３４５６７８９０\n";
}

/* EditInPlace - その場で編集 */
function EditInPlace(e) {
 var text = e.innerHTML;
 var width = e.style.width;
 if (width == 0) width = 300;

 var html = "<form><textarea style='width: " + width + "px'>" + text + "</textarea></form>"
 e.innerHTML = html;
}

/* InPlaceConfirm - その場で確認 */
function InPlaceConfirm(o, text) {
 /* <a href=... onClick="return InPlaceConfirm(this, 'Click to delete')"> */
 if (text == o.innerHTML) {
  return true;
 } else {
  o.style.color = 'red';
  o.style.fontWeight = 'bold';
  o.innerHTML = text;
  return false;
 }
}

/* dropdown calendar */
function DDCalendar(inputid,yy,mm,fulldate) {
 var inp = document.getElementById(inputid);
 var calid = inputid + '_iframe';
 if (! inp || inp.tagName != 'INPUT') throw 'not an input tag';

 var e = document.getElementById(calid);
 if (e) {
  e.style.display = 'inline';
 } else { 
  var url = 'calendar_' + yy + '_' + mm + '____' + inputid + (fulldate ? ('?date=' + encodeURIComponent(fulldate)) : '');
  var text = '<iframe class=calendar src="' + url + '" id="' + calid + '" width="185" height="240" style="position: absolute; margin-top: 22px; margin-left: 4px"></iframe>';
  inp.insertAdjacentHTML('beforeBegin', text)
  e = document.getElementById(inputid);
  e.onkeydown = function () {
   var k = window.event.keyCode;
   if (k == 27) {
    HideIframe(inputid);
    event.returnValue=false;
/*
   // このコードは凍結。本来できあがった文字列に対してregexpすべき
   } else if (k >= 48 && k < 58 || k == 186 || k == 189 || k <= 32) {
    ;
   } else {
    alert(Lang == 'ja' ? 'YYYY-MM-DD[ HH:MM:SS] の形式で入れてください。' : 'This field requires YYYY-MM-DD[ HH:MM:SS].');
    event.returnValue=false;
*/
   } 
  }
 }
}

/* hide an IFRAME document in this document */
function HideIframe(inputid) {
 var e = document.getElementById(inputid + '_iframe');
 e.style.display = 'none';
}

/* hide an IFRAME document in parent document */
function HideParentIframe(inputid) {
 var e = window.parent.document.getElementById(inputid + '_iframe');
 e.style.display = 'none';
}

/* focus parent's input area */
function FocusParentInput(inputid) {
 var e = window.parent.document.getElementById(inputid);
 e.focus();
}

/* タブ */
function TabClick(e) {
 var s = e.id.split("_");
 var tabsetid = s[0];
 var tabclicked = s[1];
 var tabbody = tabsetid + "_body_" + tabclicked;

 var el = document.getElementsByTagName("div");
 for (var i = 0;  i < el.length;  i++) {
  var d = el.item(i);
  if (d.id.match(tabsetid + "_body_")) {
   if (d.id == tabbody) {
    d.style.display = "block";
   } else {
    d.style.display = "none";
   }
  }
 }
 return true;
}

/* TabHilite - タブをハイライトする */
function TabHilite(element) {
 // element.style.fontWeight = 'bold';
 element.style.cursor = 'hand';
}

/* TabUnhilite - タブのハイライトを消す */
function TabUnhilite(element) {
 // element.style.fontWeight = 'normal';
 element.style.cursor = 'auto';
}

/* sample HTML for tab functions
<div id=tab1_a onClick="TabClick(this)" onMouseOver="TabHilite(this)" onMouseOut="TabUnhilite(this)">TAB A</div>
<div id=tab1_b onClick="TabClick(this)" onMouseOver="TabHilite(this)" onMouseOut="TabUnhilite(this)">TAB B</div>
<div id=tab1_body_a style="display: none">BODY A</div>
<div id=tab1_body_b style="display: none">BODY B</div>
*/


// DelayedWindowClose - close the window with a bit of wait
// - used in memo to give user better feeling of operation
function DelayedWindowClose(msec) {
  SetTimeoutEvent(WindowClose, null, msec, 1);
}


// ShowHelpIcon - show on-demand help icon

// - check existence of class=ondemandhelp and show icon if one exists.

function ShowHelpIcon(doshow) {
 var e = document.getElementsByTagName('div');
 var len = e.length;
 var found = 0;
 var foundicon = 0;
 for (var i = 0;  i < len;  i++) {
  if (e.item(i).className == 'myhelpicon') {
    foundicon = 1;
	break;
  }
  if (e.item(i).className == 'ondemandhelp') {
   found = 1;
   break;
  }
 }
 if (foundicon) {
  if (found) {
   e = document.getElementById('myhelpicon');
   e.style.visibility = 'visible';
   if (doshow) {
    FlipOnDemandHelp();
   }
  }
 }
}



// ReloadPage - reload page
function ReloadPage() {
 location.reload();
}


// FlashWarn/FlashWarnEnd - flash letters to draw attention of the operator
var gFo;

function FlashWarnEnd() {
 var o = document.getElementById(gFo.id);
 if (! o) return;

 o.style.color = gFo.color;
 o.style.backgroundColor = gFo.backgroundColor;
}

function FlashWarn(id) {
 var o = document.getElementById(id);
 if (! o) return;

 gFo = new Object();
 gFo.id = id;
 gFo.backgroundColor = o.style.backroundColor || 'transparent';
 gFo.color = o.style.color || 'black';

 o.style.backgroundColor = 'red';

 SetTimeoutEvent(FlashWarnEnd, null, 100, 1);
}


// RadioClick - highlight label when a radio button is checked
function RadioClick(o) {
 var id = o.id;
 var name = o.name;
 if (! id || ! name) return;

 var els = document.getElementsByTagName('label');
 var elsLen = els.length;
 for (var i = 0;  i < elsLen;  i++) {
  var f = els[i].htmlFor;
  if (! f) continue;
  var ro = document.getElementById(f);
  if (! ro) continue;
  if (f == id) {
    els[i].className = 'radio-checked';
  } else if (ro.name == name) {
    els[i].className = 'radio-nocheck';
  }
 }
}


// WindowResizeToStandard - resize screen forcibly
// - used in login to enlarge smaller memo window.
function WindowResizeToStandard() {
 return 1;

 var minw = 760;
 var minh = 600;
 var w = window.innerWidth;
 if (! w) w = document.documentElement.clientWidth;
 var h = window.innerHeight;
 if (! h) h = document.documentElement.clientHeight;
 if (w >= minw && h >= minh) return;
 if (w < minw) w = minw;
 if (h < minh) h = minh;
 resizeTo(w, h);
}


// FontSizeX() - change font size
// - size must match the definitions in fontsize_X.css
function FontSizeL() { return FontSize('12pt', 'L'); }
function FontSizeM() { return FontSize('10pt', 'M'); }
function FontSizeS() { return FontSize('8pt', 'S'); }

function FontSize(newsize,scale) {
 var els = document.getElementsByTagName('body');
 var elsLen = els.length;
 for (var i = 0;  i < elsLen;  i++) {
  els[i].style.fontSize = newsize;
 }
 var sizelist = new Array("S", "M", "L");
 var x;
 for (x in sizelist) {
  var o, s;
  if (o = document.getElementById('fontsize' + sizelist[x])) {
   s = o.src;
   if (s.match(/-on\.gif/)) s = s.replace(/-on\.gif$/, '.gif');
   if (scale == sizelist[x]) s = s.replace(/\.gif$/, '-on.gif');
   if (o.src != s) o.src = s;
  }
 }
 return true;
}

// DisplayInFront() - display object in front
function DisplayInFront(o) {
 o.style.zIndex = 1;
}

// DisplayInNormal() - display object normal
function DisplayInBack(o) {
 o.style.zIndex = -1;
}

// DarkScreen() - dark screen
function DarkScreen() {
 var x = document.getElementById('darkscreen');
 if (!x) {
  var els = document.getElementsByTagName("body");
  els[0].insertAdjacentHTML('afterBegin', '<div id=darkscreen style="position:absolute;width:100%;height:100%;background-color:red;z-index:3;alpha(opacity=70);-moz-opacity:0.7;opacity:0.7;"></div>');
 }
}

// BBSConfirmThreadDeletion
function BBSConfirmThreadDeletion(threadtitle) {
 var msg;

 if (Lang == 'en') {
  msg = 'Thread "' + threadtitle + '" will be deleted.\nAll comments and attachments in this thread will be deleted and may not be viewed thereafter.\nThis is not a recoverable operation.\nPlease confirm.';
 } else {
  msg = "スレッド「" + threadtitle + "」を削除します。\nこのスレッドに書きこまれた全てのコメントや添付ファイルが\n削除されます。削除後は参照できなくなります。\nまた、削除したスレッドを復旧することもできません。\nよろしいですか？";
 }
 return confirm(msg);
}

/* 以下は使用禁止 */

/* Submitted() - submit operation completed */
function Submitted() {
 var e;

 e = getElementById('submitCount');
 if (e) {
  e.value = e.value + 1;
 }
 return true;
}

/* SubmitForm() - submit this form and disable the button */
function SubmitForm(button) {
 var f;

 f = button.form;
 if (! f) return false;  /* form property missing, stop processing! */

 f.submit();  /* ここで眠る必要がある? */
 button.disabled = 1;
 button.blur();
 return false;
}

function ShowLinkPane(o) {
 var paneid = o.id + "LinkPane";
 var paneobj = document.getElementById(paneid);
 var panetop = o.top + 10;
 var paneleft = o.left + 10;

 if (! paneobj) {
  var e = document.createElement("div");
  e.id = paneid;
  e.position = 'absolute';
  e.style.top = panetop;
  e.style.left = paneleft;
  e.style.backgroundColor = '#FF0000';
  e.style.color = '#FFFFFF';
  e.style.zIndex = 1;
  e.style.display = 'block';
  e.style.visibility = 'visible';
  var str = document.createTextNode("This is a TEST");
  e.appendChild(str);
  document.body.appendChild(e);
  paneobj = e;
 }
}

function CellUp(o) {
 var cellnum = o.id.replace("u","") * 1;
 var thiscell = document.getElementById("s" + cellnum);
 if (! thiscell) return false;
 var thistext = thiscell.innerHTML;
 if (cellnum == 1) return false;
 var prevcell = document.getElementById("s" + (cellnum - 1));
 if (! prevcell) return false;
 var prevtext = prevcell.innerHTML;
 var previnput = document.getElementById("o" + (cellnum - 1));
 var thisinput = document.getElementById("o" + cellnum);
 if (! previnput || ! thisinput) return false;
 var thisvalue = thisinput.value;
 var prevvalue = previnput.value;
 thisinput.value = prevvalue;
 previnput.value = thisvalue;
 prevcell.innerHTML = thistext;
 thiscell.innerHTML = prevtext;
 return true;
}

function CellDown(o) {
 var cellnum = o.id.replace("d","") * 1;
 var thiscell = document.getElementById("s" + cellnum);
 if (! thiscell) return false;
 var thistext = thiscell.innerHTML;
 var nextcell = document.getElementById("s" + (cellnum + 1));
 if (! nextcell) return false;
 var nexttext = nextcell.innerHTML;
 var nextinput = document.getElementById("o" + (cellnum + 1));
 var thisinput = document.getElementById("o" + cellnum);
 if (! nextinput || !thisinput) return false;
 var thisvalue = thisinput.value;
 var nextvalue = nextinput.value;
 thisinput.value = nextvalue;
 nextinput.value = thisvalue;
 nextcell.innerHTML = thistext;
 thiscell.innerHTML = nexttext;
 return true;
}

