// Site changes popup (popup window when user exit your site)

// timeout for checking if site is changed
var timeout = 1000;
// popup window options (same as in function window.open())
var options = 'width=100,height=100';
// url of popup page
var url='hidden_popup.htm';

// don't change text below
self.closepopup = true;
self.activatepopup = true;
self.foreign = false;
clearfunction = new Function( "self.activatepopup = false;" );
foreignfunction = new Function( "self.foreign = true;" );

function exitPopup() {
	if ( self.foreign ) {
		window.open(url,'',options);
	}
	else if ( self.activatepopup ) {
		// Detect browser
		var useragent = navigator.userAgent;
		var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
		var pos = useragent.indexOf('MSIE');
		if (pos > -1) {
			bVer = useragent.substring(pos + 5);
			var pos = bVer.indexOf(';');
			var bVer = bVer.substring(0,pos);
			ieContent();
		}
		var pos = useragent.indexOf('Opera');
		if (pos > -1) {
			bVer = useragent.substring(pos + 6);
			var pos = bVer.indexOf(' ');
			var bVer = bVer.substring(0, pos);
		}
		if (bName == "Netscape") {
			var bVer = useragent.substring(8);
			var pos = bVer.indexOf(' ');
			var bVer = bVer.substring(0, pos);
		}
		if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5) {
			var pos = useragent.lastIndexOf('/');
			var bVer = useragent.substring(pos + 1);
			ns6Content();
		}
	}
}

function ieContent() {
	w=window.open('about:blank','exitpopup','top=20000,left=20000,width=1,height=1');
	self.focus();
	w.blur();
	w.document.write("<script>");
	w.document.write("self.blur();");
	w.document.write("var t = window.setTimeout('checkOpener()', "+timeout+");");
	w.document.write("function checkOpener() {");
	w.document.write("	if (!opener.closepopup) window.open('"+url+"','','"+options+"');");
	w.document.write("	window.clearTimeout(t);");
	w.document.write("	self.close();");
	w.document.write("}");
	w.document.write("</scr"+"ipt>");
}

function ns6Content() {
	w=window.open('about:blank','exitpopup','top=20000,left=20000,width=1,height=1');
	self.focus();
	w.blur();
	w.document.write("<script>");
	w.document.write("self.blur();");
	w.document.write("var t = window.setTimeout('checkOpener()', "+timeout+");");
	w.document.write("function checkOpener() {");
	w.document.write("	try {");
	w.document.write("		if (!opener.closepopup) window.open('"+url+"','','"+options+"');");
	w.document.write("	} catch(e) {");
	w.document.write("		window.open('"+url+"','','"+options+"');");
	w.document.write("	}");
	w.document.write("	window.clearTimeout(t);");
	w.document.write("	self.close();");
	w.document.write("}");
	w.document.write("</scr"+"ipt>");
}

function activateLinks() {
	for (i=0;i<document.links.length;i++) {
		if ( document.domain == document.links[i].hostname  ) {
			document.links[i].onclick = clearfunction;
		}
		else {
			document.links[i].onclick = foreignfunction;
		}
	}
}

window.onload = new Function( "activateLinks();" );
window.onunload = new Function( "exitPopup();" );
