// version 1.3
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments<FONT color=#0000cc>

var SetParentTimerID;
var PopupUrl = 'http://www.atlantis.to/newsletter-popup.htm';
//PopupUrl = 'http://localhost/atlantis/newsletter-popup.htm';

function setCookie(document, name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function setPermanentCookie(document, name, value, path, domain, secure) {
	// create an instance of the Date object
	var now = new Date();
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(now);
	// cookie expires in one year (actually, 365 days)
	// 365 days in a year
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	setCookie(document, name, value, now, path, domain, secure);
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds<FONT color=#0000cc>
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"<FONT color=#0000cc>
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function SetTimer()
{
	setTimeout("self.close()",5000);
}

function DisableCloseMessage()
{
	//window.opener=self;
}

function ShowNewsletterLink()
{
	var WinTop;
	var WinLeft;
	var WinWidth = 700;
	var WinHeight = 500;
	var ThePopupUrl = 'http://www.atlantis.to/MONTHLY-MESSAGES.htm';

	WinTop = (window.screen.height / 2) - (WinHeight / 2);
	WinLeft = (window.screen.width / 2) - (WinWidth / 2);
	ReportWinodw = window.open(ThePopupUrl,'','top=' + WinTop + ',left=' + WinLeft + ',height=' + WinHeight + ',width=' + WinWidth + ',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	self.close();
}

function CloseForGood()
{
	//alert(opener.closed);
	setPermanentCookie(document,"HideNewsletter",1);
	self.close();
}

var exit=true;
var ShowPopupOnTop = false;
var TimerID;
function ShowNewsletterPopupOnExit()
{
	
	if (TimerID)
	{
		window.clearTimeout(TimerID);
	}

	if (exit)
	{
		ShowNewsletterPopup();
	}


	if (ShowPopupOnTop)
	{
		OpenNewsletterPopup();
		if (NewsletterPopup)
		{
			NewsletterPopup.focus();		
		}
	}
	ShowPopupOnTop = true;
}

var NewsletterPopup;
var PopupSaysIAlreadyExist = false;
function ShowNewsletterPopup()
{
	HideNewsletter = getCookie("HideNewsletter");
	if (!HideNewsletter)
	{
		NewsletterInSession = getCookie("NewsletterInSession");
		//NewsletterInSession = "";
		if ((!NewsletterInSession) && (PopupSaysIAlreadyExist == false))
		{
			setCookie(document, "NewsletterInSession",1);
			OpenNewsletterPopup();
			if (NewsletterPopup)
			{
				NewsletterPopup.blur();
			}
			window.focus();
		}
	}
}

var IE;

function IE_DocumentComplete(ie, url)
{
	IE.Document.parentWindow.opener = window;
}

function SetChildParent()
{
	try
	{
		IE.Document.parentWindow.opener = window;
		window.clearTimeout(SetParentTimerID);
	}
	catch (e)
	{
	}
}

function blockError(){return true;}
window.onerror = blockError;

CheckWindowOpen();

var windowspecs;
var windowname;

function OpenNewsletterPopup()
{
	var WinTop;
	var WinLeft;
	var WinWidth = 360;
	var WinHeight = 430;

	WinTop = (window.screen.height / 2) - (WinHeight / 2);
	WinLeft = (window.screen.width / 2) - (WinWidth / 2);
	windowspecs = 'top=' + WinTop + ',left=' + WinLeft + ',height=' + WinHeight + ',width=' + WinWidth + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';

NewsletterPopup = ActualOpenNewsletterPopup(windowspecs);
self.focus();
if(!window.NewsletterPopup){
bypass(PopupUrl,windowspecs);
} else {
if(window.close == window.fclose){
bypass(PopupUrl,windowspecs);
} else {
if(NewsletterPopup.close == NewsletterPopup.fclose){
bypass(PopupUrl,windowspecs);
} else {
NewsletterPopup.location.href = PopupUrl;
}
}
}
}

function DoOnError()
{
	alert('error');
}

var SetFocus = false;
var ParentWindow = false;
function CheckParentClosed()
{
	if (!SetFocus)
	{
		if (opener.closed)
		{
			SetFocus = true;
			window.focus();
		}
		else
		{
			URL = opener.location.href;
			if (URL.indexOf('atlantis.to') == -1)
			{
				SetFocus = true;
				window.focus();
			}
		}
	}
}

function GetRandomQuote()
{
	var URL;
	var StringToWrite;

	URL = ShowMessage(1);
	/*
	if (navigator.appName == 'Netscape') 
	{
		StringToWrite = "<ilayer src='" + URL + "' name='QuoteFrame' id='QuoteFrame' width='100%' height='100%'></ilayer>";
    }
	else 
	{
		StringToWrite = "<iframe src='" + URL + "' name='QuoteFrame' id='QuoteFrame' width='100%' height='100%'></iframe>";
    }
    document.write(StringToWrite);
    */
    document.frames.QuoteFrame.location.href = URL;
    //document.getElementById("QuoteFrame").src= URL
    //document.all.QuoteFrame.src= URL;
}

function UseLink()
{
	document.all("NewsletterSignUpLink").click();
}

function AttachUnload()
{
	if (window.opener)
	{
		return false;
	}

	if (navigator.appName == 'Microsoft Internet Explorer') 
	{
		//TimerID = setTimeout("ShowNewsletterPopupOnExit()",1100);
		ShowNewsletterPopupOnExit();
		//document.body.onunload = ShowNewsletterPopupOnExit;	
		//ShowNewsletterPopupOnExit();
		/*
		if (document.all("NewsletterSignUpLink"))
		{
			ShowNewsletterPopupOnExit();
			//document.body.onload = UseLink;
		}
		else
		{
			ShowNewsletterPopupOnExit();
		}
		*/
	}
	else
	{
		ShowNewsletterPopupOnExit();
	}
}

