var popupURL="../free-newsletter.asp";
var popupURL2="onunload/exitflourish.htm";
var popupMaximized=1;
var popupHeight=400;
var popupWidth=400;
var popupScrollbars="yes" 
var popupLocation="no"
var internalBaseURLs = new Array("http://www.flourishwellness.com","http://flourishwellness.com","https://www.flourishwellness.com","https://flourishwellness.com");
var catchExtendedUnloads=0;
var browserIsNetscape=(navigator.appName.indexOf("Microsoft")!=-1) ? false : true;
var unloadNoticed=0;

//---CODE FROM COOKIE JS
var expDays = 1; // number of days the cookie should last
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
//---END CODE

function doPopup()
{
	options = "scrollbars="+popupScrollbars+",location="+popupLocation;
	helpWindow = window.open(popupURL, "NavBar", options);
	helpWindow2 = window.open(popupURL2, "NavBar2", options);

	if (popupMaximized)
	{
		helpWindow.moveTo(0,0);
		helpWindow.resizeTo(screen.availWidth, screen.availHeight);

		helpWindow2.moveTo(0,0);
		helpWindow2.resizeTo(screen.availWidth, screen.availHeight);
	}
	else
	{
		helpWindow.resizeTo(popupHeight, popupWidth);

		helpWindow2.resizeTo(popupHeight, popupWidth);
	}

	unloadNoticed=1;
}

function doInitPopupEvents()
{
	if (browserIsNetscape)
	{
		window.captureEvents(Event.CLICK);
		window.onclick=checklink;
	}
	else
	{
		document.onclick=checklink;
	}
}

function isLinkExternal(url)
{
	var s = String(url);
	var foundInternals=0;

	for ( var i = 0; i < internalBaseURLs.length; i++ )
	{
		if (s.search(internalBaseURLs[i]) == 0)
		{
			foundInternals++;
		}
	}
	
	if (s.indexOf("addfav") > 0)
	{
		foundInternals++;
	}

	return !foundInternals;
}

function checklink(e)
{
	if (!browserIsNetscape)
	{
		targetURL = window.event.srcElement.href;
	}
	else
	{
		targetURL = e.target.href;
	}

	if (targetURL && isLinkExternal(targetURL))
	{
		doPopupOnce();
	}
	else
	{
		unloadNoticed=1;
	}
}

function doPopupOnce()
{
	var count = GetCookie('count');

	if (count == null) 
	{
		count = 1;
		SetCookie('count', count, exp);
		doPopup();
	}
	else
	{
		count++;
		SetCookie('count', count, exp);
	}
}

function doCheckUnloading()
{
	//var evt = window.event;
	//alert(evt.type);
	//if (evt.srcElement != null)
	//{
	//	alert("*"+window.closed);
	//}
	//alert(document.URL);
	if (!unloadNoticed && catchExtendedUnloads)
	{
			doPopupOnce();
	}
}


//---- CODE FROM COOKIE JS
function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen)
	{
		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)
		{
			return getCookieVal(j);
		}

		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie(name, value)
{  
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) +  ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function DeleteCookie(name)
{  
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);

	var cval = GetCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	{
		endstr = document.cookie.length;
	}

	return unescape(document.cookie.substring(offset, endstr));
}

function amt()
{
	var count = GetCookie('count');

	if(count == null)
	{
		SetCookie('count','1');
		return 1;
	}
	else
	{
		var newcount = parseInt(count) + 1;
		DeleteCookie('count');
		SetCookie('count',newcount,exp);
		return count;
	}
}
//---END CODE