var RecommendUtil = Class.create({
	initialize: function(options,events){
		this.options = {
			type:"",sid:"",modType:"",modTitle:"",content:"",recommend:"",friendids:"",cmd:0
		};
		this.events = {
			onTestContent:null
		}
		Object.extend(this.options, options ||{});
		Object.extend(this.events, events ||{});
	},
	showInsertRecommend: function(){
		initShareBox("<div id=recommend_" + 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.initInsertRecommend();
	},
	initInsertRecommend: function(){
		this.options.cmd=1;
		this.options.modTitle=encodeURIComponent(this.options.modTitle);
		this.options.content=encodeURIComponent(this.options.content);
		var ajax=new Ajax.Request("/ajax/recommend.html",{
			parameters: this.options,
			onSuccess: function(res){
				var value = null;
				eval(res.responseText);
				if (value != "null") {
					ajax.recommend.setRecommendValue(value);
				}else {
					ajax.recommend.setRecommendValue("<table width='100%' height='250px;'><tr><td align=center>载入出错...</td></tr></table>");
				};
			},
			onException: function(obj,str){
				alert(obj);alert(str);
			}
		})
		ajax.recommend=this;
	},
	setRecommendValue: function(value){
		$("recommend_" + this.options.type).update(value);
	},
	testLimit:function(value, submitid){
		if (this.events.onTestLimit != null) {
			var b=(this.events.onTestLimit || Prototype.emptyFunction)(value, submitid);
		}
	},
	insertRecommend: function(obj,objtype){
		if (gid("recommendFriendIds").value == "") {
			gid("recommendMsg").innerHTML = "请选择要给哪些朋友推荐。";
			return false;
		}
		if (gid("recommendContent").value == "") {
			gid("recommendMsg").innerHTML = "请填写您要给朋友们留言。";
			return false;
		}
		if (this.events.onTestObjtype != null && isnotnull(objtype)) {
			var b=(this.events.onTestObjtype || Prototype.emptyFunction)(gid("recommendContent").value,objtype);
			if(b.length>0){
				gid("recommendMsg").innerHTML = b;
				return false;
			}
		}
		if(this.events.onTestContent!=null){
			var b=(this.events.onTestContent || Prototype.emptyFunction)(gid("recommendContent").value);
			if(b.length>0){
				gid("recommendMsg").innerHTML = b;
				return false;
			}
		}
		obj.disabled = true;
		$("recommendSumit").disabled = true;
		if($("recommendSumit2")){
			$("recommendSumit2").disabled = true;
		}
		if(gid("recommendTitle")){
			this.options.modTitle=gid("recommendTitle").value;
		}
		this.options.cmd=2;
		this.options.content=gid("recommendContent").value;
		if(this.options.modType=="" && objtype!=""){
			this.options.modType=objtype;
		}
		this.options.modTitle=encodeURIComponent(this.options.modTitle);
		this.options.content=encodeURIComponent(this.options.content);
		this.options.friendids=gid("recommendFriendIds").value;
		var ajax=new Ajax.Request("/ajax/recommend.html",{
			parameters: this.options,
			onSuccess: function(res){
				var value = null;
				eval(res.responseText);
				hideLoadbox();
				if(value==null){
					showmsg(true, "成功推荐给朋友。");
				}else{
					showmsg(true, value);
				}
			}
		})
		ajax.recommend=this;
	}
});