/*
	Popup Windows for NUCYNTA.com
	
	This popup is designed to be CSS independent and requires nothing
	to be implemented other than linking this javascript file in the header
*/
var containerElement = null;
var shadeId = "bgShadeAxert";
var popupId = "pagePopupAxert";
var popupDivWidth = 350;
var firstRun = true;
var shadeOpacity = 99;
var shadingInterval = null;
this.setWindowEvent();

var exitTitleWording = "You are now leaving NUCYNTA.COM";
var exitPopupWording = "Clicking on the Continue button will take you to a Web site to which "+
							"this Privacy Policy does not apply. We encourage you to read the "+
							"Privacy Policy of every Web site you visit.";

function displayExitPopup(url)
{
	if(document.getElementsByTagName('html')[0])
	{
		document.getElementsByTagName('html')[0].style.overflowX = "hidden";
	}
	if(!document.getElementById(popupId))
		{
		shadeBackground();
		var screenWidth = document.documentElement.clientWidth ? document.documentElement.clientWidth : null;
		var screenHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : null;
		var popupDiv = document.createElement ? document.createElement('DIV') : null;
		if(popupDiv != null)
		{
			var popupTitle = document.createElement('P');
			var popupContent = document.createElement('P');
			if(popupTitle && popupContent)
			{
				popupTitle.style.padding = "0 0 0 0";
				popupTitle.style.margin = "0 0 0 0";
				popupTitle.style.color = "#c54273";
				popupContent.style.color = "#000000";
				popupTitle.appendChild(document.createTextNode(exitTitleWording));
				popupContent.appendChild(document.createTextNode(exitPopupWording));
				var continueButton = document.createElement('button');
				var cancelButton = document.createElement('button');
				if(continueButton && cancelButton)
				{
					continueButton.style.margin = "10px 10px 0 0";
					continueButton.appendChild(document.createTextNode('Continue'));
					continueButton.onclick = function(){hidePopup();window.open(url);}
					continueButton.style.border = "1px solid #000000";
					continueButton.style.color = "#000000";
					cancelButton.appendChild(document.createTextNode('Cancel'));
					cancelButton.onclick = function(){hidePopup();}
					cancelButton.style.border = "1px solid #000000";
					cancelButton.style.color = "#000000";
					popupDiv.appendChild(popupTitle);
					popupDiv.appendChild(popupContent);
					popupDiv.appendChild(continueButton);
					popupDiv.appendChild(cancelButton);
					popupDiv.id = popupId;
					popupDiv.style.textAlign = "left";
					popupDiv.style.width = popupDivWidth+"px";
					popupDiv.style.position = "absolute";
					var scrollLoc = (window.innerHeight ? window.innerHeight : (document.documentElement ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
					popupDiv.style.top = parseInt((parseInt(screenHeight) - 250)/2)+getScrollFromTop()+"px";
					popupDiv.style.left = parseInt((parseInt(screenWidth) - popupDivWidth)/2)+"px";
					popupDiv.style.backgroundColor = "#FFFFFF";
					popupDiv.style.border = "1px solid #000000";
					popupDiv.style.padding = "15px 15px 15px 15px";
					popupDiv.style.margin = "0 0 0 0";
					popupDiv.style.zIndex = "2001";
					popupDiv.style.clear = "both";
					popupDiv.style.color = "#000000";
					if(containerElement == null)
					{
						buildContainer();
					}
					if(containerElement != null)
					{
						containerElement.appendChild(popupDiv);
					}
				}
			}
		}
	}
};
function hidePopup()
{
	if(document.getElementById(popupId))
	{
		if(containerElement !=null)
		{
			containerElement.removeChild(document.getElementById(popupId));
		}
		if(document.getElementsByTagName('html')[0])
		{
			document.getElementsByTagName('html')[0].style.overflowX = "auto";
		}
	}
	if(document.getElementById(shadeId))
	{
		if(containerElement !=null)
		{
			containerElement.removeChild(document.getElementById(shadeId));
		}
	}
};
function buildContainer()
{
	containerElement = containerElement==null ? (document.getElementsByTagName("DIV")[0]) : containerElement;
};
function setWindowEvent()
{
	window.onscroll = function(){centerPopup();resetShadePosition();};
	window.onresize = function(){handleResize();};
	firstRun = false;
};
function centerPopup()
{
	if(document.getElementById(popupId))
	{
		var scrollHeightResize = document.documentElement.clientHeight ? document.documentElement.clientHeight : 0;
		var scrollWidthResize = document.documentElement.clientWidth ? document.documentElement.clientWidth : 0;
		document.getElementById(popupId).style.top = parseInt((parseInt(scrollHeightResize) - 250)/2)+getScrollFromTop()+"px";
		document.getElementById(popupId).style.left = parseInt((parseInt(scrollWidthResize) - popupDivWidth)/2)+"px";
	}
};
function handleResize()
{
	if(document.getElementById(shadeId))
	{
		document.getElementById(shadeId).style.width = document.documentElement.clientWidth ? document.documentElement.clientWidth+"px" : null;
		document.getElementById(shadeId).style.height = document.documentElement.clientHeight ? document.documentElement.clientHeight+"px" : null;
	}
	this.centerPopup();
	this.resetShadePosition();
};
function shadeBackground()
{
	var shade = document.createElement ? document.createElement('div') : null;
	var pageWidth = (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	var pageHeight = window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
	if(shade!=null && !document.getElementById(shadeId))
	{
		shade.style.width = pageWidth+"px";
		shade.style.height = pageHeight+"px";
		if(navigator.userAgent)
		{
			if(navigator.userAgent.toLowerCase().indexOf("msie") == -1)
			{
				shade.style.width = "100%";
			}
		}
		shade.style.position = "absolute";
		shade.style.left = "0px";
		shade.style.backgroundColor = "#000000";
		shade.id = shadeId;
		shade.style.zIndex = "2000";
		shade.style.visibility = "visible";
		shade.style.opacity = "0.50";
		shade.style.filter = "alpha(opacity=50)";
		shade.style.innerHTML = "&nsbp;";
		shade.style.padding = "0 0 0 0";
		shade.style.margin = "0 0 0 0";
		if(containerElement == null)
		{
			buildContainer();
		}
		if(containerElement != null)
		{
			containerElement.appendChild(shade);
		}
		this.resetShadePosition();
		this.startShadeFadeIn();
	}
};
function startShadeFadeIn()
{
	shadeOpacity = 50;
	shadingInterval = setInterval("fadeInBackground()", 10);
};
function fadeInBackground()
{
	if(document.getElementById(shadeId))
	{
		document.getElementById(shadeId).style.opacity = "0."+shadeOpacity;
		document.getElementById(shadeId).style.filter = "alpha(opacity="+shadeOpacity+")";
	}
	if(shadeOpacity >= 75)
	{
		shadeOpacity = 50;
		clearInterval(shadingInterval);
	}
	else
	{
		shadeOpacity+=5;
	}
};
function resetShadePosition()
{
	if(document.getElementById(shadeId))
	{
		document.getElementById(shadeId).style.top = this.getScrollFromTop()+"px";
		if(navigator.userAgent.toLowerCase().indexOf("msie") == -1)
		{
			document.getElementById(shadeId).style.left = this.getScrollFromLeft()+"px";
		}
		return true;
	}
	else
	{
		return false;
	}
};
function getScrollFromTop()
{
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if ( document.body && document.body.scrollTop)
	{
		scrollY = document.body.scrollTop;
	}
	else if ( window.pageYOffset )
	{
		scrollY = window.pageYOffset;
	}
	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}
	return parseInt(scrollY);
};
function getScrollFromLeft()
{
	var scrollX = 0;
	if ( document.documentElement && document.documentElement.scrollLeft )
	{
		scrollX = document.documentElement.scrollLeft;
	}
	else if ( document.body && document.body.scrollLeft)
	{
		scrollX = document.body.scrollLeft;
	}
	else if ( window.pageXOffset )
	{
		scrollX = window.pageXOffset;
	}
	else if ( window.scrollX )
	{
		scrollX = window.scrollX;
	}
	return parseInt(scrollX);
};
function unShadeBackground()
{
	if(containerElement == null)
	{
		return false;
	}
	else
	{
		if(document.getElementById(shadeId))
		{
			containerElement.removeChild(document.getElementById(shadeId));
		}
	}
	return true;
};