// JavaScript Document
//user cookies to track whether the user has come from the Banner 08 campaign
// 6 ad networks are linking to clarkson.edu, using the URL variable "banner08"

//track the possible banner08 values
var networkArray = new Array("google","yahoo","burst","videoegg","alloy","eyeblaster")

function checkForBanner08()
{

	var earl = new String(document.location);

	var banner08Start = earl.indexOf("banner08=");
	if(banner08Start != -1)//set the cookie
	{
		var cookieVal = "";
		var adnetworkend = earl.indexOf("&",banner08Start);//starting at banner08, look for &
		if(adnetworkend == -1)//Must be last vaiable
		{
			cookieVal = earl.substring(banner08Start+9,earl.length);
		}
		else
		{
			cookieVal = earl.substring(banner08Start+9,adnetworkend);
		}
		document.cookie = cookieVal+"=1";
		//alert(document.cookie.indexOf("yahoo"));
	}
}

function checkForCookie()//return a string of the network, or empty
{
	var theNetwork = "";
	
	for(var i = 0;i < networkArray.length; i++)
	{
		if(document.cookie.indexOf(networkArray[i]) != -1)
		{
			theNetwork = networkArray[i];
		}
	}
	
	return theNetwork;
}

function changeFormAction(formRef)
{
	if(	checkForCookie() != "" )//we have a network to track, so modify the form action so the URL reflects the ad network upon request
	{
		if(formRef.action.indexOf("?") == -1)//there are no current vars contained within action, so add the ?...
		{
			formRef.action = formRef.action+"?banner08="+checkForCookie();
		}
		else
		{
			formRef.action = formRef.action+"&banner08="+checkForCookie();
		}
	}
	
	//alert(formRef.action);
}

function updateURL()
{
	if(	checkForCookie() != "" )//we have a network to track, so modify the form action so the URL reflects the ad network upon request
	{
		var earl = new String(document.location);
		
		if(earl.indexOf("banner08=") == -1)//let's keep it to one rewrite
		{
			if(earl.indexOf("?") == -1)//there are no current vars contained within action, so add the ?...
			{
				document.location = earl+"?banner08="+checkForCookie();
			}
			else
			{
				document.location = earl+"&banner08="+checkForCookie();
			}
		}
	}
}
