﻿
//See: BondFinderContentLoader.cs (loads additional segments)
//See: SearchResultOverviewGridGadget.cs (loads first segment and calls InitScrollableContentLoader)

//========> LATE LOADING IS NOT SUPPORTED IN CMS MODE (see BondFinderContentLoader and SearchResultOverviewGridGadget) <===========


// JScript File
var scrollableContentLoadUrl = null;
var scrollableContentOffset = 1; //first dynamic page
var scrollableContentReloadEnabled = true;

function ScrollableContentLoad(placeholderName) {
	if(scrollableContentLoadUrl) {
		$.post(scrollableContentLoadUrl + "&page=" + (scrollableContentOffset++),
			function (data) {
				if(data != "" && data != "ENDOFDATA") 
				{
					var placeholder = $("." + placeholderName); //placeholder is an array 
					if(placeholder.length > 0 ) //placeholder in current html? (after a postback the placeholder will change and the old loading process will stop here))
					{
						placeholder.before(data);
						scrollableContentReloadEnabled = true;
						ScrollableContentLoad(placeholderName); //recursivly load data
					}					
				}
			}
		);
	}
}


//placeholderName must change every time this function is called!
function InitScrollableContentLoader(url, placeholderName) 
{
	//Reasons why placeholderName has to change when this function is called:
	//- user starts bond search  => This function is called the first  time and the first  loading process is started (background process)
	//- user changes the sorting => This function is called the second time and the second loading process is started (background process). The first one continues!!!
	//  => If process 1 and 2 have different placeholderName no data of process 1 will be rendered (because the html code doesn't contain the marker of the old placeholderName)
	//  => If process 1 and 2 have the same  placeholderName the data of process 1 will be rendered (with the initial sorting) within the data of process 2 (Error)


//========> LATE LOADING IS NOT SUPPORTED IN CMS MODE (see BondFinderContentLoader and SearchResultOverviewGridGadget) <===========


	scrollableContentLoadUrl = url;
	scrollableContentOffset = 1;
	
	//load all content
	if(scrollableContentReloadEnabled) //this check is not really required at the moment. But it will be required if we want to load the content when the page is scrolled the first time
	{
		ScrollableContentLoad(placeholderName);
	}
}
