var global_forumid='0';
var global_topicid='0';
function foruminit(forumid)
{
	global_forumid=forumid;
}
function topicinit(topicid)
{
	global_topicid=topicid;
}

/*
//下面已有相同功能的函数ltrim() rtrim() trim()
function LTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);   

    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);

    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

 
function Trim(str)
{
    return RTrim(LTrim(str));
}*/

function go(strUrl)
{
	strUrl=strUrl.replace("{0}",global_forumid);
	strUrl=strUrl.replace("{1}",global_topicid);
	window.location.href=strUrl;
}

function post()
{
	go("newtopic.aspx?forumid={0}");
}
function reply()
{
	go("retopic.aspx?forumid={0}&topicid={1}");
}

function next()
{
	go("newtopic.aspx?topicid={1}&forumid={0}&action=next");
}
function pre()
{
	go("newtopic.aspx?topicid={1}&forumid={0}&action=pre");

}
function themebelongtopic(pid)
{
	go("showforum.aspx?forumid={0}&action=themebelong&themebelong="+pid);
}
function goodtopic()
{
	go("showforum.aspx?forumid={0}&action=goodtopic");
}

function frequentproblemtopic()
{
    go("showforum.aspx?forumid={0}&action=frequentproblemtopic");
}

function showforum()
{
	go("showforum.aspx?forumid={0}");
}

function showrule()
{
    var url= "http://popkart.tiancity.com/homepage/Community/bbsorder.htm";
    var mode = "width=520,height=550,toolbar=no,scrollbars=yes,location=no,resizeable=yes,menubar=no";
    var name = "服务条款";
    window.open(url,name,mode);
}

function managetopic(strAction)
{
	go("managetopic.aspx?topicid={1}&forumid={0}&action="+strAction);
}

function manageNickname(strAction,nickname,regionid)
{
	if ("[游客]"==nickname) { 
		return;
	}
	go("managetopic.aspx?topicid={1}&forumid={0}&action="+strAction+"&nickname="+nickname+"&regionid="+regionid);
}

function searchforum()
{
    var objType = document.getElementById("SearchOptions");
    var ptype="";
    if(objType == null)
    {
        return;
    }
    else
    {
        ptype = objType.options[objType.selectedIndex].value; 
    }
    var objValue = document.getElementById("SearchValue");
    var pvalue = "";
    if(objValue == null)
    {
        return;
    }
    else
    {
        pvalue = objValue.value;
    }
    var url = "showforum.aspx?forumid={0}&action=searchtopic&ptype="+ptype+"&pvalue="+pvalue;
    go(url);
}

function showpagelst(ID,replies,p_pagesize)
{
var pagesize=15;
if (null!=p_pagesize) {
	pagesize=p_pagesize;
}
if (replies > pagesize) {
var topicpage=""
var tol=replies/pagesize+1;

for (var i=1; i < tol; i++) {
if(i<4 || i>=tol-2){
topicpage=topicpage+"<b><a href=showpost.aspx?forumid="+global_forumid+"&topicid="+ID+"&PageIndex="+ i +">"+ i +"</a></b> ";
}
if (i >= tol-3  && i<tol-2 && i>3){topicpage=topicpage+" ... ";}
}
document.write(" ( "+topicpage+")");
}
}

function showtopicimg(cooknickname,cookieregion,nickname,regionid,Views,icon,toptopic,locktopic,pollresult,goodtopic,replies,lastname,lastregion,lasttime)
{
var urlpath="http://image.tiancity.com/popkart/bbs/";
var newDate=new Date()

newDate=""+newDate.getYear()+"-"+[newDate.getMonth()+1]+"-"+newDate.getDate()+"";
var key_word=""; 
if(lasttime.indexOf(newDate) == 0){lasttime = lasttime.replace(newDate,"今日");}
//topic = topic.replace(key_word,"<font color=red>"+key_word+"<\/font>");
if (toptopic == 2) {reimage="<img src="+ urlpath +"top.gif border=0>"}
else
if (toptopic == 1) {reimage="<img src="+ urlpath +"top.gif border=0>"}
else
if (locktopic== 1) {reimage="<img src="+ urlpath +"BBS_03.gif border=0>"}
else
if (pollresult!= '') {reimage="<img src="+ urlpath +"vote.gif border=0>"}
else
if ((replies>15) || (Views>150)) {reimage="<img src="+ urlpath +"hot.gif border=0>"}
else
if (replies>0) {reimage="<img src="+ urlpath +"BBS_01.gif border=0>"}
else{reimage="<img src="+ urlpath +"BBS_02.gif border=0>"}

if (goodtopic== 1) {reimage2="<img src="+ urlpath +"ess.gif border=0>"}
else
if (cooknickname== nickname  && cookieregion==regionid){reimage2="<img src="+ urlpath +"self.gif border=0>"}
else{reimage2=""}

if (replies>0) {reimage3=replies}
else{reimage3="-"}
document.write(reimage);

if (reimage=="") {
document.write(reimage2);
}
}

function ShowForum(ID,topic,newtopic,username,Views,icon,toptopic,locktopic,pollresult,goodtopic,replies,lastname,lasttime)
{
return;
var newDate=new Date()
newDate=""+newDate.getYear()+"-"+[newDate.getMonth()+1]+"-"+newDate.getDate()+""

var key_word="";
var cookieusername="daniel";
if(lasttime.indexOf(newDate) == 0){lasttime = lasttime.replace(newDate,"今日");}
topic = topic.replace(key_word,"<font color=red>"+key_word+"<\/font>");
if (toptopic == 2) {reimage="<img src=images/top.gif>"}
else
if (toptopic == 1) {reimage="<img src=images/f_top.gif>"}
else
if (locktopic== 1) {reimage="<img src=images/f_locked.gif>"}
else
if (pollresult!= '') {reimage="<img src=images/f_poll.gif>"}
else
if ((replies>15) || (Views>150)) {reimage="<img src=images/f_hot.gif>"}
else
if (replies>0) {reimage="<img src=images/f_new.gif>"}
else{reimage="<img src=images/f_norm.gif>"}

if (goodtopic== 1) {reimage2="<img src=images/topicgood.gif>"}
else
if (username == cookieusername) {reimage2="<img src=images/my.gif>"}
else{reimage2=""}

if (replies>0) {reimage3=replies}
else{reimage3="-"}

document.write("<tr height=25><td align=middle width=3% class=a4>"+reimage+"</td>");
document.write("<td width=3% class=a3 align=center>"+reimage2+"</td>");
document.write("<td class=a4 width=45%>&nbsp; <a target=_blank href=ShowPost.asp?id="+ID+"><img border=0 src=images/brow/"+icon+".gif></a> <a href=ShowPost.asp?id="+ID+">"+topic+"</a>");

if (replies > 15) {
var topicpage=""
var tol=replies/15+1;

for (var i=1; i < tol; i++) {
if(i<4 || i>=tol-2){
topicpage=topicpage+"<b><a href=ShowPost.asp?id="+ID+"&topage="+ i +">"+ i +"</a></b> ";
}
if (i >= tol-3  && i<tol-2 && i>3){topicpage=topicpage+" ... ";}
}
document.write(" ( <img src=images/multipage.gif> "+topicpage+")");
}

document.write(" "+newtopic+"</td><td align=middle width=9% class=a3><a href=Profile.asp?username="+username+">"+username+"</a></td><td align=middle width=6% class=a4>"+reimage3+"</td><td align=middle width=7% class=a3>"+Views+"</td><td width=27% class=a4>&nbsp;"+lasttime+" by <a href=Profile.asp?username="+lastname+">"+lastname+"</a></td></tr>");
document.write("<tr height=25 style=display:none id=follow"+ID+"><td width=3% class=a4>　</td><td width=3% class=a3>　</td><td id=followTd"+ID+" align=left class=a4 width=94% colspan=5>　Loading...</td></tr>");
}


function showhot(bVisible)
{
	if (true==bVisible || 1==bVisible) {
		showimg("hot");
	}
}
function showtop(bVisible)
{
	if ( 2==bVisible) {
		showimg("top");
	}else if (1==bVisible) {
		showimg("self");
	}
	
}
function showess(bVisible)
{
	if (true==bVisible || 1==bVisible) {
		showimg("ess");
	}
}
function showvote(bVisible)
{
	if (true==bVisible || 1==bVisible) {
		showimg("vote");
	}
}

function showself(bVisible)
{
	if (true==bVisible || 1==bVisible) {
		showimg("self");
	}
} 
function showimg(filename)
{
	document.write("<img src='images/"+filename+".gif' width='45' height='13'>");
}
function show_panel(pnlName,bVisible)
{
	var obj=document.getElementById(pnlName);
	
	if (null!=obj) {
		if (false==bVisible || 0==bVisible) {
			obj.style.display="none";
		}else
		{
			obj.style.display="block";			
		}		
	}
}


var global_css=0;
function css_color(objname,color1,color2)
{ 
	var obj=document.getElementById(objname);
	if(null!=obj)
	{	
		if((global_css++  % 2)==0)
		{
			obj.bgColor= color1;
		}else
		{
			obj.bgColor=color2;
		}
	}
}


function openkart(region,crolename,action)
{
	if ("[游客]"==crolename) {
		return;
	}
	var strurl="http://apppopkart.tiancity.com/kartguide.aspx?URL=kart/index&REGION="+region+"&ROLENAME="+crolename;
	if (null!=action) {
		if (action.indexOf("kart")>=0) {
			strurl="http://apppopkart.tiancity.com/kartguide.aspx?URL="+action+"&REGION="+region+"&ROLENAME="+crolename;
		}
	}
	window.open(strurl,null,"height=445,width=595");	
}


function imagenull(srcin)
{
	//imagenullex(srcin);
	//setTimeout("imagenullex('"+Trim(srcin)+"')",2000);	
	setTimeout("imagenullex('"+srcin+"')",2000);	
}
function imagenullex(srcin)
{
	for(i=0;i<document.images.length;i++)
    {
        if (null!=document.images[i]) {
			if (document.images[i].id.indexOf("userface") >=0) {			    
				if(document.images[i].fileSize <0)
				{
                  document.images[i].src=srcin;   
				}
				if(!IsValidImgUrl(GetServerNameOfUrl(document.images[i].src)))
				{
				  document.images[i].src=srcin; 
				}
			}
        }        
    }
 }
 
//得到网址的域名：
function GetServerNameOfUrl(strUrl)
{
   if(null == strUrl)
   {
      return;
   }
   var url=new String(strUrl);
   url = url.replace("http://","");
   if(url.indexOf("/") > 0)
   {
      url = url.substring(0,url.indexOf("/"));
   }
   return url;        
}  
function IsValidImgUrl(strUrl)
{
   if(null == strUrl)
   {
      return false;
   }
   var url = new String(strUrl);   
   
   if(url == "popkart.tiancity.com")
   {
      return true;
   }
   
   if(url == "upload.tiancity.com")
   {
      return true;
   }    
   if(url == "file.tiancity.com")
   {
      return true;
   }    
   
   return false;
} 
        
function LogoNull(srclogo)
{
    for(i=0;i<document.images.length;i++)
    {
         var imgId = document.images[i].id.toString();
         if(imgId !="" && imgId.indexOf("BbsCfgImg") !=-1)
         {
             if(document.images[i].fileSize == -1)
             {
                 document.images[i].src=srclogo;                //"http://popkart.tiancity.com/homepage/guide/images/character_ethi.gif";  //bbsconfig 默认logof 地址
             }
         } 
    }
}


//  标题与内容以为空
  var nTopicLen=0;
  var nContLen=0;
       function limitCont(vb)
       {
          nContLen = parseInt(vb);
       }
       function limitTopicCont(va,vb)
        {
          nTopicLen=parseInt(va);
          nContLen=parseInt(vb); 
        }  
       function contCheck()       //检查内容
       {
         var txtCnt = document.getElementById("txtContent");
	        if(null==txtCnt)return false;
            if(txtCnt.value.length ==0)
           {
              window.alert("主题内容不要为空");
              txtCnt.select();
              txtCnt.focus();
              return false;
           }
           if(txtCnt.value.length > nContLen)
           {
              window.alert("主题内容过长,不要超过"+nContLen+"个字符");
              txtCnt.select();
              txtCnt.focus();
              return false;
           }   
            if(trim(txtCnt.value) == "")
           {
             window.alert("内容不要只是空格！");
             txtCnt.focus();
             txtCnt.select();
             return false;
           }      
           
           var chk = document.getElementById("txtChkCode");
           if(null==chk)return false;
            if(chk.value.length ==0)
           {
              window.alert("请输入验证码");
               chk.select();
               chk.focus();
              return false;
           }
           if(chk.value.length >=5)
           {
              window.alert("验证码错误");
               chk.select();
               chk.focus();
              return false;
           }
             
           return true;    
       }      
       
       function topicContCheck()     //检查标题与内容
        {
           var title = document.getElementById("txtTopic");
		   if(null==title)return false;
           if(title.value.length == 0)
           {
              window.alert("标题不要为空");
              title.select();
              title.focus();
              return false;
           }
           if(title.value.length > nTopicLen)
           { 
              window.alert("标题过长");
              title.focus();
              title.select();
              return false;
           }   
           if(trim(title.value) == "")
           {
             window.alert("标题不要只输入空格！");
             title.focus();
             title.select();
             return false;
           }
           
           var txtCnt = document.getElementById("txtContent");
	        if(null==txtCnt)return false;
            if(txtCnt.value.length ==0)
           {
              window.alert("主题内容不要为空");
               txtCnt.select();
               txtCnt.focus();
              return false;
           }
           if(txtCnt.value.length > nContLen)
           {
              window.alert("主题内容过长");
              txtCnt.focus();
              txtCnt.select();
              return false;
           }   
           if(trim(txtCnt.value) == "")
           {
             window.alert("内容不要只是空格！");
             txtCnt.focus();
             txtCnt.select();
             return false;
           } 
           
           var lstTh = document.getElementById("lstTheme");
           if(lstTh != null)
           {
              if(lstTh.selectedIndex == 0)
              { 
                 window.alert("请选择所属主题");
                 return false;
              }
           }  
            
           var chk = document.getElementById("txtChkCode");
           if(null==chk)return false;
            if(chk.value.length ==0)
           {
              window.alert("请输入验证码");
               chk.select();
               chk.focus();
              return false;
           }
           if(chk.value.length >=5)
           {
              window.alert("验证码错误");
               chk.select();
               chk.focus();
              return false;
           }
           if(!validata()){
				return false;
           }                
           return true;    
        }    
        
       function ltrim(str)    //去掉左空格
        {
         str = str.replace(/^\s*/,"");
         return str;
        }
         
        function rtrim(str)     //去掉右空格
        {
         str = str.replace(/\s*$/,"");
         return str;         
        }
         
        function trim(str)    //去掉左右空格
        {
          return(rtrim(ltrim(str)));
        }  
        
  
  //初始化网区
 function initNetRegion(netValue)
 {
    document.write("<SELECT id=\"listNetRegion\" name=\"listNetRegion\">");
    document.write("<OPTION value=\"1\">电信一区</OPTION>");
    document.write("<OPTION value=\"3\">电信二区</OPTION>");
    document.write("<OPTION value=\"2\">网通一区</OPTION>");
     document.write("<OPTION value=\"4\">网通二区</OPTION>");
    document.write("</SELECT>");
    
    if(null == netValue)
    {
        return;
    }
    var i = 0;
    var objNR = document.getElementById("listNetRegion");
    if(objNR == null)
    {
        return;
    }
    for(i=0;i<objNR.length;i++)
    {
        if(objNR.options[i].value == netValue)
        {
           objNR.options[i].selected = true;
           break;
        }
    }
 }
 
 //显示网区
 function dispNetRegion(netValue)
 {
    if(null == netValue)
    {
       return;
    }
    var nNet = parseInt(netValue);
    switch(nNet)
    {
       case 1:
             document.write("电信一区");
             break;
       case 3:
             document.write("电信二区");
             break;
       case 2:
             document.write("网通一区");
             break;
       case 4:
             document.write("网通二区");
             break;         
       default:
             document.write("未知区域");                  
    }
 }
 
 //短讯息提示
 function showMsg(nCount)
 {
    if(nCount == null)
    {
       return;
    }
    var n = parseInt(nCount);
    if(n<=0)
    {
       return;
    }
    else
    {
       document.write("<bgsound src=\"Modules/log_ct/msg.wav\">");
       document.write("<b><a href=\"msgbox.aspx\" target=\"_blank\">");
       document.write("你有");
       document.write(n);
       document.write("条新短信</a></b>");
    }
 }    
   
   //显示 短信，删除，编辑，引用 按钮。   
  function buttonlists(nickname,regionid,replyid,ftype)
{   
    if(ftype == "reforum")
    { 
        document.write(" <td align=\"center\" width=\"56\">");
        document.write("<a onclick=\"sendmsg('"+nickname+"','"+regionid+"');\"> ");
        document.write(" <img style=\"cursor:hand\"  src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_16.jpg\" alt=\"发送短讯息\"  width=\"56\" height=\"23\"> </a>");
        document.write("  </td>");
   
        document.write(" <td  align=\"center\" width=\"55\">");
        document.write(" <a href=\"retopic.aspx?forumid="+global_forumid+"&topicid="+global_topicid+"&replyid="+replyid+"&action=del\" onclick=\"return  confirm('确定删除回复内容吗？');\"> ");
        document.write(" <img  src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_17.jpg\" alt=\"删除\" width=\"55\"  height=\"23\" border=0> </a>");
        document.write(" </td> ");
        
        document.write(" <td  align=\"center\" width=\"55\">");
        document.write(" <a  href=\"retopic.aspx?forumid="+global_forumid+"&topicid="+global_topicid+"&replyid="+replyid+"&action=edit\"> ");
        document.write(" <img  src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_18.jpg\" alt=\"编辑\" width=\"55\"  height=\"23\" border=0> </a>");
        document.write(" </td> ");
  
        document.write(" <td  align=\"center\" width=\"55\"> <a  href=\"retopic.aspx?forumid="+global_forumid+"&topicid="+global_topicid+"&replyid="+replyid+"&action=quote\">");
        document.write("  <img  src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_19.jpg\" alt=\"引用\" width=\"55\"  height=\"23\" border=0> </a> ");
        document.write("  </td>");
   }
   else if(ftype == "forum")
   {
        document.write("<td align=\"center\" valign=\"top\"  width=\"56\">"); 
        document.write("<a onclick=\"sendmsg('"+nickname+"','"+regionid+"');\">");
        document.write("<img style=\"cursor:hand\" src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_16.jpg\" alt=\"发送短讯息\" width=\"56\" height=\"23\">"); 
        document.write("</a> </td>");
        
        document.write("<td align=\"center\" valign=\"top\"  width=\"55\">");
        document.write("<a href=\"newtopic.aspx?topicid="+global_topicid+"&forumid="+global_forumid+"&action=del\" onclick=\"return confirm('确定删除此主题吗？');\">");
        document.write("<img src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_17.jpg\" alt=\"删除\" width=\"55\" height=\"23\" border=0> </a> ");
        document.write("</td>");
        
        document.write("<td align=\"center\" valign=\"top\"  width=\"55\">");
        document.write("<a href=\"newtopic.aspx?topicid="+global_topicid+"&forumid="+global_forumid+"&action=edit\">");
        document.write("<img src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_18.jpg\" alt=\"编辑\" width=\"55\" height=\"23\" border=0> </a> ");
        document.write("</td>");
        
        document.write("<td align=\"center\" valign=\"top\"  width=\"55\">");
        document.write("<a href=\"retopic.aspx?forumid="+global_forumid+"&topicid="+global_topicid+"&action=quote\">");  
        document.write("<img src=\"http://popkart.tiancity.com/homepage/Community/images/bbs4_19.jpg\" alt=\"引用\" width=\"55\" height=\"23\" border=0></a>");  
        document.write("</td>"); 
   }
 }
 
 //从showpost移过来的
function sendmsg(nickname,regionid)
{
	var url = "newmsg.aspx?act=reply";
	if(nickname != null)
	{
		url = url + "&nickname=" + nickname;
	}
	if(regionid != null)
	{
		url = url + "&regionid=" + regionid;
	}
	
	var mode = "width=400,height=280,toolbar=no,scrollbars=no,location=no,resizeable=yes,menubar=no";
	var name = "newwindow";
	window.open(url,name,mode);
}	
function replyalarm(objstat)
{
	var cf = false;
	if(objstat != "login")
	{
		cf = window.confirm("亲爱的用户,你尚未登录论坛，快速回复将无法使用！");
	}
	else
	{
		cf = true;
	}
	if(cf)
	{
		return true;
	}
	return false;
}	
// ---
				
 
 //验证有没有选择投票的类型
function validata(){
	var objchkPoll = document.getElementById("chkPoll");
	var objrdoPoll1=document.getElementById("rdoListPoll_0");			
	var objrdoPoll2=document.getElementById("rdoListPoll_1");
	var objtxtPollContent=document.getElementById("txtPollTitle");
	var nItemCount = document.getElementsByName("rdoListPoll").length;
	var objrdoPoll = document.getElementsByName("rdoListPoll")
	if(objchkPoll.checked==true){					
		if(objrdoPoll1.checked==false && objrdoPoll2.checked==false){
			alert("请选择一个投票项目!");
			return false;
		}
		if(objtxtPollContent.value==null || objtxtPollContent.value==""){
			alert("请填写投票的主题!");
			return false;
		}
	}	
	return true;			
}

 
 //进行投票操作
function OnDoPollOper()
{
	var strR = new String(OnMakeResult());		
	if(strR.indexOf("1") == -1)
	{
		window.alert("请选择投票项目");
		return;
	}
	go("newtopic.aspx?forumid={0}&topicid={1}&action=poll&result="+strR);
}			

//获取各投票项目选中信息
function OnMakeResult()
{
	var nItemCount = document.getElementsByName("objPollRadio").length;
	var objPollItem = document.getElementsByName("objPollRadio");
	var strResult = new String("");
	var i=0;
	for(i=0;i<nItemCount;i++)
	{
		if(objPollItem.item(i).checked == true)
		{
			strResult += "1|"
		}
		else
		{
			strResult += "0|"
		}
	}
	return strResult;
}	        	           

        
function OnShowButton(objKd)
{
	if(null == objKd)
	{
		document.write("&nbsp;");
		return;
	}
	var nk = parseInt(objKd);
	if(nk == 0)
	{
		document.write("<A href=\"javascript:goodtopic();\"><img src=\"http:\/\/popkart.tiancity.com\/homepage\/Community\/images\/bbs3_3.jpg\" width=\"102\" height=\"29\"  border=\"0\" style=\"cursor:hand;\"><\/A>");
		return;
	}
	if(nk == 1)
	{
		document.write("<A href=\"javascript:frequentproblemtopic();\"><img src=\"http:\/\/popkart.tiancity.com\/homepage\/Community\/images\/bbs3_03.gif\" width=\"102\" height=\"29\"  border=\"0\" style=\"cursor:hand;\"><\/A>");
		return;
	}
	document.write(nk);
}


function changeValidate(id)
{
	var ctrl;
	
	ctrl= document.getElementById(id);

	ctrl.src = "Modules\/Validate.aspx";

	return false;
	
	//document.getElementById('imgvalidate').src='Modules/Validate.aspx';return false;
}   
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            