﻿//======================================================================================================
// 함 수 명 : Global_Confirm
// 설    명 : 확인 메세지 상자 출력
// 파라메타 : 메세지
//======================================================================================================
function Global_Confirm(message)
{
    if(confirm(message))
    {
        return true;
    }
    else
    {
        return false;
    }
}


//======================================================================================================
// 함 수 명 : Global_EnterBlocking
// 설    명 : 엔터키 막기
//======================================================================================================
function Global_EnterBlocking()
{
    //엔터키를 입력한 경우
    if(event.keyCode == 13)
    {
        return false;
    }
    else
    {
        return true;
    }
}


//======================================================================================================
// 함 수 명 : Global_Trim
// 설    명 : 양쪽 공백 제거
//======================================================================================================
function Global_Trim(str)
{
    var len = str.length;           //해당 문자열 길이를 구한다
    var i = 0;
    var j = 0;
    
    //뒷쪽부터 공백인지 조사
    for(j = len - 1; j >= 0; j--)
    {
        //해당 문자가 빈칸이 아닐 경우
        if(str.charAt(j) != " ")
        {
            break;
        }
    }

    //앞쪽부터 공백인지 조사
    for(i = 0; i < j; i++)
    {
        //해당 문자가 빈칸이 아닐 경우
        if(str.charAt(i) != " ")
        {
            break;
        }
    }
 
    return str.substring(i, j + 1);
}

//======================================================================================================
// 함 수 명 : Global_OnlyNumberCheck
// 설    명 : 숫자만 입력 받기
//======================================================================================================
function Global_OnlyNumberCheck()
{
	if(((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 190) || (event.keyCode == 110))
	{
		event.returnValue = true;
	}
	else
	{
		event.returnValue = false;
	}
}

//======================================================================================================
// 함 수 명 : Global_MoneyComma
// 설    명 : 금액에 3자리마다 콤마를 넣는다.
//======================================================================================================
function Global_MoneyComma(str) {
    str = "" + str + "";
    var retValue = "";

    for (var i = 0; i < str.length; i++) {
        if (i > 0 && (i % 3) == 0) {
            retValue = str.charAt(str.length - i - 1) + "," + retValue;
        }
        else {
            retValue = str.charAt(str.length - i - 1) + retValue;
        }
    }

    return retValue;
}


//======================================================================================================
// 함 수 명 : Global_TextBoxClear
// 설    명 : 텍스트박스를 클릭하면 내용이 클리어된다.
// 파라메타 : 텍스트박스 ID
//======================================================================================================
function Global_TextBoxClear(objectID)
{
    var objectControl = document.getElementById(objectID);          //텍스트박스 컨트롤
    
    objectControl.value = "";
}

//======================================================================================================
// 함 수 명 : Global_TextBoxClear2
// 설    명 : 텍스트박스를 클릭하면 내용이 클리어된다. (히든 텍스트박스 내용도 같이 지운다.)
// 비    고 : 코드를 저장한 히든 텍스트박스가 있는 경우 사용된다.
// 파라메타 : 텍스트박스 ID
//======================================================================================================
function Global_TextBoxClear2(objectID) {
    var objectControl = document.getElementById(objectID);                  //텍스트박스 컨트롤
    var objectControlH = document.getElementById(objectID + "H");           //히든 텍스트박스 컨트롤

    objectControl.value = "";
    objectControlH.value = "";
}


//======================================================================================================
// 함 수 명 : Global_FileExtCheck
// 설    명 : 파일 확장자를 체크한다.
// 파라메타 : 객체(텍스트박스 등)
// 파라메타 : 허용할 확장자명 (',' 구분자로 이루어진 문자열)
// 파라메타 : 메세지
//======================================================================================================
function Global_FileExtCheck(object, passExtStr, msg)
{    
    var isPass = false;
    var ext = object.value.substr(object.value.lastIndexOf(".") + 1);                       //파일의 확장자
    var passExt = passExtStr.split(",");                                                    //허용할 확장자 배열                   
    
    //허용할 확장자를 하나씩 비교한다.
    for(var i=0; i < passExt.length; i++)
    {
        //해당 확장자가 허용확장자 인 경우
        if(ext.toLowerCase() == passExt[i].toLowerCase())
        {
            isPass = true;
        }
    }
    
    //허용 확장자인 경우
    if(isPass)
    {
        return true;
    }
    else
    {
        alert(msg);
        return false;
    }    
}


//======================================================================================================
// 함 수 명 : Global_TextCheckConfirm
// 설    명 : 히든 텍스트박스에 데이타가 있는지 없는지 체크한 뒤 확인 메세지를 출력한다. (삭제할 데이타 키값 등을 히든 텍스트박스에 저장한 경우 사용)
// 파라메타 : 히든 텍스트박스ID
// 파라메타 : 텍스트박스가 비었을 때 표시할 메세지
// 파라메타 : 확인 창이 떴을 경우 출력할 메세지
//======================================================================================================
function Global_TextCheckConfirm(ObjectID, messageOne, messageTwo)
{
    var isCheck = false;
    
    //삭제할 항목이 있는 경우
    if(Global_TextBoxCheck(ObjectID, messageOne))
    {
        isCheck = Global_Confirm(messageTwo);
    }
    else
    {
        isCheck = false;
    }
    
    return isCheck;
}


//======================================================================================================
// 함 수 명 : Global_TextFieldAdd
// 설    명 : 텍스트박스에 해당 값을 추가 및 삭제한다.
// 파라메타 : 텍스트박스ID
// 파라메타 : 값
// 파라메타 : 추가 및 삭제 구분값 ([ADD]:추가, [DEL]:삭제)
//======================================================================================================
function Global_TextFieldAdd(ObjectID, value, flag) {
    var textFieldControl = document.getElementById(ObjectID);        //체크박스의 값을 입력할 텍스트박스 컨트롤

    //해당 체크박스를 선택한 경우
    if (flag == "ADD") {
        //텍스트박스에서 선택된 체크박스의 값을 붙인다.
        textFieldControl.value = textFieldControl.value + value + ",";
    }
    else if (flag == "DEL") {
        //텍스트박스에서 선택된 체크박스의 값을 뺀다.
        textFieldControl.value = textFieldControl.value.replace(value + ",", "");
    }
}

//======================================================================================================
// 함 수 명 : Global_TextFieldAdd
// 설    명 : 체크박스의 키값(value)을 삭제할 데이타 키값을 텍스트박스에 추가한다.
// 파라메타 : 체크박스 객체
// 파라메타 : 체크박스의 값을 입력할 텍스트박스 아이디 (주로 히든필드 사용)
//======================================================================================================
function Global_CheckToTextFieldAdd(chkbox, ObjectID)
{    
    var textFieldControl = document.getElementById(ObjectID);        //체크박스의 값을 입력할 텍스트박스 컨트롤
        
    //해당 체크박스를 선택한 경우
	if(chkbox.checked == true)			
	{
		//텍스트박스에서 선택된 체크박스의 값을 붙인다.
		textFieldControl.value = textFieldControl.value + chkbox.value + ",";
	}
	else
	{
		//텍스트박스에서 선택된 체크박스의 값을 붙인다.
		textFieldControl.value = textFieldControl.value.replace(chkbox.value + ",", "");
	}
}


//======================================================================================================
// 함 수 명 : Global_TextFieldTwoAdd
// 설    명 : 체크박스의 키값(value)을 삭제할 데이타 키값을 텍스트박스에 추가한다. (두개의 키값을 저장할 경우 사용)
// 파라메타 : 체크박스 객체
// 파라메타 : 체크박스의 값을 입력할 텍스트박스 아이디 (주로 히든필드 사용)
// 파라메타 : 추가할 값(첫번째)
// 파라메타 : 추가할 값(두번째)
//======================================================================================================
function Global_CheckToTextFieldTwoAdd(chkbox, objectID, value1, value2)
{
    var textFieldControl = document.getElementById(objectID);        //체크박스의 값을 입력할 텍스트박스 컨트롤
    
    //해당 체크박스를 선택한 경우
	if(chkbox.checked == true)			
	{
		//텍스트박스에서 선택된 체크박스의 값을 붙인다.
		textFieldControl.value = textFieldControl.value + value1 + "$" + value2 + ",";
	}
	else
	{
		//텍스트박스에서 선택된 체크박스의 값을 붙인다.
		textFieldControl.value = textFieldControl.value.replace(value1 + "$" + value2 + ",", "");
	}
}


//======================================================================================================
// 함 수 명 : Global_SpaceHidden
// 설    명 : 체크박스를 클릭하면 지정한 부분을 숨긴다.
// 파라메타 : 체크박스 객체
// 파라메타 : 숨길 부분의 아이디
//======================================================================================================
function Global_SpaceHidden(chkbox, ObjectID)
{   
    var spaceHiddenControl = document.getElementById(ObjectID);        //숨길 부분의 컨트롤
  
    //해당 체크박스를 선택한 경우
	if(chkbox.checked == true)			
	{
		//해당 부분을 표시한다.
		spaceHiddenControl.style.display = "block";
	}
	else
	{
		//해당 부분을 숨긴다.
		spaceHiddenControl.style.display = "none";
	}
}



//======================================================================================================
// 함수명 : Global_FileUploadAddNDel
// 설명 : 파일 업로드를 위한 입력 필드 추가 삭제를 위한 수량 및 제한 조건 조절
// 파라메타: [add]:파일업로더 추가, [del]:파일업로더 삭제
// 파라메타: 파일업로더 추가 갯수 한계 정하기
// 파라메타: 파일업로더를 추가할 테이블 ID
// 파라메타: 파일업로더 크기(Width)
// 파라메타: 파일업로더ID
//======================================================================================================
function Global_FileUploadAddNDel(mode, count, filetableID, size, fileUploadID)
{	
    var oTable  = document.getElementById(filetableID);
    var cnt = oTable.rows.length;  

  	if((cnt >= 1 && mode == "add") || (cnt >= 1 && mode == "del"))
  	{
	    //파일업로더 추가일 경우 한계 갯수에 따른 메세지 출력
		if(mode == "add")
		{	
			if(cnt == count)
			{
			    alert("첨부파일은 " + count + "개 이상 추가 할 수 없습니다.");				
				
				return false;
			}
		}
		else
		{
		    if(cnt == 1)
			{
			    alert("더이상 삭제할 첨부파일이 없습니다.");				
				
				return false;
			}
		}
		
	    //파일업로더 추가
	    if(mode == "add")
	    {
            var oTr = oTable.insertRow(oTable.rows.length);
            var oTd1 = oTable.rows(oTr.rowIndex).insertCell(0);
            
            oTd1.innerHTML = "<input type='File' id='" + fileUploadID + cnt + 1 +"' name='" + fileUploadID +"' size='" + size + "' class='form' runat='server'>";
		}
		//파일업로더 삭제
		else if(cnt != 1)
		{
            oTable.deleteRow(cnt - 1);
		}
	} 
}


//======================================================================================================
// 함 수 명 : Global_Email
// 설    명 : E-Mail 형식 체크
// 파라메타 : 문자열
//======================================================================================================
function Global_Email(str) {
    if (str != "") {
        if (Global_Trim(str) != "") {
            var chkEmail = str.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);

            if (chkEmail == null) {
                alert("메일 주소의 형식이 올바르지 않습니다.");
                return false;
            }
            else {
                return true;
            }
        }
        else {
            return true;
        }
    }
    else {
        return true;
    }
}



//======================================================================================================
// 함 수 명 : Global_TextareaCheck
// 설    명 : 텍스트 에어리어 글자수 제한
// 파라메타 : 텍스트 에어리어 name
// 파라메타 : 제한 글자수
//======================================================================================================
function Global_TextareaCheck(aro_name, ari_max) {
    var ls_str = aro_name.value; // 이벤트가 일어난 컨트롤의 value 값
    var li_str_len = ls_str.length;  // 전체길이

    // 변수초기화
    var li_max = ari_max; // 제한할 글자수 크기
    var li_byte = 0;  // 한글일경우는 2 그밗에는 1을 더함
    var li_len = 0;  // substring하기 위해서 사용
    var ls_one_char = ""; // 한글자씩 검사한다
    var ls_str2 = ""; // 글자수를 초과하면 제한할수 글자전까지만 보여준다.

    for (i = 0; i < li_str_len; i++) {
        // 한글자추출
        ls_one_char = ls_str.charAt(i);

        // 한글이면 2를 더한다.
        if (escape(ls_one_char).length > 4) {
            li_byte += 2;
        }
        // 그밗의 경우는 1을 더한다.
        else {
            li_byte++;
        }

        // 전체 크기가 li_max를 넘지않으면
        if (li_byte <= li_max) {
            li_len = i + 1;
        }
    }

    // 전체길이를 초과하면
    if (li_byte > li_max) {
        alert("내용은 한글 " + li_max / 2 + "자 영문 " + li_max + "자 까지만 허용됩니다.");
        ls_str2 = ls_str.substr(0, li_len);
        aro_name.value = ls_str2;
    }
    aro_name.focus();
}

//======================================================================================================
// 함 수 명 : Global_SetCookie
// 설    명 : 쿠키에 값을 입력합니다.
// 파라메타 : 쿠키 이름
// 파라메타 : 쿠키 값
// 파라메타 : 쿠키 만료일
// 파라메타 : 제한 글자수
//======================================================================================================
function Global_SetCookie(name, value, expiredays) {
    var todayDate = new Date();
    
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

//======================================================================================================
// 함 수 명 : Global_GetCookie
// 설    명 : 쿠키에 입력된 값을 가지고 옵니다.
// 파라메타 : 쿠키 이름
//======================================================================================================
function Global_GetCookie(name) {
    var nameOfCookie = name + "=";
    var x = 0;
    
    while (x <= document.cookie.length) {
        var y = (x + nameOfCookie.length);
        if (document.cookie.substring(x, y) == nameOfCookie) {
            if ((endOfCookie = document.cookie.indexOf(";", y)) == -1)
                endOfCookie = document.cookie.length;
            return unescape(document.cookie.substring(y, endOfCookie));
        }
        x = document.cookie.indexOf(" ", x) + 1;
        if (x == 0)
            break;
    }

    return "";
}

//======================================================================================================
// 함 수 명 : Global_DelCookie
// 설    명 : 해당 쿠키를 삭제한다.
// 파라메타 : 쿠키 이름
//======================================================================================================
function Global_DelCookie(name)
{
    var expireDate = new Date();

    //어제 날짜를 쿠키 소멸 날짜로 설정한다.
    expireDate.setDate( expireDate.getDate() - 1 );
    document.cookie = name + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";
}



//======================================================================================================
// 함 수 명 : Global_RemoveOutline
// 설    명 : 라디오 버튼 및 체크 버튼의 테두리 없애는 함수
//======================================================================================================
function Global_RemoveOutline() {
    //input 컨트롤을 모두 찾는다.
    for (i = 0; i < document.getElementsByTagName("input").length; i++) {
        objinput = document.getElementsByTagName("input");

        //---------------------------------테두리(Border) 없애기------------------------------------------------------
        //input 컨트롤 중에서 "라디오버튼", "체크박스"인 경우
        if (objinput[i].type == "radio" || objinput[i].type == "checkbox" || objinput[i].type == "image") {
            objinput[i].style.border = 0;
        }
        else {
            objinput[i].style.border = "1px solid #cfcfcf";
        }
        //------------------------------------------------------------------------------------------------------------

        //--------------------------------색깔(BackGround) 넣기-------------------------------------------------------
        //input 컨트롤 중에서 "텍스트박스", "텍스트박스(패스워드)"인 경우
        if (objinput[i].type == "text" || objinput[i].type == "password") {
            objinput[i].style.background = "#F1F1F1";
        }
        else {
            objinput[i].style.background = "";
        }
        //------------------------------------------------------------------------------------------------------------
    }
}


//**********************************************************************************************************************************************************
//**********************************************************************************************************************************************************
//**********************************************************************************************************************************************************
//**********************************************************************************************************************************************************




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;
    }
}