﻿
/*********************  Jquery용 공통 모음 ************************/
// 작성일자 : 2010.02.04  gili
/*********************************************************************/
function _Confirm(message, objId, isConfirm) {

    return confirm(message);
    
    // 당분간 사용하지 않는다. 
    if (isConfirm) {
        document.getElementById(objId).onclick = "";
        document.getElementById(objId).click();
        return;      
    }
    else {
        isConfirm = false;        
    }
    if (!isConfirm) {
        jConfirm(message, '확인창', function(r) { if (r) { _Confirm(message, objId, true); } });
    } 

    return isConfirm;
}

function _Alert(message) {

    return alert(message);
    
    // 당분간 사용하지 않는다. 
    jAlert(message);
}


function _CopyClibBoard(string) {
    $.clipboard(string);
    _Alert("복사되었습니다. ");
}


//입력시 양의 숫자만 허용
function _keyDownUInt(evt) {    
    switch (evt.keyCode) {
        case 8:
        case 9:
        case 13:
        case 35:
        case 36:
        case 37:
        case 38:
        case 39:
        case 40:
        case 46:
            return true;
    }

    if ((evt.keyCode < 48 || evt.keyCode > 105) || (evt.keyCode > 57 && evt.keyCode < 96))
        evt.preventDefault();
}



function _CheckMaxLength(textField, len, message) {
try {
        var theField = document.getElementById(textField);
        if (_GetTextLength(theField.value) > len) {
            _Alert(message);
            theField.focus();
            return false;
        }
        else {
            return true;
        }
    } catch (e) { return false; }
}

function _CheckMinLength(textField, len, message) {
    try {
        var theField = document.getElementById(textField);
        if (_GetTextLength(theField.value) < len) {
            _Alert(message);
            theField.focus();
            return false;
        }
        else {
            return true;
        }
    } catch (e) { return false; }
}

function _GetTextLength(value) {
    // nvarchar를 사용할경우에는 한글과 영문의
    // 차이가 없으므로 그냥 길이를 던진다. 
    return value.length;
}


// 단축요소
// 컨트롤을 가져옴. 
function _Get(ControlId) {
    if (document.getElementById(ControlId))
        return document.getElementById(ControlId);
    return null;
}

function _GetT(ControlId) {
    if (_Get(ControlId).type == 'select-one') {
        return _Get(ControlId).options[_Get(ControlId).selectedIndex].text;
    }
    return _Get(ControlId).value;
}


// 컨트롤의 값을 가져옴
function _GetV(ControlId) {
     if (_Get(ControlId)) {
        if (_Get(ControlId).type == 'select-one') {
            if (_Get(ControlId).selectedIndex == -1)
                return '';
            return _Get(ControlId).options[_Get(ControlId).selectedIndex].value;
        }
        else if (_Get(ControlId).type == 'checkbox') {
            return _Get(ControlId).checked ? "Y" : "N";
        }
        else {
            return _Get(ControlId).value;
        }
    }
    return "";
}


// Timeout
function sleep(sec) {
    var now = new Date();
    var exitTime = now.getTime() + (sec);
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime) return;
    }
}

// ***************************************************** jquery Helper ***************************************************/
function _InitControls(id) {
    var conts = $("#" + id + " :input");
    for(var i=0;i<conts.length;i++) {
        conts[i].value = "";        
    }
    return false; 
}


// *****************************************************   팝업 영역 *****************************************************/

// 우편번호 팝업
function _PostPopup(zipControlId, AddressControlId) {
    var retVal = window.showModalDialog("/CM/CM0001L.aspx", null, "dialogWidth:" + 400 + "px;dialogHeight:" + 500 + "px;status:no;scroll:no;");
    if (!retVal) {
        return false;
    }
    _Get(zipControlId).value = retVal.zipcode;
    _Get(AddressControlId).value = retVal.address;
    return false;
}

// 전시팝업
function _SearchShowPopup(showNameCtrlId, showIdCtrlId) {
    var retVal = window.showModalDialog("http://www.artgy.or.kr/CM/CM0100M.aspx", null, "dialogWidth:" + 500 + "px;dialogHeight:" + 670 + "px;status:no;scroll:no;");
    if (retVal != null) {
        _Get(showNameCtrlId).value = retVal.showname;
        _Get(showIdCtrlId).value = retVal.showid;
    }
    return false;
}

// 블로거 리뷰 등록
function _BlogerReviewRegiPopup(isAdmin, actionControl) {
    if (isAdmin == 1) {
        var retVal = window.showModalDialog("http://www.artgy.or.kr/CM/CM0004M.aspx?type=review&adminyn=1", null, "dialogWidth:" + 378 + "px;dialogHeight:" + 670 + "px;status:yes;scroll:yes;");
    }
    else {
        var retVal = window.showModalDialog("http://www.artgy.or.kr/CM/CM0004M.aspx?type=review", null, "dialogWidth:" + 378 + "px;dialogHeight:" + 670 + "px;status:yes;scroll:yes;");

    }

    blg_reload();
 //   document.location.reload();
 //   if (retVal != null) {
 //       _Get(actionControl).click();
 //   }
    return false;
}

function _ShowTicket(states, perfid, userid) {
     if(userid == "") {    
                       alert(' 로그인 페이지로 이동합니다. ' );
                       location.href = 'https://www.artgy.or.kr/MM/Artgylogin.aspx?RedirectUrl=' + escape(location.href);
                       return;
                   }        
     
    switch (states) {
        case '0' : alert(' 예정공연으로 예매할수 없습니다. '); return false;
        case '1' : alert(' 예매할수 없습니다. '); return false;         
        case '4' : alert(' 판매중지되었습니다. '); return false; 
        case '16' : alert(' 판매마감되었습니다. '); return false; 
        case '32' : alert(' 예매완료되었습니다. '); return false; 
        case '999' : alert(' 예매완료되었습니다. '); return false; 
        // '0'예정, '1' 공연등록, '2' 정상, '4' 판매중지, '8' 판매취소, '16' 판매마감, '32' 정산완료 '99' 날짜지남.
    }    
    gf_windowOpen("http://www.artgy.or.kr/home/PerfSale/PerfSalePage.aspx?Id="+perfid, '티겟', 1010, 600);    
    return false;
}

/*************************************************/


function _NewsLetter(userid) {
     if(userid == "") {    
                       alert(' 로그인 페이지로 이동합니다. ' );
                       location.href = 'https://www.artgy.or.kr/MM/Artgylogin.aspx?RedirectUrl=/MM/MM0201M.aspx';
                       return;
                   }        
     location.href = 'https://www.artgy.or.kr/MM/MM0201M.aspx';
    return false;
}

function _RequestLogin() {
	alert(' 로그인 페이지로 이동합니다. ' );
	location.href = 'https://www.artgy.or.kr/MM/Artgylogin.aspx?RedirectUrl=' + escape(location.href);;
	return;
}        



// 상세보기 화면 이동.
function _ShowDetail(showid, genretype) {
    if (genretype == '01') // 공연
    {
        location.href = "http://www.artgy.or.kr/PF/PF0201V.aspx?showid=" + showid;
    }
    else {
        location.href = "http://www.artgy.or.kr/EH/EH0201V.aspx?showid=" + showid;
    }     
}



// 월간누리 만족도 조사.
function _MonthNuriPopup(yearmonth) {
    window.showModalDialog("http://www.artgy.or.kr/CO/CO0903M.aspx?yearmonth="+yearmonth, null, "dialogWidth:" + 416 + "px;dialogHeight:" + 259 + "px;status:no;scroll:no;");
    return false;
}

// 1:1고객만족 
function _CustomerVoice(userid) {
    if(userid == '') 
    {
        alert(' 로그인이 필요합니다. ');
        location.href = "https://www.artgy.or.kr/MM/ArtgyLogin.aspx?RedirectUrl=/CU/CU0001V.aspx";
        return false;
    }
    window.showModalDialog("http://www.artgy.or.kr/CU/CU0201M.aspx", null, "dialogWidth:" + 600 + "px;dialogHeight:" + 403 + "px;status:no;scroll:no;");
    return false;
}

// 극장보기
function _ShowTheater(thatercode) {
    switch (thatercode) {
        case "293": // 아람음악당
            gf_windowOpen("http://www.artgy.or.kr/html/theaterpop/aram_music_popup.html", '아람음악당', 820, 800);
            break;
        case "292": // 아람극장
            gf_windowOpen("http://www.artgy.or.kr/html/theaterpop/aram_theater_popup.html", '아람극장', 820, 800);
            break;
        case "7": // 어울림극장
            gf_windowOpen("http://www.artgy.or.kr/html/theaterpop/oulim_theater_popup.html", '어울림극장', 820, 800);
            break;
        case "294": // 새라새극장
            gf_windowOpen("http://www.artgy.or.kr/html/theaterpop/saerasae_theater_popup.html", '새라새극장', 820, 800);
            break;
        case "24":// 별모래극장
            gf_windowOpen("http://www.artgy.or.kr/html/theaterpop/star_theater_popup.html", '별모래극장', 820, 800);
            break;
    }
    return false;
}


// 센터팝업 
function _ShowCenter(centercode) {
    switch (centercode) {
        case "543": // 아람누리
            gf_windowOpen("http://www.artgy.or.kr/cm/cm0006m.aspx?centercode=1", '아람누리', 820, 800);
            break;
        case "542": // 어울림누리
            gf_windowOpen("http://www.artgy.or.kr/cm/cm0006m.aspx?centercode=2", '어울림누리', 820, 800);
            break;        
    }
    return false;
}

