var ajaxObj = new XMLHTTP("ajax/mybic_server.php");
ajaxObj.debug=0;

function listBlog(){
  ajaxObj.call('action=list_blog_months', respListBlog);  
}

function respListBlog(resp){
  var oDiv = document.getElementById('month_arch');
  var str = "";
  if(resp){
    str = "<table width='115px' height='315px'>";
    for(var i=1;i<13;i++){
      str += "<tr><td style='height: 24px; border-bottom: solid 1px #000000'>";
      str += "<a class='list' href='javascript:getBlogMonth(" + i + ");'>";
      str += resp[i].name + " (" + resp[i].size + ")";    
      str += "</a></trd</tr>";
    }  
    str += "</table>";
  }
  oDiv.innerHTML = str;
}

function listRecent(){
  ajaxObj.call('action=list_blog_recent', respListRecent);  
}

function respListRecent(resp){
  var oDiv = document.getElementById('recent');
  var str = "";
  if(!resp.title){return;}
  if(resp){
    str = "<table width='115px' height='115px'>";
    for(var i=0;i<5;i++){
      
      if(i == 4){
        str += "<tr><td>";      
      }else{
        str += "<tr><td style='border-bottom: solid 1px #000000'>";
      }
    
      if(resp.title.length > i || resp.title.length == 0 ){
        str += "<a class='list' href='javascript:getBlog(" + resp.id[i] + ");'>";
        str += resp.title[i];
        str += "</a>";    
      }else{
        str += "<span class='list'>";
        str += "&nbsp;";
        str += "</span>";
      }
      str += "</trd</tr>";
    }  
    str += "</table>";
  }
  oDiv.innerHTML = str;
}

function getLastBlog(){
  ajaxObj.call('action=get_last_blog', respGetLastBlog);   
}

function respGetLastBlog(resp){
  var oBody = document.getElementById('main_view');
  
  if(resp){
    if(resp.body){
      oBody.innerHTML = resp.body;
    }
  }
}

function getBlog(s){
  ajaxObj.call('action=get_blog&id='+s, respGetBlog);   
}

function respGetBlog(resp){
  var oBody = document.getElementById('main_view');
  
  if(resp){
    oBody.innerHTML = resp.body;
  }

}

function getBlogMonth(m){
  ajaxObj.call('action=get_blog_month&mnth='+m, respGetBlogMonth);   
}

function respGetBlogMonth(resp){
  var oBody = document.getElementById('main_view');
  
  if(resp){
    oBody.innerHTML = resp.body;
  }

}