/*
function nthValue (group) {
	if(group == 'n1') {
	//if statements for each group corresponding to the name chosen in the link i.e. check cookie(link, groupname, nth)
	//whichSurvey will send the corresponding survey link when necessary
		nth = "http://www.yahoo.com";
	} else if(group == 'n2') {
		nth = "http://www.apple.com";
	} else if(group == 'n3') {
		nth = "http://www.froogle.com";
	}
	return nth;
}

*/
function checkCookie(href, whichSurvey, group) {
	var nth;
	var whichSurvey;
	
	if(group=="n1") nth = 1;
	if(group=="n2") nth = 3;
	if(group=="n3") nth = 5;

	var rnd = Math.floor(1 + Math.random() * nth);
	//take off comments for if statement when implementing the random number stuff
	//but keep ghosted while testing function-ness
	
	if (rnd == nth)
	{
		if(getCookie('SCA') == "true") {
		
			//here, the cookie would be found and the user would be redirected to the original link they clicked
			//this could be done by simply moving the href link to an onclick(sendlinkhereinstead) function
			//the variable will carry the link to a spot like this one where we will simply open the url
			
			//remove commented line below...this is here for testing
			
			//document.location = 'interstitial.shtml?href='+href+'&surveyURL=' + whichSurvey;
			window.location = href;
			
		} else if(getCookie('SCA') != "true") {
		
			setCookie('SCA', "true", "14");
			
			//call survey interstitial and send the link they clicked on and the appropriate survey link
			document.location = '/research/interstitial.shtml?href='+href+'&surveyURL=' + whichSurvey;
		}
	} 
	else if (rnd != nth)
	{
			window.location = href;
	}
//alert(rnd);
}


function setCookie(NameOfCookie, value, expiredays)
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) +
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}


function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			
		if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		}
		
	}
	return null;
}
