
var TrackStat =
{
	trackStatURL: 'http://trackstat.net/',
	tracker: null,
	conversion_tracking_id: null,
	conversion_source_id: null,
	linkHolder: null,
	url: window.location,
	check_urls: null,
	found_urls: null,
	findVisitedLinks: null,
	vistedLinkColor: null,
	findLinkColor: null,
	hasLinkBeenVisited: null,
	sendVisitedLinks:null
}


TrackStat.tracker = function(SiteId)
{

	var has_js = 1;

	//var has_qt = detectQuickTime()
   	//var has_wm = detectWindowsMedia()

   	if(detectFlash())
   		var has_fl = 1;
   	else
   		var has_fl = 0;

   	if(navigator.javaEnabled())
   		var has_jv = 1;
   	else
   		var has_jv = 0;

   	if(document.title.length == 0)
   		page_name = escape(window.location);
   	else
   		page_name = escape(document.title);

	var stats;

	stats = 'pic=' + escape(SiteId);
	stats = stats + '&page_name=' + page_name;
	stats = stats + '&url=' + escape(window.location);
	stats = stats + '&ref=' + escape(document.referrer);
	stats = stats + '&width=' + screen.width;
	stats = stats + '&height=' + screen.height;
	stats = stats + '&depth=' + screen.colorDepth;
	stats = stats + '&has_js=' + has_js;
	stats = stats + '&has_jv=' + has_jv;
	stats = stats + '&has_fl=' + has_fl;
	stats = stats + '&conversion_tracking_id=' + conversion_tracking_id;
	stats = stats + '&conversion_source_id=' + conversion_source_id;

	url = "http://trackstat.net/tracker.jpg?"+stats;

	var img = document.createElement('img');
	img.src = url;
	document.body.appendChild(img);

	img.style.width = '0px';
	img.style.height = '0px';
	img.style.border = '0px';

}


var conversion_tracking_id;
var conversion_source_id;

function tracker(id)
{
	//Left for backwards compatibility
	TrackStat.conversion_tracking_id = conversion_tracking_id;
	TrackStat.conversion_source_id = conversion_source_id;
	TrackStat.tracker(id);
}


TrackStat.findVisitedLinks = function()
{
	TrackStat.linkHolder = document.createElement('div');
	TrackStat.linkHolder.id = "TrackStatLinkHolder";
	document.body.appendChild(TrackStat.linkHolder);

	//First Link, visited
	var link = document.createElement('a');
	link.href = window.location;
	link.id = "TrackStatTestLink1";
	TrackStat.linkHolder.appendChild(link);
	var link_color1 = TrackStat.findLinkColor(link);
	TrackStat.vistedLinkColor = link_color1;

	//Second link that is not visited
	var link2 = document.createElement('a');
	link2.href = 'http://youhaveneverbeenherebeforelinkdjfkdjfkdfjdk';
	link2.id = "TrackStatTestLink2";
	TrackStat.linkHolder.appendChild(link2);
	var link_color2 = TrackStat.findLinkColor(link2);

	if(link_color1 != link_color2)
	{
		//document.write('links do not match, checking. urls to check: '+TrackStat.check_urls.length);

		for (var loop = 0; loop < TrackStat.check_urls.length; loop++)
		{

			if(TrackStat.hasLinkBeenVisited(TrackStat.check_urls[loop]))
			{
				if(TrackStat.found_urls != null)
					TrackStat.found_urls = TrackStat.found_urls + TrackStat.check_urls[loop] + ',';
				else
					TrackStat.found_urls = TrackStat.check_urls[loop] + ',';
			}
			else
			{

			}
		}

		if(TrackStat.found_urls != null)
			TrackStat.sendVisitedLinks();
	}
	else
	{
		TrackStat.vistedLinkColor = '';
	}
}

TrackStat.sendVisitedLinks = function()
{

	var script = document.createElement("script");
	script.type = "text/javascript";
	script.charset = "utf-8";
	script.src = 'http://trackstat.net/HistoryTrackerPost.php?SiteId=9&found_urls=' + TrackStat.found_urls + '&noCacheIE=' + (new Date()).getTime();
	script.id = "TrackStatHistory";
	document.getElementsByTagName("head")[0].appendChild(script);
}

TrackStat.findLinkColor = function(link)
{
	if (link.currentStyle)
	{
		return link.currentStyle.color;
	}
	else
	{
		//link.setAttribute('href',window.location);
		var computed_style = document.defaultView.getComputedStyle( link, null );
		if (computed_style)
		{
			return computed_style.color;
		}
		return false;
	}
	return false;
}

TrackStat.hasLinkBeenVisited = function(url)
{

	var link = document.createElement('a');
	link.href = url;
	TrackStat.linkHolder.appendChild(link);

	if (link.currentStyle)
	{
		var color = link.currentStyle.color;
		if (color == TrackStat.vistedLinkColor)
			return true;
		return false;
	}
	else
	{
		link.setAttribute('href',url);
		var computed_style = document.defaultView.getComputedStyle( link, null );

		//document.write('<Br />'+computed_style.color +' == '+TrackStat.vistedLinkColor +' || '+url);

		if (computed_style)
		{
			if (computed_style.color == TrackStat.vistedLinkColor)
			{
				//document.write('<Br />match '+url);
				return true;
			}
			else
			{
				//document.write('<Br />no match '+url+TrackStat.vistedLinkColor);
				return false
			}
		}
		return false;
	}
}



//The code below was written by Apple Computer, Inc., and may still have their copyright
//even though their disclaimer/license says "but you are not permitted to redistribute it as
// "Apple sample code" after having made changes." which implies that you can redistribute it.
//Anyways, I'm saying this code isn't "Apple sample code" nor Trackstat's from here on down.


var javascriptVersion1_1 = false;
javascriptVersion1_1 = true;

// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) ||
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Director');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media Player');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
