/* script.js document.forms[0].s.value = cate;*/



function blogCategorys(){
  if(!getObject('tree') || !location.href.match(/.*?\/blog\/category\//)) return false;
  var title = document.title;
  var li = getElement('tree','li');
  for(var i=0;i<li.length;i++){
    var a = li[i].getElementsByTagName('a');
    if(!a.length || !a[0].getAttribute('href').match(/^.*?\/blog\/category\/.*$/)) continue;
    var cate = a[0].innerHTML;
    var reg = new RegExp('^' + cate + '\uFF5C','i');
    if(title.match(reg)){
      if(navigator.userAgent.toLowerCase().indexOf('msie') != -1 && !window.opera) a[0].setAttribute('className','here');
      else a[0].setAttribute('class','here');
    }
  }
  if(!getObject('categories')) return false;
  var title = document.title;
  var li = getElement('categories','li');
  for(var i=0;i<li.length;i++){
    var a = li[i].getElementsByTagName('a');
    if(!a.length || !a[0].getAttribute('href').match(/^.*?\/blog\/category\/.*$/)) continue;
    var cate = a[0].innerHTML;
    var reg = new RegExp('^' + cate + '\uFF5C','i');
    if(title.match(reg)){
      if(navigator.userAgent.toLowerCase().indexOf('msie') != -1 && !window.opera) a[0].setAttribute('className','here');
      else a[0].setAttribute('class','here');
    }
  }
}

function blogEntrys(){
  if(!getObject('reEntry')) return false;
  var title = document.title;
  var li = getElement('reEntry','li');
  for(var i=0;i<li.length;i++){
    var a = li[i].getElementsByTagName('a');
    if(!a.length) continue;
    var entry = a[0].innerHTML;
    var reg = new RegExp('^' + entry + '\uFF5C','i');
    if(title.match(reg)){
      if(navigator.userAgent.toLowerCase().indexOf('msie') != -1 && !window.opera) a[0].setAttribute('className','here');
      else a[0].setAttribute('class','here');
    }
  }
}

function blogTags(){
  if(!getObject('recomTags') || !location.href.match(/.*?\/blog\/tag\//)) return false;
  var title = document.title;
  var li = getElement('recomTags','li');
  for(var i=0;i<li.length;i++){
    var a = li[i].getElementsByTagName('a');
    if(!a.length) continue;
    var entry = a[0].innerHTML;
    var reg = new RegExp('^' + entry + '\uFF5C','i');
    if(title.match(reg)){
      if(navigator.userAgent.toLowerCase().indexOf('msie') != -1 && !window.opera) a[0].setAttribute('className','here');
      else a[0].setAttribute('class','here');
    }
  }
}


function setTextareaHeight(){
  var range = 76;
  var textarea = getElement('','textarea');
  if(!textarea.length) return false;
  for(var i=0;i<textarea.length;i++){
    var line = textarea[i].value.replace(/\t/g,'').replace(/\r\n/g,'\n').replace(/\r/g,'\n').split('\n');
    var len = line.length + 1;
    for(var j=0;j<line.length;j++){
      var bytes = line[j].length;
      for(var k=0;k<line[j].length;k++){
        var str = line[j].charCodeAt(k);
        if(str >= 256 && (str < 0xff61 || str > 0xff9f)) bytes += 1;
      }
      if(bytes >= range) len += Math.floor(bytes / range);
    }
    textarea[i].style.height = (len <= 8)? '120px': String(len * 16) + 'px';
  }
  setTimeout('setTextareaHeight()',100);
}


function setCatch(){
  var title = document.title;
  if(title.match(/LED/i)){
    var html = '<a href="/shop/volxjapan/Grassy-LeDio-7" style="width:600px;height:250px;"><img src="/shop/item/volxjapan/catch-LeDio7.jpg" width="600" height="250" alt="" /></a>';
    document.getElementById('blog-top-catch').innerHTML = html;
  }
}


function initProfileImage(){
  var obj = document.getElementById('profile');
  if(!obj) return false;
  var p = obj.getElementsByTagName('p')[0];
  var small = document.createElement('small');
  small.setAttribute('id','profile-image-num');
  p.appendChild(small);
  p.onclick = setProfileImage;
  setProfileImage();
}

function setProfileImage(){
  var pro = document.getElementById('profile');
  var obj = pro.getElementsByTagName('img')[0];
  var img = obj.getAttribute('src');
  pro.getElementsByTagName('p')[0].style.backgroundImage = 'url(' + img + ')';
  var num = Number(img.replace(/^.*?0?(\d+)\.jpg$/,'$1'));
//  document.getElementById('profile-image-num').innerHTML = num + '.';
  num++;
  num = (num > 12)? '01': (num < 10)? '0' + num: String(num);
  obj.setAttribute('src',img.replace(/^(.+?)\d+(\.jpg)$/,'$1' + num + '$2'));
}



setOnload(blogCategorys);

setOnload(blogEntrys);

setOnload(blogTags);

//setOnload(setCatch);

setOnload(setTextareaHeight);

setOnload(initProfileImage);

