var dopopup=true;

var geko=navigator.userAgent.search(/Gecko/)>-1;
var ie=navigator.appName=="Microsoft Internet Explorer";

// the following are htmls which chek whether 
// the opener window still has location within the site and,
// closes if it has. Otherwise, it replaces location with
// url described in slytarget.js

//var nsly="http://renard.flamingo.ru/test/popup/slyn.html";
//var sly="http://renard.flamingo.ru/test/popup/sly.html";  


var nsly="http://www.onlinetradingexpo.com/popup/slyn.html";
var sly="http://www.onlinetradingexpo.com/popup/sly.html";  

// In the case we don't want to close the popup window
// on 'back','forward' and 'reload', just comment two lines 
// above and uncomment two lines below. 

//var nsly="http://www.onlinetradingexpo.com/popup.htm";
//var sly="http://www.onlinetradingexpo.com/popup.htm";  
// In this case sly.html,slyn.html,slytarget.js become unnecessary

var slyrx=/sly/i;

var height=335;
var width=400;

var cookiename="dont_show_the_popup_window";
var mycookie=new Cookie(document,cookiename,0);
mycookie.load();


function doUnload(event)       
{	
	if (String(mycookie.what) != "undefined")	
		return true;
	if (dopopup)
	{
		if (geko || ie)
		{
			window.open(sly,"our_sly_popup","width="+width+",height="+height+",status=no,visible=no,hidden=yes,toolbar=no,directories=no,location=no,scrollbars=no,menubar=no,resizable=no");
			if (slyrx.test(sly)) focus();
		}
		else
		{
			window.open("javascript: document.location.href=\"" + nsly +"\"","our_sly_popup","width="+width+",height="+height+",status=no,visible=no,hidden=yes,toolbar=no,directories=no,location=no,scrollbars=no,menubar=no,resizable=no");
			if (slyrx.test(nsly)) focus();
		}
	}
}

function onClick(e)
{
	if(String(targetHostname(e)).toLowerCase() == String(document.location.hostname).toLowerCase())
			dopopup=false;
}

function targetHostname(event)
{
	if (ie)
	{
		var obj=window.event.srcElement;
		if (obj.type && (obj.type == "submit" || obj.type == "image"))
			dopopup=false;
		while (!obj.hostname && obj.parentElement)
		{
			obj=obj.parentElement;
		}
		if (String(obj) == "undefined")
			return "undefined";
		return obj.hostname;
	}
	if(geko)
	{	
		var obj=event.target;
		if (obj.type && (obj.type == "submit" || obj.type == "image"))
			dopopup=false;
		return event.target.parentNode.hostname;
	}
	
	var obj=event.target;
//	var txt="";
//	alert(obj.type);
//	for (var i in obj)
//		txt+= i + " = " +obj[i] + " (" + typeof(obj[i]) + ")\t";
//	alert(txt)
//	if (obj.type && (obj.type == "submit" || obj.type == "image"))
//		dopopup=false;
	return event.target.hostname;
}

function doPrepare()
{
	for (var i =0;i<document.links.length;i++)
	{
		document.links[i].onclick=onClick;
	}
	alert("prepared");
}

function doSubmit()
{
	dopopup=false;
//	alert("Here we are");
	return true;
}
// MAIN SCRIPT STARTS HERE

	window.name='our_window';
	window.onunload=doUnload;
	window.onsubmit=doSubmit;
	document.onclick=onClick;
	if (!ie)
	{
		document.captureEvents(Event.CLICK)
		window.captureEvents(Event.UNLOAD);
		window.captureEvents(Event.SUBMIT);
	}       

// just add the script to your html page in head section.
// popup window will raise when you following link out of your host.
// or typing something in navbar or reloading document.