String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g,""); 
}


var strChars = "1234567890";
var strDBConflict = "'\"&%";


function containsCharsOnly(input,chars) {
    for (var inx = 0; inx < input.value.length; inx++) {
       if (chars.indexOf(input.value.charAt(inx)) == -1)
           return false;
    }
    return true;
}


function isAlphaNumeric(str) {
	for (i = 0; i < str.length; i++) {
		c = str.charAt(i);
		
		if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) {
			return false;
		}
	}

	return true;
}


function isLowerAlphaNumeric(str) {
	for (i = 0; i < str.length; i++) {
		c = str.charAt(i);
		
		if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || c== '-')) {
			return false;
		}
	}

	return true;
}

function numericCheck(objField, strDescription, blnBit)
{

	if (textFieldCheckAdmin(objField, strDescription, blnBit) == false) return false;

	if (decimalFieldCheckAdmin(objField, strDescription, blnBit) == false) return false;
	
	return true;
}

function textLengthFix(objField, theLength, message) {
	if (objField.value.length != theLength) {
		alert(message + " " + theLength + "자를 입력해야 합니다.");
		objField.focus();
		return false;			
	}
	
	return true;
}

function textLengthCheck(objField, theLimit, message) {
	if (objField.value.length > theLimit) {
		alert(message + " " + theLimit + "자까지만 쓸 수 있습니다.");
		objField.value = objField.value.substring(0, theLimit);
		objField.focus();
		return false;			
	}
	
	return true;
}

function textLengthLimit(objField, theLimit, message) {
	if (objField.value.length > theLimit) {
		alert(message + " " + theLimit + "자까지만 쓸 수 있습니다.");
		objField.value = objField.value.substring(0, theLimit);
		return;			
	}
}

function textLengthRange(objField, theMin, theMax, message) {
	if (objField.value.length < theMin || objField.value.length > theMax) {
		alert(message + " " + theMin + "~" + theMax + "자를 입력해야 합니다.");
		objField.focus();
		return false;			
	}
	
	return true;
}

function textFieldCheck(objField, strDescription, blnBit)
{

	if (blnBit == 0) 
	{
		if (objField.value.length == 0 || objField.value.split(" ").join("") == "" || objField.value.trim() == "")
		{
			alert(strDescription + "를 입력하세요."); objField.focus(); return false;
		}
	}
	else 
	{
		if (objField.value.length == 0 || objField.value.split(" ").join("") == "" || objField.value.trim() == "")
		{
			alert(strDescription + "을 입력하세요."); objField.focus(); return false;
		}
	}
	return true;
}


function hiddenFieldCheck(objField, strDescription, blnBit)
{

	if (blnBit == 0) //마지막 글자에 받침이 없는 경우
	{
		if (objField.value.length == 0 || objField.value.split(" ").join("") == "")
		{
			alert(strDescription + "를 체크하세요."); return false;
		}
	}
	else 
	{
		if (objField.value.length == 0 || objField.value.split(" ").join("") == "")
		{
			alert(strDescription + "을 체크하세요."); return false;
		}
	}
	return true;
}


function decimalFieldCheck(objField, strDescription, blnBit)
{

	if (blnBit == 0) 
	{
		if (!containsCharsOnly(objField,strChars))
		{
			alert(strDescription + "는 숫자만 입력할 수 있습니다."); objField.focus(); objField.select(); return false;
		}
	}
	else 
	{
		if (!containsCharsOnly(objField,strChars))
		{
			alert(strDescription + "은 숫자만 입력할 수 있습니다."); objField.focus(); objField.select(); return false;
		}	
	}
	return true;
}


function initNumericCombo(combobox, startValue, endValue, stepValue)
{

	var tempValue;
	var comboLength = parseInt(((endValue - startValue)) / stepValue) + 1;
	
	combobox.length = comboLength;
	
	for (var i = 0; i < comboLength; i++)
	{
		tempValue = startValue + stepValue * i
		combobox.options[i].value = tempValue;
		if (tempValue < 10)
			combobox.options[i].text = "0" + tempValue;
		else
			combobox.options[i].text = tempValue;
	}
}

function selectCombo(combobox, selectValue)
{

	var comboLength = combobox.length;
	for (var i = 0; i < comboLength; i++)
	{
		if (combobox.options[i].value == selectValue)
		{
			combobox.options.selectedIndex = i;
			break;
		}
	}
}

function emailCheck(strEmail)
{

	var supported = 0
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr))
			supported = 1
	}
	
	if (!supported)
	{
		return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
	}
	else
	{
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		return (!r1.test(strEmail) && r2.test(strEmail));
	}
}

function juminNoCheck(juminNo1, juminNo2)
{
	a1 = juminNo1.substring(0, 1);
		aa1 = a1 * 2;
	a2 = juminNo1.substring(1, 2);
		aa2 = a2 * 3;
	a3 = juminNo1.substring(2, 3);
		aa3 = a3 * 4;
	a4 = juminNo1.substring(3, 4);
		aa4 = a4 * 5;
	a5 = juminNo1.substring(4, 5);
		aa5 = a5 * 6;
       a6 = juminNo1.substring(5, 6);
		aa6 = a6 * 7;
       b1 = juminNo2.substring(0, 1);
		bb1 = b1 * 8;
       b2 = juminNo2.substring(1, 2);
		bb2 = b2 * 9;
       b3 = juminNo2.substring(2, 3);
		bb3 = b3 * 2;
       b4 = juminNo2.substring(3, 4);
		bb4 = b4 * 3;
       b5 = juminNo2.substring(4, 5); 
		bb5 = b5 * 4;
       b6 = juminNo2.substring(5, 6);
		bb6 = b6 * 5;
   
	pivot = juminNo2.substring(6,7);
   
	sum = aa1 + aa2 + aa3 + aa4 + aa5 + aa6 + bb1 + bb2 + bb3 + bb4 + bb5 + bb6;
	modulus = sum % 11
	endnumber = 11 - modulus
      
	if (endnumber == 11)
	{
		endnumber = 1;
	} 
	else if (endnumber == 10)
	{ 
		endnumber = 0;
	}
	else
	{
		endnumber = endnumber;
	}
	
	if (pivot != endnumber)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isTextAreaDefault(obj, defaultValue) {
	if (obj.value.trim() == defaultValue) {
		return true;
	} else {
		return false;
	}
}

function onFocusTextArea(obj, defaultValue) {
	if (obj.value.trim() == defaultValue) {
		obj.value = "";
	}
}

function onBlurTextArea(obj, defaultValue) {
	if (obj.value.trim() == "") {
		obj.value = defaultValue;
	}
}