﻿


function fctChkTitleLength(strElementName, maxLen, strAlertMessage, strAction)
{
    /*
        double dblLength = 0;
        int i, j;
        string strValue = strCategorName;

        for (i = 0, j = strValue.Length; i < j; i++)
        {
            char C = strValue[i];
            dblLength += (Char.GetUnicodeCategory(C).ToString() == "OtherLetter") ? 1.85 : 1.0;

            if (dblLength > dblMaxLength)
            {
                break;
            }
        }
    */
        var len;
        var strElementValue = eval("document.getElementById(\"" + strElementName + "\").value");
        strElementValue.trim();
        len = strElementValue.toString().length;

        if (len > maxLen) {
            alert(strAlertMessage + "\n  현재길이 " + len + "/(" + maxLen + "자 제한)");

            if (strAction != "") {
                eval("document.getElementById(\"" + strElementName + "\")." + strAction);
            }
 
            return false;
        }
        else
            return true;
}


// ====================================================================================
// 작 성 일 : 2008-10-15
// 작 성 자 : 김진수2
// 설    명 : 제목과 내용의 빈값 체크
// 목    적 : 제목과 내용의 값이 없으면 입력안됨
// ====================================================================================
function fctEmptyCheck(strElementName)
{

// ------------------------------------------------------------------------------------ [2008-10-15 김진수2:수정]
// 공용함수 생성
// ------------------------------------------------------------------------------------ (변경전)
/*
    var temp = document.getElementById("ctl00$mainContent$txtTitle").value;
    
    if (temp == "")
    {
        alert("제목을 입력하세요.");
        return false;
    }
    
    if(!fn_UBWebEditor_EmptyCheck())
    {
        return false;
    }
    
    return true;
*/

    if (!fctEmptyElementCheck(strElementName, "- 제목을 입력하십시요", "focus();")) 
    {
        return false;
    }

    if (!fctChkTitleLength(strElementName, 48, "- 제목의 길이가 너무 깁니다", "focus();") == true)
    {
        return false;
    }

    // ------------------------------------------------------------------------------------ [2008-10-27 김진수2:수정]
    // 리팩토링
    // ------------------------------------------------------------------------------------ (변경전)
    /*
    if (!fn_UBWebEditor_EmptyCheck()) {
        return false;
    }
    */
    // ------------------------------------------------------------------------------------ (변경후)

    // [2008-10-27 김진수2:UBWebEditor가 빈값인지 체크]
    if (!fctEmptyUBWebEditorCheck()) 
    {
        return false;
    }
    // ------------------------------------------------------------------------------------
    return true;
}

// ========================================================================================
// 작 성 일 : 2008-10-27 10:52
// 작 성 자 : 김진수2
// 설    명 : UBWebEditor 값 체크
// 목    적 : 빈값이면 알림창 표시(UBWebEditor 함수에서 처리)
// ========================================================================================
function fctEmptyUBWebEditorCheck() {

    /*
    if (!fn_UBWebEditor_EmptyCheck()) 
    {
        return false;
    }
    return true;    
    */ 
    /*
    var obj = document.getElementById("ir1");
    if (obj.value == "") {
        alert("본문을 입력해 주시길 바랍니다.");
        return false;
    }
    else {
        return true;
    }
    */
    return true;
}

// ====================================================================================
// 작 성 일 : 2008-10-15
// 작 성 자 : 김진수2
// 설    명 : Element의 값 체크
// 목    적 : 빈값이면 알림창 표시
// ====================================================================================
function fctEmptyElementCheck(strElementName, strAlertMessage, strAction)
{
    var strElementValue = eval("document.getElementById(\"" + strElementName +"\").value");
    
    if (strElementValue.trim() == "")
    {
        alert(strAlertMessage);
        
        if (strAction != "" )
        {
            eval("document.getElementById(\"" + strElementName +"\")." + strAction);
        }
        
        return false;
    }
    else
    {
        return true;
    }
}

// ========================================================================================
// 작 성 일 : 2008-11-17 17:47
// 작 성 자 : 김재환
// 설    명 : checkBox 체크 확인
// 목    적 : 체크가 안 되어 있으면 알림창 표시
// ========================================================================================
function fctCheckboxCheck(strElementName, strAlertMessage, strAction)
{
    var obj = $(strElementName);
    
    if (obj.checked)
    {
        return true;
    }
    else
    {
        alert(strAlertMessage);
        
        if (strAction != "" )
        {
            eval("document.getElementById(\"" + strElementName +"\")." + strAction);
        }
        
        return false;
    }
}

// ========================================================================================
// 작 성 일 : 2008-11-18 11:24
// 작 성 자 : 김재환
// 설    명 : Element의 값의 길이 구하기
// 목    적 : Element의 값의 길이 구하기
// ========================================================================================
function fctGetLength(strElementName)
{
    var obj = $(strElementName);
    
    return obj.value.length;
}

// ========================================================================================
// 작 성 일 : 2008-11-18 13:13
// 작 성 자 : 김재환
// 설    명 : Element의 값의 길이 체크
// 목    적 : Element의 값의 길이 체크
// ========================================================================================
function fctLengthCheck(strElementName, strAlertMessage, strLength)
{
    var obj = $(strElementName);
    
    if (fctGetLength(strElementName) < strLength)
    {
        alert(strAlertMessage);
        obj.select();
        obj.focus();
        return false;
    }
    
    return true;
}

// ========================================================================================
// 작 성 일 : 2008-11-18 11:27
// 작 성 자 : 김재환
// 설    명 : 두 Element의 값을 비교
// 목    적 : 두 Element의 값을 비교
// ========================================================================================
function fctCompareElements(strElementOne, strElementTwo)
{
    var objOne = $(strElementOne);
    var objTwo = $(strElementTwo);
    
    if (objOne.value == objTwo.value)
    {
        return true;
    }
    else
    {
        return false;
    }
}

// ========================================================================================
// 작 성 일 : 2008-11-18 14:17
// 작 성 자 : 김재환
// 설    명 : Select 선택된 값 가져오기
// 목    적 : Select 선택된 값 가져오기
// ========================================================================================
function fctGetSelectValue(strElementName)
{
    var obj = $(strElementName);
    
    return obj.options[obj.selectedIndex].value;
}

// ========================================================================================
// 작 성 일 : 2008-11-18 14:18
// 작 성 자 : 김재환
// 설    명 : Select 값 체크하기
// 목    적 : Select 값 체크하기
// ========================================================================================
function fctSelectValueCheck(strElementName, strAlertMessage, strAction)
{   
    if (fctGetSelectValue(strElementName) != "")
    {
        return true;
    }
    else
    {
        alert(strAlertMessage);
        
        if (strAction != "" )
        {
            eval("document.getElementById(\"" + strElementName +"\")." + strAction);
        }
        
        return false;
    }
}

// ====================================================================================
// 작 성 일 : 2008-10-15
// 작 성 자 : 김진수2
// 설    명 : 팝업창의 너비와 높이를 입력받아 팝업창 오픈(feature에 left, top이 없어야겠다)
// 목    적 : 화면의 중앙에 팝업을 표시하기위함
// ====================================================================================
function fctWindowCenterOpen(strUrl, strName, strFeature, strWidth, strHeight)
{
    var intResult;
    
    var strLeft = fctGetLeftPosition(strWidth);
    var strTop = fctGetTopPosition(strHeight);
    
    // 특성이 없으면 기본값 적용
    if ( strFeature.toString().trim() == "")
    {
        strFeature = "toolbar=no,location=no,directories=no,status=no,";
        strFeature += "menubar=no,scrollbars=no,resizable=no";
    }
    
    strFeature += ",left=" + strLeft;
    strFeature += ",top=" + strTop;
    strFeature += ",width=" + strWidth;
    strFeature += ",height=" + strHeight;

    intResult = window.open(strUrl, strName, strFeature);

    //return intResult;
}

// ========================================================================================
// 작 성 일 : 2009-02-20 19:15
// 작 성 자 : 임경우
// 설    명 : 쿠키 가져오기
// 목    적 : 
// ========================================================================================

function fctGetCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

// ========================================================================================
// 작 성 일 : 2009-02-20 19:15
// 작 성 자 : 임경우
// 설    명 : 쿠키 있는지 체크
// 목    적 : 
// ========================================================================================

function fctCheckCookie() {

    PopupCookie = fctGetCookie('PopupCookie');
    if (PopupCookie != null && PopupCookie != "") {
        return false;
    }
    else {
        return true;
    }
}

// ========================================================================================
// 작 성 일 : 2009-02-20 19:15
// 작 성 자 : 임경우
// 설    명 : 쿠키 설정
// 목    적 : 
// ========================================================================================

function fctSetCookie(c_name, value, expiredays) {
    var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + "; path=/" +
            ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function fctClosePopup(obj) {
    fctSetCookie("PopupCookie", "off", 1);
    obj.close();
}

// ====================================================================================
// 작 성 일 : 2009-02-19
// 작 성 자 : 임경우
// 설    명 : 팝업 오픈
// 목    적 : 
// ====================================================================================
function fctOpenPopup(strUrl, strLeftPos, strTopPos, strDirection, strPopupCnt) {

    if (fctCheckCookie() == false) return;

    var intResult;
    var intWidth = 300;
    var intHeight = 160;
    var intHeightMargin = 20;
    var intPopupCnt = strPopupCnt;
    var strWidth;
    var strHeight;

    if (strDirection == "1") {
        strWidth = (intWidth * intPopupCnt);
        strHeight = intHeight + intHeightMargin + 5;
    }
    else if (strDirection == "2") {
        strWidth = intWidth;
        strHeight = ((intHeight * intPopupCnt) + intHeightMargin);
    }

    strFeature = "toolbar=no,location=no,directories=no,status=no,";
    strFeature += "menubar=no,scrollbars=no,resizable=no";
    strFeature += ",left=" + strLeftPos;
    strFeature += ",top=" + strTopPos;
    strFeature += ",width=" + strWidth;
    strFeature += ",height=" + strHeight;

    // [2009-02-20 임경우:쿠키 있는지 체크하기]
    intResult = window.open(strUrl, null, strFeature);
}

// ====================================================================================
// 작 성 일 : 2008-10-15
// 작 성 자 : 김진수2
// 설    명 : 팝업창의 너비를 고려하여 화면 왼쪽으로부터 팝업될 창의 위치를 구함
// 목    적 : 화면의 중간에 팝업을 위치시키기 위함
// ====================================================================================
function fctGetLeftPosition(intWidth)
{
    var ow = Math.round((screen.availWidth - intWidth)/2);

    return ow;
}

// ====================================================================================
// 작 성 일 : 2008-10-15
// 작 성 자 : 김진수2
// 설    명 : 팝업창의 높이를 고려하여 화면 상단으로부터 팝업될 창의 위치를 구함
// 목    적 : 화면의 중간에 팝업을 위치시키기 위함
// ====================================================================================
function fctGetTopPosition(intHeight)
{
    var cw = Math.round((screen.availHeight - intHeight)/2);
    
    return cw;
}

// ====================================================================================
// 작 성 일 : 2008-12-11
// 작 성 자 : 정용조
// 설    명 : 우편번호,주소의 값을 Opener에게 전달함
// 목    적 : 우편번호,주소의 값을 Opener에게 전달함
// ====================================================================================
function fctSetPostCD(strpost, straddr) {
    var strpost1;
    var strpost2;
    strpost1 = strpost.substring(0, 3);
    strpost2 = strpost.substring(4, 7);
    opener.window.document.getElementById('ctl00_MainContent_txtPost1').value = strpost1;
    opener.window.document.getElementById('ctl00_MainContent_txtPost2').value = strpost2;
    opener.window.document.getElementById('ctl00_MainContent_txtAddr1').value = straddr;
    window.close();
}

// ====================================================================================
// 작 성 일 : 2008-12-11
// 작 성 자 : 정용조
// 설    명 : 우편번호조회 창 Open
// 목    적 : 우편번호조회 창 Open
// ====================================================================================
function fctOpenPost() {
    fctWindowCenterOpen("/etc/Member/find_zip.aspx", "우편번호조회", "", 438, 315);
    return false;
}

// ========================================================================================
// 작 성 일 : 2008-12-08 11:24
// 작 성 자 : 김재환
// 설    명 : 페이지 이동
// 목    적 : 페이지 이동
// ========================================================================================
function fctGoUrl(strUrl) {
    window.location.href = strUrl;
}

// ========================================================================================
// 작 성 일 : 2009-01-14 15:48
// 작 성 자 : 임경우
// 설    명 : 게시판 리스트 페이지에서 화면스크롤 위치 설정
// 목    적 : ajax 의 스크롤바 유지기능이 끝난 후 위치를 설정 함
// ========================================================================================
function fctSetPosition(sender, args) {
    var obj = document.getElementById("ctl00_MainContent_hdnShowValue");

    if (obj.value == "aContent") {
        fctGoContent();
        //alert('콘텐츠 보기');
    }
    else if (obj.value == "aList") {
        fctGoList();
        //alert('리스트 보기');
    }
    else if (obj.value == "aWinList") {
        fctWinGoList();
        //alert('리스트 보기');
    }

    // [2009-02-20 임경우:내부 anchor 링크 초기화]
    obj.value = "noAnchor";

    // [2009-01-14 임경우:꼭 보세요 위치 재정렬]
    //fctCurrentScroll();
}

// ========================================================================================
// 작 성 일 : 2008-12-22 11:24
// 작 성 자 : 김재환
// 설    명 : 리스트 페이지에서 다른 위치로 이동
// 목    적 : 리스트 페이지에서 다른 위치로 이동
// ========================================================================================
function fctGoList() {
    location.hash = "aList";
}

// ========================================================================================
// 작 성 일 : 2008-12-22 11:24
// 작 성 자 : 김재환
// 설    명 : 리스트 페이지에서 다른 위치로 이동
// 목    적 : 리스트 페이지에서 다른 위치로 이동
// ========================================================================================
function fctWinGoList() {
    location.hash = "aWinList";
}

// ========================================================================================
// 작 성 일 : 2008-12-22 11:24
// 작 성 자 : 김재환
// 설    명 : 리스트 페이지에서 다른 위치로 이동
// 목    적 : 리스트 페이지에서 다른 위치로 이동
// ========================================================================================
function fctGoContent() {
    location.hash = "aContent";
}

// ========================================================================================
// 작 성 일 : 2008-12-05 17:44
// 작 성 자 : 김재환
// 설    명 : 즐겨찾기 추가
// 목    적 : 즐겨찾기 추가
// ========================================================================================
function fct_SetFavorites() {
    window.external.AddFavorite('http://www.ysarang.co.kr', '의사랑')
}

// ========================================================================================
// 작 성 일 : 2009-01-07 17:44
// 작 성 자 : 김재환
// 설    명 : 시작페이지 추가
// 목    적 : 시작페이지 추가
// ========================================================================================
function fct_SetStartPage(start) {
    start.style.behavior = 'url(#default#homepage)'; start.setHomePage('http://www.ysarang.co.kr');
}

// ====================================================================================
// 작 성 일 : 2009-02-23
// 작 성 자 : 김재환
// 설    명 : 팝업 오픈
// 목    적 : 
// ====================================================================================
function fctOpenSimplePopup(strUrl) {

    window.open(strUrl, 'Interlock');
}

