FL_URL_MAASWEB   = 'http://www.maas360.com/';
FL_URL_PLATFORM  = 'https://portal.fiberlink.com/';
FL_URL_TRIALS    = 'http://links.maas360.com/trialGeneric';
FL_URL_BLOG      = 'http://blog.maas360.com/';
FL_URL_MAGAZINE  = 'http://blooming-mist-21.heroku.com/';
FL_URL_DEMO      = 'http://links.maas360.com/demoRequest';




function FL_GlobalHeaderManager()
{
	this.Preload = FL_GlobalHeaderManager_Preload;
	this.Init = FL_GlobalHeaderManager_Init;
	this.AdjustLayout = FL_GlobalHeaderManager_AdjustLayout;

	this.siteId = null;
	this.campaignId = null;

	this.bIsSSL = ('https:' == window.location.href.substr(0,6));
	this.currentProtocol = (this.bIsSSL)  ?  'https:'  :  'http:';
}

function FL_GlobalHeaderManager_Preload()
{
	if (typeof(window.FL_SITE_ID) != 'undefined')
	{
		this.siteId = window.FL_SITE_ID;
	}
//	else
//	{
//		var curLoc = window.location.href;
//		if (curLoc.indexOf('://blog.maas360.com') >= 0)
//			this.siteId = 'MAASBLOG';
//		else if (curLoc.indexOf('://www.maas360.com') >= 0  ||  curLoc.indexOf('://www.fiberlink.com') >= 0)
//			this.siteId = 'MAASWEB';
//	}

	if (null !== this.siteId)
	{
		//	add site-dependent CSS
		if ('MAASWEB' == this.siteId)
		{
			fl_addStyleSheet(this.currentProtocol+'//content.fiberlink.com/www/globalHeader/FL_GlobalHeader_OpenCms_prepend.css');
		}
		else if ('MAASBLOG' == this.siteId)
		{
			fl_addStyleSheet(this.currentProtocol+'//content.fiberlink.com/www/globalHeader/FL_GlobalHeader_WordPress_prepend.css');
		}
		else if ('TRIALS' == this.siteId)
		{
			fl_addStyleSheet(this.currentProtocol+'//content.fiberlink.com/www/globalHeader/FL_GlobalHeader_Trials_prepend.css');
		}
		fl_addClassToElement(document.body, this.siteId);
	}
	else
	{
		document.writeln('<!-- Unable to determine site ID.  No site-specific CSS was loaded. -->');
	}
}

function FL_GlobalHeaderManager_Init()
{
	var tmpThis = this;
	var link = null;

	fl_addClassToElement(document.documentElement, 'WithGlobalHeader');
	fl_addClassToElement(document.body, 'WithGlobalHeader');

	var tryElem = document.getElementById('GlobalHeader_Link_Try');
	var demoElem = document.getElementById('GlobalHeader_Link_Demo');

	if ('MAASWEB' == this.siteId)
	{
		if (-1 == tryElem.href.indexOf('A='))
			tryElem.href = fl_addUrlParam(tryElem.href, 'A', 'WS_globalHeader');
		if (-1 == demoElem.href.indexOf('A='))
			demoElem.href = fl_addUrlParam(demoElem.href, 'A', 'WS_globalHeader');
	}
	else if ('MAASBLOG' == this.siteId)
	{
		if (-1 == tryElem.href.indexOf('A='))
			tryElem.href = fl_addUrlParam(tryElem.href, 'A', 'BLOG_globalHeader');
		if (-1 == demoElem.href.indexOf('A='))
			demoElem.href = fl_addUrlParam(demoElem.href, 'A', 'BLOG_globalHeader');
	}
	// trials or healthcare - don't add, php sessions will take care of it

	var selectedTabElem = null;
	if ('MAASBLOG' == this.siteId)
		var tabElem = document.getElementById('GlobalHeader_Tab_Blog');
	else  // all other undefined sites - default to website tab
		var tabElem = document.getElementById('GlobalHeader_Tab_MaasWebsite');
	fl_addClassToElement(tabElem, 'GlobalHeader_TabWrapper_On');
}

function FL_GlobalHeaderManager_AdjustLayout()
{
	if (typeof(fl_isIE) != 'undefined'  &&  fl_isIE())
	{
		//	global header must be the width of the entire window, so we have to reverse the
		//	effects of adjustMargins().
		var ghElem = document.getElementById('FL_GlobalHeader');
		if (ghElem)
		{
			if (document.body  &&  document.body.clientWidth)  // preferred
				ghElem.style.width = document.body.clientWidth + 'px';
			else if (document.documentElement  &&  document.documentElement.offsetWidth)  // might be a bit wide with scrollbars, but earlier IEs will support
				ghElem.style.width = document.documentElement.offsetWidth + 'px';
		}
	}
}



function fl_compareHostname(urlA, urlB)
{
	var strHostA;
	var strHostB;

	if (typeof(urlA) == 'object'  &&  typeof(urlA.href) != 'undefined'  &&  typeof(urlA.hostname) != 'undefined')
		strHostA = urlA.hostname;
	else
		strHostA = fl_findHostname(urlA);

	if (typeof(urlB) == 'object'  &&  typeof(urlB.href) != 'undefined'  &&  typeof(urlB.hostname) != 'undefined')
		strHostB = urlB.hostname;
	else
		strHostB = fl_findHostname(urlB);

	if (typeof(strHostA) == 'string'  &&  typeof(strHostB) == 'string')
	{
		strHostA = strHostA.toLowerCase();
		strHostB = strHostB.toLowerCase();
	}
	return (strHostA == strHostB);
}

function fl_findHostname(url)
{
	var i;
	if ((i = url.indexOf('://')) >= 0)
	{
		url = url.substr(i+3);
		while('/' == url.charAt(0))
			url = url.substr(1);
	}
	if ((i = url.indexOf('/')) >= 0)
	{
		url = url.substr(0, i);
	}
	return url;
}


function fl_addUrlParam(existingUrl, key, value)
{
	var q = (-1 == existingUrl.indexOf('?'))  ?  '?'  :  '&';
	return existingUrl + q + encodeURIComponent(key) + '=' + encodeURIComponent(value);
}


function fl_addStyleSheet(url)
{
	document.writeln('<link rel="stylesheet" type="text/css" href="'+url+'" />');
}

