function normalize_captcha(str)
{
    while (true) {
        var strprev = str;
        str = str.replace("\r", "");
        str = str.replace("\n", "");
        str = str.replace(" ", "");
        if (strprev == str) { break; }
    }
    return str;
}

function normalize_number(str)
{
    while (true) {
        var strprev = str;
        str = str.replace("\r", "");
        str = str.replace("\n", "");
        str = str.replace(" ", "");
        if (strprev == str) { break; }
    }
    return str;
}

function normalize_phonenum(str)
{
    while (true) {
        var strprev = str;
        str = str.replace("\r", "");
        str = str.replace("\n", "");
        str = str.replace(" ", "");
        str = str.replace(".", "");
        str = str.replace("-", "");
        if (strprev == str) { break; }
    }

    var prefix = str.substring(0,3);
    if (prefix != "010" && prefix != "011" && prefix != "017" &&
        prefix != "019" && prefix != "016")
    {
        str = "";
    }

    return str;
}

Array.prototype.remove = function(idx) {
	   var temp = new Array();
	   var i = this.length;

	   while(i > idx){
	       var kk = this.pop();
	       temp.push(kk);
	       i--;
	   }

	   for(var i=temp.length - 2; i>=0; i--){
	       this.push(temp[i]);
	   }
	}

//바이트의 파일크기를 KB, MB, GB로 변환한다.
function convert_size(byteSize)
{
	var size = 0;
	
	if (byteSize / (1024*1024*1024) > 1.0) {
        size = parseInt (byteSize / (1024*1024*1024))
        size += " GB";
    } else if (byteSize / (1024*1024) > 1.0) {
        size = parseInt(byteSize / (1024*1024));
        size += " MB";
    } else if (byteSize / (1024) > 1.0) {
        size = parseInt (byteSize / (1024));
        size += " KB";
    } else {
        size = byteSize + " B";
    }
	
	return size;
}

//function : 수값형식의 키입력을 체크한다.
function js_checkNumeric(evt) {
	var result = true;
	
	var keyCode = (evt.which) ? evt.which : evt.keyCode;
	var charCode = String.fromCharCode(keyCode);
	var re = new RegExp("[0-9]");
	if(charCode!="\r" && charCode!="\t" && charCode !="\b" && !re.test(charCode)) result = false;
	delete re;
	return result;
	
}

//function : 이메일주소의 키입력을 체크한다.
function js_checkEmailKey(evt) {
	var result = true;
	
	var keyCode = (evt.which) ? evt.which : evt.keyCode;
	var charCode = String.fromCharCode(keyCode);
	var re = new RegExp("[0-9A-Za-z\\.\\@]");
	if(charCode!="\r" && charCode!="\t" && charCode !="\b" && !re.test(charCode)) result = false;
	delete re;
	return result;
	
}

//function : 이메일주소의 형식을 체크한다.
function js_checkEmail(email) {
	
	 var checkTLD=1; //wether check well-known domain & two-letter contry domain
	 var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	 var emailPat=/^(.+)@(.+)$/;
	 var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	 var validChars="\[^\\s" + specialChars + "\]";
	 var quotedUser="(\"[^\"]*\")";
	 var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	 var atom=validChars + '+';
	 var word="(" + atom + "|" + quotedUser + ")";
	 var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	 var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	 
	 var matchArray = email.match(emailPat);
	 
	 if (!matchArray) {
		 return false;
	 }

	 var user=matchArray[1];
	 var domain=matchArray[2];
	 for (i=0; i<user.length; i++)
	 	if (user.charCodeAt(i)>127) { 
			return false;
	 	}
	 for (i=0; i<domain.length; i++)
	 	if (domain.charCodeAt(i)>127) { 
			return false;
	 	}
	 if (!user.match(userPat)) { // user is not valid
		 return false;
	 }
	 // IP Address형태의 Email 체크 E.g. joe@[123.124.233.4] is a legal e-mail address */
	 var IPArray=domain.match(ipDomainPat);
	 if (IPArray) { 
		 for (var i=1;i<=4;i++)
	 		if (IPArray[i]>255) { 
				return false;
	 		}
		return true;
	 }
	 // symbolic 형태의 Domain name 체크
	 var atomPat=new RegExp("^" + atom + "$");
	 var domArr=domain.split(".");
	 var len=domArr.length;
	 for (i=0;i<len;i++)
	 	if (domArr[i].search(atomPat)==-1) { 
			return false;
	 	}
	 // TLD 체크
	 if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { 
		return false;
	 }
	 if (len<2) { 
	 	return false;
	 }
	 delete userPat; delete domainPat; delete atomPat;
	 return true;
}

var m_connectingProgressText0 = " &#9679;&#9675;&#9675;&#9675;&#9675;";
var m_connectingProgressText1 = " &#9675;&#9679;&#9675;&#9675;&#9675;";
var m_connectingProgressText2 = " &#9675;&#9675;&#9679;&#9675;&#9675;";
var m_connectingProgressText3 = " &#9675;&#9675;&#9675;&#9679;&#9675;";
var m_connectingProgressText4 = " &#9675;&#9675;&#9675;&#9675;&#9679;";
var m_connectingProgressText5 = " &#9675;&#9675;&#9675;&#9679;&#9675;";
var m_connectingProgressText6 = " &#9675;&#9675;&#9679;&#9675;&#9675;";
var m_connectingProgressText7 = " &#9675;&#9679;&#9675;&#9675;&#9675;";

var progress_flag = false;
var progress_count = 1;

function js_progressStart(obj, str) {
	progress_flag = true;
	setTimeout("js_progressing(\"" + obj + "\", \"" + str + "\");", 500);
}

function js_progressStop() {
	progress_flag = false;
}

function js_progressing(obj, str) {
	
	progress_count = (progress_count + 1) % 8;
	
	if (progress_flag) {
		var prgStr;
		switch (progress_count) {
			case 0: prgStr = m_connectingProgressText0; break;
			case 1: prgStr = m_connectingProgressText1; break;
			case 2: prgStr = m_connectingProgressText2; break;
			case 3: prgStr = m_connectingProgressText3; break;
			case 4: prgStr = m_connectingProgressText4; break;
			case 5: prgStr = m_connectingProgressText5; break;
			case 6: prgStr = m_connectingProgressText6; break;
			case 7: prgStr = m_connectingProgressText7; break;
		}
		ELEM(obj).innerHTML = str + prgStr;
		setTimeout("js_progressing(\"" + obj + "\", \"" + str + "\");", 500);
	} else {
		ELEM(obj).innerHTML = "&nbsp;";
	}
	
}

function js_findTagByName(oTag, tagName, name) {
	var tags = oTag.getElementsByTagName(tagName);
	for (var idx=0; idx<tags.length; idx++) {
		if (tags[idx].name == name) return tags[idx];
	}
  return null;
}

