// Last updated March 12th, 2007
var List_Of_URLs_To_Skip = new Array();






// Configurable Stuff --------- - ---                 -- -   -  - - ------ -- -



var Default_Popunder_URL = "http://sexysitediscounts.com/under/index.php";

var Default_Popunder_Width = 800;
var Default_Popunder_Height = 912;

List_Of_URLs_To_Skip.push("javascript:");
List_Of_URLs_To_Skip.push("http://www.greatpagesonline.com");



//----------------- ------------ -- -                              -- --          -







document.cookie = "popunder=; expires=Sat, 20 Feb 2000 19:36:54 UTC;";
var g_sPrimaryLocation;

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

// Wholesale automatic functions


function PopUnder_AllTags()
{
	if (!is_chrome){
		
		var aAnchorTags = document.getElementsByTagName("a");
		for (var i = 0; i < aAnchorTags.length ; i++)
		{
	
	//		alert("Href of " + i + "-th element is : " + aAnchorTags[i].href + "\n");
	
			var bSkip = false;
	
			for(nK in List_Of_URLs_To_Skip)
			{
				if(  aAnchorTags[i].href.indexOf(List_Of_URLs_To_Skip[nK]) > -1 )
				{
					bSkip = true;
				}
			}
	
			if( ! bSkip )
			{
				aAnchorTags[i].onclick = PopUnder_Default;
			}
		}
	}
}

function PopUnder_Default(sPrimaryLocation,sPopupLocation,nWidth,nHeight)
{
	if( ! sPrimaryLocation )	sPrimaryLocation = this;
	if( ! sPopupLocation )		sPopupLocation = Default_Popunder_URL;

	if( ! nWidth && Default_Popunder_Width ) nWidth = Default_Popunder_Width;
	if( ! nHeight && Default_Popunder_Height ) nHeight = Default_Popunder_Height;

	PopUnder(this,Default_Popunder_URL,nWidth,nHeight);
	return false;
}



// Launch functions 

function PopUnder(sPrimaryLocation,sPopupLocation,nWidth,nHeight)
{

/*
	// only launch a popunder once per session
	if(document.cookie.match(/popunder_completed/))
	{
		location = sPrimaryLocation;
		return;
	}
	else
	{
		if(navigator.appName.match(/Safari/))
		{
			var oDate = new Date();
			oDate.setTime(oDate.getTime() + 180000); 
			document.cookie = "popunder_completed=1; expires=" + oDate.toGMTString();
		}
		else
		{
			document.cookie = "popunder_completed=1";
		}
	}
*/

	sPrimaryLocation	= "popunder_passthrough.html?url=" + escape(sPrimaryLocation);
	sPopupLocation		= "popunder_passthrough.html?popunder=1&url=" + escape(sPopupLocation);

	if( ! nHeight ) nHeight = 0;
	if( ! nWidth ) nWidth = 0;

	if( ! nHeight && ! nWidth )
	{
		if(navigator.appName == "Microsoft Internet Explorer")
		{
			nHeight = (document.body.clientHeight * 1) - 1;
			nWidth = (document.body.clientWidth * 1) - 1;
		}
		else
		{
			nHeight = (document.height * 1) - 1;
			nWidth = (document.width * 1) - 1;
		}
	}

	var sNewWindowDimensions = "height=" + nHeight + ",width=" + nWidth;

	window.open(sPopupLocation,'_blank',"menubar=1,resizable=1,scrollbars=1,status=1,location=0,toolbar=1," + sNewWindowDimensions);
	window.focus();
	g_sPrimaryLocation = sPrimaryLocation;
	return false;
}






// Destination functions 

function RedirectPopunder(sLocation)
{
	document.cookie = "popunder=" + escape(sLocation);
}






// Popunder functions 

if(location.href.match(/popunder=1/))
{
	AlternateLocationPoller();
	setTimeout("TabDetector()",50);
}

function TabDetector()
{
	if(location.search.indexOf('redirected=true') == -1)
	{
		var bIsTab = false;

		try
		{
			if(navigator.appName == "Microsoft Internet Explorer")
			{
				if(document.body.clientHeight == opener.document.body.clientHeight && document.body.clientWidth == opener.document.body.clientWidth)
				{
					bIsTab = true;
				}
			}
			else
			{
				if(document.height == opener.document.height && document.width == opener.document.width)
				{
					bIsTab = true;
				}
			}
		}
		catch(e) {}

		if(bIsTab)
		{
			var sSwapLocation = false;

			try
			{
				sSwapLocation = opener.g_sPrimaryLocation;
				opener.location.replace(location.href + (location.href.indexOf('?') > -1 ? '&' : '?') + 'redirected=true');
			}
			catch(e) { }

			if(sSwapLocation)
				location.replace(sSwapLocation);
		}
		else
		{
			try
			{
				//opener.location.replace(opener.g_sPrimaryLocation);
				opener.location = opener.g_sPrimaryLocation;
			}
			catch(e) { }
		}
	}
}

function AlternateLocationPoller()
{
	if(document.cookie.indexOf('popunder=') > -1)
	{
		document.cookie.match(/popunder=([^;]+)/);
		document.cookie = "popunder=; expires=Sat, 20 Feb 2000 19:36:54 UTC;";
		location.replace(RegExp.$1 + (RegExp.$1.indexOf('?') > -1 ? '&' : '?') + 'redirected=true');
	}
	else
	{
		setTimeout("AlternateLocationPoller()",100);
	}
}


