/*
Ä«µå¹øÈ£ÀÔ·Â
ÀüÈ­¹øÈ£ È®ÀÎ
¼ýÀÚ¿¡ comma ³Ö±â
µ¥ÀÌÅ¸¿¡¼­ ºó Ä­ Á¦°Å
textarea ±ÛÀÚ¼ö Á¦ÇÑ
ÀÌ¸ÞÀÏ È®ÀÎ
¿ìÆí¹øÈ£ Ã£±â - /pco/app06/kor_regWri.asp
*/
function fnchkcrdno(objNam) {
	var thisval = objNam.value ;
	var newval = "" ;
	for ( var i=0; i<thisval.length; i++ ) {
		if ( thisval.substr(i,1) >= "0" && thisval.substr(i,1) <= "9" ) {
			newval = newval + thisval.substr(i,1) ;
		}
	}
	if ( newval.length > 16 ) {
		newval = newval.substr(0,4) + " " + newval.substr(4,4) + " " + newval.substr(8,4) + " " + newval.substr(12,4) ;
	}
	else if ( newval.length > 12 ) {
		newval = newval.substr(0,4) + " " + newval.substr(4,4) + " " + newval.substr(8,4) + " " + newval.substr(12,4) ;
	}
	else if ( newval.length > 8 ) {
		newval = newval.substr(0,4) + " " + newval.substr(4,4) + " " + newval.substr(8,4) ;
	}
	else if ( newval.length > 4 ) {
		newval = newval.substr(0,4) + " " + newval.substr(4,4) ;
	}
	objNam.value = newval ;
}

function fnTelTyp(objNam) {
	var thisval = objNam.value ;
	if ( thisval.length != 0 ) {
		var newval = "" ;
		for ( var i=0; i<thisval.length; i++ ) {
			if ( thisval.substr(i,1)=="+" || thisval.substr(i,1)=="-" || thisval.substr(i,1)==" " || (thisval.substr(i,1) >= "0" && thisval.substr(i,1) <= "9") ) {
				newval = newval + thisval.substr(i,1) ;
			}
		}
		if ( newval.length != 0 && newval.substr(0,1) != "+" ) {
			newval = "+" + newval ;
		}
		objNam.value = newval ;
	}
}

function commaNum(num) {  

        if (num < 0) { num *= -1; var minus = true} 
        else var minus = false 
         
        var dotPos = (num+"").split(".") 
        var dotU = dotPos[0] 
        var dotD = dotPos[1] 
        var commaFlag = dotU.length%3 

        if(commaFlag) { 
                var out = dotU.substring(0, commaFlag)  
                if (dotU.length > 3) out += "," 
        } 
        else var out = "" 

        for (var i=commaFlag; i < dotU.length; i+=3) { 
                out += dotU.substring(i, i+3)  
                if( i < dotU.length-3) out += "," 
        } 

        if(minus) out = "-" + out 
        if(dotD) return out + "." + dotD 
        else return out  
} 

function replaceStr(strOriginal, strFind, strChange) {
	return strOriginal.split(strFind).join(strChange);
}

//-- ÀÎÀÚ textarea, byteÇ¥½Ã textÇÊµå, Á¦ÇÑbyte
function textCounter(theField,theCharCounter,maxChars) {
        var strCharCounter = 0;
        var intLength = theField.value.length;

        for (var i = 0; i < intLength; i++)
        {
                var charCode = theField.value.charCodeAt(i);
//ÇÑ±ÛÀÏ °æ¿ì
                if (charCode > 128)        {
                        strCharCounter += 2;
                } else {
                        strCharCounter++;
                }

                if(strCharCounter < (maxChars+1)) {
                        theCharCounter.value = strCharCounter;
                } else {
                        eval("alert('Please write here no more than " + maxChars + " characters.')");
                        if(!cutStr(theField, i, theCharCounter, maxChars)) {
                                alert("Please write here no more than " + maxChars + " characters.");
                        }
                        break;
                }
        }
}

function cutStr(theField, i, theCharCounter, maxChars) {
        var intLength = theField.value.length;        //-- ½ÇÁ¦ ¹®ÀÚÀÇ ±æÀÌ¸¦ ±¸ÇÑ´Ù.

        var strChar = theField.value.substring(0,i);                //¸¶Áö¸· ¹®ÀÚ¸¦ Àß¶ó³½´Ù.
        
        theField.value = strChar;
        textCounter(theField,theCharCounter,maxChars);
        return true;
}

function chkEmail(emlStr) { 
	// /kst_test/email_tst.asp Âü°í
	re=/^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i; 
 
	if(re.test(emlStr)) { 
		return true; 
	} 
	else { 
		return false; 
	} 
} 


function isEmail(strCk) {
	// regular expression Áö¿ø ¿©ºÎ Á¡°Ë
	var intSupported = 0;
	if(window.RegExp) {
		var strTemp = "a";
		var objTempReg = new RegExp(strTemp);
		if (objTempReg.test(strTemp)) intSupported = 1;
	}

	if (!intSupported) {
		return (strCke.indexOf(".") > 2) && (strCk.indexOf("@") > 0);
	}

	var objR1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var objR2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	return (!objR1.test(strCk) && objR2.test(strCk));
}


function zipSearch(form1,form2,form3,nextCursor){
	var url="/login/postno_search.asp?form1=" + form1 + "&form2=" + form2 + "&form3=" + form3 + "&nextCursor=" + nextCursor ;
	window.open(url,'', 'scrollbars=no,toolbar=no,location=no,directories=no,status=no,width=400,height=300,resizable=no,menubar=no,top=100,left=200'); 	
}

// ¼ýÀÚ¸¸ ÀÔ·Â
function SetNum(obj){
	val=obj.value;
	re=/[^0-9]/gi;
	obj.value = val.replace(re,"");
	obj.value = obj.value * 1 ;
	if (obj.value == '' ) {
		obj.value = '0' ;
	}
}


function onlyEng(objNam) {
	var thsVal = objNam.value;
	if ( thsVal.search(/[^a-z|^A-Z|^0-9|^ |^.|^,|^/|^(|^)|^#|^&|^-]/) != -1) {
		alert("Please enter only alphabets.");
		objNam.value = "";
		objNam.focus();
		return false;
	}
}

function onlyNum(objNam) {
	var thsVal = objNam.value;
	if ( thsVal.search(/[^0-9]/) != -1) {
		alert("Please enter only numbers.");
		objNam.value = "";
		objNam.focus();
		return false;
	}
}

