
/*
 * Property Logging
 * v1.0
 */
 
var statServerHit = "/scripts/log.php?";
var statCookieName = "_ABC_Session";
var statCookieVal = "";

// send hits to server
function statLog(companycodes, site){
	
	var statCookieVal = getStatCookie(statCookieName);
	var unique = 0;
	
	if(statCookieVal == ""){	
		statCookieVal = Math.round(Math.random()*2147483647);
		setStatCookie(statCookieName,statCookieVal,1);
		unique = 1;
	}
	
	var page = encodeURIComponent(document.URL);
	docinfo = document;

	var url;

	url = statServerHit;
	url = url + "&sitename=" + site;
	url = url + "&unique=" + unique;
	url = url + "&codes=" + companycodes;
	url = url + "&usersess=" + statCookieVal;

	document.write('<img src="' + url + "&t=" + mTimeStamp() + '" height="1" width="1" style="display:none;" />');

	return;
}

function mTimeStamp()
{
	var thedate = new Date();
	var timestamp = 0;

	timestamp = (thedate.getDate() - 1) * 24 * 60 * 60;
	timestamp = timestamp + ((thedate.getHours() - 1) * 60 * 60);
	timestamp = timestamp +  ((thedate.getMinutes() - 1) * 60);
	timestamp = timestamp +  ((thedate.getSeconds() - 1));
	timestamp = timestamp + "." + thedate.getMilliseconds();

	return timestamp;
}

function setStatCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getStatCookie(c_name)
{
	if (document.cookie.length>0)
		{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			
			if (c_end==-1) c_end=document.cookie.length;
			
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
