document.domain = "sbs.co.kr";

var commonHeader = function() {
	this.topHref = escape(top.location.href);
	this.topHostName = top.location.hostname;
	this.topPathName = top.location.pathname;

	this.dtdDefined = false;
	this.isLogin = false;
	this.params = new Array();
	this.tag = "";
	this.align = "center";
	this.logoImgName = "" // °¢ ¼­ºêº° ÀÌ¹ÌÁö °æ·Î ¹× ¸µÅ©
}

commonHeader.prototype = {
	/**
	 *	getCookie
	 *	@param	pmName : ÄíÅ° ÀÌ¸§
	 *	@return	ÄíÅ° °ª
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	ÄíÅ° °ªÀ» °¡Á®¿È
	 *	@date	2010-03-09
	 *	@time	¿ÀÈÄ 1:27:04
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	getCookie : function(pmName) {
		var prefix = pmName + "=";

		var cookieStartIndex = document.cookie.indexOf(prefix);
		if (cookieStartIndex == -1) return null;

		var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
		if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;

		return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	},

	/**
	 *	getIECheck
	 *	@param	-
	 *	@return	IE ¿©ºÎ
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	IE ¿©ºÎ¸¦ Ã¼Å©
	 *	@date	2010-01-13
	 *	@time	¿ÀÈÄ 3:19:51
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	getIECheck : function() {
		return (/*@cc_on!@*/false) ? true : false;
	},

	/**
	 *	getLogin
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	·Î±×ÀÎ
	 *	@date	2010-03-09
	 *	@time	¿ÀÈÄ 1:35:09
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	getLogin : function() {
		if(!ch.isLogin)	{
			top.location.href = "http://login.sbs.co.kr/Login/login.jsp?Login_ReturnURL="+ch.topHref;
		}	else {
			alert("ÀÌ¹Ì ·Î±×ÀÎ ÁßÀÔ´Ï´Ù.");
			top.location.reload();
		}
	},

	/**
	 *	getLogout
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	·Î±×¾Æ¿ô
	 *	@date	2010-03-09
	 *	@time	¿ÀÈÄ 1:35:09
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	getLogout : function() {
		if(ch.isLogin)	{
			top.location.href = "http://login.sbs.co.kr/Login/logout.jsp?Logout_ReturnURL="+ch.topHref;
		}	else {
			alert("·Î±×¾Æ¿ô ÁßÀÔ´Ï´Ù.");
			top.location.reload();
		}
	},

	/**
	 *	getProgramList
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	ÇÁ·Î±×·¥ ¸®½ºÆ® display ÄÁÆ®·Ñ
	 *	@date	2010-01-13
	 *	@time	¿ÀÈÄ 3:19:51
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	getProgramList : function() {
		var expandListDisplay = document.getElementById("channelList").style.display;

		if(expandListDisplay == "none") {
			document.getElementById("globalProgramListBtn").src = "http://img.sbs.co.kr/s9/subCommon/sbs_menu06_on.gif";
			document.getElementById("global_right_area").style.display = "none";
			document.getElementById("channelList").style.display = "";
		} else {
			document.getElementById("globalProgramListBtn").src = "http://img.sbs.co.kr/s9/subCommon/sbs_menu06.gif";
			document.getElementById("global_right_area").style.display = "";
			document.getElementById("channelList").style.display = "none";
		}
	},

	/**
	 *	setDtdDefined
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	dtd °¡ ¼±¾ðµÈ ÆäÀÌÁö ÀÎÁö Ã¼Å©ÇÏ¿© °ª ¼³Á¤
	 *	@date	2010-01-13
	 *	@time	¿ÀÈÄ 3:19:51
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	setDtdDefined : function() {
		if(ch.getIECheck()) {
			if(document.childNodes[0].nodeValue != null) {
				if((document.childNodes[0].nodeValue).indexOf("DTD") > -1) {
					//document.childNodes[0].nodeValue = "DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"";
					ch.dtdDefined = true;
				}
			}
		} else {
			ch.dtdDefined = document.doctype != null ? true : false;
			//dtdDefined = document.doctype.publicId;
		}
	},

	/**
	 *	setDisplay
	 *	@param	pmObjId	: ¿ÀºêÁ§Æ® ¾ÆÀÌµð
	 *	@param	pmDisplay	: display ¼Ó¼º
	 *	@return	-
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	¿ÀºêÁ§Æ® display ¼Ó¼º ÄÁÆ®·Ñ
	 *	@date	2010-01-13
	 *	@time	¿ÀÈÄ 3:19:51
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	setDisplay : function(pmObjId, pmDisplay) {
		var obj = document.getElementById(pmObjId);

		if(obj != null) {
			if(pmDisplay == "") {
				if(obj.style.display == "" || obj.style.display == "none") {
					obj.style.display = "block";
				} else {
					obj.style.display = "none";
				}
			} else {
				obj.style.display = pmDisplay;
			}
		}
	},

	/**
	 *	setHead
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	head ¿¡ Ãß°¡
	 *	@date	2010-01-13
	 *	@time	¿ÀÈÄ 3:19:51
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	setHead : function() {
		var element = ch.params["element"] != null ? ch.params["element"] : "";
		var url = ch.params["url"] != null ? ch.params["url"] : "";

		var docHead = document.getElementsByTagName("head");
		var newElement = document.createElement(element);

		if(element == "script") {
			newElement.type = "text/javascript";
			newElement.src = url;
		} else if(element == "link") {
			newElement.rel = "stylesheet";
			newElement.type = "text/css";
			newElement.href = url;
		}

		docHead[0].appendChild(newElement);
	},

	/**
	 *	setSearch
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	°Ë»ö submit
	 *	@date	2010-03-09
	 *	@time	¿ÀÈÄ 1:43:07
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	setSearch : function() {
		document.getElementById("grobalSearch").submit();
	},

	/**
	 *	setSearchKeypress
	 *	@param	e : key event
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	°Ë»ö input ¿¡¼­ ¿£ÅÍÅ° ÀÔ·Â½Ã °Ë»ö submit
	 *	@date	2010-03-09
	 *	@time	¿ÀÈÄ 1:43:07
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	setSearchKeypress : function(e) {
		var eventKeyCode = null;

		if(window.event) {
			eventKeyCode = window.event.keyCode;
		}	else if(e) {
			eventKeyCode = e.which;
		}

		if(eventKeyCode == 13) ch.setSearch();
	}
}

// header °´Ã¼ »ý¼º
var ch = new commonHeader();

// dtd Ã¼Å©
ch.setDtdDefined();

// ·Î±×ÀÎ Ã¼Å©
ch.isLogin = ch.getCookie("SBS_ID") != null ? true : false;

// script »ðÀÔ
ch.params["element"] = "script";
if(ch.topHostName == "sbscnbc.sbs.co.kr") {
	ch.params["url"] = "http://www.sbs.co.kr/vobos/common/js/common_header_sbscnbc.js";
} else {
	ch.params["url"] = "http://www.sbs.co.kr/vobos/common/js/common_header_sbs.js";
}
ch.setHead();