//File for pages that may need to break out of the QB embedded browser

var g_objQB = null;
var g_objAuth = null;
var g_objPrefs = null;

//Tests whether the page is being shown in the QuickBooks embedded browser.
//Tries to instantiate an ActiveX control that is only available within QuickBooks.
function isInQuickBooksEmbeddedBrowser()
{
	try
	{
		// Cheap check.  If called from a QuickBooks dialog in the embedded
		// browser, the AXC will already be defined.
		if (g_objPrefs)
		{
			return true;
		}
	
		// NOTE: this will succeed when run in IE on a machine
		// that has QB installed, even if not in the embedded browser.
		var objQB = new ActiveXObject( "QuickBooks.CoLocator" );
		if (objQB)
		{
			// This throws an exception if not in QB embedded browser.
			var objPrefs = objQB.Create( "QBPrefs.Preferences" );
			if (objPrefs)
			{
				return true;
			}
		}
	}
	catch (e)
	{
		// Fail silently.  This means we aren't in the QB embedded browser,
		// or we are in another browser (Mozilla).
	}
	return false;
}


//Ask QuickBooks to open an external browser to the given url.
function openExternalBrowser(url)
{
	var src = "qbks2://qbw:browser?external=y&url=" + escape(url);
	window.location = src;
}


//Will open in an external window.  If the user is in quickbooks embedded
//browser, this means an external browser, otherwise it's just a new window.
function openExternalWindow(url)
{
	if (isInQuickBooksEmbeddedBrowser())
	{
		openExternalBrowser(url);
	}
	else
	{
		window.open(url)
	}
}
