﻿
function $(aID)
{
  return (document.getElementById) ? document.getElementById(aID): document.all[aID];
}
String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } 
var objName="yb860831";
var objmm="mm";
function makeRequest(url)
{
 	http_request=false;
 	if(window.XMLHttpRequest)
	{//Mozilla,Safari,...
		http_request=new XMLHttpRequest();
		if(http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml');
		}
 	}
	else if(window.ActiveXObject)
	{//IE
 		try
 		{
 			http_request=new ActiveXObject("Msxml2.XMLHTTP");
 		}
		catch(e)
		{
 			try
			{
 				http_request=new ActiveXObject("Microsoft.XMLHTTP");
 			}
			catch(e){}
 		}
 	}
 	if(!http_request)
	{
 		alert('Giving up:(Cannot create an XMLHTTP instance)');
 		return false;
 	}
	return http_request;
}
var Bbs = {
	"loginCallback":null
	/**
     *  显示登录窗口
     *
     *  callback 回调函数: function:自定义函数  true:重新执行调用“父函数”(调用本函数的函数)
     */
	,"nc_else":function (nc){
		alert(nc);
	}
    ,"showLoginDialog":function(callback) {
        if (typeof(callback) == "boolean" && callback){
            // true:
            
            var func = Bbs.showLoginDialog.caller;
            var args = func.arguments;
            var size = args.length;

            for (var i=0; i<args.length; i++) {
                if (typeof(args[i]) == "undefined") {
                    size;
                }
            }
            //alert(args[0]+","+args[1]+","+args[2]+","+args[3]+","+args[4]+",");
            if (size == 0) {
                this.loginCallback = function() {func();}
            }
            else if (size == 1) {
                this.loginCallback = function() {func(args[0]);}
            }
            else if (size == 2) {
                this.loginCallback = function() {func(args[0], args[1]);}
            }
            else if (size == 3) {
                this.loginCallback = function() {func(args[0], args[1], args[2]);}
            }
            else if (size == 4) {
                this.loginCallback = function() {func(args[0], args[1], args[2], args[3]);}
            }
            else {
                alert("目前还不支持"+size+"个参数的方法");
                this.loginCallback = null;
            }
        }
        else {
            //function:
            this.loginCallback = callback;
        }
       Dialog.show("用户登陆", "/bbs/images2/inc/loginDialog.inc.html", true,true);
	   Dialog.setWidth(400);
	}
	/**
     *  发送小纸条
     * @param uid 用户ID
     */
	,"sendMessage": function (uid){
		if (typeof(uid)=="undefined") {
            uid = 0;
        }
		if (getCookie()=="") Bbs.showLoginDialog(true);
		else {Dialog.defWidth=600;Dialog.show("发送小纸条", "/bbs/AjaxJS.aspx?lx=msg_write&uid="+uid,false,false);}
	}
	/**
     * 显示已发送纸条信息
     */
    ,"showSentMessage":function(pageid) {
        if (typeof(pageid)=="undefined") {
            pageid = 1;
        }
		if (getCookie()=="") Bbs.showLoginDialog(true);
        else
		{
			Dialog.show('已发送纸条', '/bbs/AjaxJS.aspx?lx=msg_send&pg='+pageid,false,false);
        	Dialog.setWidth(600);
		}
    }
	/**
     * 显示收件箱纸条信息
     */
    ,"showMessage":function(pageid) {
        if (typeof(pageid)=="undefined") {
            pageid = 1;
        }
		if (getCookie()=="") Bbs.showLoginDialog(true);
        else
		{
			Dialog.show('我的纸条', '/bbs/AjaxJS.aspx?lx=msg_show&pg='+pageid,false,false);
        	Dialog.setWidth(600);
		}
    }
	/**
     * 显示黑名单信息
     */
    ,"showMyBlackList":function(pageid) {
        if (typeof(pageid)=="undefined") {
            pageid = 1;
        }
		if (getCookie()=="") Bbs.showLoginDialog(true);
        else
		{
			Dialog.show('黑名单', '/bbs/AjaxJS.aspx?lx=BlackList&pg='+pageid,false,false);
        	Dialog.setWidth(600);
		}
    }
	/**
     * 增加黑名单
     */
    ,"addMyBlackList":function(pageid) {
        if (typeof(pageid)=="undefined") {
            pageid = 1;
        }
		if (getCookie()=="") Bbs.showLoginDialog(true);
        else
		{
			Dialog.show('黑名单', '/bbs/AjaxJS.aspx?lx=addBlackList&pg='+pageid,false,false);
        	Dialog.setWidth(600);
		}
    }
	/*
	** 纯登陆
	*/
	,"loginC":function (){
		if (AjaxVote.loginMessage().value=="0") this.showLoginDialog(true);
		else
		{
			var loginDM=getElement("login_div");
			if (loginDM!=null)
			{
				var loginCS=AjaxVote.loginMessage().value.split(',');
				if (loginCS.length==3)
				{loginDM.innerHTML="<span class='top_login_lan'>欢迎 </span><span class='top_login_cheng'>"+loginCS[1]+"</span><span class='top_login_lan'> 进入宜宾在线社区</span>  &nbsp;&nbsp;<a href='/useradmin/'><span class='top_login_redCD'>用户中心</span></a> &nbsp;&nbsp;<a href='logout.aspx'><span class='top_login_redCD'>退出登陆</span></a>&nbsp;&nbsp;&nbsp;&nbsp;";}
			}
		}
	}
	/*
	** 纯登陆状态判断
	*/
	,"loginZTC":function (){
		if (AjaxVote.loginMessage().value=="0") {};
		else
		{
			var loginDM=getElement("login_div");
			if (loginDM!=null)
			{
				var loginCS=AjaxVote.loginMessage().value.split(',');
				if (loginCS.length==3)
				{loginDM.innerHTML="<span class='top_login_lan'>欢迎 </span><span class='top_login_cheng'>"+loginCS[1]+"</span><span class='top_login_lan'> 进入宜宾在线社区</span>  &nbsp;&nbsp;<a href='/useradmin/'><span class='top_login_redCD'>用户中心</span></a> &nbsp;&nbsp;<a href='logout.aspx'><span class='top_login_redCD'>退出登陆</span></a>&nbsp;&nbsp;&nbsp;&nbsp;";}
			}
		}
	}
}
var Dialog = {
    "init":""
    ,"dialogBox":null
    ,"defWidth":400
    ,"width":0	
    /**
     * 显示窗口
     * @param title 窗口标题
     * @param url   窗口内容页面的URL
     * @param loadCss  是否加载CSS
     * @param loadJs  是否加载JS
	 * @param callbac  是否加载JS
     **/
    ,"show":function(title, url, loadCss, loadJs) {
		admin_select_yc(0);
        if (this.dialogBox == null) {
            //窗口不存在，自动创建
            this.create();
        }
        //alert("hh44");
        this.setWidth(this.defWidth);   //默认宽度

        

        this.dialogBox.style.display = "block";    //显示窗口
        
        this.setTitle(title); //设置标题
        
        this.loading = setTimeout("Dialog.setLoading()", 200);  //200毫秒内数据没有加载就会显示“数据加载中...”
        
        Drag.init($("draghead"), this.dialogBox);

        this.dialogBox.onDragEnd=function(x,y){
          Dialog.dialogBox.ox=x-Dialog.getRange().left;
          Dialog.dialogBox.oy=y-Dialog.getRange().top;
        }
		
        this.center();   //当浏览器不是在第一屏的位置显示窗口会看不见，所以要让它自动在当前屏幕的中间显示
        
		this.loadContent(url, loadCss, loadJs);  //加载窗口内容
		
    }
    ,"setWidth":function(width) {
        if (width != this.width) {
            this.width = width;
            this.dialogBox.style.width = width+"px";
            this.center();
            
        }
        
    }
    ,"loading":null
    ,"setLoading":function() {
        this.setContent(" &nbsp;&nbsp;&nbsp;&nbsp;数据加载中...");
    }
    ,"clearLoading":function() {
        if (this.loading != null) {
            clearTimeout(this.loading);
            this.loading = null;
        }
    }

    /**
     *  加载窗口内容
     */
    ,"loadContent":function(url, loadCss, loadJs) {  
			url2=url;
			if (url.indexOf("?")>-1) url+="&"+(new Date().getTime());
 			else url+="?"+(new Date().getTime());
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					Dialog.clearLoading();
					$("dialogBox_content").innerHTML=xhttp.responseText;
					else_czlx=1;
					if (loadCss){
               			 Dialog.loadCss(url2+".css");
            		}
					if (loadJs) {
                Dialog.loadJs(url2+".js");
           			}					
				}
			}
			xhttp.open("GET",url,true);
			xhttp.send(null);
        //使用GET方式会有缓存问题，所以要使用POST
    }
    /**
     * 设置窗口内容（提示信息）.
     */
    ,"setContent":function(content) {
        $("dialogBox_content").innerHTML = "<div class='dialogBox_Content'>"+content+"</div>";    
    }

    /**
    * 关闭窗口
    **/
    ,"close":function() {
        if (this.dialogBox != null) {
            this.dialogBox.style.display = "none";
        }
		admin_select_yc(1);
    }
    /**
    * 设置窗口的标题
    * @html  窗口的标题，支持HTML
    */
    ,"setTitle":function(html) {
        $("dialogBox_title").innerHTML = html;
    }
    

    /**
    * 创建窗口
    */
    ,"create":function() {
        this.loadCss("/bbs/images2/dialog.css");
        var dialogBox = document.createElement("DIV");
        dialogBox.id = "dialogBox";
        dialogBox.className = "dialogBoxBg";
        var html = '<div class="dialogBox" style="cursor:pointer;"><div id="draghead" class="title"><h2 id="dialogBox_title"></h2><span><a href="javascript:Dialog.close()" target="_self"><img src="/bbs/images2/login01_div.gif" style="cursor:pointer" height="18" width="49" border="0" alt="关闭窗口" /></a></span></div><div class="content" id="dialogBox_content"></div></div>';
        dialogBox.innerHTML = html;
        
        document.body.appendChild(dialogBox); 

        this.dialogBox = $("dialogBox");


        this.center();  //设置窗口位置

        window.onscroll=Dialog.onBodyScroll;
    }
    
    /**
    * 加载CSS
    */
    ,"loadCss":function(filename) {
        var head = document.getElementsByTagName('HEAD').item(0);
        var style = document.createElement('link');
        style.href = filename;
        style.rel = 'stylesheet';
        style.type = 'text/css';
        head.appendChild(style);
    }
    /**
     * 加载JS
     * @param filename 脚本URL
     */
    ,"loadJs":function(filename) {
        var script = $("js1");   //应该将filename MD5编码后作为ID使用
        if (script == null) {
            script = document.createElement("script");
        }
        script.id = "js1";
        script.src = filename;
        
        //为什么要使用insertAdjacentElement？,因为appendChild在JS文件已经存在浏览器缓存时就会出现IE崩溃的情况(Bbs.editArticle方法就会出现,postArticle则正常)
        if (document.frames) {
            document.body.insertAdjacentElement("BeforeBegin",script);
        }
        else {
            document.body.appendChild(script);  //
        }
    }
    ,"onBodyScroll":function(){
        var range=Dialog.getRange();
        var top = (range.top+Dialog.dialogBox.oy);
        var left = (range.left+Dialog.dialogBox.ox);
        if (top < 5) { top  = 5; }
        if (left< 5) { left = 5; }
        
        Dialog.dialogBox.style.top=top +"px";
        Dialog.dialogBox.style.left=left +"px";

        //document.title = "scroll:"+top;
    }

    /**
     *  设置窗口居中显示
     */
    ,"center":function() {
        var range=Dialog.getRange();

        var left = (range.width-this.width)/2;
        var top  = (range.height-400)/2;

        this.dialogBox.ox= left;
        this.dialogBox.oy= top;

        if (range.left > left) { left = range.left+left;}
        if (range.top  > top ) { top  = range.top +top;}

        this.dialogBox.style.left = left + "px";
        this.dialogBox.style.top = top + "px";

        //document.title = "center:"+top;
    }
    /**
     * 移动窗口位置
     * @left 
     * @top 
     */
    ,"move":function(left, top) {
        this.dialogBox.ox= left;
        this.dialogBox.oy= top;

        this.dialogBox.style.left = left + "px";
        this.dialogBox.style.top = top + "px";
    }


    ,"getRange":function() {
        var top     = document.documentElement.scrollTop;
        var left    = document.documentElement.scrollLeft;
        var height  = document.documentElement.clientHeight;
        var width   = document.documentElement.clientWidth;

        if (top==0 && left==0 && height==0 && width==0) {
            top     = document.body.scrollTop;
            left    = document.body.scrollLeft;
            height  = document.body.clientHeight;
            width   = document.body.clientWidth;
        }
        return  {top:top  ,left:left ,height:height ,width:width } ;
    }

}
var Drag={
        "obj":null,
	"init":function(a, aRoot){
      a.onmousedown=Drag.start;
      a.root = aRoot;
      if(isNaN(parseInt(a.root.style.left)))a.root.style.left="0px";
      if(isNaN(parseInt(a.root.style.top)))a.root.style.top="0px";
      a.root.onDragStart=new Function();
      a.root.onDragEnd=new Function();
      a.root.onDrag=new Function();
		},
	"start":function(a){	
			var b=Drag.obj=this;
			a=Drag.fixE(a);
			var c=parseInt(b.root.style.top);
			var d=parseInt(b.root.style.left);
			b.root.onDragStart(d,c,a.clientX,a.clientY);
			b.lastMouseX=a.clientX;
			b.lastMouseY=a.clientY;
			document.onmousemove=Drag.drag;
			document.onmouseup=Drag.end;
			return false;
		},	
	"drag":function(a){
			a=Drag.fixE(a);
			var b=Drag.obj;
			var c=a.clientY;
			var d=a.clientX;
			var e=parseInt(b.root.style.top);
			var f=parseInt(b.root.style.left);
			var h,g;
			h=f+d-b.lastMouseX;
			g=e+c-b.lastMouseY;
			b.root.style.left=h+"px";
			b.root.style.top=g+"px";			
			b.lastMouseX=d;
			b.lastMouseY=c;
			b.root.onDrag(h,g,a.clientX,a.clientY);
			return false;
		},
	"end":function(){			
			document.onmousemove=null;
			document.onmouseup=null;
			Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
			Drag.obj=null;
		},
	"fixE":function(a){
			if(typeof a=="undefined")a=window.event;
			if(typeof a.layerX=="undefined")a.layerX=a.offsetX;
			if(typeof a.layerY=="undefined")a.layerY=a.offsetY;
			return a;
		}
};

Object.printAll = function(obj) {
    var msg = "";
    var i = 0;
    for (dd in obj) {
        msg += dd + "  ";
        if ((i+1)%5==0) {
          msg += "\n";
        }
        i++;
    }
    alert(msg);
}

var  BbsUtil= {
	"getBytes":function(str) {
        if (str == null) {
            return 0;
        }
        var bytes = 0;
        for(i=0;i<str.length;i++){
            var c = str.charCodeAt(i);
            if((c>=0 && c<=255)||(c>=0xff61 && c<=0xff9f)){
                bytes += 1;
            }else{
                bytes += 2;
            }
        }
        return bytes;
    }
}
var  BbsAdmin= {	 
	/*
	*发送短消息
	*/
	"SendMsg":function(uname,msgnr){
		if (getCookie()=="") Bbs.showLoginDialog(true);
		else
		{
			var str="l=3&u="+encodeURI(encodeURI(uname))+"&n="+encodeURI(encodeURI(msgnr));
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					var fhjg=xhttp.responseText.Trim();
					if (fhjg=="") 
					{
						alert("发送小纸条成功！！");
						Dialog.close();
					}
					else {alert(fhjg); return false;}
				}
			}
			xhttp.open("POST","JsVote.aspx",true);
			xhttp.setRequestHeader("Content-Length",str.length);
			xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			xhttp.send(str);
		}
	}
	/*
	*删除短消息
	*/
	,"DelMsg":function(mid,fs,pg){
		if (getCookie()=="") Bbs.showLoginDialog(true);
		else
		{
			var str="l=4&mid="+mid+"&fs="+fs;
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					var fhjg=xhttp.responseText.Trim();
					if (fhjg=="") 
					{
						alert("删除小纸条成功！！");
						if (fs=="0") Bbs.showSentMessage(pg);
						else Bbs.showMessage(pg);
					}
					else {alert(fhjg); return false;}
				}
			}
			xhttp.open("POST","JsVote.aspx",true);
			xhttp.setRequestHeader("Content-Length",str.length);
			xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			xhttp.send(str);
		}
	}
	/**
     * 提交普通投票
     */
    ,"Votetj":function(vid) {
		if (typeof(vid)=="undefined") {
            vid = 0;
        }
		if (parseInt(vid)<1) {alert("参数错误！！");return false;}
		else if (getCookie()=="") Bbs.showLoginDialog(true);
		else
		{
			var str=this.getid();
			if (str.length<2)
			{
				alert("请选择你要投票的选项");return false;
			}
			str="&l=13&cs="+str+"&vid="+vid;
			//alert(str);return;
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					var fhjg=xhttp.responseText.Trim();
					if (fhjg=="") 
					{
						alert("提交投票成功！！");
						BbsAdmin.VoteElse(vid);
					}
					else {alert(fhjg); return false;}
				}
			}
			xhttp.open("POST","JsVote.aspx",true);
			xhttp.setRequestHeader("Content-Length",str.length);
			xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			xhttp.send(str);
		}
	}
	/**
     * 显示投票内容
     */
    ,"VoteElse":function(vid) {
		if (typeof(vid)=="undefined") {
            vid = 0;
        }
		if (vid==0) return;
		var str="l=12&cs="+vid;
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					var fhjg=xhttp.responseText.Trim();
					if (fhjg=="") 
					{
					}
					else {$("voteelse").innerHTML=fhjg;}
				}
			}
			xhttp.open("POST","JsVote.aspx",true);
			xhttp.setRequestHeader("Content-Length",str.length);     
			xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			xhttp.send(str);
	}
	,"getid":function (){
			var arrChks = new Array();
			arrChks     = this.GetChkVlas(document.getElementsByName('VoteXz'));
			var str="";
			var tt=arrChks.length;
			for (i=0;i<tt;i++)
			{
				str=str+arrChks[i]+",";
			}
			return str;
	}
	,"GetChkVlas":function (chks){
		 var arrChks = new Array();
	 	 arrChks     = chks;
	  
	     var iNum   = arrChks.length;
	     var arrVal = new Array();
	  
	     var j = 0;
	     for(i=0;i<iNum;i++)
	     {
	      if(arrChks[i].checked)
	      {
	       arrVal[j] = arrChks[i].value;
	       j++;
	      }
	    }	  
	    return arrVal;
	}
	/**
	* 发布新帖
	* 版面ID
	**/
	,"newsadd":function (bid,lx){	
		if (getCookie()=="") Bbs.showLoginDialog(true);
		else
		{
			if (lx==0) window.self.location="bbs_post.aspx?id="+bid;
			else window.self.location="bbs_post.aspx?lx=vote&id="+bid;
		}
	}
}
function admin_select_yc(a){
			var admin_select_arr = new Array();
			admin_select_arr     = document.getElementsByName('admin_select');
			var admin_select_iNum   = admin_select_arr.length;
			var admin_select_zt="";
			if (a==0) admin_select_zt="none";
			for (i=0;i<admin_select_iNum;i++)
			{
				admin_select_arr[i].style.display=admin_select_zt;
			}
}
function getCookie(){
	var arrStr=escape(document.cookie).replace(/(mm%3D)/g,"=mm=").replace(/(%3D)/g,"=").replace(/(%3B)/g,";").replace(/(%20)/g,"").replace(/(%26)/g,"=").split(";");
	var mm="";
    for(var i = 0;i < arrStr.length;i ++){
     var temp = arrStr[i].replace(/\&/g,"=").split("=");
     if(temp[0].Trim() == objName) 
	 {
		 for (var q=1;q<temp.length-1;q++)
		 {
			 if (temp[q].Trim()==objmm )
			 {
				 mm=temp[q+1].Trim();break;
			 }
		 }
	 }
    }
	if (mm.length!=32)  mm="";
	return mm;
}
function userloginpg()
		{
			if ($("userloginname").value.Trim()=="")
			{
				alert("用户名不能为空！！");return;
			}
			if ($("userloginmm").value.Trim()=="")
			{
				alert("用户密码不能为空！！");return;
			}
			var userloginckz=0;
			if ($("userloginck")) userloginckz=1;
			var str="l=1&u="+escape($("userloginname").value.Trim())+"&m="+escape($("userloginmm").value.Trim())+"&b="+userloginckz;
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					var fhjg=xhttp.responseText.Trim();
					if (fhjg=="") 
					{
						userloginzt();						
					}
					else {alert("登陆失败！用户名或密码错误");}
				}
			}
			xhttp.open("POST","JsLogin.aspx",true);
			xhttp.setRequestHeader("Content-Length",str.length);     
			xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			xhttp.send(str);
		}
		function userloginzt()
		{
			var str="l=2";
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					var fhjg=xhttp.responseText.Trim();
					if (fhjg=="") 
					{
						alert("用户登陆信息获取出错");
					}
					else {$("pgUserLogin").innerHTML=fhjg;}
				}
			}
			xhttp.open("POST","JsLogin.aspx",true);
			xhttp.setRequestHeader("Content-Length",str.length);     
			xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			xhttp.send(str);
		}

