try {
	document.execCommand("BackgroundImageCache",false,true);
} catch(ignored) {}

function $(s) { return document.getElementById(s) };
function $C(node) {return document.createElement(node)};

/* bind */
function $A(iterable)
{
	if (!iterable) return [];
	var results = [];
	for (var i = 0, length = iterable.length; i < length; i++)
	  results.push(iterable[i]);
	return results;
}

Function.prototype.bind = function()
{
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	}
}

Function.prototype.bindEvent = function()
{
	var __method = this, args = $A(arguments), object = args.shift();
	return function(event) {
		return __method.apply(object, [event || window.event].concat(args));
	}
}
//event add
function AddEvent(element, name, func)
{
	if (element.addEventListener) {
		element.addEventListener(name, func, false);
	}
	else if (element.attachEvent) {
		element.attachEvent('on' + name, func);
	}
}
function RemoveEvent(element, name, func)
{
	if (element.addEventListener) {
		element.removeEventListener(name, func, false);
	}
	else if (element.attachEvent) {
		element.detachEvent('on' + name, func);
	}
}

function StopEvent(event) {
	var e=event || window.event;
	if(e.preventDefault) {e.preventDefault(); e.stopPropagation(); }
	else {e.returnValue = false; e.cancelBubble = true;}
};

function addClass(obj,css) {
	obj.className += (obj.className != "")? " "+css : css;
}
function removeClass(obj,css) {
	var cssArr = obj.className.split(" ");
	for(var i=0,cnt=cssArr.length;i<cnt;++i) {
		if(cssArr[i]==css) break;
	}
	if(i<cnt) {
    	cssArr.splice(i,1);
    	obj.className = cssArr.join(" ");
	}
}


/* param : idSet = [[tabId,bodyId],[tabId,bodyId],...] */
Tab = function(idSet,eType,onCss,defIdx,addLinkUrl) {
	this.cnt = idSet.length;
	this.eType = eType;
	this.onCss = onCss;
	this.tab = [];
	this.tabbody = [];
	for(var i=0;i<this.cnt;++i)
	{
		var tab = document.getElementById(idSet[i][0]);
		var tabbody = document.getElementById(idSet[i][1]);
		tab.oldCss = tab.className;
		tabbody.oldCss = tabbody.className;
		this.tab.push(tab);
		this.tabbody.push(tabbody);
		if(addLinkUrl && addLinkUrl[i])tab.onclick = this.addLink.bind(this,i,addLinkUrl[i]); //ie에서는 대입법으로 한게 가장 먼저 실행됨, ff에서는 순서대로 실행됨.
		AddEvent(tab,eType,this.on.bind(this,i));
	}
	(defIdx) ? this.on(defIdx-1) : this.on(0);
}
Tab.prototype = {
	on:function(n) {
		if(this.curIdx == n) return;
		for (var i = 0; i < this.cnt; ++i) {
			if (i == n) {
				this.tab[i].className = (this.tab[i].oldCss) ? this.tab[i].oldCss + " " + this.onCss : this.onCss;
				this.tabbody[i].className = (this.tabbody[i].oldCss) ? this.tabbody[i].oldCss + " " + this.onCss : this.onCss
			}
			else {
				this.tab[i].className = this.tab[i].oldCss;
				this.tabbody[i].className = this.tabbody[i].oldCss;
			}
		}
		this.curIdx = n;
	},
	addLink:function(n,url) {
		if(this.curIdx == n) GoPage(url);
	}
}

/*	listId : ul id,
	maxCount : 1page에 보여지는 li개수
	prevBtId, nextBtId : button id
	listTag : default는 li임. 다른 tag를 list형식으로 사용할 경우 넣을 수 있겠음.
*/
Paging = function(listId,maxCount,prevBtId,nextBtId,listTag) {
	this.el = document.getElementById(listId);
	this.tag = (listTag) ? listTag : 'li';
	this.maxCount = maxCount;
	this.prevBt = (prevBtId) ? document.getElementById(prevBtId) : null;
	this.nextBt = (nextBtId) ? document.getElementById(nextBtId) : null;
	if(this.prevBt) AddEvent(this.prevBt,"click",this.prev.bind(this));
	if(this.nextBt) AddEvent(this.nextBt,"click",this.next.bind(this));
	this.init();

}

Paging.prototype = {
	init : function() {
		this.list = this.el.getElementsByTagName(this.tag);
		this.totalCount = this.list.length;
		this.totalPage = Math.ceil(this.totalCount/this.maxCount);
		this.needPaging = (this.totalCount > this.maxCount);
		if(!this.needPaging) {
			if(this.prevBt) this.prevBt.style.display = "none";
			if(this.nextBt) this.nextBt.style.display = "none";
		}
		else {
			if(this.prevBt) this.prevBt.style.display = "";
			if(this.nextBt) this.nextBt.style.display = "";
		}
		this.curPage = 1;
		this.exec(1);
	},
	prev : function() {
		this.exec(--this.curPage);
	},
	next : function() {
		this.exec(++this.curPage);
	},
	exec : function(n) {
		if(n<=0)  this.curPage = this.totalPage;
		else if(n>this.totalPage)  this.curPage = 1;

		var min = this.maxCount*(this.curPage-1), max = this.maxCount*this.curPage;
		for(var i=0;i<this.totalCount;++i) {
			if(min <= i && i < max) this.list[i].style.display = "block";
			else this.list[i].style.display = "none";
		}
	}
}

function DaumFlash(src,fv,width,height,div,id){
	var obj = new Object();
	obj.type = 'application/x-shockwave-flash';
	obj.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
	obj.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
	obj.width = width;
	obj.height = height;
	
	if (id != undefined){
		obj.id=id;
		obj.name=id;
	}

	var param = [		
		['movie',src],
		['src',src],
		['quality','high'],
		['wmode','transparent'],//
		['allowScriptAccess','always'],
		['bgcolor','#FFFFFF'],
		['showLiveConnect','true'],
		['FlashVars',fv]
	];
	obj.param = param;
	daumActiveX(obj,div);
}

function daumActiveX(obj,div){
	// generate html code
	// for ie obejct
	var html='<object ';
	if (!obj.id && !obj.name){
		var r=Math.round(Math.random()*100);
		//html += 'id="daumActiveXObject'+r+'" name="daumActiveXObject'+r+'" ';
		html += 'id="daumActiveXObject'+r+'"" ';
	} else {
		if (obj.id) html += 'id="'+obj.id+'" ';
		else html += 'id="'+obj.name+'" ';
		/*if (obj.name) html += 'name="'+obj.name+'" ';
		else html += 'name="'+obj.id+'" ';
		*/
	}
	if (obj.type) html += 'type="'+obj.type+'" ';
	if (obj.classid) html += 'classid="'+obj.classid+'" ';
	if (obj.width) html += 'width="'+obj.width+'" ';
	if (obj.height) html += 'height="'+obj.height+'" ';
	if (obj.codebase) html += 'codebase="'+obj.codebase+'" ';
	// append events
	for (var i in obj.events){
		if (obj.events[i]){
			html += obj.events[i][0]+'="'+obj.events[i][1]+'" ';
		}
	}
	// end of object tag
	html += '>\n';
	// append params
	for (var i in obj.param){
		html += '<param name="'+obj.param[i][0]+'" value="'+obj.param[i][1]+'"/>\n';
	}

	// for ns embed
	html += '<embed ';
	if (!obj.id && !obj.name){
		var r=Math.round(Math.random()*100);
		//html += 'id="daumActiveXObject'+r+'" name="daumActiveXObject'+r+'" ';
		html += 'name="daumActiveXObject'+r+'" ';
	} else {
		//if (obj.id) html += 'id="'+obj.id+'" ';
		if (obj.name) html += 'name="'+obj.name+'" ';
	}
	if (obj.type) html += 'type="'+obj.type+'" ';
	if (obj.width) html += 'width="'+obj.width+'" ';
	if (obj.height) html += 'height="'+obj.height+'" ';
	// append params
	for (var i in obj.param){
		if (obj.param[i]){
			if (obj.param[i][0]=='movie' || obj.param[i][0]=='src'){
				var _src=obj.param[i][1];
			}
			html += obj.param[i][0]+'="'+obj.param[i][1]+'" ';
		}
	}
	html += '></embed>\n';
	html += '</object>';

	var isIE=(document.all)?true:false;
	if (isIE){
		document.getElementById(div).innerHTML=html;
	} else if (obj.type=='application/x-shockwave-flash' || obj.classid.toLowerCase()=='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'){
		// ie activex flash
		document.getElementById(div).innerHTML=html;
	} else if (navigator.platform.indexOf('Win')>=0 && obj.classid.toLowerCase()=='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95'){
		// Windows Media Player - windows platform
		document.getElementById(div).innerHTML=html;
	}
}


/**
 * daumFlashChart
 *
 * src = flash url
 * width = size (width)
 * height  = size (height)
 * div = object id
 * value = parameter
 */
function daumFlashChart(src,width,height,div,value){
	var obj = new Object();
	obj.type = 'application/x-shockwave-flash';
	obj.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
	obj.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
	obj.wmode = 'transparent';
	obj.width = width;
	obj.height = height;

	var param = [
		['movie',src],
		['src',src],
		['quality','high'],
		['wmode','transparent'],
		['bgcolor','#FFFFFF'],
		['flashvars',value],
	];
	obj.param = param;
	daumActiveX(obj,div);
}

function tvpotSWF(src,w,h){
	width = (w)? w : 502;
	height = (h)? h : 438;

	src=src.replace("flvPlayer","mloader");
	src+='&stype=m';
	var tvpot = '<object type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" align="middle" id="V000165992" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">';
	tvpot += '<param name="movie" value="'+src+'"/>';
	tvpot += '<param name="allowScriptAccess" value="always"/>';
	tvpot += '<param name="allowFullScreen" value="true"/>';
	tvpot += '<param name="loop" value="false"/>';
	tvpot += '<param name="menu" value="false"/>';
	tvpot += '<param name="wmode" value="transparent"/>';
	tvpot += '<param name="swLiveConnect" value="true"/>';
	tvpot += '<embed src="'+src+'" width="'+width+'" height="'+height+'" loop="false" menu="false" swLiveConnect="true" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" allowFullScreen="true" nowow="true"/>';
	tvpot += '</object>';
	document.write(tvpot);	
};


String.prototype.trim = function() 
{ 
	return this.replace(/(^\s*)|(\s*$)/gi, ""); 
} 

Array.prototype.sortMulti = function(sortIdx, asc)
{
	var temp = [];		
	for(var i=0; i<this.length; i++) {
		var newIdx = -1;			
		for(var j=temp.length-1; j>=0; --j) {
			if(this[i][sortIdx] < temp[j][sortIdx]) newIdx = j;
		}
		if(newIdx < 0 ) temp.push(this[i]);
		else temp.splice(newIdx,0,this[i]);
		
	}    	
	if(!asc) temp.reverse();
	return temp;
}

//style set/get
function getStyle(obj,styleText)
{
	var temp = styleText.split("-");
	var templen = temp.length;
	if(templen > 1) {
		styleText = 	temp[0];
		for(var n=1; n<templen; ++n) {
			styleText += temp[n].substr(0,1).toUpperCase() + temp[n].substr(1);
		}
	}

	if(obj.currentStyle)
		var css = obj.currentStyle;
	else
		var css = document.defaultView.getComputedStyle(obj, null);
	value = css ? css[styleText] : null;
	return (value == null || value == undefined) ? "" : value;
}


function setStyle(obj,styles)
{
	var styleArr = styles.split(";");
	var styleCnt = styleArr.length;
	for(var i=0; i<styleCnt; ++i) {
		var styleItem = styleArr[i].split(":");
		styleItem[1] = styleArr[i].substr(styleItem[0].length+1);
		styleItem[0] = styleItem[0].trim();
		switch(styleItem[0]) {
			case 'float' :
				if(obj.style.styleFloat != undefined) 
					obj.style.styleFloat = styleItem[1];
				else 
					obj.style.cssFloat = styleItem[1];
				break;
			default :
				if(styleItem[0].length>0 && styleItem[1].length>0) {
					var temp = styleItem[0].split("-");
					var templen = temp.length;
					if(templen > 1) {
						styleItem[0] = 	temp[0];
						for(var n=1; n<templen; ++n) {
							styleItem[0] += temp[n].substr(0,1).toUpperCase() + temp[n].substr(1);
						}
					}
					obj.style[styleItem[0]] = styleItem[1];	
				}
				break;
		}
	}
}


Object.extend=function(a, b){
  for (var property in b) a[property] = b[property];
  return a;
};

var Ajax = function(options) {
	this.options={
		method:'GET',
		param:'',
		onComplete:null,
		onError:null,
		asynchronous: true,
		contentType: 'application/x-www-form-urlencoded',
		encoding:'UTF-8'
	}
	Object.extend(this.options, options);
};

Ajax.prototype={
	getReq:function(){
		var req=null;
		try { req = new XMLHttpRequest(); }
		catch(e)
		{
			try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e)
			{
				try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) { }
			}
		}
		return req;
	},
	send:function(){
		this.req = this.getReq();	
		var op=this.options;
		var url=op.url;
		var param=op.param;
		var method=op.method.toUpperCase();
		if(method=='GET' && param) url=url+"?"+param;
		this.req.open(method, url, op.asynchronous);
		this.req.setRequestHeader('Content-Type', op.contentType+';charset='+op.encoding);
		
		var self = this;
		this.req.onreadystatechange = function() { self.onStateChange.call(self) }
		this.req.send(method=='POST'?param:null);
	},
	onStateChange: function() {
		if(this.req.readyState==4)
		{
			if(this.req.status=="200") this.options.onComplete(this.req);
			else
			{
				if(this.options.onError) this.options.onError(this.req);
			}				
		}
	}
};

//소숫점 잘라주기
function FormatFloat(num,len)
{
	var formatNum = num.toString();
	var dotPos = formatNum.indexOf(".");
	if(dotPos>0) {
		if(formatNum.length - formatNum.indexOf(".") > len) {
			formatNum = formatNum.substr(0,dotPos+len+1);
		} 
		else {
			while(formatNum.length - (len+1) != formatNum.indexOf(".")) formatNum = formatNum.concat("0");
		}
	}
	else {
		formatNum = formatNum.concat(".");
		while(--len>=0) formatNum = formatNum.concat("0");
	}
	return formatNum;
}


/* Cookie */
function getCookie(s){
	var tmp=document.cookie.split('; ');
	for (var i=0; i<tmp.length;i++){
		var c_name = tmp[i].split('=');
		if (c_name[0]==s) return c_name[1];
	}
	return false;
}

function setCookie(_name,_value,_day,_domain){
	var expireDate = new Date(Number(new Date())+Number(_day)*86400000);
	var ckText = _name+'='+_value+';expires='+expireDate.toGMTString()+';path=/;';
	if(_domain) ckText += "domain="+_domain+";";
	document.cookie =ckText;
}

function getTarget(event) {
	if(!event) event = window.event;	
	return (window.event) ? window.event.srcElement : event.target 
}

//popup
function openPop(url,winnm,width,height,etc_options)
{
	var options = "width="+width+",height="+height;
	if(etc_options) options += ","+etc_options;
	window.open(url,winnm,options);
}

function CenterPop(url,winnm,width,height,etc_options)
{
	var OpenerLeft = (window.screenLeft != undefined) ? window.screenLeft : window.screenX;
	var OpenerTop = (window.screenTop != undefined) ? window.screenTop : window.screenY;
	var brWidth = (window.outerWidth) ? window.outerWidth : document.documentElement.clientWidth;
	var popLeft = OpenerLeft + parseInt((brWidth-width)/2);
	var popTop = parseInt((window.screen.availHeight-height)/2);
	openPop(url,winnm,width,height,'left='+popLeft+',top='+popTop+','+etc_options)
}

function centerPop(url,winnm,width,height,etc_options)
{
	var OpenerLeft = (window.screenLeft != undefined) ? window.screenLeft : window.screenX;
	var OpenerTop = (window.screenTop != undefined) ? window.screenTop : window.screenY;
	var brWidth = (window.outerWidth) ? window.outerWidth : document.documentElement.clientWidth;
	var popLeft = OpenerLeft + parseInt((brWidth-width)/2);
	var popTop = parseInt((window.screen.availHeight-height)/2);
	openPop(url,winnm,width,height,'left='+popLeft+',top='+popTop+','+etc_options)
}

//link
function GoPage(url,target)
{
	if(target) target.location.href=url;
	else window.location.href=url;
}

function GoPageNew(url)
{
	window.open(url,"new");
}

/* list over/out */
function highlight(obj, isover, color)
{
	if(color == undefined) color = "#EFF1FF";
	if(!obj.oldColor) obj.oldColor = getStyle(obj,"background-color");
	obj.style.backgroundColor = (isover) ? color : obj.oldColor;
}

/* javascript call */
function callsrc(id,url,type) {
	var obj = $(id);
	var parent;
	if(obj) {
		parent = obj.parentNode;
		parent.removeChild(obj);
	}
	else {
		parent = document.getElementsByTagName('head')[0];
	}
	
	obj = $C('script');
	var cashTime = new Date() - Date.UTC(2008,5,0);
	if(type && type == "day") cashTime = Math.floor(cashTime/86400000);
	
	var param = (url.indexOf('?')<0) ? '?':'&';
	param += "d="+ cashTime;
 
	obj.src = url + param;
	obj.id = id;
	obj.type = "text/javascript";
	parent.appendChild(obj);
}

function rightAd(type) {
	var rand = Math.random().toString(); 
	var ordval = rand.substring(2,rand.length); 
	var clintAgent = navigator.userAgent;
	switch(type) {
		case 250 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/ad/adview?secid=00867\" width=250 height=250 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=finance_AMS></iframe>");
			break;
		case 649 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00884&type=cpm&tag=iframe&mkvid=1&ord=" + ordval + "\" width=649 height=38 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=finance_AMS></iframe>");
			break;
		case 25052 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00885&type=cpm&tag=iframe&mkvid=1&ord=" + ordval + "\" width=250 height=52 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=finance_AMS></iframe>");
			break;
		case 25041 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00886&type=cpm&tag=iframe&mkvid=1&ord=" + ordval + "\" width=250 height=41 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=finance_AMS></iframe>");
			break;
		case 6090 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/ad/adview?secid=00890\" width=60 height=90 border=0 frameborder=0 scrolling=no id=stock_AMS></iframe>");
			break;
		default :
			document.writeln("<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00883&type=cpm&tag=iframe&mkvid=1&ord=" + ordval + "\" width=180 height=180 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=stock_AMS></iframe>");
		break;
	}		
}

/* iframe onload="iframeResizing(this,'id')" */
function iframeResizing(ifrm,ifrmContentId) {
	var doc = ifrm.contentDocument;
	if(!doc) doc = ifrm.contentWindow.document;
	ifrm.height = doc.getElementById(ifrmContentId).offsetHeight+3;
}

function parentTop() {
	parent.scrollTo(0,0);
}