var MyReadUtil = Class.create({
	initialize: function(options){
		this.options = {
			sid:"",content:"",name:"",noShow:false,cmd:"",readType:""
		};
		Object.extend(this.options, options ||{});
	},
	showInsertMyRead: function(){
		initbox("<div id=myread_" + this.options.type + " style='background-color:#FFFFFF;'><table width='100%' height='250px;'><tr><td align=center>载入中...</td></tr></table></div>", 500, 250, null, false);
		this.initInsertMyRead();
	},
	initInsertMyRead: function(){
		this.options.cmd="show";
		this.options.content=encodeURIComponent(this.options.content);
		var ajax=new Ajax.Request("/ajax/book/myread.html",{
			parameters: this.options,
			onSuccess: function(res){
				var value = null;
				eval(res.responseText);
				if (value != "null") {
					ajax.myread.setMyReadValue(value);
				}else {
					ajax.myread.setMyReadValue("<table width='100%' height='250px;'><tr><td align=center>载入出错...</td></tr></table>");
				};
			}
		})
		ajax.myread=this;
	},
	testLimit:function(value, divname, submitid){
		ifInputLimit(value, 100, divname, 'gid("' + submitid + '").disabled=false;', 'gid("' + submitid + '").disabled=true;');
	},
	setMyReadValue: function(value){
		$("myread_" + this.options.type).update(value);
	},
	insertMyRead: function(obj,value){
		obj.disabled = true;
		this.options.cmd="update";
		this.options.content=encodeURIComponent(gid("myreadContent").value);
		this.options.tags=encodeURIComponent(gid("myreadTags").value);
		this.options.noShow=gid("myreadNoShow").checked;
		this.options.mark=gid("myreadMark").value;
		this.options.readType=value;
		var ajax=new Ajax.Request("/ajax/book/myread.html",{
			parameters: this.options,
			onSuccess: function(res){
				var value = null;                var hasprice = 0;
				eval(res.responseText);
				if(read_type== 3 && hasprice==1){
					ajax.myread.setMyReadValue(value);
				}else{
					if(isnotnull(ajax.myread.options.url)){
						urlto(ajax.myread.options.url+"&rmsg="+value);
					}else{
						showmsg(true,"成功修改收藏状态。");
					}       				hideLoadbox();				}
			}
		})
		ajax.myread=this;
	},
	initShow:function(markNum,num){
		this.initRating(markNum);
		this.tagsNum=num-1;
		this.setTagsShow();
	},
	initRating:function(markNum){
		this.rating=new RatingFrame("myreadRating",{defImg:"/images/book/nst.gif",
				selImg:"/images/book/sth.gif",
				value:markNum,
				fun:this.options.name+".selRating",
				callback:function(obj,index){
				switch(index){
					case 1:obj.setEndTxt("很差");break;
					case 2:obj.setEndTxt("较差");break;
					case 3:obj.setEndTxt("还行");break;
					case 4:obj.setEndTxt("推荐");break;
					case 5:obj.setEndTxt("力荐");break;
				}
			}});
	},
	selRating:function(obj,index){
		this.rating.setValue(index);
		gid("myreadMark").value=index;
	},
	addTags:function(txt){
		var text=$("myreadTags").value;
		if(findarr(txt,text," ")){
			text=delarr(txt,text," ");
		}else{
			if(trim(text).length>0){
				text=text+" "+txt;
			}else{
				text=txt;
			}
		}
		$("myreadTags").value=text;
		this.setTagsShow();
	},
	setTagsShow:function(){
		var text=$("myreadTags").value;
		for(var i=1;i<=this.tagsNum;i++){
			if(findarr($("myreadTag_bnt"+i).title,text," ")){
				$("myreadSpan_bnt"+i).className="cite";
			}else{
				$("myreadSpan_bnt"+i).className="code";
			}
		}
	}
});