/**
 * commonspot.mycs: methods for managing My CommonSpot
 */
commonspot.mycs = {};

/*
 * basic specs
 */
commonspot.mycs.BASE_MODE = 'mycs'; // base mode that's us

commonspot.mycs.common = {};

/*
 * adjusts anything in mycs that needs regular updates
 */
commonspot.mycs.common.uiWatcher = function()
{
	// TODO: build this?
};


commonspot.mycs.settingsLoader = {};
commonspot.mycs.settingsLoader.onDataChanged = function(dataset)
{
	if(dataset.getCurrentRow().baseMode != commonspot.mycs.BASE_MODE)
		return;

	var loaderURL = commonspot.clientUI.state.location.getLoaderURL('subsiteurl');
	var cmdArgs = {userSelector: 'Current', includeHidden: 0};
	var cmdOptions = {datasetRoot: commonspot.data.mycs};
	var cmdCollection = commonspot.ajax.commandEngine.commandCollectionFactory.getInstance(loaderURL);
	cmdCollection.add('DashboardSection', 'getList', cmdArgs, cmdOptions);
	cmdCollection.send();

	// Start Dashboard Right Panel Loading from My Fevorite Shortcuts
	commonspot.data.issueMyShortcutsGetCommand(true); // start chaining to do saved searches and reminders too
};

commonspot.data.uiState.dsMode.addObserver(commonspot.mycs.settingsLoader);


// activity workflow
commonspot.mycs.activityWorkflow = {};
commonspot.mycs.activityWorkflow.sectionDefs = {};

commonspot.mycs.activityWorkflow.init = function()
{
	if(commonspot.mycs.activityWorkflow.init.done)
		return;
	commonspot.mycs.activityWorkflow.init.done = true;
	
	var i, sectionID, sectionDataset;
	var sectionDefs = commonspot.data.mycs.DashboardSection_getList.getData();
	
	this.sections = {};
	for(i = 0; i < sectionDefs.length; i++)
	{
		var sectionType = sectionDefs[i].sectiontype;

		// if custom section, init as required
		if(sectionType != 'Standard')
			commonspot.mycs.activityWorkflow.dataLoader.custom.init(sectionDefs[i]);
		
		sectionID = sectionDefs[i].method;
		this.sections[sectionID] = {};
		this.sections[sectionID].cmdMethod = sectionID;
		
		this.sections[sectionID].expandManager = new this.ExpandManagerClass(sectionID);
		if(sectionType == 'Standard')
			sectionDataset = commonspot.data.mycs['ActivityWorkflow_' + sectionID];
		this.sections[sectionID].moreLessManager = this.moreLessManager.getInstance(sectionType, sectionID, sectionDataset);
	}

	commonspot.mycs.activityWorkflow.dragDrop.init();
};


commonspot.mycs.activityWorkflow.getSectionDef = function(sectionID)
{
	var sectionDef = this.sectionDefs.byMethod[sectionID];
	if(sectionDef)
		return sectionDef;
	else
		alert('[activityWorkflow.getSectionDef] SectionID not recognized: ' + sectionID);
}

commonspot.mycs.activityWorkflow.dataLoader = {};

commonspot.mycs.activityWorkflow.dataLoader.onDataChanged = function()
{
	commonspot.mycs.activityWorkflow.init();
	this.loadAllSections();
};
commonspot.data.mycs.DashboardSection_getList.addObserver(commonspot.mycs.activityWorkflow.dataLoader);

commonspot.mycs.activityWorkflow.dataLoader.loadAllSections = function()
{
	commonspot.mycs.activityWorkflow.sectionDefs = this.getSectionDefs();
	this.applySectionDisplayPrefs();
	
	// show section table for each visible section, so its loading indicator shows
	for(var method in commonspot.mycs.activityWorkflow.sectionDefs.byMethod)
		$(method).setStyle({display: ''});
	
	// get data for first section, telling it to load all, which will cascade to the rest
	var sectionDef = commonspot.mycs.activityWorkflow.sectionDefs.byPosition[0];
	if(sectionDef)
		this.loadSection(sectionDef, true);
};

commonspot.mycs.activityWorkflow.dataLoader.loadSection = function(sectionDef, getAllSections)
{
	if(sectionDef.sectiontype == 'Standard')
		this.standard.getSectionData(sectionDef, getAllSections);
	else
		this.custom.getContent(sectionDef, getAllSections);
};

commonspot.mycs.activityWorkflow.dataLoader.onSectionLoaded = function(sectionID, requestOptions)
{	
	$(sectionID + '_header_loading').setStyle({display: 'none'});

	var sectionDef = commonspot.mycs.activityWorkflow.getSectionDef(sectionID);
	if(requestOptions.getAllSections && sectionDef)
	{
		// assume getAllSections is initial dlg setup or major reload, so apply user's expand prefs
		var expand = !!sectionDef.expand;
		if(expand)
			$(sectionID + '_data').setStyle({display: 'block'});
		commonspot.mycs.activityWorkflow.sections[sectionID].expandManager.setExpand(expand);
		
		// if there's a next section, get its data or custom content too
		var nextMethodPos = commonspot.mycs.activityWorkflow.sectionDefs.byMethod[sectionID].ds_RowID + 1;
		sectionDef = commonspot.mycs.activityWorkflow.sectionDefs.byPosition[nextMethodPos];
		if(sectionDef)
			this.loadSection(sectionDef, true);
	}
};

commonspot.mycs.activityWorkflow.dataLoader.getSectionDefs = function()
{
	var sectionDefs = {};

	var sectionDefsDataset = commonspot.data.mycs.DashboardSection_getList;
	sectionDefs.byPosition = sectionDefsDataset.getData();

	// make obj from prefs, keyed by method name, or generated id for custom sections; make it easy to get methods user needs, w their settings
	sectionDefs.byMethod = commonspot.util.objectArrayToObject(sectionDefs.byPosition, 'method');
	return sectionDefs;
};

commonspot.mycs.activityWorkflow.dataLoader.applySectionDisplayPrefs = function()
{
	var sectionDomNode, expandManager, i;

	// get references to section parent container and container for sections that aren't shown
	var sectionsContainer = $('notificationsandactivity');
	var hiddenSectionsContainer = $('notificationsandactivity_hidden');

	// get children of section parent; these are potential sections, some of which may be hidden
	var sections = $('notificationsandactivity').childElements();

	// get reference to user prefs data
	var prefs = commonspot.mycs.activityWorkflow.sectionDefs;

	// loop over sections, move from parent to hidden container
	for(i = 0; i < sections.length; i++)
	{
		sectionDomNode = sections[i];
		try // ignore move failure if not there (already hidden)
		{
			sectionsContainer.removeChild(sectionDomNode);
			hiddenSectionsContainer.appendChild(sectionDomNode);
		}
		catch(e){}

		if(prefs.byMethod[sectionDomNode.id]) // if section exists in prefs, ie, is displayed at all
		{
			expandManager = commonspot.mycs.activityWorkflow.sections[sectionDomNode.id].expandManager;
			expandManager.setExpand(prefs.byMethod[sectionDomNode.id].expand);
		}
	}

	// loop over user's prefs, adding shown sections back into parent, in prefs order
	for(i = 0; i < prefs.byPosition.length; i++)
	{
		sectionDomNode = $(prefs.byPosition[i].method);
		hiddenSectionsContainer.removeChild(sectionDomNode);
		sectionsContainer.appendChild(sectionDomNode);
	}
};


commonspot.mycs.activityWorkflow.dataLoader.standard = {};

commonspot.mycs.activityWorkflow.dataLoader.standard.getSectionData = function(sectionDef, getAllSections)
{
	var method = sectionDef.method;
	$(method + '_header_loading').setStyle({display: 'inline'});

	var loaderURL = commonspot.clientUI.state.location.getLoaderURL('subsiteurl');
	var collectionOptions = {onCompleteCallback: this.getSectionDataOnComplete, getAllSections: getAllSections};

	var cmdCollection = commonspot.ajax.commandEngine.commandCollectionFactory.getInstance(loaderURL, collectionOptions);
	var cmdArgs = {limit: -1};
	var cmdOptions = {datasetRoot: commonspot.data.mycs};
	cmdCollection.add('ActivityWorkflow', method, cmdArgs, cmdOptions);
	cmdCollection.send();
};

commonspot.mycs.activityWorkflow.dataLoader.standard.getSectionDataOnComplete = function()
{
	var sectionID = this.commands[0].method; // assumes collection is just one getSectionData cmd
	commonspot.mycs.activityWorkflow.dataLoader.onSectionLoaded(sectionID, this.options);
};


commonspot.mycs.activityWorkflow.dataLoader.custom = {};

commonspot.mycs.activityWorkflow.dataLoader.custom.init = function(sectionDef)
{
	// populate method w calc'd ID; these have no method, and we key off that a lot
	sectionDef.method = 'custom_' + sectionDef.id;
	
	// build ui state dataset(s); expand/contract only as of now
	commonspot.data.uiState.activityWorkflowSectionInit(sectionDef.method);
	
	// build container for custom html when it comes back
	var html = document.getElementById('activityWorkflowSectionTemplate').innerHTML;
	html = commonspot.util.replaceTokens(html, sectionDef);
	$('notificationsandactivity').insert({bottom: html});
};

commonspot.mycs.activityWorkflow.dataLoader.custom.getContent = function(sectionDef, getAllSections)
{
	var params = (sectionDef.customizationfieldtype.toLowerCase() != 'none')
						? {customizationFieldValue: sectionDef.customizationfieldvalue}
						: {};
	new Ajax.Request
	(
		sectionDef.url,
		{
			parameters: params,
			getAllSections: getAllSections,
			sectionDef: sectionDef,
			onSuccess: commonspot.mycs.activityWorkflow.dataLoader.custom.getContentOnSuccess,
			onFailure: commonspot.mycs.activityWorkflow.dataLoader.custom.getContentOnError,
			onException: commonspot.mycs.activityWorkflow.dataLoader.custom.getContentOnError
		}
	);
};

commonspot.mycs.activityWorkflow.dataLoader.custom.getContentOnSuccess = function(xhr)
{
	var options = xhr.request.options;
	var sectionDef =  options.sectionDef;
	var sectionID = sectionDef.method;
	//$(sectionID + '_data').insert({top: xhr.responseText});

	// this little bit of insanity is so IE honors stylesheets in the inserted html; a <br> tag before them does it, go figure
	var responseHTML = (BrowserCheck().ie) ? xhr.responseText.replace('<style', '<br style="display:none" /><style') : xhr.responseText;
	$(sectionID + '_data').insert({top: responseHTML});

	commonspot.mycs.activityWorkflow.dataLoader.onSectionLoaded(sectionID, options);
	commonspot.mycs.activityWorkflow.sections[sectionID].moreLessManager.onPostUpdate();
};

commonspot.mycs.activityWorkflow.dataLoader.custom.getContentOnError = function(xhr, exception)
{
	if(!(xhr && xhr.request && xhr.request.options && xhr.request.options.sectionDef))
		return;
	var options = xhr.request.options;
	var sectionDef = options.sectionDef;
	var sectionID = sectionDef.method;
	var sectionTitle = sectionDef.title;
	var contentDiv = $(sectionDef.method + '_data');
	if(contentDiv)
		contentDiv.insert({top: 'Error retrieving custom content.'});
	commonspot.mycs.activityWorkflow.dataLoader.onSectionLoaded(sectionID, options);
};


commonspot.mycs.activityWorkflow.dragDrop = {};

commonspot.mycs.activityWorkflow.dragDrop.init = function()
{
	Sortable.create
	(
		'notificationsandactivity',
		{
			dropOnEmpty: true,
			tag: 'table',
			format: /(.+)/, // use whole element id for serialization
			handle: 'headerLeft',
			onUpdate: commonspot.mycs.activityWorkflow.dragDrop.onDrop
		}
	);
};
 
commonspot.mycs.activityWorkflow.dragDrop.onDrop = function()
{
	// get sorted array of section "names", which are IDs of dom elements
	// translate to numeric IDs associated with user prefs on server side, make list out of them
	var sectionIDList = Sortable
			.sequence('notificationsandactivity')
			.map
			(
				function(item, index)
				{
					return this[item].id;
				},
				commonspot.mycs.activityWorkflow.sectionDefs.byMethod // this arg is map method context, appears as 'this' inside map call
			)
			.join(',');
				
	// save as a user pref
	commonspotNonDashboard.util.displayMessageOverlay('notificationsandactivity', 'overlayDivStyle', 'Please Wait...');
	var loaderURL = commonspot.clientUI.state.location.getLoaderURL('subsiteurl');
	var collectionOptions = {closeOnSuccess: 0, onCompleteCallback: commonspot.mycs.activityWorkflow.dragDrop.onCompleteCallback_SaveSectionOrder};
	var cmds = commonspot.ajax.commandEngine.commandCollectionFactory.getInstance(loaderURL, collectionOptions); 	
	cmds.add('DashboardSection', 'saveOrder', {idList: sectionIDList}, {commandResponseHandler: false});  	
	cmds.send();
};

commonspot.mycs.activityWorkflow.dragDrop.onCompleteCallback_SaveSectionOrder = function()
{
	commonspotNonDashboard.util.hideMessageOverlay('notificationsandactivity');
};


/**
 * base class that manages the expand/contract state of an activity-workflow section
 * @Dependencies: manages html regions w the following features:
 * 	id of section is <cmdMethod>, also name of server-side method
 * 	object to use as expand/collapse link has class expand_collapse_link
 * 	object to use as down/right arrow img has class expand_collapse_img
 * @param cmdMethod (string): server method that generates data for this section, used as html id etc
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass = function(cmdMethod)
{
	this.cmdMethod = cmdMethod;
	this.sectionID = cmdMethod + '_data';
	this.linkClass = 'expandCollapseSpan';
	this.imageClass = 'expand_collapse_img';
	this.dataset = commonspot.data.uiState.mycs.activityWorkflow[cmdMethod];
	this.dataset.addObserver(this);

	this.attachEvents();
};

/**
 * attaches any events this mgr uses
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.attachEvents = function()
{
	var expandLink = commonspot.util.dom.getChildrenByClassName(this.cmdMethod, this.linkClass);
	expandLink.onclick = this.toggleExpand.bind(this);
};

/**
 * sets expand/contract state
 * @param expand (boolean): true to expand section, false to contract it
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.setExpand = function(expand)
{
	this.dataset.update({expand: expand});
};

/**
 * toggles between expanded and contracted states
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.toggleExpand = function()
{
	this.setExpand(!this.dataset.getCurrentRow().expand);
};

/**
 * dataset observer
 * NEEDSWORK: stop using a dataset, kill this, or change to generic notifier
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.onDataChanged = function()
{
	this.renderExpandCollapse();
};

/**
 * renders the section and any indicators as expanded or contracted
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.renderExpandCollapse = function()
{
	this.renderExpandCollapseImage();
	this.renderExpandCollapseSection();
};

/**
 * renders the indicator image showing whether we're expanded or contracted
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.renderExpandCollapseImage = function()
{
	var expand = this.dataset.getCurrentRow().expand;
	var arrowDir = expand ? 'down' : 'right';
	var imgSrc = '/commonspot/dashboard/images/controls/arrow_' + arrowDir + '_white.gif';
	var imgObj = commonspot.util.dom.getChildrenByClassName(this.cmdMethod, this.imageClass);
	imgObj.src = imgSrc;
};

/**
 * renders the actual section itself as expanded or contracted
 */
commonspot.mycs.activityWorkflow.ExpandManagerClass.prototype.renderExpandCollapseSection = function()
{
	var expand = (this.dataset.getCurrentRow().expand == 1);
	var effectOptions = {duration: 0.3};
	if(expand)
		Effect.BlindDown(this.sectionID, effectOptions);
	else
		Effect.BlindUp(this.sectionID, effectOptions);
};


/**
 * class that manages the Show More/Show Less links for an activity-workflow section
 * they come in two variants, for standard and custom sections (moreLessManager.Standard and .Custom)
 *    both extend moreLessManager.Base
 *    get the appropriate one by calling moreLessManager.getInstance()
 * @param sectionID (string): name of ActivityWorkflow method that gets data for this section
 * @depends: manages html regions w the following features:
 * 	id of section is <sectionID>, name of server-side method for factory spry-based sections
 * 	id of region bound to dataset or container cusotm content is <sectionID>_data
 * 	dataset it's bound to is commonspot.data.mycs.ActivityWorkflow_<sectionID>
 * 	region has two containers, w classes of:
 * 		data_less: holds data visible when Show Less is in effect
 * 			should come before/above next container
 * 		data_more: holds data visible when Show More is in effect; html has "display: none"
 * 			the spry:repeat region that spry populates should be inside here
 * 			this manager moves the initially visible rows to the data_less container
 * 	container for more/less link has class more_less_link
 * 		this manager maintains the visibility, text, and link action of the container's contents
 */
commonspot.mycs.activityWorkflow.moreLessManager = {};

commonspot.mycs.activityWorkflow.moreLessManager.getInstance = function(sectionType, sectionID, sectionDataset)
{
	if(sectionType == 'Standard')
		return new this.Standard(sectionID, sectionDataset);
	else
		return new this.Custom(sectionID);
};

commonspot.mycs.activityWorkflow.moreLessManager.Base = function()
{
	this.sectionID = null;
	this.regionID = null;
	this.isCustom = null;
	// can't set this until we have section definition; done by onPostUpdate if it's still undefined
	//this.isActive = true;

	this.moreDataClass = 'data_more';
	this.lessDataClass = 'data_less';
	this.moreLinkClass = 'more_less_link';
	this.moreOnServerClass = 'more_on_server';

	this.rowCount = 0;
	this.moreRowsCount = 0;
	this.lessRowsCount = 0;
	this.moreOnServer = false;

	this.showMore = false;
};

commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.init = function(sectionID, isCustom)
{
	this.sectionID = sectionID;
	this.regionID = sectionID + '_data';
	this.isCustom = isCustom;
};

/**
 * spry region observer, called after region this manages is updated
 * also called by custom sections after their content has been retrieved
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.onPostUpdate = function() // spry sections pass (notifier, data)
{
	if(typeof this.active === 'undefined')
	{
		if(this.isCustom)
		{
			var sectionDef = commonspot.mycs.activityWorkflow.getSectionDef(this.sectionID);
			this.isActive = sectionDef.useslimit;
		}
		else
			this.isActive = true;
	}
	if(!this.isActive)
		return;

	this.checkRowCount();
	this.moveInitiallyVisibleRows();
	if(this.showMore)
		commonspot.util.dom.getChildrenByClassName(this.sectionID, this.moreDataClass).show(); // when spry renders region, more container goes back to hidden
	this.renderMoreLessLink();
};

/**
 * sets show more/show less
 * @param showMore (boolean): true shows additional rows, false hides them
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.setShowMore = function(showMore)
{
	this.showMore = showMore;
	this.renderMoreLessRows();
	this.renderMoreLessLink();
};

/**
 * toggles between show more and show less
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.toggleShowMore = function()
{
	this.setShowMore(!this.showMore);
};

/**
 * shows/hides the More rows, depending on the state stored in this object
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.renderMoreLessRows = function()
{
	var effectOptions = {duration: 0.3};
	var moreContainer = commonspot.util.dom.getChildrenByClassName(this.sectionID, this.moreDataClass);
	if(this.showMore)
		Effect.BlindDown(moreContainer, effectOptions);
	else
		Effect.BlindUp(moreContainer, effectOptions);
};

/**
 * moves the number of rows we want to show initially into a container that's initially visible
 * the region spry populates is initially hidden; user can show or hide it w show more/show less
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.moveInitiallyVisibleRows = function()
{
	var i, item;
	var lessContainer = commonspot.util.dom.getChildrenByClassName(this.sectionID, this.lessDataClass);
	var moreContainer = commonspot.util.dom.getChildrenByClassName(this.sectionID, this.moreDataClass);
	commonspot.util.dom.removeAllChildren(lessContainer);
	if(moreContainer.length === 0)
		return;
	var itemsToMove = $(moreContainer).childElements();
	var itemsToMoveCount = Math.min(itemsToMove.length, this.lessRowsCount);
	for(i = 0; i < itemsToMoveCount; i++)
	{
		item = itemsToMove[i];
		moreContainer.removeChild(item);
		lessContainer.appendChild(item);
	}
};

/**
 * displays the show more/show less link and/or text
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.renderMoreLessLink = function()
{	
	var linkContainer = commonspot.util.dom.getChildrenByClassName(this.sectionID, this.moreLinkClass);
	
	linkContainer.blur();
	if(this.rowCount < 1)
		linkContainer.innerHTML = 'No pages found';	
	else if(this.lessRowsCount == this.rowCount)
		linkContainer.innerHTML = ''; 
	else if(this.moreOnServer == 1 && this.lessRowsCount >= this.rowCount)
	{	
		linkContainer.className = this.moreOnServerClass;
		linkContainer.innerHTML = '(more data is available than can be shown here)';
	}	
	else
	{
		var link = document.createElement('a');
		link.href = 'javascript:;';
		if(this.moreRowsCount < 0 || this.lessRowsCount == this.rowCount) 
			link.innerHTML = ''; 
		else	
			link.innerHTML = this.showMore ? 'show less' : this.moreRowsCount + ' more';
		link.onclick = this.toggleShowMore.bind(this);
		commonspot.util.dom.removeAllChildren(linkContainer);
		linkContainer.appendChild(link);
		if(this.moreOnServer)
		{
			var span = document.createElement('span');
			span.className = this.moreOnServerClass;
			if(this.moreRowsCount < 0)
				span.innerHTML = '';
			else if(this.moreOnServer)
				span.innerHTML = '<span style="cursor:default">(more data is available than can be shown here)</span>';
			linkContainer.appendChild(span);
		}
	}
};

/**
 * Updates internal state vars about the number of rows shown, hidden, etc.
 *
 * @sets this.rowCount (int): number of rows in dataset.
 * @sets this.moreOnServer (boolean): true when there's more data on server than we can show.
 * @sets this.lessRowsCount (int): rows displayed for show less.
 * @sets this.moreRowsCount (int): number of rows present but not displayed for show less.
 * @sets this.showMore (boolean): show more is on.
 * 	this method isn't the primary maintainer of this var
 * 	but if there aren't enough rows that any are hidden for show less, this sets it false
 * 	upshot is that if there aren't enough, then later there are, user has to show more to see them
 */
commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.checkRowCount = function()
{
	this.rowCount = this.getRowCount();

	// Decide if more data is available client side to show if requested.
	var sectionDef = commonspot.mycs.activityWorkflow.getSectionDef(this.sectionID);
	this.lessRowsCount = parseInt(sectionDef.limit);
	this.moreRowsCount = this.rowCount - this.lessRowsCount;
	if(this.moreRowsCount < 1)
		this.showMore = false;
};

commonspot.mycs.activityWorkflow.moreLessManager.Base.prototype.getRowCount = function()
{
	alert('[activityWorkflow.moreLessManager.Base] Unimplemented method: getRowCount');
};


// class that manages more-less behavior for factory spry-based sections
commonspot.mycs.activityWorkflow.moreLessManager.Standard = function(sectionID, displayedDataset)
{
	this.init(sectionID, false);
	this.displayedDataset = displayedDataset; // commonspot.data.mycs['ActivityWorkflow_' + sectionID];
	Spry.Data.Region.addObserver(this.regionID, this);
};
commonspot.mycs.activityWorkflow.moreLessManager.Standard.prototype = new commonspot.mycs.activityWorkflow.moreLessManager.Base();
commonspot.mycs.activityWorkflow.moreLessManager.Standard.prototype.constructor = commonspot.mycs.activityWorkflow.moreLessManager.Standard;

commonspot.mycs.activityWorkflow.moreLessManager.Standard.prototype.getRowCount = function()
{
	// track if more data than we can show here is present on server.
	this.moreOnServer = this.displayedDataset.responseStatus.limitexceeded;	
	return this.displayedDataset.getRowCount();
};


// class that manages more-less behavior for custom url-based sections
commonspot.mycs.activityWorkflow.moreLessManager.Custom = function(sectionID)
{
	this.init(sectionID, true);
};
commonspot.mycs.activityWorkflow.moreLessManager.Custom.prototype = new commonspot.mycs.activityWorkflow.moreLessManager.Base();
commonspot.mycs.activityWorkflow.moreLessManager.Custom.prototype.constructor = commonspot.mycs.activityWorkflow.moreLessManager.Custom;

commonspot.mycs.activityWorkflow.moreLessManager.Custom.prototype.getRowCount = function()
{
	var limitedSection = $(this.regionID).select('.data_more')[0];
	if(!limitedSection)
	{
		var sectionDef = commonspot.mycs.activityWorkflow.getSectionDef(this.sectionID);
		alert('Custom My CommonSpot section \'' + sectionDef.title + '\' is defined with usesLimit = ' +sectionDef.useslimit + ', but it has no section marked with the class \'data_more\'.');
		return 0;
	}
	return $(limitedSection).childElements().length
};

