// Àü¿ª º¯¼ö
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=385,top=10,left=20';
	popup_window(url, "wformmail", opt);
}

// Å«ÀÌ¹ÌÁö Ã¢
function popup_large_image(it_id, img, width, height, cart_dir)
{
	var top = 10;
	var left = 10;
	url = "./?doc="+cart_dir+"/largeimage.php&it_id=" + it_id + "&img=" + img;
	width = width + 50;
	height = height + 70;
	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 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 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_zip(frm_name, frm_zip1, frm_zip2, frm_addr1, frm_addr2, dir, top, left)
{
    url = './?doc='+dir+'/mbzip.php&frm_name='+frm_name+'&frm_zip1='+frm_zip1+'&frm_zip2='+frm_zip2+'&frm_addr1='+frm_addr1+'&frm_addr2='+frm_addr2;
    opt = 'scrollbars=yes,width=417,height=250,top='+top+',left='+left;
    window.open(url, "mbzip", opt);
}

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

// a ÅÂ±×¿¡¼­ onclick ÀÌº¥Æ®¸¦ »ç¿ëÇÏÁö ¾Ê±â À§ÇØ
function winopen(url, name, option)
{
    window.open(url, name, option);
    return ;
}

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

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

var old='';
function menu(name){

	submenu=eval(name+".style");

	if (old!=submenu)
	{
		if(old!='')
		{
			old.display='none';
		}
		submenu.display='block';
		old=submenu;
	}
	else
	{
		submenu.display='none';
		old='';
	}
}

// URL ÀÌµ¿
function gourl(href) 
{
	document.location.href = href;
}

// option¿¡¼­ º¯È­°¡ ¹ß»ýÇÏ¸é ±×°ªÀ» ³Ö¾îÁØ´Ù.
function chk_code(fname, oname)
{
	var tsel = fname;
	var tname = oname;

	for (var i=0; i < tsel.length; i++)
	{
		if ( tsel[i].selected )
			tname.value = tsel[i].value;
	}
}

//
// option ¼±ÅÃ¿¡ µû¸¥ º¯È­¸¦ ³Ö¾îÁÖ±â À§ÇÑ ÇÔ¼ö
// fname¿¡ º¯È­°ªÀ» oname¿¡ ³Ö¾îÁÜ.
//
function chk_option(fname, oname)
{
	var tsel = fname;
	var tname = oname;

	for (var i=0; i < tsel.length; i++)
	{
		if ( tsel[i].selected )
			tname.value = tsel[i].value;
	}
}

//
// selected µÈ °ªÀ» ³Ö´Â´Ù.
// sel: ¼±ÅÃµÈ °Í, seld: Áý¾î³ÖÀ» °÷
//
var ary  = [];
function select_add (sel, seld, tn)
{
	var len  = seld.length;
	var find = false;


	for (i=0; i<len; i++)
	{
		if ( sel.options[sel.selectedIndex].value == seld.options[i].value )
		{
			find = true;
			break;
		}
	}

	if (!find)
	{
		seld.length += 1;
		seld.options[len].value = sel.options[sel.selectedIndex].value;
		seld.options[len].text  = sel.options[sel.selectedIndex].text;
	}
	
	relation_hidden(seld,tn)
}

// selected µÈ °ªÀ» ³Ö´Â´Ù.
function select_del (sel, tn)
{
	var len  = sel.length;
	var find = false;

	for (i=0; i<sel.length; i++)
	{
		if (sel.options[i].value == sel.options[sel.selectedIndex].value)
		{
			for (k=i; k<sel.length-1; k++)
			{
				sel.options[k].value = sel.options[k+1].value;
				sel.options[k].text  = sel.options[k+1].text;
			}
			break;
		}
	}
	sel.length -= 1;
	
	relation_hidden(sel,tn)
}

// hidden °ªÀ» º¯°æ
function relation_hidden(seld, val)
{
	var str = '';
	var comma = '';
	var apo = '\'';
	
	for (i=0; i<seld.length; i++)
	{
		str += comma + apo + seld.options[i].value + apo;
		comma = ',';
	}
	val.value = str;
}

//
// Radio ¹öÆ°ÀÇ »óÅÂ¿¡ µû¶ó ¹Ú½ºÀÇ disable/enable
//
function checkDisable(f)
{
  //document.next.rdoOrigin[0].checked;
  f.style.background="#EFEFEF";
  f.value="";
  f.disabled=true;
}

function checkEnable(f)
{
  //document.next.rdoOrigin[1].checked;
  f.style.background="white";
  f.value="";
  f.disabled=false;
  f.focus();
}

// 3.36
function image_window(img, w, h)
{
    var tmp_w = w;
    var tmp_h = h;
    winl = (screen.width-w)/2;
    wint = (screen.height-h)/3;

    if (w >= screen.width) {
        winl = 0;
        w = screen.width - 10;
        h = (parseInt)(w * (h / w));
    }

    if (h >= screen.height) {
        wint = 0;
        h = screen.height - 80;
        w = (parseInt)(h * (w / h));
    }

    var settings  ='width='+w+',';
        settings +='height='+h+',';
        settings +='top='+wint+',';
        settings +='left='+winl+',';
        settings +='scrollbars=no,';
        settings +='resizable=no,';
        settings +='status=no';

    win=window.open("","newWindow",settings);
    win.document.open();
    win.document.write ("<html><head><meta http-equiv='content-type' content='text/html; charset=euc-kr'>");
    win.document.write ("<title>ÀÌ¹ÌÁö º¸±â</title></head>");
    win.document.write ("<body leftmargin=0 topmargin=0>");
    //win.document.write ("<img src='"+img+"' width='"+w+"' height='"+h+"'border=0 onclick='window.close();' style='cursor:hand' title='ÇØ»óµµ ("+tmp_w+"x"+tmp_h+")\nÅ¬¸¯ÇÏ¸é ´ÝÇô¿ä'>");
    win.document.write ("<img src='"+img+"' width='"+w+"' height='"+h+"'border=0 onclick='window.close();' style='cursor:hand'>");
    win.document.write ("</body></html>");
    win.document.close();

    if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}