function StockPrintPage() {
	window.print();
}

function StockMoveLogin() {
	location.href = "http://xo.nate.com/login.jsp?redirect=" + location.href;
}

function StockPopupResize(w, h, run_resize) {

	var listBody = document.body;

	var nWidth = w;
	var nHeight = h;
	var nHeightXP = 0;

	// 사이즈가 지정되지 않은 경우(0)는 body 사이즈로
	if (nWidth == 0) {
		nWidth = listBody.scrollWidth;
	}

	if (nHeight == 0) {
		nHeight = listBody.scrollHeight + 30;
	}

	// XP인 경우 height 29 추가
	if (window.navigator.userAgent.indexOf("SV1") != -1) {
		nHeightXP = 30;
	}

	if (window.navigator.userAgent.indexOf("7.") != -1) {
		nHeightXP += 45;
	}

	if (nHeight <= 800) {
		try {
			self.resizeTo(nWidth, nHeight + nHeightXP);
		} catch (e) {
		}
	} else {
		try {
			self.resizeTo(nWidth, nHeight + nHeightXP);
		} catch (e) {
		}
	}

	// 가운데 이동
	try {
		run_resize = typeof (run_resize) == "undefined" ? false : run_resize;

		if (run_resize) {
			var TopPos = (screen.height / 2) - (nHeight / 2);
			var LeftPos = (screen.width / 2) - (nWidth / 2);
			window.moveTo(LeftPos, TopPos);
		}
	} catch (e) {
	}

}

// 0.1초마다 이미지 전송 완료 체크 후 리사이징
function StockImageResize(imageName) {

	try {

		obj = document.images[imageName];

		if (obj.complete) {
			obj.org_height = obj.height;
			obj.org_width = obj.width;

			if (obj.width > STOCK_IMAGE_MAX_WIDTH) {
				obj.height = (STOCK_IMAGE_MAX_WIDTH * obj.height) / obj.width;
				obj.width = STOCK_IMAGE_MAX_WIDTH;
			}
		} else {
			setTimeout('StockImageResize(\'' + imageName + '\')', 100);
		}

	} catch (e) {
		alert(e.message);
	}

}

// 이미지 클릭시 원본 이미지 팝업
function StockImagePopup(imageName) {
	obj = document.images[imageName];
	window.open(obj.src);
}

// 뉴스 인쇄보기 팝업
function StockNewsPrintPage(url) {
	var viewpage = window.open(url, 'StockNewsPrintPopup',
			'scrollbars=1,resizable=1,left=0,top=0,width=595,height=600');
	viewpage.focus();
}

// 종목진단, 종목추천 보기
function StockInvestmentRead(url) {

	var width = 700;
	var height = 700;

	var TopPos = (screen.height / 2) - (height / 2);
	var LeftPos = (screen.width / 2) - (width / 2);

	var wnd = window.open(url, '', 'scrollbars=1, resizable=0, left=' + LeftPos
			+ ',top=' + TopPos + ',width=' + width + ',height=' + height);
	wnd.focus();

}

function StockIframeResizer(iframe_id) {
	this._Timer = null;
	this._FrameObj = document.getElementById(iframe_id);
	this._bIE = (/MSIE/.test(navigator.userAgent)) ? true : false;
	this._nCheckInterval = 50;
	this._bWatch = false;
	this._initVar();
}

function StockRightMultiBoxTab(OBJ) {
	if (OBJ == "1") {
		rtab1.style.display = "";
		rtab2.style.display = "none";
		rtab3.style.display = "none";
	} else if (OBJ == "2") {
		rtab1.style.display = "none";
		rtab2.style.display = "";
		rtab3.style.display = "none";
	} else {
		rtab1.style.display = "none";
		rtab2.style.display = "none";
		rtab3.style.display = "";
	}
}

function StockRightTodayTab(OBJ) {
	if (OBJ == "1") {
		r2tab1.style.display = "";
		r2tab2.style.display = "none";
	} else {
		r2tab1.style.display = "none";
		r2tab2.style.display = "";
	}
}

function StockIndexMainTab(OBJ) {
	if (OBJ == "1") {
		stockimg1.src = "/image/mtop_mn01_on.gif";
		stockimg2.src = "http://img.nate.com/img/stock/2007/mtop_mn02_off.gif";
		stockimg3.src = "http://img.nate.com/img/stock/2007/mtop_mn03_off.gif";
		stockimg4.src = "http://img.nate.com/img/stock/2007/mtop_mn04_off.gif";

		stockChart1.style.display = "";
		stockChart2.style.display = "none";
		stockChart3.style.display = "none";
		stockChart4.style.display = "none";

		stockBox1.style.display = "";
		stockBox2.style.display = "none";
		stockBox3.style.display = "none";
		stockBox4.style.display = "none";
	} else if (OBJ == "2") {
		stockimg1.src = "/image/mtop_mn01_off.gif";
		stockimg2.src = "http://img.nate.com/img/stock/2007/mtop_mn02_on.gif";
		stockimg3.src = "http://img.nate.com/img/stock/2007/mtop_mn03_off.gif";
		stockimg4.src = "http://img.nate.com/img/stock/2007/mtop_mn04_off.gif";

		stockChart1.style.display = "none";
		stockChart2.style.display = "";
		stockChart3.style.display = "none";
		stockChart4.style.display = "none";

		stockBox1.style.display = "none";
		stockBox2.style.display = "";
		stockBox3.style.display = "none";
		stockBox4.style.display = "none";
	} else if (OBJ == "3") {
		stockimg1.src = "/image/mtop_mn01_off.gif";
		stockimg2.src = "http://img.nate.com/img/stock/2007/mtop_mn02_off.gif";
		stockimg3.src = "http://img.nate.com/img/stock/2007/mtop_mn03_on.gif";
		stockimg4.src = "http://img.nate.com/img/stock/2007/mtop_mn04_off.gif";

		stockChart1.style.display = "none";
		stockChart2.style.display = "none";
		stockChart3.style.display = "";
		stockChart4.style.display = "none";

		stockBox1.style.display = "none";
		stockBox2.style.display = "none";
		stockBox3.style.display = "";
		stockBox4.style.display = "none";
	} else {
		stockimg1.src = "/image/mtop_mn01_off.gif";
		stockimg2.src = "http://img.nate.com/img/stock/2007/mtop_mn02_off.gif";
		stockimg3.src = "http://img.nate.com/img/stock/2007/mtop_mn03_off.gif";
		stockimg4.src = "http://img.nate.com/img/stock/2007/mtop_mn04_on.gif";

		stockChart1.style.display = "none";
		stockChart2.style.display = "none";
		stockChart3.style.display = "none";
		stockChart4.style.display = "";

		stockBox1.style.display = "none";
		stockBox2.style.display = "none";
		stockBox3.style.display = "none";
		stockBox4.style.display = "";
	}
}

function StockIndexForeignTab(OBJ) {
	if (OBJ == "1") {
		fotab1.style.display = "";
		fotab2.style.display = "none";
	} else {
		fotab1.style.display = "none";
		fotab2.style.display = "";
	}
}

function StockIndexOfficialTab(OBJ) {
	if (OBJ == "1") {
		kotab1.style.display = "";
		kotab2.style.display = "none";
	} else {
		kotab1.style.display = "none";
		kotab2.style.display = "";
	}
}

function StockIndexRunNewsTicker() {
	if (TickerData.SpanObj == null) {
		TickerData.SpanObj = document.getElementById('news_ticker');
	}

	if (TickerData.CurIdx >= TickerData.MaxIdx)
		TickerData.CurIdx = 0;

	var content = TickerData.Contents[TickerData.CurIdx];
	TickerData.SpanObj.innerHTML = "<a href='/news/section/read/section/ns01/keynum/"
			+ content[0] + "'>" + content[1] + "</a>";

	TickerData.CurIdx++;
}

function StockIndexRunSlide() {

	if (idxIndexSlide > 4)
		idxIndexSlide = 1;
	for ( var i = 1; i < 5; i++) {
		var obj = eval("world" + i);
		if (i == idxIndexSlide) {
			obj.style.display = "";
		} else {
			obj.style.display = "none";
		}
	}
	idxIndexSlide++;

}

StockIframeResizer.prototype = {
	/**
	 * 리사이징 호출. 내부적으로 _realResize() 함수 호출
	 */
	resize : function() {
		try {
			if (this._Timer != null) {
				this._stopTimer();
			}

			this._realResize._context = this;
			this._Timer = setInterval(this._realResize, this._nCheckInterval);
		} catch (e) {
		}
	},

	/**
	 * 실질적인 리사이징 함수
	 */
	_realResize : function() {
		try {
			// 실행 Context 구하기
			var context = typeof (arguments.callee._context) != "undefined" ? arguments.callee._context
					: this;

			if (!context._bWatch) {
				// 최대 체크 회수 제한
				if (context._nTries >= context._nMaxTries) {
					context._stopTimer();
					return;
				}

				// 종료 체크 (IE : 로딩이 끝났을 경우, FF : 같은 높이가 3번 반복될 때)
				if ((context._bIE && context._FrameObj.readyState == "complete" && context._nTries > 0)
						|| (context._nSameHeightCnt >= 3)) {
					context._stopTimer();
					return;
				}
			}

			// 크기 구해서 리사이징
			var FrameObj = context._FrameObj;

			if (context._bIE) {
				var innerHeight = FrameObj.contentWindow.document.body.scrollHeight;
			} else {
				var innerHeight = FrameObj.contentDocument.body.offsetHeight + 35;
			}

			FrameObj.style.height = innerHeight + "px";

			// 이전 저장된 높이로 같은 회수 저장
			if (!context._bWatch) {
				if (context._nPrevHeight == innerHeight) {
					context._nSameHeightCnt++;
				} else {
					context._nPrevHeight = innerHeight;
					context._nSameHeightCnt = 0;
				}

				context._nTries++;
			}
		} catch (e) {
		}
	},

	/**
	 * 타이머 종료
	 */
	_stopTimer : function() {
		clearInterval(this._Timer);
		this._initVar();
	},

	/**
	 * 내부 변수 초기화
	 */
	_initVar : function() {
		this._Timer = null;
		this._nTries = 0;
		this._nMaxTries = 10;
		this._nSameHeightCnt = 0;
		this._nPrevHeight = 0;
	},

	/**
	 * 프레임의 크기 변경 감시 활성화
	 */
	enableWatch : function() {
		this._bWatch = true;
	},

	/**
	 * 프레임의 크기 변경 감시 비활성화
	 */
	disableWatch : function() {
		this._bWatch = false;
	},

	/**
	 * 리사이징 함수 실행 간격
	 */
	setCheckInterval : function(nVal) {
		this._nCheckInterval = nVal;
	}
}

function StockIframeResizeHeight(id, height) {
	h = parseInt(height);
	var iframe = document.getElementById(id);
	iframe.style.height = h + "px";
}
