try {(navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) && document.execCommand("BackgroundImageCache",false,true);} catch(e) {}

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(" ");
	}
}

var tabClickAction = function(tabClickId) {
	try {
		var frameId = tabClickId + "tabFrame";

		if (tabClickId == "topMyTab1" || tabClickId == "newsTab1" || tabClickId == "price5StepTab" || tabClickId == "myTab1" ) {
			if(document.getElementById(frameId)) {
				document.getElementById(frameId).src = "http://stock.daum.net/clickdummy/" + tabClickId;
			}else {
				var bodyObj = document.getElementsByTagName('body')[0];
				var frameObj = document.createElement("iframe");
				frameObj.id = frameId; 
				frameObj.src = "";
				frameObj.width = "0px";
				frameObj.height = "0px";
				frameObj.frameborder = "0";
				frameObj.className = "tabClickFrame";
				bodyObj.appendChild(frameObj);
				document.getElementById(frameId).src = "http://stock.daum.net/clickdummy/" + tabClickId;
				
				bodyObj = null;
				frameObj = null;
			}
		}
	}catch(e){
		
	}finally {
		frameId = null;
	}
}

/* param : idSet = [[tabId,bodyId],[tabId,bodyId],...] */
Tab = function(idSet,eType,onCss,defIdx,addLinkUrl,openWinAddLinkUrl) {
	this.onloadCnt = false;
	this.tabClickId = "defaultTab";
	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);
		openWinAddLinkUrl = openWinAddLinkUrl || []; 
		if(addLinkUrl && addLinkUrl[i])tab.onclick = this.addLink.bind(this,i,addLinkUrl[i], openWinAddLinkUrl[i]); //ie에서는 대입법으로 한게 가장 먼저 실행됨, ff에서는 순서대로 실행됨.
		AddEvent(tab,eType,this.on.bind(this,i));
	}
	(defIdx) ? this.on(defIdx-1) : this.on(0);
	
	if (idSet[0][0]) {
		this.tabClickId = idSet[0][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;
		if(this.onloadCnt && this.eType == "click" ) {
			tabClickAction(this.tabClickId);
		} else {
			this.onloadCnt = true;
		}
	},
	addLink:function(n,url, newWin) {
		if(this.curIdx == n) {
			if(!newWin) { 
				GoPage(url);
			} else {
				window.open(url,"_blank");
			}
		}
	}
}
var YScrolling=function(cid, millisec1,millisec2, speed, height)
{
	this.cid= cid;
	this.millisec1 = millisec1;	//start term
	this.millisec2 = millisec2; //runtime term
	this.speed = speed;			//moving pixel
	this.height = height;

	this.h =0;
	this.div = $(this.cid);
	this.htmltxt = this.div.innerHTML;
	this.div.innerHTML = this.htmltxt+this.htmltxt;
	this.div.isover=false;
	this.div.onmouseover=function(){ this.isover=true; }
	this.div.onmouseout=function(){	this.isover=false; }
	this.div.scrollTop=0;

	
	var self =this;
	window.setTimeout(function(){self.play()}, this.millisec1);
	this.isMove = true;
}
YScrolling.prototype={
	play : function(){
		var self =this;
		if(this.isMove && !this.div.isover)
		{	
			this.div.scrollTop += this.speed;
			if(this.div.scrollTop >= this.div.scrollHeight/2) 
			{
				this.div.scrollTop=0;
			}
			else(this.height)
			{
				this.h += this.speed;
				if(this.h>=this.height)
				{
					//롤링 마감처리 추가
					//try{ console.log( this.div.scrollTop ); }catch(e){}
					if (this.div.scrollTop % this.height != 0) {
						this.div.scrollTop = 0;
					}
				
					if(this.h>this.height)
					{
						this.div.scrollTop -= this.h % this.height;
					}
					this.h=0;
					window.setTimeout(function(){self.play()}, this.millisec1);					
					return;
				}
			}
		}
		window.setTimeout(function(){self.play()}, this.millisec2);
	}
};
/*	listId : ul id,
	interval : 초 * 1000
	defIndx : option
*/
var Ticker = function(listId, interval, defIndx) {
	this.init(listId, interval, defIndx);
}
Ticker.prototype = {
	start : function() {
		this.exec();
		this.timer = window.setInterval(this.exec.bind(this),this.interval);
	},
	exec : function() {
		var cnt=this.liSet.length;
		for(var i=0;i<cnt;++i) {
			if(i == this.idx) this.liSet[i].style.display = "";
			else this.liSet[i].style.display = "none";
		}
		if(++this.idx >=cnt) this.idx = 0;
	},
	stop : function() {
		window.clearInterval(this.timer);
	},
	init : function(listId, interval, defIndx) {
		var ul = $(listId);
		this.liSet = ul.getElementsByTagName('li');
		this.interval = (interval) ? interval : 3000;
		this.idx = (defIndx) ? defIndx : 0;
		this.start();
	}
}

/*	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";
		}
	}
}
//100자 의견쓰기와 동일함
var ImgRadio = function(idSet,onCss,defIdx) {
	this.onCss = onCss;
	this.el = [];
	for (var i=0,cnt=idSet.length;i<cnt;++i)
	{
		this.el.push(document.getElementById(idSet[i]));
		this.el[i].oldCss = this.el[i].className;
		AddEvent(this.el[i],"click",this.check.bind(this,i));
	}
	//default 0
	(defIdx) ? this.check(defIdx) : this.check(0);
}

ImgRadio.prototype = {
	check : function(n) {
		for (var i=0,cnt=this.el.length;i<cnt;++i)
		{
			if(i==n) {
				this.el[i].className = (this.el[i].oldCss) ? this.el[i].oldCss+" "+this.onCss : this.onCss;
				document.getElementById(this.el[i].htmlFor).checked = true;
			}
			else {
				this.el[i].className = this.el[i].oldCss;
				document.getElementById(this.el[i].htmlFor).checked = false;
			}
		}
	}
}

var getExternalObject=function(id){
	if (window.document[id]) {
		return window.document[id];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[id])
			return document.embeds[id];
	} else {
		return document.getElementById(id);
	}
}
								

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;
}

function stockColor(inval) {
	inval = inval.trim();
	var res;
	switch(inval.substr(0,1)) {
		case "↑" : 
		case "▲" : res = 'cUp'; break;
		case "▼" : 
		case "↓" : res = 'cDn'; break;
		default : res = 'cFt'; break;
	}
	return res;
}

function stockColorRate(inval) {
	inval = inval.trim();
	var res;
	switch(inval.substr(0,1)) {
		case "+" : res = 'cUp'; break;
		case "-" : res = 'cDn'; break;
		default : res = 'cFt'; break;
	}
	return res;
}

function stockMark(inval,suffix,isBold,addCss) {
	inval = inval.trim();
	var value = (isBold) ? '<b>'+inval.substring(1)+'</b>' : inval.substring(1);
	if(!suffix) suffix = "";
	if(!addCss) addCss = "";
	var res;
	switch(inval.substr(0,1)) {
		case "↑" : res = '<span class="num stUp2 '+addCss+'"><em>↑</em>'+value+suffix+'</span>'; break;
		case "▲" : res = '<span class="num stUp '+addCss+'"><em>▲</em>'+value+suffix+'</span>'; break;
		case "▼" : res = '<span class="num stDn '+addCss+'"><em>▼</em>'+value+suffix+'</span>'; break;
		case "↓" : res = '<span class="num stDn2 '+addCss+'"><em>↓</em>'+value+suffix+'</span>'; break;
		case "-" : res = '<span class="num stFt '+addCss+'"><em>-</em>'+value+suffix+'</span>'; break;
		default : res = '<span class="num stFt '+addCss+'"><em>-</em>'+inval+suffix+'</span>'; break;
	}
	return res;
}

function rateMark(rate) {
	var className = "rate";
	if (rate > 0) {
		className += " positive";
	} else {
		className += " negative";
	}
	var tag = '<span class="' + className + '">' + rate + '%</span>'; 
	return tag;
}

function cutStockName(val) {
	return (val && val.length > 7) ? val.substring(0,7)+".." : val
}
/* mytab */
var myTab = {
	fav : {pg : null},
	hold : {pg : null},
	setMyGroupList : function () {
		var html = [];
		html.push('<select id="'+this.fav.selectId+'" onchange="myTab.resetList(this.selectedIndex,this)">');
		var icnt=this.fav.myGroupData.length;
		var jcnt=this.fav.myData.length;
		for(var i=0;i<icnt;++i) {
			var groupseq = this.fav.myGroupData[i].groupseq;
			var groupname = this.fav.myGroupData[i].groupname;
			for(var j=0;j<jcnt;++j) {
				if(this.fav.myData[j].groupseq == groupseq) {
					if(i==0)
						html.push('<option value="'+groupseq+'" selected="true">'+groupname+' ('+this.fav.myData[j].stocklist.length+')</option>');
					else
						html.push('<option value="'+groupseq+'">'+groupname+' ('+this.fav.myData[j].stocklist.length+')</option>');
					break;
				}
			}
		}
		html.push('<option value="total">----------------------</option>');
		html.push('<option value="gTotal">관심종목 그룹 전체보기</option>');				
		html.push('<option value="total">MY증권 바로가기</option>');
		html.push('</select>');
		
		return html.join('');
	},
	setMyStockTab : function () {
		var addInfo = $('tempInfo').innerHTML;
		var body = $(this.fav.bodyId);
		if(this.fav.myData.length == 0) {
			body.innerHTML = '<p class="'+this.fav.noItemId+'">관심종목이 없습니다.</p>'+addInfo;
			return false;
		}
		else {
			var html = [];
			html.push(this.setMyGroupList());
			html.push('<ul id="'+this.fav.ulId+'"></ul>');
			html.push('	<span class="fl_ri bottom">');
			html.push('	<span id="'+this.fav.linkId+'"><b class="num" id="'+this.fav.cntId+'"></b>개</span>');
			html.push('	<input type="button" id="'+this.fav.prevBtId+'" class="typeBtn prevBT" value="이전"><input type="button" id="'+this.fav.nextBtId+'" class="typeBtn nextBT" value="다음">');
			html.push('</span>');
			
			body.innerHTML = html.join('')+addInfo;
			return true;
		}
	},
	resetList : function (idx,el) {
		if(el && el.options[idx].value == "total") {
			GoPage('/mystock/mystocktop.daum', top);
			return;
		} else if(el && el.options[idx].value == "gTotal") {
			GoPage('/mystock/myfavoritestocklist.daum?type=7', top);
			return;						
		}
		
		var ul = $(this.fav.ulId);
		var html = [];
		var curGroupIdx = -1;
		for(var i=0,cnt=this.fav.myData.length;i<cnt;++i) {
			if(this.fav.myData[i].groupseq == el.options[idx].value) curGroupIdx = i;
		}
		if(curGroupIdx >= 0) {
	    	for(var j=0,cnt=this.fav.myData[curGroupIdx].stocklist.length;j<cnt;++j) {
				var stockInfo = this.fav.myData[curGroupIdx].stocklist[j];
				var niltagstr = "";
	    		html.push('<li>');
				if (this.fav.type == 3) {
					if(this.fav.nilMenu && j < this.fav.ulCnt){
						if(this.fav.nilProfile) {
							niltagstr = "&nil_profile=" + this.fav.nilProfile + "&nil_menu="+ this.fav.nilMenu + new String(j+1);
						} else {
							niltagstr = "&nil_profile=stockprice&nil_menu="+ this.fav.nilMenu + new String(j+1);
						}
					}
	    			html.push('<a href="/item/main.daum?code='+stockInfo[0]+niltagstr+'" title="'+stockInfo[1]+'">'+cutStockName(stockInfo[1])+'</a>');
	  				html.push('<span class="cost num">' + stockInfo[2] + '</span>');
					html.push('<span class="rate num">' + stockMark(stockInfo[4]) + '</span>');
				}
				else if(this.fav.type == 2) { 
					if(this.fav.nilMenu && j < this.fav.ulCnt){
						if(this.fav.nilProfile) {
							niltagstr = "&nil_profile=" + this.fav.nilProfile + "&nil_menu="+ this.fav.nilMenu + new String(j+1);
						} else {
							niltagstr = "&nil_profile=stockprice&nil_menu="+ this.fav.nilMenu + new String(j+1);
						}
					}
	    			html.push('<a href="/item/main.daum?code='+stockInfo[0]+niltagstr+'" title="'+stockInfo[3]+'|'+stockInfo[5]+'" target="_top">'+cutStockName(stockInfo[1])+'</a>');
					html.push('<span class="cost num">' + stockInfo[2] + '</span>');
					html.push(stockMark(stockInfo[3].substring(0,1),"",false,"mark"));
				}
	    		html.push('</li>');
	    	}
		}
		ul.innerHTML = html.join('');
		if(!this.fav.pg) this.fav.pg = new Paging(this.fav.ulId,this.fav.ulCnt,this.fav.prevBtId,this.fav.nextBtId);
		else this.fav.pg.init();
		if(this.fav.pg.needPaging) {
			$(this.fav.linkId).style.display = "";
			$(this.fav.cntId).innerHTML = this.fav.pg.totalCount;
		}
		else {
			$(this.fav.linkId).style.display = "none";
		}
		if(this.fav.toolTip) {
			this.fav.toolTip.init('myTabToolTip',this.fav.ulId)
		}
	},
	callMyStockData : function() {
		callsrc("mystockData","/xml/mystock.daum");
	},
	mystockInit : function(option) {
		Object.extend(this.fav,option);
		try{
			if(this.setMyStockTab($(this.fav.bodyId))) this.resetList(0,$(this.fav.selectId));						
			RemoveEvent($(this.fav.tabId),"click",this.callMyStockData);
		}
		catch(e) {}
	},
	setMyHoldTab : function () {
		var addInfo = $('tempInfoHold').innerHTML;
		var body = $(this.hold.bodyId);
		if(this.hold.myData[0].myholdList.length == 0) {
			body.innerHTML = '<p class="'+this.hold.noItemId+'">보유종목이 없습니다.</p>'+addInfo;
			return false;
		}
		else {
			var html = [];
			html.push('<ul id="'+this.hold.ulId+'"></ul>');
			html.push('<div id="' + this.hold.selectId + '"></div>');
			html.push('	<span class="fl_ri bottom">');
			html.push('	<span id="'+this.hold.linkId+'"><b class="num" id="'+this.hold.cntId+'"></b>개</span>');
			html.push('	<input type="button" id="'+this.hold.prevBtId+'" class="typeBtn prevBT" value="이전"><input type="button" id="'+this.hold.nextBtId+'" class="typeBtn nextBT" value="다음">');
			html.push('</span>');
			body.innerHTML = html.join('')+addInfo;
			return true;
		}
	},
	callMyHoldData : function() {
		callsrc("myholdData","/xml/myholding.daum");
	},
	resetHoldList : function (idx,el) {

		var ul = $(this.hold.ulId);
		var parRate = $(this.hold.selectId);
		var rateFlag = "";
		var rateClass = "";
		var html = [];

		for(var i=0,cnt=this.hold.myData[0].myholdList.length;i<cnt;++i) {
			var stockInfo = this.hold.myData[0].myholdList[i];
			var niltagstr = "";
			html.push('<li>');
			if (this.hold.type == 3) {
				if(this.hold.nilMenu && i < this.hold.ulCnt){
					if(this.hold.nilProfile) {
						niltagstr = "&nil_profile=" + this.hold.nilProfile + "&nil_menu="+ this.hold.nilMenu + new String(i+1);
					} else {
						niltagstr = "&nil_profile=stockprice&nil_menu="+ this.hold.nilMenu + new String(i+1);
					}
				}
				html.push('<a href="/item/main.daum?code='+stockInfo[0]+ niltagstr +'" title="'+stockInfo[1]+'">'+cutStockName(stockInfo[1])+'</a>');
				html.push('<span class="cost num">' + stockInfo[2] + '</span>');
				html.push('<span class="rate num">' + stockMark(stockInfo[4]) + '</span>');
			}
			else if(this.hold.type == 2) {
				if(this.hold.nilMenu && i < this.hold.ulCnt){
					if(this.hold.nilProfile) {
						niltagstr = "&nil_profile=" + this.hold.nilProfile + "&nil_menu="+ this.hold.nilMenu + new String(i+1);
					} else {
						niltagstr = "&nil_profile=stockprice&nil_menu="+ this.hold.nilMenu + new String(i+1);
					}
				}
				html.push('<a href="/item/main.daum?code='+stockInfo[0]+ niltagstr +'" title="'+stockInfo[3]+'|'+stockInfo[5]+'" target="_top">'+cutStockName(stockInfo[1])+'</a>');
				html.push('<span class="cost num">' + stockInfo[2] + '</span>');
				html.push(stockMark(stockInfo[3].substring(0,1),"",false,"mark"));
			}
			html.push('</li>');
		}
	
		ul.innerHTML = html.join('');
		if(!this.hold.pg) this.hold.pg = new Paging(this.hold.ulId,this.hold.ulCnt,this.hold.prevBtId,this.hold.nextBtId);
		else this.hold.pg.init();
		if(this.hold.pg.needPaging) {
			$(this.hold.linkId).style.display = "";
			$(this.hold.cntId).innerHTML = this.hold.pg.totalCount;
		}
		else {
			$(this.hold.linkId).style.display = "none";
		}
		if(this.hold.toolTip) {
			this.hold.toolTip.init('myTabToolTip',this.hold.ulId);
		}
		
		if(parseFloat(this.hold.myData[0].avgPer) > 0 ) {
			rateClass = "cUp";
			rateFlag = "+";
		} else if(parseFloat(this.hold.myData[0].avgPer) < 0 ) {
			rateClass = "cDn";
		} else {
			rateClass = "cFt";
		}
		
		parRate.innerHTML = "평가 수익률: <span class='" + rateClass+ "'>" + rateFlag + "<b>" + this.hold.myData[0].avgPer + "</b>%</span>";
		
	},		
	myHoldInit : function(option) {
		Object.extend(this.hold,option);
		try{
			if(this.setMyHoldTab($(this.hold.bodyId))) this.resetHoldList(0,$(this.hold.selectId));						
			RemoveEvent($(this.hold.tabId),"click",this.callMyHoldData);
		}
		catch(e) {}
	}
};

/* GNB siseInfo */
var GNB_sise = {
	ticker : null,
	url : null,
	niltag : null,
	_makeRollingInnerHTML: function(name, data) {
		var html = 	['<b class="dp_n" onclick="GoPage(\'', data.url, '\')" onmouseover="this.className=\'dp_n on\'" onmouseout="this.className=\'dp_n\'">', name, '</b>',
		           	 '<span class="num1" onclick="GoPage(\'' + data.url + '\')" onmouseover="this.parentNode.getElementsByTagName(\'b\')[0].className=\'dp_n on\'" onmouseout="this.parentNode.getElementsByTagName(\'b\')[0].className=\'dp_n\'">', 
		           	 	'<span class="price">' + data.price + '</span>', 
		           	 	stockMark(data.updn), 
		           	 	rateMark(data.rate), '</span>'].join("");
		return html;
	},
	_makeLayerInnerHTML: function(index, name, data) {
		var className = "GNB_itemName"+index;
		var html = ['<li class="',className,'" onclick="GoPage(\'', data.url, '\')" onmouseover="this.className=\'', className, ' on\'" onmouseout="this.className=\'',className,'\'">',
		            	'<span class="name">', name, '</span>',
		            	'<span class="price">', data.price, '</span>',
		            	stockMark(data.updn),
		            	rateMark(data.rate),
		            '</li>'].join("");
		return html;
	},
	_indexTable: {
		"0": {key:"expkospi",name:"코스피예상"},
		"1": {key:"kospi",name:"코스피"},
		"2": {key:"kospi200",name:"코스피200"},
		"3": {key:"dowjones",name:"다우존스"},
		"4": {key:"nasdaq",name:"나스닥"},
		"5": {key:"sp500",name:"S&P500"},
		"6": {key:"philadelphia",name:"필-반도체"},
		"7": {key:"dollar",name:"원/달러"},
		"8": {key:"yen",name:"원/100엔"},
		"9": {key:"wti",name:"유가"},
		"10": {key:"expkosdaq",name:"코스닥예상"},
		"11": {key:"kosdaq",name:"코스닥"},
		"12": {key:"futures",name:"선물"},
		"13": {key:"nikkei",name:"일본니케이"},
		"14": {key:"sanghai",name:"중국상해"},
		"15": {key:"ftse",name:"영국"},
		"16": {key:"pari",name:"프랑스"},
		"17": {key:"gold",name:"금"},
		"18": {key:"bdi",name:"BDI"},
		"19": {key:"dram",name:"D램지수"}
	},
	
	set : function(data){
		if(!data) return;
		var el = $('GNB_siseList');
		el.innerHTML = "";

		var defaultIndex = ["11", "1", "7", "12"];	//코스닥,코스피,원/달러,선물

		if( data.isExpMarket == "true" ) { defaultIndex.splice(0, 0, "10", "0"); }		//코스닥예상,코스피예상,코스닥,코스피,원/달러,선물
		if( data.isUSMarket == "true" ) { defaultIndex.splice(0, 4, "4", "3", "11", "1"); }	//나스닥,다우,코스닥,코스피
		
		for (var j = 2; j--;) {
			for (var i = 0, len = defaultIndex.length; i < len; ++i ) {
				var li = $C('li');
				var index = defaultIndex[i];
				li.className = "Rolling_Item" + index;
				
				var mInfo = this._indexTable[index];
				var mData = data[mInfo.key];

				if(mData) {
					li.innerHTML = this._makeRollingInnerHTML(mInfo.name, mData);
				}
				
				el.appendChild(li);
				if (i%2 === 0) {
					var span = $C("span");
					span.className = "bar";
					span.innerHTML = "|";
					el.appendChild(span);
				}
			}
		}
		
		if(!GNB_sise.ticker) GNB_sise.ticker = new YScrolling("GNB_siseList",2500,1,1,21);//new Ticker('GNB_siseList',2000);
	
		var layer_el0 = $('GNB_LayerSiseList0');
		var layer_el1 = $('GNB_LayerSiseList1');
		var layer_el2 = $('GNB_LayerSiseList2');
		var layer_el3 = $('GNB_LayerSiseList3');
		var layer_el4 = $('GNB_LayerSiseList4');
		var layer_el5 = $('GNB_LayerSiseList5');

		var siseLayerWrapper = $("siseLayerBoxWrapper");
		if ((!defaultIndex.contains("0") && !defaultIndex.contains("10"))) {
			$("GNB_siseLayerBox").className = "noextend";
			siseLayerWrapper.className = "noextend";
		} else {
			$("GNB_siseLayerBox").className = "";
			siseLayerWrapper.className = "";
		}

		layer_el0.innerHTML = layer_el1.innerHTML = layer_el2.innerHTML = layer_el3.innerHTML = layer_el4.innerHTML = layer_el5.innerHTML = "";

		var layerOrders = [{ dom:layer_el0, order:["0", "1", "12"] },
		                   { dom:layer_el1, order:["10", "11", "2"] },
		                   { dom:layer_el2, order:["3", "4", "5", "6"] },
		                   { dom:layer_el3, order:["13", "14", "15", "16"] },
		                   { dom:layer_el4, order:["7", "8", "9"] },
		                   { dom:layer_el5, order:["17", "18", "19"] } ];
		
		for (var li = 0; li < layerOrders.length; li++) {
			var lObj = layerOrders[li];
			
			var lObjOrder = lObj.order;
			for (var loi = 0; loi < lObjOrder.length; loi++) {
				var curI = lObjOrder[loi];
				
				//예상코스피:0, 예상코스닥:10
				if (curI === "0" || curI === "10") {
					if (!defaultIndex.contains(curI)) {
						continue;
					}
				}
				
				var curKey = this._indexTable[curI].key;
				var curName = this._indexTable[curI].name;
				
				if (data[curKey]) {
					lObj.dom.innerHTML += this._makeLayerInnerHTML(curI,  curName, data[curKey]);
				}
			}
		}
	},
	get : function(url){
		callsrc('gnbSise',GNB_sise.url);
	},
	repeat : function(url, nil){
		GNB_sise.niltag = nil;
		GNB_sise.url=url;
		GNB_sise.get();
		window.setInterval(GNB_sise.get,60000);
	}
};

/* 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,_path,_domain){
	var expireDate = new Date(Number(new Date())+Number(_day)*86400000);
	document.cookie = _name+'='+_value+';expires='+expireDate.toGMTString()+';path='+_path+';domain='+_domain+';';
}*/
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+";";
	//alert(document.cookie);
	document.cookie =ckText;
	//document.cookie ="STOCKCODE="+escape("036030")+";domain=stock_dev.daum.net";
}

function StopEvent(event) {
	var e=event || window.event;
	if(e.preventDefault) {e.preventDefault(); e.stopPropagation(); }
	else {e.returnValue = false; e.cancelBubble = true;}
}

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;
	var oWindow = window.open(url,winnm,options);
	return oWindow;
}

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 brHeight = (window.outerHeight) ? window.outerHeight : document.body.clientHeight - document.documentElement.scrollHeight;
	var popLeft = OpenerLeft + parseInt((brWidth-width)/2);
	//var popTop = OpenerTop + parseInt((brHeight-height)/2);
	var popTop = parseInt((window.screen.availHeight-height)/2);
	openPop(url,winnm,width,height,'left='+popLeft+',top='+popTop+','+etc_options)
}

function allPanelPop(niltag)
{
	var OpenerLeft = (window.screenLeft != undefined) ? window.screenLeft : window.screenX;
	var OpenerTop = (window.screenTop != undefined) ? window.screenTop : window.screenY;
	var brWidth = 1024;//(window.outerWidth) ? window.outerWidth : document.documentElement.clientWidth;
	var brHeight = 768;//(window.outerHeight) ? window.outerHeight : document.documentElement.clientHeight;
	var panelUrl = "http://stock.daum.net/quote/allpanel.daum";
	if (niltag && niltag != "") {
		panelUrl = panelUrl + niltag;
	}
	
	var panel = window.open(panelUrl,"ammpanel","width="+brWidth+",height="+brHeight+",left="+OpenerLeft+",top="+OpenerTop+",resizable=yes,scrollbars=yes");
	panel.focus();
}
//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);
}


//input 초기값삭제 & 기본style로 변경
function resetInputStyle(el) {
	if (!el.isFocus) {
		el.value = "";
		el.style.color = "#333";
		el.style.fontWeight = "normal";
		el.style.fontSize = "12px";
		el.style.fontFamily = "AppleGothic,굴림,gulim,sans-serif";
		el.isFocus = true;
		el.focus();
	}
}

/* suggest */
var sug = {}
sug.children = [];
sug.cur = null; //call시 현재 sug.exec 객체

sug.cookie = {
	name : "stockSuggest",
	domain : ["stock.daum.net","board1.finance.daum.net","comment.finance.daum.net","stock_dev.daum.net","localstock.daum.net","board2.finance.daum.net"]
}

sug.$ = $;
sug.$C = $C; 
sug.setCookie = setCookie; //setCookie(_name,_value,_day,_domain)
sug.getCookie = getCookie; //getCookie(s)
sug.setStyle = setStyle; //setStyle(obj,styles)
sug.addEvent = AddEvent; //AddEvent(element, name, func)
sug.stopEvent = StopEvent; //StopEvent(event)
sug.highlight = highlight; //highlight(obj,isOver,color) <- mouseout일때는 color값 필요없음
sug.resetInputStyle = resetInputStyle; //input에 들어있는 text style reset
sug.callsrc = callsrc;
sug.isSuggestOn = (sug.getCookie("stockSuggest")=="off") ? false : true;
sug.on = function() {
	sug.isSuggestOn = true;
	for(var i=0,cnt=sug.children.length;i<cnt;++i) {
		sug.children[i].input.autocomplete = "off";
	}
	sug.close();
	for(var i in this.cookie.domain) sug.setCookie(sug.cookie.name,"on",365,sug.cookie.domain[i]);
}
sug.off = function() {
	sug.isSuggestOn = false;
	for(var i=0,cnt=sug.children.length;i<cnt;++i) {
		sug.children[i].input.autocomplete = "on";
	}
	sug.close();
	for(var i in this.cookie.domain) sug.setCookie(sug.cookie.name,"off",365,sug.cookie.domain[i]);
}
sug.setList = function(data) {
	sug.cur.setList(data);
}
sug.close = function() {
	for(var i=0,cnt=sug.children.length;i<cnt;++i) {
		sug.children[i].closeBox();
	}
}
sug.autoSelect = function() {
	if(sug.cur.listCnt > 0) sug.cur.selectItem();
}



//input validate function (서비스마다 각각 설정)
sug.validate = function(val) {
	//if(val.length == 0 || (!isNaN(val) && val.length < 4)) return false;
	if(val.length == 0) return false;
	return true;
}

//결과값이 없을경우  (서비스마다 각각 설정)
sug.noResult = function() {
	return '<p style="padding:10px;line-height:18px">해당 단어(코드)로 시작하는 종목이 없습니다.</p>';
}

sug.info = function() {
	var html = '<p style="padding:4px 0;font:11px/15px 돋움,dotum">';
	if(sug.isSuggestOn) html += '현재 <b style="color:#5471AA">검색어 서제스트</b>를 사용하고 있습니다.';
	else html += '<b style="color:#5471AA">검색어 서제스트</b>를 사용해 보세요. <a href="javascript:;" onclick="sug.on()" style="color:#EB6F00;text-decoration:underline">기능켜기</a>';
	html += '<br>검색어 입력시 적합한 키워드를 제시합니다.</p>';
	return html;
}

sug.getFooter = function(isInfoShow) {
	var html ='<span style="float:right;text-align:right;padding-right:10px;">' +
						'	<a href="http://blog.daum.net/daumfinance/5594457" target="_blank">서제스트란?</a>' +
						'	';
	if(isInfoShow) html += '<span style="margin:0 4px">|</span> <a href="javascript:;" onclick="sug.close()">닫기</a>';
	//else html += '<a href="javascript:;" onclick="sug.off()">기능끄기</a>';
	html += '</span>';
	return html;
}

sug.exec = function(inputId,btnId,btnFunc,boxId,isFocus) {
	sug.children.push(this);
	this.maxHeight = 122;
	this.isInfoShow = false;
	this.isListShow = false;
	this.listCnt = 0;
	this.curIndex = -1;	
	this.timer = null;
	
	this.input = sug.$(inputId);
	this.btn = sug.$(btnId);
	this.btnFunc = btnFunc;
	this.isFocus = "off";
	
	if(isFocus) this.isFocus = "on";
	
	if(boxId) this.box = sug.$(boxId);
	else {
		this.box = sug.$C('div');
		sug.setStyle(this.box,"top:"+(this.input.offsetTop+this.input.offsetHeight)+"px;left:"+this.input.offsetLeft+"px");
		//document.title = this.input.offsetLeft;
		this.input.parentNode.style.zIndex=97-sug.children.length*4;
		this.input.parentNode.appendChild(this.box);
	}
	sug.setStyle(this.box,"display:none;position:absolute;z-index:"+(98-sug.children.length*4)+";text-align:left;width:"+this.input.offsetWidth+"px;");
	this.render();
}

sug.exec.prototype = {
	render : function() {
		this.input.setAttribute("autocomplete","off");
		this.input.maxLength = "10";
		this.defValue = this.input.value;
		
		var w = this.input.offsetWidth;//this.box.offsetWidth;
	
		this.bk = sug.$C('iframe'); this.bk.frameBorder = 0;
		sug.setStyle(this.bk,"position:absolute;background-color:#fff;width:"+w+"px;top:0;left:0;z-index:"+(99-sug.children.length*4));//height:146px;
		
		this.body = sug.$C('div');
		sug.setStyle(this.body,"position:absolute;width:"+(w-2)+"px;border:1px solid #8C95D6;z-index:"+(100-sug.children.length*4));
		
		this.list = sug.$C('ul'); this.list.className = "scroll";
		sug.setStyle(this.list,"width:"+(w-2)+"px;overflow-y:auto;overflow-x:hidden");
		this.body.appendChild(this.list);
		
		this.footer = sug.$C('div');
		sug.setStyle(this.footer,"float:left;background-color:#F4F6FB;height:14px;padding:7px 0px 3px 0px;font:11px 돋움,dotum;letter-spacing:-1px;color:#C2CFF0;width:100%;");
		
		this.icon = sug.$C('div');
		this.icon.className = "icoSugest";
		sug.setStyle(this.icon,"background-image:url(http://fn.daum-img.net/image/finance/plaza/2008/stock/common/ico_sugest.gif);background-repeat:no-repeat;width:7px;height:4px;position:absolute;top:"+(this.input.offsetTop+9)+"px;left:"+(this.input.offsetLeft+w-16)+"px;cursor:pointer;font-size:0");
		this.input.parentNode.appendChild(this.icon);
		
		/*this.resortBtn = sug.$C('a'); this.resortBtn.href="javascript:;"; this.resortBtn.innerHTML = '끝단어 더보기'; sug.setStyle(this.resortBtn,"float:left");
		this.footer.appendChild(this.resortBtn);
		sug.addEvent(this.resortBtn,"click",this.resort.bind(this));*/
		this.footer.innerHTML = sug.getFooter(this.isInfoShow);
		this.body.appendChild(this.footer);
		
		this.box.appendChild(this.bk);
		this.box.appendChild(this.body);
		
		sug.addEvent(this.input,"keydown",this.keyIn.bindEvent(this));
		sug.addEvent(this.input,"focus",this.focusInput.bindEvent(this));
		//sug.addEvent(this.input,"focus",this.resetInputStyle.bindEvent(this));
		sug.addEvent(this.input,"mousedown",this.clickInput.bindEvent(this));
		sug.addEvent(document,"mousedown",this.closeBox.bindEvent(this));
		sug.addEvent(this.icon,"mousedown",this.showInfo.bind(this));
		sug.addEvent(this.icon,"mousedown",sug.stopEvent); 
		sug.addEvent(this.body,"mousedown",sug.stopEvent); 
		sug.addEvent(this.btn,"mousedown",sug.stopEvent); 
		sug.addEvent(this.btn,"click",this.selectItem.bind(this));
		
		//if (this.isFocus == "on") this.input.focus();
	},
	showInfo : function() {
		if(!this.isInfoShow) {
			sug.close();
			this.isInfoShow = true;
			this.iconChange(this.isInfoShow);
			this.footer.innerHTML = sug.getFooter(this.isInfoShow);
			this.setList(null);
		}
		else {
			this.closeInfo();
		}
	},
	closeInfo : function() {
		if(this.isInfoShow) {
			this.isInfoShow = false;
			this.iconChange(this.isInfoShow);
			this.footer.innerHTML = sug.getFooter(this.isInfoShow);
			this.box.style.display = "none";
		}
	},
	keyIn : function(event) { //key control
	
		if(!sug.isSuggestOn)  return;

		var e=event || window.event;
		
		if((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 96 && e.keyCode <= 105) || e.keyCode == 229 || e.keyCode == 8 || e.keyCode == 46) { //48~57:숫자, 65~90:문자, 96~105:숫자키패드, 229:한글, 8:백스페이스, 46 : delete
			if(!this.timer) {
				this.checkChange.bind(this);
				this.timer = window.setInterval(this.checkChange.bind(this),100);	
			}
		} else if(e.keyCode == 38 || e.keyCode == 40) { 
			if(this.listCnt > 0) {
				if(e.keyCode == 38) { //up key
					if(this.curIndex > 0) {
						this.curIndex--;
						var li = this.list.childNodes[this.curIndex];
						//if(li.offsetTop + li.offsetHeight <= this.list.scrollTop) this.list.scrollTop -= li.offsetHeight;
						if(li.offsetTop <= this.list.scrollTop) this.list.scrollTop = li.offsetTop;
					}
					else { //curIndex이 0인 경우 박스를 닫는다.
						this.closeBox();
					}
				} 
				else { //down key
					if(this.curIndex < this.listCnt-1) this.curIndex++;
					var li = this.list.childNodes[this.curIndex];
					//if(li.offsetTop >= this.list.offsetHeight + this.list.scrollTop) this.list.scrollTop += li.offsetHeight; //ff에서 border값 때문에 계산이 안맞아서 -3해줌
					if(li.offsetTop +li.offsetHeight >= this.list.offsetHeight + this.list.scrollTop) this.list.scrollTop = (li.offsetTop +li.offsetHeight-this.list.offsetHeight); //ff에서 border값 때문에 계산이 안맞아서 -3해줌
					this.showList(); //닫혀있으면 다시 열어준다.
				}
				//highlight
				for(var i=0; i<this.listCnt; ++i) this.list.childNodes[i].onmouseout();
				if(this.curIndex >= 0 && this.curIndex < this.listCnt) this.list.childNodes[this.curIndex].onmouseover(); 
			}
		} else if(e.keyCode == 13) {//enter key
			this.selectItem();
			return false;
		}
	},
	checkChange : function() { //check input value
		if(this.input.oldValue == this.input.value) return; //변화가 없으면 무시
		this.input.code = ""; //변화가 있으면 지워줌.
		this.input.oldValue = this.input.value; 
		this.getData();
	},
	focusInput : function() { //mousedown시 show/hide
		//초기값 (ex.종목명 or 코드) 일때는 pass해야 하지만, 검색결과가 뿌려진 경우에는????
		if(this.defValue == this.input.value) {
			//this.input.value = "";
			//this.input.isFocus = true;
			sug.resetInputStyle(this.input);
		}
		sug.cur = this; //focus가 가면 sug.cur 세팅
	},
	clickInput : function() { //mousedown시 show/hide
		//초기값 (ex.종목명 or 코드) 일때는 pass해야 하지만, 검색결과가 뿌려진 경우에는????
		if(!sug.isSuggestOn) return;
		if(this.defValue == this.input.value) return;
		if(!this.isListShow) this.getData(); //필요할까??
		else this.closeList();
	},
	getData : function() {	
		var invalue = this.input.value;
		if(!sug.validate(invalue)) {
			this.removeList();
			return;
		}
		sug.callsrc('sugJs','http://suggest.finance.daum.net/stock_nsuggest?mod=js&func=sug.setList&encoding=utf_in_out&q='+encodeURIComponent(invalue))
	},
	setList : function(data) {
		sug.cur = this;  //setList 해도 sug.cur 세팅
		while(this.list.firstChild) this.list.removeChild(this.list.firstChild);
		if(!data) {
			this.showInfoList();
		} else {
			var items = data.items;
			var r_items = data.r_items;
			var itemCnt = items.length;
			var r_itemCnt = r_items.length;		
			if(itemCnt + r_itemCnt > 0) {
				this.listCnt = itemCnt + r_itemCnt;	
				var keyVal = data.rq;
				var i, j;
				for(i=0;i<itemCnt;++i) {
					this.makeItemList(i, keyVal, items[i]);
				}
				for(j=0;j<r_itemCnt;++i,++j) {
					this.makeItemList(i, keyVal, r_items[j]);
				}
			}
			else {
				this.listCnt = 0;
				this.makeItemList(0);
			}
		}
		this.showList();
		this.list.style.height = "auto";
		var listHeight = this.list.offsetHeight;
		var realHeight = (listHeight > this.maxHeight) ? this.maxHeight : listHeight;
		this.list.style.height = realHeight + "px";
		this.box.style.height = this.bk.style.height = (this.body.offsetHeight) + "px";
		this.curIndex = -1;
		this.list.scrollTop = 0;
	},
	showInfoList : function() { //<li>생성
		var li = $C('li');
		setStyle(li,"position:static;float:none;line-height:14px;padding:3px 10px 1px;height:auto");
		li.innerHTML = sug.info();
		this.list.appendChild(li);
	},
	makeItemList : function(i, keyVal, itemVal) { //<li>생성
		var li = $C('li');
		li.idx = i;
		//setStyle(li,"letter-spacing:0;width:100%;height:22px;line-height:22px;overflow:hidden");

		if(!keyVal && !itemVal) {
			setStyle(li,"position:static;float:none;height:auto");
			li.innerHTML = sug.noResult();			
		}
		else {
			//setStyle(li,"position:static;float:none;height:20px;line-height:14px;padding:3px 0 1px 10px;white-space:nowrap;overflow:hidden");
			setStyle(li,"position:static;float:none;line-height:14px;padding:4px 10px 6px;height:auto;cursor:pointer;");
			li.innerHTML = this.formatItemList(li,keyVal,itemVal);		
			li.onmouseover = function() {sug.highlight(this,true,"#efefef")}; 
			li.onmouseout = function() {sug.highlight(this,false)}; 
			li.onmousedown = this.selectItemOne.bind(this,i)
		}
		this.list.appendChild(li);
	},
	formatItemList : function(li,keyVal,itemVal) {
		//동의어 들어있는지 확인		
		if(itemVal.indexOf("(=")>=0) itemVal.match(/(.*)\(=(.*)\)\(([A-Za-z0-9]{6})\)/);
		else itemVal.match(/(.*)(.*)\(([A-Za-z0-9]{6})\)/);
		li.dataName = RegExp.$1; 
		li.dataName1 = RegExp.$2;
		li.dataCode = RegExp.$3;
		
		var html;
		var exp = new RegExp("("+keyVal.replace(/(\(|\))/gi,"\\$1")+")",'gi');
		html = li.dataName.replace(exp,"<span style=\"color:#FF5F00\">$1</span>");
		if(li.dataName1.length > 0) html += "(="+li.dataName1.replace(exp,"<span style=\"color:#FF5F00\">$1</span>")+")";
		html += "<span class=\"num\" style=\"color:#999\"> (" + li.dataCode.replace(exp,"<span style=\"color:#FF5F00\">$1</span>") +")</span>";
		return html;
	},
	showList : function() { //show ul & addevent
		if(!this.isListShow) {
			this.box.style.display = "block";
			this.list.style.display = "block";
			//this.footer.style.display = "block";
			
			//this.offBT.style.display = "";
			//this.closeBT.style.display = "none";
			//this.body.style.display = "block";
			//this.bk.style.display = "block";
			this.isListShow = true;
		}
	},
	closeList : function() { //hide ul & removeevent & timer remove
		if(this.timer) {
			window.clearInterval(this.timer);
			this.timer = null; //해줘야함
			//this.input.oldValue = "";
			this.input.oldValue = this.input.value;
		}
		this.curIndex = -1;
		if(this.isListShow) {
			//this.bk.style.display = "none";
			//this.list.style.display = "none";
			this.isListShow = false;
		}
	},
	removeList : function() { //remove ul
		this.listCnt = 0;
		this.closeBox();
	},
	closeBox : function() {
		this.box.style.display = "none";
		this.closeInfo();
		this.closeList();
	},
	iconChange : function(isOn) {
		this.icon.style.backgroundPosition=(isOn)?"0 bottom":"0 0";
	},
	selectItem : function() {
		if (!this.isListShow) {
			if (typeof(this.btnFunc) == "function") 
				this.btnFunc();
			return;
		}		
		if(this.curIndex >= 0 && this.curIndex < this.listCnt) { //선택항목이 있는 경우
			this.selectItemOne(-1);
		}
		else {
			this.selectItemAuto();
		}
	},
	selectItemOne : function(idx) { //mousedown or enter click시 호출 -> StockInsert & CloseStockList
		if(idx >= 0) this.curIndex = idx;
		var li = this.list.childNodes[this.curIndex];
		this.input.value = li.dataName.replace(/&amp;/gi,"&");
		this.input.code = li.dataCode;
		this.removeList();
		if(typeof(this.btnFunc) == "function") this.btnFunc();
	},
	selectItemAuto : function() { //enter key
		//아래 항목에 1개만 있으면 선택할필요없이 바로 code값 넣어주기
		if(this.listCnt == 1) {
			var li = this.list.firstChild;
			this.input.value = li.dataName.replace(/&amp;/gi,"&");
			this.input.code = li.dataCode;
		}
		else {
		//아래 항목에서 존재하는게 있으면 선택할필요없이 바로 code값 넣어주기 && 우선주  아닌게 1개인지 체크
			var equalItem = null;
			var noPrefer = [];
			var cnt = this.listCnt;
			for(i=0;i<cnt;++i) {
				var li = this.list.childNodes[i];
				if(this.input.value == li.dataName.replace(/&amp;/gi,"&") || this.input.value == li.dataCode) {
					equalItem = li;
					break;
				}
				if(li.dataCode.substring(5)=="0") noPrefer.push(li);
			}
			
			if(equalItem || noPrefer.length == 1) {
				var target = equalItem || noPrefer[0];
				this.input.value = target.dataName.replace(/&amp;/gi,"&");
				this.input.code = target.dataCode;				
			}
		}
		if(this.input.code && this.input.value.length>0) { //백스페이스 등으로 값을 없에는 경우, code값은 남아 있으므로 함께 check해줌
			this.removeList();
		}
		if(typeof(this.btnFunc) == "function") this.btnFunc();
	}
}

/* GNB 종목검색 */
function inputCheck(el){
	if(!el.isFocus || el.value.trim() == "") {
		alert('검색어를 입력해주세요.');
		el.focus();
		return false;
	}
	return true;
}

function stockSearch(id) {
	var el = $(id);
	var code = el.code;
	if(code) window.location.href="http://stock.daum.net/item/main.daum?code="+code;
	else {
		if(!inputCheck(el)) return;
		GoPage('http://stock.daum.net/search/search.daum?name='+encodeURIComponent(el.value));
	}
}
/* 현재가 하단 종목검색 */
function stockSearchDown(e,id) {
	if(!e) e= window.event;
	if(e.keyCode == "13") stockSearch(id);
}
function stockSearchFocus(id) {
	var el = $(id);
	resetInputStyle(el);
}
/*
function rightAd(type) {
	var rand = Math.random().toString(); 
	var ordval = rand.substring(2,rand.length);
	switch(type) {
		case 250 :
			document.writeln("<div id=\"EXTENSIBLE_BANNER_WRAP\"><div id=\"EXTENSIBLE_BANNER\"></div></div><iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00872&type=cpm&tag=iframe&mkvid=1&ord=" + ordval + "\" width=250 height=250 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=\"AMS_250exp\"></iframe>");
			break;
		case 180 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00871&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;
		case 130250 :
			try	{
				if(window.screen.width >= 1152) {
					var bannerObj = document.createElement("div");
					bannerObj.setAttribute("id","RIGHT_SPACE_BANNER");
					
					if(document.getElementById(rsTargetId)) {
						document.getElementById(rsTargetId).style.position = "relative";
						document.getElementById(rsTargetId).appendChild(bannerObj);

						bannerObj.innerHTML = "<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00887&type=cpm&tag=iframe&mkvid=1&ord=" + ordval + "\" width=130 height=250 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=stock_AMSRB></iframe>";
					}
				}
			}
			catch (e){}
			break;
		default :
			document.writeln("<iframe src=\"http://amsv2.daum.net/cgi-bin/adcgi?corpid=46&secid=00871&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;
	}		
}
*/

function rightAd(type) {
	var rand = Math.random().toString(); 
	var ordval = rand.substring(2,rand.length);
	switch(type) {
		case 250 :
			document.writeln("<div id=\"EXTENSIBLE_BANNER_WRAP\"><div id=\"EXTENSIBLE_BANNER\"></div></div><iframe src=\"http://amsv2.daum.net/ad/adview?secid=00872\" width=250 height=250 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=\"AMS_250exp\"></iframe>");
			break;
		case 180 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/ad/adview?secid=00871\" width=180 height=180 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=stock_AMS></iframe>");
			break;
		case 130250 :
			try	{
				if(window.screen.width >= 1152) {
					var bannerObj = document.createElement("div");
					bannerObj.setAttribute("id","RIGHT_SPACE_BANNER");
					
					if(document.getElementById(rsTargetId)) {
						document.getElementById(rsTargetId).style.position = "relative";
						document.getElementById(rsTargetId).appendChild(bannerObj);

						bannerObj.innerHTML = "<iframe src=\"http://amsv2.daum.net/ad/adview?secid=00887\" width=130 height=250 border=0 frameborder=0 scrolling=no marginheight=0 marginwidth=0 id=stock_AMSRB></iframe>";
					}
				}
			}
			catch (e){}
			break;
		case 6090 :
			document.writeln("<iframe src=\"http://amsv2.daum.net/ad/adview?secid=00889\" width=60 height=90 border=0 frameborder=0 scrolling=no id=stock_AMS></iframe>");
			break;
		default :
			document.writeln("<iframe src=\"http://amsv2.daum.net/ad/adview?secid=00871\" 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);
}
//실시간 시세 링크
function realApply() {
	GoPage('/quote/realapply.daum');
}

/* id = tooltip id, lid : list id */
var stockToolTip = function(_x, _y) {
	this._x = 0;
	this._y = 0;
	if(_x) this._x = _x;
	if(_y) this._y = _y;
	//this.init(id, lid);
}
stockToolTip.prototype = {
	init : function(id, lid) {
		this.el = $(id);
		this.list = $(lid);
		var lastTarget = null;
		for (var i = 0, cnt = this.list.childNodes.length; i < cnt; ++i) {
			var ch = this.list.childNodes[i];
			if (ch.nodeType == 1) {
				var target = lastTarget = this.list.childNodes[i].getElementsByTagName('a')[0];
				target.comment = target.title;
				target.removeAttribute("title");
				AddEvent(target, "mouseover", this.show.bindEvent(this,target));
				AddEvent(target, "mouseout", this.close.bindEvent(this,target));
			}
		}
	},
	show : function(event,target) {
		if(!event) event = window.event;
		var dataset = target.comment.split('|');
		this.el.innerHTML = stockMark(dataset[0])+' &nbsp;<span class="'+stockColor(dataset[0])+'">'+dataset[1];
		/*var posX = document.documentElement.scrollLeft;
		var posY = document.documentElement.scrollTop;
		this.el.style.top = (posY+event.clientY+this._y)+"px";//(target.parentNode.offsetTop + this.addTop)+"px";
		this.el.style.left = (posX+event.clientX+this._x)+"px";*/
		var targetTop = target.parentNode.parentNode.offsetTop + target.parentNode.parentNode.parentNode.offsetTop
		var targetLeft = target.parentNode.parentNode.offsetLeft + target.parentNode.parentNode.parentNode.offsetLeft; 
		this.el.style.top = (targetTop+target.parentNode.offsetTop+target.offsetHeight+2)+"px";
		this.el.style.left = (targetLeft+target.parentNode.offsetLeft+target.offsetWidth-5)+"px";
		this.el.style.display = "block";
	},
	close : function() {
		this.el.style.display = "none";
	}
}

 /* id = tooltip id, lid : list id */
/*var stockToolTip = function(id, lid, _x, _y) {
	this._x = 0;
	this._y = 0;
	if(_x) this._x = _x;
	if(_y) this._y = _y;
	this.init(id, lid);
}
stockToolTip.prototype = {
	init : function(id, lid) {
		this.el = $(id);
		this.list = $(lid);
		for (var i = 0, cnt = this.list.childNodes.length; i < cnt; ++i) {
			var ch = this.list.childNodes[i];
			if (ch.nodeType == 1) {
				var target = this.list.childNodes[i].getElementsByTagName('a')[0];
				target.comment = target.title;
				target.removeAttribute("title");
				AddEvent(target, "mouseover", this.show.bindEvent(this,ch,target));
				AddEvent(target, "mouseout", this.close.bindEvent(this,ch,target));
			}
		}
	},
	show : function(event,li,target) {
		li.insertBefore(this.el,null);
		var dataset = target.comment.split('|');
		this.el.innerHTML = '<span class="'+stockColor(dataset[0])+'">'+stockMark(dataset[0])+' &nbsp; '+dataset[1];
		this.el.style.top = this._y+"px";//(event.clientY+this._y)+"px";//(target.parentNode.offsetTop + this.addTop)+"px";
		this.el.style.left = this._x+"px";//(event.clientX+this._x)+"px";
		this.el.style.display = "block";
	},
	close : function() {
		this.el.style.display = "none";
	}
}
 */


function clickLogger(){
	var tag = '';
	try
	{
		var ref = top.document.referrer;
		var loc = top.document.location;

		var cntArg = arguments.length;
		var sc = arguments[0];
		/*	
			c1 : 종목코드
		*/

		var rootUrl = "http://log.finance.daum.net"; 
		tag = "<img name='clickLog' id='clockLog' style='display:none' src=" + "'" +  rootUrl + "/click?";
		tag += "sc=" + sc + "&";
		for ( var n=1; n<cntArg ; n++ ) {
			tag += "c"+n+"=" + arguments[n] + "&";
		}
		tag += "ref=" + encodeURIComponent(ref) + "&loc=" + encodeURIComponent(loc) + "'" ;
		tag += "width='0' height='0'>";		
	}
	catch (e) {}
	return tag;
}

/* 확장배너용 */
function extBannerOver() {
	try	{ document.getElementById('EXTENSIBLE_BANNER').style.overflow = 'visible';} catch (e){}
}
function extBannerOut() {
	try	{ document.getElementById('EXTENSIBLE_BANNER').style.overflow = 'hidden';} catch (e){}	
}

function AmsFlash(f,w,h,options){
     var param={ id:"UIswf_"+f,quality:'high',bgcolor:'#ffffff',allowScriptAccess:'always',allowFullScreen:'true'}
     Object.extend(param, options);
 
     var id='id="'+param.id+'"';
     var name = 'name="'+param.id+'"';
     var p='',e=''; 
 
     for(i in param) 
     {
          if(i=='id')continue;
          p+='<param name="'+i+'" value="'+param[i]+'">\n';
          e+=i+'="'+param[i]+'" ';
     }
     var s='<object '+id+' width="'+w+'" height="'+h+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">';
     s+='<param name="movie" value="'+f+'">'+ p; 
     s+='<embed '+name+' src="'+f+'" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" '+e+'/>';
     s+='</object>';
     if(param.containerId) {
   		var clintAgent = navigator.userAgent;
   		
		if ( clintAgent.indexOf("MSIE 6.0") != -1 && (document.location.href.indexOf("/item/quote") != -1 || document.location.href.indexOf("/item/hhmm") != -1 || document.location.href.indexOf("/item/analyst") != -1)) {
			document.getElementById(param.containerId).innerHTML = s + '<iframe src="" width="320" height="320" id="right250adDummy" frameborder="0"></iframe>';
		}else {
			document.getElementById(param.containerId).innerHTML = s;
		}
     } else {
      document.write(s);
     }
     return s;
};


/* 뉴스 폰트 변환용 */
toogle = function(id) { $(id).style.display=(getStyle($(id),'display')=='none') ? 'block':'none' };

function resizeIFrame(obj) {
	obj = (typeof obj == "string") ? document.getElementById(obj) : obj;
	obj.height = obj.contentWindow.document.body.scrollHeight;
}

function changeCompanyInfoTab(iframeSrc, onTabIdx) {
	var arr = $$("#tabSubMenu a");
	daum.Array.each(arr, function(a) { a.className = ""; });
	arr[onTabIdx].className = "on";

	$("coinfo_cp").src = iframeSrc; 
}