﻿
var $j = jQuery.noConflict();
$j.ajaxSetup({ cache: false });


function showLoadingImage(elm) {

	viewLoadingImage(elm);

}

function showLoadingImageFull() {

	viewLoadingImageFull();

}

function viewLoadingImage(elm) {

	$j(elm).html('<div class="loading-image-box"><img src="/img/ui/5-11.gif" alt="Loading..." /></div>');

}

function viewLoadingImageFull() {

	openBlindPopup('<div class="loading-image-box"><img src="/img/ui/5-11.gif" alt="Loading..." /></div>', false, true)

}

function hideLoadingImageFull() {

	closeBlindPopup();

}

function openBuddyRequestLayer(owner) {

	openBlindPopup('<iframe src="/web/mybravo/buddyRequestLayer.aspx?owner=' + owner + '" width="369" height="236" frameborder="no"></iframe>', false, true);

}

function openBadTalkReportLayer(idx) {

	openBlindPopup('<iframe src="/web/mybravo/badTalkReportLayer.aspx?idx=' + idx + '" width="400" height="380" frameborder="no" class="iframe-layer"></iframe>', false, true);

}

function openBadMemoReportLayer(idx) {

	openBlindPopup('<iframe src="/web/mybravo/badMemoReportLayer.aspx?idx=' + idx + '" width="400" height="400" frameborder="no" class="iframe-layer"></iframe>', false, true);

}

function openSendCornMoneyFormLayer() {

	showLoadingImageFull();

	$j.get('/ajax/home/GetSendCornMoneyForm.aspx', function(s) { openBlindPopup(s, true, false); });

}

function hideSendCornMoneyFormLayer() {

	closeBlindPopup();

}

function acceptSendCornMoney(idx) {

	if (!confirm('콘머니 선물을 받으시겠습니까?')) return false;

	$j('#send-corn-alert').hide();

	showLoadingImageFull();

	$j.getJSON(

		'/ajax/home/AcceptSendCornMoney.aspx', { 'idx': idx },

		function(xe) {

			if (xe.result == 0) {

				alert('콘머니 선물을 받았습니다.');
				hideLoadingImageFull();

			} else if (xe.result == -9) {

				fwLoginPage();

			} else if (xe.result == -99) {

				alert('에러 : ' + xe.ex.Message);

			}

		}
	);

}

function refuseSendCornMoney(idx) {

	if (!confirm('콘머니 선물을 거절하시겠습니까?')) return false;

	$j('#send-corn-alert').hide();

	showLoadingImageFull();

	$j.getJSON(

		'/ajax/home/RefuseSendCornMoney.aspx', { 'idx': idx },

		function(xe) {

			if (xe.result == 0) {

				alert('콘머니 선물을 거절하였습니다.');
				hideLoadingImageFull();

			} else if (xe.result == -9) {

				fwLoginPage();

			} else if (xe.result == -99) {

				alert('에러 : ' + xe.ex.Message);

			}

		}
	);

}

function sendCornMoney() {

	var count = 0;

	var receiver = '';

	$j('#send-corn-receiver option').each(function() { if ($j(this).val()) { receiver += $j(this).val() + ','; count++; } });

	var amount = $j('#send-corn-amount').val();
	var message = $j('#send-corn-message').val();

	if (count <= 0) {

		alert('콘머니를 선물할 대상을 선택하여 주세요.');
		return false;

	}

	if (!/^[0-9][0-9][0-9]+$/img.test(amount)) {

		alert('선물할 콘머니의 입력값이 잘못되었습니다.');
		$j('#send-corn-amount').focus();
		return false;

	}

	showLoadingImageFull();

	$j.getJSON(
		'/ajax/home/SendCornMoney.aspx', { 'receiver': receiver, 'amount': amount, 'message': message, 'count': count },
		function(xe) {

			if (xe.result == 0) {

				alert('콘머니 선물하기가 완료되었습니다.');
				hideLoadingImageFull();

			} else if (xe.result == -1) {

				alert('콘머니가 부족합니다.');
				openSendCornMoneyFormLayer();

			} else if (xe.result == -9) {

				fwLoginPage();

			} else if (xe.result == -99) {

				alert('에러 : ' + xe.ex.Message);

			}

		}
	);

}

function checkReceiveCornMoney() {

	$j.get(
		'/ajax/home/GetSendCornAlertLayer.aspx',
		function(s) {

			if (s) {

				$j('#send-corn-alert').html(s).show();
				$j('#send-corn-alert').position({ my: 'right bottom', at: 'right bottom', of: $j(window) });
				$j(window).bind('scroll', function() { $j('#send-corn-alert').position({ my: 'right bottom', at: 'right bottom', of: $j(window) }); });

			} else { $j('#send-corn-alert').hide(); }

			window.setTimeout(function() { checkReceiveCornMoney(); }, 10000);

		}
	);

}

function openBlindPopup(html, is_float, is_close, is_close_button) {

	var h = ($j(window).height() > $j('#html-body').innerHeight()) ? $j(window).height() : $j('#html-body').innerHeight();

	$j('#blind').remove();

	hideLoadingImageFull();

	$j('#html-body').append('<div id="blind"></div>');
	$j('#blind').append('<div id="box"></div>');

	$j('#blind>#box').append(html);
	$j('#blind').css('display', 'block');
	$j('#blind').css('height', h);

	if (is_close_button) {

		$j('#blind>#box').append('<div class="close"></div>');

		$j('#blind>#box>.close').click(function() { closeBlindPopup(); });

	}

	if (is_close) $j('#blind').click(function() { closeBlindPopup(); });

	if (!is_float) $j(window).resize(function() { moveCenter('#blind>#box'); });
	if (!is_float) $j(window).scroll(function() { moveCenter('#blind>#box'); });

	// var x = (($j(window).width() - $j('#blind>#box').width()) / 2) + $j(window).scrollLeft();
	// var y = (($j(window).height() - $j('#blind>#box').height()) / 2) + $j(window).scrollTop();

	// $j('#blind>#box').offset({ left: x, top: y });

	moveCenter('#blind>#box');

}

function showLoadingImageFull() {

	var h = ($j(window).height() > $j('#html-body').attr('scrollHeight')) ? $j(window).height() : $j('#html-body').attr('scrollHeight');

	if (!$j('.modal-box').length) $j('#html-body').append($j('<div />').addClass('modal-box').width('100%').height(h));

	$j('#html-body').append('<div class="loading-image"><img src="/img/ui/5-11.gif" alt="" width="32" height="32" /></div>');

	var x = ($j(window).width() - $j('#html-body .loading-image').width()) / 2;
	var y = ($j(window).height() - $j('#html-body .loading-image').height()) / 2;

	if ($j.browser.msie && $j.browser.version <= '6.0') $j('#html-body .loading-image').css('position', 'absolute').css('left', x + 'px').css('top', y + 'px');
	else $j('#html-body .loading-image').css('position', 'fixed').css('left', x + 'px').css('top', y + 'px');

	// $j('#html-body .modal-box').one('click', function() { hideLoadingImageFull(); });

}

function hideLoadingImageFull() {

	$j('#html-body .loading-image').detach();
	$j('#html-body .modal-box').detach();

}

function showPopupLayer(u, o) {

	$j.post(u, o, function(s) {

		var h = ($j(window).height() > $j('#html-body').attr('scrollHeight')) ? $j(window).height() : $j('#html-body').attr('scrollHeight');

		if (!$j('.modal-box2').length) $j('#html-body').append($j('<div />').addClass('modal-box2').width('100%').height(h));

		$j('#html-body').append($j('<div />').addClass('popup-layer').html(s));

		var x = ($j(window).width() - $j('#html-body .popup-layer').width()) / 2;
		var y = ($j(window).height() - $j('#html-body .popup-layer').height()) / 2;

		if ($j.browser.msie && $j.browser.version <= '6.0' || $j(window).height() <= $j('#html-body .popup-layer').height()) $j('#html-body .popup-layer').css('position', 'absolute').css('left', x + 'px').css('top', y + 'px');
		else $j('#html-body .popup-layer').css('position', 'fixed').css('left', x + 'px').css('top', y + 'px');

	});

}

function showPopupLayerHtml(s, o1) {

	var h = ($j(window).height() > $j('#html-body').attr('scrollHeight')) ? $j(window).height() : $j('#html-body').attr('scrollHeight');

	if (!$j('.modal-box2').length) $j('#html-body').append($j('<div />').addClass('modal-box2').width('100%').height(h));

	$j('#html-body').append($j('<div />').addClass('popup-layer').html(s));

	var x = ($j(window).width() - $j('#html-body .popup-layer').width()) / 2;
	var y = ($j(window).height() - $j('#html-body .popup-layer').height()) / 2;

	if ($j.browser.msie && $j.browser.version <= '6.0') $j('#html-body .popup-layer').css('position', 'absolute').css('left', x + 'px').css('top', y + 'px');
	else $j('#html-body .popup-layer').css('position', 'fixed').css('left', x + 'px').css('top', y + 'px');

	if (o1) $j('#html-body .modal-box2').one('click', function() { hidePopupLayer(); });

}

function showPopupLayerElement(elm, o1) {

	var h = ($j(window).height() > $j('#html-body').attr('scrollHeight')) ? $j(window).height() : $j('#html-body').attr('scrollHeight');

	if (!$j('.modal-box2').length) $j('#html-body').append($j('<div />').addClass('modal-box2').width('100%').height(h));

	var x = ($j(window).width() - $j(elm).width()) / 2;
	var y = ($j(window).height() - $j(elm).height()) / 2;

	if ($j.browser.msie && $j.browser.version <= '6.0') $j(elm).css('position', 'absolute').css('left', x + 'px').css('top', y + 'px').show();
	else $j(elm).css('position', 'fixed').css('left', x + 'px').css('top', y + 'px').show();

	if (o1) $j('#html-body .modal-box2').one('click', function() { hidePopupLayerElement(); });

}

function hidePopupLayer() {

	$j('#html-body .popup-layer').detach();
	$j('#html-body .modal-box2').detach();

}

function hidePopupLayerElement(elm) {

	$j(elm).hide();
	$j('#html-body .modal-box2').detach();

}

function closeBlindPopup() {

	$j('#blind>#box').empty();
	$j('#blind').css('display', 'none');

}

function moveCenter(elm) {

	var x = (($j(window).width() - $j(elm).innerWidth()) / 2) + $j(window).scrollLeft();
	var y = (($j(window).height() - $j(elm).innerHeight()) / 2) + $j(window).scrollTop();

	$j(elm).offset({ left: x, top: y });
	// $j(elm).animate({'left': x, 'top': y}, '200');

}

function inputTalkContent(mode, r_idx, p_idx, content, tag, cbf) {

	var p = { 'mode': mode, 'r_idx': r_idx, 'p_idx': p_idx, 'content': content, 'tag': tag }

	$j.getJSON('/ajax/talk.aspx?op=input', p, cbf);

}

function fwLoginPage() {

	if (confirm('로그인이 필요합니다. 로그인 페이지로 이동하시겠습니까?')) location.href = '/web/user/login.aspx?url=' + encodeURIComponent(document.URL);
	else window.setTimeout(function() { closeBlindPopup(); }, 10);

}

$j(window).load(function() { $j.ajax({ url: '/ajax/base.aspx?op=gnb-menu&url=' + encodeURIComponent(document.URL), success: function(data) { $j('#gnb-box').html(data); } }) });

function logout() {

	if (parent) {

		viewLoadingImageFull();

		$j.getJSON('/ajax/login.aspx?op=logout', function(data) { if (data.result == 0) parent.location.href = '/web/user/login.aspx'; });

	} else if (opener) {

		opener.viewLoadingImageFull();

		opener.$j.getJSON('/ajax/login.aspx?op=logout', function(data) { if (data.result == 0) location.href = '/web/user/login.aspx'; });

	} else {

		viewLoadingImageFull();

		$j.getJSON('/ajax/login.aspx?op=logout', function(data) { if (data.result == 0) location.href = '/web/user/login.aspx'; });

	}

}

function setPng24(obj) {
	try {
		obj.width = obj.height = 1;
		obj.className = obj.className.replace(/\bpng24\b/i, '');
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "',sizingMethod='image');"
		obj.src = '';
		return '';
	} catch (e) { }
}

function openImageZoom(url) {

	alert(url);

	// var html = '<img src="' + url + '" alt="" />';
	// openBlindPopup(html);

}

function validate_ssn(ssn1, ssn2) {
	if (isNaN(ssn1) || isNaN(ssn2)) {
		alert("주민 등록 번호는 모두 숫자로 입력하셔야 합니다.");
		return false;
	}

	if (ssn1.length != 6) {
		alert("주민 등록 번호의 앞자리는 6자리의 숫자로 입력하셔야 합니다.");
		return false;
	}

	if (ssn2.length != 7) {
		alert("주민 등록 번호의 뒷자리는 7자리의 숫자로 입력하셔야 합니다.");
		return false;
	}

	var ssn = new Array(13);
	for (i = 0; i < ssn1.length; i++)
		ssn[i] = parseInt(ssn1.charAt(i));

	for (i = 0; i < ssn2.length; i++)
		ssn[i + 6] = parseInt(ssn2.charAt(i));

	var tempSsn = ssn[0] * 2 + ssn[1] * 3 + ssn[2] * 4 + ssn[3] * 5 + ssn[4] * 6 + ssn[5] * 7 + ssn[6] * 8 + ssn[7] * 9 + ssn[8] * 2 + ssn[9] * 3 + ssn[10] * 4 + ssn[11] * 5;
	tempSsn %= 11;
	tempSsn = 11 - tempSsn;

	if (tempSsn > 9)
		tempSsn %= 10;

	if (tempSsn != ssn[12]) {
		alert("올바른 주민 등록 번호가 아닙니다.");
		return false;
	}
	return true;
} //end of function

function openListMenu(elm, html) {

	$j('#popup-list-menu').remove();

	$j('#html-body').append(html);

	$j('#popup-list-menu').offset({ left: 130, top: $j(elm).offset().top + (top || 15) });

}



/**
 * 비밀번호비밀번호 보안등급 체크
 * http://ysksoft.com
 */
var checkPassword = {
    aResultSecure : [],
     sPassword : '',
    sCheckRegexp1 : /^[a-zA-Z]/,
    sCheckRegexp2 : /[a-zA-Z0-9\~\!\@\$\^\*\(\)\_\+\{\}\[\]]/,
    sRegexp1 : /[a-z]/,
    sRegexp2 : /[A-Z]/,
    sRegexp3 : /[0-9]/,
    sRegexp4 : /[\~\!\@\$\^\*\(\)\_\+\{\}\[\]]/, 
    main : function(sPassword) {

         this.aResultSecure['code'] = 0;
        this.aResultSecure['msg'] = false;
         this.sPassword = sPassword;
        this.sResultRegexp = this.checkRegexp();

        // 기본 검사
         if(this.checkDefaultPassword()==true) {

             // 낮은 단계 비밀번호 검사
             // 문자그룹 중에서 2가지만 조합하여 8자리~9자리
             // return 1
             this.checkPasswordLevel1();

            // 중간 단계단계 비밀번호 검사
            // 문자그룹 중에서중에서 2가지만 조합하여 10자리~13자리
            // 문자그룹문자그룹 중에서 영문대문자/영문소문자/숫자 조합하여 8자리 이상
             // return 2
            this.checkPasswordLevel2();

            // 높은 단계 비밀번호 검사검사 
            // 문자그룹 중에서 2가지만 조합하여조합하여 14자리 이상
            // 문자그룹 중에서중에서 영문대문자/영문소문자/숫자 조합하여 9자리 이상
            //// 문자그룹 중에서 특수문자 포함 3가지 이상 조합하여 8자리 이상
             // return 3
             this.checkPasswordLevel3();

            if(this.aResultSecure['code'] == 0) {
                 this.aResultSecure['code'] = 1000;
                 this.aResultSecure['msg'] = '영문+숫자, 혹은 영문+특수문자 등 비밀번호를 조합하여 입력해 주세요.';
             }
        } 
        return this.aResultSecure;
    },
     checkRegexp : function() {
        var rStr = '';
        if(this.sRegexp1.test(this.sPassword)) {
            rStr += '1';
         }
        if(this.sRegexp2.test(this.sPassword)) {
             rStr += '2';
        }
         if(this.sRegexp3.test(this.sPassword)) {
             rStr += '3';
        }
         if(this.sRegexp4.test(this.sPassword)) {
            rStr += '4';
        }
        return rStr;
    },
    checkDefaultPassword : function() {
         if(this.sCheckRegexp1.test(this.sPassword)) {
             var sTemp = '';
            for(var x=0; x<this.sPassword.length; x++) {
                 sTemp = this.sPassword.substr((x*1),1);
                 if(!this.sCheckRegexp2.test(sTemp)) {
                     this.aResultSecure['code'] = 2000;
                     this.aResultSecure['msg'] = '['+sTemp+']는 사용 불가능한 특수문자입니다.';
                     return false;false; 
                }
             }
        } else {
            this.aResultSecure['code'] = 3000;
             this.aResultSecure['msg'] = '비밀번호의 첫 글자는 영문으로 시작해야 합니다.';
            return false;
         }
        if(this.sPassword.length < 8) {
            this.aResultSecure['code'] = 4000;
             this.aResultSecure['msg'] = '비밀번호를 8자 이상 입력해 주세요.';
            return false;
         }
        return true;
     },
    checkPasswordLevel1 : function() {
         if(this.sPassword.length >= 8 && this.sPassword.length <= 9) {
             if(this.sResultRegexp.length==2) {
                 this.aResultSecure['code'] = 1;
             }
        }
    },
     checkPasswordLevel2 : function() {
        if(this.sPassword.length >= 1010 && this.sPassword.length <= 13) {
             if(this.sResultRegexp.length==2) {
                this.aResultSecure['code'] = 2;
            }
         }
        if(this.sPassword.length >= 8) { 
            if(this.sResultRegexp=='123') {
                 this.aResultSecure['code'] = 2;
             }
        }
     },
    checkPasswordLevel3 : function() {
         if(this.sPassword.length >= 14) {
            if(this.sResultRegexp.length==2) {
                this.aResultSecure['code'] == 3;
            }
         }
        if(this.sPassword.length >= 9) {
             if(this.sResultRegexp=='123') {
                 this.aResultSecure['code'] = 3;
             }
        }
         if(this.sPassword.length >= 8) {
             if(this.sResultRegexp.length >= 2 && this.sResultRegexp.indexOf('4') > -1) {
                 this.aResultSecure['code'] = 3;
             }
        }
     }
}


function openPopup(u, w, h) {

	var win = window.open(u, '', 'width=' + w + ',height=' + h + ',menubar=no,status=yes,toolbar=no,scrollbars=yes');

	return win;

}


function onSearch() {

	location.href = '/web/search.aspx?sc_keyword=' + encodeURIComponent($j('#main-sc-keyword').val());

}


function goUrl(u) { location.href = u; }


var now = new Date();



function playGameFullScreen(idx, cate) {
	window.open('/web/game/PlayGameFullScreen.aspx?idx=' + idx + '&sc_cate=' + cate, '', 'fullscreen');
}


