<!-- Original:  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function readID() {
	var expDays = 365; // number of days the cookie should last
	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays)); 
	
	var cookieValue = GetCookie('li');
	
	if (cookieValue == null || cookieValue == "no li")
	{
		// the latest interest cookie is useless at the moment, so put something in it.
		if (location.search.length > 1)
		{
			cookieValue = location.search.substring(1, location.search.length);
		} else
		{
			// if there isn't a query string, then use the urchin information as the latest interest

			var urchinCookieValue = GetCookie('__utmz');
			var urchinOffset = urchinCookieValue.indexOf("u");
			var urchinGoodBits = urchinCookieValue.substring(urchinOffset);
			
			if (urchinCookieValue == null || urchinOffset == -1) 
			{
				// no urchin info to put in
				cookieValue = "no li";
			} else
			{
				// make the urchin cookie information more readable
				urchinGoodBits = urchinGoodBits.replace(/utmccn/, "Campaign")
				urchinGoodBits = urchinGoodBits.replace(/utmcsr/, "Source")
				urchinGoodBits = urchinGoodBits.replace(/utmctr/, "SearchTerms")
				urchinGoodBits = urchinGoodBits.replace(/utmcmd/, "Medium")
				urchinGoodBits = urchinGoodBits.replace(/ /g, "+")

				var urchinPrefix = "URCHIN:"
				urchinGoodBits = urchinPrefix.concat(urchinGoodBits)
				
				cookieValue = urchinGoodBits;
			}
		}
		
		if (cookieValue != GetCookie('li')) SetCookie('li', cookieValue, expDate);
	}
	
	if (cookieValue != null )
	{
		if (location.search.length > 1) 
		{
			cookieValue = location.search.substring(1, location.search.length);
		} else
		{
			// the URL doesn't contain a query string (campaign code)

			if( cookieValue.match("URCHIN:") == null )
			{
				// the latest interest is not URCHIN information
				// don't change anything
				
			} else
			{
				// the latest interest is URCHIN information, so update with latest urchin info

				var urchinCookieValue = GetCookie('__utmz');
				var urchinOffset = urchinCookieValue.indexOf("u");
				var urchinGoodBits = urchinCookieValue.substring(urchinOffset);
			
				if (urchinCookieValue == null || urchinOffset == -1) 
				{
					// no urchin info to put in
					cookieValue = "no li";
				} else
				{
					// make the urchin cookie information more readable
					urchinGoodBits = urchinGoodBits.replace(/utmccn/, "Campaign")
					urchinGoodBits = urchinGoodBits.replace(/utmcsr/, "Source")
					urchinGoodBits = urchinGoodBits.replace(/utmctr/, "SearchTerms")
					urchinGoodBits = urchinGoodBits.replace(/utmcmd/, "Medium")
					urchinGoodBits = urchinGoodBits.replace(/ /g, "+")

					var urchinPrefix = "URCHIN:"
					urchinGoodBits = urchinPrefix.concat(urchinGoodBits)
				
					cookieValue = urchinGoodBits;
				}
			}

			//cookieValue = "no li";
		}

		if (cookieValue != GetCookie('li')) SetCookie('li', cookieValue, expDate);
	}
// You can change the FORM location below
// where the referral ID is stored on your page
// You then access this element to get the ID
// document.FormName.id.value = id;
}

function readFI()
{
	var expDays = 365; // number of days the cookie should last
	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expDays)); 

	var cookieValue = GetCookie('fi');

	if (cookieValue == null || cookieValue == "no fi")
	{
		
		if (location.search.length > 1) 
		{
			// is there a query string? if so, then use that for the 'first intent' cookie
			cookieValue = location.search.substring(1, location.search.length);

		} else
		{
			// if there isn't a query string, then use the urchin information as the first intent

			var urchinCookieValue = GetCookie('__utmz');
			var urchinOffset = urchinCookieValue.indexOf("u");
			var urchinGoodBits = urchinCookieValue.substring(urchinOffset);
			
			if (urchinCookieValue == null || urchinOffset == -1) 
			{
				cookieValue = "no fi";
			} else
			{
				// make the urchin cookie information more readable
				urchinGoodBits = urchinGoodBits.replace(/utmccn/, "Campaign")
				urchinGoodBits = urchinGoodBits.replace(/utmcsr/, "Source")
				urchinGoodBits = urchinGoodBits.replace(/utmctr/, "SearchTerms")
				urchinGoodBits = urchinGoodBits.replace(/utmcmd/, "Medium")
				urchinGoodBits = urchinGoodBits.replace(/ /g, "+")

				var urchinPrefix = "URCHIN:"
				urchinGoodBits = urchinPrefix.concat(urchinGoodBits)
				
				cookieValue = urchinGoodBits;
			}
		}

		if (cookieValue != GetCookie('fi')) SetCookie('fi', cookieValue, expDate);
	}

// You can change the FORM location below
// where the referral ID is stored on your page
// You then access this element to get the ID
// document.FormName.id.value = id;
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

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 unescape(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=/" + 
	"; domain=equisys.com" +    
	((secure == true) ? "; secure" : "");
}
//  End -->

