var urlBRUNSON_POP = 'http://www.thebossbuster.com/js/exitpop/BrunsonFiles.html'; 
var urlAFFILIATE_POP = 'http://www.thebossbuster.com/js/exitpop/Affiliate.html';
var urlTWITTER_POP = 'http://www.thebossbuster.com/js/exitpop/Twitter.html';
var url7DAY_POP = 'http://www.thebossbuster.com/js/exitpop/7day.html';
var urlCONT_POP = 'http://www.thebossbuster.com/js/exitpop/Cont.html';
var urlJUSTMC_POP = 'http://www.thebossbuster.com/js/exitpop/JustMCRevealed.html';
var urlARTICLE_POP = 'http://www.thebossbuster.com/js/exitpop/ArticleMarketing.html';
var urlMMFROMTRAFFIC_POP = 'http://www.thebossbuster.com/js/exitpop/MMFromTraffic.html';
var urlNOBONUS_POP = 'http://www.thebossbuster.com/js/exitpop/NoBonus.html';
var urlNEWTRAFFIC_POP = 'http://www.thebossbuster.com/js/exitpop/NewTraffic.html';

var urlBRUNSON = 'http://www.thebossbuster.com/BrunsonFiles'; 
var urlAFFILIATE = 'http://www.thebossbuster.com/AffiliateProfits';
var urlTWITTER = 'http://www.thebossbuster.com/TwitterTraffic';
var url7DAY = 'http://www.thebossbuster.com/SevenDay';
var urlCONT = 'http://www.thebossbuster.com/MassControlRevealed';
var urlARTICLE = 'http://www.thebossbuster.com/ArticleMarketing';
var urlMMFROMTRAFFIC = 'http://www.thebossbuster.com/MoneyFromTraffic';
var urlNOBONUS = 'http://www.thebossbuster.com/BigDiscount';
var urlNEWTRAFFIC = 'http://www.thebossbuster.com/NewWebTraffic';
var urlPARTNER = 'http://www.thebossbuster.com/Partnership';
var urlFINALTHANKS = '';

var MIN_TOP = 15; // pixels from window top to trigger the exit popup
var POPUP_URL; // page shown in the popup when moving the mouse on top
var EXIT_URL = "http://www.thebossbuster.com/BigDiscount"; //"http://www.yahoo.com"; // page shown when closing
var POPUP_DELAY = 4; // seconds of grace before showing the popup on mouse move on top
var POPUP_WIDTH = 550;
var POPUP_HEIGHT = 470;
var POPUP_OPACITY = 50; // % of opacity around the popup
var strHardCookie = '';

if( window.parent == window ) { // do not monitor exit pages
    window.onbeforeunload = function() {
	var exitPage = showExitPage();
	if( exitPage )
	{
		exitPage = exitPage.contentWindow;
		try {
			if( exitPage.allowExit )
			{
				exitPage.allowExit();
			}
		}
		catch( e ) {
			// ignore - cross domain
		}
	}
	
	var str = '';
	/*
	str+='_$$$$___$$$$$$___$$$$___$$$$$_____$$\r\n';
	str+='$$________$$____$$__$$__$$__$$____$$\r\n';
	str+='_$$$$_____$$____$$__$$__$$$$$_____$$\r\n';
	str+='____$$____$$____$$__$$__$$__________\r\n';
	str+='_$$$$_____$$_____$$$$___$$________$$\r\n\r\n';
	*/
	str+='============================================\r\n';
	str+='WAIT!    WAIT!    WAIT!    WAIT!    WAIT!    WAIT!    WAIT!\r\n';
	str+='============================================\r\n\r\n';
	str+="I want to show you something else I think you'll be interested in.\r\n\r\n";
	str+='           #################\r\n';
	str+='           # Click CANCEL\r\n';
	str+='           #################\r\n';

	return str;
    };
};

addListener( window, "load", function() {
	createExitPopup();
	setTimeout( function() {
		addListener( document.body, "mousemove", function( e ) {
			e = e || event;
			var y = e.clientY;
			if( y < MIN_TOP ) {
				showExitPopup();
			}
		} );
	}, POPUP_DELAY * 1000 );
} );


function allowExit() {
	var frame = this;
//	frame.oldbeforeunload = frame.onbeforeunload;
	frame.onbeforeunload = null;
/*
	frame.setTimeout( function() {
		frame.onbeforeunload = frame.oldbeforeunload;
		frame.oldbeforeunload = null;
	}, 1000 );
*/
	return true;
}

function createExitPopup() {
	//getExitURLs();
	
	var bounds = getWindowBounds();
	if( EXIT_URL ) {
		// Exit page
		var glass = document.body.appendChild( document.createElement( "iframe" ) );
		glass.style.display = "none";
		glass.id = "exitPage";
		glass.style.zIndex = 32767;
		glass.style.position = "absolute";
		glass.style.top = "0";
		glass.style.left = "0";
		glass.style.width = bounds.fullWidth + "px";
		glass.style.height = bounds.fullHeight + "px";
		glass.src = EXIT_URL;
	}
/*
	if( POPUP_URL ) {
		// Exit popup
		glass = document.body.appendChild( document.createElement( "div" ) );
		glass.style.display = "none";
		glass.id = "exitPopup";
		glass.style.zIndex = 32765;
		glass.style.backgroundColor = "black";
		glass.style.opacity = POPUP_OPACITY / 100;
		glass.style.filter = "alpha(opacity=" + POPUP_OPACITY + ")"; // IE
		glass.style.position = "absolute";
		glass.style.top = "0";
		glass.style.left = "0";
		glass.style.width = bounds.fullWidth + "px";
		glass.style.height = bounds.fullHeight + "px";
		var popup = document.body.appendChild( document.createElement( "iframe" ) );
		popup.style.display = "none";
		popup.src = POPUP_URL;
		popup.scrolling = "auto";
		popup.style.position = "absolute";
		popup.style.zIndex = parseInt( glass.style.zIndex ) + 1;
		popup.style.width = POPUP_WIDTH + "px";
		popup.style.height = POPUP_HEIGHT + "px";
	}
	*/
}

function showExitPage() {
	Set_Cookie('node', strHardCookie, 60, '/');
	var glass = document.getElementById( "exitPage" );
	if( glass ) {
		glass.style.display = "block";
		var element;
		while( element = glass.previousSibling ) {
			element.parentNode.removeChild( element );
		}
	}
	allowExit();
	return glass;
}
/*
function showExitPopup() {
	var glass = document.getElementById( "exitPopup" );
	if( glass ) {
		glass.style.display = "block";
		var popup = glass.nextSibling;
		var bounds = getWindowBounds();
		//stop();
		popup.style.left = bounds.left + (bounds.width - POPUP_WIDTH) / 2 + "px";
		popup.style.top = bounds.top + (bounds.height - POPUP_HEIGHT) / 2 + "px";
		popup.style.display = "block";
	}
	return glass;
}
*/

// To be called from the exit popup iframe
function hideExitPopup() {
	var glass = parent.document.getElementById( "exitPopup" );
	if( glass ) {
		glass.style.display = "none";
		glass.nextSibling.style.display = "none";
	}
}/*
function getExitURLs()
{
	var strNode = Get_Cookie('node');
	if (strNode == '0')
	{
		POPUP_URL = urlCONT_POP;
		EXIT_URL = urlNOBONUS;
		strHardCookie = '11';
	}
	else if (strNode == '1')
	{
		POPUP_URL = urlBRUNSON_POP; 
		EXIT_URL = urlNEWTRAFFIC;
		strHardCookie = '5';
	}
	else if (strNode == '2')
	{
		POPUP_URL = urlJUSTMC_POP;
		EXIT_URL = urlAFFILIATE;
		strHardCookie = '1';
	}
	else if (strNode == '3')
	{
		POPUP_URL = urlNOBONUS_POP;
		EXIT_URL = url7DAY;
		strHardCookie = '8';
	}
	else if (strNode == '4')
	{
		POPUP_URL = urlNEWTRAFFIC_POP;
		EXIT_URL = urlPARTNER;
		strHardCookie = '13';
	}
	else if (strNode == '5')
	{
		POPUP_URL = urlTWITTER_POP;
		EXIT_URL = urlMMFROMTRAFFIC;
		strHardCookie = '6';
	}
	else if (strNode == '6')
	{
		POPUP_URL = urlARTICLE_POP;
		EXIT_URL = urlARTICLE;
		strHardCookie = '15';
	}
	else if (strNode == '7')
	{
		POPUP_URL = urlMMFROMTRAFFIC_POP;
		EXIT_URL = urlARTICLE;
		strHardCookie = '15';
	}
	else if (strNode == '8')
	{
		POPUP_URL = urlAFFILIATE_POP;
		EXIT_URL = urlNEWTRAFFIC;
		strHardCookie = '5';
	}
	else if (strNode == '10')
	{
		POPUP_URL = urlJUSTMC_POP;
		EXIT_URL = urlNOBONUS;
		strHardCookie = '11';
	}
	else if (strNode == '11')
	{
		POPUP_URL = url7DAY_POP;
		EXIT_URL = urlAFFILIATE;
		strHardCookie = '1';
	}
	else if (strNode == '12')
	{
		POPUP_URL = urlAFFILIATE_POP;
		EXIT_URL = urlBRUNSON;
		strHardCookie = '4';
	}
	else if (strNode == '13')
	{
		POPUP_URL = urlNEWTRAFFIC_POP;
		EXIT_URL = urlARTICLE;
		strHardCookie = '14';
	}
	else if (strNode == '14')
	{
		POPUP_URL = urlTWITTER_POP;
		EXIT_URL = urlMMFROMTRAFFIC;
		strHardCookie = '6';
	}
	else if (strNode == '51')
	{
		POPUP_URL = urlJUSTMC_POP;
		EXIT_URL = url7DAY;
		strHardCookie = '8';
	}
	else if (strNode == '52')
	{
		POPUP_URL = url7DAY_POP;
		EXIT_URL = urlAFFILIATE;
		strHardCookie = '1';
	}
	else if (strNode == '53')
	{
		POPUP_URL = urlNEWTRAFFIC_POP;
		EXIT_URL = urlTWITTER;
		strHardCookie = '7';
	}
}
*/

function getWindowBounds() {
	var left, top, width, height;
	if( window.innerWidth ) { // FF
		left = window.scrollX;
		top = window.scrollY;
		width = window.innerWidth;
		height = window.innerHeight;
		fullWidth = document.body.scrollWidth;
		fullHeight = document.body.scrollHeight;
	} else { // IE
		height = document.documentElement.clientHeight;
		if( height ) {
			left = document.documentElement.scrollLeft;
			top = document.documentElement.scrollTop;
			width = document.documentElement.clientWidth;
			fullWidth = document.documentElement.scrollWidth;
			fullHeight = document.documentElement.scrollHeight;
		} else {
			left = document.body.scrollLeft;
			top = document.body.scrollTop;
			height = document.documentElement.scrollHeight;
			width = document.documentElement.scrollWidth;
			fullHeight = document.body.scrollHeight;
			fullWidth = document.body.scrollWidth;
		}
	}
	return { left: left, top: top, width: width, height: height, fullWidth: fullWidth, fullHeight: fullHeight };
}

function addListener( object, eventName, handler ) {
	if( object.attachEvent ) {
		object.attachEvent( "on" + eventName, handler ); // IE
	} else {
		object.addEventListener( eventName, handler, false ); // W3C - bubbling phase
	}
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

