﻿Event.observe( window, "load",  onPageLoad);

function onPageLoad() 
{
	var elements = $$( "div.goodRight" );
	var ids = [], index = 0;
	elements.each( function( element ) {
		if (element.id != null && element.id.length > 0) ids[index++] = element.id;
	} );
		
	if ( ids.length > 0 )
	{
	    var idString = ids.join( "|" );
		GetActObjSummaryList( idString, function( returnObj ) {
			if ( returnObj && typeof( returnObj.value ) != "undefined" && returnObj.value != null) {
				var list = returnObj.value.List;
				for ( var i = 0; i < list.length; i++ ) 
				{
					var actObj = list[i];
					var element = $("d_" + actObj.RelatedObjID);
					element.innerHTML = actObj.TotalCount;
				}
			}
		} );
	}
	
	//添加投票图片按钮的监视
	var nodes = $$( "img.goodImage" ); 
	for( var i=0, count = nodes.length; i < count; i++ ) {	 
	    var node = nodes[i];	    
	   	Event.observe( node, "click", function( ) {
	        var evt = GetEvent( ); 
	        var eventSrcElement = Event.element( evt );
            var movieIdString = eventSrcElement.id;
            //Ajax begin
	        AddActObjSummaryCount( movieIdString, function( returnObj ) {
		        if ( returnObj && typeof( returnObj.value ) != "undefined" ) 
		        {		           
		            // returnObj.value：true/false
		            if (returnObj.value)
		            {   			        
			            var id = "d" + movieIdString.substring(1);
			            var element = $(id);
			            if (element != null) element.innerHTML = parseInt(element.innerHTML) + 1;
			        }
			        else alert("此IP已经投过票了。");
		        }
	        } );    // Ajax end                                                    
      	});         // Event.observe
	}
}

//获取专题活动对象的浏览数
function GetActObjSummaryList( relatedIdString, clientCallBack ) {
	    return Mtime.Component.Ajax.callBack('Mtime.Community.Controls.CommunityPages.StatisticService', 'GetActObjSummaryList', [2, relatedIdString], clientCallBack, '/Utility/StatisticService.m?Ajax_CallBack=true');
}

//增加指定对象的浏览数
function AddActObjSummaryCount( relatedIdString, clientCallBack ) {
	return Mtime.Component.Ajax.callBack('Mtime.Community.Controls.CommunityPages.StatisticService', 'AddActObjSummaryCount', [2, relatedIdString], clientCallBack, '/Utility/StatisticService.m?Ajax_CallBack=true');
}
