// see if cookie exists
var str = readCookie("FirstPageVisited") + "";

// set cookies w/ entry page and date info - *ONLY ONCE*
if(str.length == 0){
	var date = new Date();
	var day  = date.getDate();
	var month = date.getMonth() + 1;
	var yy = date.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	var dte = month + "/" + day + "/" + year
	createCookie("FirstPageVisited", window.location, 900);
	createCookie("FirstPageVisitedDate", dte, 900);
}


function PopulateFirstPageVisited(){

	// pass the cookie data to the html forms

	if(document.f1){
		document.f1.FirstPageVisited.value = readCookie("FirstPageVisited");
		document.f1.FirstPageVisitedDate.value = readCookie("FirstPageVisitedDate");
	}

	if(document.questionform){
		document.questionform.FirstPageVisited.value = readCookie("FirstPageVisited");
		document.questionform.FirstPageVisitedDate.value = readCookie("FirstPageVisitedDate");
	}
}

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 = "";
	var ck = name+"="+value+expires+"; path=/";
	document.cookie = ck;
}

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 '';
}