/* JavaScript lib. scripts by martin $ 2006/06/22 01:23:06
*/
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 ImagePath = 'theme/'+d.getElementsByTagName("script")[d.getElementsByTagName("script").length-1].id+'/Images';
var loadingAni = new Image().src = ImagePath+'/loading.gif';
var expandImg = new Image().src = ImagePath+'/expand.png';
var unexpandImg = new Image().src = ImagePath+'/unexpand.png';
var screenBack = new Image(1,1).src = ImagePath+'/screen.png';
var closeButton = new Image().src = ImagePath+'/button-close.png';

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 windowEvent(){
 if(window.event) return window.event;
 var caller = arguments.callee.caller;
 while(caller){
  var ob = caller.arguments[0];
  if(ob && ob.constructor == MouseEvent) return ob;
  caller = caller.caller;
 }
 return null;
}

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(){
 var ev = windowEvent();
 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(){
 var ev = windowEvent();
 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 getElementPosition(){
 var _x = _y = 0;
 var ob = windowEvent().target || windowEvent().srcElement;
 if(ob.offsetParent){
  while (ob.offsetParent){
   _x += ob.offsetLeft; _y += ob.offsetTop;
   ob = ob.offsetParent;
  }
 }
 return [_x, _y];
}

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;
}

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;
    var scrollTop = ed.scrollTop;
    ed.value = ed.value.slice(0,s)+ed.value.slice(s).replace(caretSelection, string);
    ed.setSelectionRange(eval(s+string.length), eval(s+string.length));
    ed.scrollTop = scrollTop;
    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,' '));
    if(typeof setXY == "function"){
     setXY(MozToolTip, -1000, -1000);
     setXY(MozToolTipShadow, -1000, -1000);
     MozToolTip.innerHTML = '';
    }
   });
  }
 }
 if(d.body){
  d.body.appendChild(MozToolTipShadow);
  d.body.appendChild(MozToolTip);
 }
}

function roundedStyle(elm, quote){
 var RS = d.getElementsByClassName("rounded", elm);
 if(quote) { var RS = d.getElementsByClassName("quoted", d, "BLOCKQUOTE"); }
 var RS_Content = [], cord = 0.93;
 for(var i=0,l=RS.length;i<l;i++){
  var contents = RS[i].innerHTML;
  var upper = '<span><span></span><span><span></span></span><span><span></span></span>'
   + '<span><span></span></span><span><span></span></span></span>';
  var lower = '<span><span><span></span></span><span><span></span></span>'
   + '<span><span></span></span><span><span></span></span><span></span></span>';

  var pbg = backgroundRGB(RS[i].parentNode), bg = backgroundRGB(RS[i]);
  var border = "rgb("+parseInt(bg[0] * cord)+", "+parseInt(bg[1] * cord)+", "+parseInt(bg[2] * cord)+")";
  var alias = "rgb("+parseInt(eval(pbg[0]+bg[0])*.5)+", "+parseInt(eval(pbg[1]+bg[1])*.5)+", "+parseInt(eval(pbg[2]+bg[2])*.5)+")";
  var bg = "rgb("+bg[0]+","+bg[1]+","+bg[2]+")";
  var wd = RS[i].style.width!='' ? RS[i].style.width : 'auto';
  RS[i].style.cssText += "background-color:transparent; margin: 1.5em 2em; width:"+wd+';padding:0;';

  RS[i].innerHTML = upper;

  var base = 'display:block; height:1px; overflow:hidden; font-size:1px; background:'+bg+';'
   + ' border-width:0 1px; border-color:'+border+'; border-style: solid;';
  
  var c = RS[i].getElementsByTagName("SPAN");
  c[0].style.cssText = 'display: block;';
  c[1].style.cssText = base + 'border-color:'+alias+'; padding:0 1px; margin:0 4px; background:'+border+';';
  c[2].style.cssText = base + 'border-color:'+alias+'; padding:0 2px; margin:0 2px; background:'+border+';';
  c[3].style.cssText = base + 'border-color: '+alias+';';
  c[4].style.cssText = base + 'border-color:'+alias+'; padding:0 1px; margin:0 1px; background:'+border+';';
  c[5].style.cssText = base + 'border-color: '+alias+';';
  c[6].style.cssText = base + 'margin:0 1px;'; c[7].style.cssText = base + 'border-color: '+alias+';';
  c[8].style.cssText = base + 'border-color: '+alias+';'; c[9].style.cssText = base + 'border-color: '+border+';';
  
  RS[i].innerHTML += lower;
  c[10].style.cssText = c[0].style.cssText;  c[11].style.cssText = c[8].style.cssText;
  c[12].style.cssText = c[9].style.cssText;  c[13].style.cssText = c[6].style.cssText;
  c[14].style.cssText = c[7].style.cssText;  c[15].style.cssText = c[4].style.cssText;
  c[16].style.cssText = c[5].style.cssText;  c[17].style.cssText = c[2].style.cssText;
  c[18].style.cssText = c[3].style.cssText;  c[19].style.cssText = c[1].style.cssText;
  
  RS_Content[i] = Element("DIV",
   { position:"relative", border:"solid 1px "+border, borderWidth:"0 1px", padding:"10px 15px", background:bg });
  RS_Content[i].innerHTML = contents;

  RS[i].insertBefore(RS_Content[i], c[10]);
  if(quote){
   var quoteLeft = Element("P", { position:"relative" });
   quoteRight = quoteLeft.cloneNode(true);
   quoteLeft.innerHTML = '&nbsp;“';
   quoteLeft.style.cssText = 'margin: -3px 0 -10px -25px;font:600 50px/.7 Georgia;color:#ddd;';
   RS_Content[i].insertBefore(quoteLeft, RS_Content[i].firstChild);
   quoteRight.innerHTML = '&nbsp;”';
   quoteRight.style.cssText = 'font:600 50px/0 Georgia;margin:10px -10px -12px 0;text-align:right;color:#ddd;';
   RS_Content[i].insertBefore(quoteRight, null);
   for (var j=1, nodes=RS_Content[i].childNodes;j<nodes.length-1;j++){
    if(typeof nodes[j].style != "undefined"){
     nodes[j].style.margin = "-27px 0 0px 10px";
    }
   }
  }
 }
}

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){
 Ajax.cloneScript("ajax.php?type=info");
 var FILTER = {'&#96;':"`", '&#44;':",", '&#124;':"|", '&#36;':"$", '&yen;':'\\', '&quot;':"\""};
 var ob = windowEvent().target || windowEvent().srcElement;
 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();
 var eY = getEventPageY();
 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:eY + "px"}
  );

  toolTip.innerHTML = 'コメント読み込み中...';
  d.body.appendChild(toolTip);
 } else {
  toolTip = o("ajaxToolTip");
  toolTip.innerHTML = 'コメント読み込み中...';
  setXY(toolTip, eX + 100, eY);
 }
 var externalLink = ' <img src="'+ImagePath+'/external-link.png" width="12" height="12" alt="Link" title="外部リンク" />';
 var callback = function(data){
  var commentDiv = Element("DIV.comment-div", {position:"relative", marginLeft:"13px"});
  data = data.replace(/\[\[(.+?):http:\/\/(.+?)\]\]/gm,
   function (s0, s1, s2){
    return '<a href="http://'+s2+'" onclick="window.open(this.href,\'\');return false;" rel="nofollow">'+s1+'</a>'+externalLink;
  });
  data = data.replace(/[^"\|]http:\/\/([;\/\?:@&=\+\$,\w\-\.!~%#\|]+)/gm,
   function (s0, s1){
    return '<a href="http://'+s1+'" onclick="window.open(this.href,\'\');return false;" rel="nofollow">http://'+s1+'</a>'+externalLink;
   });
  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 = '', aj = data.split("\n"), ajlen = aj.length;
  if(typeof ADMIN == "undefined") ADMIN = false;
  if(ajlen > 1){
   var ID = aj[0].split('|')[0], NO = isNondiscUsr = 0, tip = '';
   for(i=1; i < ajlen-1; i++){
    var a = aj[i].split('|'); // a[1] = submitter
    var cip = a[4]!=0 ? ' IP: '+a[4] : ' IP: -';
    var cmail = (a[6]=='') ? '' : ' <span style="color:rgb(250, 60, 5);font-size:11px;">メールアドレス登録あり</span>';
    if(document.cookie.match(/PPBLOG_UCONF=(.+?);/)){
     var tip = unescape(RegExp.$1).split(',').pop();
     if(tip==encodeURIComponent(a[1]+a[4])) isNondiscUsr = a[1];
    }
    if(a[7]==1){
     if(!OADMIN){
      if(a[1]==ONAME){
       if(isNondiscUsr && aj[i-1].indexOf("|"+isNondiscUsr+"|")!=-1){
        isNondiscUsr = a[1];
       } else continue;
      } else {
       if(tip==encodeURIComponent(a[1]+a[4])){ // 非公開指定したユーザーっぽい
        isNondiscUsr = a[1];
       } else continue;
      }
      if(isNondiscUsr){ NO++; c_nondisc = ' non-disclosure'; }
     } else { // ADMINなら
      NO++; c_nondisc = ' non-disclosure';
     }
    } else { NO++; c_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]+'" onclick="window.open(this.href,\'\');return false;"><img src="'+ImagePath+'/home.png" alt="Website" title="Website" class="home-icon" /></a>' : '';
    var cbody = a[3].replace(/`/gm, " <br /> ");
    var cntrl = (OADMIN || UNAME==a[1]) ?
     '<span class="comment-cntrl"><a  href="admin.php?mode=edit_comment&amp;UID='+uid+'&amp;CID='+a[0]+'"><img src="'+ImagePath+'/edit-comment.png" alt="Edit" title="このコメントの編集" /></a> <a  href="admin.php?mode=delete_comment&amp;UID='+uid+'&amp;CID='+a[0]+'" onclick="return my_confirm(\'このコメントを\')"><img src="'+ImagePath+'/del-comment.png" alt="Delete" title="このコメントの削除" /></a> ' : '';
    var res = (OADMIN || UNAME==a[1]) ?
     '<a href="admin.php?mode=res_comment&amp;UID='+uid+'&amp;CID='+a[0]+'"><img src="'+ImagePath+'/reply.png" alt="Reply" title="このコメントに返事を書く" /></a></span>' : '';
    cmt += (author==a[1] ? ' <div class="comment-entry-owner">\n' : ' <div class="comment-entry'+c_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="'+ImagePath+'/owner-comment.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+' '+(ADMIN?cip+' '+cmail:'')+'</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';
  }
  for (var i in FILTER){ cmt = cmt.replace(new RegExp(i, "g"), FILTER[i]); }
  commentDiv.innerHTML = cmt;
  articleBottom.appendChild(commentDiv);
  if(ob){
   ob.firstChild.data = ob.firstChild.data.replace(/\[\+\]/,"[-]");
   ob.title = "表示したコメントを隠します";
  }
  toolTip.innerHTML = ' コメント読み込み完了！ ';
  setTimeout('toolTip.style.top = "-1000px"', 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";
   if(ob) ob.firstChild.data = ob.firstChild.data.replace(/\[\-\]/,"[+]");
   return;
  } else {
   comment.style.display = "block";
   if(ob) 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 oContent = o("UID"+uid.replace(/d$/,''));
  var articleContent = gc("article-content", oContent);
  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';
  }
  oContent.scrollIntoView(false);
  articleContent.innerHTML = data;
  roundedStyle(articleContent);
  roundedStyle(articleContent, true);
  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){
    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 = ImagePath+"/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("+ImagePath+"/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("+ImagePath+"/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("+ImagePath+"/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:"#fff", 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("+ImagePath+"/screen.png)"});
  var loadingImg = Element("IMG", {left:Math.round(parseInt(imgWrap.style.width)/2)+"px", top:Math.round(parseInt(imgWrap.style.height)/2)+"px", 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="'+ImagePath+'/info2.png" width="21" height="14" alt="info" />';
  if(loadingImg.complete) { imgPop.src = path; };
  if(imgPop.complete){
   imgPop.style.display = imgCaption.style.display = "block";
   loadingImg.style.display = "none";
   if(expand) expand.style.display = "block";
  };
  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($2, d, $1);
  }
 }
 return null;
};

function Element(tag, prop, parent, append){
 var el = d.createElement(tag.split(/[#\.]/)[0]);
 var es = el.style;
 es.position = "absolute";
 es.left = es.top = es.padding = es.margin = 0;
 es.width = el.offsetWidth || "auto" || 0;
 es.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) es[i] = prop[i];
 if(append){
  if(parent) parent.appendChild(el); else d.body.appendChild(el);
 }
 return el;
}

function setXY(ob, x, y){
 if(!ob) return;
 if(x != null) ob.style.left = parseInt(x) + "px";
 if(y != null) ob.style.top = parseInt(y) + "px";
}

function setWH(ob, w, h){
 if(!ob) return;
 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);
 }
}

function backgroundRGB(ob){
 if(ob.currentStyle){
  var bg = ob.currentStyle.backgroundColor;
 } else if(window.getComputedStyle){
  var bg = window.getComputedStyle(ob, null).getPropertyValue('background-color');
 } else { var bg = ob.style.backgroundColor; }
 bg = (bg==''||bg=='transparent'||bg=='inherit') ? "rgb(246, 245, 247)" : bg;
 if(bg.toLowerCase().match(/#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/)){
  return [ Number(hex2dec(RegExp.$1)), Number(hex2dec(RegExp.$2)), Number(hex2dec(RegExp.$3)) ];
 }
 if(bg.toLowerCase().match(/rgb\((\d+?), (\d+?), (\d+?)\)/)){
  return [ Number(RegExp.$1), Number(RegExp.$2), Number(RegExp.$3) ];
 }
 return [ Number(246), Number(245), Number(247) ];
}

function dec2hex(d){ return (d < 16) ? ("0" + Number(d).toString(16)) : Number(d).toString(16);}
function hex2dec(h){ return Number(parseInt(h, 16));}

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(d);
 roundedStyle(d, true);
 if(lt7) setTimeout("initCSSHover()", 500);
 if(moz) setTimeout("hackFirefoxToolTip()", 250);
}

