/**
 * All check
 */
function _allCheck(form, allChkName, targetName)
{
    frmObj = document.forms[form.name];
    chkBox = frmObj[allChkName.name];

    setBox = frmObj[targetName];
    maxCnt = setBox.length;

    for(i=0;i<maxCnt;i++) {
        setBox[i].checked = chkBox.checked;
    }
}

/**
 * Market 자동접속(로그인) 새창
 *
 * @param mktNo market_no
 * @param mstId master_id
 */
function _marketAutoLogin(mktNo, mstId, allowIp)
{
    //동대문 수집 차단
    if (mktNo =='6' && allowIp ==''){
        alert("동대문닷컴 사이트 일시 운영중단 상태입니다.");
        return;
    }

    _targetWin = mstId+"_market";

    url = "/scm/market_auto_login.php?market_no="+mktNo+"&master_id="+mstId;

    window.open(url, '', "");
}


/**
 * Market 접속정보관리 팝업
 *
 * @param mktNo market_no
 * @param mstId master_id
 */
function _shopMarketList(mktNo, mstId)
{
    _targetWin = mstId+"_market";
    url = "/scm/shops/shops_market_insert.php?market_no="+mktNo+"&master_id="+mstId+"&cmdLogin=Y";
    window.open(url, _targetWin, 'width=600, height=550, left=50, top=50');
}

/**
 * Market에 등록된 상품 상세보기 새창
 *
 * @param mktNo market_no
 * @param mstId master_id
 * @param prodCode registerd_product_code(from market)
 */
function _marketProdView(mktNo, mstId, prodCode, dbNo)
{
    url = "/scm/common/market_product_view.php?market_no="+mktNo+"&master_id="+mstId+"&prod_code="+prodCode+"&dbNo="+dbNo;

    window.open(url, '', '');
}

function _marketEmoney(mktNo, mstId)
{
    url = "/scm/makret_recv_emoney.php?market_no="+mktNo+"&master_id="+mstId;
    window.open(url, "", "");

}

function _getIntToString(val)
{
    if (("" + val).length == 1) {
        val = "0" + val;
    }
    return val;

}

function _getTimeToDateFormat(dateObj, time)
{
    sYear    = dateObj.getFullYear();
    sMonth   = dateObj.getMonth() +1;
    sDay     = dateObj.getDate();

    date = sYear + "-" + _getIntToString(sMonth) + "-" + _getIntToString(sDay);

    return date;
}

function _quickSetDate(frm, sField, eField, sDays, eDays)
{
    var toDay    = new Date();
    var firstDay = new Date(toDay.getYear(),toDay.getMonth(),1);
    var sDayTime = sDays * 24 * 60 * 60 * 1000;
    var eDayTime = eDays * 24 * 60 * 60 * 1000;

    if (sDays == 'thismonth') {

        var sDayObj = firstDay;
        var eDayObj = new Date(toDay - eDayTime);

    } else if (sDays == 'lastmonth') {

        var lastDay = new Date(firstDay - 24 * 60 * 60 * 1000).getDate();

        var sDayObj = new Date(toDay.getYear(), toDay.getMonth()-1, 1);
        var eDayObj = new Date(toDay.getYear(), toDay.getMonth()-1, lastDay);

    } else {

        var sDayObj = new Date(toDay - sDayTime);
        var eDayObj = new Date(toDay - eDayTime);

    }

    sDate = _getTimeToDateFormat(sDayObj, sDayObj.getTime());
    eDate = _getTimeToDateFormat(eDayObj, eDayObj.getTime());

    frm[sField].value = sDate;
    frm[eField].value = eDate;
}


/**
 * textarea 작성 길이 체크(SMS, 댓글 등)
 */
function _checkTextLen(frmObj, strName, divId, cutLen, errMsg) {

    if(frmObj != '[object]') {
        return;
    }

    fieldName = strName.name;

    var msg = frmObj[fieldName].value;
    var len = 0;
    var lastLen;

    prtObj = document.getElementById(divId);

    if(errMsg =="") errMsg = "허용 길이 이상의 내용을 작성하셨습니다."
    if(cutLen =="") cutLen = 250;

    for (i = 0; i < msg.length; i++) {
        var nAsc = msg.charCodeAt(i);
        if ( (nAsc > 0)  && (nAsc < cutLen) && (nAsc != '\r'))
            len += 1;
        else
           len += 2;
       // OverFlow
       if(len > cutLen) {
           if(errMsg != "") alert(errMsg);
           temp = frmObj[fieldName].value.substr(0,i);
           frmObj[fieldName].value = temp;
           len = lastLen;
           break;
       }
       lastLen = len;
    }


    if ( len == 0 )
       prtObj.innerHTML = 0;
    else
       prtObj.innerHTML = len;
}

/**
 * 우편번호 찾기(새창)
 *
 * @param frmName 폼이름
 * @param zipName 우편번호 INPUT's name ( 2개일 경우 , 로 구분)
 * @param addr1Name 기본주소 INPUT's name
 * @param addr2Name 상세주소 INPUT's name
 */
function _searchZipCode(frmName, zipName, addr1Name, addr2Name)
{
    url = "/scm/common/zipcode.php?frmName="+frmName+"&zipName="+zipName+"&addr1Name="+addr1Name+"&addr2Name="+addr2Name;
    window.open(url, "zip_search", "width=500,height=370,scrolling=1,scrollbars=1,top=200,left=300");
}

/**
 * 창 크기 조절
 */
function _selfResize(width, height)
{
    self.resizeTo(width, height);
}

//상품이미지
function _prodViewProc(layerName, status, type) {

    setName = "_getOrdObj"+layerName;
    target = "img_["+layerName+"]";

    if (navigator.appName == "Netscape") {
        layerN = document.getElementById(target).style;
        if (status == 'show') layerN.visibility = 'visible';
        if (status == 'hide') layerN.visibility = 'hidden';

    }else {

        layerN = document.all[target].style;
        if (status == 'show'){
            layerN.visibility = 'visible';
            layerN.left = getxFieldY('X');
            layerN.top = getxFieldY('Y');
        }

        if (status == 'hide'){
            layerN.visibility = 'hidden';
        }

        if (status == ''){
            layerN.visibility = 'visible';
        }

    }

    prtMsg = "<table width='120' cellpadding='0' cellspacing='0' border='0' style='border:1px solid #cccccc'><tr><td bgcolor='FFFFFF' align='center'><img src='http://echosting.cafe24.com/image/admin/error_img.gif'></td></tr></table>";
    getUrl = "/scm/product_view.php";

    //게시판
    if( type == 'bbs'){
        qryStr = "cs_no=" + layerName;
    //상품
    }else if( type == 'product'){
        qryStr = "prdm_no=" + layerName;
    //주문
    }else{
        qryStr = "om_no=" + layerName;
    }
    _getServerPage(setName, target, getUrl, qryStr, prtMsg)
}

//상품이미지
function _prodViewProcInfo(layerName, status, type) {

    setName = "_getOrdObj"+layerName;
    target = "Lmemo_["+layerName+"]";

    if (navigator.appName == "Netscape") {
        layerN = document.getElementById(target).style;
        if (status == 'show') layerN.visibility = 'visible';
        if (status == 'hide') layerN.visibility = 'hidden';

    }else {
        layerN = document.all[target].style;
        if (status == 'show'){
            layerN.visibility = 'visible';
            layerN.left = getxFieldY('X');
            layerN.top = getxFieldY('Y');
        }

        if (status == 'hide'){
            layerN.visibility = 'hidden';
        }

        if (status == ''){
            layerN.visibility = 'visible';
        }

    }

    prtMsg = "<table width='120' cellpadding='0' cellspacing='0' border='0' style='border:1px solid #cccccc'><tr><td bgcolor='FFFFFF' align='center'><img src='http://echosting.cafe24.com/image/admin/error_img.gif'></td></tr></table>";
    getUrl = "/scm/product_view.php";

    //상품대장
    if( type == 'productAll'){
        qryStr = "prdm_no=" + layerName + "&ref=" + type;

    //오픈마켓 상품관리
    }else if( type == 'productDown'){
        qryStr = "prdm_no=" + layerName + "&ref=" + type;
    }
    _getServerPage(setName, target, getUrl, qryStr, prtMsg)
}

//주문정보
function _ordView(layerName, type) {

    setName = "_getOrdObj"+layerName;
    target = "Lmemo_["+layerName+"]";

    get_top("memo_["+layerName+"]");
    get_left("memo_["+layerName+"]");
//
    if (document.getElementById(target).style.display == 'block'){
        document.getElementById(target).style.display = 'none';
    }else{
        document.getElementById(target).style.display = 'block';
    }

    prtMsg = "<table cellpadding='0' cellspacing='0' border='0' style='border:1px solid #cccccc'><tr align='center'><td bgcolor='FFFFFF'><img src='http://shop.cafe24.com/scm/design/default/images/product/loading_motion.gif'></td></tr><tr><td bgcolor='FFFFFF'>LOADING...</td></tr></table>";
    getUrl = "/scm/order_view.php";
    //배송준비중
    qryStr = "om_no=" + layerName + "&type=" + type;
    _getServerPage(setName, target, getUrl, qryStr, prtMsg)
}

//주문처리로그
function _ordStatusLogView(omNo, layerName, statusType) {
    setName = "_getOrdObj"+layerName;
    target = "LstatusLog_["+layerName+"]";

    get_top("statusLog_["+layerName+"]");
    get_left("statusLog_["+layerName+"]");

    if (document.getElementById(target).style.display == 'block'){
        document.getElementById(target).style.display = 'none';
    }else{
        document.getElementById(target).style.display = 'block';
    }

    prtMsg = "<table cellpadding='0' cellspacing='0' border='0' style='border:1px solid #cccccc'><tr align='center'><td bgcolor='FFFFFF'><img src='http://shop.cafe24.com/scm/design/default/images/product/loading_motion.gif'></td></tr><tr><td bgcolor='FFFFFF'>LOADING...</td></tr></table>";
    getUrl = "/scm/order/order_status_log_view.php";

    qryStr = "om_no=" + omNo + "&layerName=" + layerName + "&statusType=" + encodeURI(statusType);
    _getServerPage(setName, target, getUrl, qryStr, prtMsg)
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
var tempX = 0;
var tempY = 0;

function getxFieldY(arg,e) {
    if (IE) {
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    }else{
        tempX = e.pageX;
        tempY = e.pageY;
    }

    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;}

    if (arg == "X"){
        return tempX + 20;
    }else{
        return tempY;
    }
}

// [Cookie] Clears a cookie
function _clearCookie(cookieName) {
    var now = new Date();
    var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
    setCookie(cookieName, '', yesterday);
}

// 쿠키를 만듭니다. 아래 closeWin() 함수에서 호출됩니다
function setCookie( name, value, expiredays )
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function 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 "";
}

// [Cookie] Sets value in a cookie
function _setCookie(cookieName, cookieValue, expireHour, path, domain, secure) {

    if( expireHour > 1) {

        _setHour = 1000 * 60 * 60 * expireHour;

        var expDate = new Date();
        expDate.setTime( expDate.getTime() + _setHour );

    }

    document.cookie =
        escape(cookieName) + '=' + escape(cookieValue)
        + (expireHour > 1 ? '; expires=' + expDate.toGMTString() : '')
        + (path ? '; path=' + path : '')
        + (domain ? '; domain=' + domain : '')
        + (secure ? '; secure' : '');
}

// [Cookie] Gets a value from a cookie
function _getCookie(cookieName) {
    var cookieValue = '';
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1) {
        var posValue = posName + (escape(cookieName) + '=').length;
        var endPos = document.cookie.indexOf(';', posValue);
        if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
        else cookieValue = unescape(document.cookie.substring(posValue));
    }
    return (cookieValue);
}

function _viewFlash(src, width, height)
{
    if(src != "") {
        objStr = '';
        objStr += '<object type="application/x-shockwave-flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
        objStr += '<param name="movie" value="'+src+'">';
        objStr += '<param name="quality" value="high">';
        objStr += '<param name="wmode" value="transparent">';
        objStr += '<embed src="'+src+'" quality="high" wmode="transparent" bgcolor="#ffffff" menu="false" width="'+width+'" height="'+height+'" swliveconnect="true" id="param" name="param" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
        objStr += '</object>';
        document.write(objStr);
    }
}

function _providerOpen()
{
    alert('지원하지 않는 서비스입니다.');
    return;
    //window.open('http://provider.shop.cafe24.com','','');
}

function _solutionOpen()
{
    window.open('http://scm.shop.cafe24.com/scm/','','');
}

function _imageHostOpen(){
    window.open('http://scm.shop.cafe24.com/scm/add/add_imagehosting.php','','');
}

function _imageManageOpen(){
    window.open('http://scm.shop.cafe24.com/scm/add/add_imagemanager.php','','');
}

function _galleryOpen(){
    window.open('http://shop.cafe24.com/web/info/info_introduce.php?menu=info&left1=02&tab=06','','');
}

function _expressOpen(){
    window.open('http://scm.shop.cafe24.com/scm/add/add_express.php','','');
}

function _smsOpen(){
    window.open('http://scm.shop.cafe24.com/scm/add/add_sms_service.php','','');
}

function _solutionOff()
{
    if(confirm("E-SCM 서비스를 종료하시겠습니까?")) {
        window.close();
    }
}

function _checkLoginSubmit(oFrm)
{
    _comp = oFrm['info[comp_id]'];
    _user = oFrm['info[usr_id]'];
    _pass = oFrm['info[usr_passwd]'];


    switch(oFrm.typeFlag.value) {
        case '1': //관리자
            _comp.value = oFrm.comp_id_1.value;
            _user.value = oFrm.comp_id_1.value;
            _pass.value = oFrm.usr_passwd_1.value;
            break;
        case '2': //운영자
            _comp.value = oFrm.comp_id_2.value;
            _user.value = oFrm.usr_id_2.value;
            _pass.value = oFrm.usr_passwd_2.value;
            break;
        case '3': //공급사
            _comp.value = oFrm.comp_id_3.value;
            _user.value = oFrm.usr_id_3.value;
            _pass.value = oFrm.usr_passwd_3.value;
            break;
    }


    if(_comp.value == '') {
        alert('ShopCafe24 ID를 입력하세요');
        switch(oFrm.typeFlag.value) {
            case '1': //관리자
                oFrm.comp_id_1.focus();
                break;
            case '2': //운영자
                oFrm.comp_id_2.focus();
                break;
            case '3': //공급사
                oFrm.comp_id_3.focus();
                break;
        }

        return false;
    }

    if(_user.value == '') {
        alert('Login ID를 입력하세요');
        switch(oFrm.typeFlag.value) {
            case '1': //관리자
                oFrm.usr_id_1.focus();
                break;
            case '2': //운영자
                oFrm.usr_id_2.focus();
                break;
            case '3': //공급사
                oFrm.usr_id_3.focus();
                break;
        }
        return false;
    }

    if(_pass.value == '') {
        alert('Password를 입력하세요');
        switch(oFrm.typeFlag.value) {
            case '1': //관리자
                oFrm.usr_passwd_1.focus();
                break;
            case '2': //운영자
                oFrm.usr_passwd_2.focus();
                break;
            case '3': //공급사
                oFrm.usr_passwd_3.focus();
                break;
        }
        return false;
    }

	return true;
}



function _popup(src, winName, wWidth, wHeight)
{
    var wx = (screen.width - wWidth) / 2;
    var wy = (screen.height - wHeight) / 2;

    // 20070403
    //suffix = "toolbar=no,menubar=no,location=no,status=yes,titlebar=yes,scrollbars=yes,resizable=yes,directories=no";
    suffix = "toolbar=no,menubar=no,location=no,status=yes,titlebar=yes,scrollbars=yes,resizable=no,directories=no";
    suffix = "width=" + wWidth + ",height=" + wHeight + ",top=" + wy + ",left=" + wx + "," + suffix;
    window.open(src, winName, suffix);
}


function marketDeliverySelect(mkt_no, master_id, mkt_id, step) {
    _popup('/scm/shops/shops_market_delivery_select.php?mkt_no='+mkt_no+'&master_id='+master_id+'&mkt_id='+mkt_id+'&step='+step, 'marketDelivery', '620', '500');
}


function formManager(mode, compListValue, compFormListValue) {
	_popup('/scm/shops/shops_market_form_manage.php?mode='+mode+'&compListValue='+compListValue+'&compFormListValue='+compFormListValue, 'formManager', '820', '500');
}

function deliveryManager(mkt_no, master_id, mkt_id, mktdc_no, market_name) {
	_popup('/scm/shops/shops_market_delivery_manage.php?mkt_no='+mkt_no+'&master_id='+master_id+'&mkt_id='+mkt_id+'&market_name='+market_name+'&mktdc_no='+mktdc_no, 'deliveryManager', '820', '500');
}

function _sendEmail(email, name, mktId)
{
    if(arguments[2] == undefined){
        url = '/scm/common/send_email_form.php?email='+email+'&name='+name+'&mktId='+mktId;
    }else{
        flag = arguments[2];
        url = '/scm/common/send_email_form.php?email='+email+'&name='+name+'&flag='+flag+'&mktId='+mktId;
    }
    _popup(url, 'marketDelivery', '620', '500');
}


function set_search_detail(){

    detail = document.getElementById('detail_search_table').style.display;

    if(detail == "block"){
        document.getElementById('detail_search_table').style.display = "none";
        document.getElementById('detail_search').value="N";
    }else{
        document.getElementById('detail_search_table').style.display = "block";
        document.getElementById('detail_search').value="Y";
    }
}

function set_result_layer(){
    result_layer = arguments[0];
    result = document.getElementById(result_layer).style.display;

    if(result == "block"){
        document.getElementById(result_layer).style.display = "none";
    }else{
        document.getElementById(result_layer).style.display = "block";
    }
}

function sms_send_pop(phone) {  //sms전송
    window.open('/scm/add/add_sms_send_mini.php?phone='+phone,'sms_pop','width=200 height=600');
}


//레이어 출력을 위한 함수
var view_layer = "";

function ctr_layer(){
        button = arguments[0];
        flag = arguments[1];
        frm = arguments[2];
        type = arguments[3];

        if (type =='all' && !checkBoxCheck(frm)) {
            alert('수정하실 예약명을 선택해주세요.');
            return;
        }

        button_top = get_top(button)+20;
        button_left = get_left(button);

        if (document.getElementById("L"+button).style.display == 'block'){
            document.getElementById("L"+button).style.display = 'none';
            view_layer = "";
        }else{
            if(view_layer != ""){
                document.getElementById(view_layer).style.display = 'none';
            }
            document.getElementById("L"+button).style.display = 'block';
            view_layer = "L"+button;
        }
}

//팁 출력을 위한 함수

function ctr_tip(){
        button = arguments[0];
        flag = arguments[1];

        if (document.getElementById("L"+button).style.display == 'block'){
            document.getElementById("L"+button).style.display = 'none';
            document.getElementById("F"+button).style.display = 'none';
        }else{
            document.getElementById("L"+button).style.display = 'block';
            document.getElementById("F"+button).style.display = 'block';
        }
}


//레이어 출력을 위한 함수(위치지정)
function ctr_layer2(){
        button = arguments[0];
        flag = arguments[1];

        button_top = get_top(button)+20;
        button_left = get_left(button);

        if (document.getElementById("L"+button).style.display == 'block'){
            document.getElementById("L"+button).style.display = 'none';
        }else{
            document.getElementById("L"+button).style.display = 'block';
            document.getElementById("L"+button).style.left = button_left;
            document.getElementById("L"+button).style.top = button_top;
        }
}


function get_top(button){
    otop = 0;
    obj = document.getElementById(button);
    while(obj.tagName !="BODY"){
        otop = otop + obj.offsetTop;
        obj = obj.offsetParent;
    }
    return otop;
}

function get_left(button){
    width_max = document.body.scrollWidth;
    oleft = 0;
    obj = document.getElementById(button);
    while(obj.tagName !="BODY"){
        oleft = oleft + obj.offsetLeft;
        obj = obj.offsetParent;
    }

    var right = eval(oleft)+eval(document.getElementById(button).width);

    var gab = eval(right)-eval(width_max);

    if(gab > 0){
        oleft = eval(oleft) - eval(gab) - 10;
    }

    return oleft;
}



function __mvMarketLink(frm,fdn,mkt_no,action) {  //마켓텝전송
    frm.elements(fdn).value=mkt_no;
    frm.action=action;
    frm.target="_self";
    frm.submit();
}


function openCustomerReport(qryStr)
{
    url = '/web/common/customer_report.php?'+qryStr;
    window.open(url, '', 'width=400,height=300,scrolling=1,scrollbars=1');
}


function lost_id_pw()  //아이디&비밀번호찾기 @add 박덕길 2007-01-12
{
        option = "tollbar=no, location=no, directories=no, status=no," +
                "menubar=no, scrollbars=yes, resizable=no," +
                "width=800, height=600, top=200, left=300 "

        //filename = 'http://test-udb.simplexi.com/src/php/idpass/cafe24IPSearch.php'
        filename = 'https://user.cafe24.com/pwsearch.php'
        open_window( filename, option )
}

function modifyInfo() {
    option = "tollbar=no, location=no, directories=no, status=no," +
            "menubar=no, scrollbars=yes, resizable=no," +
            "width=800, height=600, top=200, left=300 "

    filename = 'https://user.cafe24.com/login.php'
    open_window( filename, option )
}

function open_window( filename, option, win_name )
{
	if( !win_name )
	{
		win_name = "echosting_new"
	}

	win = window.open( filename, win_name, option );

	return win
}

function call_image_host(){
//	src = "/scm/add/add_imagehosting.php";
	src = "/scm/add/add_image_hosting_connect.php";
	suffix = "toolbar=no,menubar=no,location=no,status=yes,titlebar=yes,scrollbars=yes,resizable=yes,directories=no";
	window.open(src, "imagehosting", suffix);
}

function _file_download(flag, type)
{
    if (flag != "") {
        location.href = "/scm/file_download.php?file_type="+type;
    } else {
        alert("다운로드파일이 존재하지 않습니다.");
    }
}

//배송추적
function _ordDeliveryTrace(dlvrNo, dlvrName, invoiceNo, mktNo)
{
    idx =invoiceNo.indexOf('-');
    while(idx > 0) {
       invoiceNo = invoiceNo.replace('-', '');
       idx =invoiceNo.indexOf('-');
    }

    src  = "/scm/order/order_delivery_trace_view.php?dlvrc_no="+dlvrNo+"&dlvrc_name="+dlvrName+"&mkt_no="+mktNo+"&invoice_no="+invoiceNo;
    attr = "width=700,height=500,scrolling=1,scrollbars=1,resizable=1";
    window.open(src, "deliveryTrace", attr);
}

//온라인 가이드
function setGuide(value) {
    if(value == '1') {                  // 1 : 샵카페 이용가이드
        location.href = '02.html';
    } else if(value == '2') {           // 2 : 동영상 이용가이드
        location.href = 'm_11.html';
    } else if(value == '3') {           // 3 : 타오바오 이용가이드
        location.href = 't_01.html';
    }
}


/**
* 문자열 형식의 날짜를 Date객체로 변환
*
* @param string this, 2007-10-10
*
* @return date
* 2007-10-29 11:24오전
*/
String.prototype.setCastDate = function(sFormat){

	if(!sFormat) sFormat = "YYYY-MM-DD";

	var sFlag = sFormat.charAt(0);
	var aToken = new Array(11);
	var m = 0;

	for(var i=0, j=0 ; i <= sFormat.length; i++){
		if(sFlag != sFormat.charAt(i)){
			aToken[sFormat.charAt(i-1)] = parseFloat(this.substr(j, i-j));
			sFlag = sFormat.charAt(i);
			j = i;
			m++;
		}
	}

	if(!aToken['h']) aToken['h'] = 0;
	if(!aToken['m']) aToken['m'] = 0;
	if(!aToken['s']) aToken['s'] = 0;

	//document.write(aToken['Y'] + "-" + aToken['M'] + "-" + aToken['D'] + " " + aToken['h'] + ":" + aToken['m'] + ":" + aToken['s']);
	return new Date(aToken['Y'], aToken['M']-1, aToken['D'], aToken['h'], aToken['m'], aToken['s']);
}

/**
* Date객체를 format에 맞게 String으로 변환 리턴
*
* @param string format('YYYY-MM-SS hh:mm:ss')
*
* @return string '2007-10-10 22:10:56'
*/
Date.prototype.setCastString = function(sFormat){

	var aToken = new Array(7);
	var rtnValue = sFormat;
	var sFlag = sFormat.charAt(0);

	if(!sFormat) sFormat = "YYYY-MM-DD";

	aToken['YYYY'] = this.getFullYear();
	aToken['YY'] = this.getYear();
	aToken['MM'] = (parseInt(this.getMonth() + 1) < 10) ? "0"+ parseInt(this.getMonth()+1) : parseInt(this.getMonth() +1);    
	aToken['DD'] = (this.getDate() < 10) ? "0"+this.getDate() : this.getDate();      
	aToken['hh'] = (this.getHours() < 10) ? "0"+this.getHours() : this.getHours();    
	aToken['mm'] = (this.getMinutes() < 10) ? "0"+this.getMinutes() : this.getMinutes();
	aToken['ss'] = (this.getSeconds() < 10) ? "0"+this.getSeconds() : this.getSeconds();

	if(!aToken['hh']) aToken['h'] = "00";
	if(!aToken['mm']) aToken['m'] = "00";
	if(!aToken['ss']) aToken['s'] = "00";

	for(var i=0, j=0 ; i <= sFormat.length; i++){
		if(sFlag != sFormat.charAt(i)){
			if(!aToken[sFormat.substr(j, i-j)]){
			} else {
				rtnValue = rtnValue.replace(sFormat.substr(j, i-j), aToken[sFormat.substr(j, i-j)]);
			}

			sFlag = sFormat.charAt(i);
			j = i;
		}
	}

	return rtnValue;
}

/**
* 날짜 비교
*
* @param Date this
* @param string sType
* @param Date sVal
*
* @return integer
* 2007-10-29 11:23오전
*/
Date.prototype.dateDiff = function(sType, oVal){
	var oThis = this;
	if(!oVal) oVal = new Date();

	switch (sType){
		case 's' :	//초
			var demoninator = 1000;
		break;
		case 'm' :	//분
			oThis = new Date(oThis.getYear(), oThis.getMonth(), oThis.getDate(), oThis.getHours(), oThis.getMinutes(), 0);
			oVal = new Date(oVal.getYear(), oVal.getMonth(), oVal.getDate(), oVal.getHours(), oVal.getMinutes(), 0);

			var demoninator = 1000 * 60;
		break;
		case 'h' :	//시
			oThis = new Date(oThis.getYear(), oThis.getMonth(), oThis.getDate(), oThis.getHours(), 0, 0);
			oVal = new Date(oVal.getYear(), oVal.getMonth(), oVal.getDate(), oVal.getHours(), 0, 0);

			var demoninator = 1000 * 60 * 60;
		break;
		case 'd' :	//일
			oThis = new Date(oThis.getYear(), oThis.getMonth(), oThis.getDate(), 0, 0, 0);
			oVal = new Date(oVal.getYear(), oVal.getMonth(), oVal.getDate(), 0, 0, 0);

			var demoninator = 1000 * 60 * 60 * 24;
		break;
		default :
			var demoninator = 1000;
	}

	return parseInt((oVal.getTime() - oThis.getTime())/demoninator);
}

/**
* 문자열 형식의 날짜 비교
*
* @reference String.prototype.setCastDate()
* @reference Date.prototype.dateDiff()
*
* @param string this
* @param string sVal
* @param string sType
*
* @return integer * 2007-10-29 11:23오전
*/
String.prototype.dateDiff = function(sType, sVal){
	//2007-10-08 또는 20070108 같은 형식
	var oThis = this.setCastDate();
	var oDate = sVal.setCastDate();

	return oThis.dateDiff(sType, oDate);
}


//검색 초기화
function init_form_search(oFrm, type, url){

    if (type =='product'){
        oFrm['search[textSearchKeyword]'].value ="";
        oFrm['search[sStartDate]'].value ="";
        oFrm['search[sEndDate]'].value ="";

        //상품대장 일괄수정
        if (url =='bundle_list' || url =='all_admin') {
                oFrm['search[textSearchField]'].value ="all";
                oFrm['search[prdm_sale_flag]'].value ="";

        //상품대장
        }else if (url =='download_sc_list' || url =='download_list'){
                oFrm['search[textSearchField]'].value ="all";
                oFrm['search[sDateSearchField]'].value ="prdg_get_date";

        }else if (url =='schedule_list'){
                oFrm['search[search_status]'].value ="all";
                oFrm['search[dateFlag]'].value ="reserve_date";
        }

    }else if(type =='order') {
        oFrm['_aSetSearch[_sSetValue]'].value ="all";
        oFrm['_sSetValue'].value ="";
        oFrm['_aSetSearch[_ordStatus]'].value ="";
        oFrm['_aSetDateSearch[name]'].value ="om_order_date";
        oFrm['_aSetDateSearch[start]'].value ="";
        oFrm['_aSetDateSearch[end]'].value ="";

        //배송준비중
        if(url =='ready'){
            oFrm['_aSetSearch[om_print_use_flag]'].value ="";
        }

    }
}

function lodingBarStart()
{
    var node    = document.createElement('div');
    node.id     = 'ajaxLodingBar';
    var width   = document.body.clientWidth;
    var height  = document.body.clientHeight;
    var scrollerTop = document.body.scrollTop;

    lodingBarBackground(width, (height + scrollerTop));
    var scrollerTop = document.body.scrollTop;

    node.style.height = '180px';
    node.style.width  = '310px';
    node.style.top  = ((height/2)-90)+'px';
    //node.style.top  = (scrollerTop+((height/2)-90))+'px';
    node.style.left = ((width/2)-165)+'px';
    node.style.backgroundImage = 'url(/scm/design/default/images/main/layer_roading_back.gif)';
    node.style.position = 'absolute';
    node.style.textAlign = 'center';
    node.style.zIndex = '100';

    var html = '<img src="/scm/design/default/images/product/loading_motion.gif" alt="로딩" style="position:absolute; top:30px; left:130px;" />';
    html += '<div href="javascript:void(0);" onclick="lodingBarEnd()" style="position:absolute; top:140px; left:140px; clear:both;  cursor:pointer; width:70px; height:14px;"></div>';

    node.innerHTML = html;
//    node.update(html);
    document.body.appendChild(node);
}


function lodingBarBackground(width, height)
{
    var node = document.createElement('div');
    node.id = 'ajaxLodingBack';

    height        = height > 1000 ? height : 1000;

    node.style.backgroundColor = '#000';
    node.style.filter = "alpha(opacity=50)";
    node.style.top  = 0+'px';
    node.style.left = 0+'px';
    node.style.position = 'absolute';
    node.style.width = width+'px';
    node.style.height = height+'px';
    node.style.zIndex = '99';

    document.body.appendChild(node);
}

function lodingBarEnd() {
  var nodeBar = document.getElementById('ajaxLodingBar');
  var nodeBack = document.getElementById("ajaxLodingBack");

  nodeBar.parentNode.removeChild(nodeBar);
  nodeBack.parentNode.removeChild(nodeBack);
}

//상품일괄수집 예외처리
function lodingBarEnd2() {
  var nodeBar = parent.document.getElementById('ajaxLodingBar');
  var nodeBack = parent.document.getElementById("ajaxLodingBack");

  nodeBar.parentNode.removeChild(nodeBar);
  nodeBack.parentNode.removeChild(nodeBack);
}

//현재 날짜 가져오기
function _getNowDate(frm, obj, targetField){
    var dateObj   = new Date();

    sYear    = dateObj.getFullYear();
    sMonth   = dateObj.getMonth() +1;
    sDay     = dateObj.getDate();
    date = sYear + "-" + _getIntToString(sMonth) + "-" + _getIntToString(sDay);

    frm[targetField].value = date;
}