/*
 * Copyright (c) HanaroDream, Inc. All rights reserved.
 *
 * Original author : ÀüÇý¿µ <thinko@dreamx.com>
 * Maintainer     :  ÀüÇý¿µ <thinko@dreamx.com >
 * Date: 2005-07-21
 * Desc: ¸®½ºÆ®¿¡¼­ ÆäÀÌÁö »Ñ·ÁÁÖ´Â ÀÚ¹Ù ½ºÅ©¸³Æ®
 		  
 * $Header$
 */


function paging(total_count,pageline,pagegroup,current_page,img_url,url, flag )
{

	current_page = parseInt(current_page);
	pagegroup = parseInt(pagegroup);   
	var range_st=1; //¹üÀ§ ½ÃÀÛ
	var range_end=1; //¹üÀ§³¡.
	var go_first=1; //¸Ç¾ÕÀ¸·Î
	var go_end=1; //¸ÇµÚ·Î
	var next=0; //´ÙÀ½
	var prev=0; //ÀÌÀü

	document.write("<TABLE cellSpacing=0 cellPadding=0 border=0 >");
	document.write("<TR align=middle>");


	if( flag == true && total_count > pageline){
		document.write("<td style='PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 0px; CURSOR: hand; PADDING-TOP: 5px' align=middle><span style='font-size:8pt;'>&nbsp;");
		if(current_page <= pagegroup){
			temp = "<img src='http://hbbs.hanafos.com/image/ico_back02_off.gif' align='texttop' width='11' height='9' border='0'>"			
		}else{
			temp = "<img src='http://hbbs.hanafos.com/image/ico_back02.gif' align='texttop' width='11' height='9' border='0'>"
		}

		temp = temp.link( url+"&page=1");
		document.write( temp );
		document.write("</span></td>")
	}

	//ÃÑ ÆäÀÌÁö...
	if( total_count == 0 )
		go_end = 1
	else
		go_end = Math.ceil(total_count/pageline);


	//ÇöÀç ÆäÀÌÁö°¡ Æ÷ÇÔµÈ ¹üÀ§ ±¸ÇÏ±â./
   range_st=(Math.floor((current_page-1)/pagegroup))*pagegroup+1;
   range_end=range_st+(pagegroup-1);
	if(range_end > go_end)
		range_end=go_end;

	// ÀÌÀü ´ÙÀ½  ±¸ÇÏ±â..
	if(range_st > pagegroup)
	prev = range_st-1;
	if(range_end < go_end)
	next = range_end+1;

	var sp_head ="<TD style='TEXT-DECORATION:none;font-size:9pt;cursor=hand;' class=page onmouseover='this.style.background=\"#f7f7f7\"' onmouseout='this.style.background=\"\"' ";
	var sp_foot ="</TD>";
	var sp_line ="<TD width=1 bgColor=#cccccc></TD>";

	var p_p = ""
	var n_p = ""
	if(total_count > pageline){
		if(prev <= 0){
			p_p = "<IMG src='http://hbbs.hanafos.com/image/ico_back01_off.gif' align=textTop border=0><span style='font-size:8pt;'></span>";
		}else{
			p_p = "<IMG src='http://hbbs.hanafos.com/image/ico_back01.gif' align=textTop border=0><span style='font-size:8pt;'></span>";
		}
		if(current_page == go_end){
			n_p = "<span style='font-size:8pt;'></span><IMG src='http://hbbs.hanafos.com/image/ico_next01_off.gif' align=textTop border=0>";
		}else{
			n_p = "<span style='font-size:8pt;'></span><IMG src='http://hbbs.hanafos.com/image/ico_next01.gif' align=textTop border=0>";
		}
	}

  line = "";

  if(prev > 0 ){
		temp = p_p.link(url+"&page="+prev);
		line=line.concat("<td style='padding-top:2px; padding-right:7px; padding-bottom:0px; padding-left:3px; CURSOR: hand;' align=middle>");
		line=line.concat(temp);
		line=line.concat(sp_foot);
		line=line.concat(sp_line);
	}
	else{
		line=line.concat("<td style='padding-top:2px; padding-right:7px; padding-bottom:0px; padding-left:3px; CURSOR: hand;' align=middle>");
		line=line.concat(p_p);
		line=line.concat(sp_foot);
		line=line.concat(sp_line);
	}

	for( k=range_st;k <= range_end;k++)
	{

		line=line.concat(sp_head);

		if(k == current_page){
			temp ="><FONT color=#d84265>"+k+"</FONT>";
			line=line.concat(temp);
		}
		else {
		   temp="onClick='location.href=\"" + url+"&page="+k+ "\";'><FONT COLOR=#666666>"+ k + "</FONT>";
		   line = line.concat(temp);
		}

 		line=line.concat(sp_foot);
		line=line.concat(sp_line);
		
	}

	if(next > range_end ){
		temp= n_p.link(url+"&page="+next);
		line=line.concat("<td style='PADDING-RIGHT: 3px; PADDING-LEFT: 7px; PADDING-BOTTOM: 0px; CURSOR: hand; PADDING-TOP: 2px' align=middle>");
		line=line.concat(temp);
		line=line.concat(sp_foot);
	}
	else
	{
		line=line.concat("<td style='PADDING-RIGHT: 3px; PADDING-LEFT: 7px; PADDING-BOTTOM: 0px; CURSOR: hand; PADDING-TOP: 2px' align=middle>");
		line=line.concat(n_p);
		line=line.concat(sp_foot);
	}

	document.write(line);

	if( flag == true  && total_count > pageline){
		document.write("<td style='PADDING-RIGHT: 3px; PADDING-LEFT: 3px; BACKGROUND: none transparent scroll repeat 0% 0%; PADDING-BOTTOM: 0px; CURSOR: hand; PADDING-TOP: 2px' align=middle><p><span style='font-size:8pt;'>");

		if(current_page == go_end){
			temp = "<img src='http://hbbs.hanafos.com/image/ico_next02_off.gif' align='texttop' width='12' height='9' border='0'>";
		}else{
			temp = "<img src='http://hbbs.hanafos.com/image/ico_next02.gif' align='texttop' width='12' height='9' border='0'>";
		}
		temp = temp.link( url+"&page=" + go_end);
		document.write( temp );
		document.write("</span></td>");
	}
	document.write("</TR></TABLE>");
}