
// cookies.js
// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt
// Popup function by Anthony Mutti webmaster@wnec.edu http://www.wnec.edu
// Tested on PC IE 3.01,4.0,4.5,5.0,5.1,5.5,6.0b; NN 3.0,4.0,4.5,4.7,6.1; Opera 4.02, 5.12
// Tested on MAC OS 8-9.1 IE 3.01,4.0,4.5,5.0; NN 4.0,4.5,4.7,6.0

var today = new Date(), expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000), set_dayName,version="3.23";
var todayDate, startDate=0, stopDate=0, popupDelay=0, current=0, a=0, b=0, f=0,hit_countName;

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
	}

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 DeleteCookie (name,path,domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	}
	
	
//POPUP FUNCTION
// The Popup is designed to show up in a given interval not everytime someone views the page.	
// Use the variable popupDelay to set this interval.  The unit is hours, decimals should work.
function popUp(theURL,features,stopMonth,stopDay,stopYear,startMonth,startDay,startYear,hit_countName){	
	
	set_dayName=hit_countName;

	if (!hit_countName){hit_countName='hit_count';}
		else {hit_countName+='_count';}
	if (!set_dayName){set_dayName='set_dayDate';}
		else {set_dayName+='_dayDate';}
	
	time = new Date();
		var month=parseInt(time.getMonth()) + 1, date=parseInt(time.getDate()), year=parseInt(time.getYear()), hours = parseInt(time.getHours());
			if (year<1000) year +=1900;
	    todayDate=(month*100)+date+(year*10000); startDate=(parseInt(startMonth)*100)+parseInt(startDay)+(parseInt(startYear)*10000);stopDate=(parseInt(stopMonth)*100)+parseInt(stopDay)+(parseInt(stopYear)*10000); 
		popupDelay=((self != top)?((parent.isInFrameset)?12:3):3); 
		current=hours + date; f=current+popupDelay; a=GetCookie(set_dayName); b=GetCookie(hit_countName);

// The Popup is designed to show up in a given interval not everytime someone views the page.	
// Use the variable popupDelay to set this interval.  The unit is hours, decimals should work.
	
  if (todayDate >= startDate){
    if (stopDate >= todayDate){
			if ((GetCookie(hit_countName) == null)||(GetCookie(set_dayName) == null)||(GetCookie(set_dayName) != todayDate)){
				WNECpopup = window.open(theURL,"WNECpopupwindow",features);
				WNECpopup.focus();
				SetCookie(hit_countName,f, expiry);
				SetCookie(set_dayName,todayDate, expiry);
			
				}
			else if ((current >= GetCookie(hit_countName)) || (current < (GetCookie(hit_countName) - popupDelay))) {
				WNECpopup = window.open(theURL,"WNECpopupwindow",features);
				WNECpopup.focus();
				SetCookie(hit_countName,f, expiry);
			}
		}
	  }
	}//end of popup
	
	 
 function clearCookie(){	
	DeleteCookie (set_dayName);
	}
	
 function testCookie(){
	newWindow = window.open("",'win','height=300,width=300,');
	newWindow.document.open();
	newWindow.document.write('<html><title>test</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	//newWindow.document.write(' '+ current +'>='+ GetCookie(hit_countName) +'\n');
	newWindow.document.write('setdate='+a+' todaysdate='+todayDate+'  startdate='+startDate+' stopdate='+stopDate+' current= '+current+' hitcount='+b+' popupdelay= '+popupDelay+' next popup= '+f+' browser= '+navigator.appName+' Version'+version+' ');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
		 }
