// 이메일 체크 *****************************************************************
function emailCheck(str_email)
{
	var pattern = /^(.+)@(.+)$/;
	var atom = "\[^\\s\\(\\)<>#@,;:!\\\\\\\"\\.\\[\\]\]+";
	var word = "(" + atom + "|(\"[^\"]*\"))";
	var user_pattern = new RegExp("^" + word + "(\\." + word + ")*$");
	var ip_pattern = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var domain_pattern = new RegExp("^" + atom + "(\\." + atom +")*$");

	var arr = str_email.match(pattern);
	if (!arr)
		return false;			//"Email address seems incorrect (check @ and .'s)";
	if (!arr[1].match(user_pattern))
		return false;			//"The username doesn't seem to be valid.";

	var ip = arr[2].match(ip_pattern);
	if (ip)
	{
		for (var i=1; i<5; i++)
		{
			if (ip[i] > 255)
				return false;	//"Destination IP address is invalid!";
		}
	}
	else
	{
		if (!arr[2].match(domain_pattern))
			return false;		//"The domain name doesn't seem to be valid.";
		var domain = arr[2].match(new RegExp(atom,"g"));
		if (domain.length < 2)
			return false;		//"This address is missing a hostname!";
		if (domain[domain.length-1].length < 2 || domain[domain.length-1].length > 3)
			return false;		//"The address must end in a three-letter domain, or two letter country.";
	}

	return true;
}

 // 숫자만 *********************************************************************
function digitYN(a)
{
	var allowchar = "0123456789";
	for (i=0 ; i <a.length ; i++)
	{
		if (-1 == allowchar.indexOf(a.charAt(i)))
			return false;
	}
	return true;
}


// 숫자만 입력 (INPUT) *********************************************************
function num_only()
{
	if((event.keyCode < 48) || (event.keyCode > 57))
	{
		event.returnValue=false;
	}
}

// 알파벳 숫자만 ***************************************************************
function alphabetDigitYN(a)
{
	var allowchar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	for (b=0 ; b<a.length ; b++)
	{
		if (-1 == allowchar.indexOf(a.charAt(b)))
			return false;
	}
	return true;
}

// 영문이나 한글만 *************************************************************
function KoreanEnglishYN(a)
{
	with(Math)
	{
		for (b = 0; b < a.length; b++)
		{
			 c = a.charCodeAt(b);
			 if((c >= 97 && c <= 122) || (c >= 65 && c <= 90) || (c == 32) || (c >= 0xAC00 && c <= 0xD7A3))
				 continue;
			 else
				 return false;
		}
	}
	return true;
}

// Input 값 Disable 속성 *******************************************************
function toggleInputValue(input_obj, disable_yn)
{
	if (disable_yn)
	{
		input_obj.value = "";
		input_obj.disabled = true;
		input_obj.className = "disabled";
	}
	else
	{
		input_obj.disabled = false;
		input_obj.className = "txt";
	}
}

// 라디오 버튼 중 선택된 유뮤 **************************************************
function radioCheckedYN(input_obj)
{
	for (i = 0; i < input_obj.length ; i++)
	{
		if (input_obj[i].checked)
			return true;
	}

	return false;
}

// 라디오 인풋의 선택된 값 가져오기 ********************************************
function radioCheckedValue(input_obj)
{
	for (i = 0; i < input_obj.length ; i++)
	{
		if (input_obj[i].checked)
			return input_obj[i].value;
	}

	return "";
}

// 체크박스의 선택된 수 가져오기 ***********************************************
function inputCheckCnt(input_obj)
{
	var cnt = 0;

	for (i = 0; i < input_obj.length ; i++)
	{
		if (input_obj[i].checked)
			cnt += 1;
	}

	return cnt;
}

// 입력없음 체크 & 안내 ********************************************************
function emptyInputYN(input_obj, lable)
{
	var input = input_obj;
	var type = "";
	var type_no = 0;

	type = input_obj.type;

	if (type == undefined && input_obj.length != undefined)
		type = input_obj[0].type;
	else if (type == undefined)
		type_no = 1;

	if (type == undefined)
		type = "";
	else
		type = type.toUpperCase();

	if (type == "TEXT" || type == "HIDDEN" || type == "TEXTAREA" || type == "PASSWORD")
		type_no = 1;
	else if (type == "SELECT-ONE" || type == "SELECT-MULTIPLE")
		type_no = 2;
	else if (type == "RADIO" || type == "CHECKBOX")
		type_no = 3;

	if(type_no == 1 && input_obj.value == '')
	{
		alert("Enter " + lable + '.');
		if (!input_obj.readOnly && !input_obj.disabled)
			input_obj.focus();
		return true;
	}
	else if (type_no == 2 && input_obj.value == '')
	{
		alert("Select " + lable + '.');
		input_obj.focus();
		return true;
	}
	else if (type_no == 3)
	{
		if (input_obj.length > 1)
		{
			if (!radioCheckedYN(input_obj))
			{
				alert("Select " + lable + '.');
				input_obj[0].focus();
				return true;
			}
		}
	}
	else
		return false;
}

// 최소길이 & 안내 *************************************************************
function lengthCheckYN(input_obj, lable, num)
{
	if(emptyInputYN(input_obj, lable) || input_obj.value.length < num)
	{
		alert('Enter ' + lable + ' More Than ' + num + ' Character.');
		input_obj.focus();
		return false;
	}
	return true;
}


// 브라우저 체크 ***************************************************************
function BrowserIEYN()
{
	var isOpera, isIE = false;
	if(typeof(window.opera) != 'undefined')
		isOpera = true;
	if(!isOpera && navigator.userAgent.indexOf('MSIE') >= 0)
		isIE = true;

	return isIE;
}

