
///////////////////////////////////////////
//
//	FORM Object Check Function
//
///////////////////////////////////////////

/*
 TextField ÀÇ °ªÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö °Ë»çÇÏ¿© ¸Þ¼¼Áö¸¦ »Ñ·ÁÁØ´Ù.
 return °ªÀÌ flase ÀÏ¶§´Â °ªÀÌ ¾øÀ» °æ¿ì ÀÌ¸ç,
 return °ªÀÌ true ÀÏ¶§´Â °ªÀÌ ÀÖÀ» °æ¿ì ÀÌ´Ù.
*/
function TextCheck(item, message) {
	
	var strMemo = item.value;
	var resultMemo = strMemo.split(" ");
	
	if (!item.value || (strMemo.length + 1 == resultMemo.length)) {
		alert(message);
		item.focus();
		return false;	// °ªÀÌ ¾øÀ» °æ¿ì
	}
	return true;		// °ªÀÌ ÀÖÀ» °æ¿ì
}

/*
 Select Ç®´Ù¿î ¹Ú½º¸¦ ¼±ÅÃ Çß´ÂÁö °Ë»çÇÏ¿© ¸Þ¼¼Áö¸¦ »Ñ·ÁÁØ´Ù.
 return °ªÀÌ flase ÀÏ¶§ ¼±ÅÃ µÇÁö ¾ÊÀº °æ¿ì ÀÌ¸ç,
 return °ªÀÌ true ÀÏ¶§´Â ¼±ÅÃµÇ¾úÀ» °æ¿ì ÀÌ´Ù.
 
*/
function SelectCheck(item, message) {
	if (item.selectedIndex == 0) {
		alert(message);
		item.focus();
		return false;	// ¼±ÅÃÀ» ÇÏÁö ¾Ê¾ÒÀ» °æ¿ì
	}
	return true;		// ¼±ÅÃÀ» ÇÏ¿´À» °æ¿ì
	
}


/*
 CheckBox ¿Í Radio ÀÇ Ã¼Å©¸¦ °Ë»çÇÑ´Ù.
 return °ªÀÌ flase ÀÌ¸é ¾Æ¹«°Íµµ ¼±ÅÃµÇÁö ¾ÊÀº °ÍÀÌ¸ç,
 return °ªÀÌ true ÀÌ¸é ÇÏ³ªÀÌ»óÀÌ ¼±ÅÃµÈ °æ¿ì ÀÌ´Ù.
*/
function CheckBoxRadioCheck(item,message)
{
	var i, flag=true;
	
	if(item.length > 0) {
		for (i=0; i<item.length; i++) {
			if (item[i].checked == true) {
				flag = false;
			}
		}
	} else {
		if (item.checked == true) {
			flag = false;
		}
	}
	
	if (flag) {
		alert(message);
		if(item.length > 0) {
			item[0].focus();
		} else {
			item.focus();
		}
		return false;
	} else {
		return true;
	}
}

function impword(impstr,invalue) {
	
	impstr_array = impstr.split(",");
	
	for(i=0;i<impstr_array.length;i++) {
		if(impstr_array[i] == invalue) return false;
	}
	
	return true;
}

// ÁÖ¹Î¹øÈ£ Ã¼Å©
function check_juminno(jumin1,jumin2) {
	if(jumin1.value=="" || jumin2.value=="" || jumin1.value.length!=6 || jumin2.value.length!=7) {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£¸¦ Àû¾îÁÖ¼¼¿ä.");
	        return false;
	}

	var yy     = jumin1.value.substr(0,2);  // ³âµµ
	var mm     = jumin1.value.substr(2,2);        // ¿ù
	var dd     = jumin1.value.substr(4,2);        // ÀÏ
	var genda  = jumin2.value.substr(0,1);        // ¼ºº°
	var msg, ss, cc;
	
	// ¼ýÀÚ°¡ ¾Æ´Ñ °ÍÀ» ÀÔ·ÂÇÑ °æ¿ì
	if (!isNumeric(jumin1.value)) {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ¼ýÀÚ·Î ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin1.value = "";
	        jumin1.focus();
	        return false;
	}
	// ±æÀÌ°¡ 6ÀÌ ¾Æ´Ñ °æ¿ì
	if (jumin1.value.length != 6) {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin1.value = "";
	        jumin1.focus();
	        return false;
	}
	// Ã¹¹øÂ° ÀÚ·á¿¡¼­ ¿¬¿ùÀÏ(YYMMDD) Çü½Ä Áß ±âº» ±¸¼º °Ë»ç
	if (yy < "00" || yy > "99" ||
	        mm < "01" || mm > "12" ||
	        dd < "01" || dd > "31") {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin1.value = "";
	        jumin1.focus();
	        return false;
	}
	// ¼ýÀÚ°¡ ¾Æ´Ñ °ÍÀ» ÀÔ·ÂÇÑ °æ¿ì
	if (!isNumeric(jumin2.value)) {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®¸¦ ¼ýÀÚ·Î ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin2.value = "";
	        jumin2.focus();
	        return false;
	}
	// ±æÀÌ°¡ 7ÀÌ ¾Æ´Ñ °æ¿ì
	if (jumin2.value.length != 7) {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin2.value = "";
	        jumin2.focus();
	        return false;
	}
	// ¼ºº°ºÎºÐÀÌ 1 ~ 4 °¡ ¾Æ´Ñ °æ¿ì
	if (genda < "1" || genda > "4") {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin2.value = "";
	        jumin2.focus();
	        return false;
	}
	// ¿¬µµ °è»ê - 1 ¶Ç´Â 2: 1900³â´ë, 3 ¶Ç´Â 4: 2000³â´ë
	cc = (genda == "1" || genda == "2") ? "19" : "20";
	// Ã¹¹øÂ° ÀÚ·á¿¡¼­ ¿¬¿ùÀÏ(YYMMDD) Çü½Ä Áß ³¯Â¥ Çü½Ä °Ë»ç
	if (isYYYYMMDD(parseInt(cc+yy), parseInt(mm), parseInt(dd)) == false) {
	        alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin1.value = "";
	        jumin1.focus();
	        return false;
	}
	// Check Digit °Ë»ç
	if (!isSSN(jumin1.value, jumin2.value)) {
	        alert("ÀÔ·ÂÇÑ ÁÖ¹Îµî·Ï¹øÈ£¸¦ °ËÅäÇÑ ÈÄ, ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
	        jumin1.value = "";
	        jumin2.value = "";
	        jumin1.focus();

	        return false;
	}
	return true;
}

function isYYYYMMDD(y, m, d) {
	switch (m) {
	case 2:        // 2¿ùÀÇ °æ¿ì
	        if (d > 29) return false;
	        if (d == 29) {
	                // 2¿ù 29ÀÇ °æ¿ì ´çÇØ°¡ À±³âÀÎÁö¸¦ È®ÀÎ
	                if ((y % 4 != 0) || (y % 100 == 0) && (y % 400 != 0))
	                        return false;
	        }
	        break;
	case 4:        // ÀÛÀº ´ÞÀÇ °æ¿ì
	case 6:
	case 9:
	case 11:
	        if (d == 31) return false;
	}
	// Å« ´ÞÀÇ °æ¿ì
	return true;
}

function isNumeric(s) {
	for (i=0; i<s.length; i++) {
	        c = s.substr(i, 1);
	        if (c < "0" || c > "9") return false;
	}
	return true;
}

function isLeapYear(y) {
	if (y < 100)
	y = y + 1900;
	if ( (y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0) ) {
	        return true;
	} else {
	        return false;
	}
}

function getNumberOfDate(yy, mm) {
	month = new Array(29,31,28,31,30,31,30,31,31,30,31,30,31);
	if (mm == 2 && isLeapYear(yy)) mm = 0;
	return month[mm];
}

function isSSN(s1, s2) {
	n = 2;
	sum = 0;
	for (i=0; i<s1.length; i++)
	        sum += parseInt(s1.substr(i, 1)) * n++;
	for (i=0; i<s2.length-1; i++) {
	        sum += parseInt(s2.substr(i, 1)) * n++;
	        if (n == 10) n = 2;
	}
	c = 11 - sum % 11;
	if (c == 11) c = 1;
	if (c == 10) c = 0;
	if (c != parseInt(s2.substr(6, 1))) return false;
	else return true;
}

//ÀÓ½Ã·Î

function layermenu(str,objid) {	
	//alert(event.type);
	var strhtml = "";
	
	mx = event.x + document.body.scrollLeft;
	my = event.y + document.body.scrollTop;
	
	spaninfo = document.getElementById(objid);
	spaninfo.style.position="absolute";
	spaninfo.style.left=mx+"px";
	spaninfo.style.top=my+"px";
	spaninfo.style.zIndex = "10";
	if(str) spaninfo.style.display = "";
	else spaninfo.style.display = "none";
	
	strhtml += "<table  border='0' bgcolor='#999999' cellspacing='1' cellpadding='3'>";
	strhtml += "<tr>";
  	strhtml += "<td valign='top' style='font-size:9pt' bgcolor='#F8F8F8'>"+str+"</td>";
	strhtml += "</tr>";
	strhtml += "</table>";
	
	spaninfo.innerHTML = strhtml;
}

function layerinfo(str,objid) {
	
	//alert(event.type);
	var strhtml = "";
	
	mx = event.x + document.body.scrollLeft;
	my = event.y + document.body.scrollTop;
	
	spaninfo = document.getElementById(objid);
	spaninfo.style.position="absolute";
	spaninfo.style.left=mx+"px";
	spaninfo.style.top=my+"px";
	spaninfo.style.zIndex = "1";
	if(str) spaninfo.style.display = "";
	else spaninfo.style.display = "none";
	
	strhtml += "<table border='0' bgcolor='#999999' cellspacing='1' cellpadding='3'>";
	strhtml += "<tr>";
  	strhtml += "<td valign='top' style='font-size:9pt' bgcolor='#F8F8F8'>"+str+"</td>";
	strhtml += "</tr>";
	strhtml += "</table>";

	
	spaninfo.innerHTML = strhtml;
}

function layerinfox(str,objid) {
	
	var strhtml = "";
	var lwidth = 250;
	
	mx = event.x + document.body.scrollLeft;
	my = event.y + document.body.scrollTop;
	
	spaninfo = document.getElementById(objid);
	spaninfo.style.position="absolute";
	spaninfo.style.left=mx+"px";
	spaninfo.style.top=my+"px";
	spaninfo.style.zIndex = "1";
	if(str) spaninfo.style.display = "";
	else spaninfo.style.display = "none";
	
	strhtml += "<table border='0' width='"+lwidth+"' bgcolor='#999999' cellspacing='1' cellpadding='3'>";
	strhtml += "<tr>";
  	strhtml += "<td valign='top' style='font-size:9pt' bgcolor='#F0F0F0' align='right'><a style='cursor:hand' Onclick=\"layerinfo('','"+objid+"')\">¡¿</a></td>";
	strhtml += "</tr>";
	strhtml += "<tr>";
  	strhtml += "<td valign='top' style='font-size:9pt' bgcolor='#F8F8F8'>"+str+"</td>";
	strhtml += "</tr>";
	strhtml += "</table>";

	
	spaninfo.innerHTML = strhtml;
}