function mvSurveyInvite()
{
	var userAgent = navigator.appName + " " + navigator.appVersion;
	var notFound  = -1;
	userAgent     = userAgent.toUpperCase();

	if (userAgent.indexOf("WEBTV") == notFound && userAgent.indexOf("OPERA") == notFound)
	{
		var selRate = 0; // i.e. 1 in [whatever number is coded here]

		if ( isSelected(selRate) )
		{
			showInvitation();
		}
	}
}

function showInvitation()
{
	var theURL  = "/assets/scripts/prousesrscripts/srvy_inv.htm";
	var winName = "invite";
	var winDesc = "toolbar=no,menubar=no,scrollbars=no,resizable=yes,width=400,height=400,top=75,left=200";
	var newWin  = open(theURL, winName, winDesc);
}

function isSelected(odds)
{
	var mvCookieName  = "mv";
	var mvInviteGiven = "1";
	var mvCookieValue = getCookie(mvCookieName);

	if (mvCookieValue != mvInviteGiven)
	{
		var randVal = parseInt( (Math.random() * odds) + 1 );

		if (randVal == odds)
		{
			var expDate     = new Date();
			var threeMonths = 7 * 24 * 60 * 60 * 1000 * 14;
			expDate.setTime(expDate.getTime() + threeMonths);
			setCookie(mvCookieName, mvInviteGiven, expDate, "/");
			return true;
		}
	}

	return false;
}

function getCookie(name)
{
	var result        = null;
	var myCookie      = " " + document.cookie + ";";
	var searchName    = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;

	if (startOfCookie != -1)
	{
		startOfCookie += searchName.length;
		endOfCookie    = myCookie.indexOf(";", startOfCookie);
		result         = unescape( myCookie.substring(startOfCookie, endOfCookie) );
	}

	return result;
}

function setCookie(name, value, expires, path, domain)
{
	var expStr    = ( (expires == null) ? "" : ("; expires=" + expires.toGMTString()) );
	var pathStr   = ( (path    == null) ? "" : ("; path="    + path) );
	var domainStr = ( (domain  == null) ? "" : ("; domain="  + domain) );

	document.cookie = name + "=" + escape(value) + expStr + pathStr + domainStr;
}

mvSurveyInvite();
this.window.focus();

