document.domain = "sbs.co.kr";

var commonHeader = function() {
	this.topHref = encodeURIComponent(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 = ""; // °¢ ¼­ºêº° ÀÌ¹ÌÁö °æ·Î ¹× ¸µÅ©
	this.searchUrl = "http://search.sbs.co.kr/search.jsp";
}

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(obj) {
		var expandListDisplay = document.getElementById("service_channel").style.display;

		if(expandListDisplay == "none") {
			obj.className="on";
			document.getElementById("gnb_ad").style.display = "none";
			document.getElementById("service_channel").style.display = "";
		} else {
			obj.className="off";
			document.getElementById("gnb_ad").style.display = "";
			document.getElementById("service_channel").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;
		}
	},
	
	// DIV ÆäÀÌÂ¡ < (pre) ¹öÆ°		 		
	prePage : function(list){			
		var cur_page = document.getElementById('common_gnb_'+list+'_curent').value;
		var max_page = document.getElementById('common_gnb_'+list+'_total').value;		
		if( cur_page == 1 ) document.getElementById('common_gnb_'+list+'_curent').value=max_page;			
		else document.getElementById('common_gnb_'+list+'_curent').value=cur_page - 1;		
		document.getElementById('common_gnb_'+list+'_'+cur_page).style.display='none';
		document.getElementById('common_gnb_'+list+'_'+(document.getElementById('common_gnb_'+list+'_curent').value)).style.display='block';		
	},	

	// DIV ÆäÀÌÂ¡ > (next) ¹öÆ°		 				
	nextPage : function(list){
		var cur_page = document.getElementById('common_gnb_'+list+'_curent').value;
		var max_page = document.getElementById('common_gnb_'+list+'_total').value;	
		if( cur_page == max_page ) document.getElementById('common_gnb_'+list+'_curent').value='1';			
		else document.getElementById('common_gnb_'+list+'_curent').value=parseInt(cur_page) + 1;					
		document.getElementById('common_gnb_'+list+'_'+cur_page).style.display='none';
		document.getElementById('common_gnb_'+list+'_'+(document.getElementById('common_gnb_'+list+'_curent').value)).style.display='block';		
	},

	/**
	 *	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);
	},

	getRadioValue : function(radioObj) {
		var cnt = radioObj.length;
 		var value = '';
 
 		for (i = 0; i < cnt; i++) {
  		if (radioObj[i].checked) {
   			value = radioObj[i].value;
  		}
 		}
 
 		return value;
	},
	
	/**
	 *	setSearch
	 *	@param	-
	 *	@return	void
	 *	@throws	-
	 *	@author	sbrave3
	 *	@since	-
	 *	@todo	°Ë»ö submit
	 *	@date	2010-03-09
	 *	@time	¿ÀÈÄ 1:43:07
	 *	<pre>
	 *		-
	 *	</pre>
	 */
	setSearch : function() {
		var searchDomain =  ch.getRadioValue(cm.getObjs("tsearch"));
		var query = cm.getObj("sub_search_input");
		var searchForm = document.getElementById("grobalSearch");
		
		if (searchDomain == 'cnbc') {
			searchForm.action = 'http://search.sbs.co.kr/search_cnbc.jsp';
			searchForm.submit();
			
		} else if (searchDomain = 'mad') {
			window.open('http://www.madmoney.co.kr/signal/frmSignMain.asp?pMenuId=nowsign&ICode=' + query.value, 'madmoneySearch', '');
		}
		
	},

	/**
	 *	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";

ch.params["url"] = "http://www.sbs.co.kr/vobos/common/js/common_header_sbs2.js";

ch.setHead();

//À¥·Î±× ºÐ¼® ½ºÅ©¸³Æ®
ch.params["element"] = "script";
ch.params["url"] = "http://img.sbs.co.kr/sw11/common/makePCookie.js";
ch.setHead();
