Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++) 
		if (this[i] === value) 
			return true;
	return false;
};

//2009.7.22
function GetrArticlesIteration(node, start, limit, docstr)
{
	var showdiv = (node == null) ? "divhotarticles" : getDivContainerId(node);
					
        xajax_getHotArticles(showdiv, docstr, start, limit);
}

//2009.7.22
function RefreshRecommendedIteration(node, start, limit, docstr)
{
	var showdiv = (node == null) ? "divRecommended" : getDivContainerId(node);
					
        xajax_refreshRecommend(showdiv, docstr, start, limit);
}

//2008.12.28
function ShowHotYearArticlesIteration(node, start, limit)
{
	var showdiv = (node == null) ? "divhotarticlesofyear" : getDivContainerId(node);
					
        xajax_getHotYearArticles(showdiv, start, limit);
}

//2009.12.11
function ShowRecommendYearArticlesIteration(node, start, limit)
{
	var showdiv = (node == null) ? "divrecommendarticlesofyear" : getDivContainerId(node);
					
        xajax_getRecommendYearArticles(showdiv, start, limit);
}

//2009.12.13
function MostProductiveUsersOfYearIteration(node, start, limit, cat, year, opt)
{
	var showdiv = (node == null) ? "divmostproductiveusersofyear" : getDivContainerId(node);
					
        xajax_MostProductiveUsersOfYear(showdiv, start, limit, cat, year, opt);
}

//2010.5.23
function GetForumTopicsIteration(node, start, limit, fid, docstr)
{
	var showdiv = (node == null) ? "divforumtopics" : getDivContainerId(node);
					
        xajax_getForumTopics(showdiv, fid, docstr, start, limit);
}


//2008.12.26
function GetNewsFeed(node, start, limit, docstr)
{
	var showdiv = (node == null) ? "divnewsfeed" : getDivContainerId(node);
					
        xajax_getNewsFeed(showdiv, docstr, start, limit);
}

//2008.12.12
function GetRecentBlogsComments_shell()
{ 	
	var argv = GetRecentBlogsComments_shell.arguments;
  	var argc = GetRecentBlogsComments_shell.arguments.length;
  	var docstr = (argc > 0) ? argv[0] : "unknown-";
  	var start = (argc > 1) ? argv[1] : 0;
  	var limit = (argc > 2) ? argv[2] : 5;
	
	GetRecentBlogsComments(null, start, limit, docstr);
	
	//upadte news by the way
	GetNewsFeed(null, start, limit, docstr);
	//refresh every 5 minutes
  	setTimeout("GetRecentBlogsComments_shell('"+docstr+"')",300000);	
}

function GetRecentBlogsComments(node, start, limit, docstr)
{
	var showdiv = (node == null) ? "divblogscomments" : getDivContainerId(node);
		
	//PrepareShowContent(showdiv);
			
        xajax_getRecentBlogsComments(showdiv, docstr, start, limit);
}

function onAccessJournal(jid)
{
	var argv = onAccessJournal.arguments;
  	var argc = onAccessJournal.arguments.length;
  	var ai = (argc > 1) ? argv[1] : -1;
			
	if(ai !=-1)
		xajax_loadCmtFromBlog(ai); //只載入，但不自動refresh sidebar, 因為動態網頁的關係，比較難知道目前的state(其實還是可以從journal.inc.php知道)，無法呈現對應的資料,2009.9.15
		//xajax_loadCmtFromBlog(ai, "xajax_getRecentBlogsComments");
	
	LoadTopicsIntoReserved(jid);
	//2008.11.20 to add topic's image associated with this article, moved from LoadTopicsIntoReserved 2009.9.8
	xajax_getImageFromJournalID("divarticleimg", jid);
	//2009.12.17 show this journal's location, moved from LoadTopicsIntoReserved 2009.9.8
	//xajax_pantoJournalLocation(jid);
	
	if(document.getElementById("s-"+jid).innerHTML =="")
		xajax_getArticleSnippetStatus(jid, "getArticleSnippet");
}

//2008.12.11
function rendercommentofuserblog(node, start, limit, userid)
{
	var showdiv = (node == null) ? "divuserblogcomments" : getDivContainerId(node);
	xajax_renderCommentOfUserblog(showdiv, userid, start, limit);
}

//google friend connect introduced, since 2008.12.5
function initialfcskin(dct, ht)
{
	var skin = {};
	skin['BORDER_COLOR'] = '#b1cF81';
skin['ENDCAP_BG_COLOR'] = '#91aF61';
skin['ENDCAP_TEXT_COLOR'] = '#ffffff';
skin['ENDCAP_LINK_COLOR'] = '#ffff88';
skin['ALTERNATE_BG_COLOR'] = '#b1cF81';
skin['CONTENT_BG_COLOR'] = '#b1cF81';
skin['CONTENT_LINK_COLOR'] = '#ffff88';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#ffff88';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#ffffff';
	skin['DEFAULT_COMMENT_TEXT'] = dct;
	skin['HEADER_TEXT'] = ht;
	skin['POSTS_PER_PAGE'] = '5';
	return skin;
}

function rendergfcrating(docid, dct, ht)
{
	var skin = initialfcskin(dct, ht);
	google.friendconnect.container.renderSignInGadget(
 		{ id: 'div-fc-signin',
   		site: '10224843841355873816'},
  		skin);
	google.friendconnect.container.renderReviewGadget(
 		{ 	id: 'div-fc-rating',
   			site: '10224843841355873816',
   			'view-params':{"disableMinMax":"false","scope":"ID", "allowAnonymousPost":"false", "docId":(""+docid),"startMaximized":"true"}
		},
  		skin);
}

function renderRecommendedOfTopic(docid)
{
	var skin = {};
skin['BORDER_COLOR'] = '#b1cF81';
skin['ENDCAP_BG_COLOR'] = '#91aF61';
skin['ENDCAP_TEXT_COLOR'] = '#ffffff';
skin['ENDCAP_LINK_COLOR'] = '#ffff88';
skin['ALTERNATE_BG_COLOR'] = '#b1cF81';
skin['CONTENT_BG_COLOR'] = '#b1cF81';
skin['CONTENT_LINK_COLOR'] = '#ffff88';
skin['CONTENT_TEXT_COLOR'] = '#333333';
skin['CONTENT_SECONDARY_LINK_COLOR'] = '#ffff88';
skin['CONTENT_SECONDARY_TEXT_COLOR'] = '#666666';
skin['CONTENT_HEADLINE_COLOR'] = '#ffffff';
skin['HEADER_TEXT'] = '\u63a8\u85a6\u95b1\u8b80';
skin['RECOMMENDATIONS_PER_PAGE'] = '10';
google.friendconnect.container.renderOpenSocialGadget(
 { id: 'div-fc-recommended',
   url:'http://www.google.com/friendconnect/gadgets/recommended_pages.xml',
   site: '10224843841355873816',
   'view-params':{"docId":(""+docid)}
 },
  skin);
	
}

//2010.7.31
function initGFCAllData() 
{
      var req = opensocial.newDataRequest();
      req.add(req.newFetchActivitiesRequest(new opensocial.IdSpec({'userId' : 'OWNER', 'groupId' : 'FRIENDS'})), 'activities');
      req.send(setupGFCData);
};

function setupGFCData(data) {
      
      var activities = data.get('activities').getData();
 
      if (activities) 
      {
      	var strxml = '<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel>';
      	//var strxml = '<rss version="2.0"><channel>';
      	
        activities = activities.asArray();
        for (var i = 0; i < activities.length && i < 5; i++) 
        {
          strxml+="<item>";
          
          var activity = activities[i];
                    
          var actid = activity.getId();
          var title = activity.getField('title', {escapeType: 'none'});
          var body = activity.getField('body', {escapeType: 'none'});
          var url = activity.getField('url', {escapeType: 'none'});
          /*
          var posted_time = activity.getField('POSTED_TIME', {escapeType: 'none'});
          var stream_url = activity.getField('STREAM_URL', {escapeType: 'none'});
          var stream_favicon_url = activity.getField('STREAM_FAVICON_URL', {escapeType: 'none'});
        */
        
          strxml+=("<guid>"+actid+"</guid>");
          strxml+=("<title><![CDATA["+title+"]]></title>");
          strxml+=("<link>"+url+"</link>");
	  strxml+=("<description><![CDATA["+body+"]]></description>");			
	  /*
	  strxml+=("<pubDate>"+posted_time+"</pubDate>");
	  strxml+=("<stream_url>"+stream_url+"</stream_url>");  
	  strxml+=("<stream_favicon_url>"+stream_favicon_url+"</stream_favicon_url>");                   
         */
          strxml+="</item>";         
        }
        strxml+="</channel></rss>";
      
       	xajax_refreshGFCActivities(strxml); 
    }
};

/*
function recommendthis(elemid, id, n, docid)
{
	google.friendconnect.container.renderOpenSocialGadget(
 { id: elemid,
   url:'http://www.google.com/friendconnect/gadgets/recommended_pages.xml',
   width: 64,
   height: 21,
   site: '10224843841355873816',
   'view-params':{"pageUrl":"http://www.waytogo.cc/openarticle.php?id="+id, "pageTitle":n, "docId": docid}
 },
  rbskin);
	
}
*/

function expandjournal(ai)
{
	xajax_expandjournal(("w-"+ai),ai);
}

function shrinkjournal(ai)
{
	xajax_shrinkjournal(("w-"+ai),ai);
}

function gotoweb2(aid)
{
	window.open("openwebsite2.php?aid="+aid);
}
//encode quote, 2006.7.4 to avoid pass string with quot error
function myescape(w)
{
	w = w.replace(/"/g, "&quot;");
	w = escape(w);
	return w;
}

//encode quote, 2006.7.4 to avoid pass string with quot error
function myunescape(w)
{
	w = unescape(w);
	w = w.replace(/&quot;/g, "\"");
	return w;
}

function CloseAllSubmenu()
{
	document.getElementById("divmenu").style.display="none";
	document.getElementById("divrelatic").style.display="none";
	document.getElementById("divkeywords").style.display="none"; 
	document.getElementById("wmenu_nav_menu_search").style.display="none"; 
}

function keywordscallback()
{
   document.getElementById("divkeywords").style.left = document.getElementById("divmenu").style.left;
   document.getElementById("divkeywords").style.top = document.getElementById("divmenu").style.top;
      	
   document.getElementById("divmenu").style.display="none";   	
   document.getElementById("divkeywords").style.display="";
   document.getElementById("divkeywords").focus();
   	 
   currMenuID = "divkeywords";
   
   //overpopupmenu = true;	 
   	
   return true;
}

function wait2go_save(topicid, userid)
{
	var forwhat =document.getElementById("wait2go_forwhat").value;
	
	if(forwhat.length >10)
	{
		alert("請用10個字內說完。");
		return false;
	}
	var status = (document.getElementById("wait2go_status").checked) ? 1 :0;	
	
	var finishdate = document.getElementById("wait2go_finishdate").value;

	if(status)
	{
		if(!ifDateValid(finishdate))
            		return false;
	}
	
	var setupdate=document.getElementById("wait2go_setupdate").innerHTML;
	var publicto =document.getElementById("wait2go_publicto").value;
	var timeattr =document.getElementById("wait2go_timeattr").value;
		
	xajax_waittogoSave(topicid, userid, setupdate, publicto, timeattr, status, forwhat, finishdate);
}

function PrepareShowContent(showdiv)
{
	if(showdiv =="")
		return;
	
	//close previous menu, 2009.4.16
	//if(currMenuID != "")
	//	document.getElementById(currMenuID).style.display="none";
        
        document.getElementById("idbody").style.cursor="wait";
	//document.getElementById(showdiv).innerHTML="<span style='font-size:13px;color:#FFFFFF'>讀取中...</span>";	
}

function ClearSearchSession()
{
	xajax_setsystemcookie("titlesearch", "");
}

function removerelatic(node, wid, callback)
{	
	var argv = removerelatic.arguments;
  	var argc = removerelatic.arguments.length;
  	var type = (argc > 3) ? argv[3] : 1;
	
	var ans = confirm("確定解除本篇文章與這個關鍵字的關聯嗎?");
	if(!ans)
		return;
	
	var showdiv = (node == null) ? "divrelatic" : getDivContainerId(node);
	
	xajax_removeRelatic(showdiv, wid, callback, type);
}

function gotorelatic(node, start, limit, tagid, callback, cangoback)
{	
	var showdiv = (node == null) ? "divrelatic" : getDivContainerId(node);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getRelatic(showdiv, start, limit, tagid, callback, cangoback);
}

function menu_relaticcallback()
{   
  	document.getElementById("divrelatic").style.left = document.getElementById("divmenu").style.left;
	document.getElementById("divrelatic").style.top = document.getElementById("divmenu").style.top;
    	
    	closemenu(currMenuID);
    	//document.getElementById("divkeywords").style.display="none";   	
  	document.getElementById("divrelatic").style.display="";
   	document.getElementById("divrelatic").focus();
   	
   	currMenuID = "divrelatic";	
   	//overpopupmenu = true;
   	return true;
}

//remove keyword, 2006.5.28
function removekeyword(node, tagid, callback)
{
	//w= decodeURI(w)
	var ans = confirm("確定移除這個關鍵字?");
	if(!ans)
		return;
	
	var showdiv = (node == null) ? "divkeywords" : getDivContainerId(node);	
	
	xajax_removeKeyword(showdiv, tagid, callback);
}

function preparereservedlayer()
{
	document.getElementById("reservedtopic").style.display="";
	document.getElementById("reservedtopic").innerHTML="<span style='font-size:15px;'>相關主題載入中..</span>";	
}

function AfterKeywordSearch(word, bLoadTopic)
{
	document.getElementById("q").value = word;
	if(((word!= null) && (word !="")) && ((bLoadTopic==null) || (bLoadTopic)))
	{
		preparereservedlayer();
		xajax_loadtopicsforkeywords('reservedtopic', word);
	}
}

//2008.6.17
function smgeneric(e, menuid)
{	
	document.getElementById(menuid).style.display="block";
	document.getElementById(menuid).focus();
	currMenuID = menuid;	
}

function gajaxsearchglobal(q, site, showdiv, appendmode, rsSize, shownode)
{
	if(searchObj == null)
		GOnLoad();
	
	rsSize = rsSize || 0;
	if(rsSize != 0)
		searchObj.setResultSetSize(rsSize);
	
	appendmode = appendmode || "assign";
	
	showdiv = showdiv || "";
	shownode = shownode || null;		
		
	//try shownode for more info. 2010.3.15
	if(showdiv == "")
		showdiv = (shownode == null) ? "" : getDivContainerId(shownode);
			
	if(showdiv != "")
		searchObj.elemid = showdiv;
		
	if(appendmode == "append")
	{
		var resDiv = document.createElement('div');
  		resDiv.setAttribute("id", "gsresdiv");
  		
  		var contentobj = document.getElementById(searchObj.elemid);
  		contentobj.appendChild(resDiv);
  		searchObj.elemid = "gsresdiv";
	}	
	
	searchObj.setcbCompletefuncname("defaultSearchComplete");
	searchObj.setSite(site);
	searchObj.execute(q);
	
	searchkeeponbtw(q);
}

function searchkeeponbtw(q)
{
	setTimeout("blueskySearchObj.execute('"+q+"');", 400);
	setTimeout("keeponSearchObj.execute('"+q+"');", 600);
}

function headersearch(type, bReload)
{
	document.getElementById("st").value = type;

	var bReload = bReload || 0;	
  	
  	if(bReload == 1)
  	{
  		document.getElementById('PAD').submit();	
		return;
	}	
	
	if(!checktitlevalue())
		return;

	type = Number(type);
		
	var q = document.getElementById("q").value;
	
	//若搜尋結果將與網頁其他地方無互動，則必用AJAX；就算有互動也還是可以用AJAX，只是這樣會減少page view,2008.11.27,2009.8.22通通改用form的submit	
	switch(type)
	{
		case 0:
			GetArticlesWithKeyword(null, 0, 20, q, -1, 0);
			break;
		case 1:
			GetArticlesByGoogle(null, 0, 10, q, type, "www.waytogo.cc");
			break;
		case 2:
			//GetArticlesByYahoo(null, 0, 10, q, type, "waytogo.cc");
			gajaxsearchglobal(q, "waytogo.cc");
			break;
		case 11:
			gajaxsearchglobal(q, "www.keepon.com.tw/ActiveSite/Article");			
			break;
		case 12:
			gajaxsearchglobal(q, "www.keepon.com.tw/keepon/kpmt/blueskymap");
			break;
		case 13:
			gajaxsearchglobal("祥馬"+q, "www.keepon.com.tw/ActiveSite/Article");
			break;		
		case 100:
			SearchUsers(null, q);
			break;
		case 101:
			SearchTags(null, 0, 20, q);
			break;
		
		default:
			document.getElementById('PAD').submit();
			break;
	}
}


//type: 0->topic;1->article;2->comment 
function setkeyword(rid)
{
	var keyword = "";
	keyword = prompt("為文章可與其他文章產生關聯，請在關鍵字之間加上','或是空白做區隔，例如\"陽明山,小油坑\"","");
	
	var argv = setkeyword.arguments;
  	var argc = setkeyword.arguments.length;
  	var type = (argc > 1) ? argv[1] : 1;
  	var cb = (argc > 2) ? argv[2] : "";  	
	
	if((keyword != null)&&(keyword != ""))
	{	
		if(keyword.length>64)
		{
			alert("字串太長超過16個中文字，請重新設定。");
			return;
		}
		xajax_setKeywords(keyword, rid, cb, type);
	}
}

function gotokeywords(rid)
{
	if(currMenuID != "divkeywords")
		closemenu(currMenuID);
	xajax_getKeywords("divkeywords", rid, "keywordscallback");
}


//only use to loaddefaulttopic, openarticle is perform at outer anchor, because achor will change color while visited
function LoadTopicsIntoReserved(id)
{		
	preparereservedlayer();
	xajax_loaddefaulttopic("reservedtopic", id);
}


function checktitlevalue()
{
	var tv = document.getElementById("q").value;
	if((tv =="搜尋標題") || (tv == ""))
		return false;
	return true;
}

function CallbackWriteEventLog()
{
	xajax_refresheventshow("divevent");
}

function TagOrdChanged(chk, tagid)
{

	var btoc = chk.checked;
	
	xajax_tagOrdChanged(tagid, (btoc)? 1:0);
}



//be someone's friend
function beafan(myself, friend, tobeornottobe)
{
	if(myself == -1)
	{
		document.location.href = "upload/logon.php?retURL="+escape("/?showuser_id="+friend);
		return false;
	}
	
	xajax_MakeFriend(myself, friend, tobeornottobe);	
}

function CallbackBeafan(tobeornottobe, friendid)
{
	if(tobeornottobe == 1)
		alert("成為粉絲一族");
	else
		alert("暫時移情別戀");	
	document.location.href="/?showuser_id="+friendid;		
}

function ShowUserProfile(aid)
{
	var argv = ShowUserProfile.arguments;
  	var argc = ShowUserProfile.arguments.length;
  	
  	var action = (argc > 1) ? argv[1] : "";
  	var param = (argc > 2) ? argv[2] : "";
	
	var showdiv = "divcontent";
	
	PrepareShowContent(showdiv);
	
	ClearSearchSession();
	
	xajax_ShowUserProfile("divcontent" ,aid, action, param);	
}

function WhereWeHaveBeen(node, start, limit, myself, friend)
{
	var showdiv = (node == null) ? "divuserextrainfo" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_whereWeHaveBeen(showdiv, myself, friend, start, limit);
}

//2008.8.18
function GetArticlesOfUser(node, start, limit, aid, cat)
{
	var showdiv = (node == null) ? "divuserextrainfo" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getArticlesOfUser(showdiv, aid, cat, start, limit);
}

//2008.8.19
function getDivContainerId(node)
{
	var parentDIV = node.parentNode;
	
   	while((parentDIV.nodeName != "DIV") || ((parentDIV.id).indexOf("div") != 0)) 
   			parentDIV = parentDIV.parentNode;
   	return 	parentDIV.id;	
}

function GetArticlesOfMonth(node, start, limit, m)
{		
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getArticlesOfMonth(showdiv, m, start, limit);
}

//2008.8.19
function GetArticlesByOntology(node, start, limit, word, ai, bIncFriend, kwarstr)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
			
	PrepareShowContent(showdiv);
	
	kwarstr = kwarstr || "";	
		
	xajax_getArticlesByOntology(showdiv, start, limit, word, ai, bIncFriend, kwarstr);
	
	//if(start==0)
        //	AfterKeywordSearch(word);
}

//2008.8.25
function GetArticlesByYahoo(node, start, limit, word, sitesearch, searchdomain)
{	
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
		
	PrepareShowContent(showdiv);	
		
	xajax_getArticlesByYahoo(showdiv, start, limit, word, sitesearch, searchdomain);
	
	if(start==0)
        	AfterKeywordSearch(word);
}

//2008.8.25
function GetArticlesByGoogle(node, start, limit, word, sitesearch, searchdomain)
{	
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
		
	PrepareShowContent(showdiv);	
		
	xajax_getArticlesByGoogle(showdiv, start, limit, word, sitesearch, searchdomain);
	
	if(start==0)
        	AfterKeywordSearch(word);
}

//2008.8.26, search someone's journal more by yahoo, 2010.2.23 change to yahoo
function GetArticlesByYahoo2(node, word, ai)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
		
	xajax_getArticlesByYahoo2(showdiv, word, ai);
	
	AfterKeywordSearch(word);
}

//2008.8.19 modified
function GetArticlesWithKeyword(node, start, limit, word, ai, bIncFriend)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
	if((start ==0) && (word==""))
		ClearSearchSession();
			
        xajax_getArticles(showdiv, start, limit, word, ai, bIncFriend);
        
        if(start==0)
        	AfterKeywordSearch(word);       
}

function SearchPostsOfUser(userid, type, strwebsite)
{
	var strwebsite = strwebsite || "";
	
	var word = document.getElementById("userareasearch").value;
			
	if(word != "")
	{	
		var showdiv = "divuserextrainfo";
		
		PrepareShowContent(showdiv);
		if(type != 2)
		{					
        		xajax_getArticles(showdiv, 0, 5, word, userid, type);//bug for type mistyped,2010.7.22
        	}
        	else 
        		gajaxsearchglobal(word, strwebsite, showdiv, "assign", 4);
        			
	}
}

function GetArticlesOfCat(node, start, limit, cat)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
		
        xajax_getArticlesOfCat(showdiv, start, limit, cat);
}

function ListHotArticlesOfMonthWithKeyword(node, start, limit, word, month)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
	
	PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
		
        xajax_getArticlesByMonthKeyword(showdiv, start, limit, word, month);
        if(start==0)
        	AfterKeywordSearch(word);       
}



//list author, 2008.8.24
function ShowAuthorWebPads(node, start, limit, catid)
{
	var showdiv = (node == null) ? "divauthorlist" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
        xajax_loadwebpad(showdiv, start, limit, catid);
}

//list author, 2008.9.8
function SearchTags(node, start, limit, word)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);

	PrepareShowContent(showdiv);
	
        xajax_searchTags(showdiv, word, start, limit);
       
        GFCShowOrNot(false);
}

//2009.9.10 moved from editTourBanner.php
function edituserwebname(elemid, userid)
{
	var webname = "";
	var orgwebname = document.getElementById(elemid).innerHTML;
	
	webname  = prompt("請在此輸入個人部落名稱", ""+orgwebname);
	
	if(webname != null)
	{		
		if(webname =="")
		{
			alert("不能留白");
			return;
		}
		
		if(webname.length>40)
		{
			alert("部落格名稱超過20個中文字，請重新設定。");
			return;
		}		
		
		xajax_editUserWebName(elemid, webname, userid);
	}
	
}

//2009.12.10 
function edituserrssurl(orgrssurl, userid)
{
	var rssurl  = prompt("請在此輸入個人部落格留言板的RSS，第一次設定如以下資料正確(或不清楚)請直接按「確定」即可", ""+orgrssurl);
	
	if(rssurl != null)
	{		
		if(rssurl =="")
		{
			alert("不能留白");
			return;
		}
		
		if(rssurl.length>100)
		{
			alert("RSS位址長度超過100個字，請重新設定。");
			return;
		}		
		
		xajax_editUserRSSUrl(rssurl, userid);
	}
	
}

//2008.8.25
function GetArticlesOfHomepage(node)
{	
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);
		
	PrepareShowContent(showdiv);
	
	ClearSearchSession();
		
	xajax_getArticles(showdiv, 0, 15, "", -1, 0); //set word to "" , other params are don't care
}

//2009.9.17
function GFCShowOrNot(bShow)
{
	var strShow=(bShow) ? "" : "none";
        document.getElementById("div-fc-signin").style.display=strShow;
        document.getElementById("div-fc-rating").style.display=strShow;
        document.getElementById("div-fc-recommended").style.display=strShow;
}

//search author, 2008.9.8
function SearchUsers(node, word)
{
	var showdiv = (node == null) ? "divcontent" : getDivContainerId(node);

	PrepareShowContent(showdiv);
		
        xajax_searchUsers(showdiv, word);
        
        GFCShowOrNot(false);
}

//同行者的遊記
function GetArticlesOfParners(node, start, limit, postid, callback)
{
	var showdiv = (node == null) ? "divrelatic" : getDivContainerId(node);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getArticlesOfParners(showdiv, start, limit, postid, callback);
}

function redir2logon(retURL)
{
	document.location.href="/upload/logon.php?retURL="+retURL;
}

//2009.4.27
function GetWaittogoOfUser(node, start, limit, aid, bMyself, nFriend)
{
	var showdiv = (node == null) ? "divuserextrainfo" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getWaittogoOfUser(showdiv, aid, bMyself, nFriend, start, limit);
}

//2009.4.27
function GetFinishedPlanOfUser(node, start, limit, aid, bMyself, nFriend)
{
	var showdiv = (node == null) ? "divuserextrainfo" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getFinishedPlanOfUser(showdiv, aid, bMyself, nFriend, start, limit);
}

//2009.4.27
function GetCampaignBoard(node, start, limit)
{
	var showdiv = (node == null) ? "divcampaignextrainfo" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getCampaignBoard(showdiv, start, limit);
}

function GetRecentPublishCampaigns(node, start, limit)
{
	var showdiv = (node == null) ? "divcampaignextrainfo" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getRecentPublishCampaigns(showdiv, start, limit);
}

function GetHotOngoingCampaigns(node, start, limit)
{
	var showdiv = (node == null) ? "divcampaignextrainfo" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getHotOngoingCampaigns(showdiv, start, limit);
}

function GetHotFinishedCampaigns(node, start, limit)
{
	var showdiv = (node == null) ? "divcampaignextrainfo" : getDivContainerId(node);
	
	//PrepareShowContent(showdiv);
	
	if(start==0)
		ClearSearchSession();
	
	xajax_getHotFinishedCampaigns(showdiv, start, limit);
}

//2009.8.6
function GetLocatorSimple(node, start, limit)
{
	var showdiv = (node == null) ? "divlocatorsimpleboard" : getDivContainerId(node);
		
	if(start==0)
		ClearSearchSession();
	
	xajax_getLocatorSimple(showdiv, start, limit);
}

//2009.12.10
function GetCampaignSimple(node, start, limit)
{
	var showdiv = (node == null) ? "divcampaignsimpleboard" : getDivContainerId(node);
		
	if(start==0)
		ClearSearchSession();
	
	xajax_getCampaignSimpleBoard(showdiv, start, limit);
}

//2009.6.12 remove user specified campaign
function removeUserCampaign(cuid)
{
	var ans = confirm("確定要移除這項旅程記錄，所有已經記錄的足跡都會消失？再確定一下會不會後悔？");
	if(!ans)
		return;
	xajax_removeUserCampaign(cuid);
} 

function cb_removeUserCampaign(userid)
{
	ShowUserProfile(userid, "listcampaigns");
	xajax_getCampaignSimpleBoard("divcampaignsimpleboard");
}

//2009.6.2 recommend post
function recommendthis(postid, userid, docid, npush)
{
	xajax_recommendPost(postid, userid, docid, npush);
}

//2009.6.20 show the categories of the article
function gotocats(rid)
{
	//use the same layer of divkeyword
	if(currMenuID != "divkeywords")
		closemenu(currMenuID);
	xajax_getCats("divkeywords", rid, "keywordscallback");
}

function setcat(rid)
{
	var cat = "";
	cat = prompt("要將文章分類為：","");
	
	if((cat != null)&&(cat != ""))
	{	
		if(cat.length>16)
		{
			alert("字串太長超過4個中文字，請重新設定。");
			return;
		}
		xajax_setCat(cat, rid);
	}
}

function removecatrelatic(node, crid, callback)
{	
	var ans = confirm("確定將本篇文章從這個分類中移除嗎?");
	if(!ans)
		return;
	
	var showdiv = (node == null) ? "divkeyword" : getDivContainerId(node);
	
	xajax_removeCatRelatic(showdiv, crid, callback);
}

//2009.8.16
function GetRelaticArticlesIteration(node, start, limit, postid)
{
	var showdiv = (node == null) ? "divrelaticarticles" : getDivContainerId(node);
					
        xajax_getRelaticArticlesOfPage(showdiv, postid, start, limit);
}

//2009.8.21
function setArticleSnippetManual(postid)
{
	if(postid == -1)
		return;
  	
  	var olds = document.getElementById("s-"+postid).innerHTML.replace(/<.+?>/gim,'');
  	
  	var summary = prompt("請輸入本文的簡單摘述，可從文章中擷取複製至此", olds);
  	if((summary == "") || (summary == null))
  		return;
  
  	xajax_setArticleSnippetManual(postid, summary);
}

//2009.9.1 
function AfterSetArticleSnippet(postid)
{
	document.getElementById("trs-"+postid).style.display="";	
}

//2009.10.26
function getArticleSnippet(posturl)
{
	var argv = getArticleSnippet.arguments;
  	var argc = getArticleSnippet.arguments.length;
  	var bShowResult = (argc > 1) ? argv[1] : 0;
	
	searchObj.setcbCompletefuncname("fetchSnippetComplete", new Array(posturl, bShowResult)); 
	searchObj.setSite(null);
	searchObj.execute(posturl);
}

//2009.9.15
function setCommentLink2Post(commentid, userid, postid, callback)
{
	var npostid = "";
	npostid = prompt("請輸入這個留言對應到的遊記序號，可將滑鼠移到文章連結附近，即可從左下角看到..id=xxxx，xxxx即為遊記的序號", postid);
	if((npostid != null)&&(npostid != ""))
	{
		if(isNaN(npostid))
		{
			alert("遊記的序號為數字，請重新設定!");
			return;
		}
		xajax_setCommentLink2Post(commentid, userid, npostid, callback);
	}	
}

//2010.3.19
function callback_removerelatic()
{
	if((document.location.href.indexOf("page.php?")!=-1) || (document.location.href.indexOf("page_")!=-1))
		document.location.reload();
}



