/*
Rewind() determines where to relocate the page.
If in multi-record mode then back to BU.
If in single-record mode, then back to multi-record block.
*/
function Rewind(mode)
{
	if (mode == "fullrecord")
	{
		back_to_block();		
	}
	else if (mode == "remember")
	{
	//	alert("remember mode");
		var rewindUrl = FindBU();
		
		if (rewindUrl != null)
		{		
			if (rewindUrl.indexOf("?") != -1)	
			{
				rewindUrl = rewindUrl.substr(0, rewindUrl.indexOf("?")); //snip query string from end	
			}
			window.location.href = rewindUrl + "?remember=true"; 
			
			
		}
		else
		{
			alert("Base URL cannot be found");
		}
	}
	else if (mode == null)
	{
		//alert("forget mode");
		 var rewindUrl = FindBU();
		
		 
		if (rewindUrl != null)
		{		
			if (rewindUrl.indexOf("?") != -1)	
			{
				rewindUrl = rewindUrl.substr(0, rewindUrl.indexOf("?")); //snip query string from end	
			}
			window.location.href = rewindUrl;
		
		}
		else
		{
			alert("Base URL cannot be found");
		}
	}
}

/*
FindBU() is a helper function which parses dbtw_params for the BU name/value pair, 
stripping out the resulting URL.
*/

function FindBU()
{
	var params = window.dbtw_params;
	params = unescape(params);
	var buMatch = params.match(/BU=(.*?)\x26/);
	var baseUrl = buMatch[0];
	if (baseUrl != null)
	{
		baseUrl = baseUrl.substr(3, baseUrl.length); //remove BU=
		if (baseUrl.indexOf("&") == (baseUrl.length-1))
		{
			baseUrl = baseUrl.substr(0, baseUrl.length-1); //snip '&' char from end
			
		}	
	}
	
	
	return baseUrl;
}