// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookieValue(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function dateAdd(datePart, number, oldDate){
	var newDate = new Date ();
	if (datePart == "yy" || datePart == "yyyy")
		newDate.setTime (oldDate.getTime() + (1000 * 60 * 60 * 24 * 365 * number));
	if (datePart == "ww" || datePart == "wk")
		newDate.setTime (oldDate.getTime() + (1000 * 60 * 60 * 24 * 7 * number));
	if (datePart == "dd" || datePart == "d")
		newDate.setTime (oldDate.getTime() + (1000 * 60 * 60 * 24 * number));
	if (datePart == "hh")
		newDate.setTime (oldDate.getTime() + (1000 * 60 * 60 * number));
	if (datePart == "mi" || datePart == "n")
		newDate.setTime (oldDate.getTime() + (1000 * 60 * number));
	if (datePart == "ss" || datePart == "s")
		newDate.setTime (oldDate.getTime() + (1000 * number));
	if (datePart == "ms" )
		newDate.setTime (oldDate.getTime() + (number));


	return newDate;
}


// cookieName - name of the desired cookie

// * return string containing value of specified cookie or null if cookie does not exist
function getCookieValue(cookieName){
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");
	if (cookieStartsAt == -1)
	{
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	}
		
	if (cookieStartsAt == -1)
	{
		cookieValue = null;
	}
	else
	{
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1)
		{
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));
	}
	return cookieValue;
}
	
function leavePopUp(){
	//first check for the cookie
	if (getCookieValue("NewsletterPopup2") == "1"){
		//already done, so don't do it now
		return;
	}
	//set cookie and let it expire in 10 years
	setCookieValue("NewsletterPopup2","1",dateAdd("yy",10,new Date()));
	//Show the popup
	var width = 480;
	var height = 500;
	var left = (screen.width / 2) - (width / 2);
	var top = (screen.height / 2) - (height / 2);
	var lPopUp = window.open("http://www.dvo.com/popup.php", 'lPopUp','width=' + width + ', height=' + height + ', left=' + left + ', top=' + top + ', scrollbars, resizable');
	lPopUp.blur();
}