// Original:  Gregor (legreg@legreg.de)
// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com

var expDays = 1;
var popundername = 'http://www.discountroses.com';

var usePopup = false;
var usePopunder = true;

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 SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt() {
	var popup = GetCookie('popup');
	if(popup == null) {
		SetCookie('popup','1');
		return 1;
	}
	else {
		var newpopup = parseInt(popup) + 1;
		DeleteCookie('popup');
		SetCookie('popup',newpopup,exp);
		return popup;
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function checkVersion(link) {
	var useragent = navigator.userAgent;
	var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
	var pos = useragent.indexOf('MSIE');
	if (pos > -1) {
		bVer = useragent.substring(pos + 5);
		var pos = bVer.indexOf(';');
		var bVer = bVer.substring(0,pos);
	}
	var pos = useragent.indexOf('Opera');
	if (pos > -1)	{
		bVer = useragent.substring(pos + 6);
		var pos = bVer.indexOf(' ');
		var bVer = bVer.substring(0, pos);
	}
	if (bName == "Netscape") {
		var bVer = useragent.substring(8);
		var pos = bVer.indexOf(' ');
		var bVer = bVer.substring(0, pos);
	}
	if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5) {
		var pos = useragent.lastIndexOf('/');
		var bVer = useragent.substring(pos + 1);
	}
	if (bName == "Microsoft Internet Explorer" && bVer >= "6.0") {
		if (usePopup) {
			window.open(link,"",",toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,screenX=0,screenY=0,top=0,left=0");
		} else {
			if (parent.frames.length > 0) {
				parent.location.href = link;
			} else {
				window.location.href = link;
			}
		}
		if (usePopunder) {
			var popup = GetCookie('popup');
			if (popup == null) {
				popup=1;
				SetCookie('popup', popup, exp);
				popunderwindow = window.open(popundername,"",",toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,screenX=0,screenY=0,top=0,left=0");
				popunderwindow.blur();
				window.focus();
			} else {
				popup++;
				SetCookie('popup', popup, exp);
			}
		}
		return false;
	}
	return true;
}