var nMyTongId = 0;
var nMyBoxId = 0;
var nMyPostId = 0;
var nMyGuestbookId = 0;
var strViewMode = 'mytong';
var strSearchKeyword = '';
var strOwnerNickName = '';
var strVisitorNateId = '';

function PageInit()
{
	frameLeftVisitorList.location.href = '/user/main.do?myTongID=' + nMyTongId;
	if (strViewMode == 'mytong')		
		GoToMain();
	else if (strViewMode == 'box')
		GoToBox(false, nMyTongId, nMyBoxId);
	else if (strViewMode == 'post')
		GoToPost(false, nMyTongId, nMyBoxId, nMyPostId);
	else if (strViewMode == 'recommand')
		GoToRecommand(nMyTongId, nMyBoxId);
	else if (strViewMode == 'linkmap')
		GoToLinkmap(nMyTongId, nMyBoxId);
	else if (strViewMode == 'comment')
		GoToComment(nMyTongId, nMyBoxId, nMyPostId);
	else if (strViewMode == 'weave')
		GoToWeave(nMyTongId, nMyBoxId, nMyPostId);
	else if (strViewMode == 'sympathy')
		GoToSympathy(nMyTongId, nMyBoxId, nMyPostId);
	else if (strViewMode == 'rss')
		GoToRss(nMyTongId, nMyBoxId);
	else if (strViewMode == 'today')
		GoToMain();
	else if (strViewMode == 'search')
		GoToSearch();
	else if (strViewMode == 'guest')
		GoToGuestbook(nMyGuestbookId);
	//else if (strViewMode == 'withme')
	//	GoToMain();
	else if (strViewMode == 'together')
		GoToTogether(nMyTongId, nMyBoxId);
	else if (strViewMode == 'list' || strViewMode == 'clist' || strViewMode == 'plist')
		GoToBox(false, nMyTongId, nMyBoxId, strViewMode);
	else if (strViewMode == 'admin_invite')
		GoToAdmin(4);
	else if (strViewMode == 'clipper')
//		NavigateMain('/mytong/tongmaster/tongclipper.vm', aryMenuItem[2][0]);
		NavigateMain('/mytong/tongmaster/tongclipper.vm');
	else if (strViewMode == 'qnalist')
		NavigateMain('/qt.do?action=list',document.getElementById('txtQuestion1'));
	else if (strViewMode == 'write_guest')
		GoToWrite();
	else
		GoToMain();

		
}
function RefreshBoxList()
{
}

function RefreshVisitorList()
{
	frameLeftVisitorList.location.href = '/user/main.do?myTongID=' + nMyTongId;
}
function WriteNewPost()
{
	strViewMode = 'box';
	ShowNickLayer(null,false);
	ShowBoxLayer(null,false);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nMyTongId + '&_boxID=0&viewMode=write';
}
function GoToAdmin(nType)
{
	ShowNickLayer(null,false);
	ShowBoxLayer(null,false);

	switch(nType)
	{
		case 0:
    		frameMain.location.href = '/mytong/mytong.do?action=form&myTongID=' + nMyTongId;
    		break;
		case 1:
			frameMain.location.href = '/mytong/box.do?action=manageform&myTongID=' + nMyTongId + '&boxID=' + nMyBoxId;
			break;
		case 2:
			frameMain.location.href = '/mytong/box.do?action=manageform&myTongID=' + nMyTongId;
			break;
		case 3:
			frameMain.location.href = '/mytong/puzzle.do?action=view&myTongID=' + nMyTongId;
			break;
		case 4:
			frameMain.location.href = '/friend/inviteList.do?myTongID=' + nMyTongId;
			break;
		default:
			break;
	}
}
function GoToTong(bTopNavigate, nTongId)
{
	if (bTopNavigate)
	{
		self.location.href = '/mytong/mytong.do?action=main&myTongID=' + nTongId;
		return;
	}
	
	nMyTongId = nTongId;
	strViewMode = 'mytong';
	ShowNickLayer(null,false);
	ShowBoxLayer(null,false);
	frameMain.location.href = '/mytong/mytong.do?action=body&myTongID=' + nTongId;
}
function GoToBox(bTopNavigate, nTongId, nBoxId, strMode)
{
	RefreshVisitorList();
	if (!strMode || strMode == '')
		strMode = 'box';
	
	if (bTopNavigate)
	{
		self.location.href = '/mytong/mytong.do?action=' + (strMode == 'box' ? 'main' : 'redirect') + '&myTongID=' + nTongId + '&boxID=' + nBoxId + '&viewMode=' + strMode;
		return;
	}
	
	nMyTongId = nTongId;
	nMyBoxId = nBoxId;
	strViewMode = 'box';
	ShowNickLayer(null,false);
	ShowBoxLayer(null,false);
	
	_MakeBoxItemAsDefault(nBoxId);
	
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&viewMode=' + strMode;
	display_FAQ_Top(false);
}
function GoToPost(bTopNavigate, nTongId, nBoxId, nPostId)
{
	if (bTopNavigate)
	{
		self.location.href = '/mytong/mytong.do?action=main&myTongID=' + nTongId + '&boxID=' + nBoxId + '&postID=' + nPostId + '&viewMode=post';
		return;
	}
	
	nMyTongId = nTongId;
	nMyBoxId = nBoxId;
	strViewMode = 'post';
	
	_MakeBoxItemAsDefault(nBoxId);
	
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&_boxItemID=' + nPostId + '&viewMode=post';
}
function GoToToday()
{
	strViewMode = 'box';
	frameMain.location.href = '/mytong/happened.do?action=listall&myTongID=' + nMyTongId;
}
function GoToSearch()
{
	strViewMode = 'mytong';
	frameMain.location.href = '/search/search.do?action=searchintong&myTongID=' + nMyTongId + '&keyword=' + strSearchKeyword;
}
function GoToWithMe()
{
	strViewMode = 'box';
	frameMain.location.href = '/mytong/connected.do?action=match&ownerID=' + nMyTongId;
}
function GoToRecommand(nTongId, nBoxId)
{
	strViewMode = 'box';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&viewMode=recommand';
}
function GoToRecommandByPuzzle(nTongId, nBoxId)
{
	strViewMode = 'box';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&viewMode=recommand';
}
function GoToLinkmap(nTongId, nBoxId)
{
	strViewMode = 'box';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&viewMode=linkmap';
}
function GoToComment(nTongId, nBoxId, nPostId)
{
	strViewMode = 'post';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&_boxItemID=' + nPostId + '&viewMode=comment';
}
function GoToWeave(nTongId, nBoxId, nPostId)
{
	strViewMode = 'post';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&_boxItemID=' + nPostId + '&viewMode=weave';
}
function GoToSympathy(nTongId, nBoxId, nPostId)
{
	strViewMode = 'post';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&_boxItemID=' + nPostId + '&viewMode=sympathy';
}
function GoToRss(nTongId, nBoxId)
{
	strViewMode = 'box';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&viewMode=rss';
}
function GoToTogether(nTongId, nBoxId)
{
	strViewMode = 'box';
	_MakeBoxItemAsDefault(nBoxId);
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nTongId + '&_boxID=' + nBoxId + '&viewMode=together';
}
function GoToGuestbook(nGuestbookId)
{
	strViewMode = 'mytong';
	frameMain.location.href = '/user/guestbookList.do?myTongID=' + nMyTongId + '&guestbookid=' + nGuestbookId;
}
function GoToMain()
{
	strViewMode = 'mytong';	
	var strMode = 'service';
	var strUrl = document.location.href;
	if (strUrl.indexOf("#") >= 0)
		strMode = strUrl.substring(strUrl.indexOf("#") + 1);
	if (strMode == 'benefits')
//		NavigateMain('/mytong/tongmaster/tongbenefits.vm', aryMenuItem[1][0]);
//		NavigateMain('/mytong/tongmaster/tongbenefits.vm');
		GoToPost(false,10,2060749,28358817);
	else if (strMode == 'clipper')
//		NavigateMain('/mytong/tongmaster/tongclipper.vm', aryMenuItem[2][0]);
		NavigateMain('/mytong/tongmaster/tongclipper.vm');
	else if (strMode == 'update')
//		NavigateMain('/mytong/tongmaster/tongupdate.vm', aryMenuItem[3][0]);
		NavigateMain('/mytong/tongmaster/tongupdate.vm');
	else if (strMode == 'question')
		NavigateMain('/qt.do?action=getQueryForm', document.getElementById('txtQuestion0'));
	else if (strMode == 'present')
		NavigateMain('/mytong/tongmaster/tong_present.vm');		
	else
//		NavigateMain('/mytong/tongmaster/tongservice.vm', aryMenuItem[0][0]);
		NavigateMain('/user/guestbookList.do?myTongID=10');
}
function GoToWrite()
{
	strViewMode = 'box';
	frameMain.location.href = '/boxitem/jini.do?action=boxDesc&_tongID=' + nMyTongId + '&_boxID=' + nMyBoxId + '&viewMode=write';
}
function ShowProfile()
{
}
function ShowBigProfile()
{
}
function NavigateMain(strUrl)
{
	display_FAQ_Top(false);
	frameMain.location.href = strUrl;
}


function AddTongToLeftVisitorList()
{
}

/*

function NavigateMain(strUrl, objItem)
{
	objDefaultItem = objItem;
	MenuOver(objItem, true);
	frameMain.location.href = strUrl;
}


var objDefaultItem = null;
var aryMenuItem = new Array();
function AddToAryMenu(objItem, nType)
{
	aryMenuItem[aryMenuItem.length] = new Array(objItem, nType);
}
function MenuOver(objItem, bOver)
{
	if (bOver)
		for (var i = 0; i < aryMenuItem.length; i++)
			_ChangeMenuStyle(aryMenuItem[i][0], (aryMenuItem[i][0] == objItem), aryMenuItem[i][1]);
	else
		for (var i = 0; i < aryMenuItem.length; i++)
			_ChangeMenuStyle(aryMenuItem[i][0], (aryMenuItem[i][0] == objDefaultItem), aryMenuItem[i][1]);
}
function _ChangeMenuStyle(objItem, bOver, nType)
{
	if (nType == 0)
	{
		var strPath = objItem.src;
		objItem.src = strPath.substring(0, strPath.lastIndexOf('_') + 1) + (bOver ? 'on' : 'off') + '.gif';
	}
	else
		objItem.style.color = (bOver ? "navy" : "");
}
*/
function _MakeBoxItemAsDefault(nBoxId)
{
	var objItem = null;
	if (nBoxId == 20)
		objItem = document.getElementById('imgTongNotice');
	else
		objItem = document.getElementById('boxItem' + nBoxId.toString());
	
	objDefaultItem = objItem;
//	MenuOver(objItem, true);
}

function ShowInfoPostList(strListName)
{
	var styleNeighborBox = document.getElementById('tblNeighborBox').style;
	var styleNeighborBlog = document.getElementById('tblNeighborBlog').style;
	var styleRecommendBox = document.getElementById('tblRecommendBox').style;
	
	if (strListName == "NeighborBox")
	{
		styleNeighborBox.display = "";
		styleNeighborBlog.display = "none";
		styleRecommendBox.display = "none";
		objDefaultImg = document.getElementById('imgNeighborBox');
	}
	else if (strListName == "NeighborBlog")
	{
		styleNeighborBox.display = "none";
		styleNeighborBlog.display = "";
		styleRecommendBox.display = "none";
		objDefaultImg = document.getElementById('imgNeighborBlog');
	}
	else if (strListName == "RecommendBox")
	{
		styleNeighborBox.display = "none";
		styleNeighborBlog.display = "none";
		styleRecommendBox.display = "";
		objDefaultImg = document.getElementById('imgRecommendBox');
	}
}
function NavigateBody(strPath)
{
	frameMainBody.location.href = strPath;
}

function PopupTongSummary(strType)
{
	if (strType == 'neighbor')
		window.open('/boxitem/jini.do?action=popupConcerned&value(sort)=0&_boxID=0&_tongID=' + nMyTongId, 'popupConcerned', 'scrollbars=yes,status=yes,width=440,height=476,left=' + (window.screen.availWidth/2 - 210) + ',top=' + (window.screen.availHeight/2 - 238));
	else if (strType == 'scrap')
		window.open('/boxitem/jini.do?action=popupScrapped&value(sort)=0&_boxID=0&_tongID=' + nMyTongId, 'popupScrapped', 'status=yes,width=500,height=454,left=' + (window.screen.availWidth/2 - 250) + ',top=' + (window.screen.availHeight/2 - 227));
}

var strMapLayer = '<div id=divMapLayer style=position:absolute;top:132;left:920;>';
strMapLayer = strMapLayer + '<table border=0 cellspacing=0 cellpadding=0><tr><td id=tdMapLayer>';
strMapLayer = strMapLayer + '</td></tr></table></div>';

var objMapLayer = null;
function UseMapLayer()
{
	MyInsertAdjacentHTML("BeforeEnd", strMapLayer, document.body);
	objMapLayer = document.getElementById('divMapLayer');
}
function AddEventImgToMapLayer(strImg, strLink, strTarget)
{
	if (!objMapLayer)
		return;
	var strHtml = '<br><a href="' + strLink + '" target="' + strTarget + '"><img src="' + strImg + '"></a>';
	MyInsertAdjacentHTML("BeforeEnd", strHtml, document.getElementById('tdMapLayer'));
}

function GoTagView(strMenuMode, sTag)
{
	switch(strMenuMode)
	{
		case 'mymaintong':		
			frameMain.location.href="/boxitem/jini.do?action=myBoxListWithTag&_tongID=" + nMyTongId + "&_tag=" + TongEncodeURIComponent(sTag);
			break;
	}
}


function fnDisplayClear() {
	document.getElementById("frameMain_top").style.display = "none";
	document.getElementById("frameMain_top2").style.display = "none";
}

function display_FAQ_Top(isVisible,choiceFrame) {

	fnDisplayClear();
	var frameNum = 0;

	if(choiceFrame)
		frameNum = choiceFrame;

	var frameMainTop = null;

	if(isVisible) {
		if(frameNum == 0) 
			frameMainTop = document.getElementById("frameMain_top");
		else  if(frameNum == 1)
			frameMainTop = document.getElementById("frameMain_top2");
		else
			frameMainTop = document.getElementById("frameMain_top");
		try {
				frameMainTop.style.display="block";		
		}catch(e) {
			alert(e.toString());
		}
	} else {
		fnDisplayClear();
	}
	
		
}

