// HTML 로 넘어온 <img ... > 태그의 폭이 테이블폭보다 크다면 테이블폭을 적용한다.
function image_auto_resize(this_s,width,height){
 var ta_image = new Image();
 ta_image.src = this_s.src;
  if(!width){this_s.removeAttribute('width');
  this_s.style.width='auto';}
  else if(width < ta_image.width){
  this_s.width = width;
  }else{
  this_s.width = ta_image.width;
  }
  if(!height){this_s.removeAttribute('height');
  this_s.style.height='auto';}
  else if(height < ta_image.height){
  this_s.height = height;
  }else{
  this_s.height = ta_image.height;
  }
}

function image_auto_resize_inarea(this_s,width,height,view){
//this_s안의 모든 이미지는 자동 리사이즈 된다.
 //alert(this_s.childNodes.length);
 if(!view){view=true;}
 if(!this_s){return;}
 if(this_s.nodeType!=1){return;}
 for(var i=0,m=this_s.childNodes.length;i<m;i++){
  var ta = this_s.childNodes[i];
 
  if(ta.nodeName=='IMG'){
  //ta.style.border='1px solid #333333'; 
  image_auto_resize(ta,width,height);

  if(view){
    if(!ta.title){ta.title=ta.src;}
    if(!ta.onclick){
    ta.style.cursor='pointer';
    ta.onclick=function(){js_image_view(this,1);}
    }
    if(!ta.onload)
    ta.onload=function(){image_auto_resize(this,width,height);}
    if(!ta.onmouseover) 
    ta.onmouseover=function(){image_auto_resize(this,width,height);}
  }
  }
  if(ta.childNodes.length>0){
  image_auto_resize_inarea(ta,width,height);
  }
 }
 return;

}
function getFontSize() {
    var fontSize = parseInt(get_cookie("ck_fontsize")); // 폰트크기 조절
    if (isNaN(fontSize)) { fontSize = 12; }
    return fontSize;
}

function scaleFont(val) {
    var fontSize = getFontSize();
    var fontSizeSave = fontSize;
    if (val > 0) {
        if (fontSize <= 18) {
            fontSize = fontSize + val; 
        }
    } else {
        if (fontSize > 12) {
            fontSize = fontSize + val; 
        }
    }
    if (fontSize != fontSizeSave) {
        drawFont(fontSize);
    }
    set_cookie("ck_fontsize", fontSize, 30, g4_cookie_domain); 
}

function drawFont(fontSize) {
    if (!fontSize) {
        fontSize = getFontSize();
    }

    var subject=document.getElementById("writeSubject"); 
    var content=document.getElementById("writeContents"); 
    var comment=document.getElementById("commentContents");
    var wr_subject=document.getElementById("wr_subject");
    var wr_content=document.getElementById("wr_content");

    if (comment) {
        var commentDiv = comment.getElementsByTagName("div");
        var lineHeight = fontSize+Math.round(1.1*fontSize); 
    }

    fontSize = fontSize + "px";

    if (subject)
        subject.style.fontSize=fontSize;
    if (content)
        content.style.fontSize=fontSize; 
    if (wr_subject)
        wr_subject.style.fontSize=fontSize; 
    if (wr_content)
        wr_content.style.fontSize=fontSize; 
    if (commentDiv) {
        for (i=0;i<commentDiv.length;i++) {
            commentDiv[i].style.fontSize=fontSize;
        }
    }
}
