/* 유효성 검사 */

function isEmpty( data ) {
   for ( var i = 0 ; i < data.length ; i++ )    {
      if ( data.substring( i, i+1 ) == " " )
         return true;
   }
   return false;
}
	
function CheckID(str) 
{
    var chk = true
      	
	for (i=0; i <= str.length -1 ; i++)
	{
                ch = str.substring(i,i+1);
                if ((ch >= "0" && ch <= "9") || (ch >= "a"  && ch <= "z") ||(ch >= "A"  && ch <= "Z")) {
                	chk = true;
                } else {
                	chk = false;
                	break;
                }	
	}
	
        return chk;
}

function CheckFile(str) 
{
    var chk = true
      	
	for (i=0; i <= str.length -1 ; i++)
	{
                ch = str.substring(i,i+1);
                if (ch == "\\" || ch == "/" || ch == "*" || ch == "?" || ch == "<" || ch == ">" || ch == "\|" || ch == "\:") {
                	chk = false;
                	break;
                } else {
                	chk = true;
                }	
	}
	
        return chk;
}

function checkValid(txtBox) 
{
    //var str = txtBox.value + String.fromCharCode(event.keyCode);
    var str = txtBox.value;
     	
	for (i=0; i < str.length; i++)
	{
				if (str.charCodeAt(i)  > 255) {
					alert("영문자와 숫자의 조합만 사용할 수 있습니다.");
					txtBox.value = "";
					return false;
                } else {
                	ch = str.charAt(i);
                	if (!((ch >= "0" && ch <= "9") || (ch >= "a"  && ch <= "z") ||(ch >= "A"  && ch <= "Z"))) {
                		alert("영문자와 숫자의 조합만 사용할 수 있습니다.");
                		txtBox.value = "";
                		return false;
                	}	
                }
	}

	return true;
}

function checkNum(txtBox) 
{
	if(isNaN(txtBox.value + String.fromCharCode(event.keyCode))) {
		alert("숫자를 입력해 주세요");
		event.keyCode = 0;
	}
}

function checkEmail(evalue) 
{
	
	var chk = true
	
	if(evalue.search(/^[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+)*@[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*(\.[a-zA-Z-][a-zA-Z-]+)$/) == -1){
	    	chk = false;
	}

	return chk;

}


function checkRegId(regid)
{
	var reg1 = regid.substring(0,6);
	var reg2 = regid.substring(6,13);
	var tmp = 0;
	
  	for (var i = 0; i <=5 ; i++)
		tmp = tmp + ((i%8+2) * parseInt(reg1.substring(i,i+1)))
 
	for (var i = 6; i <=11 ; i++)
        tmp = tmp + ((i%8+2) * parseInt(reg2.substring(i-6,i-5)))

	tmp = 11 - (tmp %11)
  	tmp = tmp % 10

  	if (tmp != reg2.substring(6,7))
  	{
    	return false;
  	} else {
  		return true;	
  	}
	
}

function checkPayId(payid)
{
	var biz_value=new Array(10);
	var li_temp, li_lastid;

	//유효성 검사 루틴 적용  ex)111-11-11111
	biz_value[0] = ( parseFloat(payid.substring(0 ,1)) * 1 ) % 10; 
	biz_value[1] = ( parseFloat(payid.substring(1 ,2)) * 3 ) % 10; 
	biz_value[2] = ( parseFloat(payid.substring(2 ,3)) * 7 ) % 10; 
	biz_value[3] = ( parseFloat(payid.substring(3 ,4)) * 1 ) % 10; 
	biz_value[4] = ( parseFloat(payid.substring(4 ,5)) * 3 ) % 10; 
	biz_value[5] = ( parseFloat(payid.substring(5 ,6)) * 7 ) % 10; 
	biz_value[6] = ( parseFloat(payid.substring(6 ,7)) * 1 ) % 10; 
	biz_value[7] = ( parseFloat(payid.substring(7 ,8)) * 3 ) % 10; 

	li_temp = parseFloat(payid.substring(8,9)) * 5 + "0"; 

	biz_value[8] = parseFloat(li_temp.substring(0,1)) + parseFloat(li_temp.substring(1,2)); 
	biz_value[9] = parseFloat(payid.substring(9,10)); 

	li_lastid = (10 - ( ( biz_value[0] + biz_value[1] + biz_value[2] + biz_value[3] + biz_value[4] + biz_value[5] + biz_value[6] + biz_value[7] + biz_value[8] ) % 10 ) ) % 10; 

	if (biz_value[9]!=li_lastid){
		return false;
	} else {
		return true;
	}
}

function HangulOnly(name) {

    var ch = "\0";
    var flag = false;
 
    for (var i = 0, ch = name.charAt(i);
        (i <name.length) ; ch = name.charAt(++i)) {
        if ((ch >= '0') && (ch <= '9')) return flag;
        else if ((ch >= 'a') && (ch <= 'z')) return flag;
        else if ((ch >= 'A') && (ch <= 'Z')) return flag;
        else if ( ch == ' ' || ch == '~' || ch == '`' || ch == '\\'|| 
                  ch == '-' || ch == '_' || ch == '|' || ch == '+' ||
                  ch == '=' || ch == ',' || ch == '.' || ch == '/' ||
                  ch == '<' || ch == '>' || ch == '?' || ch == '!' ||
                  ch == '@' || ch == '#' || ch == '$' || ch == '%' || 
                  ch == '^' || ch == '&' || ch == '*' || ch == '(' || 
                  ch == ')' || ch == '\"' || ch == '[' || ch == '(' ) return flag;
    	else  return true;
    }
}

function numOnly(obj,frm,isCash)
{
	//if (event.keyCode == 9 || event.keyCode == 37 || event.keyCode == 39) return;
	
	var returnValue = "";
	for (var i = 0; i < obj.value.length; i++) {
		if (obj.value.charAt(i) >= "0" && obj.value.charAt(i) <= "9") {
			returnValue += obj.value.charAt(i);
		} else {
			returnValue += "";
		}
	}
		
	if (isCash) {
		obj.value = cashReturn(returnValue);
		return;
	}
	obj.focus();
	obj.value = returnValue;
	
}

function cashReturn(numValue)
{
	var cashReturn = "";
	for (var i = numValue.length-1; i >= 0; i--){
		cashReturn = numValue.charAt(i) + cashReturn;
		if (i != 0 && i%3 == numValue.length%3) cashReturn = "," + cashReturn;
	}
	
	return cashReturn;
}

function removeComma(cash)
{
	// submit 하기 전에 document.formname.inputboxname.value = removeComma(document.formname.inputboxname.value)
	var returnValue = "";
	for (var i = 0; i < cash.length; i++){
		if (cash.charAt(i) != ","){
			returnValue += cash.charAt(i);
		}
	}
	return returnValue;
}

function removeLeftZero(inputValue){
	var numZero = 0;
	for (var i = 0; i < inputValue.length; i++){
		if (inputValue.charAt(i) != "0" && inputValue.charAt(i) != ",")
		{
			break;
		}
		else numZero++;
	}
	
	return inputValue.substring(numZero);
}
function next_focus( a, b, c, d){
	var chk_box = eval("document."+ a +"."+ b +".value");
	var chk_box_length = chk_box.length;
	var move_box = eval("document."+ a +"."+c);

	if (chk_box_length == d) {
		move_box.focus();
	}		
}

/* 유효성 검사 */
String.prototype.isIPAddress = function () {
	if (! /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.test(this)) return false;
	if (RegExp.$1 > 254 || RegExp.$2 > 254 || RegExp.$3 > 254 || RegExp.$4 > 254)
	return false;
	if (RegExp.$1 < 0 || RegExp.$2 < 0 || RegExp.$3 < 0 || RegExp.$4 < 0) return false;
	return true;
}

function isDomain(s)
{
  return s.search(/^\s*[\w\~\-]+(\.[\w\~\-]+)+\s*$/g)>=0;
}
