//*************************************************************************************************
//
// File Name: firsttime.js
// Author: An Dang (FMS)
// Created: 07/30/07
// Main function: Determines if a visitor is coming from first time visitor page and displays 
// 		  a link to go back to that page.  It also adds a tracking mechanism to viewed pages.
//
//*************************************************************************************************

<!--

var lHist;
var lVal = document.referrer;
var lTitle = document.title;

lTitle = lTitle.replace(": Financial Management Service","");
lTitle = lTitle.replace(": U.S. Department of the Treasury","");
lTitle = lTitle.replace(": The Financial Management Service","");
lTitle = lTitle.replace(": About FMS","");

if (lVal.match('aboutfms/firstvisit'))
{	createCookie('fmsFirst',lVal,0); 
	document.write ("<p class='smallfont'><img src='http://fms.treas.gov/_images/right_arrow_white.gif' width='8' height='10' alt='white arrow' border='0'> <a href='/aboutfms/firstvisit.html'><font color='white'><b>First-Time Visitors</b></font></a></p>");  
}
else
{
	lVal = readCookie('fmsFirst');
	if (lVal != null)
	{
	if (lVal.match('aboutfms/firstvisit'))
		{  document.write ("<p class='smallfont'><img src='http://fms.treas.gov/_images/right_arrow_white.gif' width='8' height='10' alt='white arrow' border='0'> <a href='/aboutfms/firstvisit.html'><font color='white'><b>First-Time Visitors</b></font></a></p>");  }
	}
}

lHist = readCookie('fmsHist');
if (lHist == null)
{ lHist = ''; 
createCookie('fmsHist',lHist + "- <a href='" + document.URL + "'><b>" + lTitle + "</a></b><br>",0);  
}

if (lHist.match(lTitle))
{  //Do nothing 
}
else
{ 
createCookie('fmsHist',lHist + "- <a href='" + document.URL + "'><b>" + lTitle + "</a></b><br>",0);  
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//-->

