var locallink=false;
var cookie_name = "entexitpopup";

/*
function setupLinks(){
	var length =window.document.links.length;
		
	for (var i=0;i<length;i= i +1){
		var str = window.document.links[i].href;
		window.document.links[i].onclick = function(){ locallink = true };
	}	
}
*/

function setupLinks(){
	var length = window.document.links.length;		
	var orig = new Array(length);
				
	for(var i = 0; i < length; i++){
		orig[i] = window.document.links[i].onclick;
		window.document.links[i].onclick = function(){ 
			locallink=true;
				
			for(var i = 0; i < window.document.links.length; i++){
				if(window.document.activeElement == window.document.links[i]) {
					if(orig[i] != null) {
						orig[i]();
					}
				}
			}
		};
	}	
}

function checkExit(epi_URL, w, h){
	var epi_name = '_epi_popunder';
	var epi_width = w;
	var epi_height = h;
	var epi_top = 0;
	var epi_left = 0;
	
	if (!locallink) {
		var get_cookie = null;
		get_cookie = getCookie(cookie_name);
		if(get_cookie == null || get_cookie != "true"){
			var page_url = "poppage.shtml";			
			var popunder_handle = window.open(page_url, epi_name, 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no,resizable=yes,width=' + epi_width + ',height=' + epi_height + ',top=' + epi_top + ',left=' + epi_left);
			popunder_handle.blur();
		} 
	}
}

function getCookie(Name) {
  
  var search = Name + "=";
  if (document.cookie.length > 0) { // if there are any cookies
    var offset = document.cookie.indexOf(search);
    if (offset != -1) { // if cookie exists
      offset += search.length;
      // set index of beginning of value
      var end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1){
        end = document.cookie.length;
      }
      return unescape(document.cookie.substring(offset, end));
    }
    return null;
    
  }
}



