﻿/* 常用方法 */
var appciationUrl="/Service/";
window.onerror=function(){return true;}
function $(id){return document.getElementById(id);}

/*根据元素样式类获取元素对象*/
if (typeof ($C) == "undefined") {
    $C = function(classname, elem) {
    var obj = document.body; 
        if (elem != undefined ) {
            obj = $(elem);
        } 
        s = obj.getElementsByTagName('*');
        arr = [];
        for (i = 0; i < s.length; i++) {
            if (s[i].className == classname)
                arr.push(s[i])
        }
        return arr;
    }
}

/*根据元素标签获取元素对象*/
if (typeof ($T) == "undefined") {
    $T = function(tagName, elem) {
    var obj = document.body; 
        if (elem != undefined ) {
            obj = $(elem);
        }
        s = obj.getElementsByTagName(tagName);
        arr = [];
        for (i = 0; i < s.length; i++) {
            arr.push(s[i])
        }
        return arr;
        
    }
}



//统计
function TongJi(){(new Image).src="http://img.tongji.linezing.com/1425816/tongji.gif?T="+(new Date()).getTime();}
//Ajax
function Ajax2009() {
	this.xmlhttp = false;
	if(window.XMLHttpRequest) { 
		this.xmlhttp = new XMLHttpRequest();
		if (this.xmlhttp.overrideMimeType)
			this.xmlhttp.overrideMimeType("text/xml");
	}
	else if (window.ActiveXObject) {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	this.GetData = function(url, obj, callback,name,content) {
	    var self = this;
	    if (!this.xmlhttp) { alert("请更新你的浏览器"); return; }
	    this.xmlhttp.onreadystatechange = function() {
	        if (self.xmlhttp.readyState == 4) {
	            if (self.xmlhttp.status == 200) {
	                if (typeof callback == "function") {
	                    callback(self.xmlhttp.responseText,name,content);
	                }
	                if (document.getElementById(obj)) document.getElementById(obj).innerHTML = self.xmlhttp.responseText;
	            }
	            else
	                if (document.getElementById(obj)) document.getElementById(obj).innerHTML = "加载失败";
	        }
	    }
	    this.xmlhttp.open("GET", url, true);
	    this.xmlhttp.setRequestHeader("If-Modified-Since", "0");
	    this.xmlhttp.send(null);
	}
	
	this.PostData = function(url, data, callback,name,content) {
		var self = this;
		if(!this.xmlhttp) { alert("请更新你的浏览器"); return; }
		this.xmlhttp.onreadystatechange = function() {
			if (self.xmlhttp.readyState == 4) {
				if (self.xmlhttp.status == 200) {
	                if (typeof callback == "function") {
	                    callback(self.xmlhttp.responseText,name,content);
	                }
	            }
	            else
	            {
	                if(typeof errorCallback == "function")
	                {
	                    errorCallback(self.xmlhttp.responseText);
	                }
	            }
			}
		}
		this.xmlhttp.open("POST", url, true);
		this.xmlhttp.setRequestHeader("If-Modified-Since", "0");
		this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.xmlhttp.send(data);
	}
}
//全选
function AllCheck(objId,ckobj){
    var es = document.body.getElementsByTagName("input");
    for (var i = 0; i < es.length; i++) {
        var e = es[i];
        if (e.type == "checkbox" && e.name=="Sign") {
            e.checked = ckobj.checked;;
        }
    }
}
//删除帖子
function DelSubList(objId,TypeSubID,pageInfo){
var param=TypeSubID;
var IDList="";
if(TypeSubID==0){
var es = document.body.getElementsByTagName("input");
    for (var i = 0; i < es.length; i++) {
        var e = es[i];
        if (e.type == "checkbox" && e.checked && e.name=="Sign") {
            IDList+=e.value+",";
        }
    }
    param=IDList;
}
else if(TypeSubID==1){
IDList=objId;
}
else{
IDList=objId;
TypeSubID=0;
}
if(IDList==""){
    alert("请选择要删除的帖子");
    return;
}
if(confirm("确认删除吗？")){
var myajax = new Ajax2009();
myajax.GetData("Control/TopicMan.aspx?ID="+TypeSubID+"&TypeID=4&IDList="+IDList+"&T="+(new Date().getTime()),null,DelSucess,param,pageInfo);
}}
function DelSucess(res,param,pageInfo){
alert(res);
if(param==1)location.href="View.aspx?"+pageInfo;
else if(param==2)location.href="Default.aspx?"+pageInfo;
else{
var IDList=param.split(',');
for(var i=0;i<IDList.length-1;i++){if($('tr_sub'+IDList[i]))$('tr_sub'+IDList[i]).style.display="none";}
}}

//设为已回复
function SetBack(objId,TypeSubID,pageInfo){
var param=TypeSubID;
var IDList="";
if(TypeSubID==1){
IDList=objId;
}
else{
IDList=objId;
TypeSubID=0;
}
var myajax = new Ajax2009();
myajax.GetData("Control/TopicMan.aspx?ID="+TypeSubID+"&TypeID=5&IDList="+IDList+"&T="+(new Date().getTime()),null,SetBackSuccess,param,pageInfo);
}


function SetBackSuccess(res,param,pageInfo){
alert(res);
if(param==1)location.href="View.aspx?"+pageInfo;
else if(param==2)location.href="Default.aspx?"+pageInfo;
else{
var IDList=param.split(',');
for(var i=0;i<IDList.length-1;i++){if($('tr_sub'+IDList[i]))$('tr_sub'+IDList[i]).style.display="none";}
}}


function JumpGoto(id,type,rcount,pageSize,oThis){
    var index = oThis.txtPage.value;
    window.status = index;
    if(isNaN(index)){
     oThis.txtPage.value="";
     oThis.txtPage.focus();
     return false ;
    }
    else {
    var totalPage=(rcount / pageSize) + 1;
    if(index > totalPage){
    alert("输入的数大于总页数");
     oThis.txtPage.value="";
     oThis.txtPage.focus();
     return false ;
      }
    else if(index<=0){
    alert("请输入正整数");
    oThis.txtPage.value="";
    oThis.txtPage.focus();
     return false  ;
    }
    Goto(id,type,index,rcount);
    }
    return false;
}


//ajax翻页
function Goto(id,type,index,rcount){
if($("span_load"))$("span_load").innerHTML="<img src='images/loading.gif' />";
var myajax = new Ajax2009();
var Url="SubjectList.aspx";
if(type==-100){Url="SubjectBackList.aspx";if($("hid_page"))$("hid_page").value=index;}
if($("inp_key")&&$("inp_key").value!=""){
myajax.GetData("Control/SubjectList.aspx?keyType="+$("sel_Searche").value+"&keyWord="+escape($("inp_key").value)+"&id="+id+"&type="+type+"&page="+index+"&recordcount="+rcount+"&T="+(new Date().getTime()),null,Sucess2);
TongJi();return;
}
myajax.GetData("Control/"+Url+"?id="+id+"&type="+type+"&page=" +index+"&recordcount="+rcount+"&T="+(new Date().getTime()),null,Sucess,index);
TongJi();
}

function Sucess(res,name){
$("div_subList").innerHTML=res;
if($("span_load"))$("span_load").innerHTML="";
if($("div_pageButton")){$("td_pageButton1").innerHTML=$("div_pageButton").innerHTML;$("td_pageButton2").innerHTML=$("div_pageButton").innerHTML;}
else{$("td_pageButton1").innerHTML="";$("td_pageButton2").innerHTML="";}
if($("tr_top1")){
    if(name==1){$("tr_top1").style.display="";}
    else{$("tr_top1").style.display="none";}
}}



//编辑帖子
function Edit(urlHost,param){
    window.scrollTo(0,0);
	var editDiag = new Dialog("Diag");
	editDiag.Width = 900;
	editDiag.Height = 390;
	editDiag.Title = "编辑帖子";
	editDiag.URL =urlHost+ "Edit.aspx?"+param;
	editDiag.ShowButtonRow=false;
	editDiag.show();
}
//移动帖子
function Move(urlHost,id){
    window.scrollTo(0,0);
    var editDiag = new Dialog("Diag");
	editDiag.Width = 500;
	editDiag.Height = 130;
	editDiag.Title = "移动帖子";
	editDiag.URL =urlHost+ "Control/Move.aspx?SubjectID="+id;
	editDiag.ShowButtonRow=false;
	editDiag.show();
}
//显示大类别帖子
function ShowBigList(id,tag){
if(tag){
if($("List_"+id).style.display=="block"){$("List_"+id).style.display="none";$("img_ico"+id).src="images/icon_leftTitleHidden.gif";}
else {$("List_"+id).style.display="block";$("img_ico"+id).src="images/icon_leftTitleShow.gif";}
return;
}
location.href="Default.aspx?ID="+id+"&TypeID=1";
}
//引用帖子
function Quote(urlHost,ID,TypeID,param){
    window.scrollTo(0,0);
    var editDiag = new Dialog("Diag");
	editDiag.Width = 900;
	editDiag.Height = 390;
	editDiag.Title = "引用回复";
	editDiag.URL =urlHost+ "Edit.aspx?IsQuote=1&ID="+ID+"&TypeID="+TypeID+"&"+param;
	editDiag.ShowButtonRow=false;
	editDiag.show();
}
//回复帖子
function Back(urlHost,ID,TypeID,param){
    window.scrollTo(0,0);
    var editDiag = new Dialog("Diag");
	editDiag.Width = 900;
	editDiag.Height = 390;
	editDiag.Title = "管理员回复";
	editDiag.URL =urlHost+ "Edit.aspx?IsBack=1&ID="+ID+"&TypeID="+TypeID+"&page="+param;
	editDiag.ShowButtonRow=false;
	editDiag.show();
}
//搜索帖子
function search(id,TypeID){
if($("inp_key").value==""){alert("请输入关键字");return;}
if($("span_load"))$("span_load").innerHTML="<img src='images/loading.gif' />";
var myajax = new Ajax2009();
myajax.GetData("Control/SubjectList.aspx?keyType="+$("sel_Searche").value+"&keyWord="+escape($("inp_key").value)+"&id="+id+"&type="+TypeID+"&page=1&recordcount=-1&T="+(new Date().getTime()),null,Sucess2);
}
function Sucess2(res){
if($("span_load"))$("span_load").innerHTML="";
$("div_subList").innerHTML=res;
if($("div_pageButton")){$("td_pageButton1").innerHTML=$("div_pageButton").innerHTML;$("td_pageButton2").innerHTML=$("div_pageButton").innerHTML;}
else{$("td_pageButton1").innerHTML="";$("td_pageButton2").innerHTML="";}
}
//显示未回复帖子或被隐藏帖子
function showSel(id,TypeID){
if($("sel_select").value=="-1"){Nonload();return;}
if(TypeID==2){if($("sel_select").value=="0")Goto(id,5,1,-1);else if($("sel_select").value=="1") Goto(id,6,1,-1);else if($("sel_select").value=="2") Goto(id,10,1,-1);}
else {if($("sel_select").value=="0")Goto(id,7,1,-1);else if($("sel_select").value=="1") Goto(id,8,1,-1);else if($("sel_select").value=="2") Goto(id,9,1,-1);}
}
TongJi();
