
PopupExpiredays = (function () {				
	function P(){}
	
	//설정한 날짜만큼 쿠키가 유지되게. expiredays가 1 이면 하루동안 유지
	P.setCookie = function(name, value, expiredays) {		
		var expire_date = new Date();
		expire_date.setDate(expire_date.getDate() + expiredays );
		document.cookie = name + "=" + escape( value ) + "; expires=" + expire_date.toGMTString() + "; path=/";
	}

	//쿠키 소멸 함수
	P.clearCookie = function(name) {
		var expire_date = new Date();
		//어제 날짜를 쿠키 소멸 날짜로 설정한다.
		expire_date.setDate(expire_date.getDate() - 1)
		document.cookie = name + "= " + "; expires=" + expire_date.toGMTString() + "; path=/"
	}

	//쿠키값을 가져오는 함수
	P.getCookie = function(name) {
		var from_idx = document.cookie.indexOf(name+'=');
		
		if (from_idx != -1) {
			from_idx += name.length + 1
			to_idx = document.cookie.indexOf(';', from_idx)
			if (to_idx == -1) {
				to_idx = document.cookie.length
			}
			return unescape(document.cookie.substring(from_idx, to_idx))
		}
	}

	P.showPopupNotice = function(title, html, date) {
		var CloseDate = new Date(date); //팝업 윈도우를 닫고자 하는 날짜를 입력하세요.
		var Today = new Date(); //오늘 날짜		
		
		if (Today.getTime() < CloseDate.getTime()) {			
			//getCookie 함수를 호출하여 쿠키값을 가져온다.
			var blnCookie = this.getCookie("notice_popup");
			
			//쿠키값이 true가 아닐 경우에만 새 창을 띄운다.
			if ( !blnCookie ) {
				
					var callback = function(v, m, f) {
						if(v == 'later') {
							P.setCookie("notice_popup","true", 1);
						}
					}
				
					var txt = '<div id="notice_popup_title">' + title + '</div>' +
					          '<div id="notice_popup_body">' + html + '</div>';
					
					var popup = $.prompt(txt, {
						callback: callback,
						persistent: false,
						top: '30%',
						buttons: {							
							'오늘 하루 보지 않기': 'later',						
							'닫기': true
						},

					});
					
			}
		}
	}

	return P;
})();






