﻿Event.observe( window, "load",  onPageLoad);

function onPageLoad() 
{
	GetActMovieForecastList( function( returnObj ) {
		if ( returnObj && typeof( returnObj.value ) != "undefined" && returnObj.value != null) {
			var forecast = null;
			var element = null;
			var forecastList =	returnObj.value.List;
			for ( var i = 0, count = forecastList.length; i < count; i++ ) {
				forecast = forecastList[i];
				$( "p_" + forecast.ForecastID + "_0" ).innerHTML = forecast.BelievingCount;
				$( "p_" + forecast.ForecastID + "_1" ).innerHTML = forecast.UnbelievingCount;
			}
		}
	} );
	
	//添加投票图片按钮的监视
	var nodes = $$("img.pImage"); 
	for(var i=0; i < nodes.length; i++ ) {	 
	    var node = nodes[i];
	   	Event.observe( node, "click", function(){
	        var evt = GetEvent(); 
	        var eventSrcElement = Event.element( evt );
            var movieIdString = eventSrcElement.id;
            //Ajax begin
	        AddActViewCount( movieIdString, function( returnObj ) {
		        if ( returnObj && typeof( returnObj.value ) != "undefined") 
		        {
		            // returnObj.value：true/false
		            if (returnObj.value)
		            {   			        
			            var id = "p" + movieIdString.substring(1);
			            var element = $(id);
			            if (element != null) element.innerHTML = parseInt(element.innerHTML) + 1;
			        }
			        else alert("此IP已经投过票了。");
		        }
	        } );    // Ajax end                                                    
      	});         // Event.observe      	
	}
}

//获取专题活动对象的浏览数
function GetActMovieForecastList( clientCallBack ) {
	    return Mtime.Component.Ajax.callBack('Mtime.Community.Controls.CommunityPages.StatisticService', 'GetActMovieForecastList', [], clientCallBack, '/Utility/StatisticService.m?Ajax_CallBack=true');
}

//增加指定对象的浏览数
function AddActViewCount( relatedIdString, clientCallBack ) {
	return Mtime.Component.Ajax.callBack('Mtime.Community.Controls.CommunityPages.StatisticService', 'AddMovieForecastCount', [relatedIdString], clientCallBack, '/Utility/StatisticService.m?Ajax_CallBack=true');
}
