// COOKIE VARIABLES
var winWidth1 = '500';
var winHeight1 = '305';
var popup1 =  "/pop_ads/0902popad.mhtml";
var winWidth2 = '441';
var winHeight2 = '342';
var popup2 =  "https://ssl.tnr.com/pop_ads/tnr_sub_popup_0407.mhtml";

//cookie setting function
function setCookie(name, value) {
var never = new Date()
never.setTime(never.getTime() + 2000*24*60*60*1000);
var expString = ";path=/; domain=tnr.com;expires=" + never.toGMTString();
document.cookie = name + "=" + escape(value) + expString;
}

// gets the 

function getCookie(name) {
var result = null;
var myCookie = " " + document.cookie + ";";
var searchName = " " + name + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length; // skip past name of cookie
endOfCookie = myCookie.indexOf(";", startOfCookie);
result = unescape(myCookie.substring(startOfCookie, endOfCookie));
return result;
}

}

//window opening function
function cookiePop(popfile,windowW,windowH){
var popWindow = window.open(popfile,'pop','width='+windowW+',height='+windowH+',top=0,left=0,scrollbars=auto,statusbar=no,toolbar=no,resizable=yes');

}

var exit = true;
function exitfalse(){
exit=false;
}

function redirect(){}


//changes all the links to not pop on exit 
function changeurl(){
for (var i=0; i<=(document.links.length-1); i++) {
document.links[i].onclick=exitfalse;
}
for (var j=0;j<document.forms.length;j++){
document.forms[j].onsubmit=exitfalse;
}
var tr=redirect.toString();
if (tr.split('window').length>1){
exit=false;
}
}


//pops open the window
function poponexit(){
if (exit){
cookiePop(popup2,winWidth2,winHeight2); 
}
}


function poponenter(){

var today = new Date();
today = today.getDate().toString() + today.getMonth().toString() + today.getYear().toString();
cDate = getCookie('exitpop1');
	if (cDate != today){
cPops = getCookie('exitpop1num');
	if ((cPops <3) || (! cPops)){
cookiePop(popup1,winWidth1,winHeight1);
setCookie('exitpop1',today);
if (! cPops){
cPops=0;
}
setCookie('exitpop1num',cPops++);
}	
}

}


