  function getTop(el)
  {
    var top = 0;
    while (el) {
      top += el.offsetTop;
      el = el.offsetParent;
    }
    return top;
  }
  
  function getLeft(el)
  {
    var left = 0;
    while (el) {
      left += el.offsetLeft;
      el = el.offsetParent;
    }
    return left;
  }

  function cc(c1,no) {
    ajax = createAJAX_s();
    if(ajax) {
    ajax.onreadystatechange = rdata_info;
    ajax.open("GET",'rinfo.php?c1='+c1+'&no='+no,true);
    ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax.send('c1='+c1+'&no='+no);
    }
  }

  function rdata_info() {
    if( 4 == ajax.readyState ) {
      if( 200 == ajax.status ) {
          oo = document.getElementById('info');
          if( ajax.responseText ) {
            oo.innerHTML=ajax.responseText;
          }
      }
    }
  }

  function shownomaster() {
    if(!jsFORUM_master1) {
      document.write('<tr onmouseover="this.style.backgroundColor=\'#FFFFCC\'" onmouseout="this.style.backgroundColor=\'#FFFFCC\'" bgcolor="#FFFFCC">');
      document.write('<td width="4%" align=center><img src="http://pic.bahamut.com.tw/forum/I8.gif" width="19" height="19"></td>');
      document.write('<td width="4%" align=center><img src="http://pic.bahamut.com.tw/forum/M1.gif" align="absmiddle" width="19"></td>');
      document.write('<td width="8%" align="center" class="t1">');
      document.write('<a href="B.php?bsn='+bsn+'&subbsn=1"><FONT color="#3e81c6">'+subtitle(1)+'</FONT></a>');
      document.write('</td>');
      document.write('<td id="0"><a href="http://forum.gamer.com.tw/C.php?bsn=60404&snA=3890&tnum=2&locked=T" target="_blank" class="post">【巴哈】輕鬆不放縱，哈啦園地有賴你我共同維繫</a> </td>');
      document.write('<td align="right" class="t1"><a href="http://home.gamer.com.tw/SYSOP" target="_blank">SYSOP</a></td>');
      document.write('<td align=center>0</td>');
      document.write('<td align=center valign="middle">0</td>');
      document.write('<td align=center valign="middle"><font color="#3E81C6"></font></td>');
      document.write('<td align="center" valign="middle">');
      document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
      document.write('<tr>');
      document.write('<td align="right" class="t1"><FONT class=t1>今日 12:00 am<br>by <a href="http://home.gamer.com.tw/SYSOP" target="_blank"><font color="#3e81c6">SYSOP</font></a> </FONT></td>');
      document.write('<td width="18" align="right"><a href="http://forum.gamer.com.tw/C.php?bsn=60111&snA=44209&tnum=1"><img src="http://pic.bahamut.com.tw/forum/lastpost.gif" title="觀看最後發表文章" border="0" align="absmiddle" width="14" height="9"></a></td>');
      document.write('</tr>');
      document.write('</table>');
      document.write('</td>');
      document.write('</tr>');
    }
  }

  /*** 共用函數區 ***/
  function ba_getDoc(divobj){
    return document.getElementById(divobj);
  }

  function ba_getDocStyle(divobj){
    return document.getElementById(divobj).style;
  }

  function ba_showDiv(divobj){
    ba_getDocStyle(divobj).display = '';
  }

  function ba_hiddenDiv(divobj){
    ba_getDocStyle(divobj).display = 'none';
  }

  function ba_getObj(){
    //W3C DTD 設定
    if( document.documentElement && document.documentElement.scrollTop ){
      return document.documentElement;
    }else{
      return document.body;
    }
  }

  function ba_getDivMask(){
    if( !ba_getDoc('maskdiv') )
    {
      //建立背景遮罩
      var mask = document.createElement('div');
      mask.id = 'maskdiv';
      //mask.style.position = 'absolute';
      mask.style.width = document.body.scrollWidth + 'px';
      mask.style.height = document.body.scrollHeight + 'px';
      //mask.style.left = '0px';
      //mask.style.top = '0px';
      //mask.style.backgroundColor = '#333333';
      mask.className = 'maskdiv';
      //if(isIE()){
      //  mask.style.filter = 'alpha(opacity=60)';
      //}else{
      //  mask.style.opacity = '0.6';
      //}

      document.body.appendChild(mask);
    }
  }
  
  function ba_getDialog(w, h){
    if( !ba_getDoc('dialogdiv') )
    {
      CH_num=2;
      if( !h ){ var CH_num=6; }

      //建立對話框
      var dialog = document.createElement('div');
      dialog.id = 'dialogdiv';
      dialog.style.position = 'absolute';
      dialog.style.width = w + 'px';
      dialog.style.height = h + 'px';
      dialog.style.left = Math.floor(document.body.clientWidth / 2) - (parseInt(dialog.style.width) / 2) + 'px';
    
      var styleTop = Math.floor(document.documentElement.clientHeight / CH_num) - (parseInt(dialog.style.height) / CH_num) + ba_getObj().scrollTop + 'px';
      dialog.style.top = styleTop;

      document.body.appendChild(dialog);
    }
  }

  function ba_getCss(){
    //動態建立CSS
    if( isIE() ){
      var element_style = document.createStyleSheet('');
    }else{
      var element_style = document.createElement('style');
      element_style.id = 'styleCss';
      element_style.type = 'text/css';
    }
    
    return element_style;
  }

  function ba_set_dialogArea(em_type, em_div){
    //重設對話框的高度
    if( 'add' == em_type ){
      ba_getDocStyle('dialogdiv').height = parseInt(ba_getDocStyle('dialogdiv').height) + ba_getDoc(em_div).offsetHeight + 'px';
    }else{
      ba_getDocStyle('dialogdiv').height = parseInt(ba_getDocStyle('dialogdiv').height) - ba_getDoc(em_div).offsetHeight + 'px';
    }
  }
  
  function ba_destroy(){
    //移除元素
    var div = ba_getDoc('dialogdiv');
    try { document.body.removeChild(div); }catch(e){}

    div = ba_getDoc('maskdiv');
    try { document.body.removeChild(div); }catch(e){}

    div = ba_getDoc('styleCss');
    try { document.getElementsByTagName('head')[0].removeChild(div); }catch(e){}
  }

  function ba_checkLogin( ln ){
    if( 'no' == ln )
    {
      document.cookie = "ckFrom=" + location.href + "; domain=gamer.com.tw;";
      location.href = 'https://user.gamer.com.tw/login.php';
      
      return false;
    }
    
    return true;
  }

  /*** ajax ***/
/*
  function createajax() {
    if( window.ActiveXObject ) {
      try {
        return new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
        try {
          return new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e2) {
          return null;
        }
      }
    }else if(window.XMLHttpRequest) {
      return new XMLHttpRequest();
    }else{
      return null;
    }
  }
*/
  
  function getDialog_layout(where, para){
    ajaxHttp = createAJAX_s();
    if( !ajaxHttp ){
      alert( 'Your browser does not support AJAX!' );
      return;
    }

    para = para + '&' || '?';
    para = para + new Date().getTime();
      
    switch(where){
      case 1:
        url='accuse.php'+para;
        ajaxHttp.onreadystatechange = function (){ accuse_requestData(395, 148); };
        break;

      case 2:
        url='http://forum.gamer.com.tw/gemadmin/accuse-num.php'+para;
        ajaxHttp.onreadystatechange = function (){ accuse_requestData_num(); };
        break;

      case 3:
        url='accuseDetail.php'+para;
        ajaxHttp.onreadystatechange = function (){ accuse_requestData_detail(); };
        break;
    }
      
    if( '' == url ){
      return;
    }
  
    ajaxHttp.open("GET", url, true);
    ajaxHttp.send(null);
  }
  
  /*** 個別函數區 ***/
  function accuse_requestData(w, h){
    if( 4 == ajaxHttp.readyState )
    {
      if( 200 == ajaxHttp.status ){
        ba_getDivMask();
        ba_getDialog(w, h);
        ba_getDoc('dialogdiv').innerHTML = ajaxHttp.responseText;
      }else{
        alert( '系統忙碌中，請稍待。(1)' );
      }
    }
  }

  function accuse_requestData_num(){
    if( 4 == ajaxHttp.readyState )
    {
      if( 200 == ajaxHttp.status ){
        if( 0 < parseInt(ajaxHttp.responseText) ){
          ba_getDoc('auseNum').innerHTML = "　　<font style='background:red; color:#FFF; font-size:13px;'> 您有 <a href='gemadmin/accuseAll.php' target='_blank'><font color='#FFFFFF'>" + parseInt(ajaxHttp.responseText) + "</font></a> 件檢舉待處理&nbsp;</font>";
        }
      }
    }
  }

  function accuse_setDialog(aeT, ln, bsn, sn, other_p){
    if( ba_checkLogin(ln) )
    {
      switch(aeT){
        case 1:
          accuse_set_css();
          tttmp = (jsFORUM_master1) ? '&m=1' : '';
          getDialog_layout(1, '?bsn='+bsn+'&sn='+sn+tttmp);
          break;

        case 3:
          getDialog_layout(3, '?bsn='+bsn+'&sn='+sn+'&'+other_p);
          break;
      }
    }
  }

  function xml_ckError(hrquest) {
    var xmldoc = hrquest.responseXML;
    var nodes = xmldoc.getElementsByTagName('error');
    if(nodes.length) {
      alert(nodes[0].firstChild.nodeValue);
      return true;
    }
    return false;
  }
  
  function accuse_requestData_detail() {
    if ( 4 == ajaxHttp.readyState ) {
      if ( 200 == ajaxHttp.status ) {
        if(xml_ckError(ajaxHttp) ) {
          return 0;
        }
        else{
          var output_d =  '<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#666666">';
              output_d += '<tr>';
              output_d += '  <td bgcolor="#FFFFFF">';
              output_d += '    <TABLE width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">';
              output_d += '      <TR>';
              output_d += '        <TD bgcolor="#FFFFFF"><table width="100%" cellpadding="1" cellspacing="0" bgcolor="#999999" class="t2">';
              output_d += '          <tr>';
              output_d += '            <td height="25" align="center" valign="bottom"><strong><font color="#FFFFFF">檢 舉 人 清 單</font></strong></td>';
              output_d += '          </tr>';
              output_d += '        </table></TD>';
              output_d += '      </TR>';
              output_d += '    </TABLE>';
              output_d += '    <table width="100%" border="0" cellpadding="2" cellspacing="1" bordercolor="#EBE9DC" bgcolor="#FFFFFF">';
              output_d += '      <tr bgcolor="#EBE9DC">';
              output_d += '        <td width="150" class="t1">檢舉人帳號</td>';
              output_d += '        <td width="150" align="center" class="t1">檢舉時間</td>';
              output_d += '        <td align="center" class="t1">補充說明</td>';
              output_d += '      </tr>';

          var xmldoc = ajaxHttp.responseXML.documentElement;
          var nodes = xmldoc.getElementsByTagName('uIdata');

          var bg=0;
          for(var j=0; j < nodes.length; j++){
            ause_uid = xmldoc.getElementsByTagName('uIuid')[j].childNodes[0].nodeValue;
            ause_time = xmldoc.getElementsByTagName('uItime')[j].childNodes[0].nodeValue;
            ause_exp = xmldoc.getElementsByTagName('uIexp')[j].childNodes[0].nodeValue;

            bgc = (!bg) ? '#FFFFFF' : '#F5F5F5';

            output_d += '      <tr bgcolor="' + bgc + '">';
            output_d += '        <td class="t1"><a href="http://home.gamer.com.tw/' + ause_uid + '" target="_blank"><font color="#999999">' + ause_uid + ' </font></a></td>';
            output_d += '        <td align="center" class="t1">' + ause_time + '</td>';
            output_d += '        <td align="center" class="t1">' + ause_exp + '</td>';
            output_d += '      </tr>';
          }

              output_d += '    </table>';
              output_d += '    <table width="100%" border="0" cellpadding="2" cellspacing="2" bgcolor="#F0F0F0">';
              output_d += '      <tr>';
              output_d += '        <td align="center"><a href="javascript:accuse_btn_cancel()" class="button">關閉視窗</a></td>';
              output_d += '      </tr>';
              output_d += '    </table>';
              output_d += '  </td>';
              output_d += '</tr>';
              output_d += '</table>';

          ba_getDivMask();
          ba_getDialog(600, 0);
          ba_getDoc('dialogdiv').innerHTML = output_d;
        }
      }
    }
  }

  function accuse_btn_show(ae_o){
/*
    if( ba_getDocStyle('accuse_explain').display ){
      document.getElementById('accuse_explain').style.display = '';
      ae_o.value='不想補充';
      ba_set_dialogArea('add', 'accuse_explain');
    }
    else{
      //hidden elements 將使offsetHeight=0，所以要先執行
      ba_set_dialogArea('sub', 'accuse_explain');
      document.getElementById('accuse_explain').style.display = 'none';
      ae_o.value='補充說明';

      //清空 form
      document.forms.frm0311.aExp.value='';
    }
*/
    if( 6 == ae_o ){
      document.getElementById('accuse_explain').style.display = '';
      ba_set_dialogArea('add', 'accuse_explain');

      //清空 form
      document.forms.frm0311.aExp.value='（請輸入 50 字內之說明）';
    }
    else{
      //hidden elements 將使offsetHeight=0，所以要先執行
      ba_set_dialogArea('sub', 'accuse_explain');
      document.getElementById('accuse_explain').style.display = 'none';
    }
  }

  function accuse_faq_show(){
    if( ba_getDocStyle('accuse_faq_div').display ){
      ba_showDiv('accuse_faq_div');
      ba_set_dialogArea('add', 'accuse_faq_div');
    }
    else{
      //hidden elements 將使offsetHeight=0，所以要先執行
      ba_set_dialogArea('Subtract', 'accuse_faq_div');
      ba_hiddenDiv('accuse_faq_div');
    }
  }
  
  function accuse_btn_cancel(){
    ba_destroy();
  }

  function accuse_set_css(){
    var c = '#report_wrapper{ width:380px; font-size:15px; color:#464646; margin:0; position:relative; padding:2px; border:1px solid #d2e2e9; background-color:#FFFFFF; }';
        c += 'h1.report_title{ background:#ecf3f6; text-align:center; font-size:16px; line-height:24px; font-weight:bold; margin:0; padding:0; width:380px;}';
        c += 'img.report_close{ position:absolute; right:4px; top:4px; border:none;}';
        c += 'img.report_question{ position:absolute; right:26px; top:4px; border:none;}';
        c += '#report_wrapper p{ padding:10px;}';
        c += '.report_color1{ color:#999999; font-size:12px;}';
        c += '#report_wrapper input{ padding:2px; margin:3px 0 0 0;}';
        c += 'input.report_intxt{ width:350px; border:1px solid #CCCCCC; height:24px; line-height:24px;}';
        c += 'p.report_exp{ font-size:12px; padding:5px; margin:0;}';
        c += 'p#report_btntb{ margin:0; padding:5px; text-align:center;}';
        c += '.brspace{ line-height:3px;}';
          
    var cssStyle = ba_getCss();
    
    if( isIE() ){
      cssStyle.cssText = c;
    }else{
      cssStyle.appendChild(document.createTextNode(c));
      document.getElementsByTagName('head')[0].appendChild( cssStyle );
    }
  }

  function accuse_ckData(){
    var ajaxHttp = createAJAX_s();
    if( !ajaxHttp ){
      alert( 'Your browser does not support AJAX!' );
      return false;
    }

    f = document.forms.frm0311;

    if( 0 == f.areason.value || '' == f.areason.value ){
      alert('請提供檢舉理由。');
      return false;
    }

    if( '（請輸入 50 字內之說明）' == f.aExp.value ){
      f.aExp.value = '';
    }

    if( 6 == f.areason.value && '' == f.aExp.value ){
      alert('請填寫檢舉理由(限50字內)。');
      f.aExp.focus();
      return false;
    }

    if( 6 !== parseInt(f.areason.value) ){
      f.aExp.value = f.areason.options[f.areason.value].text;
    }

    if( 50 < f.aExp.value.length || '' == f.aExp.value || 0 >= f.aExp.value.length ){
      alert('檢舉理由限50字以內。');
      return false;
    }

    if( f.w.value ){
      alert('資料處理中。');
      return false;
    }

    if( !confirm('確定送出檢舉？') ){
      return false;
    }

    f.w.value = 1;

    ajaxHttp.onreadystatechange = function(){
      switch(ajaxHttp.readyState){
        case 4: //XHR_RS_LOADED
          if(ajaxHttp.status == 200){
            var text = ajaxHttp.responseText;
            switch(text){
              case 'ERROR_LOGIN':     ba_checkLogin('no');  break;
              case 'ERROR_DATA' :     alert('資料查詢失敗，請重新操作。');  accuse_btn_cancel();   break;
              case 'ERROR_EXPn' :     alert('請提供檢舉理由，限50字以內。'); break;
              case 'ERROR_PERM' :     alert('權限不足。'); break;
              case 'ERROR_SYSTEM1' :  alert('資料查詢失敗(1-1)'); break;
              case 'ERROR_SYSTEM2' :  alert('無法檢舉本篇文章'); break;
              case 'ERROR_SYSTEM3' :  alert('資料查詢失敗(1-2)'); break;
              case 'ERROR_POSTED' :   alert('已舉報過。'); break;
              case 'ERROR_SYSTEM4' :  alert('資料查詢失敗(1-3)！'); break;
              case 'ERROR_SYSTEM5' :  alert('檢舉失敗，請重新操作。');  accuse_btn_cancel();  break; 
              case 'ERROR_DEL' :      alert('您無法檢舉自己的文章，請自行編輯或刪除。');  accuse_btn_cancel();  break;
              case 'FINISH' :         alert('檢舉已成功送出，板務群將依規定處理。');  accuse_btn_cancel();  break;
            }
          }else{
            alert("http response code error!");
          }
        break;
      }
    };
      
    param = '&bsn=' + f.bsn.value + '&sn=' + f.sn.value + '&aExp=' + encodeURIComponent(f.aExp.value) ;
    ajaxHttp.open("POST", "accuse2.php", true);
    ajaxHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxHttp.setRequestHeader("Content-length", param.length);
    ajaxHttp.setRequestHeader("Connection", "close");
    ajaxHttp.send(param);

    return false;
  }

  function accuse_count(u){
    getDialog_layout(2, "?uid="+u);
  }

/*
  function accuse_tips(what_o, what_k){
    what_o = ba_getDoc('M'+what_o);
    what_obj = ba_getDocStyle('reporttxt');
    switch(what_k){
      case 1:
        what_obj.top = getTop(what_o) + 22;
        what_obj.left = getLeft(what_o) - 1;
        what_obj.display = 'block';
        break;
      case 2:
        what_obj.display = 'none';
        break;
    }
  }
*/

  function accuse_tips(what_o, what_k){
    what_o = ba_getDoc('M'+what_o);
    switch(what_k){
      case 1:
        var tp = document.createElement('div');
        tp.id = 'reporttxt';
        tp.className = 'in_report';
        tp.style.top = getTop(what_o) + 22 + "px";
        tp.style.left = getLeft(what_o) - 1 + "px";
        tp.innerHTML = '發現任何違規文章，可按下「檢舉」鈕，回報給板務管理群。';

        document.body.appendChild(tp);
        break;
      case 2:
        try{ document.body.removeChild(ba_getDoc('reporttxt')) } catch(e){}
        break;
    }
  }

