function openCatalog( strURL )
{
    var screen_width = 1024 - 10;
    var screen_height = 768 - 30;
    strFeatures = "left=0,top=0,width=" + screen_width + ",height=" + screen_height + ", ";
    strFeatures += "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
    strURL += "&sub_library_call=1";
    windowname=window.open( strURL, "piuriBook", strFeatures );
    windowname.focus();
    return;
}
function openWindow( strURL )
{
  var left = 30;
  var top = 30;
  var height = 148;
  var width = 330;
  var opt = "scrollbars=yes,width="+width+",height="+height+",top="+top+",left="+left;
  windowname=window.open( strURL, "Ebook", opt );
  windowname.focus();
  return;
}
function openExec( strURL )
{
  var left = 0;
  var top = 0;
  var height = 0;
  var width = 0;
  var opt = "scrollbars=yes,width="+width+",height="+height+",top="+top+",left="+left;
  windowname=window.open( strURL, "exec", opt );
  windowname.focus();
  return;
}
// Àü¿ª º¯¼ö
var errmsg = "";
var errfld;

// ÇÊµå °Ë»ç
function check_field(fld, msg) 
{
    if ((fld.value = trim(fld.value)) == "") 			   
        error_field(fld, msg);
    else
        clear_field(fld);
    return;
}

// ÇÊµå ¿À·ù Ç¥½Ã
function error_field(fld, msg) 
{
    if (msg != "")
        errmsg += msg + "\n";
    if (!errfld) errfld = fld;
    fld.style.background = "#BDDEF7";
}

// ÇÊµå¸¦ ±ú²ýÇÏ°Ô
function clear_field(fld) 
{
    fld.style.background = "#FFFFFF";
}

function trim(s)
{
	var t = "";
	var from_pos = to_pos = 0;

	for (i=0; i<s.length; i++)
	{
		if (s.charAt(i) == ' ')
			continue;
		else 
		{
			from_pos = i;
			break;
		}
	}

	for (i=s.length; i>=0; i--)
	{
		if (s.charAt(i-1) == ' ')
			continue;
		else 
		{
			to_pos = i;
			break;
		}
	}	

	t = s.substring(from_pos, to_pos);
	//				alert(from_pos + ',' + to_pos + ',' + t+'.');
	return t;
}

// ÀÚ¹Ù½ºÅ©¸³Æ®·Î PHPÀÇ number_format Èä³»¸¦ ³¿
// ¼ýÀÚ¿¡ , ¸¦ Ãâ·Â
function number_format(data) 
{
	
    var tmp = '';
    var number = '';
    var cutlen = 3;
    var comma = ',';
    var i;
   
    len = data.length;
    mod = (len % cutlen);
    k = cutlen - mod;
    for (i=0; i<data.length; i++) 
	{
        number = number + data.charAt(i);
		
        if (i < data.length - 1) 
		{
            k++;
            if ((k % cutlen) == 0) 
			{
                number = number + comma;
                k = 0;
			}
        }
    }

    return number;
}

// E-Mail °Ë»ç
function email_check(email) 
{
    if (email.value.search(/(\S+)@(\S+)\.(\S+)/) == -1)
        return false;
    else
        return true;
}

// ÁÖ¹Îµî·Ï¹øÈ£ °Ë»ç
function jumin_check(j1, j2) 
{
    if (j1.value.length<6 || j2.value.length<7)
        return false;

    var sum_1 = 0;
    var sum_2 = 0;
    var at=0;
    var juminno= j1.value + j2.value;
    sum_1 = (juminno.charAt(0)*2)+
            (juminno.charAt(1)*3)+
            (juminno.charAt(2)*4)+
            (juminno.charAt(3)*5)+
            (juminno.charAt(4)*6)+
            (juminno.charAt(5)*7)+
            (juminno.charAt(6)*8)+
            (juminno.charAt(7)*9)+
            (juminno.charAt(8)*2)+
            (juminno.charAt(9)*3)+
            (juminno.charAt(10)*4)+
            (juminno.charAt(11)*5);
    sum_2=sum_1%11;

    if (sum_2 == 0) 
	{
        at = 10;
    } 
	else 
	{
        if (sum_2 == 1) 
            at = 11;
		else 
            at = sum_2;
    }
    att = 11 - at;
    if (juminno.charAt(12) != att) 
	{
        return false;
    }

    return true
}

// »õ Ã¢
function popup_window(url, winname, opt)
{
    window.open(url, winname, opt);
}

// ¿ìÆí¹øÈ£ Ã¢
function popup_zip(frm_name, frm_zip1, frm_zip2, frm_addr, rel_dir, top, left)
{
	url = rel_dir+'/zip.php?frm_name='+frm_name+'&frm_zip1='+frm_zip1+'&frm_zip2='+frm_zip2+'&frm_addr='+frm_addr;
	opt = 'scrollbars=yes,width=416,height=250,top='+top+',left='+left;
	popup_window(url, "winzip", opt);
}


// Æû¸ÞÀÏ Ã¢
function popup_formmail(url)
{
	opt = 'scrollbars=yes,width=417,height=500,top=10,left=20';
	popup_window(url, "wformmail", opt);
}

// Å«ÀÌ¹ÌÁö Ã¢
function popup_large_image(it_id, width, height)
{
	var top = 10;
	var left = 10;
	url = "large_image.php?it_id=" + it_id;
	width = width + 50;
	height = height + 50;
	opt = 'scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left;
	popup_window(url, "largeimage", opt);
}

// , ¸¦ ¾ø¾Ø´Ù.
function no_comma(data)
{
	var tmp = '';
    var comma = ',';
    var i;

	for (i=0; i<data.length; i++)
	{
		if (data.charAt(i) != comma)
		    tmp += data.charAt(i);
	}
	return tmp;
}

// »èÁ¦ °Ë»ç È®ÀÎ
function del(href) 
{
  if(confirm("»èÁ¦ÇÑ ÀÚ·á´Â º¹±¸ÇÒ ¼ö ¾ø½À´Ï´Ù.\n\n»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) 
    document.location.href = href;
}

// º¸³»ÁØ ¹®ÀåÀ¸·Î È®ÀÎÇÏ°í ÀÌµ¿
function confirm_msg(msg, href) 
{
  if(confirm(msg)) 
    document.location.href = href;
}

// ÄíÅ° ÀÔ·Â-ÆË¾÷Ã¢ ¿ë
function set_cookie(name, value, expirehours) 
{
	var today = new Date();
	today.setTime(today.getTime() + (60*60*1000*expirehours));
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}

// ÄíÅ° ¾òÀ½
function get_cookie(name) 
{
    var find_sw = false;
    var start, end;
    var i = 0;

	for (i=0; i<= document.cookie.length; i++)
	{
		start = i;
		end = start + name.length;

		if(document.cookie.substring(start, end) == name) 
		{
			find_sw = true
			break
		}
	}

    if (find_sw == true) 
	{
        start = end + 1;
        end = document.cookie.indexOf(";", start);

        if(end < start)
            end = document.cookie.length;

        return document.cookie.substring(start, end);
    }
    return "";
}

// ÄíÅ° Áö¿ò
function delete_cookie(name) 
{
	var today = new Date();

	today.setTime(today.getTime() - 1);
	var value = getCookie(name);
	if(value != "")
		document.cookie = name + "=" + value + "; path=/; expires=" + today.toGMTString();
}

// TEXTAREA »çÀÌÁî º¯°æ
function textarea_size(fld, size)
{
	var rows = parseInt(fld.rows);

	rows += parseInt(size);
	if (rows > 0) {
		fld.rows = rows;
	}
}

// ¹Ù±¸´Ï ¼±ÅÃ ¹ÝÀü
function reverse()
{
   var i, chked=0;
   //if(confirm('ÀüÃ¼ ¼±ÅÃ ÇÏ½Ã°Ú½À´Ï±î? (¼±ÅÃ ¹ÝÀü)'))
   //{
       for(i=0;i<document.list.length;i++)
       {
        if(document.list[i].type=='checkbox')
        {
          if(document.list[i].checked) { document.list[i].checked=false; }
          else { document.list[i].checked=true; }
        }
       }
   //}
   for(i=0;i<document.list.length;i++)
   {
      if(document.list[i].type=='checkbox')
      {
       if(document.list[i].checked) chked=1;
      }
   }
}

// °³ÀÎ¼­Àç¿¡¼­ ¼±ÅÃ µÈ Ã¥ Ã¥Àå ÀÌµ¿ÇÏ±â
function bookStatusChange(type,move_to,sel_bs_code)
{
  var i, chked=0;
  for(i=0;i<document.list.length;i++)
  {
    if(document.list[i].type=='checkbox')
    {
      if(document.list[i].checked) chked=1;
    }
  }
  if(chked)
  {
    document.list.selected.value='';
    for(i=0;i<document.list.length;i++)
    {
      if(document.list[i].type=='checkbox')
      {
        if(document.list[i].checked)
        {
          document.list.selected.value=document.list[i].value+';'+document.list.selected.value;
        }
      }
    }
		if(type=='selmove')
		{
    	if(confirm("¼±ÅÃÇÏ½Å Ã¥ÀåÀ¸·Î ÀÌµ¿ÇÕ´Ï´Ù.")) 
        document.location.href="book_status_change.php?it_id=0&type="+type+"&move_to="+move_to+"&sel_bs_code="+sel_bs_code+"&selected="+document.list.selected.value;
		}
		else if(type=='seldel')
		{
    	if(confirm("¼±ÅÃÇÏ½Å Ã¥À» »èÁ¦ÇÕ´Ï´Ù. »èÁ¦ÇÏ¸é º¹±¸ ÇÒ ¼ö ¾ø½À´Ï´Ù.")) 
        document.location.href="book_status_change.php?it_id=0&type="+type+"&move_to="+move_to+"&sel_bs_code="+sel_bs_code+"&selected="+document.list.selected.value;
		}
  }
  else {alert('¼±ÅÃÇÏ½Å Ã¥ÀÌ ¾ø½À´Ï´Ù.');}
}
// ÀÌ¿ëÀÚ¿¡°Ô ÇÇ¿ì¸®ºÏ ÁõÁ¤ÇÏ±â
function selectedChange(type,url)
{
   var i, royalty=0, chked=0;
   for(i=0;i<document.list.length;i++)
   {
     if(document.list[i].type=='checkbox')
     {
       if(document.list[i].checked) chked=1;
     }
   }
   if(chked)
   {
     document.list.selected.value='';
     for(i=0;i<document.list.length;i++)
     {
      if(document.list[i].type=='checkbox')
      {
        if(document.list[i].checked)
        {
          document.list.selected.value=document.list[i].value+';'+document.list.selected.value;
        }
      }
     }

     if(confirm("¼±ÅÃÇÏ½Å´ë·Î ½ÇÇàÇÒ±î¿ä?")) 
        document.location.href=url+"&type="+type+"&selected="+document.list.selected.value;
   }
   else {alert('³×¸ðÄ­À» vÃ¼Å©ÇÏ°Å³ª ¼±ÅÃ ±ÛÀÚ¸¦ Å¬¸¯ÇÏ¼¼¿ä.');}
}

function siteFavorite(url, name)
{
    if(!url)
        window.external.AddFavorite('http://piuri.com', 'ÀüÀÚÃ¥°ú ÇÔ²² Áñ°Å¿î ¼¼»ó, ÇÇ¿ì¸®!')
    else
        window.external.AddFavorite(url, name)
}
function siteHome(url)
{
    sethome.style.behavior='url (#default#homepage)';
    if(!url)
        sethome.setHomePage('http://piuri.com');
    else
        sethome.setHomePage(url);
}

var rolling_book_mouseEvent=1;
// banner_roll("divÅÂ±× id", ¹è³Ê1°³³ôÀÌ, µô·¹ÀÌ, ÀÌµ¿¼Óµµ ¼ýÀÚ°¡ ³ôÀ¸¸é ºü¸§, 0);
function banner_roll(div_id, banner_height, banner_delay, banner_speed, this_height, org_call)
{
	if(eval(rolling_book_mouseEvent)){
		var div_tag = document.getElementById(div_id);
		var span_tag, i;

		if(banner_speed<1)
			banner_speed=1;

		this_height+=banner_speed;
		// ÃÖÃÊ ºÒ·¶À» ¶§´Â Á» ´õ ±æ°Ô ¼­ ÀÖ±â À§ÇØ
		if(org_call == 1)
		{
			setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", 0, 0);", 7000);
		} else if(this_height < banner_height) {
			div_tag.style.top = -this_height;
			setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", " + this_height + ", 0);", 0);
		} else {
			span_tag = div_tag.getElementsByTagName("SPAN");
			div_tag.appendChild(span_tag[0]);
			div_tag.style.top = 0;
			setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", 0, 0);", banner_delay);
		}
	}
	else
	{
		setTimeout("banner_roll('" + div_id + "', " + banner_height + ", " + banner_delay + ", " + banner_speed + ", " + this_height + ");", banner_speed);
	}
	return true;
}
function show_div_change(lay) 
{ 
	if(this.prev_lay){ 
	  document.getElementById(this.prev_lay).style.display="none"; 
	  document.getElementById(lay).style.display="block"; 
	}else{ 
	  document.getElementById(lay).style.display="block"; 
	} 
  this.prev_lay=lay; 
} 
function sleep(sec) { 
    var now = new Date(); 
    var exitTime = now.getTime() + (sec*1000); 
    while (true) { 
          now = new Date(); 
          if (now.getTime() > exitTime) return; 
    } 
} 
// »óÇ° Ä£±¸¿¡°Ô ÃßÃµÇÏ±â
function popup_item_recommend(it_id)
{
	var top = 10;
	var left = 10;
	var width = 417;
	var height = 420;
	url = "item_recommend.php?it_id=" + it_id;
	opt = 'scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left;
	popup_window(url, "itemrecommend", opt);
}
// »óÇ° Æò°¡ÇÏ±â
function popup_item_value(it_id, mb_id)
{
	var top = 100;
	var left = 100;
	var width = 445;
	var height = 450;
	if(mb_id == "")
	{
			alert("È¸¿ø Àü¿ë ¼­ºñ½º ÀÔ´Ï´Ù.");
			return;
	}
	url = "item_value.php?it_id=" + it_id;
	opt = 'scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left;
	popup_window(url, "itemvalue", opt);
}
function my_lib_go(id)
{
  document.location.href="my_library.php?sel_bs_code="+id;
}
function frmsearch2_check(f)
{
		errmsg = "";
		errfld = "";

		if (f.search_str.value == "")
		{
				check_field(f.search_str, "°Ë»öÇÏ½Ç ´Ü¾î¸¦ ÀÔ·ÂÇÏ½Ê½Ã¿À.");
		}

		if (errmsg) {
				alert(errmsg);
				errfld.focus();
				return false;
		}

		return true;
}
function url_go(url)
{
	if(url)
  	document.location.href=url;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
