//	topic.js 2007-11-30 usp
//
// Dependencies: global.js, cookies.js
//
//	2007-11-13 usp - recreated from scratch
// 2007-11-16 usp - onloadTopic( ) modified for floating layout
// 2007-12-05 usp - projectLink( ) modified for scriptlet action

function onloadTopic()
{ 
	// NOTE: It may be necessary to test if synchronizeTopic function is available at that time. This may 
	// not be the case if the frameset onload event handler runs lengthy.
	if ( window.parent.frames["toc"] && window.parent.frames["toc"].synchronizeTopic ) window.parent.frames["toc"].synchronizeTopic( document.location.href );
}

// called when the user clicks the reload frameset link or programmatically
// if the document did not find a parent frameset document.
//
function reloadFrameset()
{
	reload.href += "?topic=" + document.location.href;
}

// pops up a document in a new window
// all parameters are optional.
// 2007-09-16 usp changes
function popUp( evt, uri, w, h, x, y, sb, tb  )
{
	var srcElement = sourceElement( evt );
	if ( srcElement.tagName == "A" )
	{
		if ( ! uri )  uri = srcElement.href;
	}
	else if ( srcElement.tagName == "IMG" )
	{
		if ( ! uri )  uri = srcElement.src;
		if ( ! w ) w = srcElement.width + 16;
		if ( ! h ) h = srcElement.height + 10;
	}
	cancelEvent( evt );
	
	var features = "resizable=yes,scrollbars=" + (sb == null ? "yes" : sb) + ",toolbar="; 
	features = features + (tb == null ? "no" : tb); 
	if ( x != null ) features = features + ",left=" + x;
	if ( y != null ) features = features + ",top=" + y;
	if ( w != undefined ) features = features + ",width=" + w;
	if ( h != undefined ) features = features + ",height=" + h;
	window.open(uri,'', features);
}

// Searches for an anchor element and opens the URI in a new window
// 2007-09-16
function linkPopUp( evt, uri,w, h, x, y, sb, tb )
{
	if ( ! uri ) 
	{
		srcElement = sourceElement( evt );
		while ( srcElement.tagName != "A" ) 
		{
			srcElement = srcElement.parentNode;
			if ( srcElement == null ) return;
		}
		uri = srcElement.href;
	}
	popUp( evt, uri, w, h, x, y, sb, tb  );
}


// replaces the href of a link with the local url
//
function dynalink( evt, localUrl )
{
	if ( evt && evt.srcElement.tagName == "A" )
	{
		evt.srcElement.href = localUrl;		
	}
}

// Determines whether to link to local ms-help documentation, or search for online docs
// Online help is preferred and must occur in the href attribute. 
// Local help must appear in the local attribute.
//
function mshelp( evt )
{
	var anchor = sourceElement( evt );
	if ( anchor.tagName != "A" ) return;
	var localhelp = anchor.getAttribute( "local" );
	if ( localhelp == null || localhelp == "" ) return;
	// check if href is empty
	var documentPath = document.location.href.replace( new RegExp( "[^/]*$" ), "" );
	if ( anchor.href == "" || anchor.href == documentPath )  
	{
		// no href, look for local help url
		anchor.href = localhelp;
		return;
	}
	var useLocalHelp = getCookie( "mshelpUseLocal" )
	if ( useLocalHelp == 1 ) anchor.href = localhelp;
}

function projectLink( filename )
{
	// check source element and cookie
	var setting = getCookie( "InfoTutorialProjectPath" );
	if ( setting == null || setting == "" ) 
	{
		alert( "No project folder defined. Navigate to the site configuration page for setting." );
		return;
	}
	// append slash befor concatenating
	if ( setting.lastIndexOf( "/" ) + 1 != setting.length ) setting +="/";
	// compose path to project file
	document.activeElement.href=setting.concat( filename );
}

// Regular expresstion to analyzes the complete URL into path, filename, query and hash
// var matches = document.location.href.match( new RegExp( "(.*)/([^/?#]*)([?][^#]*|)(#.*|)$" ));

