var page;

page = "http://www.nl.edu/survey";

var dName = self.location.href.toLowerCase().split('/')[2];

if(dName != null){
	page = "http://www.nl.edu/survey/"
}

var windowprops = "width=680,height=575,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no";
var isNav4, isIE4;

var mys=self.location.href.toLowerCase().split('/')[2];
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
	isNav4 = (navigator.appName == "Netscape") ? true : false;
	isIE4 = (navigator.appName == "Microsoft Internet Explorer") ? true:false;
}

flag = "";
Yaxis = 0;
blurred = "no";

if (isIE4){
	document.onclick=sp;
	window.onclick=sp;
	document.onunload=usp;
	window.onunload=usp;
	window.onblur=blurme;
	window.onkeydown=usp;
}


function usp(ev) {	

		range = screen.height - document.body.offsetHeight;
				
		if (isIE4){
			ev=window.event;
		}

		if(range < 160) {
			upperY = -12;
		}
		if(range >= 160) {
			upperY = -35;
		}
		if(range >= 170) {
			upperY = -40;
		}

		if(Yaxis == 0) {
			Yaxis = ev.clientY;
		}

		if (Yaxis < upperY || Yaxis > 0 || ev.keyCode == 116 || ev.keyCode == 17)
		  flag="no";

		if(Yaxis <= -9600) {
		   flag="yes";
		}

		if(blurred == "yes" && Yaxis < 0) {
		   flag = "yes";
		}

	    	var exit_survey = GetCookie('exit_survey');

		if (isNav4){
                  flag = "no";
		}

		if (((flag=="" || flag=="yes") && ev.keyCode != 32 && ev.keyCode != 18) && exit_survey==null) //spacebar & ctrl+tab 
		{
  		  pop();

                  // Set Cookie
                  setCookie('exit_survey','1',30);
		}
}

function sp(ev) {
	if (isIE4){
		ev=window.event;
	}
	Yaxis = ev.clientY;
}

function blurme(ev) {
	if (isIE4){
		ev=window.event;
	}
	Yaxis = ev.clientY;
	blurred = "yes";
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
function getCookieVal(offset) {
   	var endstr = document.cookie.indexOf (";", offset);
   	if (endstr == -1)
   		endstr = document.cookie.length;
   	return unescape(document.cookie.substring(offset, endstr));
}

function pop() {
		window.open(page, "POPUP1", windowprops);
}


function setCookie(name, value, expiredays)
{
  var ExpireDate = new Date ();
  ExpireDate.setTime(ExpireDate.getTime() + (expiredays*24*60*60*1000));

  document.cookie = name + "=" + escape(value) + "; expires=" + ExpireDate.toGMTString() + "; path=/";
}