function setSemiCookie(name, value, expires) 
{
	var expires = expires === undefined ? new Date(2020, 1, 1) : new Date(1900, 1, 1);
	setCookie(name, value, expires, '/');
}	
	
function setCookie(name, value)
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + value +
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path=" + path))+
		((domain==null) ? "" : ("; domain=" + domain))+
		((secure==true) ? "; secure" : "");
}
function getCookie(strName)
{
	var nStart = document.cookie.indexOf(strName + '=');
	if (nStart != -1)
	{
		nStart = nStart + strName.length + 1;
		var nEnd = document.cookie.indexOf(';', nStart);
		if (nEnd == -1)
			nEnd = document.cookie.length;
		return document.cookie.substring(nStart, nEnd);
	}
	return null;
}

function ViewGNBLayer(sLayerName)
{
	document.getElementById(sLayerName).style.display = (document.getElementById(sLayerName).style.display == "none" ? "block":"none");
}

function gotoMyTong()
{
	if (_GetCookieValue('GUID'))
		if (_GetCookieValue('SYS_USER_ID'))
		{
    		document.location.href = "/user/user.do?action=GoTong";
    	}
		else
			PopupJoinTong('&need_toss=true&redirect_url=/user/user.do?action=GoTong');
	else
		PopupLogin('&need_toss=true&redirect_url=/user/user.do?action=GoTong');
}

function gotoMyThemeTong(url)
{
	if (_GetCookieValue('GUID'))
		if (_GetCookieValue('SYS_USER_ID'))
		{
    		document.location.href = url;
    	}
		else
			PopupJoinTong('&need_toss=true&redirect_url=/user/user.do?action=GoTong');
	else
		PopupLogin('&need_toss=true&redirect_url=/user/user.do?action=GoTong');
}

function SetObjDirection(sTarget, sDirection, sValue,sIndex)
{
	var sHTML;
	sHTML = "<a href=\""+sDirection+"\">" + sValue + "</a>";
	sHTML += "\n";
	document.getElementById("spanGNBDirection").innerHTML = sHTML;
	changeImage("liOptDirection_" + sIndex);
	sCookieOptDirection = sIndex;
}

function SetOptSearch(sIndex)
{
	setSemiCookie('optSearch',sIndex);
	if(sCookieOptSearch != sIndex)
	{
//		changeImage("liOptSearch_" + sCookieOptSearch);
		sCookieOptSearch = sIndex;
//		changeImage("liOptSearch_" + sIndex);
		document.getElementById('search_type').innerHTML = sIndex == '1' ? 'ÀüÃ¼¿¡¼­' : 'ÀÌÅë¿¡¼­';
	}
	ViewGNBLayer('divSearchOption');
}

function SetOptDirection(sIndex)
{
	setSemiCookie('optDirection', sIndex);	
	changeImage("liOptDirection_" + sCookieOptDirection);
	
	switch(sIndex)
	{
	case '0' :
		SetObjDirection('spanGNBDirection','/boxitem/jini.do?action=goUnknown','·£´ýÅë',sIndex);
		break;
	case '1' :
		SetObjDirection('spanGNBDirection','/tongmaster','ÅëÅ«¾ÆÀÌÅë',sIndex);
		break;
	case '2' :
		SetObjDirection('spanGNBDirection','/tongmaster#clipper','ÅëÅ¬¸®ÆÛ',sIndex);
		break;
	case '3' :
		SetObjDirection('spanGNBDirection','/mtmain/promote.do?action=main','ÀÌº¥Æ®',sIndex);
		break;
	case '4' :
		SetObjDirection('spanGNBDirection','http://www.nate.com','Nate.com',sIndex);
		break;
	case '5' :
		SetObjDirection('spanGNBDirection','http://theme.tong.nate.com','Å×¸¶Åë',sIndex);
		break;	
	}
	ViewGNBLayer('divDirection');	
}

function changeImage(sObjName)
{
	CHIMG(document.getElementById(sObjName).getElementsByTagName("IMG")[0]);
}

function CHIMG(obj){
   var str = obj.src;          
   if(str.indexOf('on.gif') < 0){ 
    ss = str.substr(0, str.indexOf('.gif')) 
    obj.src = ss + "on.gif";    
   }else{            
    ss = str.substr(0, str.indexOf('on.gif'))
    obj.src = ss + ".gif";
   }
  }

  
  
var bView = false;
function ViewBookMark()
{
	if (_GetCookieValue('GUID')) {
		if (_GetCookieValue('SYS_USER_ID')) {
			if(bView)
			{
				CloseBookMark();
				return;	
			}
			for(var i = 1; i<= nListTotalSize; i++)
			{	
				if(i < 20)
				{
					document.getElementById("liBookmark"+i).style.display = "";
				}
			}	
			
			document.getElementById("divFavoriteMore").style.display =(nListTotalSize > 20) ? "": "none";	
			document.getElementById("divFavoriteClose").style.display =(nListTotalSize > 20) ? "none": "";		
			document.getElementById("divFavoriteTong").style.display = "block";	
			bView = true;
		} else {
			PopupJoinTong('&need_toss=false&redirect_url='+location.href);
		}
	} else {
		alert("·Î±×ÀÎÀ» ÇØ¾ß »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù");
	}
}
function GoRandomTong()
{
	top.location.href = "/boxitem/jini.do?action=goUnknown";
}

function CloseBookMark()
{
	bView = false;
	for(var i = 1; i<= nListTotalSize; i++)
	{	
		document.getElementById("liBookmark"+i).style.display = "none";
	}	
	
	if(nListTotalSize > 20)
	{
		document.getElementById("divFavoriteMore").style.display = "none";
	}
	

	document.getElementById("divFavoriteClose").style.display = "none";	
	document.getElementById("divFavoriteTong").style.display = "none";	
}

function ViewBookMarkMore()
{
	for(var i = 20; i<= nListTotalSize; i++)
	{	
		document.getElementById("liBookmark"+i).style.display = "";
	}	
	document.getElementById("divFavoriteMore").style.display = "none";
	document.getElementById("divFavoriteClose").style.display = "";
}
