//#########################################################################
/* Rsupport link list*/
/* maked by larblue */
//#########################################################################

/* 좌측 고객지원 배너 링크 */
function leftBannerLink(Num) {
	var btn = document.getElementById('leftBanner' + Num);
	var btnLink = btn.firstChild.getAttribute('href');
	if (Num == 1) {
		window.open(btnLink, '', 'width=440,height=500,scrollbars=yes,resizable=yes');
	} else {
		window.location.href = btnLink;
	}
}
/* 좌측 플래시 링크 외부처리 */
function rsdown1() {
	location.href = '/contents/ko/document/download.aspx';
}
function rsdown2() {
	location.href = '/contents/ko/document/download.aspx';
}
function rsdown3() {
	location.href = '/contents/ko/document/download.aspx';
}

/* main banner rotation */
function rotation() {
    var current = 0;
    var banners = $("#mainbanner > a");
    for (var i = 0; i < banners.length; i++) {
        if ($(banners[i]).css("display") == "block") {
            current = i;
        }
    }
    $(banners).css("display", "none");
    if (banners.length-1 == current) {
        $(banners[0]).css("display", "block");
    }
    else {
        $(banners[current + 1]).css("display", "block");
    }
}

$(function() {
    if (document.getElementById('mainbanner')) { setInterval('rotation()', 3000); };

    $('.gnb span').css('display', 'none');
    $('.feature p:first').css('display', 'block');
    $('.notice li ul').css('display', 'none');
    $('.notice li ul:first').css('display', 'block');
    $('.left_menu ul ul ul').css('display', 'none');
    $('.banner a:first').css('display', 'block');

    /* GNB Navigation Animation & Link */
    $('.gnb>li').mouseover(function() {
        $(this).children('a').addClass('over');
        $(this).children('ul').css('display', 'block');
        $(this).children('span').css('display', 'block');
    });
    $('.gnb>li').mouseout(function() {
        $(this).children('a').removeClass('over');
        $(this).children('ul').css('display', 'none');
        $(this).children('span').css('display', 'none');
    });
    /* Language Selection Animation & Link */
    $('.changelang').toggle(function() {
        $(this).addClass('changelangover');
        $(this).children('div').css('display', 'block');
    }, function() {
        $(this).removeClass('changelangover');
        $(this).children('div').css('display', 'none');
    });
    $('.changelang li').mouseover(function() {
        $(this).addClass('over');
    }).mouseout(function() {
        $(this).removeClass('over');
    });
    $('.changelang li a').click(function() {
        top.document.location.href = $(this).attr('href');
    });
    /* main 3tap tip,product information, mov guide */
    $('.feature li > a').click(function() {
        $('.feature li a').removeClass('on');
        $(this).addClass('on');
        $('.feature li').children('p').css('display', 'none');
        var targetlist = $(this).attr('href');
        $(targetlist).children('p').css('display', 'block');
        return false;
    });
    $('#f_menu03 p a.pdf').click(function() {
        var linkPoint = $(this).attr('href');
        window.open(linkPoint, 'movguide', 'width=850, height=550');
        return false;
    });
    $('dl.product a.appliance').click(function() {
        var linkPoint = $(this).attr('href');
        window.open(linkPoint, '', 'width=650,height=500,scrollbars=no');
        return false;
    });
    /* Notice Tab Animation */
    $('.notice>ul>li').click(function() {
        $('.notice li a').removeClass('on');
        $(this).children('a:first').addClass('on');
        $('.notice li ul').css('display', 'none');
        $(this).children('ul').css('display', 'block');
        return false;
    });
    $('.sublist li a').click(function() {
        location.href = $(this).attr('href');
    });

    /* left menu accodian */
    var bodyStyle = $('body').attr('class');
    var chapterNum = 0;
    var menuNum = 0;
    var submenuNum = 0;
    if (bodyStyle.length >= 7) {
        chapterNum = bodyStyle.substring(4, 5);
        menuNum = bodyStyle.substring(5, 6);
        submenuNum = bodyStyle.substring(6, 7);
    }
    var locationInfo = '.left_menu>ul>li:nth-child(' + chapterNum + ') ul>li:nth-child(' + menuNum + ')';

    var mainlistNum = locationInfo + ' ul';
    var listNum = locationInfo + '>a:first';
    var sublistNum = locationInfo + ' ul li:nth-child(' + submenuNum + ')';
    var leftMenu = '.leftmenu' + chapterNum;

    $('.left_menu>ul>li').css('display', 'none');
    $(leftMenu).css('display', 'block');
    $(mainlistNum).css('display', 'block');
    $(listNum).css('background', 'url(/contents/ko/images/common/left_sprite_bg.gif) 0 -552px').css('color', '#dd2120');
    $(sublistNum).addClass('over');

    //	if (bodyStyle.indexOf('main')==0) { $('.wrap_bottom_foot').css('margin', '0'); }
});

/* Print Script */
function mediaPrint(){
    window.open('/contents/ko/document/print.html','Print','width=820,height=700,scrollbars=yes');
}

/* 친구에게 소개하기 팝업창 */
function  introduceFriend(){
    var paraBox = document.getElementById('paraBox');
    var introPopPos = document.getElementById('introducePop');
    var pHeight = paraBox.offsetHeight;
    introPopPos.style.top = pHeight - 151 + "px";
    introPopPos.style.display = "block";
}
function introduceFriendHide(){
    var introPopPos = document.getElementById('introducePop');
    introPopPos.style.display = "none";
}

//Appliance pop //
function fnQNA(){
    window.opener.location.href="/contents/ko/service/support_inquire_write.aspx"
    self.close();
}

function openUsingGuide(){
    window.open('https://rview.net/remoteview/bc/contents/main/openUsingGuide.aspx?cNo=4','uguide','width=640,height=445,scrollbars=no');
}
/* eventLink until 2 */
function eventLink(id){
	if (id <10){
    	var btn = document.getElementById('eventBt00'+id);
	}else if (10 < id <100){
    	var btn = document.getElementById('eventBt0'+id);
	}else {
    	var btn = document.getElementById('eventBt'+id);
	}
    var btnLink = btn.firstChild.getAttribute('href');
    window.location.href = btnLink;
}
/* eventNewLink until 6 */
function eventNewLink(id){
	if (id <10){
    	var btn = document.getElementById('eventNum00'+id);
	}else if (10 < id <100){
    	var btn = document.getElementById('eventNum0'+id);
	}else {
    	var btn = document.getElementById('eventNum'+id);
	}
    var btnLink = btn.firstChild.getAttribute('href');
    window.open(btnLink,'','');
}

/*
===============================================================================
* Program Common
===============================================================================
*/

//id type Check :  영문소문자,숫자,_
function IDTypeChk(str){
//    if(str.trim()=="" || str.trim() == null){
//        alert("ID를 입력해주세요");
//        return false;
//    }
    var len = str.length;
    if(len < 4 || len > 30){
        alert("ID는 4자 이상 30자 이하 영문소문자,숫자만 입력가능합니다.");
        return false;
    }
	for (i=0; i <= len -1 ; i++){
	    var chr=str.charCodeAt(i);
	    //48~57
	    //65~90 97~122
	    if(!(chr>=48 && chr<=57) && !(chr >= 97 && chr <= 122)){
			alert("ID는 영문소문자, 숫자만 입력가능합니다.");
			return false;
	    }   
    }
	return true;
}

//pwd type Check :  영문소문자,숫자,_
function PwdTypeChk(str){
//    if(str.trim()=="" || str.trim() == null){
//        alert("비밀번호를 입력해주세요");
//        return false;
//    }

    if(str.trim() != ""){
        var len = str.length;
        if(len < 6 || len > 30){
            alert("비밀번호는 6자 이상 30자 이하 영문소문자, 숫자만 입력가능합니다.");
            return false;
        }
	    for (i=0; i <= len -1 ; i++){
	        var chr=str.charCodeAt(i);
	        if(!(chr>=48 && chr<=57) && !(chr >= 97 && chr <= 122)){
			    alert("비밀번호는 영문소문자, 숫자만 입력가능합니다.");
			    return false;
	        }   
        }
	    return true;
    }
}

// tel form check
function chkTelNm(arg){
    if (arg.trim().length < 6 ){
        return false;
    }else if ((arg == "123-4567") || (arg == "111111")){
        return false;
    }else{
        return true;
    }
}

    /* dialog controllers */
    var dialogEl;
    function createDialog() {
        //console.info('createDialog', arguments);

        return $([
          '<div class="dialog" style="display: none;">',
            '<h3 class="title"></h3>',
            '<a href="#" class="close"></a>',
            '<div class="body"></div>',
          '</div>'
        ].join('\n')).appendTo(document.body);
    }

    function centerDialog() {
        dialogEl && dialogEl.is(':visible') && dialogEl.animate({
            left: $(window).width() / 2 - dialogEl.width() / 2,
            top: $(window).height() / 2 - dialogEl.height() / 2 + $(window).scrollTop()
        });
    }

    function openDialog(title, data, options) {
        //console.info('openDialog', arguments);
        if (!dialogEl) {
            dialogEl = createDialog();
            dialogEl.find('.close').click(closeDialog);
        }
        if (!options) options = {};

        dialogEl.css({ width: options.width || 600 });
        options.height && dialogEl.css({ height: options.height });

        function callback() {
            options.callback && options.callback();
            centerDialog();
        }

        dialogEl.css({
            left: $(window).width() / 2 - dialogEl.width() / 2
        }).find('.title').html(title).end().find('.body').html(data);

        if (dialogEl.is(':visible')) callback();
        else {
            dialogEl.show().css({
                top: 0 - dialogEl.height()
            }).animate({
                top: $(window).height() / 2 - dialogEl.height() / 2 + $(window).scrollTop()
            }, callback);
        }
        //console.log($(data).find('script'), dialogEl.find('script'));
    }

    function closeDialog(event) {
        //console.info('closeDialog', arguments);
        dialogEl.animate({ top: 0 - dialogEl.height() }, function() {
            dialogEl.hide();

            var player = window.document.getElementById("player");
            if (player.sendEvent) {
                player.sendEvent("stop", true);
            }

        });
        event.preventDefault();
        event.stopPropagation();
    }

    /* shared functions */
    function stop(event) {
        event.preventDefault();
        event.stopPropagation();
    }

    function request(pageId, callback) {        
        $.ajax({
            type: 'get',
            url: '/_common/lib/VideoPlayer.aspx?pageid=' + pageId,
            success: callback,
            error: function() {
                alert('Error!');
            }
        });
    }

    function LiveChat(obj) {
        var url = 'http://wwwkr.startsupport.com/WebRelayHelp/ALWN2000?relay_uri=4430&windowId=1';
        window.open(url, 'LiveChat', 'width=440,height=500,scrollbars=yes,resizable=yes');
    }
