
Event.observe(window, 'load', onLoad_He, false);

// String オブジェクト拡張（フラグメント識別子トル）
String.prototype.removeFlagment = function(){
  return this.replace(/#.+?$/,'');
};

function onLoad_He() {
  showHtml_He();
  addScript_He();
}

function addScript_He() {
  var msec = (new Date()).getTime();
  var script = document.createElement('script'); 
  script.id = 'http://dtp-bbs.com/cgi-bin/he/view.cgi?url='
            + cleaningURL_He(document.location)
            + '&cache=' + msec ;

  script.charset = 'UTF-8';
  script.src     = script.id; 
  document.lastChild.appendChild(script);
}

function changeHe(json) {
  showHeValue_He((json == null)?0:json.value);
}

function showHtml_He(){
  var objElement = document.createElement('span'); 
  objElement.innerHTML=''
  + 'このページは&nbsp;<span id="he"></span>&nbsp;です。このエントリーが役に立ったら★をクリック！'
  + '    <form method="get" name="ajaxform" action="http://dtp-bbs.com/cgi-bin/he/setiframe.cgi" id="">'
  + '      <input type="hidden" name="url" id="url" value="' + cleaningURL_He(document.location) + '" />'
  + '      <input type="hidden" name="value" id="value" value="" />'
  + '      <button type="button" onclick="setHe_He(1);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-01.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(2);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-02.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(3);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-03.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(4);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-04.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(5);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-05.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(6);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-06.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(7);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-07.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(8);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-08.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(9);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-09.gif" width="32" height="32" /></button>'
  + '      <button type="button" onclick="setHe_He(10);"><img src="http://blog.ddc.co.jp/img/icon/images/star-32x32-10.gif" width="32" height="32" /></button>'
  + '    </form>'
  + '';
  var scripts = document.getElementsByTagName('script');
  var objScript = scripts[ scripts.length - 1 ];
  for (var i = 0; i < scripts.length; i++) {
    if ( (scripts[i].getAttribute('src') ) &&
         (scripts[i].getAttribute('src').match(/he.js$/) ) ){
      objScript = scripts[i]
    }
  }
  objScript.parentNode.insertBefore(objElement, objScript);
}


function showHeValue_He(f){
  var fspan = f ;

  if ( f >= 10 ) {
    fspan = '<span style="font-size:125%;">' + f +'</span>';
  }
  if ( f >= 30 ) {
    fspan = '<span style="font-size:150%;">' + f +'</span>';
  }
  if ( f >= 50 ) {
    fspan = '<span style="font-size:175%;color:red;">' + f +'</span>';
  }
  if ( f >= 100 ) {
    fspan = '<span style="font-size:200%;color:red;font-weight:bold;">' + f +'</span>';
  }
  if ( f >= 200 ) {
    fspan = '<span style="font-size:300%;color:red;font-weight:bold;">' + f +'</span>';
  }


  var fpoints = '<img src="http://blog.ddc.co.jp/img/icon/famfamfam/star.gif" width="16" height="16" alt="GoodStar">&nbsp;' + fspan + '&nbsp;point';

  if ( f != 1 ) {
    fpoints = fpoints + 's';
  }


  if ($('he')) {
  Element.update( $('he'), fpoints);
  }

  if ($('hepoints1')) {
  Element.update( $('hepoints1'), fpoints);
  }

  if ($('hepoints2')) {
  Element.update( $('hepoints2'), fpoints);
  }

}


function setHe_He(f) {
  $('value').value = f;
  var url = "http://dtp-bbs.com/cgi-bin/he/set.cgi?url="+cleaningURL_He(document.location)+"&value="+f;
  new Ajax.Request(url, { method: "get", onComplete: addScript_He } );
}

function cleaningURL_He(f) {
  return f.toString().removeFlagment();
}
