/*
	(c) Copyright 2004, MarketVision Research. All rights reserved.
	Contact John Winger (jwwinger@mv-research.com) for more info.
*/

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 = 150; // i.e. 1 in [whatever number is coded here]

		if ( isSelected(selRate) )
		{
			var isIE5plus = false;
			if (userAgent.indexOf("MSIE 5") > notFound || userAgent.indexOf("MSIE 6") > notFound)
				isIE5plus = true;

			var theUrl  = (isIE5plus ? "/media/pcc/HTML/proUse/mv_cst_ckdom_5p.htm" : "/media/pcc/HTML/proUse/mv_cst_ckdom_u5.htm");
			var winName = "ckdom";
			var winDesc = "toolbar=no,menubar=no,scrollbars=no,resizable=no,width=50,height=50,top=2950,left=2950";

			window.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();
