
var UserConfig = {
	CancelFavoriteThreadUrl : "http://bbs.tiexue.net/DeleteFavoriteThread.aspx" //"http://bbs.tiexue.net/DeleteFavoriteThread.aspx" //收藏后台处理页面地址
} 

//取消收藏
function CancelFavoriteThread(threadID,userID){
    var logUID = document.getElementById("LogUserID").value;
    if(logUID > 0){
        if(logUID == userID){
	        if(window.confirm("确认删除此收藏主题？")){
		        var FavoriteCallBack = {
			        success:function(o){//处理发送请求成功
				        if(o.responseText != "undefined"){//是否有服务器返回的字符串
					        if(o.status == 200){//返回的请求http状态是否OK
						        var msg = o.responseText;//获取服务器返回的信息
						        alert(msg);
						        if(msg == "成功删除！"){//移除删除节点
							        document.getElementById("Favorite"+threadID).outerHTML = "";						
						        }
					        }
				        }
			        },
			        failure:function(o){//处理发送请求失败
				        if(o.responseText != "undefined"){
					        alert(o.statusText);//提示错误信息
				        }
			        }
		        };
		        var sUrl = "agent.aspx?desturl=" + this.encodeURIComponent(this.UserConfig.CancelFavoriteThreadUrl)
		        var postData = "ThreadID=" + this.encodeURIComponent(threadID) + "&UserID=" + this.encodeURIComponent(userID);
		        var request = YAHOO.util.Connect.asyncRequest("POST",sUrl,FavoriteCallBack,postData);
	        }
	    }
	    else{
	        alert("你不能删除他人收藏！");
	    }
	}
	else{
	    alert("请登录后操作！");
	}
}

//批量取消收藏
function  BatchCancelFavoriteThread(hostID){    
    var logUID = document.getElementById("LogUserID").value;
    if(logUID > 0){
        if(logUID == hostID){
	        if(window.confirm("确认删除此收藏主题？")){
		        var elList = YAHOO.util.Dom.getElementsByClassName("checkBox","input")
		        var threadIdList = "";//ThreadID参数，用，分隔
		        for(var i=0;i<elList.length;i++){
			        if(elList[i].checked){//是否选中
				        threadIdList += elList[i].id;
				        if(i<elList.length-1){
					        threadIdList += ",";
				        }
			        }		
		        }	
		        if(threadIdList.length > 0){
			        var FavoriteCallBack = {
				        success:function(o){//处理发送请求成功
					        if(o.responseText != "undefined"){//是否有服务器返回的字符串
						        if(o.status == 200){//返回的请求http状态是否OK
							        var msg = o.responseText;//获取服务器返回的信息
							        alert(msg);
							        if(msg == "成功删除！"){//移除删除节点
								        for(var i=0;i<elList.length;i++){
									        if(elList[i].checked){//是否选中
										        document.getElementById("Favorite"+elList[i].id).outerHTML = "";		
									        }		
								        }					
							        }
						        }
					        }
				        },
				        failure:function(o){//处理发送请求失败
					        if(o.responseText != "undefined"){
						        alert(o.statusText);//提示错误信息
					        }
				        }
			        };
        			
			        var sUrl = "agent.aspx?desturl=" + this.encodeURIComponent(this.UserConfig.CancelFavoriteThreadUrl)
			        var postData = "IDList=" + this.encodeURIComponent(threadIdList) + "&UserID=" + this.encodeURIComponent(hostID);
			        var request = YAHOO.util.Connect.asyncRequest("POST",sUrl,FavoriteCallBack,postData);
		        }
		        else{
			        alert("请选中要删除的收藏主题!");
		        }
	        }
	    }
	    else{
	        alert("你不能删除他人收藏！");
	    }
	}
	else{
	    alert("请登录后操作！");
	}
}

//收藏列表页页面全选
function SelectAll(thisObj){
	var elList = YAHOO.util.Dom.getElementsByClassName("checkBox","input")
	if(thisObj.checked){//未全选
		for(var i = 0;i < elList.length;i++){
			elList[i].checked = true;
		}
	}
	else{
		for(var i = 0;i < elList.length;i++){
			elList[i].checked = false;
		}
	}
}

//兼容ff下没有outerHTML。使用HTMLElement扩展方式
var setOuterHtml = function(s){
   var range = this.ownerDocument.createRange();
   range.setStartBefore(this);
   var fragment = range.createContextualFragment(s);
   this.parentNode.replaceChild(fragment, this);
};

if(window.HTMLElement) {
  HTMLElement.prototype.__defineSetter__("outerHTML", setOuterHtml);
}