var diagnose = false; // switch to true for diagnostic text


// Heinle's function for retrieving a cookie.
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// An adaptation of Dorcht's function for setting a cookie.
function dropCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function showPopUnder(dURL,w,h,whenToShow) { // whenToShow = once, always, perSession

	// get Window size properties
		if (document.all)
			var xMax = screen.width, yMax = screen.height;
		else
			if (document.layers)
				var xMax = window.outerWidth, yMax = window.outerHeight;
			else
				var xMax = 640, yMax=480;

		var xOffset = (xMax)/2, yOffset = (yMax)/2;
		var x = xOffset-(w/2), y = yOffset-(h/2);
		
	// set default values
		w = (w==null)? xMax : w;
		h = (h==null)? yMax : h;
		whenToShow = (whenToShow==null)? "always" : whenToShow;
		
		var anyPath = "/"; // otherwise, cookies separate for each directory

	// if no cookie found (or cookie expired), pop up URL and reset cookie as needed
		
		switch (whenToShow) {
			case "always" :
				var showWin = true;
				if (diagnose) window.status = getCookie(dURL)+" a";
				break;
			case "once" :
				if (getCookie(dURL)>"") {
					showWin = false;
					if (diagnose) window.status = getCookie(dURL)+" o 0";
					}
				else {
					showWin = true;
					var neverExpires = new Date("December 31, 2023");
					setCookie(dURL,"popped",neverExpires,anyPath);
					if (diagnose) window.status = getCookie(dURL)+" o 1";
					}
				break;
			case "perSession" :
				if (diagnose) alert(getCookie(dURL));
				if (getCookie(dURL)>"") {
					showWin = false;
					if (diagnose) window.status = getCookie(dURL)+" s 0";
					}
				else {
					showWin = true;
					var expiresAtSessionEnd = null;
					setCookie(dURL,"popped",expiresAtSessionEnd,anyPath);
					if (diagnose) window.status = getCookie(dURL)+" s 1";
					}
				if (diagnose) alert(getCookie(dURL));
				break;
			default :
				var showWin = true;
		}
		
		var screenParams = 'scrollbars=no,titlebar=no,menubar=no,width='+w+',height='+h+',screenX='+x+',screenY='+y+',top='+y+',left='+x+'';
		if (showWin)	
			win2=window.open(dURL,"newWin",screenParams);
			win2.blur();
			window.focus();

		return;
	}

function showPop(dURL,w,h,whenToShow) { // whenToShow = once, always, perSession

	// get Window size properties
		if (document.all)
			var xMax = screen.width, yMax = screen.height;
		else
			if (document.layers)
				var xMax = window.outerWidth, yMax = window.outerHeight;
			else
				var xMax = 640, yMax=480;

		var xOffset = (xMax)/2, yOffset = (yMax)/2;
		var x = xOffset-(w/2), y = yOffset-(h/2);
		
	// set default values
		w = (w==null)? xMax : w;
		h = (h==null)? yMax : h;
		whenToShow = (whenToShow==null)? "always" : whenToShow;
		
		var anyPath = "/"; // otherwise, cookies separate for each directory

	// if no cookie found (or cookie expired), pop up URL and reset cookie as needed
		
		switch (whenToShow) {
			case "always" :
				var showWin = true;
				if (diagnose) window.status = getCookie(dURL)+" a";
				break;
			case "once" :
				if (getCookie(dURL)>"") {
					showWin = false;
					if (diagnose) window.status = getCookie(dURL)+" o 0";
					}
				else {
					showWin = true;
					var neverExpires = new Date("December 31, 2023");
					dropCookie(dURL,"popped",neverExpires,anyPath);
					if (diagnose) window.status = getCookie(dURL)+" o 1";
					}
				break;
			case "perSession" :
				if (diagnose) alert(getCookie(dURL));
				if (getCookie(dURL)>"") {
					showWin = false;
					if (diagnose) window.status = getCookie(dURL)+" s 0";
					}
				else {
					showWin = true;
					var expiresAtSessionEnd = null;
					dropCookie(dURL,"popped",expiresAtSessionEnd,anyPath);
					if (diagnose) window.status = getCookie(dURL)+" s 1";
					}
				if (diagnose) alert(getCookie(dURL));
				break;
			default :
				var showWin = true;
		}
		var screenParams = 'scrollbars=no,toolbar=no,menubar=no,titlebar=no,width='+w+',height='+h+',screenX='+x+',screenY='+y+',top='+y+',left='+x+'';
		if (showWin)	window.open(dURL,"newWin",screenParams);

		return;
	}

if (diagnose) alert("Script loaded");