var DOC = document;
var historyBlank = domain+"Libs/_js/blank.html?";

// 메시지 얼럿트
var alerts = document.alerts = function(str) { str.alert(); return false; }
var confirms = document.confirms = function(str) { return str.confirm() }

// 브라우져 정보
var browser = {};
/MSIE ([0-9]{1,})\.?/.exec(navigator.userAgent);
browser.version = RegExp.$1;
browser.kind = navigator.userAgent.match(/MSIE/) ? "IE" : "GEKO";

var rss_icon_func = function(obj) {
	window.clipboardData.setData('text', obj.href);
	alerts('RSS 주소가 복사되었습니다.');
}

/*
// IE 전용 스크립트 - 2008.12.11 fixed
var setPng24 = function(el, save) {
	if(el.src=="about:blank") return;
	if(browser.kind=="GEKO" || (browser.kind=="IE" && browser.version>6)) return;
	if(save!==false) el.setAttribute('default', el.src);

	el.style.height = '1px';
	el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+el.src+')';
	el.src = "about:blank";
}
*/

// 2009.02.03 개선 - CSS : expression 사용안함
var rankup_setPng24 = function(el) {
	if(browser.kind=="GEKO" || (browser.kind=="IE" && browser.version>6)) return false;
	if(el==undefined) {
		if(!document.body.id) document.body.id = '_tmp_body_';
		el = document.body.id;
	}
	var imgs = $(el).getElementsBySelector('img[class~="png24"]');
	imgs.each(function(img) { 
		img.setAttribute('default', img.src);
		img.style.height = '1px';
		img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+img.src+')';
		img.src = 'about:blank';
	});
}

//##################################################################################
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//숫자 아닌값을 숫자로 바꾸는 스크립트
function onlyDigit(el) {
	el.value = el.value.replace(/\D/g,'');
}

// flash object 처리
var flashDraw = function(i,s,w,h,t) {
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width="+w+" height="+h+" id="+i+"><param name=wmode value="+t+" /><param name=allowScriptAccess value=sameDomain /><param name=movie value="+s+" /><param name=quality value=high /><param name=menu value=false /><param name=loop value=true /><embed src="+s+" name="+i+" quality=high wmode="+t+" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" width="+w+" height="+h+" allowScriptAccess=sameDomain loop=false menu=false></object>");
}

// media player object 처리
var mediaDraw = function(i,s,w,h) {
	document.write("<object id='"+i+"' width='"+w+"' height='"+h+"' classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'><param NAME='AudioStream' VALUE='-1'><param NAME='AutoSize' VALUE='0'><param NAME='AutoStart' VALUE='-1'><param NAME='AnimationAtStart' VALUE='-1'><param NAME='AllowScan' VALUE='-1'><param NAME='AllowChangeDisplaySize' VALUE='-1'><param NAME='AutoRewind' VALUE='0'><param NAME='Balance' VALUE='0'><param NAME='BaseURL' VALUE=''><param NAME='BufferingTime' VALUE='100'><param NAME='CaptioningID' VALUE=''><param NAME='ClickToPlay' VALUE='0'><param NAME='CursorType' VALUE='0'><param NAME='CurrentPosition' VALUE='-1'><param NAME='CurrentMarker' VALUE='0'><param NAME='DefaultFrame' VALUE='Slide'><param NAME='DisplayBackColor' VALUE='0'><param NAME='DisplayForeColor' VALUE='16777215'><param NAME='DisplayMode' VALUE='0'><param NAME='DisplaySize' VALUE='4'><param NAME='Enabled' VALUE='-1'><param NAME='EnableContextMenu' VALUE='0'><param NAME='EnablePositionControls' VALUE='-1'><param NAME='EnableFullScreenControls' VALUE='0'><param NAME='EnableTracker' VALUE='-1'><param NAME='Filename' VALUE='"+s+"'><param NAME='InvokeURLs' VALUE='-1'><param NAME='Language' VALUE='-1'><param NAME='Mute' VALUE='0'><param NAME='PlayCount' VALUE='1'><param NAME='PreviewMode' VALUE='0'><param NAME='Rate' VALUE='1'><param NAME='SAMILang' VALUE=''><param NAME='SAMIStyle' VALUE=''><param NAME='SAMIFileName' VALUE=''><param NAME='SelectionStart' VALUE='-1'><param NAME='SelectionEnd' VALUE='-1'><param NAME='SendOpenStateChangeEvents' VALUE='-1'><param NAME='SendWarningEvents' VALUE='-1'><param NAME='SendErrorEvents' VALUE='-1'><param NAME='SendKeyboardEvents' VALUE='0'><param NAME='SendMouseClickEvents' VALUE='0'><param NAME='SendMouseMoveEvents' VALUE='0'><param NAME='SendPlayStateChangeEvents' VALUE='-1'><param NAME='ShowCaptioning' VALUE='0'><param NAME='ShowControls' VALUE='1'><param NAME='ShowAudioControls' VALUE='1'><param NAME='ShowDisplay' VALUE='0'><param NAME='ShowGotoBar' VALUE='0'><param NAME='ShowPositionControls' VALUE='0'><param NAME='ShowStatusBar' VALUE='0'><param NAME='ShowTracker' VALUE='1'><param NAME='TransparentAtStart' VALUE='-1'><param NAME='VideoBorderWidth' VALUE='2'><param NAME='VideoBorderColor' VALUE='0'><param NAME='VideoBorder3D' VALUE='0'><param NAME='Volume' VALUE='-600'><param NAME='WindowlessVideo' VALUE=''></object>");
}

// 페이지 스크롤바 위치
function getPageScroll() {
	var yScroll;
	if(self.pageYOffset) yScroll = self.pageYOffset;
	else if(document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop; // Explorer 6 Strict
	else if(document.body) yScroll = document.body.scrollTop; // all other Explorers
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// 페이지 사이즈
function getPageSize(){
	var xScroll, yScroll;
	if(window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if(self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if(document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
	pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// 블라인드
var sb_selects;
var screenBlind = function(mode) {
	if(mode == "on") {
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var sendingImage = document.createElement("img");
		sendingImage.src = domain+"images/sending.gif";
		sendingImage.setAttribute('id','sendingImage');
		sendingImage.style.position = "absolute";
		sendingImage.width = "195";
		sendingImage.height = "18";
		sendingImage.style.zIndex = "150";
		sendingImage.style.top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - sendingImage.height) / 2) + 'px';
		sendingImage.style.left = ((arrayPageSize[0] - sendingImage.width) / 2) + 'px';
		sendingImage.style.display = "block";
		$('screenBlind').appendChild(sendingImage);
		$('screenBlind').style.height = (arrayPageSize[1] + 'px');
		$('screenBlind').style.display = "block";
		sb_selects = document.getElementsByTagName("select");
		for(var i=0; i<sb_selects.length; i++) sb_selects[i].style.visibility = "hidden";
	}
	else if(mode=='off') {
		$('screenBlind').update('');
		$('screenBlind').style.display = "none";
		for(var i=0; i<sb_selects.length; i++) sb_selects[i].style.visibility = "visible";
	}
}

//##################################################################################
//## 카테고리 처리
//##################################################################################
var changeCategory = function(code, from, to, val, extra1, extra2) {
	var text3 = to.options[0].getAttribute('text3');
	if(from.value==='') {
		if(text3!=null) to.options[0].text = text3;
		to.options[0].removeAttribute('text3');
		to.options.length = 1;
		to.value = '';
	}
	else {
		var text2 = to.options[0].getAttribute('text2');
		if(text2!=null && text3==null) {
			var tmp_text = to.options[0].text;
			to.options[0].text = text2;
			to.options[0].setAttribute('text3', tmp_text);
		}
		var url = domain+"Libs/_js/load_category_item.ajax.php?code="+code+"&parent_no="+from.value;
		var myRequest = new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				if(!transport.responseText.match(null)) {
					var resultData = transport.responseXML.getElementsByTagName('resultData')[0];
					var parent_no = resultData.getAttribute('parent_no');
					if(parent_no!=from.value) return false;
					var optionsData = resultData.getElementsByTagName('options')[0];
					var option = optionsData.getElementsByTagName("option");
					to.options.length = 1;
					to.value = '';
					var optgroups = to.getElementsByTagName("optgroup");
					for(var i=parseInt(optgroups.length); i>0; i--) to.removeChild(optgroups[i-1]);
					for(var i=0; i<option.length; i++) {
						if(option[i].getAttribute("optgroup")!=null) {
							var newOptgroup = document.createElement("optgroup");
							newOptgroup.style.color = "#565656";
							newOptgroup.style.backgroundColor = "#EEEEEE";
							newOptgroup.setAttribute("label", option[i].getAttribute("label"));
							to.appendChild(newOptgroup);
						}
						else {
							var newOption = document.createElement("option");
							newOption.setAttribute("value", option[i].getAttribute("value"));
							if(val == option[i].getAttribute("value")) newOption.setAttribute("selected", "selected");
							newOption.innerHTML = option[i].firstChild.nodeValue;
							to.appendChild(newOption);
						}
					}
				}
			},
			onComplete: function() {myRequest = null}
		});
	}
	for(var i=1; i<=2; i++) {
		var extra = eval('extra'+i);
		if(extra==null) break;
		extra.options.length = 1;
		extra.value = '';
	}
}


//##################################################################################
//## 콤보박스 클래스 정의
//##################################################################################
var COMBOBOX = function() {
	this.items = new Array(); // 오브젝트
	this.drawMode = "multi";  // 드로우 방식 : single  or  multi
	this.width = 0;
	this.pulldown_flag = new Array(); // 풀다운 체크
	this.left = "<img src='"+domain+"images/top01_search01.gif'>";
	this.body = "url('"+domain+"images/top01_search02.gif') repeat-x";
	this.right = "<img src='"+domain+"images/top01_search_icon.gif'>";
	this.styles = { // 스킨에 적용할 스타일
		"base": "border:#dedede 0px solid;font-size:9pt;cursor:pointer;padding:0px;",
		"option": "border:#dedede 1px solid;font-size:9pt;background-color:white;padding:2px;", // 옵션배경
		"item": "border:0;font-size:9pt;font-family:dotum;color:black;line-height:120%;background-color:white;padding:2 0 0 5px;" // 아이템
	};
	this.base_color = { // 기본색상 : this.styles['item'] 설정값과 동일하게 설정
		"background": "white",
		"color": "black"
	};
	this.hover_color = { // 호버색상
		"background": "#336699",
		"color": "white"
	};
}
// 콤보박스 선택
COMBOBOX.prototype.select_item = function(obj) {
	var item = $(obj.parentNode.id.replace(/_option$/g,''));
	item.value = obj.value;
	$(item.name+'_text').update(obj.innerHTML);
	this.pulldown(item.name);
}
// 콤보박스 아이템 호버
COMBOBOX.prototype.item_hover = function(obj, mode) {
	var color = (mode=="hover") ? this.hover_color : this.base_color;
	var name = obj.parentNode.id.replace(/_option$/g,'');
	var item = $(name);
	if(this.pulldown_flag[parseInt(item.getAttribute('no'))]==true) { // 선택값 초기화
		var option = obj.parentNode.getElementsByTagName('div');
		for(var i=0; i<option.length; i++) {
			if(option[i].value==item.value) {
				this.pulldown_flag[parseInt(item.getAttribute('no'))] = false;
				this.item_hover(option[i], 'base');
				break;
			}
		}
	}
	for(var idx in color) obj.style.setAttribute(idx, color[idx]);
}
// 콤보박스 풀다운
COMBOBOX.prototype.pulldown = function(obj) {
	var item = $(obj+'_option');
	item.style.display = (item.style.display=="block") ? "none" : "block";
	if(item.style.display=="block") {
		var option = item.getElementsByTagName('div');
		for(var i=0; i<option.length; i++) {
			if(option[i].value==$(obj).value) {
				this.pulldown_flag[$(obj).getAttribute('no')] = true;
				for(var idx in this.hover_color) option[i].style.setAttribute(idx, this.hover_color[idx]);
				break;
			}
		}
		var frame = item.getElementsByTagName('iframe')[0];
		frame.style.width = parseInt(item.offsetWidth, 10)-2;
		frame.style.height = parseInt(item.offsetHeight, 10)-2;
	}
}
// 콤보박스 스킨
COMBOBOX.prototype.skin = function(obj, no) {
	var skins = { // 스킨
		"base": "<input type='hidden' name=\"{:name:}\" value=\"{:value:}\" no='{:no:}'><div style='"+this.styles['base']+"' id=\"{:name:}\" onClick=\"combobox.pulldown('{:name:}')\"><table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td>"+this.left+"</td><td style=\"background:"+this.body+";width:{:width:}px;font-family:verdana;letter-spacing:-1px;padding:3 3 0 1px;overflow:hidden\" id='{:name:}_text'>{:text:}</td><td align='right'>"+this.right+"</td></tr></table></div>",
		"option": "<div style='margin-top:2px;position:absolute;display:none;"+this.styles['option']+"' id=\"{:name:}_option\"><iframe src=\"about:blank\" style=\"position:absolute;z-index:0;left:-1px;top:-1px;"+this.styles['option']+"\" frameborder=\"0\"></iframe>{:item:}</div>",
		"item": "<div style='position:relative;z-index:1;cursor:pointer;width:100%;"+this.styles['item']+"' value=\"{:value:}\" onMouseOver=\"combobox.item_hover(this, 'hover')\" onMouseOut=\"combobox.item_hover(this, 'base')\" onClick=\"combobox.select_item(this)\">{:text:}</div>"
	};
	var option = obj.options;
	var skinHTML = skins['base'].replace(/{:name:}/g, obj.name).replace(/{:no:}/g, no);
	skinHTML = skinHTML.replace(/{:value:}/g, obj.value).replace(/{:text:}/g, obj.options[obj.selectedIndex].text); // 현재 선택된 값;
	for(var i=0, item='', max_width=0; i<option.length; i++) {
		if(max_width < option[i].text.bytes()) max_width = option[i].text.bytes();
		item += skins['item'].replace(/{:value:}/g, option[i].value).replace(/{:text:}/g, option[i].text);
	}
	return skinHTML.replace(/{:width:}/g, Math.ceil(parseInt(max_width)*6)) + skins['option'].replace(/{:name:}/g, obj.name).replace(/{:item:}/g, item);
}
// 콤보박스 생성
COMBOBOX.prototype.draw = function(obj) {
	if(obj) this.items[0] = obj;
	for(var i=0; i<this.items.length; i++) {
		if(this.items[i].outerHTML) this.items[i].outerHTML = this.skin(this.items[i], i);
		else {
			// 파폭 - 미구현
			var xs = new XMLSerializer;
			xs.serializeToString(this.items[i]).innerHTML = this.skin(this.items[i], i);
		}
	}
}
// 콤보박스 초기화
COMBOBOX.prototype.initialize = function() {
	var items = document.getElementsByTagName('select');
	for(var i=0; i<items.length; i++) {
		if(items[i].type=="combobox") {
			this.pulldown_flag[this.items.length] = false;
			if(this.drawMode=="multi") this.items.push(items[i]);
			else this.draw(items[i]); // 드로우
		}
	}
	if(this.items.length) this.draw();
}


//##################################################################################
//## 플로팅 클래스 정의
//##################################################################################
var FLOATING = function(el, pattern, x, y, pro, cycle) {
	this.floatingObj = document.getElementById(el); // 개체
	this.marginX = x ? x : 0;					// x축 여백
	this.marginY = y ? y : 0;					// y축 여백
	this.pro = pro ? pro : 10;					// 개체이동속도
	this.cycle = cycle ? cycle : 10;			// 재귀호출간격
	this.pattern = pattern ? pattern : 'y';	// 움직임 { x | y | xy }
	this.floatingObj.style.position = "absolute";
	this.initialize();
}
// 플로팅 동작
FLOATING.prototype.initialize = function () {
	var classObj = this;
	var floatingObjLeft = this.floatingObj.style.left ? parseInt(this.floatingObj.style.left,10) : this.floatingObj.offsetLeft;
	var floatingObjTop = this.floatingObj.style.top ? parseInt(this.floatingObj.style.top,10) : this.floatingObj.offsetTop;
	var docLeft = document.body.scrollLeft + this.marginX;
	var docTop = document.body.scrollTop>this.marginY ? document.body.scrollTop : this.marginY;

	var moveX = Math.ceil(Math.abs(floatingObjLeft - docLeft) / this.pro);
	var moveY = Math.ceil(Math.abs(floatingObjTop - docTop) / this.pro);

	if(this.pattern.indexOf('x')!=-1) this.floatingObj.style.left = floatingObjLeft < docLeft ? floatingObjLeft + moveX + "px" : floatingObjLeft - moveX + "px";
	if(this.pattern.indexOf('y')!=-1) this.floatingObj.style.top = floatingObjTop < docTop ? floatingObjTop + moveY + "px" : floatingObjTop - moveY + "px";
	
	setTimeout(function(){classObj.initialize()}, classObj.cycle); // 재귀호출
}

//##################################################################################
//## 랭크업 슬라이더 - 2008.12.18
//##################################################################################
var RANKUP_SLIDER = Class.create({
	initialize: function(el, title, show) {
		this.show = show;
		this.slider_body = $(el).cleanWhitespace();
		if(title!=undefined && rankup_menu.menu_infos.category) {
			try { $(title).innerHTML = rankup_menu.menu_items[rankup_menu.menu_infos.category].text }
			catch(e) {
				var classObj = this;
				setTimeout(function() { classObj.initialize(el, title) }, 0); // 렉 발생시 빈번한 호출로 memory overflow 가 일어나는 현상을 방지하기 위해 약간의 딜레이를 줌
			}
		}
		if(this.slider_body.firstChild==null) $(title.replace(/_title/, '')).hide();
		else if(this.show==true) {
			// 화제의 포토 초기화
			this.show_window(null, this.slider_body.firstChild);
			this.append_event();
		}
	},
	direction: function(mode) {
		var items = {first: this.slider_body.firstChild, last: this.slider_body.lastChild};
		switch(mode) {
			case 1: /* 윗쪽 */
			case 4: /* 왼쪽 */
				new Insertion.Before(items.first, items.last.cloneNode(true));
				this.slider_body.removeChild(items.last);
				break;
			case 2: /* 오른쪽 */
			case 3: /* 아랫쪽 */
				new Insertion.After(items.last, items.first.cloneNode(true));
				this.slider_body.removeChild(items.first);
				break;
		}
		// 클릭 이벤트 리셋
		if(this.show==true) this.append_event();
	},
	show_window: function(event, obj) {
		var obj = obj==undefined ? Event.element(event) : obj;
		while(!obj.tagName.match(/li/i)) obj = obj.parentNode;
		var item_info = {
			no: obj.getAttribute('no'),				title: obj.getAttribute('title'),
			width: obj.getAttribute('width'),		height: obj.getAttribute('height'),
			section: obj.getAttribute('section'),	category: obj.getAttribute('category'),
			item: obj.getAttribute('item'),			photo: obj.getElementsByTagName('img')[0].src
		}
		with(item_info) {
			var params = $H({section:section, category:category, item:item, no:no});
			var link = domain+"news/view.html?"+params.toQueryString();
			var img = photo.match(/\/no\_/i) ? "<img src='"+domain+"images/no_225_150.gif' width='225' height='150' border='0'>" : "<img src='"+photo+"' width='"+width+"' height='"+height+"' border='0'>";
			$('photo_preview').update("<a href='"+link+"'>"+img+"</a>");
			$('photo_title').update("<a href='"+link+"'>"+title+"</a>");
		}
	},
	append_event: function() {
		var classObj = this;
		$$('#'+this.slider_body.id+' li').each(function(li) {
			Event.stopObserving(li, 'click', classObj.show_window); // 이벤트 리스너 제거
			Event.observe(li, 'click', classObj.show_window); // 이벤트 리스너 설정
		});
	}
});

//##################################################################################
//##  글자 크기 제어 - 2009.01.14
//##################################################################################
var font_size = {
	size: {def:9, min:8, max:20},
	plus: function(el) {
		var obj = $(el);
		var fsize = obj.style.fontSize ? parseInt(obj.style.fontSize, 10) : this.size.def;
		if(fsize < this.size.max) obj.setStyle({ 'fontSize': (fsize+1)+'pt', 'lineHeight': '180%' });
	},
	minus: function(el) {
		var obj = $(el);
		var fsize = obj.style.fontSize ? parseInt(obj.style.fontSize, 10) : this.size.def;
		if(fsize > this.size.min) obj.setStyle({ 'fontSize': (fsize-1)+'pt', 'lineHeight': '180%' });
	}
}

//##################################################################################
//## 달력 클래스 정의 - 2008.09.12
//##################################################################################
var RANKUP_CALENDAR = Class.create({
	initialize: function() {
		this.browser = (/MSIE/.test(navigator.userAgent)) ? "IE" : "GEKO";
		this.toDay = new Date();
		this.selYear = this.browser=="IE" ? this.toDay.getYear() : this.toDay.getYear()+1900;
		this.selMonth = this.toDay.getMonth();
		this.selDay = this.toDay.getDate();
		this.lastDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		this.calendarBody = "calendarBody";
		this.selComponent = null;
		this.compYear = null;
		this.compMonth = null;
		this.compDay = null;
		this.drawStatus = false;
		this.minDate = null; // 하한선
		this.maxDate = null; // 상한선
	},
	// 달력 범위 설정
	get_calendar_range: function(mode) {
		var calendar_options = '';
		switch(mode) {
			case "year":
				this.toDay = new Date();
				var now_year = this.browser=="IE" ? this.toDay.getYear() : this.toDay.getYear()+1900;
				if(this.minDate==null) {
					var min_year = parseInt(now_year, 10)-1;
					this.minDate = new String(min_year)+"-01-01";
				}
				else {
					var date_infos = this.minDate.split("-");
					var min_year = date_infos[0];
				}
				if(this.maxDate==null) {
					var max_year = parseInt(now_year, 10)+1;
					this.maxDate = new String(max_year)+"-12-31";
				}
				else {
					var date_infos = this.maxDate.split("-");
					var max_year = date_infos[0];
				}
				for(var year=max_year; year>=min_year; year--) calendar_options += "<option value='"+year+"'>"+year+"년</option>";
				break;
			case "month":
				for(var month=1; month<=12; month++) {
					var num = new String(month);
					num = num.length==1 ? 0+num : num;
					calendar_options += "<option value='"+month+"'>"+num+"월</option>";
				}
				break;
		}
		return calendar_options;
	},
	// 달력 그리기
	draw_calendar: function(el, base) {
		var obj = $('calendar_div');
		this.selComponent = el;
		this.minDate = el.getAttribute('mindate');
		this.maxDate = el.getAttribute('maxdate');
		if(this.maxDate!=null && base==undefined && el.value=='') base = {'value':this.maxDate};

		if(obj!=null) rankup_calendar.remove_calendar();
		this.drawStatus = false;

		var new_div = document.createElement('div');
		new_div.style.position = "absolute";
		new_div.id = "calendar_div"; // 고정
		new_div.style.zIndex = 1;
		var width = (this.browser=="IE") ? 160 : 148;
		new_div.innerHTML = "\
		<div style='position:absolute;width:160px;height:179px;z-index:80;left:0px;top:0px;'><iframe src='about:blank' style='width:100%;height:100%;' frameborder='0'></iframe></div>\
		<div style='width:"+width+"px;z-index:100;position:relative;border:#cdcdcd 1px solid;top:0px;left:0px;padding:4px;background-color:#f8f8f8;'>\
		<table cellpadding='0' cellspacing='0' border='0' style='margin-bottom:4px;'>\
		<tr>\
			<td style='padding-right:3px;'><select style='width:64px' onChange=\"rankup_calendar.change_date_II(this)\">"+this.get_calendar_range('year')+"</select></td>\
			<td style='padding-right:3px;'><select style='width:52px' onChange=\"rankup_calendar.change_date_II(this)\">"+this.get_calendar_range('month')+"</select></td>\
			<td align='right'><a onClick='rankup_calendar.remove_calendar()'><img src='"+domain+"images/btn_close_s.gif' align='absmiddle'></a></td>\
		</tr>\
		</table>\
		<span style='display:none'><button onClick=\"rankup_calendar.change_date('-1 year')\" style=\"background:url('"+domain+"images/btn_prev.gif');width:13px;height:16px;border:0;\"></button> <input type='text' size='3' readOnly style='letter-spacing:0px;background-color:#f8f8f8;'> <button onClick=\"rankup_calendar.change_date('1 year')\" style=\"background:url('"+domain+"images/btn_next.gif');width:13px;height:16px;border:0;\"></button>\
		&nbsp;&nbsp;<button onClick=\"rankup_calendar.change_date('-1 month')\" style=\"background:url('"+domain+"images/btn_prev.gif');width:13px;height:16px;border:0;\"></button> <input type='text' size='1' readOnly style='background-color:#f8f8f8;'> <button onClick=\"rankup_calendar.change_date('1 month')\" style=\"background:url('"+domain+"images/btn_next.gif');width:13px;height:16px;border:0;\"></button></span>\
		<table cellpadding='0' cellspacing='1' bgcolor='#C9C9C9' border='0' style='margin-top:3px;' width='100%'>\
		<tr bgcolor='#f4f8fb' align='center'>\
			<td><font color='red'>일</font></td>\
			<td>월</td>\
			<td>화</td>\
			<td>수</td>\
			<td>목</td>\
			<td>금</td>\
			<td><font color='#3366cc'>토</font></td>\
		</tr>\
		<tbody bgcolor='white' align='center' id='"+this.calendarBody+"'>\
		</tbody>\
		</table>\
		</div>";
		this.selComponent.parentNode.appendChild(new_div);
		(base==null||base==undefined) ? this.change_date(el.value) : this.change_date(base.value);
		if(this.browser=="IE") {
			new_div.style.marginLeft = -(this.selComponent.offsetWidth);
			new_div.style.marginTop = this.selComponent.offsetHeight+4;
		}
		else new_div.style.marginTop = 4;
		/*
		}
		// 재활용
		else {
			obj.style.display = "block";
			this.selComponent.parentNode.appendChild(obj);
			(base==null||base==undefined) ? this.change_date(el.value) : this.change_date(base.value);
		}*/
	},
	change_date_II: function(el) {
		var info_selects = $('calendar_div').getElementsByTagName('select');
		this.change_date(info_selects[0].value+'-'+info_selects[1].value+'-'+this.selDay);
	},
	change_date: function(date) { // date { 1 year | -1 year | -1 month | 1 month }
		if(date=='') {
			this.toDay = new Date();
			this.selYear = this.browser=="IE" ? this.toDay.getYear() : this.toDay.getYear()+1900;
			this.selMonth = this.toDay.getMonth();
			this.selDay = this.toDay.getDate();
			this.compYear = this.compMonth = this.compDay = '';
		}
		else {
			switch(date) {
				case "-1 year": this.selYear -= 1; break;
				case "1 year": this.selYear += 1; break;
				case "-1 month":
					if(this.selMonth!=0) this.selMonth -= 1;
					else { // 0 : 1월
						this.selYear -= 1;
						this.selMonth = 11;
					}
					break;
				case "1 month":
					if(this.selMonth!=11) this.selMonth += 1;
					else { // 11 : 12월
						this.selYear += 1;
						this.selMonth = 0;
					}
					break;
				default: // 날짜값을 받은 경우 : 2008-09-12
					var date_infos = date.split('-');
					with(Math) {
						this.compYear = floor(date_infos[0]);
						this.compMonth = floor(date_infos[1])-1;
						this.compDay = floor(date_infos[2]);
					}
					if(this.drawStatus===true && this.compYear==this.selYear && this.compMonth==this.selMonth && this.compDay==this.selDay) return true;
					this.selYear = this.compYear;
					this.selMonth = this.compMonth;
					this.selDay = this.compDay;
			}
		}
		var calendar_body = $(this.calendarBody);
		this.toDay = new Date(this.selYear, this.selMonth, this.selDay);
		this.lastDays[1] = (this.selYear%4)==0 && ((this.selYear%100)!=0 || (this.selYear%400)==0) ? 29 : 28;
		var info_inputs = $('calendar_div').getElementsByTagName('input');
		var info_selects = $('calendar_div').getElementsByTagName('select');
		info_inputs[0].value = info_selects[0].value = this.selYear;
		info_inputs[1].value = info_selects[1].value = this.selMonth+1;

		calendar_body.update(); // 초기화

		var first_day_cell = 0;
		var first_cell = ((this.toDay.getDay()+7)-(this.selDay-1)%7)%7;
		for(var row=0, day=1; row<6; row++) {
			var new_row = calendar_body.insertRow(calendar_body.rows.length);
			for(var cell=0; cell<7; cell++) {
				if(cell == first_cell) first_day_cell += 1;
				var new_cell = new_row.insertCell(cell);
				switch(cell) {
					case 0: new_cell.style.color = "#ff0000"; break;
					case 6: new_cell.style.color = "#3366cc"; break;
				}
				if(first_day_cell>=1 && day<=this.lastDays[this.selMonth]) {
					new_cell.innerHTML = day;
					new_cell.style.cursor = "pointer";
					if(day++==this.compDay && this.compMonth==this.selMonth && this.compYear==this.selYear) {
						new_cell.className = "selectCell";
						new_cell.setAttribute("selected", "true");
						this.selCell = new_cell;
					}
					else new_cell.className = "normalCell";
					//Event.observe(new_cell, "mouseover", this.toggle_className);
					//Event.observe(new_cell, "mouseout", this.toggle_className);
					//Event.observe(new_cell, "click", this.apply_date);
					if(this.browser=="IE") new_cell.attachEvent("onclick", this.apply_date);
					else new_cell.addEventListener("click", this.apply_date, true);
				}
				else {
					new_cell.innerHTML = '';
					new_cell.style.backgroundColor = "#F5F5F5";
				}
				new_cell.height = '20px';
				new_row.appendChild(new_cell);
			}
		}
		this.drawStatus = calendar_body.rows.length==6;
	},
	// 날짜 변경 - 단축키
	set_date: function(mode, dest, base) {
		if(base==undefined || base=='') {
			// 오늘을 기준으로 날짜 계산
			var toDay = new Date();
			var baseYear = this.browser=="IE" ? toDay.getYear() : toDay.getYear()+1900;
			var baseMonth = toDay.getMonth();
			var baseDay = toDay.getDate();
			var base_date = baseYear+"-"+baseMonth+"-"+baseDay;
		}
		else {
			var base_date = base.value;
		}
		var classObj = this;
		var url = domain+"Libs/_js/calculate_date.ajax.php?base_date="+base_date+"&mode="+mode+"&garbage="+Math.random();
		var myRequest = new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				if(!transport.responseText.match(null)) {
					var dest_date = transport.responseXML.getElementsByTagName('resultData')[0].firstChild.nodeValue;
					if(in_array(mode,['today','yesterday'])) dest.value = base.value = dest_date;
					else dest.value = dest_date;
					if(classObj.selComponent===dest) classObj.change_date(dest.value);
				}
			},
			onComplete: function() {myRequest=null}
		});
	},
	// 분류 설정시 아이템 오버/아웃시에 사용
	toggle_className: function(event) {
		this.className = event.type!="mouseover" ? this.getAttribute("selected")!=null ? "selectCell" : "normalCell" : this.getAttribute("selected")!=null ? "shoverCell" : "hoverCell";
	},
	// 달력박스 감추기
	hidden_calendar: function() {
		var obj = $('calendar_div');
		if(obj!=null) obj.style.display = "none";
	},
	// 달력개체 제거
	remove_calendar: function() {
		var obj = $('calendar_div');
		if(obj!=null) obj.parentNode.removeChild(obj);
	},
	// 선택한 날짜값 반환
	apply_date: function(event) {
		rankup_calendar.selMonth += 1;
		var el = Event.element(event);
		var year = rankup_calendar.selYear;
		var month = new String(rankup_calendar.selMonth);
		var day = el.innerHTML;
		if(month.length==1) month = '0'+month;
		if(day.length==1) day = '0'+day;
		var selDate = year+"-"+month+"-"+day;
		var url = domain+"Libs/_js/calculate_date.ajax.php?mode=check_date&min_date="+rankup_calendar.minDate+"&max_date="+rankup_calendar.maxDate+"&sel_date="+selDate+"&garbage="+Math.random();
		var myRequest = new Ajax.Request(url, {
			method: 'get',
			onSuccess: function(transport) {
				if(!transport.responseText.match(null)) eval(transport.responseXML.getElementsByTagName('resultData')[0].firstChild.nodeValue);
			}
		});
	}
});
var rankup_calendar = new RANKUP_CALENDAR;

/*
## 랭크업 달력 클래스 사용 방법 ##
☞ 스타일 : .calendar {width:80px;text-align:center;font-family:verdana;letter-spacing:-2px;font-weight:bolder;cursor:pointer;}
☞ 사용법 : <span style='float:left'><input type="text" name="sdate" readOnly value="2008-09-12" onClick="rankup_calendar.draw_calendar(this)" class="calendar"></span>
*/

//##################################################################################
//## 랭크업 CSS 버튼 생성 - 2008.12.18 // 2009.02.03 fixed
//##################################################################################
var rankup_css_button = {
	initialize: function() {
		if(!document.body.id) document.body.id = '_tmp_body_';
		var buttons = $(document.body.id).getElementsBySelector('a[class="css_button"]');
		buttons.each(function(button) { rankup_css_button.formalize(button) });
	},
	apply: function(el) {
		var buttons = $(el).getElementsBySelector('a[class="css_button"]');
		buttons.each(function(button) { rankup_css_button.formalize(button) });
	},
	formalize: function(button) {
		var shape = button.getAttribute('shape');
		var shapes = shape==null ? [] : shape.split(' ');
		if(!in_array(shapes, ['normal', 'small'])) shapes.push('normal');
		for(var i=0; i<shapes.length; i++) {
			if(!shapes[i]) continue;
			var class_name = 'css_'+shapes[i]+'_button';
			if(button.id) $(button.id).addClassName(class_name);
			else { button.id = '_tmp_button_'; $(button.id).addClassName(class_name); button.removeAttribute('id'); }
		}
		//if(!button.href) button.href = 'javascript:void(0)';
		button.onmouseover = function() {window.status=''; return true}
		button.update('<span>'+button.innerHTML+'</span>');
	}
}

/*
## 랭크업 CSS 버튼 사용 방법 ##
☞ 스타일 : 
	a.css_normal_button{padding-left:8px;background:url('./images/btn1_bg.gif');text-decoration:none;font:12px 굴림;color:#777777;letter-spacing:0px;line-height:27px;display:inline-block;}
	a.css_normal_button:hover{background: url('./images/btn1_bg.gif') 0 -27px;color:#000000;}
	a.css_normal_button span{padding-right:8px;background:url('./images/btn1_bg.gif') 100% 0;cursor:pointer;padding-top:7px;padding-bottom:7px;line-height:27px;}
	a.css_normal_button:hover span{background:url('./images/btn1_bg.gif') 100% -27px;}
☞ 사용법 : <a class="css_button">랭크업CSS버튼</a>
*/
