//Parameters: cPageName, cReferrer
//If cPageName is NOT set - store page name in it.
//If cReferrer is NOT set - store page referrer in it.
//Sample:
//Log defult values:
//<script SRC="Logme.js"></script>
//Preset Page name and referrer:
//<Script>
//var cPageName="Page-Name", cReferrer=document.cookie
//<script SRC="Logme.js"></script>
//
//
//

highLightLink()

var dDate = new Date(), nMonth, nDay, nYear, newDate, cCookie = document.cookie, dDate = new Date(), 
	nSecs = dDate.getSeconds() + dDate.getMinutes() * 60, nMinute = dDate.getMinutes(), nHour = dDate.getHours(), 
	cDomain = ".abeautifulbedroom.com", aCookie, cKey = "", cValue = "", nGglPlace=0, cKeyWord="", 
	cLocationHref = document.location.href;

if (cCookie.indexOf("Reff=") == -1)
	{
	nMonth = dDate.getMonth() + 3;
	nYear = dDate.getFullYear();
	nDay = dDate.getDate();
	if (nMonth > 12)
		{
		nMonth = nMonth - 12;
		nYear = nYear + 1;
		}
	newDate = new Date(nYear, nMonth, nDay)
	document.cookie = "Reff=" + document.referrer + ";expires=" + newDate + ";domain=" + cDomain + ";path=/;";
	}

if (typeof(cPageName)=="undefined")
	{
	var _Str = String(document.location),
		_Place = _Str.lastIndexOf("/") + 1,
		cPageName = unescape(_Str.substr(_Place ))
	}

if (typeof(cReferrer)=="undefined")
	{
	cReferrer = document.referrer
	}

if (cPageName == "")
	{
	cPageName = "/"
	}

//If no cLogmeID set, we create new one, otherwise, we just change the date for 1/2 later.
if (cCookie.lastIndexOf("cLogmeID") == -1)
	{
	cValue = String(Math.random());
	cValue = cValue.substr(cValue.length - 15);
	cValue = "_" + cValue.replace(" ","0");
	}
	else
	{
	aCookie = cCookie.split("; ");
	cValue = "";
	for (i=0; i<aCookie.length; i++)
		{
		cKey = aCookie[i].substr(0, aCookie[i].indexOf("="));
		if (cKey == "cLogmeID")
			{
			cValue = aCookie[i].substr(aCookie[i].indexOf("=") + 1);
			i = aCookie.length;
			}
		}
	}

//Here we advance the expiration for 1/2 ahead
nMonth = dDate.getMonth();
nYear = dDate.getFullYear();
nDay = dDate.getDate();
nMinute = nMinute + 30
if (nMinute > 60)
	{
	nMinute = nMinute - 60
	nHour = nHour + 1
	}

newDate = new Date(nYear, nMonth, nDay, nHour, nMinute)
document.cookie = "cLogmeID=" + cValue + ";expires=" + newDate + ";domain=" + cDomain + ";path=/;";

//This trigger ?ggl that should be placed in the address of the landing page from adWords of Google.
//When found, will figure the keyword and store with the referral of the exit page.
nGglPlace = cLocationHref.indexOf("?ggl")
cKeyWord = "No_Google_AdWords"
if (nGglPlace > -1)
	{
	nGglPlace = cReferrer.indexOf("&q=")
	if (nGglPlace > -1)
		{
		cKeyWord = cReferrer.substr(nGglPlace + 3)
		if (cKeyWord.indexOf("&") > -1)
			{
			cKeyWord = cKeyWord.substr(0, cKeyWord.indexOf("&"))
			}
		}
	}

//This save referal URL for the tCart thanks page.
if (cCookie.lastIndexOf("_VisitReferal=") == -1 && cReferrer.length > 0)
	{
	nMonth = nMonth + 1
	if (nMonth > 12)
		{
		nMonth = nMonth - 12
		nYear = nYear + 1
		}
	newDate = new Date(nYear, nMonth, nDay, nHour, nMinute)
	document.cookie = "_VisitReferal=" + document.referrer + "___" + cLocationHref + "___" + cKeyWord + "___VisitDate_" + dDate.toString() + ";expires=" + newDate + ";domain=" + cDomain + ";path=/;";
	}

var _Img = new Image();

//If page is on secure server will not log it, so no browser will not show errors. 
var _Str = String(document.location)

if (_Str.substr(0,5) != "https")
	{
	reloadSrc(cPageName)
	}


function reloadSrc(_PageName)
	{
	_Img.src="http://www.Website-Tracking.com/Logme/FoxLog.dll/logme.logme.Logme?ABBR," + 
		escape(_PageName) + " ," + escape(cReferrer) + " ," + window.navigator.appVersion + " ," + 
		window.screen.width + " ," + cValue
	}

function sendClick(cTitle, cHref)
    {
	reloadSrc(cTitle)
    window.setTimeout('window.location.href="' + cHref + '"',1500);
    }


function highLightLink() {
	var aLinks = document.getElementsByTagName("A"), x, nLen, cPage, cHref, cParPage0, cParPage1, cParPage2
	for (x=0;x<aLinks.length;x++)
		{
		cPage = document.location.href.substr(document.location.href.lastIndexOf("/"))
		cHref = aLinks[x].href.substr(aLinks[x].href.lastIndexOf("/"))
		if (aLinks[x].className == "topMenuLinks" && (cPage == cHref || cPage == "/" && cHref == "/index.html"))
			{
			aLinks[x].style.borderStyle = "inset"
			aLinks[x].style.borderWidth = "1px"
			aLinks[x].style.backgroundColor="#FFD3A8"
/*
			aLinks[x].style.borderTop="1px solid #663300"
			aLinks[x].style.borderLeft="1px solid #663300"
			aLinks[x].style.borderRight="1px solid #CC6600"
			aLinks[x].style.borderBottom="1px solid #CC6600"
*/
			}
		}
	}
