/*
	String.prototype.trim = function(){
	    return this.replace(/(^\s*)|(\s*$)/gi, "");
	}

	String.prototype.replaceAll = function(str1, str2){
	    var temp_str = "";

	    if (this.trim() != "" && str1 != str2){
	        temp_str = this.trim();

	        while (temp_str.indexOf(str1) > -1){
	            temp_str = temp_str.replace(str1, str2);
	        }
	    }

	    return temp_str;
	}
*/
	//Header Menu Show
	function showMenu(id) {
		switch(id){
		case 'glb' : $('#h_glb').addClass("gnb_glb_on");
			break;
		case 'lang' : $('#h_lang').addClass("gnb_lang_on");
			break;
		case 'aff' : $('#f_aff').addClass("aff_on");
			break;
		default : $('#h_'+id).addClass("lnb_"+id+"_on"); break;
		}
	}

	//Header Menu Hide
	function hideMenu(id) {
		switch(id){
		case 'glb' : $('#h_glb').removeClass("gnb_glb_on");
			break;
		case 'lang' : $('#h_lang').removeClass("gnb_lang_on");
			break;
		case 'aff' : $('#f_aff').removeClass("aff_on");
		default : $('#h_'+id).removeClass("lnb_"+id+"_on"); break;

		}
	}

	function spotOption() {
	    var objWrap = document.getElementById("wrap");
	    var expireDate = new Date();
	    expireDate.setDate(expireDate.getDate() + 1);

	    if (objWrap.className.indexOf("spot_collapse") > -1) {
	        removeClass(objWrap, "spot_collapse");
	        setCookie("spot_status", "on", expireDate, "/", "nhncorp.com", "");
	    } else {
	        addClass(objWrap, "spot_collapse");
	        setCookie("spot_status", "off", expireDate, "/", "nhncorp.com", "");
	    }
	}

	function keepToggleSpotArea() {
	    var objWrap = document.getElementById("wrap");
	    var spot_curr_status = getCookie("spot_status");

	    if (spot_curr_status == "on") {
	        removeClass(objWrap, "spot_collapse");  
	    } else if (spot_curr_status == "off") {
	        addClass(objWrap, "spot_collapse");
	    } else {
	        removeClass(objWrap, "spot_collapse");  
	    }
	}
		
    // 쿠키 생성
    function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires.toGMTString() : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");
        document.cookie = curCookie;
    }

    // 쿠키값 가져오기
    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 addClass(obj, value) {
        obj.className += " " + value;
    }

    function removeClass(obj, value) {
        obj.className = obj.className.replace(" " + value, "");
    }

	function changeDate(date) {
		if($("#from_date").val().replaceAll(".","") > $("#to_date").val().replaceAll(".","")){
			alert('검색기간이 올바르지 않습니다.');
			$("#"+selectId).val(oldselectData);
			return;
		}
	}

    try { document.execCommand('BackgroundImageCache', false, true);} catch(e) {}


/** 메인페이지 롤링 **/
    var mouse = 1;
    var inews = 4;
    function newsroll() {
    	if(mouse==0) return;
    	$("#newsitem"+inews).css("display","none");
    	$("#pritem"+inews).css("display","none");
    	++inews;
    	if(inews > 3) inews = 0;
    	$("#newsitem"+inews).css("display","block");
    	$("#pritem"+inews).css("display","block");
    }
    
  
    
    
    function slideShow() {

    	$('#gallery1 a').css({opacity: 0.0});
    	$('#gallery1 a:first').css({opacity: 1.0});

    	$('#gallery2 a').css({opacity: 0.0});
    	$('#gallery2 a:first').css({opacity: 1.0});

    	$('#gallery3 a').css({opacity: 0.0});
    	$('#gallery3 a:first').css({opacity: 1.0});

    	setInterval('gallery()',6000);

    }

    function gallery() {
    	var current = ($('#gallery1 a.show')?  $('#gallery1 a.show') : $('#gallery1 a:first'));
    	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery1 a:first') :current.next()) : $('#gallery1 a:first'));
    	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
    	current.animate({opacity: 0.0}, 1000).removeClass('show');

    	var current = ($('#gallery2 a.show')?  $('#gallery2 a.show') : $('#gallery2 a:first'));
    	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery2 a:first') :current.next()) : $('#gallery2 a:first'));
    	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
    	current.animate({opacity: 0.0}, 1000).removeClass('show');

    	var current = ($('#gallery3 a.show')?  $('#gallery3 a.show') : $('#gallery3 a:first'));
    	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery3 a:first') :current.next()) : $('#gallery3 a:first'));
    	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
    	current.animate({opacity: 0.0}, 1000).removeClass('show');

    }
    
    function notice_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 "";
    }

