$(function() {

	var CreateShare = function(element, options) {
	   this.init(element, options)
	};
    CreateShare.prototype.init = function(element, options){
        this.element        = $(element);
        this.options        = options;
        this.bindInEvents();
    };
    CreateShare.prototype.bindInEvents = function(){
    	 var Sharelink = this.element;
    	 var target = this.element.data('target');
    	 var obj = this.element.next();
    	 var opt = obj.data('id');
    	 var Closelink = this.element.next().find("[data-target=ui-close]");
    	 Sharelink.on("click", function () {
    		 if (target === opt ) {
    			 if (obj.css("display") === "none") {
    				 Sharelink.addClass('ov');
    				 obj.show().delay(150).animate({ 'opacity': '1' }, 300, 'easeOutCubic');
    			 } else {
    				 Sharelink.removeClass('ov');
    				 obj.hide().delay(150).animate({ 'opacity': '0' }, 300, 'easeOutCubic');
    			}
    		 }
    	 });
    	 Closelink.on("click", function () {
    		 Sharelink.removeClass('ov');
    		 obj.hide().delay(150).animate({ 'opacity': '0' }, 300, 'easeOutCubic');
    	 });
    };
	function checkSharePlugin(option){
        var $this = $(this);
        var data  = $this.data('target');
        var options = $.extend({}, $this.data(), typeof option === 'object' && option);
        $this.data('target', (data = new CreateShare(this, options)));
        if (typeof option === 'string') data[option]()
    }
    $.fn.checkShare = checkSharePlugin;
	$(window).on("load",function(){
        $("[data-target=\"ui-open\"]").each(function () {
            var $this = $(this);   //버튼
            var option = $this.data();
            checkSharePlugin.call($this, option);
        });
    });
	
});	
	
	function GetIEVersion() {
	    var sAgent = window.navigator.userAgent;
	    var Idx = sAgent.indexOf("MSIE");

	    // If IE, return version number.
	    if (Idx > 0)
	        return parseInt(sAgent.substring(Idx+ 5, sAgent.indexOf(".", Idx)));

	    // If IE 11 then look for Updated user agent string.
	    else if (!!navigator.userAgent.match(/Trident\/7\./))
	        return 11;

	    else
	        return 99; //It is not IE
	}

	/**
	 *  하위 ie8이하 브라우저 checkbox, radio 영역 class 추가
	 * */

	if (GetIEVersion() === 9) {
	    $("body").addClass("ie9");
	}
	if (GetIEVersion() <= 8) {
	    $("body").addClass("ie8");
	}
	
// 파라미터 받아오기
function getParameter(strParamName){
    var arrResult = null;
    if(strParamName){
        arrResult = location.search.match(new RegExp("[&?]" + strParamName + "=(.*?)(&|$)"));
    }
    return arrResult && arrResult[1] ? arrResult[1] : null;
}
//sns공유 시작
//페이스북
function facebookOpen() {
  var titl = $("#body_layout .contents_wrap .title_wrap h2").text();
  titl = titl.replace ('"', '&quot;');
  titl = titl.replace ('"', '&quot;');
  titl = encodeURIComponent(titl);
  var link = encodeURIComponent(location.href);
  var url = "http://www.facebook.com/sharer.php?u=" + link + "&t=" + titl;
  snswindowOpen (url, 900, 450, 'no');
}
//twitter
function twitterOpen() {
  var titl = $("#body_layout .contents_wrap .title_wrap h2").text();
  titl = titl.replace ('"', '&quot;');
  titl = titl.replace ('"', '&quot;');
  titl = encodeURIComponent(titl);
  var link = encodeURIComponent(location.href);
  var url = "http://twitter.com/share?text=" + titl + "&url=" + link;
  snswindowOpen (url, 800, 400, 'yes');
}
//카카오스토리 공유
function kakaoOpen() {
  var titl = $("#body_layout .contents_wrap .title_wrap h2").text();
  titl = titl.replace ('"', '&quot;');
  titl = titl.replace ('"', '&quot;');
  titl = encodeURIComponent(titl);
  var link = encodeURIComponent(location.href);
  var url = "https://story.kakao.com/share?url=" + link ;
  snswindowOpen (url, 900, 450, 'no');
}
//naver
function naverOpen() {
  var titl = $("#body_layout .contents_wrap .title_wrap h2").text();
  titl = titl.replace ('"', '&quot;');
  titl = titl.replace ('"', '&quot;');
  titl = encodeURIComponent(titl);
  var link = encodeURI(encodeURIComponent(location.href ));
  var url = "http://share.naver.com/web/shareView.nhn?url=" + link + "&title=" + titl;
  snswindowOpen (url, 800, 400, 'yes');
}
function snswindowOpen () {
  var nUrl; var nWidth; var nHeight; var nLeft; var nTop; var nScroll;
  nUrl = arguments[0];
  nWidth = arguments[1];
  nHeight = arguments[2];
  nScroll = (arguments.length > 3 ? arguments[3] : "no");
  nLeft = (arguments.length > 4 ? arguments[4] : (screen.width/2 - nWidth/2));
  nTop = (arguments.length > 5 ? arguments[5] : (screen.height/2 - nHeight/2));
  winopen=window.open(nUrl, 'SNS', "left="+nLeft+",top="+nTop+",width="+nWidth+",height="+nHeight+",scrollbars="+nScroll+",toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no");
}
/* flow label */
$(document).ready(function(){
	if(!$("label").is(".flow")) return false;
	var o1 = $("label.flow");
	var o2 = $("label.flow").next();
	o1.css({"position":"absolute"});
	o1.bind("click focusin",function(){
		$(this).css({"visibility":"hidden"});
	});
	o2.bind("click focusin",function(){
		$(this).prev().css({"visibility":"hidden"});
	});
	o2.bind("focusout",function(){
		if($(this).val() == ""){
			$(this).prev().css({"visibility":"visible"});
		}
	});
	if(o2.val() != ""){ o1.css({"visibility":"hidden"}); }
});
/* OS 체크 불린값 전달 window 폰, window 기반 태블릿pc 에서 테스트가 필요함 */
function chaked_OS(){
	var device = navigator.userAgent;
	var str = device.split(";");
		str = str[0].split("(");
		str = str[1].split(" ");
	var chkOS = false;
	if(str[0] != "Windows" && str[0] != "Macintosh" && str[0] != "compatible"){
		chkOS = true; // 데스크탑이 아닐 때 true
	}
	return chkOS;
}
function return_width(){
	var w = $(window).width(); return w;
}
/* MSIE 9이하 버전체크 */
function ms_ver(){
	if(navigator.userAgent.match('MSIE')){
		var msie = navigator.userAgent;
		var ms_ver = msie.substr(msie.lastIndexOf('MSIE')).split('MSIE')[1];
			ms_ver = Number(ms_ver.split('.')[0]);
		return ms_ver;
	}else{
		return null;
	}
}
//쿠키저장
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 arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0; while(i< clen)
	{
		var j = i + alen;
		if(document.cookie.substring(i,j)==arg)
			{
			var end = document.cookie.indexOf(";",j);
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(j,end));
			}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}
/*********팝업관련 자바스크립트 소스****************/
function close_layer(num){
	document.getElementById(num).style.display = 'none';
	//쿠키굽기
	setCookie(num, 'done' , 1);
}
function close_layer2(num){
	document.getElementById(num).style.display = 'none';
}
function link_target(url,target){
	if(target=='_blank'){
		window.open(url);
	}else if(target=='_self'){
		location.href=url;
	}else{
		opener.location.href=url;
	}
}
function admissionFormCheck()
{
	var f = document.admissionForm;
	if(f.n_name.value.length<1)
	{
		alert("이름을 입력해 주세요");
		f.n_name.focus();
		return false;
	}
	if(f.jumin_num.value.length != 13)
	{
		alert("주민번호는 숫자만 입력해 주세요");
		f.jumin_num.focus();
		return false;
	}
	return true;
}
function message()
{
	alert("서비스준비중입니다.");
	return false;
}
/* mobile select */
function tab_mobile(){
    var window_w = $(window).width();
    tab = $("#tab_moType1");
    tab_li = tab.find(">ul>li");
    tab_on = tab.find(">ul>li.on");
  		if(tab.find(">.title").size() == 0){
        $('<strong class="title"><i class="arrow"></i></strong>').prependTo(tab);
     }
    var tab_tit = tab.find(">.title");
    if(tab_on.size() != 0){
        tab_tit.html(tab_on.find(">a").clone());
        } else {
        tab_tit.html(tab_li.eq(0).find(">a").clone());
        }
        var tab_btn = tab_tit.find(">a");
        tab_btn.click(function(){
        if(tab_li.eq(0).is(":hidden")){
            tab_tit.find(">a").addClass("on");
            tab_li.slideDown();
            } else {
                tab_tit.find(">a").removeClass("on");
                tab_li.slideUp();
            }
            return false;
        });
	     if(window_w < 768){
	         if(tab.hasClass("mobile")) return false;
	         tab.removeClass("pc").addClass("mobile");
	     } else {
	         if(!tab.hasClass("mobile")) return false;
	         tab.removeClass("mobile").addClass("pc");
	         tab_li.removeAttr("style");
	     }
    }
function table_mobile(){
  $(".table-responsive").each(function () {
      var $this = $(this);   //버튼
      var option = $this.find(".table-icon");
      var window_w = $(window).width();
      if(option.size() == 0){
        var icon = $('<button class="table-icon icon--hide"><svg class="swipe-icon" xmlns="http://www.w3.org/2000/svg"><g fill="#F0542B"><path d="M17.506 12.59c-.452-2.69-2.19-3.17-3.018-3.245-.624-.816-1.514-1.262-2.54-1.262-.22 0-.443.02-.668.06-.607-.725-1.444-1.12-2.397-1.12-.72 0-1.355.225-1.793.482l-1.785-5.61C4.94.732 3.975 0 2.792 0 1.897 0 1.056.427.542 1.128c-.5.677-.625 1.525-.357 2.38l2.253 7.088c-.32.184-.604.43-.84.727-.46.58-.737 1.347-.82 2.28-.124 1.387.335 2.933 1.363 4.595.7 1.12 1.47 1.994 1.79 2.334l1.06 2.48c.26.606.85.988 1.51.988h7.05c.806 0 1.487-.563 1.62-1.354l.01-.05.297-2.468.048-.108c1.58-3.596 2.23-6.025 1.997-7.43zm-3.118 7.18c-.015.037-.026.075-.033.114l-.31 2.57c-.04.247-.255.417-.504.417H6.5c-.205 0-.39-.11-.472-.3L4.92 19.99c-.023-.057-.057-.106-.1-.15-.452-.475-3.158-3.432-2.918-6.13.143-1.597.92-2.114 1.45-2.28.268-.085.413-.373.33-.64l-2.42-7.61c-.38-1.21.584-2.026 1.53-2.026.6 0 1.195.33 1.436 1.097l2.07 6.5c.073.23.284.36.495.36.148 0 .297-.06.4-.2.085-.113.188-.222.31-.316.272-.21.8-.432 1.38-.432.594 0 1.24.237 1.707.96.1.15.264.24.437.24.048 0 .095-.007.143-.02.205-.06.478-.116.78-.116.58 0 1.268.21 1.773 1.01.095.15.258.24.434.24h.07c.607 0 1.822.266 2.166 2.316.32 1.903-1.766 6.43-2.004 6.992z" fill="#F0542B"></path><path class="swipe-arrow" d="M9.766 3.294h5.505l-1.21 1.213c-.22.22-.22.578 0 .8.11.11.26.164.4.164.15 0 .29-.05.4-.16l2.11-2.11c.22-.22.22-.58 0-.8L14.8.24c-.22-.22-.577-.22-.797 0-.22.22-.22.578 0 .798l1.128 1.13H9.77c-.312 0-.564.252-.564.563 0 .31.252.56.564.56z" fill="#F0542B"></path></g></svg></button>').prependTo($(this));
      }
      if(window_w < 768){
        $this.removeClass("table-pc").addClass("table-responsive");
        option.removeClass('icon--hide');
      } else {
        $this.addClass("table-pc");
        option.addClass('icon--hide');
      }
    });
}


function table_mobile1(){
  $(".flip-scroll").each(function () {
      var $this = $(this);   //버튼
      var option = $this.find(".table-icon");
      var window_w = $(window).width();
      if(option.size() == 0){
        var icon = $('<button class="table-icon icon--hide"><svg class="swipe-icon" xmlns="http://www.w3.org/2000/svg"><g fill="#F0542B"><path d="M17.506 12.59c-.452-2.69-2.19-3.17-3.018-3.245-.624-.816-1.514-1.262-2.54-1.262-.22 0-.443.02-.668.06-.607-.725-1.444-1.12-2.397-1.12-.72 0-1.355.225-1.793.482l-1.785-5.61C4.94.732 3.975 0 2.792 0 1.897 0 1.056.427.542 1.128c-.5.677-.625 1.525-.357 2.38l2.253 7.088c-.32.184-.604.43-.84.727-.46.58-.737 1.347-.82 2.28-.124 1.387.335 2.933 1.363 4.595.7 1.12 1.47 1.994 1.79 2.334l1.06 2.48c.26.606.85.988 1.51.988h7.05c.806 0 1.487-.563 1.62-1.354l.01-.05.297-2.468.048-.108c1.58-3.596 2.23-6.025 1.997-7.43zm-3.118 7.18c-.015.037-.026.075-.033.114l-.31 2.57c-.04.247-.255.417-.504.417H6.5c-.205 0-.39-.11-.472-.3L4.92 19.99c-.023-.057-.057-.106-.1-.15-.452-.475-3.158-3.432-2.918-6.13.143-1.597.92-2.114 1.45-2.28.268-.085.413-.373.33-.64l-2.42-7.61c-.38-1.21.584-2.026 1.53-2.026.6 0 1.195.33 1.436 1.097l2.07 6.5c.073.23.284.36.495.36.148 0 .297-.06.4-.2.085-.113.188-.222.31-.316.272-.21.8-.432 1.38-.432.594 0 1.24.237 1.707.96.1.15.264.24.437.24.048 0 .095-.007.143-.02.205-.06.478-.116.78-.116.58 0 1.268.21 1.773 1.01.095.15.258.24.434.24h.07c.607 0 1.822.266 2.166 2.316.32 1.903-1.766 6.43-2.004 6.992z" fill="#F0542B"></path><path class="swipe-arrow" d="M9.766 3.294h5.505l-1.21 1.213c-.22.22-.22.578 0 .8.11.11.26.164.4.164.15 0 .29-.05.4-.16l2.11-2.11c.22-.22.22-.58 0-.8L14.8.24c-.22-.22-.577-.22-.797 0-.22.22-.22.578 0 .798l1.128 1.13H9.77c-.312 0-.564.252-.564.563 0 .31.252.56.564.56z" fill="#F0542B"></path></g></svg></button>').prependTo($(this));
      }
      if(window_w < 768){
        $this.removeClass("table-pc").addClass("flip-scroll");
        option.removeClass('icon--hide');
      } else {
        $this.addClass("flip-scroll");
        option.addClass('icon--hide');
      }
    });
}
$(document).ready(function(){
    	table_mobile();
    	$(window).resize(function(){table_mobile();});
      table_mobile1();
      $(window).resize(function(){table_mobile1();});
      $(".table-responsive").on("click", function() {
        $(this).find(".table-icon").addClass('icon--hide');
      });
      $(".flip-scroll").on("click", function() {
        $(this).find(".table-icon").addClass('icon--hide');
      });
});
$(document).ready(function(){
	if ($('.scrollbar-inner').length) {
			$('.scrollbar-inner').scrollbar({
				autoScrollSize : false,
			});
		}
});
$(document).ready(function(){
    $('.return_top').click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });
});
/// basic tab (WAI-ARIA Roles)
$(document).ready(function(){
	$(".tabpanel:first-of-type").addClass("on").attr("tabindex", "0");
	$(".js-tab").eq(0).addClass("on");
	$(".js-tab").eq(0).find('a').attr("tabindex", "0").attr("aria-selected", "true");
	$(".js-tab a").on("click", function(event){
		  if (event.preventDefault) {
		      event.preventDefault()
		    } else {
		      event.returnValue = false
		    }
		  var $this = $(this),
		      $scope = $this.parents('.ui-tablist'),
		      $tabButtons = $scope.find('.js-tab'),
		      $activeTab = $tabButtons.filter('.on')
		  if ($activeTab[0] !== $this[0]) {
		    var $tabPanels = $scope.find('.tabpanel'),
		        $activePanel = $tabPanels.filter('.on')
		    $activeTab.removeClass('on');
						$activeTab.children('a').attr('aria-selected', 'false');
		    $this.parent('li').addClass('on');
						$this.attr('aria-selected', 'true')
						var href = $this.attr("aria-controls");
						$activePanel.removeClass('on');
						$("[id="+href+"]").addClass('on');
		  }
		  event.preventDefault()

    });
    shotUrl();
    //즐겨찾기 고정버튼 생성
    $('#body_layout').prepend('<div class="bookmark2"><p class="icon_bookmark"><img class="star" src="/images/kor/common/icon_bookmark.png" alt="즐겨찾기" /></p></div>');
  
    //즐겨찾기 닫기
    $(document).on("click",".bookmark > .icon_bookmark",function(){ 
    	$('.bookmark').remove();
    
    });
    
    
    //즐겨찾기 S
    $('.bookmark2 > .icon_bookmark').click(function(){   	
	    //즐겨찾기 고정
	    $.ajax({
			url : '/myPage/selectFvrtUrlAjax.do',
			type : 'POST',
			dataType : 'json',
			data : {},
			success : function(result){
				resultList = result;				
				var Html = '<div class="bookmark">'+
	            	   '<p class="icon_bookmark"><img class="star" src="/images/kor/common/icon_bookmark.png" alt="즐겨찾기" /></p>'+
	            	   '<div class="bookmark_area">'+
	            	   '<p class="bookmark_title">즐겨찾기</p>'+
	            	   '<ul class="list-1st">';
				if(resultList.length>0){
				  $.each(resultList, function(i, v){
						
							Html += '<li><a href="'+v.url+'" title="'+v.title+'바로가기">'+v.title+'</a><span class="delete_btn"><input type="hidden" id="seq" name="seq" value="'+v.seq+'" />삭제</span></li>';
						
				  });
				}
				else
					{
					Html += '<li>즐겨찾기를 추가해주세요.</li>';
					}
				  Html += '</ul>'+
		    		'</div>'+
		    		'</div>';
				  $('#body_layout').append(Html);				   
			},
			 error : function(error) {
				 var Html = '<div class="bookmark">'+
			          	   '<p class="icon_bookmark"><img class="star" src="/images/kor/common/icon_bookmark.png" alt="즐겨찾기" /></p>'+
			          	   '<div class="bookmark_area">'+
			          	   '<p class="bookmark_title">즐겨찾기</p>'+
			          	   '<ul class="list-1st">'+			
			               '<li><a href="/kor/login.do" style="overflow:inherit;">로그인을 해주세요.</a></li>';
				 		   '</ul>'+
				 		   '</div>'+
	    		           '</div>';
			  $('#body_layout').append(Html);	
			 }
		});   
    });
   //즐겨찾기 E    
    
   //즐겨찾기 삭제
    $(document).on("click",".delete_btn",function(){ 
     	
        var seq = $(this).find('input[name="seq"]').val();         
    	$.ajax({
    		url : '/myPage/deleteFvrtUrlAjax.do',
    		type : 'POST',
    		data : {"seq" : seq},
    		success : function(result){
    			if(result == 'SUCC'){
    				 alert("url을 즐겨찾기에서  삭제하였습니다.");
    				 
    			}
    			else if(result == 'ERR')
    			{
    				alert("url을 즐겨찾기에서  삭제실패하였습니다.");
    			}
    			location.reload();
    		},
    		 error : function(error) {
    			 location.reload();
			 }
    	});
    });
   //즐겨찾기 삭제
});


$(function() {
    var Modal = function(btn, options) {
        this.options            = options;
        this.$body              = $(document.body);
        this.$button            = $(btn);
        this.href = this.$button.attr("href");
        this.$element           = $(this.options.target || (this.href && this.href.replace(/.*(?=#[^\s]+$)/, ""))); //button-target or a href
        //this.$element           = $(this.options.target);
        this.backdropselector   = "modal__backdrop";
        this.widthtselector    = "modal__body";
        this.heightselector    = "modal__content";
        this.isShown            = null;

        if(this.options.contentSousrce){
            this.contentReplace();
        }
    };

    Modal.DEFAULTS = {
        backdrop    : true,
        show        : true,
        keyboard    : true,
        width: 600
    };

    Modal.prototype.show = function () {
        var element = this.$element,
            modalBtn = this.button,
            modalBodyWidth = this.options.width;

        this.isShown = true;
        this.$body.addClass("modal__open");
        $("html").addClass("modal__open");

        //크기 조정 및 보이기
        this.setSize();
        element.show();

        var transition = element.hasClass("fade");
        if (transition) {
            element[0].offsetWidth; // force reflow
        }

        element.addClass("active");

        //모달 뒤 검은 배경
        if(this.options.backdrop){
            this.backdrop();
        }

        //닫기 버튼
        element.on('click.close', '[data-close=\'modal\']', $.proxy(this.hide, this));

        $(document)  //  모달 포커스 이동
        .off("focusin.modal") // guard against infinite focus loop
        .on("focusin.modal", function (e) {
            if (element[0] !== e.target && !element.has(e.target).length) {
                element.trigger("focus");
            }
        });

        this.escape();

        //브라우저 리사이즈
        this.resize();

        this.enforceFocus()
    };

    Modal.prototype.enforceFocus = function () {
        $(document)
            .off('focusin.modal') // guard against infinite focus loop
            .on('focusin.modal', $.proxy(function (e) {
                if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
                    this.$element.trigger('focus')
                }
            }, this))
    }


    Modal.prototype.hide = function(e){
        var element = this.$element,
            backdrop = "." + this.backdropselector,
            modalbtn = this.$button ;

        this.isShown = false;

        if (e) e.preventDefault();
        element.hide().removeClass("active");
        $(document.body).removeClass("modal__open");
        $("html").removeClass("modal__open");

        element.find(backdrop).remove();
        modalbtn.trigger("focus");

        this.escape();
        this.resize();
        
        if(this.options.file){
            $("#txt").find("a[href='" + this.options.file + "']").focus();
        }

    };
    Modal.prototype.contentReplace = function(){
        //console.log(this.options.contentSousrce);
        $("." + this.heightselector).html(this.options.contentSousrce);
    };
    //검은 배경
    Modal.prototype.backdrop = function(){
        var element = this.$element,
            backdrop = $("<div class='" + this.backdropselector + "'></div>")
        .prependTo(element)
        .css("height", 0)
        .css("height", element[0].scrollHeight)
        .on("click", $.proxy(this.hide, this));
        
    };
    Modal.prototype.adjustBackdrop = function () {
        this.$element.find("."+this.backdropselector)
        .css('height', 0)
        .css('height', this.$element[0].scrollHeight)
    };
    Modal.prototype.setSize = function (width, height) {
        var element = this.$element,
            modalWidth = this.options.width,
            modalHeight = this.options.height;

        if( modalWidth > $(window).width() ){
            modalWidth = $(window).width() - 50;
        }
        element.find("." + this.widthtselector).css({
            width : modalWidth
        });
        
        //console.log(modalHeight);
        if(modalHeight){
            element.find("." + this.heightselector).css({
                height : modalHeight
            });
        }
    };

    Modal.prototype.resize = function(){
         if (this.isShown) {
            $(window).on('resize.modal', $.proxy(this.adjustBackdrop, this))
        } else {
            $(window).off('resize.modal')
        }
    };

    Modal.prototype.escape = function () {

        if (this.isShown && this.options.keyboard) {
            this.$element.on('keyup', $.proxy(function (e) {
                e.which == 27 && this.hide()
            }, this))
        } else if (!this.isShown) {
            this.$element.off('keydown')
        }
    };

    function modalPlugin(option){
        return this.each(function(){
            var $this = $(this);
            var data  = $this.data("modal");
            var href = $this.attr("href");
            var $target = $($this.attr("data-target") || (href && href.replace(/.*(?=#[^\s]+$)/, ""))); // strip for ie7

            var options = $.extend({ remote: !/#/.test(href) && href }, Modal.DEFAULTS, $this.data(), $target.data(), typeof option === 'object' && option);

            if (!data) {
                $this.data("modal", (data = new Modal(this, options)));
            }

            if (typeof option === "string") {
                data[option]()
            }
            else if (options.show) {
                data.show()
            }
        });
    }

    $.fn.madalPop                   = modalPlugin;

    $(document).on("click.modal", "[data-button='modal']",function(e){
        e.preventDefault();
        var $this = $(this);   //버튼
        var option = $this.data();

        if ($this.is("button") || $this.is("a")) {
            e.preventDefault();
        }
        modalPlugin.call($this, option);
    });

});

(function($){
	  
	  var $fileBox = null;
	  
	  $(function() {
		  inits();
	  })
	  
	  function inits() {
	    $fileBox = $('.form-upload');
	    fileLoad();
	  }
	  
	  function fileLoad() {
	    $.each($fileBox, function(idx){
	      var $this = $fileBox.eq(idx),
	          $btnUpload = $this.find('[type="file"]'),
	          $label = $this.find('[data-button="upload"]');
	      
	      $btnUpload.on('change', function() {
	        var $target = $(this),
	            fileName = $target.val(),
	            $fileText = $target.siblings('[type="text"]');
	        $fileText.val(fileName);
	      })
	      
	      $btnUpload.on('focusin focusout', function(e) {
	        e.type == 'focusin' ?
	          $label.addClass('focus') : $label.removeClass('focus');
	      })
	      
	    })
	  }
	  
	  
	})(jQuery);

//chekcbox  전체 선택, 해제
$(function(){
  var checkedall = function(el, options) {
      $element            = $(el);
      this.element        = el;
      this.options        = options;
      this.checkBtn       =  $element.find(this.options.checkallid);  //전체선택 checkbox
      this.checkItemName  = 'input[name=\"' + this.options.checkname +'\"]';
      this.checkItem      = $element.find(this.checkItemName); //각 checkbox name
      this.checkItemNum   = this.checkItem.length;

      this.checkBtn.on('change',  $.proxy(this.changeall, this));
      this.checkItem.on('change',  $.proxy(this.changeitem, this));
  };

  checkedall.prototype.changeall = function(){
      this.checkItem .prop('checked', this.checkBtn.prop("checked"));
      var checkItemStatus = $(this.checkItem).is(":checked");
      if(this.options.visibletarget){
          this.displayTarget(checkItemStatus);
      }
  };

  checkedall.prototype.changeitem = function(){

      this.checkedItem = $(this.element).find(this.checkItemName + ":checked").length;
      //checkItem 체크, 해제 되면
      if(false === this.checkItem.prop("checked")){
          this.checkBtn.prop('checked', false);
      }

      if( this.checkedItem > 0 &&  this.checkedItem < this.checkItemNum){ //checkedItem 1개이상 체크되면
          this.checkBtn.prop('checked', false);
          this.targetStatus = true;
      }
      else if (this.checkedItem === this.checkItemNum ){ //checkedItem 모두 체크되면
          this.checkBtn.prop('checked', true);
          this.targetStatus = true;
      }
      else{
          this.checkBtn.prop('checked', false);  //checked 없으면
          this.targetStatus = false;
      }

      if(this.options.visibletarget){
          this.displayTarget(this.targetStatus);
      }
  };


  checkedall.prototype.displayTarget = function(visible){
      var visibleStatus = $(this.options.visibletarget).is(":visible");
      if(visible === true){
          if(!visibleStatus){
              $(this.options.visibletarget).show();
          }
      } else{
          if(visibleStatus) {
              $(this.options.visibletarget).hide();
          }
      }
  };

  function checkAll(option){
      var $this = $(this);
      var data  = $this.data("select");
      var options = typeof option === 'object' && option;

      if (data) $this.data('select', (data = new checkedall(this, options)));
      if (typeof option === 'string') data[option]()

  }
  $(window).on("load",function(){
      $("[data-select=\"checkall\"]").each(function () {
          var $this = $(this);   //버튼
          var option = $this.data();
          checkAll.call($this, option);
      });
  });


});


$(function(){
    var CreateMap = function(element, options) {
        this.init(element, options)
    };
    CreateMap.DEFAULTS = {
        level : 3,
        draggable : true,
        zoomable : true,
        typecontrol : false
    };
    CreateMap.prototype.init = function(element, options){
        this.element        = $(element);
        this.options        = options;
        this.addMarker();
    };
    CreateMap.prototype.addMarker = function(){
        var mapContainer = this.element[0],
            mapOption = {
                center: new daum.maps.LatLng(this.options.lat, this.options.lng), // 지도의 중심좌표
                level: this.options.level // 지도의 확대 레벨
            };

        var map = new daum.maps.Map(mapContainer, mapOption); // 지도를 생성합니다

        map.setDraggable(this.options.draggable); //지도  drag 제어
        map.setZoomable(this.options.zoomable);   //지도 확대,축소 제어

        if(this.options.typecontrol) {
            var mapTypeControl = new daum.maps.MapTypeControl();
            map.addControl(mapTypeControl, daum.maps.ControlPosition.TOPRIGHT);

            var zoomControl = new daum.maps.ZoomControl();
            map.addControl(zoomControl, daum.maps.ControlPosition.RIGHT);
        }

        var imageSrc = '/pcms/common/images/marker.png',
            imageSize = new daum.maps.Size(40, 42), // 마커이미지의 크기
            imageOption = {offset: new daum.maps.Point(27, 69)}; // 마커의 좌표와 일치시킬 이미지 안에서의 좌표를 설정

        // 마커가 표시될 위치
        var markerImage = new daum.maps.MarkerImage(imageSrc, imageSize, imageOption),
            markerPosition = new daum.maps.LatLng(this.options.lat, this.options.lng);


        // 마커를 생성
        var marker = new daum.maps.Marker({
            position: markerPosition,
            image: markerImage
        });

        // 마커가 지도 위에 표시되도록 설정
        marker.setMap(map);

        if(this.options.title || this.options.info ){
            var customOverlay = new daum.maps.CustomOverlay({
                position: markerPosition
            });

            var content = document.createElement('div');
            content.className = "ui-map-info";


            var title = document.createElement('div');
            title.className ="ui-map-info__title";
            title.appendChild(document.createTextNode(this.options.title));
            content.appendChild(title);

            if(this.options.info){
                var info = document.createElement('div');
                info.className ="ui-map-info__content";
                info.appendChild(document.createTextNode(this.options.info));
                content.appendChild(info);

                content.className = "ui-map-info--multi";
            }
            customOverlay.setContent(content);
            customOverlay.setMap(map);
        }
    };

    function checkMapPlugin(option){
        var $this = $(this);
        var data  = $this.data('map');
        //var options = typeof option === 'object' && option;
        var options = $.extend({}, CreateMap.DEFAULTS, $this.data(), typeof option === 'object' && option);
        $this.data('map', (data = new CreateMap(this, options)));
        if (typeof option === 'string') data[option]()
    }
    $.fn.checkMap             = checkMapPlugin;

    
        $("[data-map=\"map\"]").each(function () {
            var $this = $(this);   //버튼
            var option = $this.data();
            checkMapPlugin.call($this, option);
        });
  

});

/*
function CopyUrl(event){
    var t = document.createElement("textarea");
    var str = "";

    document.body.appendChild(t);
    if(document.location.href.indexOf('bbs') > -1 && document.location.href.indexOf('view') > -1){
    	str = "?nttId=" + document.searchForm.nttId.value;
    }
    t.value = document.location.href + str;
    
    t.select();
    document.execCommand('copy');
    document.body.removeChild(t);

    alert("url을 클립보드에 저장하였습니다.");
    event.preventDefault()
}
*/

function CopyUrl(event){
    var t = document.createElement("textarea");
    var str = "";

    document.body.appendChild(t);
    if(document.location.href.indexOf('bbs') > -1 && document.location.href.indexOf('view') > -1){
    	str = "?nttId=" + document.searchForm.nttId.value;
    }
    t.value = document.location.href + str;
    
    t.select();
    document.execCommand('copy');
    document.body.removeChild(t);

    alert("url을 클립보드에 저장하였습니다.");
    event.preventDefault()
}

function shotUrl(){
    if( $('.print_wrap').length > 0 ){
    	$('.print_wrap').find('.copy').parent().remove();
        $('.print_wrap').append('<li><button onclick="CopyShotUrl(); return false;" title="짧은URL" >짧은URL</button></li>');
        $('.print_wrap').append('<li class="n3" id="bookmark"><button id="bookmark" onclick="FvrtUrl(); return false;" title="즐겨찾기" >즐겨찾기</button></li>');
    }
}

function CopyShotUrl(event){	
	var hostUrl = $(location).attr('protocol') + "//" + $(location).attr('host');
    var localUrl = document.location.href;    
    var subject = $('.page__title').text();
    $.ajax({
		url:'/prog/shortUrlCheck.do',
		data: {
        	'redirectUrl': localUrl,
            'subject':subject
		},
		dataType: "json",
		type : "POST",
		success: function(data) {
			var shortUrl = hostUrl + "/shrUrl/" + data + ".do";
			
			var t = document.createElement("textarea");
			document.body.appendChild(t);
			t.value = shortUrl;
			t.select();
			document.execCommand('copy');
			document.body.removeChild(t);
			alert("짧은URL을 클립보드에 저장하였습니다.");
		}
    });
}

function FvrtUrl(){
    var t = document.createElement("textarea");
    var str = "";
    var title= $('.page__title').text();

    
    document.body.appendChild(t);
//    if(document.location.href.indexOf('bbs') > -1 && document.location.href.indexOf('view') > -1){
//    	str = "?nttId=" + document.searchForm.nttId.value;
//    }

    t.value = document.location.href + str;
	$.ajax({
		url : '/myPage/insertFvrtUrlAjax.do',
		type : 'POST',
		dataType : 'json',
		data : {"title" : title, "url" : t.value},
		success : function(result){
			if(result == 'SUCC'){
				 alert("url을 즐겨찾기에 저장하였습니다.");
				  $('.bookmark').remove();
				  $('.bookmark2 > .icon_bookmark').click();
			}
			else if(result == 'ERR')
			{
				alert("url을 즐겨찾기에 저장실패하였습니다.");
			}
			else if(result == 'CHECK')
			{
				alert("해당URL은 즐겨찾기에  중복으로 등록되어있습니다.");
			}
			else if(result == 'COUNT')
			{
				alert("6개이상 즐겨찾기 URL을 추가할 수 없습니다. 마이페이지에서 기존 URL 삭제 후 진행하여 주시기 바랍니다. ");
			}
			else 
			{
				alert("로그인 이후 가능합니다.");
			}
			
		}
	});
}
/*
function autolink(id) 
{
		var container = document.getElementsByClassName(id);
	    var doc = container.innerHTML;
	    var regURL = new RegExp("(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:;200-377()]+)","gi");
	    var regEmail = new RegExp("([xA1-xFEa-z0-9_-]+@[xA1-xFEa-z0-9-]+\.[a-z0-9-]+)","gi");
	    container.innerHTML = doc.replace(regURL,"<a href='$1://$2' target='_blank' title='새창열림' class='btn-windows'>$1://$2<i class='ir'></i></a>").replace(regEmail,"<a href='mailto:$1' class='btn-email'>$1<i class='ir'></i></a>");
}
$(function(){
	if(document.location.href.indexOf('bbs') > -1 && document.location.href.indexOf('view') > -1){
		autolink('bbs--view--content');
	}
});

*/

/*
$(function(){
    $('.bbs--view--content').each(function(){
        var str = $(this).html();
        var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/gi
        var replaced_text = str.replace(regex, "<a href='$1' target='_blank' title='새창열림' class='btn-windows'>$1<i class='ir'></i></a>");
        $(this).html(replaced_text);
    });

});*/