 var siteDomain = "http://magazine.joins.com" ;
//************************************************
// str ÀÌ °ø¹éÀÌ³ª NULL ÀÌ¸é TRUE ¾Æ´Ï¸é FALSE  *
//************************************************
function isEmpty(str) {
	if( str != null )
	{
		for( i=0 ; i < str.length ; i++)
		{
			if( !isWhiteChar( str.charAt(i) ) )
				return false;
		}
	}
	return ((str == null) || (str.length == 0));
}

//****************************************************************************
// str ÀÌ °ø¹éÀÌ³ª ÅÜ , ¸®ÅÏ ¹®ÀÚµé·Î ½ÇÁ¦¹®ÀÚ°¡ ¾øÀ»°æ¿ì TRUE ¾Æ´Ï¸é FALSE *
//****************************************************************************
function isWhitespace (str) {
	var whitespace = " \t\n\r";
	var i;
	if (isEmpty(str)) {
		return true;
	}
	for (i = 0; i < str.length; i++) {
		var chr = str.charAt(i);
		if (whitespace.indexOf(chr) == -1) {
			return false;
		}
	}
	return true;
}

//****************************************************************************
// Char  C°¡ whitechar ÀÎÁö Ã¼Å©
//****************************************************************************
function isWhiteChar(c)
{
	 return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
}


//************************************************
//¾ÆÀÌµðÀúÀå°ü·Ã ÇÔ¼öµé							 *
//************************************************

function SetUserid() 	{

	var strUserID, strUserPasswd;
	strUserID = document.LoginFrm.txtId.value;
	strUserPasswd = document.LoginFrm.txtPasswd.value;

	if( isEmpty(strUserID) )	{
			alert("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			document.LoginFrm.txtId.focus();
	}
	else if( isEmpty(strUserPasswd) ) {
			alert("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			document.LoginFrm.txtPasswd.focus();
	
	}
	else if (strUserID == "" || strUserPasswd == "" || strUserID == null)	{
			alert("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			document.LoginFrm.txtId.focus();
	
	} 
	else	{
		var expiry = new Date();
		var path = "/";
		var domain = document.domain;
		var secure = "";
		if (document.LoginFrm.idchk.checked == true)	{		
			expiry.setTime(expiry.getTime() + 90 * (24 * 60 * 60 * 1000));
			setCookie("pop_magazine",strUserID,expiry,path,domain,secure);
			document.LoginFrm.submit();
		}
		else{
			expiry = expiry.setFullYear(1900);
			delCookie("pop_magazine",strUserID,expiry,path,domain,secure);
			document.LoginFrm.submit();
		}
	}
	
}


//************************************************
//ÀÎ±â ¿¬Àç¹° ±â»ç ¸®½ºÆ®						 *
//************************************************
function callSeries(pAid, pSourceCode){
	var requestUrl = "/article/getSeriesArticle.asp?aid=" + pAid + "&sourcecode=" +pSourceCode;	
	yAjax.open("get",requestUrl,true,null,"TEXT","displySeries")
}
  
function displySeries(pStr){
	var displayObj = document.getElementById("M_Series");
	if (pStr=="")
		displayObj.style.display = "none";
	else
		displayObj.innerHTML = pStr;
}

//************************************************
//Áö³­È£ º¸±â Select List						 *
//************************************************
function callPress(pSourceCode){
	var requestUrl = siteDomain + "/article/getPress.asp?sourcecode=" +pSourceCode;	
	yAjax.open("get",requestUrl,true,null,"TEXT","displyPress")
}
  
function displyPress(pStr){
	var displayObj = document.getElementById("M_PressList");
	if(pStr == "")
		displayObj.style.display = "none";
	else
		displayObj.innerHTML = pStr;
}

//************************************************
//ÆíÁýÀå¿¡°Ô ÇÑ¸¶µð °Ô½ÃÆÇÀ¸·Î ÀÌµ¿				 *
//************************************************
function goBBS(pSourceCode){
	var bbsName = "";
	if(pSourceCode=="MM")
		 bbsName = "mmtalk";
	else if(pSourceCode=="ME")
		 bbsName = "metalk";
	else if(pSourceCode=="MW")
		 bbsName = "mwtalk";
	else if(pSourceCode=="MF")
		 bbsName = "mftalk";

	location.href ="http://bbs.joins.com/list.asp?tb_name=" + bbsName;
}

//************************************************
//ÀÎ±â ¿¬Àç¹° ¸®½ºÆ®·Î ÀÌµ¿						 *
//************************************************
// function goListSeries(pObj){	
//	location.href = "article_list.asp?catcode=" + pObj.options[pObj.selectedIndex].value;
// }

function goListSeries(pObj, pSourceCode){	
	var strDirectory = "";
	if(pSourceCode=="MM")
		strDirectory = siteDomain + "/monthly/";
	else if(pSourceCode=="ME")
		strDirectory = siteDomain + "/economist/";
	else if(pSourceCode=="MW")
		strDirectory = siteDomain + "/newsweek/";
	else if(pSourceCode=="MF")
		strDirectory = siteDomain + "/forbes/";
	
	location.href = strDirectory + "article_list.asp?catcode=" + pObj.options[pObj.selectedIndex].value;
 }

//************************************************
//Áö³­ È£ º¸±â ¸®½ºÆ®·Î ÀÌµ¿					 *
//************************************************
function goListPress(pObj, pSource){
	var strDirectory = "";
	var selectValue = pObj[pObj.selectedIndex].value ;

	if (pSource =="10"){
			strDirectory = "/monthly/";
	}
	else if	(pSource =="11"){
		strDirectory = "/economist/";
	}
	else if	(pSource =="14"){
		strDirectory = "/newsweek/";
	}
	else if	(pSource =="15"){
		strDirectory = "/forbes/";
	}
	else{
		strDirectory = "";
	}


	if (selectValue == "more"){
		location.href=siteDomain  +strDirectory +"search.asp?source="+pSource;
	}
	else{		
		location.href= siteDomain  +strDirectory+ "search.asp?source="+pSource+"&hosu=" + escape(selectValue);
	}
}

//************************************************
//±â»ç ¸®½ºÆ®·Î ÀÌµ¿							 *
//************************************************
//function goList(pSCode){
//	location.href = "article_list.asp?catcode=" + pSCode;
//}

function goList(pSCode, pSourceCode){
	var strDirectory = "";
	if(pSourceCode=="MM")
		strDirectory = siteDomain + "/monthly/";
	else if(pSourceCode=="ME")
		strDirectory = siteDomain + "/economist/";
	else if(pSourceCode=="MW")
		strDirectory = siteDomain + "/newsweek/";
	else if(pSourceCode=="MF")
		strDirectory = siteDomain + "/forbes/";

	location.href = strDirectory + "article_list.asp?catcode=" + pSCode;
}


//----------------------------------------------------
// ************** ±â»ç °ü·Ã ÇÔ¼ö ****************   
//----------------------------------------------------    
    var arrFontSize   = [12,14,16,18,20,24];
    var arrLineHeight = [19,21,23,27,30,32];

    var article_fontSize = parseInt(getCookie("article_fontSize"));
	if (article_fontSize == null)
	{
		article_fontSize = 3;
	}
    function fontPlus(pObj) {	
    	if (article_fontSize < (arrFontSize.length-1)) {
    		article_fontSize = article_fontSize + 1; 
    		setFont(article_fontSize,pObj); 
    	}
    }
    
    function fontMinus(pObj) {
    	if(article_fontSize > 0){
    		article_fontSize = article_fontSize - 1; 
    		setFont(article_fontSize,pObj); 
    	}
    }       

    function initFont(pObj){ 
	    if (isNaN(article_fontSize) == true) {
		    article_fontSize = 2;	
	    }else if(eval(article_fontSize)>=arrFontSize.length){
	        article_fontSize = 2;	
        }
	    setFont(article_fontSize, pObj);
    }

    function setFont(article_fontSize, pObj){ 	
		var obj = document.getElementById(pObj);
		if (obj != null)
		{
			obj.style.fontSize = arrFontSize[article_fontSize]+"px";
			obj.style.lineHeight = arrLineHeight[article_fontSize] + "px";
			setFontCookie(article_fontSize);
		}	    
    }	

    function setFontCookie(article_fontSize) {

    	var expiry = new Date();
    	var path = "/";
    	var domain = document.domain;
    	var secure = "";
    	
	    expiry.setTime(expiry.getTime() + 90 * (24 * 60 * 60 * 1000));
	    setCookie("article_fontSize",article_fontSize,expiry,path,domain,secure);
    }    
    
    
    function ArticlePrint(pAid, pGubun,pSourceCode){
		if (pGubun == "BL")
			popupWindow(siteDomain+"/magazine/_include/printArticle.asp?aid="+pAid,"print",800,650,"yes");	        
		else
			popupWindow(siteDomain+"/article/printArticle.asp?aid="+pAid+"&path="+pSourceCode,"print",800,650,"yes");
    }

    function ArticleEmail(){
        popupWindow(siteDomain+"/article/mailArticle.asp","email",510,560,"no");
    }    

    function ArticleBlogScrap(aid,pGubun,pCode) {
		var at_viewUrl = "http://magazine.joins.com/";
		var at_articleUrl = "";
		var at_sourcecode = "";
		if (pCode=="01"){
			at_viewUrl += "monthly";
			at_source = "¿ù°£Áß¾Ó";
			at_sourcecode = "MM";
		}
		else if(pCode=="02"){
			at_viewUrl += "economist";
			at_source = "ÀÌÄÚ³ë¹Ì½ºÆ®";
			at_sourcecode = "ME";
		}
		else if(pCode=="03"){
			at_viewUrl += "newsweek";
			at_source = "´º½ºÀ§Å©";
			at_sourcecode = "MW";
		}
		else{
			at_viewUrl += "forbes";
			at_source = "Æ÷ºê½º";
			at_sourcecode = "MF";
		}
		at_articleUrl = at_viewUrl + "/view.asp?aid="+aid;
		/*
	    with(document.frmSaveBlog){
	        action = "http://blog.joins.com/center/joins/outbound_scrap_pre.asp";	    
	        user_id.value = getCookieA("MemArray","MemID");	    	        
	        source.value = "<a href='"+at_viewUrl+"/'>[¸Å°ÅÁø-"+at_source+"]</a> <a href='"+at_articleUrl+"'>±â»ç º»¹® ÀÐ±â</a>";	    
	        board_idx.value = aid;
	        subject.value = document.getElementById("M_Title").innerHTML;
	        //content.value = "<table width='675' cellspacing='0' cellpadding='0' border='0'>" + document.getElementById("M_htmlBody").innerHTML + "</table>";
			content.value = "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td>" + document.getElementById("M_htmlBody").innerHTML + "</td></tr></table>";
	        //content.value = "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td id='articleBody' class='article04'>" + document.getElementById("M_htmlBody").innerHTML + "</td></tr></table>";
	        window.open("about:blank","Blog","toolbar=no, location=0, directory=no, status=no, menubar=no, scrollbars=no, resizable=yes, top=200, left=350, width=200, height=200");      
	        target = "Blog";
	        submit();
        }	    
		*/
		var openUrl = "";
		if (pGubun == "BL")
			openUrl = "http://magazine.joins.com/magazine/_include/sendBlogArticle.asp?aid=" + aid+"&path="+at_sourcecode;
		else
			openUrl = "http://magazine.joins.com/article/sendBlogArticle.asp?aid=" + aid+"&path="+at_sourcecode;

		window.open(openUrl,"Blog","toolbar=no, location=0, directory=no, status=no, menubar=no, scrollbars=no, resizable=yes, top=200, left=350, width=200, height=200");      
    }    

//************************************************
//ÀÎµ¦½º ¼îÄÉÀÌ½º °ü·Ã ÇÔ¼ö						 *
//************************************************
function onLoadShowCase(pObj,pObjNum){
	var objCol = document.getElementsByName("M_Home_Showcase_01");
	var imgObj = null;
	var imgIdx = 0;
	for (var idx=0 ; idx < objCol.length ; idx++ )
	{
		imgIdx = idx+1;
		imgObj = document.getElementById("M_Tab_0" +imgIdx);
		imgObj.style.display = "block";
	}
	tabOver(pObj, pObjNum);
}

function tabOver(pObj, pObjNum){
	tabOut(pObj, pObjNum);
	var objNum = eval(pObjNum) - 1;
	var divObjCol = document.getElementsByName("M_Home_Showcase_01");
	var nowDivObj = divObjCol[nowShowCase];
	var nextDivObj = divObjCol[objNum];

	if (nowDivObj == null)
	{
		nowDivObj = divObjCol[0];
	}

	if (nextDivObj == null){
		nextDivObj = divObjCol[0];
	}

	nowDivObj.style.display = "none";
	nextDivObj.style.display = "block";
	nowShowCase = objNum ;
}

function tabOut(pObj,pObjNum){ 
	var imgIdx = "0" + eval(nowShowCase + 1) ;
	var prevImgObj = document.getElementById("M_Tab_"+imgIdx);
	var prevImgOff = "http://images.joins.com/ui_joins/magazine07/btn_"+imgIdx+"_off.gif";
	var nextImgOn = "http://images.joins.com/ui_joins/magazine07/btn_"+pObjNum+"_on.gif";
	var nextImgObj = pObj;
	if (prevImgObj == null)
	{
		prevImgObj = document.getElementById("M_Tab_01")
  	    prevImgOff = "http://images.joins.com/ui_joins/magazine07/btn_01_off.gif";
	}
	if (nextImgObj == null)
	{
		nextImgObj = document.getElementById("M_Tab_01")
		nextImgOn = "http://images.joins.com/ui_joins/magazine07/btn_01_on.gif";
	}

	prevImgObj.src = prevImgOff;	
	nextImgObj.src = nextImgOn;
}

/*
function tabOver(pObj, pObjNum){
	var divID = "M_Home_Showcase_"
	tabOut(pObj, pObjNum);
	var nowDivObj = document.getElementById(divID + nowShowCase);
	var nextDivObj = document.getElementById(divID + pObjNum);

	if (nowDivObj == null)
	{
		nowDivObj = document.getElementById("M_Home_Showcase_01");
	}

	if (nextDivObj == null){
		nextDivObj = document.getElementById("M_Home_Showcase_01");
	}

	nowDivObj.style.display = "none";
	nextDivObj.style.display = "block";
	nowShowCase = pObjNum ;
}

function tabOut(pObj,pObjNum){ 
	var prevImgObj = document.getElementById("M_Tab_"+nowShowCase);
	var prevImgOff = "http://images.joins.com/ui_joins/magazine07/btn_"+nowShowCase+"_off.gif";
	var nextImgOn = "http://images.joins.com/ui_joins/magazine07/btn_"+pObjNum+"_on.gif";
	var nextImgObj = pObj;
	if (prevImgObj == null)
	{
		prevImgObj = document.getElementById("M_Tab_01")
  	    prevImgOff = "http://images.joins.com/ui_joins/magazine07/btn_01_off.gif";
	}
	if (nextImgObj == null)
	{
		nextImgObj = document.getElementById("M_Tab_01")
		nextImgOn = "http://images.joins.com/ui_joins/magazine07/btn_01_on.gif";
	}

	prevImgObj.src = prevImgOff;	
	nextImgObj.src = nextImgOn;
}
*/
function onLoadShowCase2(pObj){
	var showcaseObj = document.getElementById(pObj);
	showcaseObj.style.display = "block";
}


//************************************************
//°¡Àå ¸¹ÀÌ º» ±â»ç Á¶È¸						 *
//************************************************

function displayBestClick(pObj,pXsl){
    var xmlhttp = false;    
    var aid;
    var curUrl = location.href; 
    var bestclick_xml = "http://magazine.joins.com/_include/html/bestclick.xml";
	var bestclick_xsl = "http://magazine.joins.com/counter/"+pXsl+".xsl";

		xmlhttp = createHttpRequest();    
		if(!xmlhttp) return "Áö¿øÇÏÁö ¾Ê´Â ºê¶ó¿ìÁ®ÀÔ´Ï´Ù.";   
		
		if (curUrl.indexOf("magazine.joins.com") < 0)
		{
			return;
		}
		
		// load XML
		xmlhttp.open("GET", bestclick_xml, false);
		xmlhttp.send(null);

		if(xmlhttp.readyState == 4){
			if(xmlhttp.status == 200){
				var xmlDoc = xmlhttp.responseXML;
			}else{
				xmlhttp.open("GET", 0., false);
				xmlhttp.send(null);            
				var xmlDoc = xmlhttp.responseXML;
			}
		}else
			exit;  


		if(window.ActiveXObject){        
			// load xsl
			xmlhttp.open("GET", bestclick_xsl, false);
			xmlhttp.send(null);
			bestclick_xslt = xmlhttp.responseXML;
			
			var tmpHtml = xmlDoc.transformNode(bestclick_xslt);
			document.getElementById(pObj).innerHTML=tmpHtml;        

		}else{
			// load xsl
//			if(bestclick_xslProc==null){
				bestclick_xslProc = new XSLTProcessor();
				xmlhttp.open("GET",bestclick_xsl,false);
				xmlhttp.send(null);            
				bestclick_xslProc.importStylesheet(xmlhttp.responseXML);
//			}            

			var oResultFragment = bestclick_xslProc.transformToFragment(xmlDoc,document);                 
			var oDiv = document.getElementById(pObj);        
			if(oDiv.childNodes.length>0)oDiv.removeChild(oDiv.childNodes[0]);
			oDiv.appendChild(oResultFragment);     
			
			// Æ¯¼ö¹®ÀÚ Ã³¸®(firefox¶§¹®¿¡)
			tmpHtml = oDiv.innerHTML;        
			tmpHtml = replace(tmpHtml,"&lt;","<");
			tmpHtml = replace(tmpHtml,"&gt;",">");
		   oDiv.innerHTML = replace(tmpHtml,"&amp;","&");        
		}
}    
