/* JavaScript lib. scripts by martin $ 2006/05/23 01:24:12
*/
var d = document;
var ie = (d.selection && !window.opera) ? 1 : 0;
var lt7 = navigator.appVersion.match(/MSIE [56]/) ? 1 : 0;
var moz = (d.getSelection && !window.opera) ? 1 : 0;
var smilies = {};
var caretSelection = "";
var loadingAni = new Image().src = 'Images/loading.gif';
var expandImg = new Image(34,34).src = "Images/expand.png";
var unexpandImg = new Image(34,34).src = "Images/unexpand.png";
var screenBack = new Image(1,1).src = "Images/screen.png";
var closeButton = new Image(75,16).src = "Images/button-close.png";

function insertLink(target){
 var t = d.getElementById(target);
 var link = prompt('リンクしたいURLをどうぞ: ', 'http://');
 if(link){
  link = link.replace(/^(http\:\/\/)/g,'');
  if(!link.match(/[^;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()%]/)){
   var site = prompt("サイト名をどうぞ ", "");
   if(site) t.value += ('[link:'+link+']' + site + '[/link]');
  } else link = prompt('URLに不適な文字が入っているような...', link);
 } else {
  return;
 }
}

function googleIt(query){
 window.open(encodeURI("http://www.google.com/search?hl=ja&ie=UTF-8&oe=UTF-8&q="+query));
}
function wikipediaIt(query){
 window.open("http://ja.wikipedia.org/wiki/%E7%89%B9%E5%88%A5:Search?search="+encodeURI(query));
}
function getClientWidth(){
 if(self.innerWidth){
  return self.innerWidth;
 } else if(d.documentElement && d.documentElement.clientWidth){
  return d.documentElement.clientWidth;
 } else if(d.body){
  return d.body.clientWidth;
 }
}

function getClientHeight(){
 if(self.innerHeight){
  return self.innerHeight;
 } else if(d.documentElement && d.documentElement.clientHeight){
  return d.documentElement.clientHeight;
 } else if(d.body){
  return d.body.clientHeight;
 }
}

function getDocHeight(){ var h;
 if(d.documentElement && d.body){
  h = Math.max(
   d.documentElement.scrollHeight,d.documentElement.offsetHeight,d.body.scrollHeight
  );
 } else h = d.body.scrollHeight;
 return (arguments.length==1) ? h + 'px' : h;
}

function getEventPageX(ev){
 if(ev.pageX){
  return ev.pageX;
 } else if(ev.clientX){
  if(d.documentElement && typeof d.documentElement.scrollLeft != "undefined"){
   return d.documentElement.scrollLeft + ev.clientX;
  } else if(d.body && typeof d.body.scrollLeft != "undefined"){
   return d.body.scrollLeft + ev.clientX;
  }
 }
 return 0;
}

function getEventPageY(ev){
 if(ev.pageY){
  return ev.pageY;
 } else if(ev.clientY){
  if(d.documentElement && typeof d.documentElement.scrollTop != "undefined"){
   return d.documentElement.scrollTop + ev.clientY;
  } else if(d.body && typeof d.body.scrollTop != "undefined"){
   return d.body.scrollTop + ev.clientY;
  }
 }
 return 0;
}

function getScrollY(){
 if(d.documentElement && typeof d.documentElement.scrollTop != "undefined"){
  return d.documentElement.scrollTop;
 } else if(d.body && typeof d.body.scrollTop != "undefined"){
  return d.body.scrollTop;
 } else if(typeof window.pageYOffset != "undefined"){
  return window.pageYOffset;
 }
 return 0;
}

my_confirm = function(text,add){
 if(arguments.length==1) text += "削除しますか？";
 if(!confirm(text)) return false;
 else return true;
}

Cookie = { // クッキーの設定，呼び込み，削除
 set : function(name,value,days){
  var exp = "";
  if(days){
   var dt = new Date();
   dt.setTime(dt.getTime()+(days*24*60*60*1000));
   exp = "; expires="+dt.toGMTString();
  } else exp = "; expires=Sat, 31-Dec-2005 00:00:00 GMT;";
  d.cookie = name + "=" + escape(value) + exp + "; path=/";
 },
 get : function(name){
  c = document.cookie.split(";");
  for(var i=0,l=c.length;i<l;i++){
   index = c[i].indexOf("=");
   if(c[i].substr(0,index)==name||c[i].substr(0,index)==" "+name)return unescape(c[i].substr(index+1));
  }
  return '';
 },
 del : function(name) { Cookie.set(name,'',-1); }
}

readMore = function(id, self){
 var ob = o(id);
 if(ob.style.display!="block"){
  ob.parentNode.firstChild.title = '記事をたたむ';
  ob.parentNode.firstChild.innerHTML = '&laquo;hide';
  ob.parentNode.firstChild.style.backgroundPosition = "0 100%";
  ob.style.display = "block";
 } else if(ob.style.display=="block") {
  ob.parentNode.firstChild.title = '続きをよむ';
  ob.parentNode.firstChild.innerHTML = '&raquo;more';
  ob.parentNode.firstChild.style.backgroundPosition = "0 0";
  ob.style.display = "none";
 }
}

function toggleMenu(id, ob){
 var p = ob.parentNode.parentNode;
 var t = 'sidebar-'+id;
 for(var i=0,l=p.childNodes.length;i<l;i++){
  if(p.childNodes[i].className && p.childNodes[i].className.indexOf(t) > 0){
   var el = p.childNodes[i]; break;
  } else el = '';
 }
 if(el=='') return;
 var bgPos = ob.style.backgroundPosition;
 ob.style.backgroundPosition = bgPos=='0px 100%' ? '0px 0px' : '0px 100%';
 ob.title = bgPos=='0px 100%' ? '閉じます' : '展 開！';
 el.style.display = el.style.display=="none" ? 'block' : 'none';
}

Caret = { // マウスで指定したポイントあるいは文字列に要素を挿入
 get : function(){
  if(typeof ed == 'undefined'){
   if(o('Page1')!=null) ed = o('Page1');
   else if(o('c_com')!=null) ed = o('c_com');
   else ed = d.getElementsByTagName('TEXTAREA')[0];
  }
  if(ie){
   if(!d.selection.createRange()) ed.focus();
   ed.selected = d.selection.createRange().duplicate();
  } else if(d.getSelection && moz){
   ed.selected = ed.value.substring(ed.selectionStart, ed.selectionEnd);
  } else ed.selected = ' ';
  return caretSelection = (ie) ? ed.selected.text : ed.selected;
 },
 set : function(string){
  if(typeof(caretSelection)=='undefined' || typeof(ed)=='undefined') Caret.get();
  if(ed.createTextRange){
   if(caretSelection.length > 0){
    if(caretSelection.length > 0){
     ed.selected.text = string;
     ed.selected.select();
    } else ed.value += string;
   } else {
    ed.focus();
    ed.selected = d.selection.createRange().duplicate();
    ed.selected.text = string;
   }
   if(ed.selected) ed.selected.select();
  } else if(d.getSelection && caretSelection.length>=0 && ed.selectionStart>=0){
    var s = ed.selectionStart;
    ed.value = ed.value.slice(0,s)+ed.value.slice(s).replace(caretSelection, string);
    ed.setSelectionRange(s+string.length, s+string.length);ed.focus();
  } else ed.value += string;
 }
}

hackFirefoxToolTip = function(e){
 var imgs = d.getElementsByTagName('IMG');
 MozToolTip = Element("DIV", {backgroundColor:"ivory", border:"1px solid #333", padding:"1px 3px", font:"500 11px arial", zIndex:10000, top:"-100px"});
 MozToolTipShadow = Element("DIV", {MozOpacity:0.3, MozBorderRadius:"3px", background:"#000", zIndex:(MozToolTip.style.zIndex - 1)})
 
 for(i=0,l=imgs.length; i<l; i++){
  if(imgs[i].getAttribute('title') != null || imgs[i].getAttribute('alt') != null){
   addEvent(imgs[i], "mouseover", function(e){
    this._title = this.getAttribute('title')!=null ? this.getAttribute('title') : this.getAttribute('alt');
    this.setAttribute('title', '');
    this._title = this._title.replace(/[\r\n]+/g,'<br/>').replace(/\s/g,'&nbsp;');
    if(this._title=='') return;
    setXY(MozToolTip, 20 + e.pageX, 30 + e.pageY);
    MozToolTip.innerHTML = this._title;
    setWH(MozToolTipShadow, MozToolTip.offsetWidth -2, MozToolTip.offsetHeight -2);
    setXY(MozToolTipShadow, parseInt(MozToolTip.style.left) + 5, parseInt(MozToolTip.style.top) + 5);
   });
   addEvent(imgs[i], "mouseout", function(){
    this.setAttribute('title', MozToolTip.innerHTML.replace(/<br\/>/g,'&#13;&#10;').replace(/&nbsp;/g,' '));
    setXY(MozToolTip, -1000, -1000);
    setXY(MozToolTipShadow, -1000, -1000);
    MozToolTip.innerHTML = '';
   });
  }
 }
 d.body.appendChild(MozToolTipShadow);
 d.body.appendChild(MozToolTip);
}

function quotedStyle(elm){
 if(!elm){
  var bq = d.getElementsByTagName("BLOCKQUOTE");
 } else {
  var bq = elm.getElementsByTagName("BLOCKQUOTE");
 }
 for(i=0,l=bq.length;i<l; i++){
  var q = bq[i];
  with (q.style){
   position = "relative";
   margin = "20px 3em";
   padding = "15px 30px 6px 30px";
   height = q.offsetHeight + "px";
   background = "#f0efec";
  }
  var qtl = Element("SPAN", {background:"url(Images/qtl.png) no-repeat 0 0", width:"24px", height:"24px"});
  var qtr = qtl.cloneNode(true);
  var qbl = qtl.cloneNode(true);
  var qbr = qtl.cloneNode(true);
  with (qtr.style){
   background = "url(Images/qtr.png) no-repeat 0 0";
   left = q.offsetWidth - 12 + "px";
  }
  with (qbl.style){
   background = "url(Images/qbl.png) no-repeat 0 0";
   top = q.offsetHeight - 12 + "px";
  }
  with (qbr.style){
   background = "url(Images/qbr.png) no-repeat 0 0";
   top = q.offsetHeight - 24 + "px";
   left = q.offsetWidth - 24 + "px";
  }
  q.insertBefore(qtr, q.firstChild); q.insertBefore(qtl, q.firstChild);
  q.insertBefore(qbl, q.firstChild); q.insertBefore(qbr, q.firstChild);
 }
}

function roundedStyle(elm){
 var elm = elm ? elm : document;
 var rs = d.getElementsByClassName("rounded", elm);
 for(i=0,l=rs.length;i<l;i++){
  var q = rs[i];
  with (q.style){
   position = "relative";
   padding = "6px 6px 6px 50px";
   margin = "20px 3em";
   backgroundColor = "#eee";
   lineHeight = 1.5;
   height = q.offsetHeight + "px";
  }
  var qtl = Element("SPAN", {background:"url(Images/rtl.png) no-repeat 0 0", width:"12px", height:"12px"});
  var qtr = qtl.cloneNode(true);
  var qbl = qtl.cloneNode(true);
  var qbr = qtl.cloneNode(true);
  with (qtr.style){
   background = "url(Images/qtr.png) no-repeat 0 0";
   left = q.offsetWidth - 12 + "px";
  }
  with (qbl.style){
   background = "url(Images/qbl.png) no-repeat 0 0";
   top = q.offsetHeight - 12 + "px";
  }
  with (qbr.style){
   background = "url(Images/rbr.png) no-repeat 0 0";
   top = q.offsetHeight - 12 + "px";
   left = q.offsetWidth - 12 + "px";
  }
  q.insertBefore(qtr, q.firstChild); q.insertBefore(qtl, q.firstChild);
  q.insertBefore(qbl, q.firstChild); q.insertBefore(qbr, q.firstChild);
 }
}

var Ajax = {
 request : function(){
  return window.XMLHttpRequest ? 
  new XMLHttpRequest() : (window.ActiveXObject) ?
  new ActiveXObject(navigator.appVersion.match(/MSIE 5/) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP") : null;
 },
 get : function(url, func){
  var r = Ajax.request();
  try {
   r.open("GET", url, true);
   r.onreadystatechange = function(){
    Ajax.debug("Now Loading.. "+ url + " : " + r.readyState);
    if(r.readyState==4){
     if(func) func(r.responseText);
     Ajax.debug("");
    }
   }
   r.send(null);
  } catch (e){Ajax.debug(e,1)}
 },
 post : function(url, data, func){
  var r = Ajax.request();
  try {
   r.open("POST", url, true);
   r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   r.onreadystatechange = function(){
    if(r.readyState==4){
     if(func) func(r.responseText);
    }
   }
   r.send(data);
  } catch (e){Ajax.debug(e,1)}
 },
 cloneScript : function(src){
  var id = src.split(/\//).pop().replace(/\./, '_');
  var h = d.getElementsByTagName("head")[0];
  var s = d.createElement("script");
  var r = Ajax.request();
  s.type = "text/javascript";
  s.charset = "euc-jp";
  s.id = id;
  if(!d.getElementById(id)){
   h.appendChild(s);
  } else return true; // cached
  r.open("GET", src, false); // Not async.
  r.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
  r.send(null);
  if(r.readyState==4 && r.status==200|304){ // Opera8.02's "304" is OK
   s.text = r.responseText; // text property!
   return true;
  }
  if(d.getElementById(id)){
   d.getElementById(id).parentNode.removeChild(d.getElementById(id));
   Ajax.debug("404 error : " + src);
  }
  return false;
 },
 debug : function(d, a){!a ? (window.status=d) : alert("Ajax debug: "+d);}
}

comments_in_situ = function(uid, author, allowed, ob, e){
 Ajax.cloneScript("ajax.php?type=info");
 var loaded = Ajax.cloneScript('ajax.php?type=json&aim=owner/smiley.ini.php');
 var articleBottom = gc("article-bottom", o("UID"+uid))!=null ?
  gc("article-bottom", o("UID"+uid)) : gc("article-united-bottom", o("UID"+uid));
 var eX = getEventPageX(e);
 if(o("ajaxToolTip")==null){
  toolTip = Element("DIV#ajaxToolTip",
   {backgroundColor:"ivory", border:"1px solid #333", padding:"2px 3px", width:"140px", font:"500 13px MS P Gothic, Osaka", textAlign:"center",
    zIndex:10000, left:eX + (getClientWidth()/2<eX?-200:200) + "px", top:getEventPageY(e) + "px"}
  );

  toolTip.innerHTML = 'コメント読み込み中...';
  d.body.appendChild(toolTip);
 } else {
  toolTip = o("ajaxToolTip");
  toolTip.innerHTML = 'コメント読み込み中...';
  with (toolTip.style){
   display = "block";
   top = getEventPageY(e) + "px";
   left = eX + (getClientWidth()/2<eX?-200:200) + "px";
  }
 }
 var callback = function(data){
  var commentDiv = Element("DIV.comment-div", {position:"relative", marginLeft:"13px"});
  data = data.replace(
   /[^\|](http:)(\/\/[;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()%]+)[^\|]/gm,
   function (s0,s1,s2){
    return '<a href="'+s1+s2+'" title="新しいウィンドウで開きます" onclick=\'window.open(this.href,null);return false;\'>'+s1+s2+'</a>`';
   }
  );
  data = data.replace(
   /\[link:(.+?)\](.+?)\[\/link\]/gm,
   function (s0, s1, s2){
    return '<a href="http://'+s1+'">'+s2+'</a>';
   }
  );
  data = data.replace(/\[q\]`?(.+?)`?\[\/q\]/gm, '<p class="comment-quote">\\$1</p>');
  for (var i in smilies){
   var r = new RegExp(i.toString().replace(/(\W)/, "\\$1"), "g");
   data = data.replace(r, smilies[i]);
  }
  var cmt = '', nondisc = '';
  var aj = data.split("\n");
  var ajlen = aj.length;
  if(typeof ADMIN == "undefined") ADMIN = false;
  if(ajlen > 1){
   var ID = aj[0].split('|')[0];
   var NO = 0;
   for(i=1; i < ajlen-1; i++){
    var a = aj[i].split('|'); // a[1] = submitter
    if(a[7]==1){
     if(!ADMIN){
      continue;
     } else {
      nondisc = " non-disclosure";
      NO++;
     }
    } else {
     NO++;
     nondisc = '';
    }
    var d = new Date(a[0]*1000), Y = d.getFullYear(), mn = d.getMonth()+1, day = d.getDate();
    var h = d.getHours(), mt = d.getMinutes(), s = d.getSeconds();
    h = (h < 10) ? "0"+h : h; mt = (mt < 10) ? "0"+mt : mt; s = (s < 10) ? "0"+s : s;
    var u = a[5]!='' ? ' <a href="'+a[5]+'"><img src="Images/home.png" alt="Website" title="Website" class="home-icon" /></a>' : '';
    var cbody = a[3].replace(/`/gm, "<br />");
    var cntrl = ADMIN ?
     '<span class="comment-cntrl"><a  href="index.php?mode=edit_comment&amp;UID='+uid+'&amp;CID='+a[0]+'"><img src="Images/edit_comment.png" alt="Edit" title="このコメントの編集" /></a> <a  href="index.php?mode=delete_comment&amp;UID='+uid+'&amp;CID='+a[0]+'" onclick="return my_confirm(\'このコメントを\')"><img src="Images/del_comment.png" alt="Delete" title="このコメントの削除" /></a> ' : '';
    var res = (ADMIN) ?
     '<a href="index.php?mode=res_comment&amp;UID='+uid+'&amp;CID='+a[0]+'"><img src="Images/reply.png" alt="Reply" title="このコメントに返事を書く" /></a></span>' : '';
    cmt += (author==a[1] ? ' <div class="comment-entry-owner">\n' : ' <div class="comment-entry'+nondisc+'">\n');

    if(author==a[1]){ // owner
     cmt += ('  <p><a class="owner" id="CID'+a[0]+'" title="Permalink" href="index.php?UID='+ID+'#CID'+a[0]+'"> <img src="Images/lcomment.png" class="comment-owner" title="Permalink" alt="Owner Comment" /></a> '+a[1]+u+' &mdash; '+Y+'/'+mn+'/'+day+'@'+h+mt+s+'</p>\n');
    } else {
     cmt += ('  <p class="comment-index"><a class="No" id="CID'+a[0]+'" title="Permalink" href="index.php?UID='+ID+'#CID'+a[0]+'">#'+NO+'.</a> '+a[1]+u+' &mdash; '+Y+'/'+mn+'/'+day+'@'+h+mt+s+'</p>\n');
    }
    cmt += ('  <div class="comment-body" style="color:#'+a[2]+';">'+cbody+cntrl+res+'</div>\n');
    cmt += '</div>\n';
    if(i < ajlen-1 ) cmt += '<hr class="comment-separator" />\n';
   } //for-loop
   if(allowed){
    cmt += '<div class="commentFormHere"><button type="button" onclick="loadCommentForm('+uid+');return false;" title="コメントする">Add your comment</button></div>\n';
   } else {
    cmt += '<p class="comment-closed">この記事に対するコメントは締め切られています</p>\n';
   }
   cmt += '</div><!--#comment-div-->\n';
  }
  commentDiv.innerHTML = cmt;
  articleBottom.appendChild(commentDiv);
  ob.firstChild.data = ob.firstChild.data.replace(/\[\+\]/,"[-]");
  ob.title = "表示したコメントを隠します";
  toolTip.innerHTML = ' コメント読み込み完了！ ';
  setTimeout('toolTip.style.display = "none"', 500);
 } //#callback
 if(articleBottom.innerHTML.match(/comment-div/)){ // already loaded and displayed
  var comment = gc("comment-div", articleBottom);
  toolTip.style.display = "none";
  if(comment.style.display!="none"){
   comment.style.display = "none";
   ob.firstChild.data = ob.firstChild.data.replace(/\[\-\]/,"[+]");
   return;
  } else {
   comment.style.display = "block";
   ob.firstChild.data = ob.firstChild.data.replace(/\[\+\]/,"[-]");
   return;
  }
 }
 if(!loaded){
  return;
 } else {
  Ajax.get('ajax.php?type=text&aim=comments/'+uid+'.log', callback);
 }
}

function loadCommentForm(uid,ob){
 var loaded1 = Ajax.cloneScript("ajax.php?type=info");
 var loaded2 = Ajax.cloneScript("ajax.php?type=clone&aim=js/comment.js");
 if(loaded1 && loaded2){
  Ajax.get("ajax.php?type=commentform&UID="+uid, function(data){gc("commentFormHere",o("UID"+uid)).innerHTML=data;});
 }
}

function loadArticle(uid, page){
 var type = (page) ? "page" : "article";
 Ajax.get("ajax.php?type="+type+"&UID="+uid+(page?("&page="+page):""), function(data){
  var articleContent = gc("article-content", o("UID"+uid.replace(/d$/,'')));
  articleContent.style.lineHeight = 1.7;
  if(gc("comment-expand", o("UID"+uid))!=null){
   data += '<p class="comment-expand" title="ここでコメントを展開します">'
        + gc("comment-expand", o("UID"+uid)).innerHTML
        + '</p>\n';
  }
  articleContent.innerHTML = data;
  quotedStyle(articleContent);
  roundedStyle(articleContent);
  if(moz) hackFirefoxToolTip();
 });
}

function AjaxLogIn(){
 o("loginSubmit").disabled = true;
 var MD5_module = Ajax.cloneScript("./js/md5.js");
 if(MD5_module){
  var auto = (o("auto_login") && o("auto_login").checked) ? 1 : 0;
  Ajax.post("admin.php", "mode=login&ID="+MD5.$(o("ID").value)+"&PWD="+MD5.$(o("PWD").value)+"&type=ajax&auto_login="+auto,
   function(to){(to);
    if(to.match(/\.php/)){
     d.write('<script type="text\/javascript">window.location.href="'+to+'";<\/script>');
    } else {
     alert(to);
     o("loginSubmit").disabled = false;
     o("ID").focus();
    }
   }
  );
 } else alert("md5.js module Not Loaded!");
}

function AjaxLogInForm(){
 Ajax.cloneScript("ajax.php?type=info");
 var loginCS = new Image(14,14).src = "Images/dialog-close.png";
 var BS = Element("DIV", {width:getClientWidth()+"px", height:getDocHeight()+"px", backgroundColor:"#708090", zIndex:999});
 var IO = Element("DIV",
  {left:Math.round((getClientWidth()-270)/2)+"px", top:"-160px", width:"270px", height:"180px", zIndex:1000, textAlign:"center",
   border:"outset 3px #aaa", borderTopWidth:0, background:"#ccc url(Images/login-bg.png) repeat-x", padding:"0 20px" });
 var CS = Element("IMG", { left:"287px", top:"4px", width:"14px", height:"14px", cursor:"pointer"});
 CS.src = loginCS;  CS.title = " 閉じる ";
 
 if(typeof AUTO_LOGIN != 'undefined'){
  if(AUTO_LOGIN){
   setXY(IO, null, 0);
   setWH(IO, null, 120);
   var UI = '<h3>ppBlog*Login</h3>\n'
   + '<p style="line-height:1.3;">自動ログインが有効です.<br />ログインモードに移ります.</p>'
   + '<p><input id="auto_login" name="auto_login" type="hidden" value="1" /></p>';
  } else {
   var UI = '<h3>ppBlog*Login</h3>\n'
   + '<p><label for="ID"> I D </label><input type="text" name="ID" id="ID" /><br />'
   + '<label for="PWD">PWD </label><input type="password" name="PWD" id="PWD" /></p>'
   + (SOLO ? '<p><label for="auto_login" title="次回から自動ログインモードになります">auto-login mode?</label> '
   + '<input id="auto_login" name="auto_login" type="checkbox" value="1" /><br /></p>\n' : '\n')
   + '<p><button type="submit" id="loginSubmit">&nbsp;</button></p>';
  }
 }
 IO.innerHTML = UI;
 addEvent(CS, "click", function(){d.body.removeChild(BS);d.body.removeChild(IO);});
 
 if(ie){
  BS.style.filter = "alpha(opacity=73)";
 } else BS.style.opacity = 0.73;
 IO.appendChild(CS);
 d.body.appendChild(BS);
 d.body.appendChild(IO);
 
 if(typeof AUTO_LOGIN != 'undefined' && AUTO_LOGIN){
  
  Ajax.post("admin.php", "mode=login&type=auto_login", function(to){
   if(to.match(/\.php/)){
    setTimeout('window.location.replace("'+to+'");', 1200);
   }
  });
 } else {
  var fieldcss = "color:#333; height:16px; vertical-align:middle; padding:3px 8px; width:160px; border-width:0;"
              + "margin-bottom: 5px; background: transparent url(Images/txtfield-bg.png) no-repeat 0 0;";
  var btncss = "margin:9px auto 0 auto;width:64px; height:28px; border-width:0; cursor:pointer;"
              + "background: transparent url(Images/submit-button.png) no-repeat;";
  o("loginSubmit").style.cssText = btncss;
  o("ID").style.cssText = o("PWD").style.cssText = fieldcss;
  o("ID").previousSibling.style.cssText = "margin-left:15px;font: 600 15px Arial;color:#444;";
  o("PWD").previousSibling.style.cssText = "font: 600 15px Arial;color:#444;";
  o("loginSubmit").title = "Check it out";
  if(o("ID")) o("ID").focus();
  addEvent(o("loginSubmit"), "click", AjaxLogIn);
  var slideDown = function(ob){ob.style.top = (parseInt(ob.style.top)+10) +"px"};
  slideDown.loop(1, 16)(IO);
 }
}

function gc(clsName, pElement){
 var children = pElement.getElementsByTagName("*");
 for(var i=0,l=children.length;i<l;i++){
  if(children[i].className==clsName) return children[i];
 }
 return null;
}

d.getElementsByClassName = function(className, pElement, tagName){
 var cls, gets = [];
 var obs = pElement.getElementsByTagName((!tagName?"*":tagName));
 for (var i=0,l=obs.length; i < l; i++){
  var cls = obs[i].className.split(/\s+/);
  for (var j=0,k=cls.length; j < k; j++){
   if(cls[j]==className){
    gets.push(obs[i]); break;
   }
  }
 }
 return gets;
}

imagePop = function (e, path, w, h){
 var gcW = getClientWidth(), gcH = getClientHeight(), ratio, ow = w, oh = h;
 if(w > gcW-20 || h > gcH-70){
  ratio = Math.min((gcW-20)/w, (gcH-70)/h);
  w = Math.round(w * ratio); h = Math.round(h * ratio);
 } else ratio = 1;
 if(typeof imgPop == "undefined") imgPop = null;
 if(imgPop==null){
  var imgWrap = Element("DIV", {left:Math.round((gcW-w) / 2)+"px", top:Math.round((gcH-h-67) / 2 + getScrollY())+"px", width:w+"px", height:(h+45)+"px", backgroundColor:"#ccc", zIndex:1000, border:"1px solid #aaa", padding: "10px"});
  var imgCaption = Element("P", {left:0, top:(h+20)+"px", width:w+"px", textAlign:"right", font:"500 9pt/1.5 MS P Gothic", color:"navy", display:"none"});
  imgPop = Element("IMG", {left:"10px", top:"10px", width:w+"px", height:h+"px", backgroundColor:"#fff", border:"1px solid #aaa", display:"none"});
  var Screen = Element("DIV", {width:gcW+"px", height:getDocHeight()+"px", zIndex:999, background:"url(../Images/screen.png)"});
  var loadingImg = Element("IMG", {left:Math.round(parseInt(imgWrap.style.width)/2)+"px", top:Math.round(parseInt(imgWrap.style.height)/2)+"px", width:"32px", height:"32px", backgroundColor:"#fff", zIndex:999});
  var closeImg = Element("IMG", {left:(parseInt(imgWrap.style.width)-68)+"px", top:"15px", width:"75px", height:"16px", cursor:"pointer"});
  closeImg.src = closeButton;
  closeImg.title = "閉じる";
  if(ratio < 1){
   var expand = Element("IMG", {left:"12px", top:"12px", width:"34px", height:"34px", zIndex:1000, cursor:"pointer", display:"none"});
   expand.src = expandImg; expand.title = " 実物大で表示 ";
   expand.on = false;
  }
  loadingImg.src = loadingAni;
  Screen.style.backgroundImage = "url("+screenBack+")";
  d.body.appendChild(Screen);
  
  if(ie){
   if(lt7) Screen.style.filter = "alpha(opacity=73)";
   e.target = e.srcElement;
  }
  imgWrap.appendChild(loadingImg);
  imgWrap.appendChild(imgCaption);
  imgWrap.appendChild(imgPop);
  imgWrap.appendChild(closeImg);
  d.body.appendChild(imgWrap);
  if(ratio < 1) imgWrap.appendChild(expand);
  var caption = (typeof e.target._title=="undefined") ? e.target.title : e.target._title;
  caption = caption.replace(/[\r\n]+/g,'<br/>').replace(/\s/g,'&nbsp;');
  caption = caption.split(/<br\/?>/);
  if(caption.length > 1){
   imgCaption.innerHTML = (caption[0]+"<br />"+caption[1]+" ("+ow+"×"+oh+")");
  } else imgCaption.innerHTML = '画像をクリックすると閉じます <img src="Images/info2.png" width="21" height="14" alt="info" />';
  addEvent(loadingImg, "load", function(){ imgPop.src = path; });
  addEvent(imgPop, "load", function(){
   imgPop.style.display = imgCaption.style.display = "block";
   loadingImg.style.display = "none";
   if(expand) expand.style.display = "block";
  });
  addEvent(closeImg, "click", function(){
   d.body.removeChild(imgWrap);
   d.body.removeChild(Screen);
   imgPop = null;
  });
  addEvent(imgPop, "click", function(){
   d.body.removeChild(imgWrap);
   d.body.removeChild(Screen);
   imgPop = null;
  });
  if(ratio < 1){
   addEvent(expand, "click", function(){
    if(expand.on==false){
     setXY(imgWrap, 0, getScrollY());
     setWH(imgWrap, ow+3, oh);
     setWH(imgPop, ow, oh);
     setXY(closeImg, (parseInt(imgWrap.style.width)-69), null);
     expand.src = unexpandImg; expand.title = " ウィンドウのサイズに合わせる ";
     expand.on = true;
    } else {
     setXY(imgWrap, Math.round((gcW-w) / 2), Math.round((gcH-h-67) / 2 + getScrollY()));
     setWH(imgWrap, w, h+45);
     setWH(imgPop, w, h);
     setXY(closeImg, (parseInt(imgWrap.style.width)-66), null);
     expand.src = expandImg; expand.title = " 実物大で表示 ";
     expand.on = false;
    }
   });
  } //#ratio==1
  imgPop.title = "マウスクリックで閉じます";
 } //#imgPop==null
}

initCSSHover = function(){
 if(ie){
  if(o("theme-selector")){
   var root = o("theme-selector");
   addEvent(root, "mouseover", tsOver);
   addEvent(root, "mouseout", tsOut);
  }
 }
}
function tsOver(){this.className+=" over";}
function tsOut(){this.className=this.className.replace(/ over/, "");}
function noCSS(){
 if(d.styleSheets) for(var i=0,l=d.styleSheets.length;i<l;i++)d.styleSheets.item(i).disabled = true;
 for(var i=0, link = d.getElementsByTagName("link"), l = link.length; i < l; i++){
  if(link[i].rel.match(/stylesheet/i)) link[i].disabled = true;
 }
 for(var e = d.getElementsByTagName("*"), i=0, l=e.length; i < l; i++) e[i].style.cssText = "";
}
function addEvent(obj, evType, fn){
 if(!obj["_"+evType]){
  obj["_"+evType] = [];
  if(obj["on" + evType] != null) obj["_"+evType].push(obj["on" + evType]);
  obj["on" + evType] = evokeEvent;
 } else for(var i in obj["_"+evType]) if(obj["_"+evType][i]===fn) return;
 obj["_"+evType].push(fn);
};
function removeEvent(obj, evType, fn){
 if(obj["_"+evType]){
  for(var i in obj["_"+evType]){
   if(obj["_"+evType][i]===fn) delete obj["_"+evType][i];
  }
 }
};
function evokeEvent(e) {
 var e = e || window.event;
 for(var i in this["_"+e.type]) this["_"+e.type][i].apply(this,[e]);
};

function o(a){
 if(typeof a == "object") return a;
 if(typeof a == "string"){
  if(a.match(/(^[a-zA-Z0-9_-]+$)/)){ // Unique ID
   return d.getElementById(a);
  } else if(a.match(/([a-zA-Z0-9\*]*?)\.([a-zA-Z0-9_-]+$)/)){ // tagName.className
   return d.getElementsByClassName(RegExp.$2, d, RegExp.$1);
  }
 }
 return null;
};

function Element(tag, prop, parent, append){
 var el = d.createElement(tag.split(/[#\.]/)[0]);
 with (el.style){
  position = "absolute";
  left = top = padding = margin = 0;
  width = el.offsetWidth || "auto" || 0;
  height = el.offsetHeight || "auto" || 0;
 }
 if(tag.split(/#/)[1]) el.id = tag.split(/#/)[1];
 if(tag.split(/\./)[1]) el.className = tag.split(/\./)[1];
 if(prop) for (var i in prop) el.style[i] = prop[i];
 if(append){
  if(parent) parent.appendChild(el); else d.body.appendChild(el);
 }
 return el;
}

function setXY(ob, x, y){
 if(x != null) ob.style.left = parseInt(x) + "px";
 if(y != null) ob.style.top = parseInt(y) + "px";
}

function setWH(ob, w, h){
 if(w != null) ob.style.width = parseInt(w) + "px";
 if(h != null) ob.style.height = parseInt(h) + "px";
}

Function.prototype.await = function(ms){
 var self = this;
 var f = function(){
  var a = f.arguments, t = this;
  var callee = function(){self.apply(t, a);};
  setTimeout(callee, ms);
 };
 return f;
}

Function.prototype.loop = function(ms, limit){
 var count = 0, self = this;
 return function(a){
  if(limit <= count) return;
  count++;
  self.await(ms)(a);
  arguments.callee.await(ms)(a);
 }
}

DOM = {
 ready : false,
 size : d.documentElement.getElementsByTagName("*").length,
 check : function(){ DOM.ready ?  DOM.onload() : DOM.update.await(100)(DOM.size); },
 update : function(i){
  if(d.documentElement.getElementsByTagName("*").length==i){
   DOM.ready = true;
   DOM.onload();
  } else {
   DOM.size = d.documentElement.getElementsByTagName("*").length;
   DOM.update.await(50)(DOM.size);
  }
 },
 onload : function(){}
}
DOM.check();

DOM.onload = function(){
 roundedStyle();
 quotedStyle();
 if(lt7) initCSSHover();
 if(moz) hackFirefoxToolTip();
}

