var pattern_word1 = /他妈的|她妈的|它妈的|你妈的|你马|的比|SB|sb|妈的比|妈比的|妈b|妈B|操你|靠你|猪头|白吃|有毛病|贱人|垃圾|日你|日你|我日你妈|呢妈比|你它妈|你他妈|操你老母|垃圾人|日它|日他|日她|操你妈的比|骂死|死贱人|淫荡/gi;
var pattern_html2 = /<(?:.|\s)*?>/gi;
function JH(){}
JH.prototype.loadData=ipc;
JH.prototype.returnData=ipd;
window.TV = new JH();
function ipc(val){
  if(!val) return;
  if(!val.count1) val.count1 = 0;
  if(!val.count2) val.count2 = 0;
  $("c1").innerHTML = val.count1;
  $("c2").innerHTML = val.count2;
}
function ipd(){}
TT.init(1);
window.onload=function(){
try{
  if($("m1")){
	  $("m1").src="loadNum.jsp";
  }
  if($("co")){
     EV.observe($("co"),"focus",Feiy);
  }
  if($("suid")){
     var usid = $("suid").getAttribute("em");
     $("suid").src="read_topc.jsp?usid="+usid;
  }
  if($("topc")){
    $("topc").src="read_topc3.jsp";
  }
  if($("pj")){
   var picid = $("pj").getAttribute("em");
    $("pj").src="read_topc4.jsp?id="+picid;
  }
  }catch(e){
    alert(e.description);
  }
};
function readTopc4(val){
  if($("node1")){
     $("node1").innerHTML = val.node1;
  }
  if($("node2")){
   $("node2").innerHTML = val.node2;
  }
  if($("node3")){
   $("node3").innerHTML = val.node3;
  }
  if($("dup")){
    if(val.node4== 0){
      alert("您已经投过票了.");
    }
   $("dup").value = val.node4;
  }
}
function topicRead3(CC){
  if($("tpc1")&&CC){
    $("tpc1").innerHTML = CC.html1;
  }else{
   $("tpc1").innerHTML = "数据加载失败!";
  }
  if($("tpc2")&&CC){
    $("tpc2").innerHTML = CC.html2;
  }else{
   $("tpc2").innerHTML = "数据加载失败!";
  }
  if($("tpc3")&&CC){
    $("tpc3").innerHTML = CC.html3;
  }else{
    $("tpc3").innerHTML = "数据加载失败!";
  }
}
function topicRead2(html){
  if($("dc1")&&html){
   $("dc1").innerHTML = html;
  }else{
   $("dc1").innerHTML = "加载数据失败!";
  }
}
function topicRead(html){
if($("su")&& html){
   $("su").innerHTML = html; 
}else{
  $("su").innerHTML = "加载数据失败!";
}
}
EV.observe($("tiwen"),"click",NewsAskTop);
EV.observe($("ss"),"click",SearchAskTop);
function SearchAskTop(){
  var D = $("search");
  if(D.value.trim()==""){
    //如果输入框中用户没有输入则获焦点
    var A = "<form style='text-align:left;margin-top:25px'  name='empform' onsubmit='return false'><div style='background:url(../pic/noteicon.gif) 0 0 no-repeat;padding:4px 0 8px 24px;font-size:14px'>请输入您要搜索的问题：</div><input size='42' id='emptyAskTitle'><br /><input type='button' class='bnsrh' style='margin-top:4px' value='继续搜索' id='empaskbtn'> </form><br><br>";
    Pdialog.show("&nbsp;&nbsp;",{info:A,width:350,height:240});
    setTimeout(function(){$("emptyAskTitle").focus()},100);
    $("empaskbtn").onclick=O;
  }else{
   document.searchForm.action="q.jsp?&rm=10&st=1";
   document.searchForm.submit();
  }
}
function NewsAskTop(){
  var D = $("search");
  if(D.value.trim()==""){
    //显示对话框
    var A = "<form style='text-align:left;margin-top:25px'  name='empform' onsubmit='return false'><div style='background:url(../pic/noteicon.gif) 0 0 no-repeat;padding:4px 0 8px 24px;font-size:14px'>请输入您的提问标题：</div><input size='42' id='emptyAskTitle'><br /><input type='button' class='bnsrh' style='margin-top:4px' value='继续提问' id='empaskbtn'> <a href='javascript:void()' target='_blank' style='font-size:12px;'>如何提问</a></form><br><br>";
    Pdialog.show("&nbsp;&nbsp;",{info:A,width:350,height:240});
    setTimeout(function(){$("emptyAskTitle").focus()},100);
    $("empaskbtn").onclick=B;
  }else{
    document.searchForm.action="q.jsp?rm=10&st=2";
    document.searchForm.submit();
  }
}
function B(){
   //提交用户的数据
  if($("emptyAskTitle").value.trim() == ""){
    $("emptyAskTitle").focus();
    return false;
  }
  document.searchForm.search.value = $("emptyAskTitle").value;
  Pdialog.hide();
  setTimeout("NewsAskTop()",100);
}
function O(){
  //提交用户的数据
  if($("emptyAskTitle").value.trim() == ""){
    $("emptyAskTitle").focus();
    return false;
  }
  document.searchForm.search.value = $("emptyAskTitle").value;
  Pdialog.hide();
  setTimeout("SearchAskTop()",100);
}
function loginSys(){
   Pdialog.show("&nbsp;&nbsp;",{width:380,height:350,url:"tb.jsp?act=1"});
}
function dofocusTextArea(obj){
  if(obj.value == '回答即可得2分，回答被采纳则获得悬赏分以及奖励20分'){
    obj.value = '';
	obj.rows=10;
  }
  if(obj.value == '详细的问题说明，有助于回答者给出准确的答案'){
    obj.value = '';
    obj.rows = 6;
  }
  if(obj.value == '说声谢谢，感谢回答者无私的帮助'){
    obj.value = '';
  }
  
  obj.className = 'mybbofont2';
}
function pollTop(val,picid){
 var cc = $("dup").value;
 if(cc == 0){
   alert("您已投过票了!");
   return;
 }else{
   $("pj").src="read_topc4.jsp?id="+picid+"&val="+val;
 }
  
}
function showSolution(val){
  //clear all twen　name bar
  for(var i=1 ; i<5 ; i++){
    var showid = "twen"+i+"_list";
    var showname = "twen"+i;
    if($(showid)){
      El.hide($(showid));
    }
    if($(showname)){
      El.show($(showname));
    }
  }
  var a = val.split("_");
  if(a.length >= 2){
    El.show($(a[0]));
  }else{
    El.show($(val+"_list"));
  }
   El.hide($(val));
}
function askLogin(val){
 
  var content_text = $("content_text");
  if(content_text.value == '回答即可得2分，回答被采纳则获得悬赏分以及奖励20分'||content_text.value.length <5){
    $("msg001").innerHTML = '请输入回答内容,若您的答案被采纳,系统将奖励您一定的积分哦.';
    content_text.focus();
    return;
  }
  if(content_text.value.length >10000){
    $("msg001").innerHTML = "输入大于10000字符，请去除后重新提交.";
    content_text.focus();
    return;
  }
  if(val == 0){
    Pdialog.show("&nbsp;&nbsp;",{width:600,height:285,url:"login_answer.jsp"});
  }else{
    if($("content_text")){
     var val = $("content_text").value.replace(pattern_html2,"").replace(/\n/gi,"<br/>");
     $("contentval").value = val.replace(/\r/gi,"").replace(/\s/,'&nbsp;').replace(pattern_word1,'***');
    }
    //内容替换完成.提交
    if($("ask_status")) $("ask_status").value = "1";
    document.form2.submit();
  }
}
/* return servers */
function loginAndAnonyReport(array){
  //登陆回复返回值为1的．不登陆回复返回值为0
  //内容转换去除\n与\r
  if($("content_text")){
    var val = $("content_text").value.replace(pattern_html2,"").replace(/\n/gi,"<br/>");
     $("contentval").value = val.replace(/\r/gi,"").replace(pattern_word1,"***");
  }
  if($("ask_status")){
    $("ask_status").value = array.isLogin;
  }
  if(array.isLogin){
    if($("is_remember")) $("is_remember").value = array.remember;
    //提交到write_back
    //关闭对话框
    Pdialog.hide();
    document.form2.submit();
  }
  document.form2.submit();
}
function processBar(val){
  var iNum = parseInt(val);
  var tc = 1;
  switch(iNum){
   case 1:
     //增加renew
     var renew = $("renew");
     if(renew){
       if(renew.value.length <= 4 || renew.value == '详细的问题说明，有助于回答者给出准确的答案'){
         $("msg002").innerHTML = "请输入问题补充内容，不可少于4个字符．";
         renew.focus();
         return;
       }
       if(renew.value.length >= 1500){
         $("msg002").innerHTML = "补充内容不能超过1500个字符,请检查后重新操作.";
         renew.focus();
         return;
       }
     }
     //加br
     var renews_bar = $("renews");
     renews_bar.value = renew.value.replace(pattern_html2,"").replace(/\n/gi,"<br/>").replace(/\r/gi,"").replace(/\s/gi,'&nbsp;').replace(pattern_word1,"**");
     tc = 1;
     break;
   case 2:
     //悬赏分
     var evl = $("evl");
     if(evl){
       var ival = parseInt(evl);
       if(ival <=0){
         $("msg003").innerHTML = "您的悬赏次数已用完,无法再次对该问题悬赏了.";
         return;
       }
     }
     tc = 2;//将悬赏次数-1 ,增加悬赏分.增加天数.
     break;
   case 3:
      //悬赏分
     if(confirm("是否确定要关闭该提问?您的悬赏分将无法返回.")){
       tc = 3;
     }
     break;
   case 4:
     break;
   case 5:
     break;
  }
  
  document.f1.action = "process_tail.jsp?tc="+tc;
  document.f1.submit();
}

//采纳为答案
function updateData(pcid,bak1,usid){
   //读取hmc2的选择分,与当前处理用户的积分对比,如果发现,hmc2>用户积分,则return
   var hmc2 = $("hmc2").value;
   var uspy = $("bfpy");
   if(uspy){
     var pys = parseInt(uspy.innerHTML);
     if(pys < hmc2){
       alert("奖励积分大于您的总积分值,请重新选择!");
       return;
     }
   }
  document.f3.action = "process_best.jsp?ct="+pcid+"&status="+bak1+"&usid="+usid;
  document.f3.submit();
}
//修改答复
function modifyBack(pciid){
  //显示层
  var nav = $("nav_"+pciid);
  if(nav){
    nav.style.display = '';
    $("modc").focus();
  }
}
function cl(v){
  var nav = $(v);
  if(nav){
    nav.style.display = 'none';
  }
}
//提交修改
function modRC(pcid){
  //modr modc
  var pcid = parseInt(pcid);
  var n1 = $("n1");
  if(pcid <=0 ){
    n1.innerHTML = "用户编号为空．不能提交修改!";
    return ;
  }
  var modc = $("modc");
  if(modc && (modc.value.length < 4  || modc.value.length > 10000)){
    n1.innerHTML = "您输入的回复应该在 4 ~ 10000个字之间，请删减后重新提交．";
    modc.focus();
    return;
  }
  //替换回车
  var modcc = $("modcc");
  modcc.value = modc.value.replace(pattern_html2,"").replace(/\n/gi,"<br/>").replace(/\r/gi,"").replace(/\s/gi,'&nbsp;').replace(pattern_word1,"***");
  document.f3.action = "modify_rc.jsp?pci="+pcid;
  document.f3.submit();
}

//采纳设置
var hmcid = null;
var hmcoldHtml = '';
function doBest(obj,picid,status,usid){
  if(hmcid != null && obj.parentNode != hmcid){
    hmcid.innerHTML = hmcoldHtml;
  }
  var html = '<div style="border:1px solid #dcdcdc;padding:5px;">'
            +' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-size:12px;">'
            +'<tr><td width="5%" valign="top">感谢语或评论：</td><td><textarea rows="6" style="width:80%" name="hmc1"  class="mybbsfont1" onfocus="dofocusTextArea(this)" id="hmc1">说声谢谢，感谢回答者无私的帮助</textarea></td></tr>'
            +'<tr><td colspan="2">如果您对这一回答非常满意,您可以选择给回答者额外的积分奖励：'
            +'<select name="hmc2" id="hmc2">'
            +'<option value="0">0</option>'
            +'<option value="5">5</option>'
            +'<option value="10">10</option>'
            +'<option value="15">15</option>'
            +'<option value="20">20</option>'
            +'<option value="30">30</option>'
            +'<option value="40">40</option>'
            +'<option value="50">50</option>'
            +'</select></td></tr>'
            +'<tr><td ><input type="button" value=" 确 定 " onclick="updateData('+picid+','+status+','+usid+')" />&nbsp;<input type="button" value=" 取 消 " onclick="hmc()"/></td></tr>'
            +' </table></div>';
  hmcoldHtml = obj.parentNode.innerHTML ;
  hmcid = obj.parentNode;
  obj.parentNode.innerHTML = html;
}

function hmc(){
   if(hmcid != null && hmcoldHtml != ''){
    hmcid.innerHTML = hmcoldHtml;
  }
}

function returnPoll(){
  var a1 = document.getElementsByName("a1");
  var sel = 0;
  for(var i=0; i<a1.length; i++){
    if(a1[i].checked){
      sel++;
    }
  }
  if(sel <=1){
    alert("至少选择两个备选的答案");
    return;
  }
  document.fc1.action = "return_poll.jsp";
  document.fc1.submit(); 
}
//投票
function poll_pt(picid){
  document.f3.action="process_poll.jsp?picid="+picid;
  document.f3.submit();
}
//
function poll_pb(val){
 window.open('poll_result.jsp?mainid='+val,'结果','width=400,top=40,left=400,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no');
}
