// common.js

// 사이트 바로가기 시작 ======================================= //
function topSelect1Open(){
  strTemp = document.getElementById('totalGogo').innerHTML;
  document.getElementById("linkyo").style.display = "";
}

function topSelect1Close(str,str2){
  strTemp = document.getElementById('totalGogo').innerHTML;
  document.getElementById("linkyo").style.display = "none";
  document.getElementById('totalGogo').innerHTML = "<a href=\"javascript:topSelect1Open();\"><img src=\"/Images/g/si_sitego.gif\" alt=\"사이트 바로가기\" /></a>";
  if (str2!=""){
    window.open(str2,'','');
  }
}



// 퀵메뉴 (적용할개체 , X축여백 , Y축여백 , 미끄러지는속도:작을수록빠름..기본20 , 빠르기:작을수록부드러움..기본10);

function Floating(FloatingObj,MarginX,MarginY,Percentage,setTime,Mstart) {
	this.FloatingObj = FloatingObj;
	this.MarginX = (MarginX) ? MarginX : 0;
	this.MarginY = (MarginY) ? MarginY : 0;
	this.Percentage = (Percentage) ? Percentage : 20;
	this.setTime = (setTime) ? setTime : 10;
	this.FloatingObj.style.position = "relative";
	this.Body = null;
	this.setTimeOut = null;
	this.Mstart = (Mstart) ? Mstart : 0;
	this.Run();
}

Floating.prototype.Run = function () {
	if ((document.documentElement.scrollLeft + document.documentElement.scrollTop) > (document.body.scrollLeft + document.body.scrollTop)) {
		this.Body = document.documentElement;
	} else {
		this.Body = document.body;
	}

	var This = this;
	var FloatingObjLeft = (this.FloatingObj.style.left) ? parseInt(this.FloatingObj.style.left,10) : this.MarginX;//this.FloatingObj.offsetLeft;
	var FloatingObjTop = (this.FloatingObj.style.top) ? parseInt(this.FloatingObj.style.top,10) : this.Mstart;//this.FloatingObj.offsetTop;
	var DocLeft = this.Body.scrollLeft + this.MarginX;
	var DocTop = this.Body.scrollTop + this.MarginY;

	var MoveX = Math.abs(FloatingObjLeft - DocLeft);
	MoveX = Math.ceil(MoveX / this.Percentage);
	var MoveY = Math.abs(FloatingObjTop - DocTop);
	MoveY = Math.ceil(MoveY / this.Percentage);

	if (FloatingObjLeft < DocLeft) {
		this.FloatingObj.style.left = FloatingObjLeft + MoveX + "px";
	} else {
		this.FloatingObj.style.left = FloatingObjLeft - MoveX + "px";
	}

	if (FloatingObjTop < DocTop) {
		this.FloatingObj.style.top = FloatingObjTop + MoveY + "px";
	} else {
		this.FloatingObj.style.top = FloatingObjTop - MoveY + "px";
	}

	window.clearTimeout(this.setTimeOut);
	this.setTimeOut = window.setTimeout(function () { This.Run(); },this.setTime);
}



function Global_ResizeWIndow(width, height) {
    window.resizeTo(width, height);
}

function Global_ResizeImage(areaID, maxWidth) {
    var contentObject = document.getElementById(areaID);

    Global_FindImgObject(contentObject, maxWidth);
}

function Global_FindImgObject(parentsObject, maxWidth) {
    for (var i = 0; i < parentsObject.children.length; i++) {
        if (parentsObject.children[i].tagName == "IMG") {
            var img = parentsObject.children[i];

            var width = img.width;
            var height = img.height;

            if (width > maxWidth) {
                img.sourceWidth = img.width;
                img.sourceHeight = img.height;

                img.width = maxWidth;
                img.height = (maxWidth * height) / width;
                img.title = "클릭하시면 원본 이미지를 보실 수 있습니다.";
                img.style.cursor = "hand";
                img.attachEvent('onclick', OnResizedImageClick);
            }
        }
        else if (parentsObject.children[i].children.length > 0) {
            Global_FindImgObject(parentsObject.children[i], maxWidth);
        }
    }
}

function OnResizedImageClick() {
    var sourceObject = event.srcElement;

    var width = sourceObject.sourceWidth;
    var height = sourceObject.sourceHeight;

    var screenX = (event.clientX) - (width / 2);
    var screenY = (event.clientY) + (height / 2) - 100;

    var resizedImagePopUp = window.open('', 'resizedImage', 'top=' + screenY + ',left=' + screenX + ',width=' + width + ',height=' + height);

    resizedImagePopUp.document.write("<html>");
    resizedImagePopUp.document.write("<title>이미지 원본</title>");
    resizedImagePopUp.document.write("<body style='margin:0px'>");
    resizedImagePopUp.document.write("<img src='" + sourceObject.src + "' onclick='self.close();' title='클릭하면 창을 닫습니다.' style='cursor:hand'>");
    resizedImagePopUp.document.write("</body>");
    resizedImagePopUp.document.write("</html>");
}

// 해당 텍스트 값에서 확장자를 추출합니다.

function Global_GetFileExtension(controlObject) {
    var contolValue = controlObject.value;

    var index = contolValue.lastIndexOf(".")

    if ((Global_TrimSpaces(contolValue) != "") && (contolValue.length != 0)) {
        return contolValue.substring(index + 1).toLowerCase();
    }
    else {
        return '';
    }
}

// Javascript로 QueryString 구하기 ---------------------------------------------------------------------------------------------
function Global_Request(valuename) {
    var rtnval = "";
    var nowAddress = unescape(location.href);
    var parameters = (nowAddress.slice(nowAddress.indexOf("?") + 1, nowAddress.length)).split("&");

    for (var i = 0; i < parameters.length; i++) {
        var varName = parameters[i].split("=")[0];
        if (varName.toUpperCase() == valuename.toUpperCase()) {
            rtnval = parameters[i].split("=")[1];
            break;
        }
    }

    return rtnval;
}

// 두개의 컨트롤의 값을 비교해서 같은지를 반환합니다. --------------------------------------------------------------------------
function Globl_ControlToControlValueCheck(sourceControlName, targetControlName, message) {
    var sourceControl = FindObject(sourceControlName);
    var targetControl = FindObject(targetControlName);

    if (sourceControl == null || targetControl == null) {
        alert("한개의 이상의 컨트롤이 없습니다.");
        return false;
    }
    else {
        if (Global_TrimSpaces(sourceControl.value) != Global_TrimSpaces(targetControl.value)) {
            alert(message);
            return false;
        }
        else {
            return true;
        }

    }
}


// 해당 창 크기의 정 중앙 좌표를 가지고 옵니다.
function Global_Width(popupWindowWidth) {
    return (document.body.clientWidth / 2) - (popupWindowWidth / 2);
}

function Global_Height(popupWindowHeight) {
    return (document.body.clientHeight / 2) - (popupWindowHeight / 2);
}

// 창을 중앙/이벤트 발생 위치하도록 엽니다.
function WindowCenterOpen(url, name, width, height, enableScroll, isCenter) {
    var properties = "width=" + width;
    properties += ", height=" + height;

    if (isCenter) {
        properties += ", left=" + Global_Width(width);
        properties += ", top=" + Global_Height(height);
    }
    else {
        properties += ", left=" + (window.event.clientX + 10);
        properties += ", top=" + (window.event.clientY + height);
    }

    if (enableScroll)
        properties += ", scrollbars=1";


    var popWindow = window.open(url, name, properties);

    if (popWindow == null) {
        alert("팝업이 차단되었습니다.");
        return false;
    }
}

// 컨트롤의 Client를 저장합니다.
var clientIDList = new Array();

// 해당 텍스트 컨트롤이 공백인지를 검사  ---------------------------------------------------------------------------------------
function Global_ControlValueCheck(controlName, message, enableBadWordCheck) {
    var control = FindObject(controlName);

    if (control != null) {
        if (Global_TrimSpaces(control.value) == '') {
            alert(message);
            control.value = '';
            control.focus();
            return false;
        }
        else {
            if (enableBadWordCheck) {
                // 불량단어 필터링이 걸릴경우 불량단어를 검사
                return ChkeckBadWord(control);
            }
            else {
                return true;
            }
        }
    }
    else {
        return true;
    }
}

// 금지단어 등록
var BadWords = "개새끼,소새끼,병신,지랄,씨팔,십팔,니기미,찌랄,지랄,쌍년,쌍놈,빙신,좆까,니기미,좆같은게,잡놈,벼엉신,바보새끼,씹새끼,씨발,씨팔,시벌,씨벌,떠그랄,좆밥,추천인,추천id,추천아이디,추천id,추천아이디,추/천/인,등신,싸가지,미친놈,미친넘,찌랄,죽습니다,님아,님들아,씨밸넘";

function ChkeckBadWord(control) {
    //  이 함수를 사용하기 위해서는 불량 단어 변수 BadWord를 지정해야 합니다.
    var TempObj = control;

    if (BadWords == null) {
        return;
    }

    var BadText = BadWords.split(",");

    if (BadText == "") {
        return false;
    }

    var swear_words_arr = new Array();

    for (var i = 0; i < BadText.length; i++) {
        swear_words_arr = swear_words_arr.concat(BadText[i]);
    }

    var swear_alert_arr = new Array;
    var swear_alert_count = 0;

    var compare_text = TempObj.value;

    for (var i = 0; i < swear_words_arr.length; i++) {
        for (var j = 0; j < (compare_text.length); j++) {
            if (swear_words_arr[i] == compare_text.substring(j, (j + swear_words_arr[i].length)).toLowerCase()) {
                swear_alert_arr[swear_alert_count] = compare_text.substring(j, (j + swear_words_arr[i].length));
                swear_alert_count++;
            }
        }
    }

    var alert_text = "";

    for (var k = 1; k <= swear_alert_count; k++) {
        alert_text += "\n" + "* " + swear_alert_arr[k - 1];
    }

    if (swear_alert_count > 0) {
        alert("금지된 단어를 사용하였습니다.\n_______________________________\n" + alert_text + "\n_______________________________");
        return false;
    }
    else {
        return true;
    }
}

// 컨트롤을 찾습니다. ----------------------------------------------------------------------------------------------
function FindObject(objectName) {
    var tempObjectName = objectName;

    // 검사대상 컨트롤을 찾습니다.
    // 정의된 clientID리스트를 돕니다.
    for (var i = 0; i < clientIDList.length; i++) {
        // 객체가 있다.
        if (document.getElementById(clientIDList[i] + "_" + objectName) != null) {
            // 아직 컨트롤의 이름이 설정되지 않았다면
            if (tempObjectName == objectName) {
                // 이름을 설정
                tempObjectName = clientIDList[i] + "_" + objectName;
            }
        }
    }

    if (document.getElementById(tempObjectName) != null) {
        return document.getElementById(tempObjectName);
    }
    else {
        return null;
    }
}

// 해당 문자열의 공백을 제거 ----------------------------------------------------------------------------------------------------
function Global_TrimSpaces(text) {
    var temp = "";

    text = '' + text.toUpperCase();

    splitstring = text.split(" ");

    for (i = 0; i < splitstring.length; i++)

        temp += splitstring[i];

    return temp;
}

function Global_CheckPID(controlName1, controlName2) {
    var NUM = "0123456789";

    var PID1 = FindObject(controlName1).value;
    var PID2 = FindObject(controlName2).value;

    var chk = 0;

    var nYear = PID1.substring(0, 2);

    var nMondth = PID1.substring(2, 4);

    var nDay = PID1.substring(4, 6);

    var nSex = PID2.charAt(0);

    if (!IsValid(PID1, NUM)) {
        alert("주민번호가 올바르지 않습니다.");
        FindObject(controlName1).select();
        return false//-1;
    }

    if (PID1.length != 6 || nMondth < 1 || nMondth > 12 || nDay < 1 || nDay > 31) {
        alert("주민번호가 올바르지 않습니다.");
        FindObject(controlName1).select();
        return false//-1;
    }

    if (!IsValid(PID2, NUM)) {
        alert("주민번호가 올바르지 않습니다.");
        FindObject(controlName1).select();
        return false//1;
    }

    if (PID2.length != 7 || (nSex != 1 && nSex != 2 && nSex != 3 && nSex != 4 && nSex != 5 && nSex != 6 && nSex != 7 && nSex != 8)) {
        alert("주민번호가 올바르지 않습니다.");
        FindObject(controlName1).select();
        return false//1;
    }

    if (nSex == 5 || nSex == 6 || nSex == 7 || nSex == 8) {
        var sum = 0;
        var odd = 0;
        var PID = PID1 + PID2;
        buf = new Array(13);
        for (i = 0; i < 13; i++) buf[i] = parseInt(PID.charAt(i));
        odd = buf[7] * 10 + buf[8];
        if (odd % 2 != 0) {
            alert("주민번호가 올바르지 않습니다.");
            FindObject(controlName1).select();
            return false//-1;
        }

        multipliers = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5];
        for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);
        sum = 11 - (sum % 11);
        if (sum >= 10) sum -= 10;
        sum += 2;
        if (sum >= 10) sum -= 10;
        if (sum != buf[12]) {
            alert("주민번호가 올바르지 않습니다.");
            FindObject(controlName1).select();
            return false//-1;
        }
    }
    else {
        var i;
        for (i = 0; i < 6; i++) {
            chk += ((i + 2) * parseInt(PID1.charAt(i)));
        }

        for (i = 6; i < 12; i++) {
            chk += ((i % 8 + 2) * parseInt(PID2.charAt(i - 6)));
        }

        chk = 11 - (chk % 11);
        chk %= 10;

        if (chk != parseInt(PID2.charAt(6))) {
            alert("주민번호가 올바르지 않습니다.");
            FindObject(controlName1).select();

            return false//-1;
        }
    }

    return true//0;
}

// 주민등록체크의 서브 함수로 사용됩니다.
function IsValid(s, spc) {
    var i;
    if (s.length < 1) return false;
    for (i = 0; i < s.length; i++) {
        if (spc.indexOf(s.substring(i, i + 1)) < 0) {
            return false;
        }
    }

    return true;
}

// 필요한 이미지를 미리 로드 합니다. -------------------------------------------------------------------------------------------
function Global_PreloadImage() {
    var img_list = Global_PreloadImage.arguments;
    if (document.preloadlist == null)
        document.preloadlist = new Array();
    var top = document.preloadlist.length;
    for (var i = 0; i < img_list.length; i++) {
        document.preloadlist[top + i] = new Image;
        document.preloadlist[top + i].src = img_list[i + 1];
    }
}

// Select 항목을 조정합니다. ----------------------------------------------------------------------------------------

//항목을 추가합니다.
function Global_AddOption(theForm, text, value) {
    var newOpt = document.createElement("OPTION");
    newOpt.text = text;
    newOpt.value = value;
    theForm.add(newOpt);
}

// 항목을 제거 합니다.
function Global_ReMoveOption(theForm, selectedIndex) {
    try {
        var selLength = theForm.length;

        if (selLength > 0) {
            theForm.remove(selectedIndex);
        }
    }
    catch (error) {
        alert(error.description);
        return false;
    }
}


//+--------------------------------------------------------------------		
//	브라우져 버전 체크 
// 2010-03-09 PKH 추가
//+--------------------------------------------------------------------	
function whichBrs() {
    var agt = navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) {
        var msieNo = agt.substr(agt.indexOf("msie"), 8);
        msieVer = msieNo.substr(5, 3);
        return 'MSIE ' + msieVer;
    }
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
        if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0, agt.indexOf('\/'));
        }
        else return 'Netscape';
    } else if (agt.indexOf(' ') != -1)
        return navigator.userAgent.substr(0, agt.indexOf(' '));
    else return navigator.userAgent;
}


//+--------------------------------------------------------------------		
// 팝업 창 중앙에 띄우기 
// 2010-03-09 PKH 추가
//+--------------------------------------------------------------------	
function winOpen_center(url, target, width, height, etc) {
    if (screen.width < 1025) {
        LeftPosition = 0;
        TopPosition = 0;
    } else {
        LeftPosition = (screen.width) ? (screen.width - width) / 2 : 100;
        TopPosition = (screen.height) ? (screen.height - height) / 2 : 100;
    }
    var target = window.open(url, target, 'width=' + width + ',height=' + height + ',top=' + TopPosition + ',left=' + LeftPosition + ',' + etc);
    target.focus();
}


//+--------------------------------------------------------------------		
// 금액 입력과 동시에 콤마찍기 OnKeyUp
// 2010-03-11 PKH 
// 호출방법
// onkeyup="this.value=changeCommaAdd_PKH(this.value);"
// maxlength="19"	//콤마를 포함해서 19자리까지 허용이 됩니다. 오버가 되면 1~9를 클릭하더라도 "0"으로 채워집니다.
//+--------------------------------------------------------------------
function changeCommaAdd_PKH(n) {
    var B = whichBrs();
    var rtn;
    if (B == "MSIE 5.5" || B == "MSIE 6.0" || B == "MSIE 7.0" || B == "MSIE 8.0") {
        rtn = Number(String(n).replace(/\..*|[^\d]/g, "")).toLocaleString().slice(0, -3);
    } else {
        rtn = Number(String(n).replace(/\..*|[^\d]/g, "")).toLocaleString();
    }
    return rtn;
}
function changeCommaAdd_US_PKH(n) {
    var B = whichBrs();
    var rtn;
    var bExists = n.indexOf(".");
    if (bExists < 0) n = n + ".00";
    var temp_int = n.substring(0, n.lastIndexOf('.'));
    var temp_float = n.substring(n.lastIndexOf('.'));
    var round_float = roundXL(Number(temp_float), 2);
    if (round_float == 0) round_float = "0.00";
    if (B == "MSIE 5.5" || B == "MSIE 6.0" || B == "MSIE 7.0" || B == "MSIE 8.0") {
        rtn = Number(String(temp_int).replace(/\..*|[^\d]/g, "")).toLocaleString().slice(0, -3);
    } else {
        rtn = Number(String(temp_int).replace(/\..*|[^\d]/g, "")).toLocaleString();
    }
    rtn = rtn + String(round_float).substring(String(round_float).lastIndexOf('.'));
    return rtn;
}

//+--------------------------------------------------------------------		
// 전화번호 입력시 자동 하이픈입력
// 2010-03-11 PKH 
// 핸드폰, 일반전화, 070,080,1588,1688 등의 모든 번호 입력가능
// 0505 번도 정상입력됩니다.
// 필요한 번호이상 입력시 자동 삭제됩니다.
//+--------------------------------------------------------------------

function OnCheckPhone(oTa) {
    var ________result = "";
    document.onkeypress = function (e) {
        if (typeof (e) != "undefined") ________result = e.which;
        else ________result = event.keyCode;
        //	alert(________result);
    }
    //	return;
    var oForm = oTa.form;
    var sMsg = oTa.value;
    if (!sMsg) return;
    var onlynum = "";
    var imsi = 0;
    onlynum = RemoveDash2(sMsg);  //하이픈 입력시 자동으로 삭제함 
    onlynum = checkDigit(onlynum);  // 숫자만 입력받게 함
    var retValue = "";
    if (________result != 12) {
        if (onlynum.substring(0, 2) == 02) {  // 서울전화번호일 경우  10자리까지만 나타나교 그 이상의 자리수는 자동삭제 
            if (GetMsgLen(onlynum) <= 1) oTa.value = onlynum;
            if (GetMsgLen(onlynum) == 2) oTa.value = onlynum + "-";
            if (GetMsgLen(onlynum) == 4) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 3);
            if (GetMsgLen(onlynum) == 4) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 4);
            if (GetMsgLen(onlynum) == 5) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 5);
            if (GetMsgLen(onlynum) == 6) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 6);
            if (GetMsgLen(onlynum) == 7) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 5) + "-" + onlynum.substring(5, 7); ;
            if (GetMsgLen(onlynum) == 8) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 6) + "-" + onlynum.substring(6, 8);
            if (GetMsgLen(onlynum) == 9) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 5) + "-" + onlynum.substring(5, 9);
            if (GetMsgLen(onlynum) == 10) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 6) + "-" + onlynum.substring(6, 10);
            if (GetMsgLen(onlynum) == 11) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 6) + "-" + onlynum.substring(6, 10);
            if (GetMsgLen(onlynum) == 12) oTa.value = onlynum.substring(0, 2) + "-" + onlynum.substring(2, 6) + "-" + onlynum.substring(6, 10);
        }
        if (onlynum.substring(0, 2) == 05) {  // 05로 시작되는 번호 체크 
            if (onlynum.substring(2, 3) == 0) {  // 050으로 시작되는지 따지기 위한 조건문 
                if (GetMsgLen(onlynum) <= 3) oTa.value = onlynum;
                if (GetMsgLen(onlynum) == 4) oTa.value = onlynum + "-";
                if (GetMsgLen(onlynum) == 5) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 5);
                if (GetMsgLen(onlynum) == 6) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 6);
                if (GetMsgLen(onlynum) == 7) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 7);
                if (GetMsgLen(onlynum) == 8) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8);
                if (GetMsgLen(onlynum) == 9) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 7) + "-" + onlynum.substring(7, 9); ;
                if (GetMsgLen(onlynum) == 10) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8) + "-" + onlynum.substring(8, 10);
                if (GetMsgLen(onlynum) == 11) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 7) + "-" + onlynum.substring(7, 11);
                if (GetMsgLen(onlynum) == 12) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8) + "-" + onlynum.substring(8, 12);
                if (GetMsgLen(onlynum) == 13) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8) + "-" + onlynum.substring(8, 12);
            } else {
                if (GetMsgLen(onlynum) <= 2) oTa.value = onlynum;
                if (GetMsgLen(onlynum) == 3) oTa.value = onlynum + "-";
                if (GetMsgLen(onlynum) == 4) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 4);
                if (GetMsgLen(onlynum) == 5) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 5);
                if (GetMsgLen(onlynum) == 6) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6);
                if (GetMsgLen(onlynum) == 7) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7);
                if (GetMsgLen(onlynum) == 8) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6) + "-" + onlynum.substring(6, 8); ;
                if (GetMsgLen(onlynum) == 9) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 9);
                if (GetMsgLen(onlynum) == 10) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6) + "-" + onlynum.substring(6, 10);
                if (GetMsgLen(onlynum) == 11) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 11);
                if (GetMsgLen(onlynum) == 12) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 11);
            }
        }

        if (onlynum.substring(0, 2) == 03 || onlynum.substring(0, 2) == 04 || onlynum.substring(0, 2) == 06 || onlynum.substring(0, 2) == 07 || onlynum.substring(0, 2) == 08) {  // 서울전화번호가 아닌 번호일 경우(070,080포함 // 050번호가 문제군요) 
            if (GetMsgLen(onlynum) <= 2) oTa.value = onlynum;
            if (GetMsgLen(onlynum) == 3) oTa.value = onlynum + "-";
            if (GetMsgLen(onlynum) == 4) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 4);
            if (GetMsgLen(onlynum) == 5) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 5);
            if (GetMsgLen(onlynum) == 6) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6);
            if (GetMsgLen(onlynum) == 7) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7);
            if (GetMsgLen(onlynum) == 8) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6) + "-" + onlynum.substring(6, 8); ;
            if (GetMsgLen(onlynum) == 9) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 9);
            if (GetMsgLen(onlynum) == 10) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6) + "-" + onlynum.substring(6, 10);
            if (GetMsgLen(onlynum) == 11) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 11);
            if (GetMsgLen(onlynum) == 12) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 11);

        }
        if (onlynum.substring(0, 2) == 01) {  //휴대폰일 경우 
            if (GetMsgLen(onlynum) <= 2) oTa.value = onlynum;
            if (GetMsgLen(onlynum) == 3) oTa.value = onlynum + "-";
            if (GetMsgLen(onlynum) == 4) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 4);
            if (GetMsgLen(onlynum) == 5) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 5);
            if (GetMsgLen(onlynum) == 6) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6);
            if (GetMsgLen(onlynum) == 7) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7);
            if (GetMsgLen(onlynum) == 8) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 8);
            if (GetMsgLen(onlynum) == 9) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 9);
            if (GetMsgLen(onlynum) == 10) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 6) + "-" + onlynum.substring(6, 10);
            if (GetMsgLen(onlynum) == 11) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 11);
            if (GetMsgLen(onlynum) == 12) oTa.value = onlynum.substring(0, 3) + "-" + onlynum.substring(3, 7) + "-" + onlynum.substring(7, 11);
        }

        if (onlynum.substring(0, 1) == 1) {  // 1588, 1688등의 번호일 경우 
            if (GetMsgLen(onlynum) <= 3) oTa.value = onlynum;
            if (GetMsgLen(onlynum) == 4) oTa.value = onlynum + "-";
            if (GetMsgLen(onlynum) == 5) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 5);
            if (GetMsgLen(onlynum) == 6) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 6);
            if (GetMsgLen(onlynum) == 7) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 7);
            if (GetMsgLen(onlynum) == 8) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8);
            if (GetMsgLen(onlynum) == 9) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8);
            if (GetMsgLen(onlynum) == 10) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8);
            if (GetMsgLen(onlynum) == 11) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8);
            if (GetMsgLen(onlynum) == 12) oTa.value = onlynum.substring(0, 4) + "-" + onlynum.substring(4, 8);
        }
    }
}

function RemoveDash2(sNo) {
    var reNo = ""
    for (var i = 0; i < sNo.length; i++) {
        if (sNo.charAt(i) != "-") {
            reNo += sNo.charAt(i)
        }
    }
    return reNo
}

function GetMsgLen(sMsg) { // 0-127 1byte, 128~ 2byte 
    var count = 0
    for (var i = 0; i < sMsg.length; i++) {
        if (sMsg.charCodeAt(i) > 127) {
            count += 2
        }
        else {
            count++
        }
    }
    return count
}

function checkDigit(num) {
    var Digit = "1234567890";
    var string = num;
    var len = string.length;
    var retVal = "";
    for (i = 0; i < len; i++) {
        if (Digit.indexOf(string.substring(i, i + 1)) >= 0)
            retVal = retVal + string.substring(i, i + 1);
        else if (Digit.indexOf(string.substring(i, i + 1)) == -1)
            reVal = "";
    }
    return retVal;
}
//전화번호 자동 하이픈 코드 끝//


// 양쪽 공백 없애기
function sideTrim(str) {
    var pattern = /(^\s*)|(\s*$)/g; // \s 공백 문자
    str = str.replace(pattern, "");
    return str;
}

//  단순히 자바스크립트에서 getHttprequest(부를 주소);
//   부르면 페이지 이동없이 그 페이지의 결과를 받을 수 있습니다.

function getHttprequest(URL) {
    var xmlhttp = null;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open('GET', URL, false);
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && xmlhttp.statusText == 'OK') {
            responseText = xmlhttp.responseText;
        }
    }

    xmlhttp.send('');
    return responseText = xmlhttp.responseText;
}

//id 값 간단히 받기
//2010-03-29 PKH
function getById(id, where) {
    if (where == null)
        return document.getElementById(id);
    else
        return eval(where + ".document.getElementById('" + id + "')");
}


//onload event 호출하기
//2010-04-14 PKH
function addLoadEvents(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}

// FF까지 지원하는 숫자만 입력
// 호출방법 : onKeyPress="return numbersonly(event, false)
// 한글입력은 STYLE="IME-MODE:DISABLED" 로 제어
// 2010-04-14 PKH
function numbersonly(e, decimal) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;

    keychar = String.fromCharCode(key);
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27)) return true;
    else if ((("0123456789").indexOf(keychar) > -1)) return true;
    else if (decimal && (keychar == ".")) return true;
    else return false;
}

//2010-06-03 PKH
//US $ 입력 시 "." 허용
function price_us(e, decimal, obj) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) || (key == 46)) {
        if (key == 46) {
            var bExists = obj.value.indexOf(".");
            if (bExists > -1) return false;
            else return true;
        }
        return true;
    } else if ((("0123456789").indexOf(keychar) > -1)) return true;
    else if (decimal && (keychar == ".")) return true;
    else return false;
}

//2010-06-03 PKH
//소수부 반올림
function roundXL(n, digits) {
    if (digits >= 0) return parseFloat(n.toFixed(digits)); // 소수부 반올림

    digits = Math.pow(10, digits); // 정수부 반올림
    var t = Math.round(n * digits) / digits;

    return parseFloat(t.toFixed(0));
}

//2010-06-03 PKH
//전화번호 입력 시 "-" 허용
function numbersonly_tel(e, decimal, obj) {
    var key;
    var keychar;
    if (window.event) key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) || (key == 45)) {
        if (key == 45) {
            var bExists = obj.value.lastIndexOf("-");
            if (obj.value.length - bExists > 1) return true;
            else return false;
        }
        return true;
    } else if ((("0123456789").indexOf(keychar) > -1)) return true;
    else if (decimal && (keychar == ".")) return true;
    else return false;
}

// input type 의 maxLength와 글자수가 맞으면 다음 field로 넘김
// 2010.04.30 ILoveFeel
// param 설명 :
// _this : 현재 field
// _length : 현재 field의 maxlength
// _next : 이동시킬 field
function next_obj(_this, _length, _next) {
    var value = _this.value;
    if (value.length == _length) {
        _next.focus();
    }
}

//+--------------------------------------------------------------------		
//	 팝업 창 중앙에 띄우기 
//+--------------------------------------------------------------------	
function pop_center(url, target, width, height) {
    var x, y;
    x = window.screen.availWidth / 2;
    y = window.screen.availHeight / 2;

    x = x - (width / 2);
    y = y - (height / 2);
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    var target = window.open(url, target, 'width=' + width + ',height=' + height + ',scrollbars=no, top=' + y + ',left=' + x);
    target.focus();
}
//+--------------------------------------------------------------------		
//	 팝업 창 중앙에 띄우기 
// 2010.03.05 ILoveFeel 추가
//+--------------------------------------------------------------------	
function pop_center_feature(url, target, width, height, feature) {
    var x, y;
    x = window.screen.availWidth / 2;
    y = window.screen.availHeight / 2;

    x = x - (width / 2);
    y = y - (height / 2);
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    var target = window.open(url, target, 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',' + feature);
    target.focus();
}

// 메일 체크 2010-05-18 sskypark
function isEmail(str) {
    // regular expression 지원 여부 점검 
    var supported = 0;
    if (window.RegExp) {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) supported = 1;
    }
    if (!supported)
        return (str.indexOf(".") > 3) && (str.indexOf("@") > 0);
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
    var r3 = new RegExp("^.[\\S\g]+\\@(\\[?)[a-zA-Z0-9\\-\]+\\.[a-zA-Z0-9\\-\]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");

    return ((!r1.test(str) && r2.test(str)) || (!r1.test(str) && r3.test(str)));
} 


