<!--
list_p=1;
search_text="";
search_type2="";
select_img_num="";
select_img_data="";
image_feel_text="";
img=new Array();
guestbook = function () {

  var guestbook_show_text,index_show_data_possessor,index_show_state,index_show_state1,index_show_state2,index_show_hide,index_show_hideno,index_show_aside,index_show_asideno,index_show_aside_mark;
	var index_temp,index_show_data,index_show_data_reply,index_show_data_isa,index_show_data_nisa,index_show_data_risa,index_show_data_rnisa;
  var index_show_data_mark1,index_show_data_mark2,index_show_post_risa,index_show_post_rnisa;	
  var index_show_nodata,index_show_page,index_post_ing,index_post_ok,index_post_no,index_replay_ok,index_replay_no;
  var page_for_text,page_for_nolink_text,page_for_link_text,index_show_mail1,index_show_mail2;
  var image_feel,image_feel_tr,image_feel_td,image_feel_ntd;

	this.templates = function (templates_data) {
	  guestbook_show_text=guestbook_show.innerHTML;
		index_temp=templates_data;
		index_show_data=BCut(index_temp,'<!--留言資料顯示樣式{-->','<!--留言資料顯示樣式}-->');
		index_show_state=BCut(index_show_data,'<!--狀態{-->','<!--狀態}-->');
    index_show_state1=BCut(index_show_data,'<!--狀態1{-->','<!--狀態1}-->');
		index_show_state2=BCut(index_show_data,'<!--狀態2{-->','<!--狀態2}-->');
		index_show_mail1=BCut(index_show_data,'<!--留言人信箱{-->','<!--留言人信箱}-->');
		index_show_mail2=BCut(index_show_data,'<!--回覆人信箱{-->','<!--回覆人信箱}-->');
		index_show_data_reply=BCut(index_show_data,'<!--有回覆{-->','<!--有回覆}-->');
		index_show_data_isa=BCut(index_show_data,'<!--留言人是會員{-->','<!--留言人是會員}-->');
		index_show_data_nisa=BCut(index_show_data,'<!--留言人不是會員{-->','<!--留言人不是會員}-->');
		index_show_data_possessor=BCut(index_show_data,'<!--版主功能{-->','<!--版主功能}-->');
		index_show_aside=BCut(index_show_data_possessor,'<!--設為悄悄話{-->','<!--設為悄悄話}-->');
		index_show_asideno=BCut(index_show_data_possessor,'<!--取消悄悄話{-->','<!--取消悄悄話}-->');
		index_show_hide=BCut(index_show_data_possessor,'<!--設為隱藏{-->','<!--設為隱藏}-->');
		index_show_hideno=BCut(index_show_data_possessor,'<!--取消隱藏{-->','<!--取消隱藏}-->');
		index_show_aside_mark=BCut(index_show_data,'<!--悄悄話標記{-->','<!--悄悄話標記}-->');
		index_show_data_mark1=BCut(index_show_data,'<!--版主標記1{-->','<!--版主標記1}-->');
		index_show_data_mark2=BCut(index_show_data,'<!--版主標記2{-->','<!--版主標記2}-->');
		index_show_data_risa=BCut(index_show_data,'<!--回覆人是會員{-->','<!--回覆人是會員}-->');
		index_show_data_rnisa=BCut(index_show_data,'<!--回覆人不是會員{-->','<!--回覆人不是會員}-->');
		index_show_post_risa=BCut(index_show_data,'<!--會員回覆表單{-->','<!--會員回覆表單}-->');
		index_show_post_rnisa=BCut(index_show_data,'<!--訪客回覆表單{-->','<!--訪客回覆表單}-->');
		index_show_nodata=BCut(index_temp,'<!--沒有留言資料顯示樣式{-->','<!--沒有留言資料顯示樣式}-->');
		index_show_page=BCut(index_temp,'<!--留言資料頁碼顯示樣式{-->','<!--留言資料頁碼顯示樣式}-->');
		page_for_text=BCut(index_show_page,'<!--換頁頁碼回圈{-->','<!--換頁頁碼回圈}-->');
		page_for_nolink_text=BCut(page_for_text,'<!--不使用換頁連結{-->','<!--不使用換頁連結}-->');
		page_for_link_text=BCut(page_for_text,'<!--使用換頁連結{-->','<!--使用換頁連結}-->');
		index_post_ing=BCut(index_temp,'<!--資料處理中{-->','<!--資料處理中}-->');
		index_post_ok=BCut(index_temp,'<!--成功訊息提示{-->','<!--成功訊息提示}-->');
		index_post_no=BCut(index_temp,'<!--失敗訊息提示{-->','<!--失敗訊息提示}-->');
		image_feel=BCut(index_temp,'<!--表情圖示顯示樣式{-->','<!--表情圖示顯示樣式}-->');
		image_feel_tr=BCut(index_temp,'<!--表情圖示換行{-->','<!--表情圖示換行}-->');
		image_feel_td=BCut(index_temp,'<!--有表情圖示{-->','<!--有表情圖示}-->');
		image_feel_ntd=BCut(index_temp,'<!--無表情圖示{-->','<!--無表情圖示}-->');
		this.make_img_text();
		readurl_class();
	}

	this.guestbook_data = function (data) {
    aei=-1;
    select_post_num="";
    select_post_data="";
    gdata=data.split(' |');
    pdata=gdata[0].split(',');
    sdata=gdata[1].split(' ,');
    s1data=gdata[2].split(' ,');
    w_text="";r_w_text="";
    if (gdata[1]=="") sdata.length=0;
    for (i=0;i<sdata.length;i+=10){
      aei=i;
      r_w_text="";s1data_num=0;s1data_j="j";
      for (j=0;j<s1data.length;j+=10){
        if (s1data[j]==sdata[i]) {
          if (s1data_j=="j") s1data_j=j;
          s1data_num+=10;
		      rep=new Array (
            (s1data[j+2]=="")?index_show_data_risa:index_show_data_rnisa,'',
            (s1data[j+2]==possessor_surname)?'':index_show_data_mark2,'',
            (s1data[j+4]=="")?index_show_mail2:'','',
            '{reply_id}',s1data[j+1],
            '{reply_usurname}',s1data[j+2],
            '{reply_uname}',s1data[j+3],
            '{reply_email}',s1data[j+4],
            '{reply_isaside}',s1data[j+5],
            '{reply_title}',s1data[j+6],
            '{reply_contents}',this.unmake_img_text(s1data[j+7]),
            '{reply_time}',s1data[j+8],
            '{reply_ip}',s1data[j+9],
            '{num}',s1data_num/10,
            '{possessor_mark}',(s1data[j+2]==possessor_surname)?possessor_mark:''
		      );
          r_w_text+=Makeup(index_show_data_reply,rep);
        }
      }
      if (s1data_num>0)
        s1data.splice(s1data_j, s1data_num);
		    rep=new Array (
		      index_show_data_reply,r_w_text,
		      (sdata[i+1]=="")?index_show_data_isa:index_show_data_nisa,'',
          (account_surname)?index_show_post_rnisa:index_show_post_risa,'',
          (sdata[i+1]==possessor_surname)?'':index_show_data_mark1,'',
          (account_surname==possessor_surname)?'':index_show_data_possessor,'',
          (account_surname==possessor_surname)?'':index_show_state,'',
          (sdata[i+5]=="1")?index_show_aside:index_show_asideno,'',
          (sdata[i+4]=="1")?index_show_hide:index_show_hideno,'',
          (sdata[i+4]=="1")?index_show_state1:index_show_state2,'',
          ((account_surname==possessor_surname || (account_surname==sdata[i+1] && sdata[i+1]!="")) && sdata[i+5]=="1")?'':index_show_aside_mark,'',
          (sdata[i+3]=="")?index_show_mail1:'','',
          '{account_uname}',account_uname,
          '{account_email}',account_email,
		      '{id}',sdata[i],
		      '{usurname}',sdata[i+1],
          '{uname}',sdata[i+2],
          '{email}',sdata[i+3],
          '{isaside}',sdata[i+5],
          '{title}',sdata[i+6],
          '{contents}',this.unmake_img_text(sdata[i+7]),
          '{time}',sdata[i+8],
          '{ip}',sdata[i+9],
          '{possessor_mark}',(sdata[i+1]==possessor_surname)?possessor_mark:''
		    );
        w_text+=Makeup(index_show_data,rep);
    }

    neednum=(pdata[1]==0)?1:pdata[1];
    if (list_p<1 || list_p>neednum) list_p=1;
    p=list_p;
    theme=pdata[0];
    pagup=(p-1<1)?1:p-1;
    pagdown=(p+1>neednum)?neednum:p+1;
    show_pmin=(p-5>0)?p-5:1;
    show_pmax=(show_pmin+10<=neednum)?show_pmin+10:neednum;
    d_for="";
    for (i=show_pmin;i<=show_pmax;i++) {
      rep=new Array (
          '{p}',i
      );
      d_for+=Makeup((p==i)?page_for_nolink_text:page_for_link_text,rep);
    }

		rep=new Array (
      page_for_text,d_for,
      (possessor_preview!="")?'index.php?':'','cexndex.php?preview='+possessor_preview+'&',
      'cexndex.php?preview=','index.php?preview=',
      '{theme}',theme,
      '{page}',p,
      '{neednum}',neednum,
      '{pagup}',pagup,
      '{pagdown}',(pagdown==0)?1:pagdown,
      '{domainname}',domainname,
      '{addcontents_length}',addcontents_length
		);
    guestbook_show.innerHTML=Makeup(w_text+index_show_page,rep);
    if (aei-10>=0)
      document.getElementById('form_post'+sdata[aei-10]).style.top=-400;
    if (aei>=0)
      document.getElementById('form_post'+sdata[aei]).style.top=-400;
		readurl_class();
	}

	this.cpage = function (data) {
    scroll(0, 0);
    guestbook_show.innerHTML=guestbook_show_text;
    list_p=data;
    readurl=new Array (
      'o_guestbook.guestbook_data(text)','index.php','POST','action=get_data&p='+list_p+'&search_text='+search_text+'&search_type='+search_type2
    );
    readurli=-4;
    readurl_class();
	}

	this.postdata = function (data) {
	  scroll(0, 0);
    form_post_set.innerHTML=index_post_ing;
    document.getElementById('form_post_set').style.visibility='';
    document.getElementById('form_post_set').style.top=document.body.scrollTop+20;
    readurl=new Array (
      'o_guestbook.post_data2(text)','index.php','POST','action=post_data&uname='+encodeURIComponent(funame)+'&email='+encodeURIComponent(femail)+'&isaside='+encodeURIComponent(fisaside)+'&title='+encodeURIComponent(ftitle)+'&contents='+encodeURIComponent(fcontents)+'&authpic='+encodeURIComponent(fauthpic)+'&id='+data
    );
    readurli=-4;
    readurl_class();
	}
	this.post_data2 = function (data) {
	  sdata=data.split(' ,');
	  scroll(0, 0);
		rep=new Array (
      '{message}',sdata[1]
		);
	  if (sdata[0]=="0") {
      form_post_set.innerHTML=Makeup(index_post_no,rep);
    } else {
      this.post_clear(select_post_data);
      if (select_post_data=="" && select_post_num!="")
        select_post('');
      form_post_set.innerHTML=Makeup(index_post_ok,rep);
      guestbook_show.innerHTML=guestbook_show_text;
      list_p=1;
      search_text="";
      readurl=new Array (
        'o_guestbook.guestbook_data(text)','index.php','POST','action=get_data&p=1'
      );
      readurli=-4;
      readurl_class();
  	}
  }

	this.post_clear = function (data) {
	  fauthpic=document.getElementById('authpic'+data).value='';
	  if (data=="") {
	    fisaside='0';
	    //document.getElementsByName('isaside')[1].checked==true;
	    ftitle=document.getElementById('title'+data).value='';
	  } 
    if (account_surname=="") funame=document.getElementById('uname'+data).value='';
	  femail=document.getElementById('email'+data).value='';
	  fcontents=document.getElementById('contents'+data).value='';
	}

	this.close_post_set = function () {
    document.getElementById('form_post_set').style.visibility='hidden';
	}

	this.change_img = function (data) {
	  document.getElementById('authpic_img'+data).setAttribute("src","JoinAuthPic.php?" + Math.random());
  }
  
  this.search = function () {
    search_text=document.getElementById('search_guestbook').value;
    search_type2=document.getElementById('search_type').value;
    guestbook_show.innerHTML=guestbook_show_text;
    list_p=1;
    readurl=new Array (
      'o_guestbook.guestbook_data(text)','index.php','POST','action=get_data&p=1&search_text='+encodeURIComponent(search_text)+'&search_type='+encodeURIComponent(search_type2)
    );
    readurli=-4;
    readurl_class();
  }

  this.select_del = function (data) {
	  scroll(0, 0);
    form_post_set.innerHTML=index_post_ing;
    document.getElementById('form_post_set').style.visibility='';
    document.getElementById('form_post_set').style.top=document.body.scrollTop+20;
    readurl=new Array (
      'o_guestbook.select_del2(text)','index.php','POST','action=del_data&id='+data
    );
    readurli=-4;
    readurl_class();
  }
  this.select_del2 = function (data) {
	  sdata=data.split(' ,');
	  scroll(0, 0);
		rep=new Array (
      '{message}',sdata[1]
		);
	  if (sdata[0]=="0") {
      form_post_set.innerHTML=Makeup(index_post_no,rep);
    } else {
      form_post_set.innerHTML=Makeup(index_post_ok,rep);
      this.cpage(1);
  	}
  }

  this.set_cls = function (data,cls) {
	  scroll(0, 0);
    form_post_set.innerHTML=index_post_ing;
    document.getElementById('form_post_set').style.visibility='';
    document.getElementById('form_post_set').style.top=document.body.scrollTop+20;
    readurl=new Array (
      'o_guestbook.select_del2(text)','index.php','POST','action='+cls+'&id='+data
    );
    readurli=-4;
    readurl_class();
  }

this.select_img = function(data) {
  if (select_img_data!=data) {
    select_class('form_img'+select_img_data,'absolute','hidden');
    select_img_num="";
    select_img_data=data;
  }
  if (select_img_num!="") {
    select_class('form_img'+data,'absolute','hidden');
    select_img_num="";
  } else {
    //if (document.getElementById('form_img'+data).innerHTML=="")
    document.getElementById('form_img'+data).innerHTML=image_feel_text;
    select_class('form_img'+data,'','');
    select_img_num="1";
  }
}

  this.make_img_text = function() {
    w=0;w_text="";w_a="";show_w=change_tr;
    for (i=0;i<images.length;i++)
      img[i]=images[i];
    for (i=0;i<img.length;i++){
      if (w!=show_w) {
		    rep=new Array (
          '{images_url}',img[i],
          '{images_i}',(((i-i%10)/10<=0)?'0':'')+i
		    );
        w_text+=Makeup(image_feel_td,rep);
        w++;
        if (i+1>=img.length){
          if (img.length/2>show_w)
          for (j=show_w;j>w;j--)
            w_text+=image_feel_ntd;
          w=show_w;
        }
      }
      if(w==show_w) {
        w=0;
		    rep=new Array (
          image_feel_ntd,'',
          image_feel_td,w_text
		    );
        w_a+=Makeup(image_feel_tr,rep);
        w_text="";
      }
    }
		rep=new Array (
      image_feel_tr,w_a
		);
    image_feel_text=Makeup(image_feel,rep);
  }

  this.unmake_img_text = function(data) {
    while (1){
      tlong=data.indexOf("[:");
      if (tlong!=-1){
			  data=data.substring(0, tlong)+'<img src="'+img[data.substring(tlong+2, tlong+4)-0]+'" align="absmiddle" border="0">'+data.substring(tlong+4, data.length);
		  } else break;
    }
    return data;
  }
}
var o_guestbook = new guestbook();

//-->
