/*********************************************************************
 *
 *		Cookie Reader/Writer for selection of 1st time user or not
 *
 *    	Created: 15th Nov 2000 - Cristiano Rastelli - Area Web
 *
 *********************************************************************/


/* myVisitor() -- reads the status of the Visitor out of the cookie and builds an object */

function getVisitorProfile() {


	// Verify the "First Time User" status 
	if ( document.cookie == "" ) {		// No cookie - Must be 1st time user, then...

		this.visitStatus = "newVisit"
		
	} else if ( getCookieStatus("everVisited") ) {	// "everVisited" cookies exist - Must have been here before
		
		// Test if visitor has been here recently... (true if "lastVisited" cookie not yet expired)
		this.visitStatus = ( getCookieStatus("lastVisited") ? "regVisit" : "expVisit" )
		
	} else {	// When in doubt... it's better to test again

		this.visitStatus = "newVisit"

	}

	// Test if visitor is "Flashed"...
	this.flashStatus = ( getCookieStatus("itisFlashed") ? "goFlash" : "" )
		
	// Test visitor's platform...
	this.platformStatus = getBrowserPlatform()

}





/* getCookieStatus() -- reads the status of the Visitor out of a cookie for a given variable */

function getCookieStatus(varName) {

	booleanTest = ( document.cookie.indexOf(varName) != -1 ) 
    return booleanTest;
}



/* setCookieStatus(varName, varValue, varExpireNumber, varExpireMeasure) -- write the name and value of a variable to a cookie  */

/*   everVisited 	= Has visitor ever been here ? (Cookie expiration measure is years)
     lastVisited 	= Has visitor recently been here ? (Cookie expiration measure is minutes)  
     itisFlashed	= Is the visitor Flash-enabled ?	
*/


function setCookieStatus(varName, varValue, varExpireNumber, varExpireMeasure) {

	// Calculate expire interval, in milliseconds
	if ( varExpireMeasure == "seconds" ) 		{ varExpireMillisec = varExpireNumber * 1000 }
	else if ( varExpireMeasure == "minutes" ) 	{ varExpireMillisec = varExpireNumber * 1000 * 60 }
	else if ( varExpireMeasure == "hours" ) 	{ varExpireMillisec = varExpireNumber * 1000 * 60 * 60 }
	else if ( varExpireMeasure == "days" ) 		{ varExpireMillisec = varExpireNumber * 1000 * 60 * 60 * 24}
	else if ( varExpireMeasure == "years" ) 	{ varExpireMillisec = varExpireNumber * 1000 * 60 * 60 * 24 * 365}

	// Set expiration date for the value to write to the cookie
	varExpireTime = new Date()
	varExpireTime.setTime(varExpireTime.getTime() + varExpireMillisec)	// in milliseconds

	document.cookie = varName + '=' + varValue + '; expires=' + varExpireTime.toGMTString() + '; path=/'

}





/* remCookieStatus(varName) -- write a null value to the cookie value to delete it  */

function remCookieStatus(varName) {

	varNow = new Date()
	varNow.setTime(varNow.getTime() - 1 )
	document.cookie = varName + '=""; expires=' + varNow.toGMTString() + '; path="/"'

}


/* getBrowserPlatform -- get the platform used by the browser client */

function getBrowserPlatform() {

    var platform

    if (navigator.appVersion.indexOf("Win") != -1) {
		platform = "Win"
    } else if (navigator.appVersion.indexOf("Macintosh") != -1) {
		platform = "Mac"
    } else if (navigator.appVersion.indexOf("X11") != -1) {
		platform = "Unx"
	}

    return platform

}

