// This script has been developed by ordecon.systems (http://www.ordecon.com/)
// All rights reserved. Please do not modify the source code and re-distribute
// only in the original package!


// Script configuration variables:
	// Popup window options:
		// The URL to show in the popup window
		var popupURL="/survey/";
		
		// The size of the popup window
			// set this to 1 if you want the window maximized, 0 otherwise
			var popupMaximized=0;

			// if you don't want a maximized window, enter the size here, otherwise, just set it to any numerical value
			var popupWidth=600;
			var popupHeight=600;
		
		// "yes" if you want the new window to have scrollbars, otherwise "no"
		var popupScrollbars="yes"

		// "yes" if you want the new window to have the address bar, otherwise "no"
		var popupLocation="no"

	// What is considered internal?
	var internalBaseURLs = new Array(
		"http://dev.4allmemory.com",
		"http://www.4allmemory.com"
	);

	// Extended Unload Event:
	// Should I pop up a window when the user exits by manualy typing in an URL, choosing a bookmark, or hitting the back
	// button?
	// WARNING: browser security does not allow JavaScript to find out what the URL of the new page is. Therefore all such
	// events (typing URL, opening a bookmark or hitting back) will cause a popup, regardless if they will keep the user
	// on your page.
	var catchExtendedUnloads=1;

//
//
// You can and should let the things below live their own life, without your meddling litle fingers! ;)
//
//
var browserIsNetscape=(navigator.appName.indexOf("Microsoft")!=-1) ? false : true;
var unloadNoticed=0;

function doPopup() {
	options = "scrollbars="+popupScrollbars+",location="+popupLocation;
	helpWindow = window.open(popupURL, "NavBar", options);
	helpWindow.blur();
	window.focus();

	if (popupMaximized) {
		helpWindow.moveTo(0,0);
		helpWindow.resizeTo(screen.availWidth, screen.availHeight);
	} else {
		helpWindow.resizeTo(popupWidth, popupHeight);
	}

	unloadNoticed=1;
}

function doInitPopupEvents() {
	if (browserIsNetscape) {
		window.captureEvents(Event.CLICK);
		window.onclick=checklink;
	} else {
		document.onclick=checklink;
	}
}

// Returns zero if the link is found among the internalBaseURLs, else it returns non-zero
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++;
		}
	}

	return !foundInternals;
}

function checklink(e) {
	if (!browserIsNetscape) {
		targetURL = window.event.srcElement.href;
	} else {
		targetURL = e.target.href;
	}

	// If the event carries a non-null targetURL with it, it means that the user is going away,
	// so let's check the click...
	if (targetURL && isLinkExternal(targetURL)) {
		doPopup();
	} else {
		unloadNoticed=1;
	}
}

function doCheckUnloading() {
	if (!unloadNoticed && catchExtendedUnloads) {
		doPopup();
	}
}

