(function(){
function $(s){
	return document.getElementById(s);
	}
var isIE = !!window.ActiveXObject;
var isCSS1Dom = document.compatMode && (document.compatMode != "BackCompat");
var FuncBase = {
	extendObj : function(s,d){//将s的属性复制给d
		for(var p in s){
			d[p] = s[p];
			}
		},
	cmbObj : function(){//合并obj,个数不限
		var ret = {},tmp;
		for(var i=0,ilen=arguments.length;i<ilen;i++){
			tmp = arguments[i];
			for(var p in tmp){
				ret[p] = tmp[p];
				}
			}
		return ret;
		},
	pina : function(p,a){
		for(var i=0,ilen=a.length;i<ilen;i++){
			if(a[i]==p)return true;
			}
		},
	extendClass : function(f,p){
		for(var px in f.prototype){
			if(p.prototype[px]==undefined){
				p.prototype[px] = f.prototype[px];
				}
			}
		}
	}

var EffectBase = {
	hl : function(el,oncomplete){
		if(el.isShowing)return false;
		var hightlight = {
			_timer : null,
			_step : 4,
			_delay : 100,
			_clear : function(){
				if(this._timer){clearInterval(this._timer);}
				},
			setopt : function(p,v){
				this['_'+p] = v;
				},
			show : function(eo){
				var obj = this;
				var oldbgcolor = eo.style.backgroundColor;
				this._curcolor = 60;
				eo.style.backgroundColor = 'rgb(100%,100%,60%)';
				eo.isShowing = true;
				this._timer = setInterval(function(){
					obj._curcolor += obj._step;
					if(obj._curcolor > 100){
						obj._clear();
						eo.style.backgroundColor = 'rgb(100%,100%,100%)';
						eo.style.backgroundColor = oldbgcolor;
						eo.isShowing = false;
						if(typeof(obj._afterF)=='function'){obj._afterF()};
						}
					else{
						eo.style.backgroundColor = 'rgb(100%,100%,' + obj._curcolor + '%)';
						} 
					},this._delay);
				}
			}
		hightlight.setopt('afterF',oncomplete);
		hightlight.show(el);
		},
	dragit : function dragit(hd,tar){
		DragO={
				getAbsX : function(e){
					var bx=isCSS1Dom?document.documentElement.scrollLeft:document.body.scrollLeft;
					var x=isIE?e.clientX+bx:e.pageX;
					return x},
				getAbsY : function(e){
					var by=isCSS1Dom?document.documentElement.scrollTop:document.body.scrollTop;
					var y=isIE?e.clientY+by:e.pageY;return y},
				setAlpha : function(newObj,alp){
						if(document.all)newObj.style.filter = "alpha(opacity="+alp+"0)";
						else newObj.style.opacity = alp/10;},
				doDown:function(e){
				e=e?e:window.event;
				var x = isIE?e.offsetX:e.layerX;
				var y = isIE?e.offsetY:e.layerY;
				var tar = this.tar;
				var el = this;
				DragO.setAlpha(tar,6);
				document.onmousemove = function(e){
					e=e?e:event;
					isIE?el.setCapture():window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP)
					tar.style.left=(DragO.getAbsX(e)-x)+'px';
					tar.style.top=(DragO.getAbsY(e)-y)+'px';
					}
				document.onmouseup = function(e){
					e=e?e:event;
					document.onmousemove = null;
					isIE?el.releaseCapture():window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP)
					DragO.setAlpha(tar,10);
					}
				},
				init:function(el,tar){
					el.onmousedown=this.doDown;
					el.tar = tar;
					el.style.cursor = 'move'; 
				}
			}
		DragO.init(hd,tar);	
		}
	}
	
function TplBase(tplstr){
	this._tpl = tplstr;
	}
TplBase.filter = {
	arrayclass : function(aid){if(aid==1)return 'class="pollNone"';return aid%2 ? '' : 'class="even"';},
	trclass : function(aid){return aid%2 ? 'class="even"' : '';},
	titlepre : function(qid){return '调查'+qid+'.';},
	spanclass : function(aid){var aid = aid+1;return ['style',(aid%5)].join('');},
	output_ans_head : function(aid){if(aid%4==1){return '<tr align="center" valign="top">'}else{return ''}},
	output_ans_head_noatr : function(aid){if(aid%4==1){return '<tr>'}else{return ''}},	
	output_ans_head_as : function(aid){if(aid%4==1){return '<tr align="center" valign="top" class="as">'}else{return ''}},	
	output_ans_tail : function(aid){if(aid%4==0){return '</tr>'}else{return ''}}
	}	
TplBase.prototype = {
	_dotpl : function(str,dataobj){
			var dataobj = dataobj;
			var str = str;
			var ifre = /\%\(if\s+([^)]*)\)(.*?)\%\(endif\)/ig;
			var qre = /%\(questionloop\)(.*)%\(\/questionloop\)/i;
				str = this._proqloop(str,dataobj);
				str = this._proif(str,dataobj);
			return this._rnd(str,dataobj);	
			},
	_proif : function(str,dataobj){
		var ret = str,sigstr,sigmatcharr,condition,ifmiddle,iftpl,ifps,sigrnd,elseps,elsetpl;
		var elifmat;
		var elifcon = [];
		var eliftpl = [];
		var ifre = /\%\(if\s+([^)]*)\)(.*?)\%\(endif\)/ig;
		var ifresig = /\%\(if\s+([^)]*)\)(.*?)\%\(endif\)/i;
		var elsere = /\%\(elif\s+([^)]*?)\)(.*?(%\(elif|%\(else|$))/i;
		var matcharr = str.match(ifre);
		if(!matcharr){return ret;}
		for(var i=0,ilen=matcharr.length;i<ilen;i++){
			elsetpl = '';
			elifcon = [],eliftpl = [];
			sigstr = matcharr[i];
			sigmatcharr = sigstr.match(ifresig);
			condition = sigmatcharr[1];
			ifmiddle = sigmatcharr[2];
			ifps = ifmiddle.indexOf('%(elif')!=-1 ? ifmiddle.indexOf('%(elif') : ifmiddle.indexOf('%(else');
			iftpl = ifps!=-1 ? ifmiddle.substr(0,ifps) : ifmiddle;
			while(ifmiddle.match(elsere)){
				elifmat = ifmiddle.match(elsere);
				elifcon.push(elifmat[1]);
				eliftpl.push(elifmat[2].replace(elifmat[3],''));
				ifmiddle = ifmiddle.replace(elifmat[0].replace(elifmat[3],''),'');
				}
			elseps = ifmiddle.indexOf('%(else)');
			if(elseps!=-1){
				//iftpl = ifmiddle.substr(0,elseps);
				elsetpl = ifmiddle.substr(elseps+7);
				}
			//else{
			//	iftpl = ifmiddle;
			//	}
			if(dataobj[condition]){
				sigrnd = iftpl/*this._rnd(iftpl,dataobj)*/;
				}
			else{
				sigrnd = elsetpl ? elsetpl/*this._rnd(elsetpl,dataobj)*/ : '';
				}
			for(var k=0,klen=elifcon.length;k<klen;k++){
				if(dataobj[elifcon[k]]){
					sigrnd = eliftpl[k];
					}
				}
			ret = ret.replace(sigstr,sigrnd);
			}
		return ret;
		},
	_proqloop : function(str,dataobj){
		var ret = str,tmp,aloopstr;
		var qre = /%\(questionloop\)(.*)%\(\/questionloop\)/i;
		var qloop = str.match(qre);
		if(!qloop){return ret;}
		var qloopstr = qloop[1];
		var are = /%\(answerloop\)(.*?)%\(\/answerloop\)/ig;
		var are1 = /%\(answerloop\)(.*?)%\(\/answerloop\)/i;
		var aloop = qloopstr.match(are);
		if(!aloop){alert('no answer loop');return false;}
		for(var n=0,nlen=aloop.length;n<nlen;n++){
			qloopstr = qloopstr.replace(are1,'%(answerblock'+n+')');
			}
		var questionblock = '';
		for(var i=0,ilen=dataobj.question.length;i<ilen;i++){
			var qdataobj = dataobj.question[i];
			FuncBase.extendObj(dataobj,qdataobj); 
			for(var m=0,mlen=aloop.length;m<mlen;m++){
				var answerblock = '';
				aloopstr = aloop[m].replace(/\%\(\/?answerloop\)/ig,'');
				for(var k=0,klen=qdataobj.answer.length;k<klen;k++){
					var adataobj = qdataobj.answer[k];
					FuncBase.extendObj(qdataobj,adataobj);
					FuncBase.extendObj({'answerloopid':k+1},adataobj);
					tmp = this._proif(aloopstr,adataobj);
					answerblock += this._rnd(tmp,adataobj);
					tmp = null;
					}
				qdataobj['answerblock'+m] = answerblock;					
				}
			tmp = this._proif(qloopstr,qdataobj);
			questionblock += this._rnd(tmp,qdataobj);
			tmp = null;
			}
		ret = ret.replace(qre,questionblock);
		return ret;
		},
	_proaloop : function(str,dataobj){
		var ret = str,sigstr,sigmatcharr,sigsegment,condition,ifmiddle,iftpl,sigrnd,elseps,elsetpl;
		var are = /%\(answerloop\)(.*?)%\(\/answerloop\)/ig;
		var are1 = /%\(answerloop\)(.*?)%\(\/answerloop\)/i;
		matcharr = str.match(are);
		if(!matcharr){return ret;}
		for(var i=0,ilen=matcharr.length;i<ilen;i++){
			sigstr = matcharr[i];
			sigmatcharr = sigstr.match(are1);
			sigsegment = sigmatcharr[1];
			sigsegment = this._proif(sigsegment,dataobj);
			sigrnd = this._rnd(sigsegment,dataobj);
			ret = ret.replace(sigstr,sigrnd);
			}
		},		
	_rnd : function(tpl,ns/*,scope*/){
	        //scope = scope || window;
	        var scope = TplBase.filter;
	       	var fn = function(w, g) {
	            g = g.split("|");
	            var cnt = ns[g[0]];
	            for(var i=1; i < g.length; i++)
	                cnt = scope[g[i]](cnt);
	            if(cnt === '')
	                return '';
	            if(cnt == 0 || cnt == -1){
	            	cnt += '';
	            	}
	            return cnt || 'Null';//w;
	        };
	        return tpl.replace(/%\(([A-Za-z0-9_|.]*)\)/g, fn);				
		},
	render : function(dataobj){
		var tpl = this._tpl;
		tpl = tpl.replace(/\<\!\-\-|\-\-\>/g,'');
		tpl = tpl.replace(/\n|\r/ig,'');
		tpl = tpl.replace(/%\(c\)(.*?)%\(\/c\)/ig,'');
		return this._dotpl(tpl,dataobj);		
		}/*,
	votehtml : function(dataobj){
		var tpl = this._votetpl()
		tpl = tpl.replace(/\<\!\-\-|\-\-\>/g,'');
		tpl = tpl.replace(/\n|\r/ig,'');
		tpl = tpl.replace(/%\(c\)(.*?)%\(\/c\)/ig,'');
		return this._dotpl(tpl,dataobj);
		},
	resulthtml : function(dataobj){
		var tpl = this._resulttpl();
		tpl = tpl.replace(/\<\!\-\-|\-\-\>/g,'');
		tpl = tpl.replace(/\n|\r/ig,'');
		tpl = tpl.replace(/%\(c\)(.*?)%\(\/c\)/ig,'');		
		return this._dotpl(tpl,dataobj);
		}*/
	}
	
function ActionBase(sid,tpl){
	this.init(sid,tpl);
	}
ActionBase.prototype = {
	init : function(sid,tpl){
		this._sid = sid;
		this._pagetpl = new TplBase(tpl.pagetpl);
		this._resulttpl = new TplBase(tpl.resulttpl);
		this._minipagetpl = new TplBase(tpl.minipagetpl);
		//this._type = atype;
		window['pplivecontrol'+this._type+this._sid] = this;
		this._extdata = {};
		this._initextdata();		
		},
	_sid : null,//SubjectId 
	_type : null,//是投票还是竞猜 to be extend
	_ismini : false,//是否小型页面
	_urlpre : {},//to be extend
	_config : {},//to be extend
	//_extdata : {},//not to be extend
	_data : null,//数据
	_datastat : false,//数据状态
	_view : null,//负责显示的模块
	_beforeF : null,_afterF : null,//提交前后函数
	_getdata : function(t){//获取数据并调度获取数据之后的操作 t=v投票数据,t=r结果数据
		var pobj = this;
		var nextfunc = t=='v' ? function(){pobj.showpage()} : function(){pobj.showresult()};
		var cb = function(r){
			pobj._updatedata(r);
			nextfunc();
			}
		var url = [this._urlpre['getdataurl'],'SubjectID=',this._sid,'&random=',Math.random()].join('');
		Ajax.sendJs(url,cb);			
		},
	_updatedata : function(r){},//to be extend
	_initextdata : function(){},//to be extend
	setopt : function(p,v){
		this['_'+p] = v;
		},
	config : function(p,v){
		this._config[p] = v;
		},
	setextd : function(p,v){
		this._extdata['p'] = v;
		},		
	dosubmit : function(){},//to be extend(dovote)
	//_aftersubmit : function(){},//to be extend(setHasvote)	
	showpage : function(){//(showvote)
		this.closer();
		this._updatepage();
		//if(typeof(this._afterupdatepage)=='function'){
			//this._afterupdatepage();
		//	}
		},
	_updatepage : function(){//(updatevote)
		if(this._datastat){
			var dataobj = FuncBase.cmbObj(this._extdata,this._data);
			var tpl = this._ismini ? this._minipagetpl : this._pagetpl;
			var con = $(this._config['containerpre'] + this._sid);
			if(!con)return;
			if(this._data['subjectid']=='0')return;
			con.innerHTML = tpl.render(dataobj);
			if(typeof(this._afterupdatepage)=='function'){
				this._afterupdatepage();
				}			
			return true;
			}
		this._getdata('v');			
		},
	showresult : function(){},//to be extend
	_openr : function(dataobj){//显示结果层
		var d = $(this._config['containerpre']+'_result'+this._sid);
		var con = $(this._config['containerpre'] + this._sid);
		if(!d){
			d = document.createElement('div');
			d.id = this._config['containerpre']+'_result'+this._sid;
			document.body.insertBefore(d,document.body.firstChild);
			}
		d.innerHTML = this._resulttpl.render(dataobj);
		d.style.position= 'absolute';
		d.style.display = 'block';
		d.style.zIndex = 1000;
		d.getElementsByTagName('div')[0].style.margin = '0';
		//d.style.top = ViewArea.scrollTop() + ViewArea.height()/2 - d.clientHeight/2 + 'px';
		//d.style.left = ViewArea.scrollLeft() + ViewArea.width()/2 - d.clientWidth/2 + 'px';
		centerElement(d);
		EffectBase.dragit($('resulthandler'+this._sid),d);
		//this._updatevote();	
		},
	closer : function(){//关闭结果层
		try{
			$(this._config['containerpre']+'_result'+this._sid).style.display='none';
			}catch(e){}
		return false;		
		}
	}	
	
var pplivevotetpl = {
pagetpl : '<!--\
<div class="window_A1" style="width:500px ">\
<div class="pollMotion" style="display:none;" id="votetip%(subjectid)">正在提交数据，请稍后……</div>\
<table class="w_C1" width="500">\
  <tr>\
    <th class="pollTitle"><i>&nbsp;</i>%(subjectname)</th>\
  </tr>\
	  %(questionloop)\
	    	<tr>\
	    		<td class="pollNote">\
		    		%(if subjectmore)\
					%(questionloopid|titlepre)%(questionname)\
				%(else)\
					%(questionname)\
				%(endif)\
			</td>\
	  	</tr>\
	  	<tr>\
	    		<td class="resultView whiteBody">\
				%(if qimgtype)\
				<table class="pollContent pollImg">\
      				%(c)<tr align="center" valign="top">%(/c)\
      				%(answerloop)\
      					%(answerloopid|output_ans_head)\
       					 <td %(answerloopid|arrayclass)>\
       					 <label for="no%(answerid)">\
       					 <img src="%(answerimg)" /><br />\
       					 %(if subjectshowi)\
       					 <input type="%(answertype)" name="%(qinputname)" id="no%(answerid)" value="%(ainputvalue)"/>\
       					 %(endif)\
       					 %(answername)\
       					 </label>\
       					</td>\
       				%(answerloopid|output_ans_tail)\
       				%(/answerloop)	\
      				%(c)</tr>%(/c)\
    				</table>\
    				%(else)\
				<table class="pollContent">\
				%(answerloop)\
					<tr>\
					  <td %(answerloopid|arrayclass)>\
				%(if subjectshowi)\
				<input type="%(answertype)" name="%(qinputname)" id="no%(answerid)" value="%(ainputvalue)" style="padding-right:10px; " />\
				%(endif)\
					  <label for="no%(answerid)">%(answername)</label>\
					  </td>\
					</tr>\
				%(/answerloop)	\
				</table>\
				%(endif)\
			</td>\
  		</tr>\
	%(/questionloop)\
	  <tr>\
    		<td align="center" class="pollSbt">\
			%(if subjectopenvote)\
				<input type="submit" class="sbt_A1" value="投票" onclick="%(dovotes)"/>\
			%(endif)\
    			%(if subjectopenresult)\
				<input type="submit" class="sbt_A2" value="查看" onclick="%(showresult)"/>\
			%(endif)\
		</td>\
  	</tr>\
 	 <tr>\
    		<td class="pollOther">\
    		    	<table width="100%"  border="0" cellspacing="0" cellpadding="0">\
      			<tr>\
      			%(if subjectvotetip)<td align="left" class="C_F60">%(subjectvotetip)</td>%(endif)\
      			<td align="right">　\
    			%(if subjectplink)[<a href="%(subjectplink)" class="C_F60">观看节目</a>]%(endif)\
    			%(if subjectpost)[<a href="%(subjectpost)" class="C_F60">去P吧讨论</a>]%(endif)\
    			</td>\
    			</tr>\
    			</table>\
    		</td>\
 	 </tr>\
	  </table>\
</div>\
-->',
minipagetpl : 
'<dl class="areaD question">\
    <dt><span class="imgIco">用户调查</span></dt>\
    <dd>\
	%(questionloop)\
	<h1>%(questionname)</h1>\
	%(answerloop)\
	<p>\
		%(if subjectshowi)\
			<input type="%(answertype)" name="%(qinputname)" id="no%(answerid)" value="%(ainputvalue)" />\
		%(endif)\
		<label for="no%(answerid)">%(answername)</label>\
	</p>\
	%(/answerloop)\
	<ins>\
	%(if subjectopenvote)\
		<input type="submit" class="sbt_57x21_001" value="投票" onclick="%(dovotes)"/>\
	%(endif)\
	%(if subjectopenresult)\
		<input type="submit" class="sbt_57x21_002" value="查看" onclick="%(showresult)"/>\
	%(endif)\
	</ins>\
	<br style="clear:both" />\
	%(/questionloop)\
	</dd>\
</dl>',
resulttpl : '<!--\
<div class="window_A1" style="width:500px ">\
<table class="w_C1" width="500">\
  <tr>\
    <th class="pollTitle" id="resulthandler%(subjectid)"><span onclick="%(closer)"><a href="#1" class="close_A1" title="返回" >返回</a></span>%(subjectname)</th>\
  </tr>\
	  %(questionloop)\
	    	<tr>\
	    		<td class="pollNote">\
		    		%(if subjectmore)\
					%(questionloopid|titlepre)%(questionname)\
				%(else)\
					%(questionname)\
				%(endif)\
			</td>\
	  	</tr>\
	  	<tr>\
	    		<td class="resultView whiteBody">\
	    		%(if qimgtype)\
	    			<table class="pollContent pollImg">\
		  			%(c)<tr align="center" valign="top" class="as">%(/c)\
		  			%(answerloop)\
		  			%(answerloopid|output_ans_head_as)\
       					 <td %(answerloopid|arrayclass)>\
       					 <label for="no%(answerid)">\
       					 <img src="%(answerimg)" /><br />\
       					 %(answername)\
       					 </label>\
       					</td>\
       					%(answerloopid|output_ans_tail)\
       					%(/answerloop)	\
		 			 %(c)</tr>%(/c)\
				</table>\
	    		%(endif)\
				<table class="pollContent">\
				%(answerloop)\
				          <tr %(answerloopid|arrayclass)>\
           					<th width="32%">%(answerloopid).%(answername)</th>\
            					<th width="33%"><span style="width:%(answershowpect)%" class="%(answerloopid|spanclass)"></span></th>\
            					<th width="35%"><big>%(answercount)票</big> <tt>(%(answerpect)%)</tt></th>\
          				</tr>\
				%(/answerloop)	\
				</table>\
			</td>\
  		</tr>\
	%(/questionloop)\
 	 <tr>\
    		<td align="right" class="pollOther">\
    			%(if subjectplink)[<a href="%(subjectplink)" class="C_F60">观看节目</a>]%(endif)\
    			%(if subjectpost)[<a href="%(subjectpost)" class="C_F60">去P吧讨论</a>]%(endif)\
    		</td>\
 	 </tr>\
 	 </table>\
</div>\
-->'
	}

function PollClass(sid,tpl){
	this.init(sid,tpl);
	}
PollClass.prototype = {
	_type : 'poll',
	_urlpre : {
		'getdataurl' : 'http://poll.pplive.com/Result.aspx?',//数据地址
		'dovoteurl' : 'http://poll.pplive.com/poll.aspx?',//投票地址
		'quepre' : 'answers'//投票时question参数的前缀		
		},
	_config : {
		'containerpre' : '',//投票容器前缀
		'inpnamepre' : 'pplivevotequt',//投票选项input 的name 后缀
		'inpvaluepre' : 'pplivevoteans',//投票选项input 的 value后缀
		//'showinpage' : false,//在本页显示
		'waitvotedata' : false,//是否等待投票返回数据
		'resultafvote' : true,//投票完成之后显示投票结果
		'viewtype' : 1,
		'hasvote' : false,//用户已投票
		'mustvote' : false,//必须投票才能看结果
		'resultnotopen' : false//结果永不公开
		},
	_updatedata : function(r){//从获取的数据中更新_data
		var ret = {};
		var dataobj = r.Subject;
		//ret['c'] = true;
		ret.subjectid = dataobj['Id'];
		ret.subjectname = dataobj['Name'];
		var hasvote = Cookie.get('haspplivedovote'+this._sid);
		var hvflag = hasvote ? 2 : 1;
		this.config('hasvote',hasvote);
		ret.subjectopenvote = parseInt(dataobj['EnablePoll'])&&!(hasvote);
		ret.subjectvotetip = '';
		ret.subjectvotetip += parseInt(dataobj['EnablePoll']) ? '' : '超过今日投票限额 ';
		ret.subjectvotetip += hasvote ? '已投票,谢谢关注' : '';
		if(dataobj['OverTimeType']=='2'){
			ret.subjectopenvote = false;
			ret.subjectvotetip = '投票已截止,谢谢关注';
			}
		else if(dataobj['OverTimeType']=='0'){
			ret.subjectopenvote = false;
			ret.subjectvotetip = '投票尚未开始,谢谢关注';				
			}
		ret.EnableView = dataobj['EnableView'];	
		ret.ViewStyle = dataobj['ViewStyle'];		
		ret.subjectopenresult = dataobj['EnableView'] & hvflag;
//		if(hasvote){
//			ret.subjectopenresult = dataobj['EnableView']!=2 ? true : false;
//			}
		ret.subjectresulttip = '不能查看';
		ret.subjectplink = dataobj['SynacastURL'];
		ret.subjectpost = dataobj['P8URL'];
		ret.subjectshowi = dataobj['OverTimeType']=='1'&&ret.subjectopenvote;
		this.config('showinpage',dataobj['ViewStyle']=='1');
		if(this._config['showinpage'])this._extdata['closer'] = this._extdata['showvote'];
		if(dataobj['ViewStyle']=='2'){
			ret.subjectopenresult=false;
			this.config('resultnotopen',dataobj['ViewStyle']=='2')
			}
		ret.question = [];
		var oriqut =dataobj.Questions? dataobj.Questions.Question : [];
		if(!(oriqut instanceof Array))oriqut = [oriqut];
		var aqut,tmpqut,orians,aans,tmpans;
		if(oriqut.length>1){ret.subjectmore=true;}//有两个以上的question
		for(var i=0,ilen=oriqut.length;i<ilen;i++){
			aqut = oriqut[i];
			tmpqut = {};
			tmpqut['questionname'] = aqut['Name'];
			tmpqut['questionid'] = aqut['Id'];
			tmpqut['qimgtype'] = aqut['Type'] & 2;
			tmpqut['questionloopid'] = i+1;
			tmpqut['qinputname'] = [aqut['Id'] , '_' , this._config['inpnamepre']].join('');
			//tmpqut['qtexttype'] = true;
			tmpqut['answer'] = [];
			try{
				orians = aqut.Answers.Answer;
				}catch(e){//没有Answer
					ret.question.push(tmpqut);
					continue;
				}
			if(!(orians instanceof Array))orians = [orians];
			tmpqut['totlecount'] = 0;
			var maxcount = 1;
			var tmpcount;
			for(var c=0,clen=orians.length;c<clen;c++){
				tmpcount = 0;
				if(!orians[c]['Count'])break;
				tmpcount = parseInt(orians[c]['Count'])
				tmpqut['totlecount']+=tmpcount;
				if(tmpcount>maxcount)maxcount=tmpcount;
				}
			for(var j=0,jlen=orians.length;j<jlen;j++){
				aans = {};	
				tmpans = orians[j];
				aans['answername'] = tmpans['Name'];
				aans['answerimg'] = tmpans['ImageURL'];
				//if(tmpans['ImageURL']){tmpqut['qimgtype'] = true;/*tmpqut['qtexttype'] = false*/};
				aans['answertype'] = aqut['Type'] & 1 ? 'checkbox' : 'radio';
				aans['answerid'] = tmpans['Id'];
				aans['ainputvalue'] = tmpans['Id'] + '_' + this._config['inpvaluepre'];
				if(tmpans['Count']){
					aans['answercount'] = parseInt(tmpans['Count']);
					if(!tmpqut['totlecount']){aans['answerpect']='0.0';}
					else{aans['answerpect'] = (100*aans['answercount']/parseInt(tmpqut['totlecount'])).toString().substr(0,4);}
					aans['answershowpect'] = (100*aans['answercount']/maxcount).toString().substr(0,4);
					}	
				tmpqut['answer'].push(aans);
				}
			ret.question.push(tmpqut);
			}
		this._data = ret;
		this._datastat = true;
		},
	_initextdata : function(){
		this._extdata['dovotes'] = 'window.pplivecontrol'+this._type+this._sid+'.dosubmit();return false';
		this._extdata['showresult'] = 'window.pplivecontrol'+this._type+this._sid+'.showresult();return false';
		this._extdata['showvote'] = 'window.pplivecontrol'+this._type+this._sid+'.showpage();return false';
		this._extdata['closer'] = 'window.pplivecontrol'+this._type+this._sid+'.closer();return false';		
		},
	_getvote : function(){//获取用户的投票项
		var tmp = {},tmpa = [],votestr,avotevalue,inp;
		var ret = [];
		var con = $(this._config['containerpre'] + this._sid);
		var inps = con.getElementsByTagName('input');
		for(var i=0,ilen=inps.length;i<ilen;i++){
			inp = inps[i];
			avotevalue = inp.value.split('_')[0];
			if(inp.type=="checkbox"){
				if(inp.checked){
					if(inp.name in tmp){tmp[inp.name].push(avotevalue);}//如果此多选项已经在tmp中,则在tmp中该项的数组中push该选项的值
					else{tmp[inp.name]=[avotevalue];}//如果此多选项不在tmp中,则在tmp中新建一个包括此选项值的数组
				}
			}
			if(inp.type=='radio'){
				if(inp.checked){tmp[inp.name] = [avotevalue];
					}
				}
		}
		if(!tmp)return false;
		for(var p in tmp){
			if(typeof(tmp[p])!='function')
			tmpa = tmpa.concat(tmp[p]);
			}
		if(!tmpa)return false;
		//ret = tmpa.join(',');
		ret = tmpa;
		return ret;
		},
	dosubmit : function(){
		this.closer();
		var votearr = this._getvote();
		var votestr = votearr.join(',');
		if(!votestr){alert('你还没有选择');return false;}
		var pobj = this;
		var parm = {//传给beforeF和afterF的参数
			sid : pobj._sid,
			//config : pobj._config,
			showresult : function(){pobj.showresult();}
			}
		var cb = function(r){
			parm.responseText = r.responseText;
			if(typeof(pobj._afterF)=='function')pobj._afterF(parm);
			}
		var url = [this._urlpre['dovoteurl'],'SubjectID=',this._sid,'&',this._urlpre['quepre'],'=',votestr].join('');
		if(typeof(pobj._beforeF)=='function')pobj._beforeF(parm);
		this._setHasvote();
		try{
			this._addVote(votearr);
		}catch(e){/*alert('add failed')*/}
		if(this._config['waitvotedata']){
			Ajax.sendJs(url,cb);
			}
		else{
			Ajax.sendJs(url,function(){});
			parm.responseText = '200-ok';
				if(typeof(pobj._afterF)=='function'){
					setTimeout(function(){
						pobj._afterF(parm);
						},1000);
					}
			}
		return true;		
		},
	_setHasvote : function(){
		//写入cookie
		Cookie.set('haspplivedovote'+this._sid,'1',1);
		//if(!this._config['showinpage']){this._updatepage()};
		this._config['hasvote'] |= 1;//设置为已投票
		this._data['subjectopenvote'] = false;
		this._data['subjectshowi'] = false;
		this._data['subjectvotetip'] = '已投票,谢谢关注';
		this._data['subjectopenresult'] = this._data['ViewStyle']!='2'&&(this._data['EnableView'] & 2) ? true : false;
		},
	_addVote : function(arr){
		var q = this._data.question;
		var tmpq,a,tmpa,cflag;
		for(var i=0,ilen=q.length;i<ilen;i++){
			tmpq = q[i];
			cflag = false;//改变了数值
			for(var k=0,klen=tmpq.answer.length;k<klen;k++){
				tmpa = tmpq.answer[k]
				if(FuncBase.pina(tmpa['answerid'],arr)){
					tmpa['answercount']++;
					tmpq['totlecount']++;
					cflag = true;
					}
				}
			tmpa = null;
			if(cflag){
				for(var m=0,mlen=tmpq.answer.length;m<mlen;m++){
					tmpa = tmpq.answer[m];
					tmpa['answerpect'] = (100*tmpa['answercount']/parseInt(tmpq['totlecount'])).toString().substr(0,4);
					}
				}
			}
		},
	showresult : function(){
		if(!this._config['showinpage']||!this._config['resultnotopen']){this._updatepage()};
		if(this._config['resultnotopen'])return false;//结果不公开
		//if(!this._config['openresult'])return false;
		if(this._config['mustvote']&&!this._config['hasvote']){alert('请先投票再查看');return false;}
		if(this._datastat){
			var dataobj = FuncBase.cmbObj(this._extdata,this._data);
			if(this._config['showinpage']&&!this._ismini){$(this._config['containerpre'] + this._sid).innerHTML = this._resulttpl.render(dataobj);}
			else{this._openr(dataobj);}
			return false;
			}
		this._getdata('r');
		}														
	}
FuncBase.extendClass(ActionBase,PollClass);		
function initpoll(sid,opt,cfg){
	var opt = opt||{};
	var cfg = cfg||{};
	var containerpre = opt['containerpre'] || 'pplivepollcontainer';
	var containerclass = opt['containerclass'] || 'pplivepollcontainer';
	//document.write('<div id="' + containerpre + sid + '" class="' + containerclass + '"></div>');
	var afterF = opt['afterF']||null;
	var beforeF = opt['beforeF']||null;
	var poll = new PollClass(sid,pplivevotetpl);
	poll.setopt('afterF',afterF);
	poll.setopt('beforeF',beforeF);
	poll.setopt('ismini',cfg.showmini);
	poll.config('containerpre',containerpre);
	poll.showpage();
	}
var Pollopt = {
	beforeF: function(obj){
		$('votetip'+obj.sid).innerHTML = '<img src="http://res.pplive.com/poll/images/buffer_A1.gif" width="32" height="32" />正在提交数据，请稍后……';
		centerElement($('votetip'+obj.sid));
		$('votetip'+obj.sid).style.display = 'block';
		},
	afterF : function(obj){
		$('votetip'+obj.sid).innerHTML = '投票成功';
		EffectBase.hl($('votetip'+obj.sid),function(){
			$('votetip'+obj.sid).style.display = 'none';
			obj.showresult();
			})
		}
	}	
	
var pplivewagertpl = {
pagetpl : '\
<div class="window_A1" style="width:500px">\
<div class="pollMotion" style="display:none;" id="wagertip%(subjectid)">正在投票，请稍后……</div>\
<table class="w_C1">\
  <tr>\
    <th class="pollTitle">%(subjectname)</th>\
  </tr>\
  %(questionloop)\
  <tr>\
    <td class="pollNote">%(subjectdec)</td>\
      </tr>\
  <tr>\
    <td class="resultView whiteBody" id="wagertablecon%(subjectid)">\
	    <table class="pollContent" >\
	    %(answerloop)\
          <tr %(loopid|trclass) id="wagertr%(answerid)">\
            <td width="32%">\
            %(if showrad)\
            <input type="radio" name="%(qinputname)" id="no%(answerid)" value="%(inpvalue)"/>\
            %(endif)\
            <label for="no%(answerid)">%(answername)</label>\
            </td>\
            %(if showapic)<td width="32%"><span style="width:%(answerpect)%" class="%(loopid|spanclass)"></span></td>%(endif)\
            <td width="36%">%(if showman)<big>%(gpc)人</big>%(endif) %(if showval)<tt>(%(gval)分)</tt>%(endif)<label id="wagerla%(answerid)"></label></td>\
          </tr>\
          %(/answerloop)\
        </table>\
	</td>\
  </tr>\
  %(/questionloop)\
  <tr>\
    <td align="left" id="wagertipcon%(subjectid)">\
		<table cellspacing="5" class="jcIntegral">\
			<tr><td colspan="2" class="jcIco2">当前奖金总额：<i class="C_090" id="prizepoll%(subjectid)">%(prizepoll)</i>分</td>\
		    </tr>\
			<tr>\
			<td class="jcpre" id="pointarea%(subjectid)"></td>\
			<td align="left" valign="top"  id="timearea%(subjectid)"></td>\
		    </tr>\
		</table>\
	</td>\
  </tr>\
  <tr>\
    <td align="center" class="pollSbt">\
	%(if showwager)\
	<input type="submit" class="sbt_A1" value="提交" onclick="%(dosubmit)" />\
	%(endif)\
	</td>\
  </tr>\
  <tr>\
    <td align="right" class="pollOther">\
    %(if subjectplink)[<a href="%(subjectplink)" class="C_F60">观看节目</a>]%(endif)\
    %(if subjectpost)[<a href="%(subjectpost)" class="C_F60" target="_blank">去P吧讨论</a>]%(endif)\
    <a href="#"><img src="http://res.pplive.com/poll/images/help.gif" border="0" style="margin-bottom:-2px" /></a>\
    </td>\
  </tr>\
</table>\
</div>',
minipagetpl : 
'<dl class="areaD question">\
	<dt><span class="imgIco yellow">竞猜</span></dt>\
	<dd>\
		<h3>本期奖金<i>%(prizepoll)</i></h3>\
		<h2 id="timearea%(subjectid)">开奖日期：2007年8月15日</h2>\
		%(questionloop)\
			<h1>%(subjectdec)</h1>\
			%(answerloop)\
				<p>\
					%(c)%(if showrad)%(/c)\
					<input type="radio" name="%(qinputname)" id="no%(answerid)" value="%(inpvalue)"/>\
					%(c)%(endif)%(/c)\
					<label for="no%(answerid)">%(answername)</label>\
				</p>\
			%(/answerloop)\
		<h2><span id="pointarea%(subjectid)"></span></h2>\
		%(if showwager)\
			<ins><input type="submit" class="sbt_57x21_001" value="提交" onclick="%(dosubmit)" /></ins>\
		%(endif)\
		<br style="clear:both" />\
		%(/questionloop)\
	</dd>\
</dl>',
resulttpl : '<div class="window_A1" style="width:430px ">\
<table class="w_B1">\
  <tr>\
    <th class="pollTitle" id="resulthandler%(subjectid)">\
    <span onclick="%(closer)"><a href="#1" class="close_A1" title="返回" >返回</a></span><i>&nbsp;</i>竞猜结果</th>\
  </tr>\
  <tr>\
    <td class="pollTopic jcIco1">%(subjectname)</td>\
  </tr>\
  %(questionloop)\
  <tr>\
    <td class="pollNote">%(subjectdec)</td>\
  </tr>\
  <tr>\
    <td class="resultView whiteBody">\
	    <table class="pollContent">\
             %(answerloop)\
			<tr %(answerloopid|arrayclass)>\
           		<th width="32%">%(answerloopid).%(answername)</th>\
            		<th width="33%"><span style="width:%(answerpect)%" class="%(answerloopid|spanclass)"></span></th>\
            		<th width="35%"><big>%(gpc)人</big> <tt>(%(gval))分</tt></th>\
          		</tr>\
          %(/answerloop)\
        </table>\
	</td>\
  </tr>\
  %(/questionloop)\
  <tr>\
    <td align="right" class="pollOther">\
    %(if subjectplink)[<a href="%(subjectplink)" class="C_F60" target="_blank">观看节目</a>]%(endif)\
    %(if subjectpost)[<a href="%(subjectpost)" class="C_F60" target="_blank">去P吧讨论</a>]%(endif)\
    </td>\
  </tr>\
</table>\
</div>'	
	}

function WagerClass(sid,tpl){
	this.init(sid,tpl);
	}
WagerClass.prototype = {
	_type : 'wager',
	_urlpre : {
		'getdataurl' : 'http://jingcai.pplive.com/Result.aspx?',//数据地址
		'dowagerurl' : 'http://jingcai.pplive.com/Guess.aspx?'//投票地址	
		},
	_config : {
		'containerpre' : 'pplivewagercontainer',//容器前缀
		'chipinput' : 'pplivewagerchip',//投注积分input前缀
		'inpnamepre' : 'pplivewagerqut',//选项radio的name 后缀
		'inpvaluepre' : 'pplivewagerval',//选项radio的value后缀
		'waitvotedata' : true,
		'MinChip' : 0,
		'MaxChip' : 0
		},
	_updatedata : function(r){
		var ret = {};
		var aw = r.Subject;
		var tmpstr;
		var prizecount=0,peoplecount=0;
		//ret = aw;
		ret.subjectid = aw.Id;
		ret.subjectname = aw.Name;
		ret.subjectdec = aw.Description;
		ret.state = aw.State;
		ret.daan = aw.CorrectOption;
		ret.question = [{}];
		ret.question[0].qinputname = aw.Id + '_' + this._config['inpnamepre'];
		try{
			ops=aw.Options.Option
			}catch(e){ops=[]};
		if(!(ops instanceof Array))ops = [ops];
		for(var i=0,ilen=ops.length;i<ilen;i++){
			prizecount += parseInt(ops[i].GuessValue);
			peoplecount += parseInt(ops[i].GuessPersonCount);
			}
		ret.question[0].prizecount = prizecount;
		ret.question[0].peoplecount = peoplecount;	
		ret.question[0].answer = [];
		ans = ret.question[0].answer;	
		for(var i=0,ilen=ops.length;i<ilen;i++){
			ans[i] = {};
			ans[i].answerid = ops[i].Id;
			ans[i].answerpect = ops[i]['GuessPersonCount']!='0' ?((100*parseInt(ops[i]['GuessPersonCount'])/parseInt(peoplecount)+'').substr(0,4)):'0';
			ans[i].loopid=i;
			ans[i].answername = ops[i].Name;
			ans[i].inpvalue = ops[i].Id + '_' + this._config['inpvaluepre'];
			ans[i].gval = ops[i].GuessValue;
			ans[i].gpc = ops[i].GuessPersonCount;
			}
		
		ret.showman = aw.ViewOption & 2;//显示已投人数
		ret.showval = aw.ViewOption & 1;//显示已投分数
		ret.showapic = ret.showman || ret.showval;//显示柱状图
		ret.prizepoll = prizecount + parseInt(aw.PrizePool);
		ret.chipinput = this._sid +'_' + this._config['chipinput'];
		ret.minprize = parseInt(aw.MinValue);
		ret.maxprize = parseInt(aw.MaxValue);
		ret.wagerend = aw.State == '2';
		if(aw.State == '3'){ret.wagerend=true;ret.wagercheck=true};
		if(aw.State == '4'){ret.deleted = aw.State == '4';}
		ret.endtime = aw.EndTime;
		ret.checktime = aw.CheckTime;
		if(ret.minprize==ret.maxprize){
			ret.givenprize = true;
			}
		this.config('MinChip',ret.minprize);
		this.config('MaxChip',ret.maxprize);
		ret.subjectplink = aw.SynacastURL;
		ret.subjectpost = aw.P8URL;
		//ret.question.answer = aw.Options.Option;
		//ret.expire = false;
		//ret.canwager = Cookie.get(this._getUname()+'haspplivedowager'+this._sid) ? true : false;
		ret.showwager = true;
		ret.haswager = false;
		ret.userright = false;
		//ret.hasnotlogin = !this.islogin();
		if(aw.User){
			//ret.hasnotlogin = aw.User.Login == 'False';
			if(aw.User.IsCanPoll=='False'){ret.showwager=false;ret.haswager=true};
			ret.usergval = aw.User.GuessValue;
			tmpstr = aw.User.PrizeValue||'0';
			tmpstr = tmpstr + '';
			ret.userprize = tmpstr.indexOf('.')==-1 ? 
				tmpstr : tmpstr.substr(0,tmpstr.indexOf('.'));
			if(ret.userprize!='0'){ret.userright=true;}
			}
		ret.showwager = ret.showrad = (ret.wagerend||ret.wagercheck||ret.haswager||ret.deleted) ? false : true;		
		this._data = ret;
		this._datastat = true;
		},//to be extend
	_initextdata : function(){
		//this._urlpre['getdataurl'] += this._getUname() + '&';
		//this._urlpre['dowagerurl'] += this._getUname() + '&';
		this._extdata['dosubmit'] = 'window.pplivecontrol'+this._type+this._sid+'.dosubmit();return false';
		this._extdata['showresult'] = 'window.pplivecontrol'+this._type+this._sid+'.showresult();return false';
		this._extdata['closer'] = 'window.pplivecontrol'+this._type+this._sid+'.closer();return false';		
		//this._extdata['username'] = 'wawa';
		},//to be extend
	_getUname : function(){
		//return 'wawa';
		var coki__PPName = Cookie.get('PPName') || '';
		var userName = coki__PPName.split('$')[0];
		userName = encodeURIComponent(userName);
		return userName ? userName : false;
		},	
	dosubmit : function(){
		var usersel = this._getVal();
		if(!usersel)return;
		this.closer();
		var pobj = this;
		var parm = {//传给beforeF和afterF的参数
			sid : pobj._sid,
			//config : pobj._config,
			showresult : function(){pobj.showresult();}
			}
		var cb = function(r){
			var wstatus = r.responseText.split('-')[0]
			var wtip = r.responseText.split('-')[1];
			if(wstatus=='6'){
				pobj._setHaswager();
				pobj._addWager(usersel);
				pobj._updatepage();
				}
			pobj.showtip(wtip,4000);
			parm.responseText = r.responseText;
			if(typeof(pobj._afterF)=='function')pobj._afterF(parm);
			}
		var url = [this._urlpre['dowagerurl'],'OptionID=',usersel[0],'&GuessValue=',usersel[1]].join('');
		if(typeof(pobj._beforeF)=='function')pobj._beforeF(parm);
		if(this._config['waitvotedata']){
			Ajax.sendJs(url,cb);
			}
		else{
			Ajax.sendJs(url,function(){});
			this._setHaswager();
			this._addWager(usersel);
			this._updatepage();
			parm.responseText = '1-ok';
				if(typeof(pobj._afterF)=='function'){
					setTimeout(function(){
						pobj._afterF(parm);
						},1000);
					}
			}
		return true;		
		},//to be extend(dovote)
	_getVal : function(){
		var retop = retval = null;
		var con = $(this._config['containerpre']+this._sid);
		var rads = con.getElementsByTagName('input');//(this._sid+'_'+this._config['inpnamepre']);
		for(var i=0,ilen=rads.length;i<ilen;i++){
			if(rads[i].type=='radio'&&rads[i].checked){
				retop = rads[i].value.split('_')[0];
				break;
				}
			}
		if(!retop){alert('你还没有选择!');return false;}
		retval = parseInt($(this._sid + '_' + this._config['chipinput']).value);
		if(!retval){alert('请输入投注积分');return false;}
		if(retval<this._config['MinChip']||retval>this._config['MaxChip']){
			this.showtip('请输入合法积分',1500);return false;
			}
		return [retop,retval];
		},
	_setHaswager : function(){
		//Cookie.set(this._getUname()+'haspplivedowager'+this._sid,'1',0,0,1,0,0,0);
		},
	_addWager : function(valarr){
		var _data = this._data;
		var qut = null, ans = null, changeflag = false;
		_data.haswager = true;
		_data.prizepoll +=valarr[1];
		_data.showrad = false;
		_data.showwager = false;
		qut = _data.question[0];
		qut.prizecount += valarr[1]
		qut.peoplecount ++;
		for(var i=0,ilen=qut.answer.length;i<ilen;i++){
			changeflag = false;
			ans = qut.answer[i];
			if(ans.answerid==valarr[0]){
				ans.gpc = parseInt(ans.gpc) + 1;
				ans.gval = parseInt(ans.gval) + valarr[1];
				changeflag = true;
				}
			ans.answerpect = (100*ans['gpc']/parseInt(qut['peoplecount'])).toString().substr(0,4);
			}
		},		
	_afterupdatepage : function(){
		//if(this._ismini)return;
		var d = this._data;
		var pointtd = $('pointarea'+this._sid);
		var timetd = $('timearea'+this._sid);
		var pointstr = '';
		var timestr = '';
		var chipinput = [this._sid ,'_',this._config['chipinput']].join('');
		if(d['deleted']){
			//$('wagertablecon'+this._sid).innerHTML = '&nbsp;';
			//$('wagertablecon'+this._sid).style.borderTop = '1px solid #D5D5D5';
			$('prizepoll'+this._sid).innerHTML = '0';
			$('wagertablecon'+this._sid).style.display = 'none';
			$('wagertipcon'+this._sid).style.borderTop = '1px solid #D5D5D5';
			pointtd.innerHTML = '<i>竟猜因故取消，原投注金额已返回用户个人帐户。</i>';
			return;
			}
		if(d['wagerend']){//已截止
			if(d['wagercheck']){//已发布
				if(!this.ismini){
					try{
						$('wagertr'+this._data['daan']).className += ' pollProper';
						$('wagerla'+this._data['daan']).innerHTML = '正确答案';
					}catch(e){}
					}
				if(d['haswager']){//已投票
					if(d['userright']){//答对
						pointtd.className = 'pollright';
						pointstr = ['<i><img src="http://res.pplive.com/poll/images/happy.gif" width="20" height="20" />恭喜！您猜对了！</i>',
						'竞猜',d.usergval,'分，共获得',d.userprize,
						'分。可去<a href="http://passport.pplive.com/UserCenter.aspx">我的PP中心</a>',
						'><a href="http://passport.pplive.com/Guess.aspx?username=',
						this._getUname(),
						'">我的竞猜</a>',
						' 查看详情'].join('');
						}
					else{//答错
						pointtd.className = 'pollwrong';
						pointstr = ['<i><img src="http://res.pplive.com/poll/images/mad.gif" width="20" height="20" />您猜错了，真遗憾！</i>',
						'可去<a href="http://passport.pplive.com/UserCenter.aspx">',
						'我的PP中心</a>>',
						'<a href="http://passport.pplive.com/Guess.aspx?username=',
						this._getUname(),
						'">我的竞猜</a> 查看详情'].join('');
						}
					}
				else{//未投票
					pointstr = '本次竞猜已结束,期待你下次参与';
					}
				}
			else{//未发布
				pointstr = '竞猜投交已截止,请等待结果公布';
				timestr = '结果公布时间  ' + d['checktime'];				
				}
			if(this._ismini&&!timestr){
				timestr = '竞猜已截止';
				}	
			}
		else{//未截止
			if(d['haswager']){//已投票
				pointstr = '竞猜已投交,请等待结果公布';
				timestr = '结果公布时间  ' + d['checktime'];
				}
			else{//未投票
				if(d['givenprize']){
					pointstr = ['本次竞猜需要消耗',d['minprize'],'个积分<input type="hidden" value="',d['minprize'],
					'" id="',chipinput,'" />'].join('');
					}
				else{
					pointstr = ['输入本注投注积分<input type="text" size="4" style="height:16px;line-height:16px" id="',chipinput,'"/>分<i>(',d['minprize'],'--',d['maxprize'],'分)</i>'].join('');
					}
				timestr = '本次竞猜截止时间  ' + d['endtime'];	
				}
			}
		//try{	
			pointtd.innerHTML = pointstr;
			timetd.innerHTML = timestr;
		//}catch(e){}
		},
	islogin : function(){
		return this._getUname() ? true : false;
		},
	showtip : function(s,t){
		var t = t==undefined ? 2 : t; 
		$('wagertip'+this._sid).innerHTML = s;
		centerElement($('wagertip'+this._sid));
		$('wagertip'+this._sid).style.display = 'block';
		var self = this;
		var func = function(){
			EffectBase.hl(
				$('wagertip'+self._sid),
				function(){
					$('wagertip'+self._sid).style.display = 'none';
					}
				);
			};
		clearTimeout(this._tiptimer);
		this._tiptimer = setTimeout(func,t);
		},	
	shownotlogin : function(){
		$(this._config['containerpre'] + this._sid).innerHTML = '你还没有登录,请先<a href="http://passport.pplive.com/Login.aspx?APReturnURL='+window.location.href+'">登录</a>再参加竞猜';
		},		
	showresult : function(){
		var dataobj = FuncBase.cmbObj(this._extdata,this._data);
		this._openr(dataobj);
		}//to be extend			
	}
FuncBase.extendClass(ActionBase,WagerClass);	
function initwager(sid,opt,cfg){
	var opt = opt||{};
	var cfg = cfg||{};
	var containerpre = opt['containerpre'] || 'pplivewagercontainer';
	var containerclass = opt['containerclass'] || 'pplivewagercontainer';
	//document.write('<div id="' + containerpre + sid + '" class="' + containerclass + '"></div>');
	var afterF = opt['afterF']||null;
	var beforeF = opt['beforeF']||null;
	var wager = new WagerClass(sid,pplivewagertpl);
	wager.setopt('afterF',afterF);
	wager.setopt('beforeF',beforeF);
	wager.setopt('ismini',cfg.showmini)
	//wager.config('ismini',cfg.showmini);
	wager.config('containerpre',containerpre);
//	if(!wager.islogin()){
//		wager.shownotlogin();
//		return false;
//		}
	wager.showpage();	
	}
var Wageropt = {
	beforeF: function(obj){
		$('wagertip'+obj.sid).innerHTML = '<img src="http://res.pplive.com/poll/images/buffer_A1.gif" width="32" height="32" />正在提交数据，请稍后…';
		centerElement($('wagertip'+obj.sid));
		$('wagertip'+obj.sid).style.display = 'block';
		}/*,
	afterF : function(obj){
		$('wagertip'+obj.sid).innerHTML = '投票成功';
		EffectBase.hl($('wagertip'+obj.sid),function(){
			$('wagertip'+obj.sid).style.display = 'none';
			obj.showresult();
			})
		}
	*/	
	}	

var Ajax = {
	sendJs : function(url,callback,options){
		var head=document.getElementsByTagName("head")[0];
		var sce=document.createElement('script');
		sce.id=yun.getGuid();
		yun.regJson(sce.id,callback,options);
		sce.type='text/javascript';
		var qs='&cb=yun.dojson&jsonId='+sce.id;url=url.match(/\?/)?url+qs:url+'?'+qs;
		sce.src=url;//+'&random='+Math.random();
		head.appendChild(sce)
		}
	}
	
var Cookie = {
	get : function(cname){
	        var cookieValue = null;
	        if (document.cookie && document.cookie != '') {
	            var cookies = document.cookie.split(';');
	            for (var i = 0; i < cookies.length; i++) {
	                var cookie = cookies[i].replace(/^\s+|\s+$/g,'');
	                // Does this cookie string begin with the name we want?
	                if (cookie.substring(0, cname.length + 1) == (cname + '=')) {
	                    cookieValue = decodeURIComponent(cookie.substring(cname.length + 1));
	                    break;
	                }
	            }
	        }
	        return cookieValue;		
		},
	set : function(cname,cval,cexp){
		var expires = '';
		var d = new Date();
		d.setTime(d.getTime() + cexp* 24 * 60 * 60 * 1000);
		expires = '; expires=' + d.toUTCString();
		var path = '; path=/';
		var domain = '; domain=pplive.com';
		 var secure = '';
		document.cookie = [cname, '=', encodeURIComponent(cval), expires, path, domain, secure].join('');
		}
	}

function centerElement(el){
	var t = PageSize.getScrollTop() + PageSize.getHeight()/2 - el.clientHeight/2;
	var l = PageSize.getScrollLeft() + PageSize.getWidth()/2 - el.clientWidth/2;
	el.style.top = t + 'px'; 
	el.style.left = l + 'px';
	}		
var PageSize = new function(){
	
	
	this.getScrollTop = function(){
		return isCSS1Dom ? 
			document.documentElement.scrollTop : document.body.scrollTop;};
			
	this.getScrollLeft = function(){
		return isCSS1Dom ? 
			document.documentElement.scrollLeft : document.body.scrollLeft;};
			
	this.getHeight = function(){
		var y1=document.body.clientHeight;
		var y2=document.documentElement.clientHeight;
		return isCSS1Dom ? y2 : y1;};
		
	this.getWidth = function(){
		var x1=document.body.clientWidth;
		var x2=document.documentElement.clientWidth;
		return isCSS1Dom ? x2 : x1;};
		
	this.pageHeight = function(){
		var viewHeight = this.getHeight();
		var pageHeight = document.body.scrollHeight;
		return Math.max(viewHeight,pageHeight);
		};	
	};		
window.initpoll = initpoll;
window.Pollopt = Pollopt;
window.initwager = initwager;
window.Wageropt = Wageropt;	
})()		

if(!yun){
	var yun={ver:'1.1.5',idseq:100,id:'yun',htData:[]};
	}

yun.getGuid=function(){return this.id+this.idseq++};
yun.reg=function(key,obj){this.htData[key]=obj};
yun.regJson=function(id,callBack,opt){this.reg(id,{cb:callBack,op:opt})};
yun.dojson=function(id,Jo){
	var jb=this.htData[id];
	jb.cb(Jo,jb.op);
	jb.cb=jb.opt=jb=this.htData[id]=null;
};
	