QueryString = function(str) { 
   var str = str ? str : document.location.href; 
   this.argv = new Array(); 
   this.queryString = str.split('?')[1]; 
   if (!this.queryString) this.queryString = ''; 
   var _argv = this.queryString.split('&'); 
   for(var i=0; i<_argv.length; i++) { 
      $=_argv[i].split('='); 
      var _key = $[0]; 
      var _val = $[1]; 
      this.argv[_key] = $[1]; 
   } 

   if (!this.argv) this.argv = new Array(); 

   this.setVar = function(key,val) { 
      if (typeof key == 'object') { 
         for (var item in key) this.argv[item] = key[item]; 
      } else { 
         this.argv[key] = val; 
      } 
      return this.getVar(); 
   } 

   this.getVar = function(key) { 
      if (key) { 
         if (!this.argv[key]) return ''; 
         else { 
            return this.argv[key]; 
         } 
      } else { 
         var cnt = 0; 
         for(var c in this.argv) cnt++;   // XXX: Å° ÀÌ¸§À» °¡Áø array ´Â length ¼Ó¼ºÀ¸·Î Ç×»ó 0 À» “Ê¾î³½´Ù. 
         if (cnt > 0) { 
            var _item = new Array(); 
            for (var x in this.argv) if (this.argv[x]) _item[_item.length] = x + '=' + this.argv[x]; 
            else continue; 
            return '?' + _item.join('&'); 
         } else return '?'; 
      } 
   } 
} 

Paging = function(total) { 
   this.config = { 
      thisPageStyle: 'font-weight: bold;', 
      itemPerPage: 10,		// ¸®½ºÆ® ¸ñ·Ï¼ö 
      pagePerView: 10		// ÆäÀÌÁö´ç ³×ºñ°ÔÀÌ¼Ç Ç×¸ñ¼ö 
   } 

   this.totalItem = total; 
   this.qs = new QueryString; 

   this.calculate = function() { 
      this.totalPage = Math.ceil(this.totalItem / this.config.itemPerPage); 
      this.currentPage = this.qs.getVar('page'); 
      if (!this.currentPage) this.currentPage = 1; 
      if (this.currentPage > this.totalPage) this.currentPage = this.totalPage; 
      this.lastPageItems = this.totalPage % this.config.itemPerPage; 

      this.prevPage = this.currentPage-1; 
      this.nextPage = this.currentPage+1; 
      this.seek = this.prevPage * this.config.itemPerPage; 
      this.currentScale = parseInt(this.currentPage / this.config.pagePerView); 
      if (this.currentPage % this.config.pagePerView < 1) this.currentScale--; 
      this.totalScale = parseInt(this.totalPage / this.config.pagePerView); 
      this.lastScalePages = this.totalPage % this.config.pagePerView; 
      if (this.lastScalePages == 0) this.totalScale--; 
      this.prevPage = this.currentScale * this.config.pagePerView; 
      this.nextPage = this.prevPage + this.config.pagePerView + 1; 
   } 

   this.toString = function() { 
      var ss, se; 
      this.calculate(); 
      if (this.config.prevIcon) var prevBtn ='<img src="'+this.config.prevIcon+'" border="0" align="absmiddle">'; 
      else var prevBtn = '<img src="/Admission/Counsel/include/bt_pre1.gif" border="0" align="absmiddle"> '; 
      if (this.currentPage > this.config.pagePerView) { 
         prevBtn = prevBtn.link(this.qs.setVar('page',this.prevPage)); 
      } 

      ss = this.prevPage + 1; 
      if ((this.currentScale >= this.totalScale) && (this.lastScalePages != 0)) se = ss + this.lastScalePages; 
      else if (this.currentScale <= -1) se = ss; 
      else se = ss + this.config.pagePerView; 

      var navBtn = ''; 
      for(var i = ss; i<se; i++) { 
         if (i == this.currentPage) { 
            _btn = '<span style="'+this.config.thisPageStyle+'">['+i+']</span>'; 
         } else { 
            _btn = '<a href="'+this.qs.setVar('page',i)+'" style="'+this.config.otherPageStyle+'">['+i+']</a>' 
         } 
         navBtn+=_btn; 
      } 

      if (this.config.prevIcon) var nextBtn ='<img src="'+this.config.nextIcon+'" border="0" align="absmiddle">'; 
      else var nextBtn = ' <img src="/Admission/Counsel/include/bt_next1.gif" border="0" align="absmiddle">'; 
      if (this.totalPage > this.nextPage) { 
         nextBtn = nextBtn.link(this.qs.setVar('page',this.nextPage)); 
      } 
      return prevBtn+navBtn+nextBtn; 
   } 
}

