if (board_seq=="")
{
	board_seq="1";
}

var totalpage;
var board_info;
var contentData;
var contentSubData;		
var contentViewData;	
var commentList;
var seq;
var board_seq_status;
var totalpage;
var nowpage;

var main_Div=document.getElementById("cctank");

function initialize() {

   //page setting
   if (getParameter("page")==""){
   	nowpage="1";
   }else{
   	nowpage=getParameter("page");
   }
   
   dhtmlHistory.initialize();
   // subscribe to DHTML history change
   // events
   dhtmlHistory.addListener(historyChange);

	// if this is the first time we have
	// loaded the page...
	if (dhtmlHistory.isFirstLoad()) {
	   // start adding history
	   dhtmlHistory.add("list", "s");
	}

	seq = getParameter("seq");

	fnInit();
}
//Page Initialize and CallBack function S//
//Receive data for viewing List Page
function fnInit(){

	var request = new Ajax.Request('/cctankboard/getInfo.asp',
		{
		method:'get',
		parameters:'board_seq='+board_seq+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxSuccessHandle,
		onFailure:function(){alert('Something went wrong')}
		});
}

/** Our callback to receive history 
    change events. */
function historyChange(newLocation, historyData) {
   var historyMsg = historyData;

   if (newLocation == "list") {
	  fnShowList();
   } else if (newLocation=="view"){
	if (historyData){
		var request = new Ajax.Request('/cctankboard/getViewData.asp',
		{
			method:'get',
			parameters:'seq='+historyData+'&dummy='+new Date().getTime(),
			onSuccess:fnAjaxViewHandle,
			onFailure:function(){
				alert('Something went wrong:historyChange')
				}
		});
	}else{
		history.go(-1);
	}
   }else{
   	history.go(-1);
   }
}

function getParameter(key)
{

    var url = location.href;
    var spoint = url.indexOf("?");
    var query = url.substring(spoint,url.length);
    var keys = new Array;
    var values = new Array;
    var nextStartPoint = 0;

    while(query.indexOf("&",(nextStartPoint+1) ) >-1 ){
        var item = query.substring(nextStartPoint, query.indexOf("&",(nextStartPoint+1) ) );
        var p = item.indexOf("=");
        keys[keys.length] = item.substring(1,p);
        values[values.length] = item.substring(p+1,item.length);
        nextStartPoint = query.indexOf("&", (nextStartPoint+1) );
  
    }

    item = query.substring(nextStartPoint, query.length);
    p = item.indexOf("=");

    keys[keys.length] = item.substring(1,p);
    
 values[values.length] = item.substring(p+1,item.length);

 var value = "";
    for(var i=0; i<keys.length; i++){
        if(keys[i]==key){
            value = values[i];
        }
    }
    return value;
}

//Ajax callback function for receiving List data
function fnAjaxSuccessHandle(request){
	board_info = eval("(" + request.responseText + ")");
	//alert(request.responseText);
	var request = new Ajax.Request('/cctankboard/getList_new.asp',
		{
		method:'get',
		parameters:'board_seq='+board_seq
			+'&listview=' + board_info.info[0].listview
			+'&nowpage=' + nowpage+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxListSuccessHandle,
		onFailure:fnAjaxListFailureHandle
		});
}

function fnAjaxListSuccessHandle(request){
	contentData=eval("(" + request.responseText + ")");
	totalpage=contentData.pageinfo[0].totalpage;
	nowpage=contentData.pageinfo[0].nowpage;
	if (seq!="")
	{
		//seq 파라미터가 있을경우
		var request = new Ajax.Request('/cctankboard/getViewData.asp',
		{
		method:'get',
		parameters:'seq='+seq+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxViewHandle,
		onFailure:function(){
			alert('Something went wrong')
			}
		});	
		seq="";
	}else{
		fnShowList();
	}

}

function fnAjaxListFailureHandle(request){
	alert(request.responseText);	
}
//Page Initialize and CallBack Function E//


//Create Writing form------------------------------------------------------------------------

function fnShowWriteForm(){
  clearForm();
  var ourDiv=document.getElementById('cctank');
  var t=document.createElement('table');
  t.setAttribute("id","cctank_write");
  t.className="cctank_table";
  var tb=document.createElement('tbody');
   
  var tr1=fnAddTrInput("제 목","txtSubject","text",40,"cctank_write_head");
  tb.appendChild(tr1);

  var tr2=fnAddTrInput("작성자","txtName","text",20,"cctank_write_head");
  tb.appendChild(tr2);
  
  var tr2_1=fnAddTrInput("e-mail","txtEmail","text",20,"cctank_write_head");
  tb.appendChild(tr2_1);
  
  var tr3=fnAddTrInput("비밀번호","txtPasswd","password",20,"cctank_write_head");
  tb.appendChild(tr3);  

  var tr3_1=fnAddTrCheck("비밀글","security","cctank_write_head");
  tb.appendChild(tr3_1);
  

  var tr4=fnAddTrIfr("첨부파일","cctank_write_head");
  tb.appendChild(tr4);
    
  var tr5=fnAddTrTextArea("내 용","txtContent",40,70,"cctank_write_head");
  tb.appendChild(tr5);
  
  t.appendChild(tb);
 
 //create Button
  var divBtn = document.createElement("div");
  divBtn.setAttribute("id","divBtn");
  
  var wbtn = document.createElement("img");
  wbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_ok.gif");
  wbtn.onmouseover=function(){this.style.cursor='hand';}
  wbtn.onclick=fnSendWriteForm;

  var cbtn = document.createElement("img");
  cbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_canc.gif");
  cbtn.onmouseover=function(){this.style.cursor='hand';}
  cbtn.onclick=fnShowList; 
  
  divBtn.appendChild(wbtn);
  divBtn.appendChild(cbtn);

  var form1=document.createElement("form");
  
  form1.appendChild(t);    
  form1.appendChild(divBtn);
  ourDiv.appendChild(form1);

  fnSetEditor("txtContent");  
}

//Send data for writng
function fnSendWriteForm(){
	var subject = document.getElementById("txtSubject").value;
	var name = document.getElementById("txtName").value;
	var pwd = document.getElementById("txtPasswd").value;
	var contents = GetContents("txtContent");
	var email = document.getElementById("txtEmail").value;

	var security = document.getElementById("security").checked;
	var sec_val;

	if(security){
		sec_val="Y";
	}else{
		sec_val="N";
	}
	
	if (subject=="")
	{
		alert("제목을 입력바랍니다.");
		return false;
	}

	if (name=="")
	{
		alert("이름을 입력바랍니다.");
		return false;
	}
	var request = new Ajax.Request('/cctankboard/writeContent.asp',
		{
		method:'post',
		contentType:'application/x-www-form-urlencoded',
		encoding:'utf-8',
		
		parameters:'board_seq='+encodeURIComponent(board_seq)
			+'&subject='+encodeURIComponent(subject)
			+'&writer='+encodeURIComponent(name)
			+'&pwd=' +encodeURIComponent(pwd)
			+'&contents='+encodeURIComponent(contents)
			+'&email='+email
			+'&sec='+sec_val,
		onSuccess:fnAjaxWriteSuccessHandle,
		onFailure:fnAjaxWriteFailureHandle
		});	
}

function fnAjaxWriteSuccessHandle(request){
	var data = eval("("+request.responseText+")");
	//alert(data.result[0].sql);
	cctank_ifr.cctank_uploader.seq.value=data.result[0].seq;
	cctank_ifr.cctank_uploader.submit();
}

function fnIframeUploadSuccessHandle(){
	fnInit();
}

function fnAjaxWriteFailureHandle(request){
	//alert(request.responseText);
}

//Create Reply form------------------------------------------------------------

function fnShowReplyForm(){
  clearForm();
  var ourDiv=document.getElementById('cctank');
  var t=document.createElement('table');
  t.setAttribute("id","cctank_reply");
  t.className="cctank_table";
  var tb=document.createElement('tbody');
  
  var tr1=fnAddTrInput("제 목","txtSubject","text",40,"cctank_reply_head");
  tb.appendChild(tr1);

  var tr2=fnAddTrInput("작성자","txtName","text",20,"cctank_reply_head");
  tb.appendChild(tr2);
  
  var tr2_1=fnAddTrInput("E-mail","txtEmail","text",20,"cctank_reply_head");
  tb.appendChild(tr2_1);
  
  var tr3=fnAddTrInput("비밀번호","txtPasswd","password",20,"cctank_reply_head");
  tb.appendChild(tr3);  
  
  var tr3_1=fnAddTrCheck("비밀글","security","cctank_reply_head");
  tb.appendChild(tr3_1);

  var tr4=fnAddTrIfr("첨부파일","cctank_reply_head");
  tb.appendChild(tr4);
    
  var tr5=fnAddTrTextArea("내 용","txtContent",20,70,"cctank_reply_head");
  tb.appendChild(tr5);
  
  t.appendChild(tb);


 //create Button
  var divBtn = document.createElement("div");
  divBtn.setAttribute("id","divBtn");
  
  var wbtn = document.createElement("img");
  wbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_ok.gif");
  wbtn.onmouseover=function(){this.style.cursor='hand';}
  wbtn.onclick=fnSendReplyForm;

  var cbtn = document.createElement("img");
  cbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_canc.gif");
  cbtn.onmouseover=function(){this.style.cursor='hand';}
  cbtn.onclick=fnShowList; 
  
  divBtn.appendChild(wbtn);
  divBtn.appendChild(cbtn);

  var form1=document.createElement("form");
  
  form1.appendChild(t);    
  form1.appendChild(divBtn);
  ourDiv.appendChild(form1);

//reply original message
  document.getElementById("txtContent").value="<br><br><br>--------------------------원문글-------------------------<br>"+decodeURIComponent(contentViewData.board[0].contents);

  fnSetEditor("txtContent");  

//automaically fill subject
  document.getElementById("txtSubject").value="[re] " + contentViewData.board[0].subject;

}

//Send data for reply
function fnSendReplyForm(){
	var subject = document.getElementById("txtSubject").value;
	var name = document.getElementById("txtName").value;
	var pwd = document.getElementById("txtPasswd").value;
	var contents = GetContents("txtContent");
	var email = document.getElementById("txtEmail").value;
	var security = document.getElementById("security").checked;
	var sec_val;

	if (security)
	{
		sec_val="Y";
	}else{
		sec_val="N";
	}

	var depth = 0;
	depth = parseInt(contentViewData.board[0].depth)+1;

	if (subject=="")
	{
		alert("제목을 입력바랍니다.");
		return false;
	}

	if (name=="")
	{
		alert("이름을 입력바랍니다.");
		return false;
	}

	var request = new Ajax.Request('/cctankboard/writeContent.asp',
		{
		method:'post',
		contentType:'application/x-www-form-urlencoded',
		encoding:'utf-8',
		
		parameters:'board_seq='+encodeURIComponent(board_seq_status)
			+'&subject='+encodeURIComponent(subject)
			+'&writer='+encodeURIComponent(name)
			+'&pwd=' +encodeURIComponent(pwd)
			+'&sec=' +sec_val
			+'&email=' +email
			+'&contents='+encodeURIComponent(contents)
			+'&depth='+encodeURIComponent(depth)
			+'&parent_seq='+encodeURIComponent(contentViewData.board[0].seq),
		onSuccess:fnAjaxReplySuccessHandle,
		onFailure:fnAjaxReplyFailureHandle
		});	
}

function fnAjaxReplySuccessHandle(request){
	var data = eval("("+request.responseText+")");
	fnScroll();
	cctank_ifr.cctank_uploader.seq.value=data.result[0].seq;
	cctank_ifr.cctank_uploader.submit();

}

function fnAjaxReplyFailureHandle(request){
	alert("fail:"+request.responseText);
}
//------------------------------------------------------------------------------------------
/*
function fnAjaxViewHandle(request){

  var auth=false;
  var passwd;

  contentViewData=eval("("+request.responseText+")")
  
  if (contentViewData.board[0].security=="Y")
  {
		alert("선택하신 글은 비밀글입니다. 비밀번호 확인 후 열람 가능합니다.");
		passwd = prompt("비밀번호를 입력바랍니다.","");
		if (passwd==contentViewData.board[0].passwd)
		{
			auth=true;
		}else{
			auth=false;
		}

  }else{
	auth=true;
  }
  
  if(auth){
	  
	  board_seq_status=contentViewData.board[0].board_seq;
	  //alert(contentViewData.board[0].board_seq);
	  fnShowView();
  }else{
	alert("해당글을 읽을 수 없습니다.");
  }
}
*/
function fnAjaxViewHandle(request){

  var auth=false;
  var passwd;

  contentViewData=eval("("+request.responseText+")")
  
  if (contentViewData.board[0].security=="Y")
  {
		alert("선택하신 글은 비밀글입니다. 비밀번호 확인 후 열람 가능합니다.");

		var settings = "width=262,height=180,top=300,left=300,location=no,toolbar=no,menubar=no,directories=no,status=no,scrollbars=no,scrollable=no,resizable=no";
		window.open("/cctankboard/passwd.asp?mode=security", "pwdcheck", settings);

  }else{
	  board_seq_status=contentViewData.board[0].board_seq;
	  fnShowView();
  }
}


function fnCallbackPasswdForSecurity(pwdchk){
	if (pwdchk==contentViewData.board[0].passwd)
	{
		board_seq_status=contentViewData.board[0].board_seq;
		fnShowView()
	}else{
		alert("해당글을 읽을 수 없습니다.");
	}		
}

function fnShowView(){
	  clearForm();
	  
	  var ourDiv=document.getElementById('cctank');

	  var t=document.createElement('table');
	  t.setAttribute("id","cctank_view");

	  t.className="cctank_table";
	  var tb=document.createElement('tbody');
	  
	  var tr1=fnAddTrText("제 목",contentViewData.board[0].subject,"view_subject","cctank_view_head");
	  tb.appendChild(tr1);

	  var tr2=fnAddTrText("작성자",contentViewData.board[0].writer,"view_name","cctank_view_head");
	  tb.appendChild(tr2);

	  var tr2_1=fnAddTrText("E-mail",contentViewData.board[0].email,"view_email","cctank_view_head");
	  tb.appendChild(tr2_1);

	  var tr30=fnAddTrFile("첨부파일1",contentViewData.board[0].fileName1,"view_file","cctank_view_head");
	  tb.appendChild(tr30);

	  var tr31=fnAddTrFile("첨부파일2",contentViewData.board[0].fileName2,"view_file","cctank_view_head");
	  tb.appendChild(tr31);

	  var tr32=fnAddTrFile("첨부파일3",contentViewData.board[0].fileName3,"view_file","cctank_view_head");
	  tb.appendChild(tr32);    

	  var tr4=fnAddTrText("작성일",contentViewData.board[0].wdate,"view_date","cctank_view_head");
	  tb.appendChild(tr4);
	  
	  var tr4_1 = fnAddTrImage("이미지",contentViewData.board[0].fileName1);
	  if(tr4_1){
		  tb.appendChild(tr4_1);
	  }

	  var tr4_2 = fnAddTrImage("이미지",contentViewData.board[0].fileName2);
	  if(tr4_2){
		  tb.appendChild(tr4_2);
	  }
	  
	  var tr4_3 = fnAddTrImage("이미지",contentViewData.board[0].fileName3);
	  if(tr4_3){
		  tb.appendChild(tr4_3);
	  }
	  
	  var tr5=fnAddTrHTML("내 용",contentViewData.board[0].contents,"view_contents","cctank_view_head");
	  tb.appendChild(tr5);
	  
	  t.appendChild(tb);


	  var divBtn = document.createElement("div");
	  divBtn.setAttribute("id","divBtn");
	  
	  var wbtn = document.createElement("img");
	  wbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_write.gif");
	  wbtn.onmouseover=function(){this.style.cursor='hand';}
	  wbtn.onclick=fnShowWriteForm;
	  
	  var rbtn = document.createElement("img");
	  rbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_reply.gif");
	  rbtn.onmouseover=function(){this.style.cursor='hand';}
	  rbtn.onclick=fnShowReplyForm;

	  var mbtn = document.createElement("img");
	  mbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_edit.gif");
	  mbtn.onmouseover=function(){this.style.cursor='hand';}
	  mbtn.onclick=function(){
		var request = new Ajax.Request('/cctankboard/modifyContent.asp',
			{
			method:'post',
			contentType:'application/x-www-form-urlencoded',
			encoding:'utf-8',
			
			parameters:'seq='+encodeURIComponent(contentViewData.board[0].seq),
			onSuccess:fnAjaxModifySuccessHandle
			});
	  };  
	  
	  var dbtn = document.createElement("img");
	  dbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_dele.gif");
	  dbtn.onmouseover=function(){this.style.cursor='hand';}
	  dbtn.onclick=function(){
		var conf=confirm('정말로 삭제하시겠습니까?');
		if (conf)
		{
			var request = new Ajax.Request('/cctankboard/deleteContent.asp',
				{
				method:'post',
				contentType:'application/x-www-form-urlencoded',
				encoding:'utf-8',
				
				parameters:'seq='+encodeURIComponent(contentViewData.board[0].seq),
				onSuccess:fnAjaxDeleteSuccessHandle
				});
		}
	  };   
	  
	  var lbtn = document.createElement("img");
	  lbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_list.gif");
	  lbtn.onmouseover=function(){this.style.cursor='hand';}
	  lbtn.onclick=function(){
		  dhtmlHistory.add("list","k");
		  fnInit();
		  //fnShowList(); 
	  }

	  var pbtn = document.createElement("img");
	  pbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_print.gif");
	  pbtn.onmouseover=function(){this.style.cursor='hand';}
	  pbtn.onclick=function(){
		  fnOpenPrint(contentViewData.board[0].seq);
	  }
		
	  if(board_info.info[0].auth_write=="Y"){
		  divBtn.appendChild(wbtn);
		  divBtn.appendChild(rbtn);
		  divBtn.appendChild(mbtn);
		  divBtn.appendChild(dbtn);
	  }  
	  divBtn.appendChild(lbtn);
	  divBtn.appendChild(pbtn);
	  
	  var br = document.createElement("br");
	  
	  ourDiv.appendChild(t);
	  ourDiv.appendChild(divBtn); 	
	  ourDiv.appendChild(br); 	

	  //comment list View
	  fnViewComment(contentViewData.board[0].seq);	

}

function fnOpenPrint(arg){
	window.open("/cctankboard/print.asp?seq=" + arg, '_blank', 'width=800, height=600, scrollbars=yes');	
}

function fnViewComment(seq){
  var request = new Ajax.Request('/cctankboard/getCommentList.asp',
  {
  method:'get',
  parameters:'seq='+seq
	+'&dummy='+new Date().getTime(),
  onSuccess:fnAjaxCommentList,
  onFailure:function(){alert('Something went wrong1')}
  });
}

function fnAjaxCommentList(request){
  	commentList = eval("(" + request.responseText + ")");

  	fnShowCommentList();
}

function fnShowCommentList(){
  var ourDiv=document.getElementById('cctank');
  var t=document.createElement('table');
  t.setAttribute("id","cctank_view");
  t.className="cctank_table";
  
  var tb=document.createElement('tbody');
  tb.setAttribute("id","cctank_listbody");

  for(i=0;i<commentList.comments.length-1;i++){
 	fnTrToTbForComment(tb,i,commentList);
  }

  t.appendChild(tb);
  ourDiv.appendChild(t);
  
  fnShowWriteComment();
};

function fnShowWriteComment(){

  var ourDiv=document.getElementById('cctank');

  var t=document.createElement('table');
  t.setAttribute("id","cctank_write");
  t.className="cctank_table";
  var tb=document.createElement('tbody');
  
  if(cc_name==""){	
	  var tr=document.createElement('tr');
	  var td=document.createElement('td');
	  td.rowSpan=2;
	  
	  var newTextarea=document.createElement("textarea");
	  newTextarea.setAttribute("rows","3");
	  newTextarea.setAttribute("cols","45");
	  newTextarea.setAttribute("id","txtComment");
	  newTextarea.setAttribute("name","txtComment");
	  newTextarea.value="댓글을 달아주세요.";
	  newTextarea.onfocus=function(){this.value=""};

	  td.appendChild(newTextarea);

	  tr.appendChild(td);	
	  
	  td=document.createElement('td');

	  var tdText = document.createTextNode("작성자 ");
	  
	  td.appendChild(tdText);
	  tr.appendChild(td);
	  
	  td=document.createElement('td');  

	  var newInput=document.createElement("input");
	  newInput.setAttribute("type","text");
	  newInput.setAttribute("size","9");
	  newInput.setAttribute("id","txtWriter");

	  td.appendChild(newInput);
	  tr.appendChild(td);
	  tb.appendChild(tr);
	  
	  tr=document.createElement("tr");
	  td=document.createElement("td");
	  tdText = document.createTextNode("비밀번호 ");
	  td.appendChild(tdText);
	  tr.appendChild(td);  
	  
	  td =document.createElement("td");  
	  newInput=document.createElement("input");
	  newInput.setAttribute("type","password");
	  newInput.setAttribute("size","8");
	  newInput.setAttribute("id","txtPasswd");
		
	  td.appendChild(newInput);
		
	  tr.appendChild(td);
			
	  tb.appendChild(tr);
  }else{
	  var tr=document.createElement('tr');
	  var td=document.createElement('td');
  
	  var newTextarea=document.createElement("textarea");
	  newTextarea.setAttribute("rows","3");
	  newTextarea.setAttribute("cols","75");
	  newTextarea.setAttribute("id","txtComment");
	  newTextarea.setAttribute("name","txtComment");
	  newTextarea.value="댓글을 달아주세요.";
	  newTextarea.onfocus=function(){this.value=""};
	  td.appendChild(newTextarea);

	  var newInput=document.createElement("input");
	  newInput.setAttribute("type","hidden");
	  newInput.setAttribute("id","txtWriter");
      newInput.setAttribute("value",cc_name);  	
		
	  td.appendChild(newInput);

	  newInput=document.createElement("input");
	  newInput.setAttribute("type","hidden");
	  newInput.setAttribute("id","txtPasswd");
      newInput.setAttribute("value",cc_pwd);
		
	  td.appendChild(newInput);
		
	  tr.appendChild(td);
			
	  tb.appendChild(tr);
  }


  t.appendChild(tb);


 //create Button
  var divBtn = document.createElement("div");
  divBtn.setAttribute("id","divBtn");
  
  var wbtn = document.createElement("img");
  wbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_ok.gif");
  wbtn.onmouseover=function(){this.style.cursor='hand';}
  wbtn.onclick=fnSendComment;

  divBtn.appendChild(wbtn);

  var form1=document.createElement("form");
  
  form1.appendChild(t);    
  form1.appendChild(divBtn);
  ourDiv.appendChild(form1);

}

function fnSendComment(){

	var writer = document.getElementById("txtWriter").value;
	var pwd = document.getElementById("txtPasswd").value;
	var comment = document.getElementById("txtComment").value;
	
	if (comment=="" || comment=="댓글을 달아주세요.")
	{
		alert("내용을 입력바랍니다.");
		return false;
	}

	if (writer=="")
	{
		alert("이름을 입력바랍니다.");
		return false;
	}
	var request = new Ajax.Request('/cctankboard/writeComment.asp',
		{
		method:'post',
		contentType:'application/x-www-form-urlencoded',
		encoding:'utf-8',
		
		parameters:'ref_seq='+contentViewData.board[0].seq
			+'&writer='+encodeURIComponent(writer)
			+'&pwd=' +encodeURIComponent(pwd)
			+'&comment='+encodeURIComponent(comment),
		onSuccess:fnAjaxCommentSuccessHandle,
		onFailure:fnAjaxCommentFailureHandle
		});	
}

function fnAjaxCommentSuccessHandle(request){
	var data = eval("("+request.responseText+")");

	fnShowView();
	//alert(data.result[0].sql);

}

function fnAjaxCommentFailureHandle(request){

}

//if it doesn't check password, this will be only this, 
//but if it check password, this will have callback function.
function fnAjaxModifySuccessHandle(request){
	var data = eval("("+request.responseText+")");
	
	if((data.result[0].message=="0")&&(data.result[0].inputview=="Y")){
			var settings = "width=262,height=180,top=300,left=300,location=no,toolbar=no,menubar=no,directories=no,status=no,scrollbars=no,scrollable=no,resizable=no";
			window.open("/cctankboard/passwd.asp?mode=modify", "pwdcheck", settings);
	}else if(data.result[0].message=="1"){		
		var con = confirm("수정하시겠습니까?");
		if(con){
			fnShowModifyForm();
		}
	}else{
		alert(modify_msg[data.result[0].message]);
	}
}

function fnCallbackPasswdForModify(pwdchk){

	var request = new Ajax.Request('/cctankboard/modifyContent.asp',
	{
	method:'post',
	contentType:'application/x-www-form-urlencoded',
	encoding:'utf-8',
		
	parameters:'seq='+encodeURIComponent(contentViewData.board[0].seq)
		  +'&pwd='+encodeURIComponent(pwdchk),
	onSuccess:fnAjaxModifySuccessHandle
	});	
	
}

function fnCallbackPasswdForDelete(pwdchk){

	var request = new Ajax.Request('/cctankboard/deleteContent.asp',
	{
	method:'post',
	contentType:'application/x-www-form-urlencoded',
	encoding:'utf-8',
		
	parameters:'seq='+encodeURIComponent(contentViewData.board[0].seq)
		  +'&pwd='+encodeURIComponent(pwdchk),
	onSuccess:fnAjaxDeleteSuccessHandle
	});	
	
}

var modify_msg=new Array(4);

modify_msg[1]="수정되었습니다.";
modify_msg[2]="글작성자만이 수정가능합니다.";
modify_msg[3]="비밀번호가 틀렸습니다.";

//---------------------------------------------------------------------------------------
function fnShowModifyForm(){
  
  clearForm();
  fnScroll();

  var ourDiv=document.getElementById('cctank');
  var t=document.createElement('table');
  t.setAttribute("id","cctank_modify");
  t.className="cctank_table";
  var tb=document.createElement('tbody');
      
  var tr1=fnAddTrInput("제 목","txtSubject","text",40,"cctank_modify_head");
  tb.appendChild(tr1);

  var tr2=fnAddTrInput("작성자","txtName","text",20,"cctank_modify_head");
  tb.appendChild(tr2);

  var tr2_1=fnAddTrInput("E-mail","txtEmail","text",20,"cctank_modify_head");
  tb.appendChild(tr2_1);
  
  var tr3=fnAddTrInput("비밀번호","txtPasswd","password",20,"cctank_modify_head");
  tb.appendChild(tr3);  
  
  var tr3_1=fnAddTrCheck("비밀글","security","cctank_modify_head");
  tb.appendChild(tr3_1);

  var tr4=fnAddTrIfrForModify("첨부파일","cctank_write_head",contentViewData.board[0].seq,contentViewData.board[0].fileName1,contentViewData.board[0].fileName2,contentViewData.board[0].fileName3);
  tb.appendChild(tr4);
      
		
  var tr5=fnAddTrTextAreaForModify("내 용","txtContent",20,70,"cctank_modify_head");
  tb.appendChild(tr5);
   
  t.appendChild(tb);
 
 //create Button
  var divBtn = document.createElement("div");
  divBtn.setAttribute("id","divBtn");
  
  var wbtn = document.createElement("img");
  wbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_ok.gif");
  wbtn.onmouseover=function(){this.style.cursor='hand';}
  wbtn.onclick=fnSendModifyForm;

  var cbtn = document.createElement("img");
  cbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_canc.gif");
  cbtn.onmouseover=function(){this.style.cursor='hand';}
  cbtn.onclick=fnShowList; 
  
  divBtn.appendChild(wbtn);
  divBtn.appendChild(cbtn);

  var form1=document.createElement("form");
  
  form1.appendChild(t);    
  form1.appendChild(divBtn);
  ourDiv.appendChild(form1);
  
  fnSetEditor("txtContent");  

  document.getElementById("txtSubject").value=contentViewData.board[0].subject;
  document.getElementById("txtName").value=contentViewData.board[0].writer;
  document.getElementById("txtPasswd").value=contentViewData.board[0].passwd;
  document.getElementById("txtEmail").value=contentViewData.board[0].email;

  if (contentViewData.board[0].security=="Y")
  {
	document.getElementById("security").checked=true;
  }else{
	document.getElementById("security").checked=false;
  }
 }

function fnSendModifyForm(){
	var subject = document.getElementById("txtSubject").value;
	var name = document.getElementById("txtName").value;
	var pwd = document.getElementById("txtPasswd").value;
	var contents = GetContents("txtContent");
	var email = document.getElementById("txtEmail").value;
	var security = document.getElementById("security").checked;
	var sec_val;
	if (security)
	{
		sec_val="Y";
	}else{
		sec_val="N";
	}

	if (subject=="")
	{
		alert("제목을 입력바랍니다.");
		return false;
	}

	if (name=="")
	{
		alert("이름을 입력바랍니다.");
		return false;
	}
	var request = new Ajax.Request('/cctankboard/modifyContentPrc.asp',
		{
		method:'post',
		contentType:'application/x-www-form-urlencoded',
		encoding:'utf-8',

		parameters:'seq='+encodeURIComponent(contentViewData.board[0].seq)
			+'&subject='+encodeURIComponent(subject)
			+'&writer='+encodeURIComponent(name)
			+'&pwd=' +encodeURIComponent(pwd)
			+'&sec=' +sec_val
			+'&email=' +email
			+'&contents='+encodeURIComponent(contents),
		onSuccess:fnAjaxModifyPrcSuccessHandle,
		onFailure:fnAA
		});
};
function fnAA(request){
	alert(request.responseText);
}
function fnAjaxModifyPrcSuccessHandle(request){
	cctank_ifr.cctank_uploader.submit();
};
//---------------------------------------------------------------------------------------
var error_msg=new Array(4);

error_msg[1]="삭제되었습니다.";
error_msg[2]="글작성자만이 삭제가능합니다.";
error_msg[3]="비밀번호가 틀렸습니다.";

//if it doesn't check password, this will be only this, 
//but if it check password, this will have callback function.
function fnAjaxDeleteSuccessHandle(request){
	var data = eval("("+request.responseText+")");
	
	if((data.result[0].message=="0")&&(data.result[0].inputview=="Y")){
		
		var settings = "width=262,height=180,top=300,left=300,location=no,toolbar=no,menubar=no,directories=no,status=no,scrollbars=no,scrollable=no,resizable=no";
		window.open("/cctankboard/passwd.asp?mode=delete", "pwdcheck", settings);
		
	}else if(data.result[0].message=="1"){
		alert(error_msg[data.result[0].message]);
		fnInit();
	}else{
		alert(error_msg[data.result[0].message]);
	}
}
//
function fnShowList() {

  clearForm();

  fnScroll();

  var ourDiv=document.getElementById('cctank');
  var t=document.createElement('table');
  t.setAttribute("id","cctank_list");
  t.className="cctank_table";
  var tb=document.createElement('tbody');
  tb.setAttribute("id","cctank_listbody");
  var trth=document.createElement('tr');

  fnAddThToTr(trth,"번호","list_head_id");
  fnAddThToTr(trth,"제목","list_head_title");
  fnAddThToTr(trth,"작성자","list_head_writer");
  fnAddThToTr(trth,"작성일","list_head_date");
  fnAddThToTr(trth,"조회수","list_head_visited");
  
  tb.appendChild(trth);

  for(i=0;i<contentData.board.length-1;i++){
  	fnTrToTb(tb,i,contentData);
  }

  t.appendChild(tb);

  
  var divBtn = document.createElement("div");
  divBtn.setAttribute("id","divBtn");
  //divBtn.setAttribute("align","right");

  var divPage = document.createElement("div");
  divPage.setAttribute("id","divPage");

  var wbtn = document.createElement("img");
  wbtn.setAttribute("src","/cctankboard/skin/"+board_info.info[0].skin_name+"/bbsbtn_write.gif");
  wbtn.onmouseover=function(){this.style.cursor='hand';}  
  wbtn.onclick=fnShowWriteForm;

  
  var ubtn = document.createElement("img");
  ubtn.setAttribute("src","/cctankboard/img/b_back_blue.gif");
  ubtn.onmouseover=function(){this.style.cursor='hand';}  
  if(nowpage==1){
	ubtn.onclick=function(){alert("첫페이지입니다.");}	
  }else{
  	ubtn.onclick=fnPageUp;
  }
  var dbtn = document.createElement("img");
  dbtn.setAttribute("src","/cctankboard/img/b_next_blue.gif");
  dbtn.onmouseover=function(){this.style.cursor='hand';}  
  if(totalpage==nowpage){
	dbtn.onclick=function(){alert("마지막페이지입니다.");}	
  }else{
  	dbtn.onclick=fnPageDown;
  }  

  if (board_info.info[0].auth_write=="Y"){ divBtn.appendChild(wbtn)};

  var minus10btn = document.createElement("img");
  minus10btn.setAttribute("src","/cctankboard/img/b_10minus_blue.gif");
  minus10btn.onmouseover=function(){this.style.cursor='hand';}  
  if(totalpage<=10){
	minus10btn.onclick=function(){alert("첫번째블럭입니다.");}	
  }else{
  	if(nowpage<=10){
	  	minus10btn.onclick=function(){alert("첫번째블럭입니다.");};
	}else{
	  	minus10btn.onclick=function(){
	  		nowpage=nowpage-10;	
	  		fnInit();
	  	};	
	}
  }
  
  divPage.appendChild(minus10btn);
  divPage.appendChild(document.createTextNode("  "));
  divPage.appendChild(ubtn);
  divPage.appendChild(document.createTextNode("  "));
  //리스트 나타내기
  if(totalpage<=10){
    //총페이지수가 10이하라면 1~총페이지수까지 뿌려줌
    for(i=1;i<=totalpage;i++){
	var pagetxt = document.createTextNode(i.toString()+"  ");
	var font = document.createElement("font");
	var newAnchor = document.createElement("a");
	
	font.appendChild(pagetxt);
	if(i==nowpage){
		font.setAttribute("color","blue");	
	}else{
		font.setAttribute("color","gray");	
	}	
	newAnchor.appendChild(font);
	newAnchor.setAttribute("id",i);
	newAnchor.onmouseover=function(){this.style.cursor='hand';}
	newAnchor.onclick=function(){
		nowpage=parseInt(this.id.toString());
		fnInit();
	}
	divPage.appendChild(newAnchor);
    }    	
  }else{
    //총페이지수가 10이상이라면 현재페이지가 있는 1~10사이의 범위를 뿌려줌 물론 총 페이지수를 넘지는 못함
    if(nowpage<=10){
    //현재페이지가 1~10사이의페이지라면...
	for(i=1;i<=10;i++){
		var pagetxt = document.createTextNode(" " +i.toString()+" ");
		var font = document.createElement("font");
		var newAnchor = document.createElement("a");
		font.appendChild(pagetxt);
		if(i==nowpage){
			font.setAttribute("color","blue");	
		}else{
			font.setAttribute("color","gray");	
		}	
		newAnchor.appendChild(font);
		newAnchor.setAttribute("id",i);
		newAnchor.onmouseover=function(){this.style.cursor='hand';}
		newAnchor.onclick=function(){
			nowpage=parseInt(this.id.toString());
			fnInit();
		}
		divPage.appendChild(newAnchor);
	}     	
    }else{
    //현재페이지가 11이상의 페이지라면, 현재페이지의 앞단위의 1~10까지를 출력한다.
    	var headnum = nowpage.toString().substr(0,(nowpage.toString().length-1));
    	headnum = headnum*10;

	for(i=1;i<=10;i++){
    		if((headnum+i)<=totalpage){
			var pagetxt = document.createTextNode(" " +(headnum+i).toString()+" ");
			var font = document.createElement("font");
			var newAnchor = document.createElement("a");
			font.appendChild(pagetxt);
			if((headnum+i)==nowpage){
				font.setAttribute("color","blue");	
			}else{
				font.setAttribute("color","gray");	
			}	
			newAnchor.appendChild(font);
			newAnchor.setAttribute("id",headnum+i);
			newAnchor.onmouseover=function(){this.style.cursor='hand';}
			newAnchor.onclick=function(){
				nowpage=parseInt(this.id.toString());
				//alert(nowpage);
				fnInit();
			}
			divPage.appendChild(newAnchor);
		}
	}     	    
    }    
  }  
  
  divPage.appendChild(dbtn);
  var plus10btn = document.createElement("img");
  plus10btn.setAttribute("src","/cctankboard/img/b_10plus_blue.gif");
  plus10btn.onmouseover=function(){this.style.cursor='hand';}  
  if(totalpage<=10){
	plus10btn.onclick=function(){alert("마지막블럭입니다.");}	
  }else{
  	if(totalpage<(parseInt(nowpage)+10)){
		plus10btn.onclick=function(){alert("마지막블럭입니다.");}
	}else{
	  	plus10btn.onclick=function(){
	  		nowpage=parseInt(nowpage)+10;	
	  		fnInit();
	  	};	
	}
  }
  divPage.appendChild(document.createTextNode("  "));  
  divPage.appendChild(plus10btn);
        
  ourDiv.appendChild(t);
  ourDiv.appendChild(divPage);
  ourDiv.appendChild(divBtn);
    
}

function fnPageUp(){
	nowpage=parseInt(nowpage)-1;
	fnInit();
}

function fnPageDown(){
	nowpage=parseInt(nowpage)+1;
	fnInit();
}

function fnAddTrInput(sName,sInputId,sType,iSize,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.className=sClass;

  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');
  var newInput=document.createElement("input");
  newInput.setAttribute("type",sType);
  newInput.setAttribute("size",iSize);
  newInput.setAttribute("id",sInputId);

  if((cc_name!="")&&(cc_pwd!="")){
	  if(sInputId=="txtName"){
		newInput.setAttribute("value",cc_name);  	
	  };
	  if (sInputId=="txtPasswd"){
	  	newInput.setAttribute("value",cc_pwd);
	  };
	  if (sInputId=="txtEmail"){
	  	newInput.setAttribute("value",cc_email);
	  };
  };   
  
  td.appendChild(newInput);
  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}


function fnAddTrCheck(sName,sInputId,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.className=sClass;

  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');
  var newInput=document.createElement("input");
  newInput.setAttribute("type","checkbox");
  newInput.setAttribute("id",sInputId);
  var TextNode = document.createTextNode(" 비밀글(관리자와 비밀번호를 입력한 사람만 볼 수 있습니다.)");
  td.appendChild(newInput);
  td.appendChild(TextNode);
  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}

function fnDel(){
	clearForm();
}


function clearForm(){
	var ourDiv=document.getElementById('cctank');
	ourDiv.innerHTML="";
}

//insert IFRAME
function fnAddTrIfr(sName,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.className=sClass;
  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');

  var ifr=document.createElement("iframe");
  ifr.setAttribute("id","cctank_ifr");
  ifr.setAttribute("width","100%");
  ifr.setAttribute("height","75");
  ifr.setAttribute("scrolling","no");
  ifr.setAttribute("frameBorder","0");
  ifr.setAttribute("marginHeight","0");
  ifr.setAttribute("marginWidth","0");
  ifr.setAttribute("src","/cctankboard/dummy.asp");

  td.appendChild(ifr);
  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}

function fnAddTrIfrForModify(sName,sClass,seq,file1,file2,file3){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.className=sClass;
  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');

  var ifr=document.createElement("iframe");
  ifr.setAttribute("id","cctank_ifr");
  ifr.setAttribute("width","100%");
  ifr.setAttribute("height","160");
  ifr.setAttribute("scrolling","no");
  ifr.setAttribute("frameBorder","0");
  ifr.setAttribute("marginHeight","0");
  ifr.setAttribute("marginWidth","0");
  ifr.setAttribute("src","/cctankboard/modifyFile.asp?seq="+seq+"&file1="+file1+"&file2="+file2+"&file3="+file3);

  td.appendChild(ifr);
  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}

function fnAddTrTextArea(sName,sInputId,iRows,iCols,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.className=sClass;
  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');
  var newTextarea=document.createElement("textarea");
  newTextarea.setAttribute("rows",iRows);
  newTextarea.setAttribute("cols",iCols);
  newTextarea.setAttribute("id",sInputId);
  newTextarea.setAttribute("name",sInputId);
  td.appendChild(newTextarea);
  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}

function fnAddTrTextAreaForModify(sName,sInputId,iRows,iCols,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.className=sClass;
  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');
  var newTextarea=document.createElement("textarea");
  newTextarea.setAttribute("rows",iRows);
  newTextarea.setAttribute("cols",iCols);
  newTextarea.setAttribute("id",sInputId);
  newTextarea.setAttribute("name",sInputId);

  var CallBtn = document.createElement("input");
  CallBtn.setAttribute("type","button");
  CallBtn.setAttribute("value"," 기존 데이터 불러오기 ");
  CallBtn.onmouseover=function(){this.style.cursor='hand';}  
  CallBtn.onclick=SetContents;


  td.appendChild(newTextarea);
  td.appendChild(CallBtn);
  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}


function fnSetEditor(sName){
	var sBasePath = "/FCKeditor/";

	var oFCKeditor = new FCKeditor( sName ) ;
	oFCKeditor.BasePath	= sBasePath ;
	oFCKeditor.Height=400;
	oFCKeditor.ReplaceTextarea() ;
}

function GetContents(sName)
{
	var oEditor = FCKeditorAPI.GetInstance(sName) ;

	return oEditor.GetXHTML( true );
}

function SetContents()
{
	var oEditor = FCKeditorAPI.GetInstance("txtContent") ;

	// Set the editor contents (replace the actual one).
	oEditor.SetHTML( decodeURIComponent(contentViewData.board[0].contents) ) ;
}

function fnAddTrText(sName,sData,sId,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.setAttribute("id",sId);
  th.className=sClass;
  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');
  if (sName=="E-mail")
  {
	 var newAnchor = document.createElement("a");
	 newAnchor.appendChild(document.createTextNode(sData));
	 newAnchor.onmouseover=function(){this.style.cursor='hand';}
	 newAnchor.onclick=function(){
		 location.href="mailto:"+sData;
	 }
	 td.appendChild(newAnchor);
  }else{
	  var newTextNode=document.createTextNode(sData);

	  td.appendChild(newTextNode);
  }  
  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}

function fnAddTrFile(sName,sData,sId,sClass){
  var tr=document.createElement('tr');
  var th=document.createElement('th');
  th.scope="rows";
  th.setAttribute("id",sId);
  th.className=sClass;
  th.appendChild(document.createTextNode(sName));
  var td=document.createElement('td');
  
  if(sData!=""){
	  var newAnchor = document.createElement("a");
	  //사진일경우 사진 출력 페이지로..
	  if (sData.toLowerCase().indexOf("jpg")>0 || sData.toLowerCase().indexOf("gif")>0 )
	  {
		  newAnchor.setAttribute("href","javascript:fnShowImage('/cctankboard/data/"+sData + "')");
	  }else{
	  //아니면 그냥띄우기
		  newAnchor.setAttribute("href","/cctankboard/data/"+sData);
	  }
	  //newAnchor.setAttribute("target","_blank");
	
	  var newTextNode=document.createTextNode(sData);
	  newAnchor.appendChild(newTextNode);	
	  
	  td.appendChild(newAnchor);
  }

  tr.appendChild(th);
  tr.appendChild(td);	
  
  return tr;
}

function fnShowImage(path){
	var settings = "width=800,height=600,top=300,left=300,location=no,toolbar=no,menubar=no,directories=no,status=no,scrollbars=no,scrollable=no,resizable=no";
	window.open("/cctankboard/image.asp?path="+path, "ImageView", settings);
}

function fnAddTrHTML(sName,sHTML,sId,sClass){
  var tr=document.createElement('tr');
  var td=document.createElement('td');

  td.colSpan=2;

  var tddiv = document.createElement("div");
  tddiv.setAttribute("id",sId);

  tddiv.innerHTML = decodeURIComponent(sHTML);
  //alert(tddiv.innerHTML);
  td.appendChild(tddiv);
  
  tr.appendChild(td);	

  return tr;
}

function resizeImg(obj){
    var maxWidth = 600;
    var maxHeight = 600;

    var imgWidth = obj.width;
    var imgHeight = obj.height;

    var widthDiffer = imgWidth - maxWidth;
    var heightDiffer = imgHeight - maxHeight;

    var diffPer = 0;

    if(widthDiffer > heightDiffer) diffPer = maxWidth / imgWidth;
    else diffPer = maxHeight / imgHeight;

    obj.width = imgWidth * diffPer;
    obj.height = imgHeight * diffPer;

    //alert("imgWidth=" + imgWidth + "\nimgHeight = " + imgHeight + "\nwidthDiffer = " + widthDiffer + "\nheightDiffer = " + heightDiffer  + "\ndiffPer = " + diffPer );
}

function fnAddTrImage(sName,sImg){
  if (sImg!="" && (sImg.toLowerCase().indexOf("jpg")>0||sImg.toLowerCase().indexOf("gif")>0))
  {
	  var tr=document.createElement('tr');
	  var td=document.createElement('td');

	  td.colSpan=2;

	  var tddiv = document.createElement("span");


	  var newImg = document.createElement("img");
	  newImg.src = "/cctankboard/data/" + sImg;
	  newImg.onload=function(){

	    var maxWidth = 600;
	    var maxHeight = 600;

	    var imgWidth = this.width;
	    var imgHeight = this.height;
	    
	    if (imgWidth>maxWidth){	
		    var widthDiffer = imgWidth - maxWidth;
		    var heightDiffer = imgHeight - maxHeight;
		
		    var diffPer = 0;
		
		    if(widthDiffer > heightDiffer) diffPer = maxWidth / imgWidth;
		    else diffPer = maxHeight / imgHeight;
		
		    this.width = imgWidth * diffPer;
		    this.height = imgHeight * diffPer;	  	
	    }
	  };
	  tddiv.appendChild(newImg);

	  td.appendChild(tddiv);
	  
	  tr.appendChild(td);	

	  return tr;
  }
}
function fnAddThToTr(oTr,sName, sId){
	var th = document.createElement("th");
	th.scope="col";
	th.setAttribute("id",sId);
	th.className="cctank_list_head";
	var tdText = document.createTextNode(sName);
	th.appendChild(tdText);
	oTr.appendChild(th);
}

function fnAddTdToTr(oTr,sVal){
	var td = document.createElement("td");
	var tdText = document.createTextNode(sVal);
	td.appendChild(tdText);
	oTr.appendChild(td);
}



function fnAddSubjectToTr(oTr,sVal,sChild,sDepth,sSeq,comment_cnt,file,newcheck,security){
	var td = document.createElement("td");
	td.setAttribute("align","left");
	
	contain=document.createElement("div");
	contain.setAttribute("align","left");
	
	if(sChild=="Y"){
		temp1=document.createElement("span");
		temp1.appendChild(document.createTextNode("+ "));
		temp1.setAttribute("id","cctank_listplus" + sSeq);
		temp1.style.paddingLeft=(sDepth)+"em";
		temp1.onmouseover=function(){this.style.cursor='hand'};
		if(board_info.info[0].expand=="Y"){
			/*기본열림상태유지S*/
			var request = new Ajax.Request('/cctankboard/getSubList.asp',
			{
				method:'get',
				parameters:'depth='+ sDepth+'&parent_seq='+sSeq+'&dummy='+new Date().getTime(),
				onSuccess:fnAjaxSubListHandle,
				onFailure:function(){alert('Something went wrong')}
			});		
			
			/*기본열림상태유지E*/
		}else{
			/*기본닫힘상태유지S*/
			temp1.onclick=function(){
				var request = new Ajax.Request('/cctankboard/getSubList.asp',
				{
				method:'get',
				parameters:'depth='+ sDepth+'&parent_seq='+sSeq+'&dummy='+new Date().getTime(),
				onSuccess:fnAjaxSubListHandle,
				onFailure:function(){alert('Something went wrong')}
				});
			}
			/*기본닫힘상태유지E*/
		}
	}else{
		temp1=document.createElement("span");
		temp1.style.paddingLeft=(sDepth)+"em";
		temp1.appendChild(document.createTextNode(" "));
	}	

	temp2=document.createElement("span");

	if (comment_cnt!=0)
	{
		sVal = sVal + "["+comment_cnt+"]";
	}
	
	if (parseInt(sDepth)>0)
	{
		var newImg = document.createElement("img");
		newImg.src = "/cctankboard/skin/otsukael_2/icon_cursor.gif"
		temp2.appendChild(newImg);
		temp2.appendChild(document.createTextNode(" " + sVal + " "));
	}else{
		temp2.appendChild(document.createTextNode(sVal + " " ));
	}
	
	if(newcheck=="Y"){
		var newImg = document.createElement("img");
		newImg.src = "/cctankboard/img/icon_red_new.gif";
		temp2.appendChild(newImg);
	}

	if(file){
		var newImg = document.createElement("img");
		newImg.src = "/cctankboard/img/ico_attach.gif";
		temp2.appendChild(newImg);
	}
	if(security=="Y"){
		var newImg = document.createElement("img");
		newImg.src = "/cctankboard/img/ico_lock.gif";
		newImg.width=12;
		newImg.height=12;
		temp2.appendChild(newImg);
	}
	temp2.onclick=function(){
		
		dhtmlHistory.add("view",sSeq);

		var request = new Ajax.Request('/cctankboard/getViewData.asp',
		{
		method:'get',
		parameters:'seq='+sSeq+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxViewHandle,
		onFailure:function(){
			alert('Something went wrong')
			}
		});	
	};
	temp2.onmouseover=function(){this.style.cursor='hand'};
			
	contain.appendChild(temp1);
	contain.appendChild(temp2);
	
	td.appendChild(contain);
	oTr.appendChild(td);

}


function fnTrToTbForComment(oTb,ii,jData){
  	
  	var tr=document.createElement("tr");
	
	tr.className="cctank_tabletr";
  	
	var td = document.createElement("td");
	td.setAttribute("align","left");
	td.className="comment_body";
	
	var tdText = document.createElement("span")
	
	tdText.innerHTML=decodeURIComponent(jData.comments[ii].comment).replace(/(\n)/gi,"<br>");
	
	td.appendChild(tdText);
	tr.appendChild(td);

	td = document.createElement("td");
	td.className="comment_writer";
		
	tdText = document.createTextNode(jData.comments[ii].writer);
	
	td.appendChild(tdText);
	
	var temp=document.createElement("span");
	
	temp.appendChild(document.createTextNode(" [del]"));
	temp.onclick=function(){
		var request = new Ajax.Request('/cctankboard/deleteComment.asp',
		{
		method:'post',
		contentType:'application/x-www-form-urlencoded',
		encoding:'utf-8',
		parameters:'seq='+encodeURIComponent(jData.comments[ii].seq),
		onSuccess:fnAjaxCommentDeleteSuccessHandle,
		onFailure:function(){
			alert("fail");
		}
		});			
	};
	
	temp.onmouseover=function(){this.style.cursor='hand'};	
	
	td.appendChild(temp);
	
	td.appendChild(document.createElement("br"));
	
	tdText = document.createTextNode(jData.comments[ii].wdate);
	
	td.appendChild(tdText);
	
	tr.appendChild(td);
	
  	oTb.appendChild(tr);

}



function fnCallbackPasswdForCommentDel(seq,pwdchk){
	//alert(seq+" "+pwdchk);

	var request = new Ajax.Request('/cctankboard/deleteComment.asp',
	{
	method:'post',
	contentType:'application/x-www-form-urlencoded',
	encoding:'utf-8',
	parameters:'seq='+encodeURIComponent(seq)
		  +'&pwd='+encodeURIComponent(pwdchk),
	onSuccess:fnAjaxCommentDeleteSuccessHandle
	});	
	
}

var c_error_msg=new Array(4);

c_error_msg[1]="삭제되었습니다.";
c_error_msg[2]="글작성자만이 삭제가능합니다.";
c_error_msg[3]="비밀번호가 틀렸습니다.";

//if it doesn't check password, this will be only this, 
//but if it check password, this will have callback function.
function fnAjaxCommentDeleteSuccessHandle(request){
	var data = eval("("+request.responseText+")");

	if((data.result[0].message=="0")&&(data.result[0].inputview=="Y")){
		
		var settings = "width=262,height=180,top=300,left=300,location=no,toolbar=no,menubar=no,directories=no,status=no,scrollbars=no,scrollable=no,resizable=no";
		window.open("/cctankboard/passwd.asp?mode=commentDel&seq=" + data.result[0].seq, "pwdcheck", settings);
		
	}else if(data.result[0].message=="1"){
		alert(c_error_msg[data.result[0].message]);
		fnShowView();
	}else{
		alert(c_error_msg[data.result[0].message]);
	}

}
function fnTrToTb(oTb,ii,Data){
	var fileatt=false;

	tr=document.createElement("tr");
  	tr.setAttribute("id","cctank_listtr"+Data.board[ii].seq);
  	if(ii%2==1){
  		tr.className="cctank_tabletr";
  	}else{
  		tr.className="cctank_tabletralt";
  	}
	if (Data.board[ii].fileName1!="" || Data.board[ii].fileName2!="" || Data.board[ii].fileName3!="")
	{
		fileatt=true;
	}	  	
  	fnAddTdToTr(tr,Data.board[ii].no);
  	fnAddSubjectToTr(tr,Data.board[ii].subject,Data.board[ii].child,Data.board[ii].depth,Data.board[ii].seq,Data.board[ii].comment_cnt,fileatt,Data.board[ii].new_check,Data.board[ii].security);
  	fnAddTdToTr(tr,Data.board[ii].writer);
  	fnAddTdToTr(tr,Data.board[ii].wdate);
  	fnAddTdToTr(tr,Data.board[ii].visited);
  	oTb.appendChild(tr);
}

function fnTrToTbSub(ii,Data){
	var fileatt=false;

	trid = document.getElementById("cctank_listtr"+Data.board[0].parent_seq).rowIndex;
	newTr=document.getElementById("cctank_list").insertRow(trid+1);
  	newTr.setAttribute("id","cctank_listtr"+Data.board[ii].seq);
  	newTr.className=document.getElementById("cctank_listtr"+Data.board[0].parent_seq).className;
  	//Sub List has not index number
  	//fnAddTdToTr(newTr,Data.board[ii].seq);
	if (Data.board[ii].fileName1!="" || Data.board[ii].fileName2!="" || Data.board[ii].fileName3!="")
	{
		fileatt=true;
	}	  	

  	fnAddTdToTr(newTr,"");
  	fnAddSubjectToTr(newTr,Data.board[ii].subject,Data.board[ii].child,Data.board[ii].depth,Data.board[ii].seq,Data.board[ii].comment_cnt,fileatt,Data.board[ii].new_check,Data.board[ii].security);
  	fnAddTdToTr(newTr,Data.board[ii].writer);
  	fnAddTdToTr(newTr,Data.board[ii].wdate);
	fnAddTdToTr(newTr,Data.board[ii].visited);
}

function fnShowSubList(Data) {
  for(i=0;i<Data.board.length-1;i++){
  	fnTrToTbSub(i,Data);
  }
}

function fnAjaxSubListHandle(request){
	contentSubData=eval("(" + request.responseText + ")");

	fnShowSubList(contentSubData);

	fnChangePlusBtn(contentSubData);
}

function fnChangePlusBtn(Data){
	temp1 = document.getElementById("cctank_listplus"+Data.board[0].parent_seq);
	temp1.removeChild(temp1.childNodes[0]);
	temp1.appendChild(document.createTextNode("- "));
	temp1.style.paddingLeft=(Data.board[0].depth-1)+"em";
	temp1.onmouseover=function(){this.style.cursor='hand'};
	temp1.onclick=function(){
		var request = new Ajax.Request('/cctankboard/getSubList.asp',
		{
		method:'get',
		parameters:'depth='+ (Data.board[0].depth-1) +'&parent_seq='+Data.board[0].parent_seq+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxSubListDelHandle,
		onFailure:function(){alert('Something went wrong')}
		});
	}
}

function fnAjaxSubListDelHandle(request){
	contentSubData=eval("(" + request.responseText + ")");

	fnRemoveSubList(contentSubData);

	fnChangeMinusBtn(contentSubData);
}

function fnChangeMinusBtn(Data){
	temp1 = document.getElementById("cctank_listplus"+Data.board[0].parent_seq);
	temp1.removeChild(temp1.childNodes[0]);
	temp1.appendChild(document.createTextNode("+ "));
	temp1.style.paddingLeft=(Data.board[0].depth-1)+"em";
	temp1.onmouseover=function(){this.style.cursor='hand'};
	temp1.onclick=function(){
		var request = new Ajax.Request('/cctankboard/getSubList.asp',
		{
		method:'get',
		parameters:'depth='+ (Data.board[0].depth-1)+'&parent_seq='+(Data.board[0].parent_seq)+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxSubListHandle,
		onFailure:function(){alert('Something went wrong')}
		});
	}
}

function fnRemoveSubList(Data) {
  var target = document.getElementById("cctank_listbody");
  for(i=0;i<Data.board.length-1;i++){
  	delTr = document.getElementById("cctank_listtr"+Data.board[i].seq);

  	var request = new Ajax.Request('/cctankboard/getSubList.asp',
		{
		method:'get',
		parameters:'depth='+ (Data.board[0].depth) +'&parent_seq='+Data.board[0].seq+'&dummy='+new Date().getTime(),
		onSuccess:fnAjaxSubListDelHandle,
		onFailure:function(){alert('Something went wrong')}
		});
  	
  	while(delTr.hasChildNodes()){
  		delTr.removeChild(delTr.firstChild);
  	}
	target.removeChild(delTr);
  }
}

function fnScroll(){
	scroll(0,0);
};

function fnOpenRss(rss_addr){
   document.all['cctank_rss_addr'].innerText=rss_addr;
   var doc = document.body.createTextRange();
   doc.moveToElementText(document.all['cctank_rss_addr']);
   doc.execCommand('copy');

	alert('클립보드로 RSS주소가 복사되었습니다.\n ctrl + V 또는 붙여넣기하여 RSS 리더에 주소를 추가하시면 됩니다.');
}
