﻿    var bFirstAlert = false;
	var nodesc2 = false;
	var CommentPageSize = 10;
	var CommentCurPage = 1;
	var CommentTotalAll;
	var CommentTotal = 0;
	var ticketurl = "";
		
	function assignError(res){
        alert(res);
	}

	function getCount() {

		var url = ticketurl + "/Common/AsynPage/Comment/PerfComCount.aspx";
		new Ajax.Request(url,{
			asynchronous:true,
			method: "get",
			parameters: "IdBoard=" + BoardId,
			onSuccess: function(request){
				getCount_Callback(request.responseText);
			},
			onFailure: function(request){
				assignError(request.responseText);
			}
		});
	}
	
	function getCount_Callback(res){

		CommentTotal = res;
		if(CommentTotalAll != CommentTotal){
			getCommentData();
		}else{
			getCommentData();
		}
		CommentTotalAll = CommentTotal;
	}
	
	function getCommentData(){

		//getPaging(DivPage);
		//if(document.all.divTot !=null){
		//	document.getElementById("divTot").innerHTML = "총 <span class='b txt_o2'>" + CommentTotal + "개</span>의 글이 등록되었습니다.";
		//}
		//DivTot.innerHTML = "["+CommentCurPage+"/"+(parseInt(((CommentTotal-1)/CommentPageSize))+1)+"] 총 "+CommentTotal+"개";		
		divComment.innerHTML = "";	
		document.getElementById("divComment").style.display = "none";
		document.getElementById("divComment").style.overflow = "hidden";
			
		var url = ticketurl + "/Common/AsynPage/Comment/PerfComList.aspx";
		new Ajax.Request(url,{
			asynchronous:true,
			method: "get",
			parameters: "IdBoard=" + BoardId,
			onSuccess: function(request){
				getCommentData_Callback(request.responseText);
			},
			onFailure: function(request){
				assignError(request.responseText);
			}
		});
	}
	
	function getCommentData_Callback(res){
		if(CommentCurPage > 1 && (res+"n")=="n"){
			nodesc2=true;
			CommentCurPage = CommentCurPage-1;
			getCount();
		}else{
			nodesc2=false;
			var rep = "&nbsp;";
			//alert(res.replace(new RegExp(rep, "gi"), " "));
			divComment.innerHTML = res.replace(new RegExp(rep, "gi"), " ");
			document.getElementById("divComment").style.display = "";
			
		}
	}
	
	function goCommentReg(){
		
		var Esit = "";
		/*
		for(var i=0;i<document.all.radICon.length;i++){
			if(document.all.radICon[i].checked){
				Esit = document.all.radICon[i].value;
				break;
			}
		}
		*/
		var url = ticketurl + "/Common/AsynPage/Comment/PerfComReg.aspx";
		new Ajax.Request(url,{
			asynchronous:true,
			method: "post",
			postBody: "IdBoard=" + BoardId +"&contents=" + escape(document.getElementById("txtComdesc").value),
			onSuccess: function(request){
				goCommentReg_Callback(request.responseText);
			},
			onFailure: function(request){
			    assignError(request.responseText);
			}
		});
	}
	
	function goCommentReg_Callback(res){
		if(res=="0"){
			alert("로그인후 등록하실수 있습니다");
		}else{
			document.getElementById("txtComdesc").value='';
			document.getElementById("spanByte").innerText = "0";
			getCount();
		}
	}
	
	function Delcomment(comid){
		if(confirm("코멘트를 삭제하시겠습니까?")){
			goDelComment(comid);
		}
	}
	
	function goDelComment(comid){
		var url = ticketurl + "/Common/AsynPage/Comment/PerfComDel.aspx";
		new Ajax.Request(url,{
			asynchronous:true,
			method: "get",
			parameters: "cid="+comid,
			onSuccess: function(request){
				goDelComment_Callback(request.responseText);
			},
			onFailure: function(request){
				assignError(request.responseText);
			}
		});
	}
	
	function goDelComment_Callback(res){
		if(res=="0"){
			alert("삭제권한이 없습니다.");
		}else{
			getCount();
		}
	}

	function goToCommentMoving(movePage){
		CommentCurPage =  movePage;
		getCommentData();
	}
	
	function RegComment(){
		if(CheckForm()){
			goCommentReg();
		}
	}



function getPaging(objdiv){
		
	objdiv.innerHTML = "";
	var FromPage= (parseInt((CommentCurPage-1)/10)*10)+1;
	
	var ToPage = FromPage+9;
	var PageCount = parseInt(((CommentTotal-1)/CommentPageSize))+1;
	if(PageCount > FromPage+9){
		ToPage=FromPage+9;
	}else{
		ToPage=PageCount;
	}

    objdiv.innerHTML = "<table width='560' border='0' align='center' cellpadding='0' cellspacing='0'>";
    objdiv.innerHTML += "<tr>";
    objdiv.innerHTML += "<td>";

	if(parseInt(((CommentCurPage-1)/10)) > 0){
	    objdiv.innerHTML += "&nbsp;<a href='javascript:goToMoving(" + (FromPage - 1) + ");' onfocus=this.blur()><img src=http://ticket.clubbalcony.com/images/common/btn_first.gif border=0 align=absmiddle></a>&nbsp;";
	}else{
	objdiv.innerHTML += "&nbsp;<img src=http://ticket.clubbalcony.com/images/common/btn_first.gif border=0 align=absmiddle>&nbsp;";
	}

	if(CommentCurPage > 1) {
	    objdiv.innerHTML += "&nbsp;<a href='javascript:goToMoving(" + (CommentCurPage - 1) + ");' onfocus=this.blur()><img src=http://ticket.clubbalcony.com/images/common/btn_prev.gif border=0 align=absmiddle></a>&nbsp;";
	}else{
	objdiv.innerHTML += "<img src=http://ticket.clubbalcony.com/images/common/btn_prev.gif border=0 align=absmiddle>&nbsp;";
	}

	for(var i=FromPage;i<=ToPage;i++)
	{
		if(i==CommentCurPage)
			objdiv.innerHTML += "<font color='red'><strong><a class='a_focus'><span class='bs_no_c'>&nbsp;"+i+"&nbsp;</span></strong></a></font>";
		else
			objdiv.innerHTML += "<a href='javascript:goToMoving("+i+");'>&nbsp;"+i+"&nbsp;</a>";
	}
	
	if(CommentCurPage < PageCount){
	    objdiv.innerHTML += "&nbsp;<a href='javascript:goToMoving(" + (CommentCurPage + 1) + ");' onfocus=this.blur()><img src=http://ticket.clubbalcony.com/images/common/btn_next.gif border=0 align=absmiddle></a>&nbsp;";
	}else{
	objdiv.innerHTML += "&nbsp;<img src=http://ticket.clubbalcony.com/images/common/btn_next.gif border=0 align=absmiddle>&nbsp;";
	}
	if(ToPage < PageCount){
	    objdiv.innerHTML += "<a href='javascript:goToMoving(" + (ToPage + 1) + ");' onfocus='this.blur();'><img src=http://ticket.clubbalcony.com/images/common/btn_last.gif border=0 align=absmiddle></a>&nbsp;";
	}else{
	objdiv.innerHTML += "<img src=http://ticket.clubbalcony.com/images/common/btn_last.gif border=0 align=absmiddle>&nbsp;";
	}
	
	objdiv.innerHTML += "</td>";
	objdiv.innerHTML += "</tr>";
	objdiv.innerHTML += "</table>";
}

function toTimeString(date) {
			var year  = date.getFullYear();
			var month = date.getMonth() + 1;
			var day   = date.getDate();

			if (("" + month).length == 1) { month = "0" + month; }
			if (("" + day).length   == 1) { day   = "0" + day;   }
			return (year +"-"+ month +"-"+ day)
}



