/** 쿠키 처리 **/
function setCookie(name, value, day) {
    var today = new Date();
    var expires=new Date();
    expires.setTime(today.getTime() + 86400 * day);
    document.cookie=name + "=" + escape(value) + " ; expires=" + expires.toGMTString();
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


/** 로그인 타입별 노출 **/
function login_type(type) {
	if (type == "sub") {
		$('login_style').style.backgroundPosition = "0px -19px";
		$('sub_login').style.display	= "";
		$('main_login').style.display	= "none";
        setCookie('trans_login_type', 'sub', 365);
	} else {
		$('login_style').style.backgroundPosition = "0px 0px";
		$('sub_login').style.display	= "none";
		$('main_login').style.display	= "";
        deleteCookie('trans_login_type');
	}
}

/** 페이지 타입별 메뉴 처리 **/
function changeMenu(type) {
	switch(type) {
		case "how_charge" :
			$('main-menu').style.backgroundPosition = "0px -35px";
		break;
		case "system_info" :
			$('main-menu').style.backgroundPosition = "0px -70px";
		break;
		case "site_management" :
			$('main-menu').style.backgroundPosition = "0px -105px";
		break;
		case "crm_center" :
			$('main-menu').style.backgroundPosition = "0px -140px";
		break;
		case "partner_info" :
			$('main-menu').style.backgroundPosition = "0px -175px";
		break;
		default : 
			$('main-menu').style.backgroundPosition = "0px 0px";
		break;
	}
}

/** 로그인 폼 안에 디폴트 값및 클릭 시 이벤트 관련 처리. **/
var message = {
    'login_id' : '',
    'login_pw' : '',
    'sub_url' : '',
    'sub_id' : '',
    'sub_pw' : ''
};
var default_message = {
    'login_id' : '',
    'login_pw' : '',
    'sub_url' : 'http://',
    'sub_id' : '',
    'sub_pw' : ''
};
var loginform_notifier = {
    focus : function() {
        var ele = Event.element(arguments[0]);
        var id = ele.id;
        if ($F(ele) == message[id]) {
            if (id == 'sub_pw' || id == 'login_pw') {
                Element.removeClassName(ele, 'img_passwd');
            } else if (id == 'login_id' || id == 'sub_id') {
                Element.removeClassName(ele, 'img_id');
            } else if (id == 'sub_url') {
                Element.removeClassName(ele, 'img_url');
                ele.value = default_message[id];
            }
        }
    },

    blur : function() {
        var ele = Event.element(arguments[0]);
        var id = ele.id;
        if ($F(ele).length == 0 || $F(ele) == default_message[id]) {
            if (id == 'sub_pw' || id == 'login_pw') {
                Element.addClassName(ele, 'img_passwd');
            } else if (id == 'login_id' || id == 'sub_id') {
                Element.addClassName(ele, 'img_id');
            } else if (id == 'sub_url') {
                Element.addClassName(ele, 'img_url');
                ele.value = message[id];
            }
        }
    },

    init : function() {
        var ele = arguments[0];
        var id = ele.id;
        if ($F(ele).length == 0) {
            ele.value = message[id];
        }
    }
};


/** 운영자 로그인 **/
function login() {
    // 폼검사
    if ($('login_id').value.length == 0 || $('login_id').value == message['login_id']) {
        alert('아이디를 입력해 주세요.');
        Field.activate($('login_id'));
        return false;
    }
    if ($('login_pw').value.length == 0) {
        alert('비밀번호를 입력해 주세요.');
        Field.activate($('login_pw'));
        return false;
    }

    // 아이디 저장 체크시 쿠키를 저장 한다.
    if ($('id_chk').checked == true) {
        setCookie('id_chk', 'on', 365);
        setCookie('saved_id', $('login_id').value, 365);
    } else {
        deleteCookie('id_chk');
        deleteCookie('saved_id');
    }
}

/** 부운영자 로그인 **/
function sub_login() {
    // 폼검사
    if ($F('sub_url').length == 0 || $F('sub_url') == message['sub_url']) {
        alert('상점 URL을 입력해 주세요.');
        Field.activate($('sub_url'));
        return false;
    }
    if ($F('sub_id').length == 0 || $F('sub_id') == message['sub_id']) {
        alert('부운영자 아이디를 입력해 주세요.');
        Field.activate($('sub_id'));
        return false;
    }
        
    if ($F('sub_pw').length == 0) {
        alert('부운영자 비밀번호를 입력해 주세요.');
        Field.activate($('sub_pw'));
        return false;
    }

    // 쿠키에 부운영자 id 저장
    if ($('sub_id_chk').checked == true) {
        setCookie("sub_id_chk", 'on', 365);
        setCookie('save_sub_id', $F('sub_id'), 365);
    } else {
        deleteCookie('sub_id_chk');
        deleteCookie('save_sub_id');
    }

    // 쿠키에 부운영자 url 저장
    if ($('sub_url_chk').checked == true) {
        setCookie('sub_url_chk', 'on', 365);
        setCookie('save_sub_url', $F('sub_url'), 365);
    } else {
        deleteCookie('sub_url_chk');
        deleteCookie('save_sub_url');
    } 
        
    var f = $('login_form');
    f.action = $F('sub_url') + '/makeshop/transmanager/index2.html';
    f.submit();
}

/** footer 이메일 정책 **/
function nospam() {
    window.open("http://www.makeshop.co.kr/main/nospam.html","nospam","height=210,width=600,scrollbars=no");
}

/** 공지사항 팝업 띄우기 **/
function notice_Popup(id) {
    if (id == 'FULL') {
        var notice_popup = window.open('./notice.html?board_name=notice','mail', 'width=531, height=525, scrollbars=yes');
    } else {
        var notice_popup = window.open('./notice_view.html?board_name=notice&id='+id,'mail', 'width=531, height=514, scrollbars=yes');
    }
    notice_popup.focus();
}

/** footer 패밀리 사이트 이동 **/
function move_site(value) {
    if (value.length > 1) {
        window.open("http://" + value);
    }
}
// 세금 계산서 확인 창
function tax_window() {
    window.open('http://trans.makeshop.co.kr/bill/index.html', 'tax_window', 'width=250,height=129,scrollbars=yes');
}

/** 회원가입 팝업창 **/
function applicant_window() {
    var applicant_step = window.open('/member_join_step1.html', 'applicant_window', 'width=550, height=750, scrollbars=yes');
    applicant_step.focus();
}
/** 서비스 결제 팝업창 **/
function payment_window() {
    var payment_window = window.open('/trans_payment_info.html', 'payment_window', 'width=530, height=600, scrollbars=yes');
    payment_window.focus();
}
/** 관리자 체험하기 **/
function guest_login() {
    window.open("guest_login.html", "", "scrollbars=auto");
}

/** footer에 셀렉트 박스 처리 **/
function show_family() {
    if ($('fam_list').style.display == "none") {
        new Effect.Parallel([
            new Effect.Opacity($('fam_list'), { sync: true, from: 0, to: 1, duration: 0 }), 
            new Effect.BlindDown($('fam_list'), { duration:3.0 }),
            new Effect.Move($('fam_list'), { sync: true, x: 0, y: -196, mode: 'relative' })
        ], { 
          delay: 0
        });
    } else {
        new Effect.Parallel([
            new Effect.BlindUp($('fam_list'), { duration:3.0 }),
            new Effect.Move($('fam_list'), { sync: true, x: 0, y: 196, mode: 'relative' })
        ], { 
          delay: 0
        });
    }
}

