﻿	var nodesc = false;
	var PageSize = 10;
	var ListSize = 10;
	var CurPage = 1;
	var TotalAll;
	var Total = 0;
	var Search = "0";
	var SearSt = "";
	var ticketurl = "";

	function assignError(res){
        alert(res);
	}
	
	function onSearch()
	{
	    var objSearch = document.getElementById("dropSearch");
	    
	    for(i=0; i<objSearch.length; i++)
	    {
	        if(objSearch[i].selected)
	        {
	            Search = objSearch[i].value;
	            break;
	        }
	    }    
	    SearSt = document.getElementById("txtSearch").value;
	    
        if(SearSt.length < 1)
        {
            alert("검색어는 2자 이상이어야 합니다.");
            return;
        }
	    
   		divSearchArea.innerHTML = "";	
		document.getElementById("divSearchArea").style.display = "none";
		document.getElementById("divSearchArea").style.overflow = "hidden";
		
		CurPage = 1;

	    if(Search != 0)
	        getSearchCount();
	    else    
	        getBoardList();
	}

	function getSearchCount() {
        
        if(SearSt.length < 1)
            return;
        
		var url = ticketurl + "/Common/AsynPage/Search/SearchCount.aspx";

		new Ajax.Request(url,{
			asynchronous:true,
			method: "get",
			parameters: "Search=" + Search + "&SearSt=" + SearSt,
			onSuccess: function(request){
				getSearchCount_Callback(request.responseText);
			},
			onFailure: function(request){
				assignError(request.responseText);
			}
		});
	}
	
	
	function getSearchCount_Callback(res){
		Total = res;
		TotalAll = Total;	

		getBoardList();
	}
	
	function getBoardList(){
       
        if(SearSt.length < 1)
            return;
	
	    if(TotalAll > PageSize)
	    {
		    document.getElementById("divPagerArea").style.display = "";
		    getPaging2(divPagerArea, PageSize, ListSize);
		}
		else
		{
   		    divPagerArea.innerHTML = "";	
		    document.getElementById("divPagerArea").style.display = "none";
		    document.getElementById("divPagerArea").style.overflow = "hidden";
    	}
    	
		var url = ticketurl + "/Common/AsynPage/Search/Search.aspx";
		new Ajax.Request(url,{
			asynchronous:true,
			method: "get",
			parameters: "Search=" + Search + "&SearSt=" + SearSt + "&page=" + CurPage + "&size=" + PageSize,
			onSuccess: function(request){
				getBoardList_Callback(request.responseText);
			},
			onFailure: function(request){
				assignError(request.responseText);
			}
		});
	}
	
	function getBoardList_Callback(res){
		if(CurPage > 1 && (res+"n")=="n"){
			nodesc=true;
			CurPage = CurPage-1;
			getSearchCount();
		}else{
			nodesc=false;
			divSearchArea.innerHTML = res;
			document.getElementById("divSearchArea").style.display = "";
		}
    }
    
	function goToMoving(movePage){
		CurPage =  movePage;
		getBoardList();
	}

    function getPaging2(objdiv, pagesize, listsize){
    		
	    objdiv.innerHTML = "";
	    var innerHtml = "";
	    var FromPage = parseInt((CurPage - 1) / listsize) * listsize + 1;
	    var ToPage = FromPage+listsize-1;
	    var PageCount = parseInt(((Total-1)/pagesize))+1;
	    if(PageCount <= ToPage)
		    ToPage=PageCount;
    		                           	
        innerHtml = "<table border='0' cellpadding='0' cellspacing='0'>";
        innerHtml += "<tr>";
        innerHtml += "<td width='22'>";

	    if(parseInt(((CurPage-1)/listsize)) > 0){
	        innerHtml += "<a href='javascript:goToMoving(" + (FromPage - 1) + ");' onfocus=this.blur()><img src='/images/common/btn_prev02.gif' border='0'></a>";
	    }else{
	        innerHtml += "<img src='/images/common/btn_prev02.gif' border='0' align='absbottom'>";
	    }
        innerHtml += "</td><td width='20'>";

	    if(CurPage > 1) {
	        innerHtml += "<a href='javascript:goToMoving(" + (CurPage - 1) + ");' onfocus=this.blur()><img src='/images/common/btn_prev01.gif' border='0'></a>";
	    }else{
	        innerHtml += "<img src='/images/common/btn_prev01.gif' border='0' align='absbottom'>";
	    }
        innerHtml += "</td><td align='center'>";

	    for(var i=FromPage;i<=ToPage;i++)
	    {
		    if(i==CurPage)
			    innerHtml += "<font color='red'>"+i+"</font>&nbsp;";
		    else
			    innerHtml += "<a href='javascript:goToMoving("+i+");'>"+i+"</a>&nbsp;";
	    }
        innerHtml += "</td><td width='22'>";
    	
	    if(CurPage < PageCount){
	        innerHtml += "<a href='javascript:goToMoving(" + (CurPage + 1) + ");' onfocus=this.blur()><img src='/images/common/btn_next01.gif' border='0'></a>";
	    }else{
	        innerHtml += "<img src='/images/common/btn_next01.gif' border='0' align='absbottom'>";
	    }
        innerHtml += "</td><td width='20'>";
        
	    if(ToPage < PageCount){
	        innerHtml += "<a href='javascript:goToMoving(" + (ToPage + 1) + ");' onfocus='this.blur();'><img src='/images/common/btn_next02.gif' border='0'></a>";
	    }else{
	        innerHtml += "<img src='/images/common/btn_next02.gif' border='0' align='absbottom'>";
	    }
        innerHtml += "</td>";
	    innerHtml += "</tr>";
	    innerHtml += "</table>";
    	
	    objdiv.innerHTML = innerHtml;
    }