// variables that are used throught the functions
var cookieValues = new Object;

// basic reading, writing and arithmetic. well maybe not arithmetic.
function writeCookie(name,value,expire,path) {
	document.cookie = name+"="+value +"; expire="+expire+"; path="+path;
}

function readCookie() {
	cookieArray = document.cookie.split(";");
	for (i=0; i < cookieArray.length; i++) {
		tempName = cookieArray[i].slice(0,cookieArray[i].indexOf("="));
		tempValue = cookieArray[i].slice(cookieArray[i].indexOf("=")+1);
		eval("cookieValues." + tempName + " = '" + tempValue +"'");
	}
}

// creates a date to be used when the cookie is written
// if toDelete is set to 0 then the cookie will expire in a year
// if toDelete is set to 1 then the cookie will expire immediately
function createDate(dontDelete) {
	theDate = new Date();
	if (dontDelete) {
		newYear = theDate.getFullYear() + 1;
	} else {
		newYear = theDate.getFullYear() - 1;
	}
	theDate.setFullYear(newYear);
	return theDate.toUTCString();
}

// checks to see if cookies are enabled, also writes out the last page visited on the home page, if the user is returning.
function cookieCheck() {
	writeCookie("cookieEnabled","true",createDate(1),"/");
	readCookie();

	if (cookieValues.cookieEnabled) {
		writeCookie("cookieEnabled","",createDate(0),"/");
	} else {
		alertText = "You appear to have cookies disabled, or your browser doesn't support them.\n"
		alertText += "You may continue to use the website without cookies, however it may not function as expected. \n"
		alertText += "We recommend that you:\n\n"

		alertText += "\t1) Make sure that your browser supports cookies\n"
		alertText += "\t2) Make sure that cookies are enabled.\n\n"

		alertText += "If your browser doesn\’t support cookies, please upgrade to one that does."
		alert(alertText);
	}
}

function checkVisitTime() {
	//alert("I just called to say...I looooooove you...");
	readCookie();
	sessionStartTime = new Date(cookieValues.arrivalTime);
	currentTime = new Date();
	timeElapsed = currentTime.getTime() - sessionStartTime.getTime();
	waitTime = 10/*minutes*/ * 60/*seconds*/ * 1000/*milliseconds*/;

	if (timeElapsed >= waitTime && !cookieValues.saPopped) {
		top_position = screen.height/2 - 289/2;
		left_position = screen.width/2 - 500/2;
		if (window.screenX) {
			top_position = "screenX=" + top_position;
			left_position = "screenY=" + left_position;
		} else {
			top_position = "top=" + top_position;
			left_position = "left=" + left_position;
		}
		MM_openBrWindow('special-announcement-popup.asp','didyouknow','width=496,height=312,'+top_position+','+left_position);
		writeCookie("saPopped",'true',"","/");
		if (popupTimeout) {
			window.clearInterval(popupTimeout);
		}
	}
}

if (location.search.indexOf("sa")!=-1) {
	top_position = screen.height/2 - 289/2;
	left_position = screen.width/2 - 500/2;
	if (window.screenX) {
		top_position = "screenX=" + top_position;
		left_position = "screenY=" + left_position;
	} else {
		top_position = "top=" + top_position;
		left_position = "left=" + left_position;
	}
	MM_openBrWindow('special-announcement-popup.asp','didyouknow','width=496,height=312,'+top_position+','+left_position);
}

popupTimeout = window.setInterval("checkVisitTime()",10*1000);
cookieCheck();

if (!cookieValues.arrivalTime) {
	writeCookie("arrivalTime",new Date().toLocaleString(),"","/");
} else {
	checkVisitTime();
}

// EoF