﻿// JScript ファイル

var PlogMode={
    list:{simple:"simple",full:"full",summary:"summary",follow:"follow",followed:"followed"}
}


//生成されたクラス
var callplog;

//クラス宣言
var PLog = Class.create();

//クラス定義
PLog.prototype = {
    //コンストラクタ
    initialize: function(chatpnl,mode,sub_data,main_id,options) {
    
        
        callplog=this;
        
        this.mode=mode;                
        this.main_id=main_id;
        this.sub_data=sub_data;
        
        this.pager=false;
        this.postable=false;
        this.count=10;
        this.baseurl = 'http://petitlog.bangkokmadam.net/';
        this.ajaxurl = 'petitlog/xml/';
        this.userurl = '';
        this.tagurl = '/tag/';
        this.itemurl = '/';
        this.imageurl = "assets/css/plog/";
        this.swfurl = "assets/swf/plog.swf";
        this.chaseparent =false;
        this.hasresponse =false;
        this.linkresponse =false;
        this.subresponsable =false;
        this.list=PlogMode.list.simple;        
        this.maxlength=1000;
        this.basepanel=null;
        
        this.swfMovie=null;
                
        if(options!=undefined){
            if(options.baseurl != undefined){this.baseurl = options.baseurl;}
            if(options.ajaxurl != undefined){this.ajaxurl = options.ajaxurl;}
            if(options.userurl != undefined){this.userurl = options.userurl;}
            if(options.tagurl != undefined){this.tagurl = options.tagurl;}
            if(options.itemurl != undefined){this.itemurl = options.itemurl;}
            if(options.imageurl != undefined){this.imageurl = options.imageurl;}
            if(options.swfurl != undefined){this.swfurl = options.swfurl;}
            if(options.count != undefined){this.count = options.count;}
            if(options.pager != undefined){this.pager = options.pager;}
            if(options.chaseparent != undefined){this.chaseparent = options.chaseparent;}
            if(options.list != undefined){this.list = options.list;}
            if(options.postable != undefined){this.postable = options.postable;}
            if(options.hasresponse != undefined){this.hasresponse = options.hasresponse;}
            if(options.subresponsable != undefined){this.subresponsable = options.subresponsable;}
            if(options.linkresponse != undefined){this.linkresponse = options.linkresponse;}
            if(options.basepanel != undefined){this.basepanel = options.basepanel;}
        }
        
        this.login_uid="";
        this.login_uname="";
        this.login_uimage="";
        this.page=0;
        this.backtext="";
        
        this.to=null;
        this.rescd=null;
        this.toname=null;
        this.restext=null;
        
        this.mainPanel=ElementCreator.createItem(null,"div","twit");
        
        var pnl=this.mainPanel;
        
        this.topPanel =ElementCreator.createItem(pnl,"div","topPanel");
	    
        
        //送信パネル
        
	    this.sendPanel =ElementCreator.createItem(this.topPanel,"div","send");
	    this.sendPanel.style.display="none"; 
	    
	    //送信メンバー
	    this.sendMemberIcon =ElementCreator.createItem(this.sendPanel,"div","member");
	    
	    
	    var bln =this.createBalloon(this.sendPanel);
	    this.simplePanel=ElementCreator.createItem(bln,"div","form");
        
	    	    
	    //送信フォーム
	    this.rtnPanel =ElementCreator.createItem(this.simplePanel,"div","ret");
	    
	    var bdytop=ElementCreator.createItem( this.simplePanel,"div","top");
	    
	    
	    var bdy=ElementCreator.createItem( this.simplePanel,"div","body");
	    this.rtnPanel.style.display="none";
	    
	    this.sendFlashPanel=ElementCreator.createItem(bdy,"div","itemright");
	    var itemleft=ElementCreator.createItem(bdy,"div","itemleft");
	    this.sendItemPanel=ElementCreator.createItem(itemleft,"div","formitem");
	    this.chatSendText =ElementCreator.createTextArea(this.sendItemPanel,50,8);
        this.chatSendText.setAttribute("id","body");
        this.chatSendText.setAttribute("name","body");
        this.chatSendText.className="textarea";
        this.chatSendText.onkeypress = this.keyPressExp.bindAsEventListener(this);

       
	    //拡張リンク
	    this.sendSimple =ElementCreator.createLink(bdytop,null,"sendsimple","シンプルモード"); 
        this.sendSimple.onclick = this.simpleForm.bindAsEventListener(this);

        //タグリンク
        var tagset=ElementCreator.createItem(bdytop,"div","categorytags");
        this.myTags=ElementCreator.createItem(tagset,"ul","mytags");
        this.allTags=ElementCreator.createItem(tagset,"ul","alltags");
        this.allTags.style.display="none";
        this.myExpandTags=ElementCreator.createLink(tagset,null,"alltag","全タグ表示");
        this.myExpandTags.setAttribute("title","全タグを表示する");
        this.myExpandTags.onclick= this.extpandTags.bindAsEventListener(this);
        this.myTagReaded=false;

	    //Footer
        /*var btm=ElementCreator.createItem(this.simplePanel,"div","bottom");*/
        var bbtn=ElementCreator.createItem(this.simplePanel,"div","sendbutton");

	    this.sendExpand =ElementCreator.createLink(bbtn,null,"sendexpand","タグ・画像添付"); 
        this.sendExpand.onclick = this.expandForm.bindAsEventListener(this);
 
        
	    //OKボタン
	    this.sendbtn =ElementCreator.createButton(bbtn,"投稿する"); 
	    this.sendbtn.className="ok";
	    this.sendbtn.onclick = this.sendMessage.bindAsEventListener(this);
        //キャンセルボタン
	    var cancelbtn =ElementCreator.createButton(bbtn,"×"); 
	    cancelbtn.className="cancel";
        cancelbtn.onclick = this.cancelMsg.bindAsEventListener(this);
        cancelbtn.setAttribute("title","キャンセル");
        
        
        var rootcss=((this.list==PlogMode.list.full) || (this.list==PlogMode.list.simple))?"root":"";
        
		//メインつぶやきパネル
		var maincontainer  =ElementCreator.createItem(pnl,"div","twits");
		this.chatTopPanel  =ElementCreator.createItem(maincontainer,"div","pager");
		this.chatListPanel  =ElementCreator.createItem(maincontainer,"div",rootcss);
		this.chatBottomPanel  =ElementCreator.createItem(maincontainer,"div","pager");
		

        //制御パネル
        var ctrlpanel =ElementCreator.createItem(pnl,"div","option");
        this.infopanel =ElementCreator.createItem(ctrlpanel,"span","info");
                
        
        
        Event.observe(window, "load", this.init.bind(this,chatpnl), false);
        
       
        
        
   },
   extpandTags:function(chatpnl){
        
        if(this.allTags.getElementsByTagName("li").length>0){
            //Mytagから移行
            this.myTagSelectToAllTagSelect();
        }else{
            //新規取得
            this.getTags();
        }
        
   },
     
   init:function(chatpnl){
        var pnl=$(chatpnl);         
        
      	pnl.appendChild(this.mainPanel);
      
        
       
        
		//初期データ読込
		this.refresh();
     

		
   },
   refresh:function(){
       if(this.chatSendText!=null){
        this.chatSendText.value="";
       }
        
   
        this.refreshList(null,0);
   },
   getInfo:function(){
        
        var otext= this.chatSendText.value.replace(/[ 　\f\n\r\t\v]+$/g, '');
        
        if(otext==""){
            return {status:1};
        }
                
        if(otext.length>this.maxlength){
            alert("コメントは"+this.maxlength+"文字までです。（現在"+otext.length+"文字）");
            return {status:2};
        }
        
        var tags='';
        if(this.isExpandForm()){
            //タグ取得
            tags=this.getSelectedTags();
            //クッキー保存
            this.setCookie("lastselectedtags",tags); 
        }
                   
        return {status:0,body:otext,to_uid:this.to,plog_id:this.rescd,tags:tags};
   },
   createParam:function(func,data,id,hasrespose,cnt,page){
        var now =new Date();
        
        var rtn;        
        if(func=="tag_master"){
            rtn=this.baseurl+this.ajaxurl+ func;
        }
        else if(func=="tag"){
            rtn=this.baseurl+this.ajaxurl+ func+"/"+id;
        }
        else if(func=="item"){
            rtn=this.baseurl+this.ajaxurl+ func+"/"+id+"/"+data+"/"+(hasrespose?"1":"0");
        }
        else if(func=="sub_items" || func=="tag"){
            rtn=this.baseurl+this.ajaxurl+ func+"/"+data;
        }
        else{ 
        
            if(func=="public_timeline" || func=="public_summary" || func=="main_timeline"){
                rtn=this.baseurl+this.ajaxurl+ func ; 
            }else if(func=="tag_summary"){
                rtn=this.baseurl+this.ajaxurl+ func +"/"+data;
            }else if(func=="tag_timeline" || func=="search"){
                if(id==undefined || id==null){
                    id=0;
                }
                rtn=this.baseurl+this.ajaxurl+ func +"/"+data+"/"+id;
            }else {
                rtn=this.baseurl+this.ajaxurl+ func+"/"+id;
            }
            
            rtn +="/"+(hasrespose?"1":"0")+ "/"+page+"/"+cnt;                
            
        }
        rtn +="/"+now.getTime();
        
        return rtn;
        
        
   },
   createBalloon:function(pnl){
   	    var bln =ElementCreator.createItem(pnl,"div","balloon");
   	    bln =ElementCreator.createItem(bln,"div","balloonin1");
   	    bln =ElementCreator.createItem(bln,"div","balloonin2");
   	    bln =ElementCreator.createItem(bln,"div","balloonin3");
   	    bln =ElementCreator.createItem(bln,"div","balloonin4");
   	    return ElementCreator.createItem(bln,"div","balloonin5");

   },
   isExpandForm:function(){
        return Element.hasClassName(this.simplePanel, "expandform");
   },   
   showreplyoriginal:function(e,to,toname,rescd,res/*,pnl*/){
        this.sendPanel.style.display="block"; 
        this.chatTopPanel.style.display="none";
         
        this.to=null;
        this.rescd=null;
        
        this.toname=null;
        this.restext=null;
        
        if(to!=undefined && to!=""){    
            this.to=to;
            this.toname=toname;
        }
        if(rescd!=undefined && rescd!=""){    
            this.rescd=rescd;
            this.restext=res;
        }
      
        if(this.to==null && this.getCookie("lastexpandform")=="1"){
            //expand分岐
            if(!Element.hasClassName(this.simplePanel, "expandform")){
                this.expandForm();
            }
            this.cookieToMyTag();
        
        }else{
            if(!Element.hasClassName(this.simplePanel, "simpleform")){
                 this.simpleForm();
            }
        }
        
        /*

        //現在の送信パネルの親ノード
        var pnode = this.sendPanel.parentNode;
        if(pnl!=undefined && pnl!=null){
            //送信パネルが指定されている場合
            if(pnode==null){
                pnl.appendChild(this.sendPanel);
            }else if(pnode!=pnl){
                pnode.removeChild(this.sendPanel);
                pnl.appendChild(this.sendPanel);
            }
            pnl.style.display="block";
        }else{
            //トップパネルに戻す
            if(pnode==null){
                this.topPanel.appendChild(this.sendPanel);
            }else if(pnode!=this.topPanel){
                pnode.removeChild(this.sendPanel);
                this.topPanel.appendChild(this.sendPanel);
            }
        }
        */

        this.rtnPanel.style.display="none";
        this.rtnPanel.innerHTML="";
	    if(this.to!=null){
	        this.rtnPanel.style.display="block"; 
	        if(this.rescd!=null){
	            this.rtnPanel.innerHTML="<p>"+toname+"さんの「"+res+"」への返信コメント</p>";
	        }else{
	            this.rtnPanel.innerHTML="<p>"+toname+"さんへのメッセージ</p>";
	        }
	    }
	    
	    try{
	        
	        var win=ElementUtil.getWinRect();
	        
	        var tor=ElementUtil.getOffsetRect(this.sendPanel);

	        if(win.y>tor.y){
	        
	            ElementUtil.scrollTo(tor.y,function(){
	                    if(this.chatSendText!=null){
	                        this.chatSendText.focus();
	                    }
	                }.bind(this));
	            
	       }else{
                if(this.chatSendText!=null){
                    this.chatSendText.focus();
                }
	       }
	        
	    }catch(ex){
	    }
	    
	    
   },
   keyPress:function(e){
        if(e.keyCode==13 || e.keyCode==10){
            this.sendMessage();
            //e.keyCode=0;
            if (e.preventDefault) {
              e.preventDefault();
            } else {
              e.returnValue = false;
            }

            return false;
        }/*else if(e.keyCode == 27 || e.keyCode==e.DOM_VK_ESCAPE){	
            this.clearMsg();
        
	    }*/
   },
   keyPressExp:function(e){
        if(e.ctrlKey || (e.modifiers&2==2)){
            if(e.keyCode==13 || e.keyCode==10){
                
                if(this.swfMovie==null){
                    this.sendMessage();
                }else{
                    //この送信はできないみたい。
                    /*
                    try{
                        this.swfMovie.mainSend();
                    }catch(ex){
                        return false;
                    }
                    */
                    return false;
                }
                
                if (e.preventDefault) {
                  e.preventDefault();
                } else {
                  e.returnValue = false;
                }

                return false;
                
            }
        }
   },
   clearMsg:function(){
        
        if(!this.postable){
            this.sendPanel.style.display="none";
            if(this.chatTopPanel.innerHTML!=""){
                this.chatTopPanel.style.display="block";
            }            
        }else{
            this.showreplyoriginal(null);
        }
        
        //タグ初期化
        this.cookieToMyTag();
        
        //消去
        if(this.chatSendText!=null){
            this.chatSendText.value="";
        }
   },
   cancelMsg:function(e){
        //キャンセル処理
        this.clearMsg();
   },
   simpleForm:function(e){
        
        
        if(this.swfMovie!=null){
            try{
                this.swfMovie.clearImage();
            }catch(ex){
            }
        }
        
        this.simplePanel.className="form simpleform";
                
        if(this.to==null){
            this.setCookie("lastexpandform","0"); 
        }
        
        //タグ初期化
        //this.cookieToMyTag();
   
   },
   expandForm:function(e){
        
        if((this.swfMovie==null) && (this.swfurl.length>0)){
            
            //レイトバインディング
            var hasRightVersion = DetectFlashVer(10, 0, 0);
	        if(hasRightVersion) { 
                var flash;
                if(isIE && isWin && !isOpera){
                    flash='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="plogswf" width="100%" height="160px" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0">'+
                    '<param name="movie" value="'+this.swfurl+'">'+
                    '<param name="play" value="true">'+
                    '<param name="loop" value="true">'+
                    '<param name="quality" value="high">'+
                    '<param name="bgcolor" value="#ffffff">'+
                    '<param name="allowScriptAccess" value="sameDomain">'+
                    '<param name="allowFullScreen" value="false">'+
                    '<param name="scale" value="noscale">'+
                    '<param name="flashvars" value="uploadurl='+encodeURIComponent(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,0))+'&refreshcall=callplog.refresh&clearcall=callplog.clearMsg&infocall=callplog.getInfo&posterrorcall=callplog.errorPostMsg">'+
                    '</object>';
                    this.sendFlashPanel.innerHTML=flash;
                    
                    
                    
                     //Flash検索
                     this.swfMovie=$('plogswf');
                    
                    
                }else{
                    flash='<embed src="'+this.swfurl+'" name="plogswf"  width="100%" height="160px" play="true" '+
                    'loop="true" quality="high" bgcolor="#ffffff" allowScriptAccess="sameDomain" allowFullScreen="false" scale="noscale" flashvars="uploadurl='+this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,0)+'&refreshcall=callplog.refresh&clearcall=callplog.clearMsg&infocall=callplog.getInfo&posterrorcall=callplog.errorPostMsg" pluginspage="http://www.adobe.com/go/getflashplayer_jp"> '+
                    '</embed>';
                    this.sendFlashPanel.innerHTML=flash;
                    
                    var embs=document.getElementsByTagName("embed");
                    for(var ei=0,ej=embs.length;ei<ej;ei++){
                        if(embs[ei].getAttribute("name")=="plogswf"){
                            this.swfMovie=embs[ei];
                            break;
                        }
                    }
                }
                
            }
            
        }

        if(this.swfMovie!=null){
            this.simplePanel.className="form expandform";
        }else{
            this.simplePanel.className="form simpleform";
            //ここで一度でもFlashを生成できなかった場合swfを停止する
            this.swfurl="";
        }

        if(this.to==null){
            this.setCookie("lastexpandform","1"); 
        }
        
   },
   sendMessage:function(e){
        //送信情報を取得
        var inf=this.getInfo();

        //更新処理
        
        if(inf.status==1){
            
            this.refreshList(null,0);
            return;
        }else if(inf.status!=0){
            return;
        }
        
        this.backtext=inf.body;
        
        //パラメータ作成
        
        var para="mode=add&body="+encodeURIComponent(inf.body);
        para+="&tags="+encodeURIComponent(inf.tags);
        if(inf.to_uid!=null){
            para+="&to_uid="+inf.to_uid;
            if(inf.plog_id!=null){
                para+="&plog_id="+inf.plog_id;
            }
        }
       
      
        this.chatListPanel.innerHTML='<div class="loading"><img src="'+this.imageurl+'loading.gif" alt="読み込み中"/></div>';
        this.chatTopPanel.innerHTML="";
        this.chatBottomPanel.innerHTML="";

        new Ajax.Request(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,0), {
            method: "post",
            parameters: para,
            onFailure : this.errorPost.bindAsEventListener(this),
            onException : this.errorPost.bindAsEventListener(this),
            onSuccess:this.postResponsToHtml.bindAsEventListener(this)
        });
      
      
      
       //二重投稿防止
       this.clearMsg();

    },
    errorPost:function(httpObj){
         this.errorPostMsg();
         this.chatSendText.value=this.backtext;       
        
    },
    errorPostMsg:function(){
        alert("投稿に失敗しました。再度投稿してください。");
    },
    postResponsToHtml:function(httpObj){
        //投稿完了
        
        this.responsToHtml(httpObj);
    },    
    deleteItem:function(e,tcd){
        //削除    
        if(confirm("このプチログを削除してもよろしいですか？")){
            var para="mode=delete&plog_id="+tcd;
            new Ajax.Request(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,this.page), {
                method: "post",
                parameters: para,
                onFailure : this.errorResponse.bindAsEventListener(this),
                onException : this.errorResponse.bindAsEventListener(this),
                onSuccess:this.responsToHtml.bindAsEventListener(this)
            });
        }
    },
    refreshList:function(e,page){
    
    /*
       //リフレッシュ前にメッセージクリア
       this.clearMsg();
	  */
	          
       //更新処理
       this.chatListPanel.innerHTML='<div class="loading"><img src="'+this.imageurl+'loading.gif" alt="読み込み中"/></div>';
       this.chatTopPanel.innerHTML="";
       this.chatBottomPanel.innerHTML="";
       
       new Ajax.Request(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,page), {
            onFailure : this.errorResponse.bindAsEventListener(this),
            onException : this.errorResponse.bindAsEventListener(this),
            onSuccess:this.responsToHtml.bindAsEventListener(this)
        });
       
    
    },
    errorResponse:function(httpObj){
        
       this.chatListPanel.innerHTML="";
       
       var el=ElementCreator.createLink(this.chatListPanel,null,"error","リスト取得に失敗しました。クリックして再度取得してください。"); 
       el.onclick=this.refreshList.bindAsEventListener(this,this.page);
       
        
    },
    responsToHtml:function(httpObj){
        //受信データ公開        
        
       var rt = httpObj.responseXML.documentElement;
      
       if(rt.tagName!="plogdata"){
            this.errorResponse(httpObj);
            return;
       }
      
      　this.chatListPanel.innerHTML="";
       this.chatBottomPanel.innerHTML="";
       this.chatBottomPanel.style.display="none";
       this.chatTopPanel.innerHTML="";
       this.chatTopPanel.style.display="none";
      
        //ログインユーザー情報取得
        
        var inf=rt.getElementsByTagName("info");
        
        if(inf.length>0){
            
        
            this.login_uid=XMLUtil.childData(inf[0],"uid");
            this.login_uname=XMLUtil.childData(inf[0],"uname");
            this.login_uimage=XMLUtil.childData(inf[0],"uimage");
            
          
            
            
            
            
            if(this.login_uid!=""){
                
                if(this.basepanel!=null){
                    var bpnl= $(this.basepanel);
                    if(bpnl!=null){
                        bpnl.style.display="block";
                    }
                }
                
                
                if((this.main_id!=this.login_uid) || (this.list!=PlogMode.list.full)){
                    var href = this.baseurl + this.userurl + this.login_uid;
                    //this.sendMemberIcon.innerHTML='<a href="'+href+'" class="image" title="'+this.login_uname+'"><img src="'+this.login_uimage+'" alt="'+this.login_uname+'"/><span class="name">'+this.login_uname+'</span></a>'; 
                    
                    ElementCreator.createLink(this.sendMemberIcon,null,null,'<img src="'+this.login_uimage+'" alt="'+this.login_uname+'"/><span class="name">'+this.login_uname+'</span>',null,href,this.login_uname); 
                    this.sendPanel.className="send me";
                }else{
                    this.sendMemberIcon.innerHTML="";
                    this.sendPanel.className="send noicon";
                }
                if(!this.myTagReaded){
                    //タグマスタ読み込み   		
		            
                    this.getTags(this.login_uid);
                }
                
                this.sendPanel.style.display=this.postable?"block":"none";
            }else{
                this.sendPanel.style.display="none";
            }
            
            
            
            
            
            if(this.mode=="item"){
                //単品ノードの場合ヘッダー表示
                
                var previtem=XMLUtil.childData(inf[0],"prev");
                var nextitem=XMLUtil.childData(inf[0],"next");
            
                if(previtem!="" || nextitem!=""){
                    if(previtem!=""){
                        ElementCreator.createLink(this.chatTopPanel,null,"prevpage","前のプチログへ",null,this.baseurl+this.userurl + this.main_id+ this.itemurl + previtem); 
                    }
                    if(nextitem!=""){
                        ElementCreator.createLink(this.chatTopPanel,null,"nextpage","次のプチログへ",null,this.baseurl+this.userurl + this.main_id+ this.itemurl + nextitem); 
                    }
                }
                
                if(this.main_id!=null){
                    ElementCreator.createLink(this.chatTopPanel,null,"listpage","一覧へ",null,this.baseurl + this.userurl + this.main_id); 
                    
                }
                this.chatTopPanel.style.display="block";
                
            }else{
                //単件以外で
                
                if((!this.postable) && (this.main_id==this.login_uid)){
                    //投稿不可モードで投稿可とする場合
                    var newpost=ElementCreator.createLink(this.chatTopPanel,null,"newpost","新規投稿"); 
                    newpost.onclick=this.showreplyoriginal.bindAsEventListener(this);
                    this.chatTopPanel.style.display="block";
                    
                }
                
            }
            
            
            var total=XMLUtil.childData(inf[0],"total");
            if(total=="0"){
                       
                ElementCreator.createItem(this.chatListPanel,"div","message","プチログがありません"); 
                
            }else{
            
                //メインリスト表示
                if((this.list==PlogMode.list.full) || (this.list==PlogMode.list.simple)){
                    this.subResponsToHtml(httpObj,this.chatListPanel,0);
                }else{
                    this.summaryResponsToHtml(httpObj,this.chatListPanel);
                }
            
                
            
                
                
                if(this.pager){
                    //ページャー表示
                
                    this.page=0;
                
                    var pages=XMLUtil.childData(inf[0],"pages");
                    if(pages!=""){
                        pages=Number(pages);
                        if(pages>1){
                            this.chatBottomPanel.style.display="block";
                            var pel;
                            this.page=Number(XMLUtil.childData(inf[0],"page"));
                            if(this.page>0){
                               pel=ElementCreator.createLink(this.chatBottomPanel,null,"prevpage","前へ"); 
                               pel.onclick=this.refreshList.bindAsEventListener(this,this.page-1);
                            }
                            if(this.page<pages-1){
                               pel=ElementCreator.createLink(this.chatBottomPanel,null,"nextpage","次へ"); 
                               pel.onclick=this.refreshList.bindAsEventListener(this,this.page+1);
                            }
                            
                            pager=ElementCreator.createItem(this.chatBottomPanel,"ul"); 
                            
                            var pgst=0;
                            var pged=pages-1;
                            
                            if(pages>11){
                               
                               if(this.page-5>1){
                                   pgst= this.page-5;
                                  if(pgst>pages-10){
                                     pgst=pages-10;
                                  }                           
                               }                       
                               if(this.page+5<pages-2 ){
                                  pged=this.page+5;
                                  if(pged<9){
                                     pged=9;
                                  }
                               }
                               
                               
                            }
                            
                            if(pgst>0){
                               pel=ElementCreator.createItem(pager,"li"); 
                               pel=ElementCreator.createLink(pel,null,null,"1"); 
                               pel.onclick=this.refreshList.bindAsEventListener(this,0);
                               //if(pgst>1){
                                ElementCreator.createItem(pager,"li","spc","-");
                               //}
                            }
                            
                            
                            for(var i=pgst;i<=pged;i++)
                            {
                               if(i==this.page){
                                   ElementCreator.createItem(pager,"li","now",""+(i+1)); 
                               }else{
                                   pel=ElementCreator.createItem(pager,"li"); 
                                   pel=ElementCreator.createLink(pel,null,null,""+(i+1)); 
                                   pel.onclick=this.refreshList.bindAsEventListener(this,i);
                               }
                            }     
                                     
                           if(pged<pages-1){
                               //if(pged<pages-2){
                                   ElementCreator.createItem(pager,"li","spc","-");
                               //}
                               pel=ElementCreator.createItem(pager,"li"); 
                               pel=ElementCreator.createLink(pel,null,null,""+pages); 
                               pel.onclick=this.refreshList.bindAsEventListener(this,pages-1);
                               
                           }                       
                            
                            
                                            

                            
                        }
                    
                    }
                }
            }
          
        }
        
        this.clearMsg();
    },
   
    
    resUser:function(to,toname){
        this.showreplyoriginal(null,to,toname);
    },
    resTwit:function(tcd){
        //更新処理
        
        //エラー時は何もやらない
        new Ajax.Request(this.createParam("item",tcd,null,this.hasresponse), {
            onSuccess:this.resTwitResponsToHtml.bindAsEventListener(this)
        });
        
    },
    resTwitResponsToHtml:function(httpObj){
        //受信データ公開        
        var rt = httpObj.responseXML.documentElement;
        var schnodes = rt.getElementsByTagName("plog");
         if(schnodes.length>0){
            var node=schnodes[0];
            
            var tcd=XMLUtil.childData(node,"plog_id");
            var sender=XMLUtil.childData(node,"uname");
            var sendercd=XMLUtil.childData(node,"uid");
            var senderimage=XMLUtil.childData(node,"uimage");
            var to=XMLUtil.childData(node,"to_uname");
            var tocd=XMLUtil.childData(node,"to_uid");
            var text=XMLUtil.childData(node,"body");
            
           
            this.showreplyoriginal(null,sendercd,sender,tcd,text);
            
        }
   },
    subTwit:function(e,tcd,pnl,lvl,refresh,postdata){
        if(refresh || pnl.style.display=="none"){
            //更新処理
            //エラー時は何もやらない
            
            pnl.innerHTML='<img src="'+this.imageurl+'loading.gif" alt="読み込み中"/>';
            if(postdata!=undefined && postdata!=null){
                new Ajax.Request(this.createParam("sub_items",tcd), {
                      method: "post",
                      parameters: postdata,
                      onFailure : this.errorResPost.bindAsEventListener(this,pnl),
                      onException : this.errorResPost.bindAsEventListener(this,pnl),
                      onSuccess:this.subResponsToHtml.bindAsEventListener(this,pnl,lvl)
                });
            }else{
                new Ajax.Request(this.createParam("sub_items",tcd), {
                    onSuccess:this.subResponsToHtml.bindAsEventListener(this,pnl,lvl)
                });
            }
        }else{
            //既に表示されている場合
            pnl.innerHTML="";
            pnl.style.display="none";
        }
    },
    errorResPost:function(httpObj,pnl){
         pnl.innerHTML="";
         this.errorPostMsg();
          
    },
    parentTwit:function(e,tcd,pnl,lnk,lvl){
        //更新処理
       //lnk.innerHTML='<span class="res"><span>RT:↓</span></span>'; 
       
       //エラー時は何もやらない
         new Ajax.Request(this.createParam("item",tcd,null,this.hasresponse), {
            onSuccess:this.parentResponsToHtml.bindAsEventListener(this,pnl,lvl,lnk)
        });
        
    },
    parentResponsToHtml:function(httpObj,pnl,lvl,lnk){
        lnk.innerHTML=''; 
       
       var rt = httpObj.responseXML.documentElement;
       var ps = XMLUtil.tagChilds(rt,"plogs");
       if(ps.length>0){
            var schnodes = XMLUtil.tagChilds(ps[0],"plog");
            this.subResponsToHtmlCore(schnodes,pnl,false,lvl);
       }
    
    },
    subResponsToHtml:function(httpObj,pnl,lvl){
       
       var rt = httpObj.responseXML.documentElement;
       var ps = XMLUtil.tagChilds(rt,"plogs");
       if(ps.length>0){

            var schnodes = XMLUtil.tagChilds(ps[0],"plog");
            pnl.innerHTML="";
            pnl.style.display=(schnodes.length==0)?"none":"block";
           
            this.subResponsToHtmlCore(schnodes,pnl,true,lvl);
        }
    },
    subResponsToHtmlCore:function(schnodes,pnl,append,lvl){
       //受信データ公開        
        
       for(var t=0;t<schnodes.length;t++){
            var node=schnodes[t];
            
            var tcd=XMLUtil.childData(node,"plog_id");
            var sender=XMLUtil.childData(node,"uname");
            var sendercd=XMLUtil.childData(node,"uid");
            var senderimage=XMLUtil.childData(node,"uimage");
            
            var rescount=XMLUtil.childData(node,"response_count");
            var responsable=(XMLUtil.childData(node,"responsable")=="1");
            var visible=(XMLUtil.childData(node,"visible")!="0");
            var follow=(XMLUtil.childData(node,"follow")=="1");
            var tags=XMLUtil.childData(node,"tags");
            if(tags!=""){
                tags=tags.split(",");
            }else{
                tags=new Array();
            }
            
            var date=DateTimeFunc.parseDate(XMLUtil.childData(node,"date"));
            var text=XMLUtil.childData(node,"body");
            var image=XMLUtil.childData(node,"image");
            var imagethumb=XMLUtil.childData(node,"image_thumb");
            
            var to=XMLUtil.childData(node,"reply_uname");
            var tocd=XMLUtil.childData(node,"reply_uid");
            var rescd=XMLUtil.childData(node,"reply_plog_id");
            var restext=XMLUtil.childData(node,"reply_body");
            
            var reslim=restext.replace(/(\r|\n|\r\n)/g," ");
            if(reslim.length>10){
                //返信サマリ作成
                reslim=reslim.substr(0,9)+"…";
            }
            
            //var rerescd=XMLUtil.childData(node,"res返信CD");
            //var resdate=XMLUtil.childData(node,"res投稿日時");
            
            var noicon=false;
            
            if((this.list==PlogMode.list.full) && (lvl==0)){
                noicon=true;
            }
            
            
            
                        
            var listpanel = ElementCreator.createItem(null,"div","twitlist"); 
            
            var parentel=pnl;
            
            if(append){
               //下に追加
                parentel.appendChild(listpanel); 
            }else{
                parentel=pnl.parentNode;
                parentel.insertBefore(listpanel,pnl); 
                
            }
            
          
            //var logel =ElementCreator.createItem(listpanel,"div",cls);
            var logel =ElementCreator.createItem(listpanel,"div","twititem");

            //if(lvl==0){
                Element.addClassName(logel, "zoomitem");
            //}
            
            if(noicon){
                Element.addClassName(logel, "noicon");
            }
            if(this.login_uid!=sendercd){
                Element.addClassName(logel, "import");
            }
            if(follow){
                Element.addClassName(logel, "follow");
            }else{
                if(this.login_uid==sendercd){
                    Element.addClassName(logel, "me");
                }else{
                    Element.addClassName(logel, "nofollow");
                }
            }
            

            
            var href = this.baseurl + this.userurl + sendercd;
            var memel=ElementCreator.createItem(logel,"div","member");
            ElementCreator.createLink(memel,null,null,'<img src="'+senderimage+'" alt="'+sender+'"/><span class="name">'+sender+'</span>',null,href,sender); 
            //ElementCreator.createItem(logel,"div","member",'<a href="'+href+'" class="image" title="'+sender+'"><img src="'+senderimage+'" alt="'+sender+'"/></a><a href="'+href+'" class="name" title="'+sender+'">'+sender+'</a>'); 
            
            
            //ゴミ消去
            text=text.replace(/[\r\n ]*$/,"");
                
            var outline=text.replace(/(\r|\n|\r\n)/g," ");
            var isoutline=false;
            
            var re = new RegExp("(\b?)(https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+)", "g");
            text=text.replace(re,'$1<a class="url" href="$2" target="_blank">$2</a>');
            
                                    
            if(outline.length>100){
                //要約outline作成
                isoutline=true;
                outline=outline.substr(0,99)+"…";
            }else if(outline!=text){
                //改行抜きのoutline作成
                isoutline=true;
            }
                   
            
            var bln =this.createBalloon(logel);
            var side=ElementCreator.createItem(bln,"div","side");
            var bdy=ElementCreator.createItem(bln,"div","body");
                    
                    
            //改行置換
                        
            text=text.replace(/(\r|\n|\r\n)/g,"<br/>");
            

            var img=null;
            var imgL=null;
            
            if(image!=""){
                //Element.addClassName(bdy, "withimage");
                var imgbase=ElementCreator.createItem(bdy,"div","mainimage");
                imgL=ElementCreator.createImage(imgbase,image,"画像");
                imgbase=ElementCreator.createItem(bdy,"div","thumb");
                img=ElementCreator.createImage(imgbase,imagethumb,"画像");
            }
            
            
            var txt=ElementCreator.createItem(bdy,"div","text");
            var btm=ElementCreator.createItem(bln,"div","bottom");
            //ElementCreator.createItem(bdy,"div","bodyend",".");
        
            if((text=="") && (image=="") && (restext=="")){
                 //中身がない場合
                 txt.innerHTML="コメントなし";
                 
                 Element.addClassName(logel, "disable");
                 
            }else{
                //文字か
            
               if(/*(!noicon) &&*/ (isoutline || (img!=null))){
                    //画像があるサムネイルか、outlineの場合
                    
                    if(img!=null){
                        img.onclick=this.swapZoomItem.bindAsEventListener(this,logel);
                        img.style.cursor="pointer";
                        //imgL.onclick=this.swapZoomItem.bindAsEventListener(this,logel);
                        //imgL.style.cursor="pointer";
                    }
                    
                    ElementCreator.createItem(txt,"span","outline",outline);
                    
                    var clel=ElementCreator.createLink(side,null,"minus","閉じる");
                    clel.onclick=this.swapZoomItem.bindAsEventListener(this,logel);
                    clel=ElementCreator.createLink(side,null,"plus","開く");
                    clel.onclick=this.swapZoomItem.bindAsEventListener(this,logel);
                    
                }else{
                    ElementCreator.createItem(txt,"span","outline",outline);

                }
            
                
                ElementCreator.createItem(txt,"span","maintext",text);
                
                            
                if(parentel.className!="child"){
                
                    if(( (tocd!="") && (tocd!=sendercd) ) || (rescd!="")){
                        var respnl= ElementCreator.createItem(txt,"span","res");
                        ElementCreator.createLink(respnl,null,"name",'<span class="retweet">&raquo;</span>'+ to,null,this.baseurl +this.userurl +tocd);
                        if(rescd!="" &&  reslim!=""){                        
                            var restel= ElementCreator.createLink(respnl,null,"restext",reslim,null,this.baseurl +this.userurl+tocd+this.itemurl +rescd);
                            if(reslim!=restext){
                                restel.setAttribute("title",restext);
                            }
                            
                            //親を呼び出し展開可能であれば                        
                            if(this.chaseparent){
                                var orgres=ElementCreator.createLink(respnl,null,"expand","▲");
                                orgres.onclick=this.parentTwit.bindAsEventListener(this,rescd,listpanel,respnl,lvl-1);
                            }
                            
                             if(responsable && visible){
                                //親記事が存在する場合
                                var rtnp=ElementCreator.createLink(respnl,null,"reply","返信");
                                rtnp.setAttribute("title","この親プチログに返信");
                                rtnp.onclick=this.showreplyoriginal.bindAsEventListener(this,tocd,to,rescd,reslim/*,childspanel*/);
                            }    
                            
                        }                                
                    }
                }
            
                if(tags.length>0){
                    var tagspnl=ElementCreator.createItem(btm,"ul","tags");
                    for(var ti=0,tj=tags.length;ti<tj;ti++){
                        if(tags[ti]!=""){
                            var tagli=ElementCreator.createItem(tagspnl,"li");
                            ElementCreator.createLink(tagli,null,null,tags[ti],null,this.baseurl+this.userurl +sendercd+ this.tagurl+ encodeURIComponent(tags[ti]));
                        }
                    }
                }
               
                //日付要素は記事単体に飛ぶエレメントとする
                 
             
                if(this.linkresponse || (rescd=="")){
                    var dateel=ElementCreator.createLink(btm,null,"date",date.toDateTimeStringS(),null,this.baseurl+this.userurl +sendercd + this.itemurl + tcd);
                    dateel.setAttribute("title","このプチログを開く");
                }else{
                    ElementCreator.createItem(btm,"span","date",date.toDateTimeStringS());
                }

                 
            

                var childspanel = ElementCreator.createItem(listpanel,"div","child");
                childspanel.style.display="none";
                
                if(!append){
                    parentel.removeChild(pnl);
                    childspanel.appendChild(pnl);                
                    childspanel.style.display="block";
                }
                

                
                //操作
                if(this.login_uid!=""){
                
                    //送信者のアイテムの場合
                    if(sendercd==this.login_uid){
                        var del=ElementCreator.createLink(btm,null,"delete","削除");
                        del.setAttribute("title","このプチログを削除");
                        del.onclick=this.deleteItem.bindAsEventListener(this,tcd);
                    }
                
                    if(responsable && visible){
                        if(this.subresponsable || (rescd=="")){
                            var rtn=ElementCreator.createLink(btm,null,"reply","返信");
                            rtn.setAttribute("title","このプチログへ返信コメント");
                            rtn.onclick=this.showreplyoriginal.bindAsEventListener(this,sendercd,sender,tcd,outline/*,childspanel*/);
                        }
                    }    
                    
                    
                }
                
                
                //返信情報
                if(rescount!="" && rescount!="0"){
                    var reel=ElementCreator.createLink(btm,null,"rescount","コメント "+rescount+" 件");
                    reel.setAttribute("title","返信コメント "+rescount+" 件");
                    reel.onclick=this.subTwit.bindAsEventListener(this,tcd,childspanel,lvl+1,false);
                    
                    
                    //子ども検索
                    var childs=node.getElementsByTagName("plogs");
                    
                    if(childs.length>0){
                        var cschnodes = XMLUtil.tagChilds(childs[0],"plog");
                        this.subResponsToHtmlCore(cschnodes,childspanel,true,lvl+1);
                    }else{
                        //単品モードの場合,自動で子どもを取りに行く
                        if(this.mode=="item"){
                            this.subTwit(null,tcd,childspanel,lvl+1,true);
                        }
                    
                    
                    }
                    
                }
                
                
            }
            
        }
    },
    swapImage:function(e,a,b){
        b.style.display="none";
        a.style.display="block";
    },
    swapZoomItem:function(e,el){
        
        if(Element.hasClassName(el, "zoomitem")){
            Element.removeClassName(el, "zoomitem"); 
        }else{
            Element.addClassName(el, "zoomitem"); 
        }
        
        
    },
    summaryResponsToHtml:function(httpObj,pnl){
       
       var rt = httpObj.responseXML.documentElement;
       var ps = XMLUtil.tagChilds(rt,"plogs");
       if(ps.length>0){

            var schnodes = XMLUtil.tagChilds(ps[0],"plog");
            pnl.innerHTML="";
            pnl.style.display=(schnodes.length==0)?"none":"block";
           
           for(var t=0;t<schnodes.length;t++){
                var node=schnodes[t];
                this.summaryResponsToHtmlCore(node,pnl,false);
           }
           
           if(this.list==PlogMode.list.summary){
                ElementCreator.createItem(pnl,"br","clearleft"); 
           }
        }
    },
    summaryResponsToHtmlCore:function(node,pnl,overrideitem){
       //サマリ用受信データ公開        
        
        
        var tcd=XMLUtil.childData(node,"plog_id");
        var sender=XMLUtil.childData(node,"uname");
        var sendercd=XMLUtil.childData(node,"uid");
        var senderimage=XMLUtil.childData(node,"uimage");
        var to=XMLUtil.childData(node,"to_uname");
        var tocd=XMLUtil.childData(node,"to_uid");
        
        var follow=(XMLUtil.childData(node,"follow")=="1");
        var visible=(XMLUtil.childData(node,"visible")!="0");
        
        var date=DateTimeFunc.parseDate(XMLUtil.childData(node,"date"));
        var text=XMLUtil.childData(node,"body");
        var image=XMLUtil.childData(node,"image");
        var imagethumb=XMLUtil.childData(node,"image_thumb");
        var rescd=XMLUtil.childData(node,"reply_plog_id");
        var restext=XMLUtil.childData(node,"reply_body");
        
        
        var listpanel;
        if(overrideitem){
           //中身の入れ替え
           listpanel=pnl;
           listpanel.innerHTML="";
        }else{
            listpanel = ElementCreator.createItem(pnl,"div","twitlist");             
        }
      
        //var logel =ElementCreator.createItem(listpanel,"div",cls);
        var logel =ElementCreator.createItem(listpanel,"div","twititem");
      
        if(this.login_uid!=sendercd){
            Element.addClassName(logel, "import");
        }
        if(follow){
            Element.addClassName(logel, "follow");
        }else{
            if(this.login_uid==sendercd){
                Element.addClassName(logel, "me");
            }else{
                Element.addClassName(logel, "nofollow");
            }
        }
            
        
        Element.addClassName(listpanel, "summary");
        if((this.list==PlogMode.list.follow) || (this.list==PlogMode.list.followed)){
            if(this.login_uid!="" && this.login_uid==this.main_id){
                Element.addClassName(listpanel, "followcontroler");
                var ctrl=ElementCreator.createItem(logel,"div","controler"); 
                
                if(this.login_uid!=sendercd){
                    var rmv,ritm;
                    var clist=ElementCreator.createItem(ctrl,"ul","action"); 
                    if(follow){
                        ritm= ElementCreator.createItem(clist,"li",null); 
                        ElementCreator.createItem(ritm,"span","followuser","お気に入り中"); 
                        rmv=ElementCreator.createLink(ritm,null,null,"解除"); 
                        rmv.onclick=this.removeMember.bindAsEventListener(this,sendercd);
                    }else if(visible){
                        ritm= ElementCreator.createItem(clist,"li"); 
                        rmv=ElementCreator.createLink(ritm,null,null,"お気に入りに追加"); 
                        rmv.onclick=this.addMember.bindAsEventListener(this,sendercd);
                    }
                    
                    if(this.list==PlogMode.list.followed){
                        ritm= ElementCreator.createItem(clist,"li"); 
                        ElementCreator.createItem(ritm,"span","refollowuser","お気に入られ中"); 
                        rmv=ElementCreator.createLink(ritm,null,null,"解除"); 
                        rmv.onclick=this.removeFollowMember.bindAsEventListener(this,sendercd);
                    }
                    
                }
            }
        }
        
        
        var href = this.baseurl + this.userurl + sendercd;
        var memel=ElementCreator.createItem(logel,"div","member");
        if(visible || (sendercd==this.login_uid) || follow){
            ElementCreator.createLink(memel,null,null,'<img src="'+senderimage+'" alt="'+sender+'"/><span class="name">'+sender+'</span>',null,href,sender); 
            //ElementCreator.createItem(logel,"div","member",'<a href="'+href+'" class="image" title="'+sender+'"><img src="'+senderimage+'" alt="'+sender+'"/></a><a href="'+href+'" class="name" title="'+sender+'">'+sender+'</a>'); 
        }else{
            ElementCreator.createItem(memel,"span",null,'<img src="'+senderimage+'" alt="'+sender+'"/><span class="name">'+sender+'</span>'); 
        }
        
        
        //ゴミ消去
        text=text.replace(/[\r\n ]*$/,"");
        
        var outline=text.replace(/(\r|\n|\r\n)/g," ");
        
        var outlen=(image=="")?24:20;
        
        if((outline.length>outlen) || (((tocd!="") && (tocd!=sendercd) ) || (rescd!=""))){
            //要約outline作成
            outline=outline.substr(0,outlen-1)+"…";
            
        }
        
        var disable=false;

        var bln =this.createBalloon(logel);
        
        var bdy=ElementCreator.createItem(bln,"div","body");

        if((!visible) && (!follow)){
            disable=true;
            ElementCreator.createItem(bdy,"div","text","非公開");
            Element.addClassName(logel, "disable");
            
        }else if(outline=="" && image==""){
            disable=true;
            ElementCreator.createItem(bdy,"div","text","コメントなし");
            Element.addClassName(logel, "disable");
        }else{
        
             //サマリ情報
            
            href = this.baseurl+this.userurl+sendercd + this.itemurl + tcd;
        
            if(this.linkresponse || (rescd=="")){
                bdy =ElementCreator.createLink(bdy,null,"bodyfull",null,null,href);
                bdy.setAttribute("title","このプチログを開く");
            }
            
            
            if(image!=""){
                ElementCreator.createImage(bdy,imagethumb,outline);
                //var imglnk=ElementCreator.createLink(imgbase,null,null,sender,imagethumb,href);
            }
        
            ElementCreator.createItem(bdy,"span","outline",outline);
            
            var btm=ElementCreator.createItem(bdy,"span","bottom");
            
    
            
            ElementCreator.createItem(btm,"span","date",date.toDateTimeStringS());
            
        }
        
        
        
       
        
    },
   removeMember:function(e,memcd){
        //メンバー削除
        if(confirm("このプチログをお気に入りから解除しますか？")){
        
            var para="mode=delete_follow&followed_uid="+memcd;
            new Ajax.Request(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,this.page), {
                method: "post",
                parameters: para,
                onFailure : this.errorResponse.bindAsEventListener(this),
                onException : this.errorResponse.bindAsEventListener(this),
                onSuccess:this.responsToHtml.bindAsEventListener(this)
            });
        }
   },
   removeFollowMember:function(e,memcd){
        //メンバー削除
        if(confirm("このユーザーのお気に入られから解除しますか？")){
        
            var para="mode=delete_followed&follow_uid="+memcd;
            new Ajax.Request(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,this.page), {
                method: "post",
                parameters: para,
                onFailure : this.errorResponse.bindAsEventListener(this),
                onException : this.errorResponse.bindAsEventListener(this),
                onSuccess:this.responsToHtml.bindAsEventListener(this)
            });
        }
   },
   addMember:function(e,memcd){
        //メンバー削除
        if(confirm("このプチログをお気に入りに追加しますか？")){
            var para="mode=add_follow&followed_uid="+memcd;
            new Ajax.Request(this.createParam(this.mode,this.sub_data,this.main_id,this.hasresponse,this.count,this.page), {
                method: "post",
                parameters: para,
                onFailure : this.errorResponse.bindAsEventListener(this),
                onException : this.errorResponse.bindAsEventListener(this),
                onSuccess:this.responsToHtml.bindAsEventListener(this)
            });
        }
   },
   getTags:function(memcd){
        //タグ取得
        
        
        if(memcd!=undefined){
            new Ajax.Request(this.createParam("tag",null,memcd), {
                onSuccess:this.responsToTag.bindAsEventListener(this,false)
            });
        }else{
            new Ajax.Request(this.createParam("tag_master"), {
                onSuccess:this.responsToTag.bindAsEventListener(this,true)
            });
        }
        
   },
   responsToTag:function(httpObj,isall){
       
       var rt = httpObj.responseXML.documentElement;
       var ps = rt.getElementsByTagName("tag");
       
       var pnl=this.allTags;
       if(!isall){
           pnl=this.myTags;
           this.myTagReaded=true;
       }
       
       
       pnl.innerHTML="";
       var el;
       for(var i=0,j=ps.length;i<j;i++){
           el= ElementCreator.createItem(pnl,"li");
           el= ElementCreator.createLink(el,null,null,ps[i].firstChild.nodeValue);
           el.onclick=this.tagSelect.bindAsEventListener(this,el);
       }
       
       
       if(!isall){
           //初回読み込み時にタグ設定
           this.cookieToMyTag();
       }else{
            //Mytagから選択移行
            
            this.myTagSelectToAllTagSelect();
       }
       
    },
    cookieToMyTag:function(){
    
        var ctags=this.getCookie('lastselectedtags',null);
        this.clearTagSelection(this.myTags,ctags);
        this.allTags.style.display="none";
        this.myTags.style.display="inline";
        this.myExpandTags.style.display="inline-block";
    
    },    
    myTagSelectToAllTagSelect:function(){
        var nowsel= this.getSelectedTags();
        this.clearTagSelection(this.allTags,nowsel);
        this.allTags.style.display="inline";
        this.myTags.style.display="none";
        this.myExpandTags.style.display="none";
    }, 
    tagSelect:function(e,el){
        if(Element.hasClassName(el, "selected")){
            Element.removeClassName(el, "selected")
        }else{
            Element.addClassName(el, "selected")
        }
    },
    clearTagSelection:function(el,lst){
        var els=el.getElementsByTagName("a");
        var i,j;
        for(i=0,j=els.length;i<j;i++){
            Element.removeClassName(els[i], "selected");
        }
        if(lst!=undefined && lst!=null){
            for(i=0,j=els.length;i<j;i++){
                var tg=els[i].innerHTML;
                if(lst.indexOf(tg)>=0){
                    Element.addClassName(els[i], "selected");
                }
            }
        }
        
    },
    getSelectedTags:function(){
        var el=this.myTags;
        if(this.allTags.style.display!="none"){
            el=this.allTags;
        }
        var tgs=new Array();
        
        var els=el.getElementsByTagName("a");        
        for(var i=0,j=els.length;i<j;i++){
            if(Element.hasClassName(els[i], "selected")){
               tgs.push(els[i].innerHTML); 
            }
        }
        return tgs.join(',');
    },
    getCookie:function(key,def) {
        var item=this.cookiekey+'_'+key;
        var arr = document.cookie.split(";");
        for(var i = 0; i < arr.length; i++) {
            var index = arr[i].indexOf("=");
            //2番目は頭がスペースのとき
            if(arr[i].substring(0, index) == item || 
                    arr[i].substring(0, index) == " " + item)
                return decodeURIComponent(arr[i].substring(index + 1));
        }
        return def;
    },
    setCookie:function(key, value) {
        //cookieを保存
        var item=this.cookiekey+'_'+key;
        
        var d = new Date();
        d.setTime(d.getTime() + 100*365*24*60*60*1000); //100年後
        var expire = d.toGMTString();
        document.cookie = item + "=" + encodeURIComponent(value) + ";expires=" + expire;
    }
    
}


