// pad t to the left with places# of zeros
function lpadzeros(t,places)
{
	var temp = t;
	temp = '000000' + t;
	temp = temp.substr(temp.length - places);
	return temp;
}
	
function getTdate()
{
	var tdate = new Date();
	tdate = tdate.getUTCFullYear() + '-' + lpadzeros(tdate.getUTCMonth()+1,2) + '-' + lpadzeros(tdate.getUTCDate(),2) + '_' + lpadzeros(tdate.getUTCHours(),2) + '.' + lpadzeros(tdate.getUTCMinutes(),2) + '.' + lpadzeros(tdate.getUTCSeconds(),2) + '.' + tdate.getUTCMilliseconds();
	return tdate;
}

// Create a cookie
function writeCookie(cookieName, cookieValue, expires, domain, path, secureFlag)
{
   if (cookieName)
   {
      var cookieDetails = cookieName + '=' + escape(cookieValue);
      cookieDetails += (expires ? '; expires=' + expires.toGMTString(): '');
      cookieDetails += (domain ? '; domain=' + domain: '');
      cookieDetails += (path ? '; path=' + path: '');
      cookieDetails += (secureFlag ? '; secure': '');
      document.cookie = cookieDetails;
   }
}

// Obtain a cookie's value
function readCookie(cookieName)
{
   cookieValue = readUnescapedCookie(cookieName)

   if (cookieValue != null)
   {
      cookieValue = unescape(cookieValue);
   }

   return cookieValue;
}

// Obtain a cookie's unescaped value
function readUnescapedCookie(cookieName)
{
   var cookieValue = document.cookie;
   var cookieRegExp = new RegExp('\\b' + cookieName + '=([^;]*)');
   cookieValue = cookieRegExp.exec(cookieValue);

   if (cookieValue != null)
   {
      cookieValue = cookieValue[1];	
   }
   return cookieValue;
}

// delete cookie to start over
//writeCookie('csistats', '');

// Read csistats cookie. If it is undefined, save the current date/time.
// If it is defined, do nothing.
var cookieName = 'csistats';
var cookieValue = readCookie(cookieName);
if (cookieValue=='undefined' || cookieValue==null || cookieValue=='' || cookieValue=='false')
{
	cookieValue = getTdate();
	var expires = new Date('12-31-2006');
	writeCookie(cookieName, cookieValue, expires);
}

// load a tiny picture in order to determine screen width, height, and color depth
document.writeln("<img width='1' height='1' src='/log_analysis_screen_info.gif?" + "width=" + screen.width + "&height=" + screen.height + "&depth=" + screen.colorDepth + "&tdate=" + getTdate() +"'>");