/*------------------------------------------------------------
  ÀÛ¼ºÀÏÀÚ : 2003³â 4¿ù 16ÀÏ ¿ÀÀü 12½Ã 10ºÐ
  ÀÛ ¼º ÀÚ : º¯ÁøÈñ, jinhui5@hanmail.net

  ÆÄÀÏÀ§Ä¡ : /global/shared/function/scripts/
  ÆÄ ÀÏ ¸í : Default.js
  ³»    ¿ë : ÀÚÁÖ »ç¿ëµÇ´Â Java Script Function
------------------------------------------------------------*/

var doc;
var frm;
var strScriptPath;

// Window OnLoad Event
function window.onload() { Initialize(); }

// Ä¿¼­ÀÇ ½ºÅ¸ÀÏÀ» ÇÚµå·Î º¯°æÇÑ´Ù.
function Hand(obj) { obj.style.cursor = 'hand'; }

// ¹è°æ»öÀ» º¯°æÇÑ´Ù.
function ChangeBGColor(obj, color) { obj.style.background = color; }

// ÆùÆ®»öÀ» º¯°æÇÑ´Ù.
function ChangeFTColor(obj, color) { obj.style.color = color; }

// ÄÁÆ®·Ñ Å¬¸¯
function ClickCtrl(ctrl) { ctrl.click(); }

/*------------------------------------------------------------
  Ã¼Å©¹Ú½º(CheckBox) °ü·Ã ÇÔ¼öµé
------------------------------------------------------------*/

// Æû¾ÈÀÇ ¸ðµç Ã¼Å©¹Ú½ºÀÇ »óÅÂ¸¦ bln À¸·Î º¯°æÇÑ´Ù.
function ChangeAllCheckBox(frm, bln)
{
	var element = frm.elements;

	for (var i = 0; i < element.length; i++)
		if (element[i].type == "checkbox")
			element[i].checked = bln;
}

// µ¿¸íÀÇ ¸ðµç Ã¼Å©¹Ú½ºÀÇ »óÅÂ¸¦ bln À¸·Î º¯°æÇÑ´Ù.
function ChangeAllCheckBox2(chk, bln)
{
	if (!chk.length) chk.checked = bln;
	else
	{
		for (var i = 0; i < chk.length; i++)
			chk[i].checked = bln;
	}
}

// Æû¾ÈÀÇ Ã¼Å©¹Ú½ºÀÇ °³¼ö¸¦ ¸®ÅÏÇÑ´Ù.
function GetCheckBoxCount(frm)
{
	var element = frm.elements;
	var cnt = 0;

	for (var i = 0; i < element.length; i++)
		if (element[i].type == "checkbox") cnt++;

	return cnt;
}

// Æû¾ÈÀÇ Ã¼Å©µÈ Ã¼Å©¹Ú½ºÀÇ °³¼ö¸¦ ¸®ÅÏÇÑ´Ù.
function GetCheckedBoxCount(frm)
{
	var element = frm.elements;
	var cnt = 0;

	for (var i = 0; i < element.length; i++)
		if (element[i].type == "checkbox" && element[i].checked == true) cnt++;
	
	return cnt;
}

// µ¿¸íÀÇ Ã¼Å©¹Ú½º Áß Ã¼Å©µÈ ¼ö¸¦ ¸®ÅÏÇÑ´Ù.
function GetCheckedBoxCount2(chk)
{
	var cnt = 0;

	if (!chk.length)
	{
		if (chk.checked) cnt = 1;
	}
	else
	{
		for (var i = 0; i < chk.length; i++)
		{
			if (chk[i].checked) cnt++;
		}
	}

	return cnt;
}

// Æû¾ÈÀÇ Ã¼Å©µÈ Ã¼Å©¹Ú½ºÀÇ °ªÀ» split ·Î ¿¬°áÇØ ¸®ÅÏÇÑ´Ù.
// Ã¼Å©µÈ Ã¼Å©¹Ú½º°¡ ¾øÀ¸¸é null À» ¸®ÅÏÇÑ´Ù.
function GetCheckedBoxValues(frm, split)
{
	var element = frm.elements;
	var strRtn = null;

	for (var i = 0; i < element.length; i++)
		if (element[i].type == "checkbox" && element[i].checked)
			if (!strRtn) strRtn = element[i].value;
			else strRtn += split + element[i].value;

	return strRtn;
}

// µ¿¸íÀÇ Ã¼Å©¹Ú½º Áß Ã¼Å©µÈ °ªÀ» split ·Î ¿¬°áÇØ ¸®ÅÏÇÑ´Ù.
function GetCheckedBoxValues2(chk, split)
{
	var strRtn = null;

	if (!chk.length)
	{
		if (chk.checked) strRtn = chk.value;
	}
	else
	{
		for (var i = 0; i < chk.length; i++)
		{
			if (chk[i].checked)
				if (!strRtn) strRtn = chk[i].value;
				else strRtn += split + chk[i].value;
		}
	}

	return strRtn;
}

/*------------------------------------------------------------
  ¶óµð¿À¹öÆ°(Radio) °ü·Ã ÇÔ¼öµé
------------------------------------------------------------*/

// ¶óµð¿À ¹öÆ°ÀÇ value ¸¦ °Ë»öÇÏ¿© ÀÏÄ¡ÇÏ´Â ¶óµð¿À ¹öÆ°À» ¼±ÅÃÇÑ´Ù.
function CheckByValue(ctl, val)
{
	for (var i = 0; i < ctl.length; i++)
		if (ctl[i].value.toLowerCase() == val.toLowerCase())
		{
			ctl[i].checked = true;
			break;
		}
}

// Ã¼Å©µÈ ¶óµð¿À ¹öÆ°ÀÇ °ªÀ» ¸®ÅÏÇÑ´Ù.
function GetRadioValue(ctl)
{
	var val = "";

	for (var i = 0; i < ctl.length; i++)
	{
		if (ctl[i].checked)
		{
			val = ctl[i].value;
			break;
		}
	}

	return val;
}

// Ã¼Å©µÈ ¶óµð¿À ¹öÆ°ÀÇ °ª2À» ¸®ÅÏÇÑ´Ù.
function GetRadioValue2(ctl)
{
	var val = "";

	for (var i = 0; i < ctl.length; i++)
	{
		if (ctl[i].checked)
		{
			val = ctl[i].value2;
			break;
		}
	}

	return val;
}

/*------------------------------------------------------------
  ÄÞº¸¹Ú½º(Select) °ü·Ã ÇÔ¼öµé
------------------------------------------------------------*/

// Select¿¡ ¿É¼ÇÀ» Ãß°¡ÇÑ´Ù.
function AddOption(ctl, txt, val)
{
	var opt = new Option(txt, val);
	ctl.options[ctl.options.length] = opt;
}

// SelectBoxÀÇ ¿É¼ÇÀ» Á¦°ÅÇÑ´Ù.
function RemoveOption(ctl)
{
	if (RemoveOption.arguments[1]) ctl.options.length = 0;
	else ctl.options[ctl.selectedIndex] = null;
}

// SelectÀÇ ¿É¼ÇµéÀÇ °ªÀ» split ·Î ¿¬°áÇØ ¸®ÅÏÇÑ´Ù.
// Select¿¡ ¿É¼ÇÀÌ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é null À» ¸®ÅÏÇÑ´Ù.
function GetSelectValues(ctl, split)
{
	var strRtn = null;

	for (var i = 0; i < ctl.options.length; i++)
		if (!strRtn) strRtn = ctl.options[i].value;
		else strRtn += split + ctl.options[i].value;

	return strRtn;
}

// SelectÀÇ ¿É¼Ç value ¸¦ °Ë»öÇÏ¿© ÀÏÄ¡ÇÏ´Â ¿É¼ÇÀ» ¼±ÅÃÇÑ´Ù.
function SelectByValue(ctl, val)
{
	for (var i = 0; i < ctl.options.length; i++)
		if (ctl.options[i].value.toLowerCase() == val.toLowerCase())
		{
			ctl.options[i].selected = true;
			break;
		}
}

// SelectÀÇ ¿É¼Ç text ¸¦ °Ë»öÇÏ¿© ÀÏÄ¡ÇÏ´Â ¿É¼ÇÀ» ¼±ÅÃÇÑ´Ù.
function SelectByText(ctl, txt)
{
	for (var i = 0; i < ctl.options.length; i++)
		if (ctl.options[i].text.toLowerCase() == txt.toLowerCase())
		{
			ctl.options[i].selected = true;
			break;
		}
}

// SelectÀÇ °ªÀÌ "" ¶Ç´Â "_line_" ÀÏ °æ¿ì 0¹øÂ° OptionÀ» ¼±ÅÃÇÑ´Ù.
function ChkSelect(ctl)
{
	if (ctl.value == "" || ctl.value == "_line_")
		ctl.options[0].selected = true;
}

/*------------------------------------------------------------
  ±âÅ¸ ÇÔ¼öµé
------------------------------------------------------------*/

// ¹®ÀÚ¿­¿¡ Æ¯¼ö¹®ÀÚ°¡ ÀÖ´ÂÁö¸¦ Ã¼Å©ÇÑ´Ù.
// Æ¯¼ö¹®ÀÚ°¡ Æ÷ÇÔµÇ¾î ÀÖÀ¸¸é true ¸¦ ¸®ÅÏÇÑ´Ù.
function CheckSpChr(str)
{
	var char;
	var bln = false;

	for (var i = 0; i < str.length; i ++)
	{
		char = str.charCodeAt(i);
		if ((char >= 0 && char <= 47) || (char >= 58 && char <= 64) ||
			(char >= 91 && char <= 96) || (char >= 123 && char <= 127))
		{
			bln = true;
			break;
		}
	}

	return bln;
}

// ¹®ÀÚ¿­¿¡ 2¹ÙÀÌÆ®ÀÇ ¹®ÀÚ°¡ Æ÷ÇÔµÇ¾î ÀÖ´ÂÁö Ã¼Å©ÇÑ´Ù.
// Æ÷ÇÔµÇ¾î ÀÖÀ¸¸é true ¸¦ ¸®ÅÏÇÑ´Ù.
function Check2Chr(str)
{
	var s = new String(str);
	var l = s.length;
	var bRtn = false;

	for (var i = 0; i < l; i++)
	{
		var temp = s.charAt(i);

		if (escape(temp).length > 4)
		{
			bRtn = true;
			break;
		}
	}

	return bRtn;
}

// ¹®ÀÚ¿­¿¡ °ø¹éÀÌ ÀÖ´ÂÁö¸¦ Ã¼Å©ÇÑ´Ù.
function CheckSpace(str)
{
	return (str.indexOf(" ") > -1);
}

// ¸Þ½ÃÁö(msg)¸¦ º¸³»°í ÄÁÆ®·Ñ(ctl)ÀÌ Æ÷Ä¿½º¸¦ °¡Áø´Ù.
function Alert(msg)
{
	alert(msg);
	if (Alert.arguments[1]) Active(Alert.arguments[1]);
}

// ÄÁÆ®·Ñ(ctl)ÀÌ Æ÷Ä¿½º¸¦ °¡Áø´Ù.
function Active(ctl)
{
	ctl.focus();

	if (ctl.type.toLowerCase() == "text" || ctl.type.toLowerCase() == "textarea")
		if (ctl.value.length > 0) ctl.select();
}

// ÇØ´ç ³â, ¿ùÀÇ ¸¶Áö¸· ÀÏÀ» ¸®ÅÏÇÑ´Ù.
function CalcLastDay(y, m)
{
	var lstDay;

	switch (parseInt(m))
	{
		case 1: case 3: case 5: case 7: case 8: case 10: case 12:
		{
			lstDay = 31;
			break;
		}
		case 4: case 6: case 9: case 11:
		{
			lstDay = 30;
			break;
		}
		case 2:
		{
			if ((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0)) lstDay = 29;
			else lstDay = 28;
			break;
		}
	}
	
	return lstDay;
}

// ¼ýÀÚ¿¡ ÀûÇÕÇÑÁö¸¦ Ã¼Å©ÇÑ´Ù.
function IsNumeric(str)
{
	return (!isNaN(str) && !CheckSpace(str) && str.length > 0)
}

// URL ¿¡¼­ ÆÄÀÏ¸íÀ» Á¦¿ÜÇÑ URL À» °¡Á®¿Â´Ù.
function GetURL(url)
{
	return (url.substr(0, url.lastIndexOf("/") + 1));
}

// URL ¿¡¼­ ÆÄÀÏ¸íÀ»¸¸ °¡Á®¿Â´Ù.
function GetFileFullName(url)
{
	return (url.substr(url.lastIndexOf("/") + 1));
}

// ÆÄÀÏ¸í¿¡¼­ È®ÀåÀÚ¸¦ Á¦¿ÜÇÑ ¸í¸¸ °¡Á®¿Â´Ù.
function GetFileName(fname)
{
	return (fname.substr(0, fname.lastIndexOf(".")));
}

// ÆÄÀÏ¸í¿¡¼­ È®ÀåÀÚ¸¦ °¡Á®¿Â´Ù.
function GetFileExt(fname)
{
	return (fname.substr(fname.lastIndexOf(".") + 1));
}
/*------------------------------------------------------------
  À©µµ¿ì °ü·Ã ÇÔ¼öµé
------------------------------------------------------------*/

// ÆäÀÌÁö ÀÌµ¿
function Go(t) { self.history.go(t); }

// ÆäÀÌÁö¸¦ ÀÌµ¿ÇÑ´Ù.
// url          : ÆäÀÌÁö URL
// arguments[1] : ÀÌµ¿ÇÒ À©µµ¿ì
// arguments[2] : ÆäÀÌÁö ÀÌµ¿ ¹æ¹ý
function Move(url)
{
	var wnd = (Move.arguments[1] ? Move.arguments[1] : self);
	var pmt = (Move.arguments[2] ? Move.arguments[2] : 0);

	if (pmt == 0) wnd.location.href = url;
	else if (pmt == 1) wnd.location.replace(url);
}

// ÆäÀÌÁö¸¦ ¸®·ÎµåÇÑ´Ù.
// arguments[0] : ¸®·ÎµåÇÒ À©µµ¿ì
function ReloadWnd()
{
	var wnd = (ReloadWnd.arguments[0] ? ReloadWnd.arguments[0] : self);
	wnd.location.reload();
}

// À©µµ¿ì ±¸Á¶
function CWnd()
{
	this.url = "";
	this.name = "";
	this.width = 0;
	this.height = 0;
	this.left = 0;
	this.top = 0;
	this.toolbar = "no";
	this.menubar = "no";
	this.scrollbars = "no";
}

// À©µµ¿ì ¿ÀÇÂ
function OpenWnd(wnd)
{
	var opt = "width=" + String(wnd.width) + ", height=" + String(wnd.height) +
		", left=" + String(wnd.left) + ", top=" + String(wnd.top) + 
		", toolbar=" + wnd.toolbar + ", menubar=" + wnd.menubar +
		", scrollbars=" + wnd.scrollbars

	return window.open(wnd.url, wnd.name, opt);
}

// À©µµ¿ì Å¬·ÎÁî
function CloseWnd(wname)
{
	wname.close();
}

// Ã¢ÀÌ ½ºÅ©¸°ÀÇ °¡¿îµ¥ ¿Àµµ·Ï Left À§Ä¡¸¦ ¸®ÅÏÇÑ´Ù.
function SetWndL2C(width)
{ return (screen.width / 2) - (width / 2); }

// Ã¢ÀÌ ½ºÅ©¸°ÀÇ °¡¿îµ¥ ¿Àµµ·Ï Top À§Ä¡¸¦ ¸®ÅÏÇÑ´Ù.
function SetWndT2C(height)
{ return (screen.height / 2) - (height / 2); }

// Show Object
function Show(obj)
{ if (obj.style.display != "block") obj.style.display = "block"; }

// Hide Object
function Hide(obj)
{ if (obj.style.display != "none") obj.style.display = "none"; }

/*------------------------------------------------------------
  ÁÖ¹Î¹øÈ£/»ç¾÷ÀÚ¹øÈ£ °ü·Ã ÇÔ¼öµé
------------------------------------------------------------*/

// ÁÖ¹Îµî·Ï¹øÈ£¸¦ °Ë»çÇÑ´Ù.
// ¿Ã¹Ù¸¥ ÁÖ¹Îµî·Ï¹øÈ£ÀÌ¸é true ¸¦ ¸®ÅÏÇÑ´Ù.
function CheckRegNo(reg_string)
{
	var a = reg_string.substring(6, 7);
	var sum;
	var num;

	if (a < '1' || a > '4') return false;
	else
	{
		sum = 0;
		num = 2;

		for(var i = 0; i < 12; i++)
		{
			a = reg_string.substring(i, i + 1);
			sum = sum + num * (a - '0');
			num++;
			if( num == 10 ) num = 2;
		}

		i = (11 - (sum % 11)) % 10;
		a = reg_string.substring(12, 13);

		return (a == i);
	}
}

// »ç¾÷ÀÚ¹øÈ£ Ã¼Å©
function CheckBizNo(biz_string)
{
	var rtn = false;
	var sumMod = 0;

	if (biz_string.length > 0 && biz_string.length == 10)
	{
		sumMod += parseInt(biz_string.substring(0, 1));
		sumMod += parseInt(biz_string.substring(1, 2)) * 3 % 10;
		sumMod += parseInt(biz_string.substring(2, 3)) * 7 % 10;
		sumMod += parseInt(biz_string.substring(3, 4)) * 1 % 10;
		sumMod += parseInt(biz_string.substring(4, 5)) * 3 % 10;
		sumMod += parseInt(biz_string.substring(5, 6)) * 7 % 10;
		sumMod += parseInt(biz_string.substring(6, 7)) * 1 % 10;
		sumMod += parseInt(biz_string.substring(7, 8)) * 3 % 10;
		sumMod += Math.floor(parseInt(biz_string.substring(8, 9)) * 5 / 10);
		sumMod += parseInt(biz_string.substring(8, 9)) * 5 % 10;
		sumMod += parseInt(biz_string.substring(9, 10));

		if (sumMod % 10 == 0) rtn = true;
	}

	return rtn;
}

// ³¯Â¥Ã¼Å©
// dt : 0000-00-00
function ChkDate(dt)
{
	var y;
	var m;
	var d;
	var s1;
	var s2;

	if (dt == "" || dt.length != 10)
		return false;
	else
	{
		y = dt.substr(0, 4);
		m = dt.substr(5, 2);
		d = dt.substr(8, 2);
		s1 = dt.substr(4, 1);
		s2 = dt.substr(7, 1);

		if (!IsNumeric(y) || Number(y) < 1000) return false;
		else if (!IsNumeric(m) || Number(m) < 1 || Number(m) > 12) return false;
		else if (!IsNumeric(d) || Number(d) < 1 || Number(d) > 31) return false;
		else if (s1 != "-") return false;
		else if (s2 != "-") return false;
		else return true;
	}
}

// È¸¿ø ÇÁ·ÎÇÊ º¸±â
function ViewUserProfile(uid)
{
	var wUserProfile = new CWnd();

	with (wUserProfile)
	{
		url = "/user/userprofile.asp?struid=" + uid + "&btag=0";
		name = "wnUserProfile";
		width = 300;
		height = 300;
		//left = SetWndL2C(width);
		//top = SetWndT2C(height);
		left = 0;
		top = 0;
		toolbar = "no";
		menubar = "no";
		scrollbars = "no";
	}

	OpenWnd(wUserProfile);
}

// ÀçÇÐ»ý ÇÁ·ÎÇÊ º¸±â
function ViewStudProfile(studno)
{
	var wStudProfile = new CWnd();

	with (wStudProfile)
	{
		url = "/user/studprofile.asp?strstudno=" + studno;
		name = "wnStudProfile";
		width = 300;
		height = 300;
		left = 0;
		top = 0;
		toolbar = "no";
		menubar = "no";
		scrollbars = "no";
	}

	OpenWnd(wStudProfile);
}

// Á¹¾÷»ý ÇÁ·ÎÇÊ º¸±â
function ViewGradProfile(studno)
{
	var wGradProfile = new CWnd();

	with (wGradProfile)
	{
		url = "/user/gradprofile.asp?strstudno=" + studno;
		name = "wnGradProfile";
		width = 300;
		height = 300;
		left = 0;
		top = 0;
		toolbar = "no";
		menubar = "no";
		scrollbars = "no";
	}

	OpenWnd(wGradProfile);
}

// Å¬·´ È¸¿ø ÇÁ·ÎÇÊ º¸±â
function ViewClubMemberProfile(cid, uid)
{
	var wClubMemberProfile = new CWnd();

	with (wClubMemberProfile)
	{
		url = "/community/club/member/clubmemberprofile.asp?strcid=" + cid + "&struid=" + uid;
		name = "wnClubMemberProfile";
		width = 300;
		height = 300;
		left = 0;
		top = 0;
		toolbar = "no";
		menubar = "no";
		scrollbars = "no";
	}

	OpenWnd(wClubMemberProfile);
}


function assert_msglen(msg, max_len)
{
	var nbytes = 0;
	var onechar;
	var msgLen = msg.length;

	for(k=0;k<msgLen;k++) {
		onechar = msg.charAt(k);

		if(escape(onechar).length > 4)	//ÇÑ±Û Ã¼Å©
			nbytes += 2;
		else
			nbytes++;

		if(nbytes>max_len) {					//¸Þ¼¼Áö ÀÚ¸£±â
			msg = msg.substring(0, k);
			break;
		}
	}
	return msg;
}

function Cal_Length(msg)
{
	var nbytes = 0;
	var cnt=0;

	for (i = 0; i < msg.length; i++) {
		var ch = msg.charAt(i);
		
		if (escape(ch).length > 4) {
			nbytes += 2;
			nbytes -= cnt;
		}
		else {
			nbytes++;
		}
	}
	return nbytes;
}

function cal_byte(max_len, frm)
{
	var formCbyte;		//ÇöÀç ¹ÙÀÌÆ® InputBox
	var msgLen=0;		//Àü¼Û¸Þ¼¼Áö ±æÀÌ

	msgLen  = Cal_Length(frm.value);//snd_msg ±æÀÌ Ã¼Å©

	if (msgLen > max_len) {
		window.alert("ÇØ´ç ¶õ¿¡´Â "+max_len+"¹ÙÀÌÆ® ÀÌ»ó ÀÔ·ÂÇÒ¼ö ¾ø½À´Ï´Ù.  \r\nÃÊ°úµÈ ºÎºÐÀº »èÁ¦µË´Ï´Ù.");
		frm.value	= assert_msglen(frm.value, max_len);
		return;
	}
}