//============================================================================================'
// ³»  ¿ë: JavaScript¿ë °ø¿ë Library
// ¸¸µçÀÌ: ³ë°æÇõ
// °»½ÅÀÏ: 2003/06/30
// º¯  °æ: ÄíÅ° set,clear,control ÇÔ¼ö Ãß°¡ÇÔ(2003/11/19 Á¤ÈÆ¿µ)
//============================================================================================'

function showMsg(obj, msg1, msg2) {
	alert(msg1 + msg2);
	obj.focus();
	obj.select();
	return;
}

function trim(str) {
	var endlength = str.length;
	var a = 0;
	var b =0;
	while( a == 0) {
		a = str.indexOf(" ");
		if(a != 0)break;
		str = str.substring(a+1,endlength);
	}
	while( str.lastIndexOf(" ") > str.length -2) {
		b = str.lastIndexOf(" ");
		if(b == -1)break;
		str = str.substring(0,b);
	}
	return str;
}

function isEmpty(bErrDisp, obj , msg)
{
	var str = obj.value;
	var chkstr = trim(str);

	if ( ( chkstr == "") || ( chkstr == null ) || (chkstr.substr(0,1) == " "))
	{
		if (bErrDisp)
		{
			alert( msg +" ÀÔ·ÂÇÏ¼¼¿ä.");
			obj.focus();
			obj.select();
		}
		return true ;
	}
	return false;
}

function chkSpace(bErrDisp, obj, msg)
{
	if (obj.value.indexOf(" ") >= 0)
	{
		if (bErrDisp)
		{
			alert(msg + " ºóÄ­¾øÀÌ ºÙ¿©¾²¼¼¿ä.");
			obj.focus();
			obj.select();
		}
		return true;
	}
	return false;
}

function isAlphabet(bErrDisp, obj, msg)
{
	var chkstrArray = obj.value.match(/[A-Za-z]/ig);

	if (chkstrArray != null)
	{
		if (chkstrArray.length == obj.value.length)
		{
			return true;
		}
	}
	if (bErrDisp)
	{
		alert( msg +" ¿µ¹®À¸·Î¸¸ ÀÔ·ÂÇÏ¼¼¿ä.");
		obj.focus();
		obj.select();
	}
	return false;
}

function isNumeric(bErrDisp, obj, msg)
{
	var chkintArray = obj.value.match(/[0-9]/ig);
	if (chkintArray != null)
	{
		if (chkintArray.length == obj.value.length)
		{
			return true;
		}
	}
	if (bErrDisp)
	{
		alert( msg +" ¼ýÀÚ·Î ÀÔ·ÂÇÏ¼¼¿ä.");
		obj.focus();
		obj.select();
	}
	return false;
}

function isNumAlpha(bErrDisp, obj, msg)
{
	var chkstrArray = obj.value.match(/[A-Za-z0-9]/ig);

	if (chkstrArray != null)
	{
		if (chkstrArray.length == obj.value.length)
		{
			return true;
		}
	}
	if (bErrDisp)
	{
		alert( msg +" ¿µ¹®°ú ¼ýÀÚ·Î¸¸ ÀÔ·ÂÇÏ¼¼¿ä.");
		obj.focus();
		obj.select();
	}
	return false;
}

function chkQuotation(bErrDisp, obj, msg)
{
	if (obj.value.indexOf("\"") >= 0)
	{
		if (bErrDisp)
		{
			alert(msg + "\"¸¦ ÀÔ·ÂÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
			obj.focus();
			obj.select();
		}
		return true;
	}
	return false;
}

function isValidEmail(bErrDisp, obj, msg)
{
	var emailsArray = obj.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
	if (emailsArray == null)
	{
		if (bErrDisp)
		{
			alert( msg + " Á¤È®È÷ ÀÔ·ÂÇÏ¼¼¿ä.");
			obj.focus();
			obj.select();
		}
		return false;
	}
	return true;
}

function chkSelect(bErrDisp, obj, msg, nullValue)
{
	var idx = obj.selectedIndex;
	if (obj[idx].value == nullValue)
	{
		if (bErrDisp)
		{
			alert(msg + " ¼±ÅÃÇÏ¼¼¿ä.");
		}
		return true;
	}
	return false;
}

function chkRadio(bErrDisp, obj, msg) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked)
			return false;
	}
	if (bErrDisp)
	{
		alert(msg + " ¼±ÅÃÇÏ¼¼¿ä.");
	}
	return true;
}

function getNDigit(iValue, iDigit) {
	var sValue = iValue, iRef;

	for (var i = 2; i <= iDigit; i++)	{
		iRef = 1;
		for (var j=1; j < i; j++) {iRef = iRef * 10;}
		if (iValue < iRef) sValue = "0" + sValue;
	}
	return sValue;
}

function getCookie_1DIM(Name) {
  var search = Name + "="
  if (document.cookie.length > 0) { // ÄíÅ°°¡ ¼³Á¤µÇ¾î ÀÖ´Ù¸é
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // ÄíÅ°°¡ Á¸ÀçÇÏ¸é
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset)
      // ÄíÅ° °ªÀÇ ¸¶Áö¸· À§Ä¡ ÀÎµ¦½º ¹øÈ£ ¼³Á¤
      if (end == -1)
        end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
}

function getCookie_2DIM(name0,name1) {

   if (name0=='MGAMEJS'||name0=='MGAME')
   {
	   if(name1=='AGE'||name1=='SEX'||name1=='TYPE')
	   {
			var cookieValue_Name0 = getCookie_1DIM('MGAMEIF');
			if (cookieValue_Name0 == null||cookieValue_Name0=='undefined') {
				return "";
			}
			if(name1=='AGE')
		   {
			   return cookieValue_Name0.substring(11,13);
		   }
		   /* Ã¼Çè¾ÆÀÌµð Ã¼Å©¿ë Ãß°¡ - 2007.05.08 ¹Ú¼º¿í */
		   else if(name1=='TYPE')
		   {
			   return cookieValue_Name0.substring(18,22);
		   }
		   else
		   {
			   return cookieValue_Name0.substring(1,2);
		   }
	   }
   }

   var cookieValue_Name0 = getCookie_1DIM(name0);

   if (cookieValue_Name0 == null) {
	   return;
   }

   var cookieValue_Name1 = cookieValue_Name0.split("&");
   var repStr = name1 + "=";
   for (var i = 0; i < cookieValue_Name1.length; i++) {
		if (cookieValue_Name1[i].indexOf(repStr) >= 0) {
			var tmpStr = new RegExp(repStr, "gi");
			return cookieValue_Name1[i].replace(tmpStr,"");
		}
   }
}

function getCookie(name1, name2) {
   var cname = name1 + "=";
   if (name1=='MGAMEJS'||name1=='MGAME')
   {
	   if(name2=='AGE'||name2=='SEX')
	   {
			var cookieValue_Name0 = getCookie_1DIM('MGAMEIF');
			if (cookieValue_Name0 == null||cookieValue_Name0=='undefined') {
				return "";
			}
		   if(name2=='AGE')
		   {
			   return cookieValue_Name0.substring(11,14);
		   }
		   else
		   {
			   return cookieValue_Name0.substring(1,2);
		   }
	   }
   }

	var vars = document.cookie;
 	if (vars.length > 0) {
		begin = vars.indexOf(cname);
		if (begin != -1) {
			if ((name2 == null) || (name2.length == 0)) {
		   		begin += cname.length;
		   		end = vars.indexOf(";", begin);
		  		if (end == -1) end = vars.length;
					return unescape(vars.substring(begin, end));
			} else {
				cname = name1 + "=" + name2 + "=";
				begin = vars.indexOf(cname, begin);
				if (begin == -1) {
					cname = "&" + name2 + "=";
					begin = vars.indexOf(cname, begin);
				}
				if (begin != -1) {
					begin += cname.length;
					end = vars.indexOf("&", begin);
					if (end == -1) {
				   		end = vars.indexOf(";", begin);
				  		if (end == -1) end = vars.length;
					}
					return unescape(vars.substring(begin, end));
				}
			}

	   	}
 	}
	return null;
}

//¼³Á¤ÇÑ ³¯Â¥¸¸Å­ ÄíÅ°°¡ À¯ÁöµÇ°Ô. expiredays°¡ 1ÀÌ¸é ÇÏ·çµ¿¾È À¯Áö
function setCookie(name, value, expiredays)	{
	var expire_date = new Date();
	expire_date.setDate(expire_date.getDate() + expiredays );
	if(value == 0)
		document.cookie = name + "=" + escape( value ) + "; path=/; domain=mgame.com";
	else
		document.cookie = name + "=" + escape( value ) + "; expires=" + expire_date.toGMTString() + "; path=/; domain=mgame.com";
 }

//ÄíÅ° ¼Ò¸ê ÇÔ¼ö
function clearCookie(name) {
    var expire_date = new Date();
    //¾îÁ¦ ³¯Â¥¸¦ ÄíÅ° ¼Ò¸ê ³¯Â¥·Î ¼³Á¤ÇÑ´Ù.
    expire_date.setDate(expire_date.getDate() - 1000)
    //document.cookie = name + "=; expires=" + expire_date.toGMTString() + "; path=/"
    document.cookie = name + "=;";
}

//Ã¼Å© »óÅÂ¿¡ µû¶ó ÄíÅ° »ý¼º°ú ¼Ò¸êÀ» Á¦¾îÇÏ´Â ÇÔ¼ö
function controlCookie(elemnt,cookieName) {
	if (elemnt.checked) {
		//Ã¼Å© ¹Ú½º¸¦ ¼±ÅÃÇßÀ» °æ¿ì ÄíÅ° »ý¼º ÇÔ¼ö È£Ãâ

		setCookie(cookieName,"true", 1)
		window.close()
	}
	else {
		//Ã¼Å© ¹Ú½º¸¦ ÇØÁ¦ÇßÀ» °æ¿ì ÄíÅ° ¼Ò¸ê ÇÔ¼ö È£Ãâ
		clearCookie(cookieName)
	}
	return
}

function wclose() {
		window.close()
}

function getQueryField(name) {
	var cname = name + "=";
	var vars = location.search;
 	if (vars.length > 0) {
		begin = vars.indexOf(cname);
 		if (begin != -1) {
	   		begin += cname.length;
	   		end = vars.indexOf("&", begin);
	  		if (end == -1) end = vars.length;
	   		return unescape(vars.substring(begin, end));
	   	}
 	}
	return null;
}

function chkResID(bErrDisp, objFront, objBack, msg) {
	var re1, re2;
	var result;

	if (objFront.value.match(/^[0-9]{6}$/ig) == null) {
		if (bErrDisp) { showMsg(objFront, msg, "ÁÖ¹Îµî·Ï¹øÈ£(¿Ü±¹ÀÎµî·Ï¹øÈ£)¸¦ Á¤È®ÇÏ°Ô ÀÔ·ÂÇÏ¼¼¿ä."); }
		return false;
	}
	if (objBack.value.match(/^[0-9]{7}$/ig) == null) {
		if (bErrDisp) { showMsg(objBack, msg, "ÁÖ¹Îµî·Ï¹øÈ£(¿Ü±¹ÀÎµî·Ï¹øÈ£)¸¦ Á¤È®ÇÏ°Ô ÀÔ·ÂÇÏ¼¼¿ä."); }
		return false;
	}

	var chk = 0;
	var yy = parseInt(objFront.value.substring(0,2));
	var mm = parseInt(objFront.value.substring(2,4));
	var dd = parseInt(objFront.value.substring(4,6));
	var sex = parseInt(objBack.value.substring(0,1));

	var tToday = new Date();
	var curYear = tToday.getYear();
	var bIsValid = true;
	if (mm <1 || mm>12 || dd<1 || dd>31) bIsValid = false;
	if (sex == 1 || sex == 2) if (yy < 10)  bIsValid = false;
	if (sex == 3 || sex == 4) if (yy > (curYear%100))  bIsValid = false;
	if (bIsValid = false) {
		if (bErrDisp) { showMsg(objFront, msg, "ÁÖ¹Îµî·Ï¹øÈ£¸¦ Á¤È®ÇÏ°Ô ÀÔ·ÂÇÏ¼¼¿ä."); }
		return false;
	}

	if ((sex >= 1) && (sex <= 4)) { // ³»±¹ÀÎ
		for (var i = 0; i <=5 ; i++)
			chk = chk + ((i%8+2) * parseInt(objFront.value.substring(i,i+1)));
		for (var i = 6; i <=11 ; i++)
			chk = chk + ((i%8+2) * parseInt(objBack.value.substring(i-6,i-5)));
		chk = 11 - (chk %11);
		chk = chk % 10;
		if (chk != objBack.value.substring(6,7)) {
			if (bErrDisp) { showMsg(objFront, msg, "ÁÖ¹Îµî·Ï¹øÈ£°¡ À¯È¿ÇÏÁö ¾Ê½À´Ï´Ù."); }
			return false;
		}
	} else { // ¿Ü±¹ÀÎ
		var sum = 0;
		var odd = 0;
		var reg_no = objFront.value + objBack.value;

		buf = new Array(13);
		for (i = 0; i < 13; i++) buf[i] = parseInt(reg_no.charAt(i));

		odd = buf[7]*10 + buf[8];
		if (odd%2 != 0) {
			if (bErrDisp) { showMsg(objFront, msg, "¿Ü±¹ÀÎµî·Ï¹øÈ£°¡ À¯È¿ÇÏÁö ¾Ê½À´Ï´Ù."); }
			return false;
		}

		if ((buf[11] != 6)&&(buf[11] != 7)&&(buf[11] != 8)&&(buf[11] != 9)) {
			if (bErrDisp) { showMsg(objFront, msg, "¿Ü±¹ÀÎµî·Ï¹øÈ£°¡ À¯È¿ÇÏÁö ¾Ê½À´Ï´Ù."); }
			return false;
		}

		multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
		for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);
		sum=11-(sum%11);
		if (sum>=10) sum-=10;
		sum += 2;
		if (sum>=10) sum-=10;

		if ( sum != buf[12]) {
			if (bErrDisp) { showMsg(objFront, msg, "¿Ü±¹ÀÎµî·Ï¹øÈ£°¡ À¯È¿ÇÏÁö ¾Ê½À´Ï´Ù."); }
			return false;
		}
	}
	return true;
}

function getLenB(str){
	var sum = 0;

	var k;
	for(var i = 0; i < str.length; i++){
		k = str.charCodeAt(i) ;
		if(k >= 0 && k <= 255)
			sum += 1;
		else
			sum += 2;
	}
	return sum;
}

function kor_left(str, len)
{
	var str2	= '';
	var len2	= 0;
	for(tti=0;tti<str.length;tti++)
	{
		var charval	= str.charAt(tti);

		if(charval < String.fromCharCode(0) || charval > String.fromCharCode(255))
			len2	+= 2;
		else
			len2	+= 1;

		if(len2 <= len)
			str2	+= charval;
	}

	if(str2.length != str.length)
		str2 = str2.substring(0, str2.length-2) + ' ..';

	return str2;
}

function RTableTopHTML(strLineColor, strBodyColor, strWidth, intInnerWidth) {
	document.write("<table cellpadding=0 cellspacing=0 border=0 width=" + strWidth + " ><tr height=1><td rowspan=4 width=1></td><td rowspan=3 width=1></td><td rowspan=2 width=1></td><td width=2></td><td bgcolor=" + strLineColor + "></td><td width=2></td><td rowspan=2 width=1></td><td rowspan=3 width=1></td><td rowspan=4 width=1></td></tr><tr height=1><td bgcolor=" + strLineColor + "></td><td bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td></tr><tr height=1><td bgcolor=" + strLineColor + "></td><td colspan=3 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td></tr><tr height=2><td bgcolor=" + strLineColor + "></td><td colspan=5 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td></tr></table><table cellpadding=0 cellspacing=0 border=0 width=" + strWidth + " ><tr><td width=1 bgcolor=" + strLineColor + "></td><td valign=top bgcolor=" + strBodyColor + "><table cellpadding=0 cellspacing=0 border=0 width=100%><tr height=" + (((intInnerWidth - 5) < 0) ? 0 : intInnerWidth - 5) + "><td></td></tr><tr><td width=" + intInnerWidth + "></td><td >");
}

function RTableTopHTML2(strLineColor, strBodyColor, strWidth) {
	document.write("<table cellpadding=0 cellspacing=0 border=0 width=" + strWidth + " ><tr height=1><td rowspan=4 width=1></td><td rowspan=3 width=1></td><td rowspan=2 width=1></td><td width=2></td><td bgcolor=" + strLineColor + "></td><td width=2></td><td rowspan=2 width=1></td><td rowspan=3 width=1></td><td rowspan=4 width=1></td></tr><tr height=1><td bgcolor=" + strLineColor + "></td><td bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td></tr><tr height=1><td bgcolor=" + strLineColor + "></td><td colspan=3 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td></tr><tr height=2><td bgcolor=" + strLineColor + "></td><td colspan=5 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td></tr></table>");
}

function RTableBottomHTML(strLineColor, strBodyColor, strWidth, intInnerWidth) {
	document.write("</td><td width=" + intInnerWidth + "></td></tr><tr height=" + (((intInnerWidth - 5) < 0) ? 0 : intInnerWidth - 5) + "><td></td><td bgcolor=" + strBodyColor + "></td><td></td></tr></table></td><td width=1 bgcolor=" + strLineColor + "></td></tr></table><table cellpadding=0 cellspacing=0 border=0 width=" + strWidth + " ><tr height=2><td rowspan=4 width=1></td><td width=1 bgcolor=" + strLineColor + "></td><td width=1 bgcolor=" + strBodyColor + "></td><td width=2 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strBodyColor + "></td><td width=2 bgcolor=" + strBodyColor + "></td><td width=1 bgcolor=" + strBodyColor + "></td><td width=1 bgcolor=" + strLineColor + "></td><td rowspan=4 width=1></td></tr><tr height=1><td rowspan=3></td><td bgcolor=" + strLineColor + "></td><td colspan=3 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td><td rowspan=3></td></tr><tr height=1><td rowspan=2></td><td bgcolor=" + strLineColor + "></td><td bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td><td rowspan=2></td></tr><tr height=1><td></td><td bgcolor=" + strLineColor + "></td><td></td></tr></table>");
}

function RTableBottomHTML2(strLineColor, strBodyColor, strWidth) {
	document.write("<table cellpadding=0 cellspacing=0 border=0 width=" + strWidth + " ><tr height=2><td rowspan=4 width=1></td><td width=1 bgcolor=" + strLineColor + "></td><td width=1 bgcolor=" + strBodyColor + "></td><td width=2 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strBodyColor + "></td><td width=2 bgcolor=" + strBodyColor + "></td><td width=1 bgcolor=" + strBodyColor + "></td><td width=1 bgcolor=" + strLineColor + "></td><td rowspan=4 width=1></td></tr><tr height=1><td rowspan=3></td><td bgcolor=" + strLineColor + "></td><td colspan=3 bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td><td rowspan=3></td></tr><tr height=1><td rowspan=2></td><td bgcolor=" + strLineColor + "></td><td bgcolor=" + strBodyColor + "></td><td bgcolor=" + strLineColor + "></td><td rowspan=2></td></tr><tr height=1><td></td><td bgcolor=" + strLineColor + "></td><td></td></tr></table>");
}

function RTableBeforeBodyHTML(strLineColor, strBodyColor, strWidth, intInnerWidth) {
	document.write("<table cellpadding=0 cellspacing=0 border=0 width=" + strWidth + " ><tr><td width=1 bgcolor=" + strLineColor + "></td><td valign=top bgcolor=" + strBodyColor + "><table cellpadding=0 cellspacing=0 border=0 width=100%><tr height=" + (((intInnerWidth - 5) < 0) ? 0 : intInnerWidth - 5) + "><td></td></tr><tr><td width=" + intInnerWidth + "></td><td >");
}

function RTableAfterBodyHTML(strLineColor, strBodyColor, strWidth, intInnerWidth) {
	document.write("</td><td width=" + intInnerWidth + "></td></tr><tr height=" + (((intInnerWidth - 5) < 0) ? 0 : intInnerWidth - 5) + "><td></td><td bgcolor=" + strBodyColor + "></td><td></td></tr></table></td><td width=1 bgcolor=" + strLineColor + "></td></tr></table>");
}

function MGMidButton(strText, strLink, intWidth) {
	var strHTML = "<table border=0 cellpadding=0 cellspacing=0 onMouseOver=\"this.style.cursor='hand'\">";
	strHTML += "<tr><td><img src=/images/btn_common_head.gif width=11 height=25 border=0></td>";
	strHTML += "<td background=/images/btn_common_body.gif width=" + intWidth + " align=center valign=Middle><a href=\""+strLink+"\"><font style=\"font-family: µ¸¿ò; font-size: 12px\">" + strText + "</a></td>";
	strHTML += "<td><img src=/images/btn_common_tail.gif width=2 height=25 border=0></td></tr></table>";
	document.write(strHTML);
}

function MGIcoButton(strText, strLink, intWidth) {
	var strHTML = "<table border=0 cellpadding=0 cellspacing=0 onMouseOver=\"this.style.cursor='hand'\">";
	strHTML += "<tr><td><img src=/images/btn_icon_small_head.gif width=20 height=21 border=0></td>";
	strHTML += "<td background=/images/btn_icon_small_body.gif width=" + intWidth + " align=center valign=Middle><a href=\""+strLink+"\"><font style=\"font-family: µ¸¿ò; font-size: 12px\">" + strText + "</a></td>";
	strHTML += "<td><img src=/images/btn_icon_small_tail.gif width=8 height=21 border=0></td></tr></table>";
	document.write(strHTML);
}
//admin@worldcafe.co.kr