var IfengAppVote = {
	encoding:'utf-8',
	author:'huweiqi',
	date:'2008.1.28'
};

(function(){
	//IFRAME提交
	IfengAppVote.iframeSubmit = function (rURL){
		try{
			document.getElementById('voteIframe').src = rURL;
		}catch(err){
		}
	}
	
	//截取字符串
	IfengAppVote.substr = function(s, d) {
		if(typeof(s)=='undefined'||s.length==0){
			return '';
		}
		if(s.length>d){
			return s.substr(0, d)+'...';
		}else{
			return s;
		}
	}
	
	IfengAppVote.voteflag = true;
	IfengAppVote._a = new Object();
	IfengAppVote._callback;
	
	//提交投票
	IfengAppVote.vote = function(_a,sid,vid,iid){
		var requesturl = "http://space.ifeng.com/vote/votingJSON.do?surveyId="+sid+"&aw"+vid+"="+iid+"&t="+new Date().getTime();
		IfengAppVote._a = _a;
		IfengAppVote.iframeSubmit(requesturl);
		setTimeout('voteResult(IfengAppVote._a,IfengAppVote.voteflag,IfengAppVote.vote_msg);',200);
	}
	
	//提交投票,含回调函数 cds add at 2009-2-24
	IfengAppVote.vote_callback = function(_a,sid,vid,iid,callback){
		var requesturl = "http://space.ifeng.com/vote/votingJSON.do?surveyId="+sid+"&aw"+vid+"="+iid+"&t="+new Date().getTime();
		IfengAppVote._a = _a;
		IfengAppVote._callback = callback;
		IfengAppVote.iframeSubmit(requesturl);
		setTimeout('voteResult(IfengAppVote._a,IfengAppVote.voteflag,IfengAppVote.vote_msg,IfengAppVote._callback);',200);
	}
	
	voteResult = function(_a,_v,_m,_callback){
		if(_v){
			_a.innerHTML = (new Number(_a.innerHTML)) + 1;
			if(_callback)
			{
				_callback();
			}
		}
		if(typeof(_m)=='undefined'){
			alert('投票成功！');
		}else{
			alert(_m);
		}
	}
	
})()