﻿// Version-1.3.0.2

/**
* The main Genie tracking object
* Only one of these to be created per page. 
* Properties set are passed to created tracking objects
*/
function Genie()
{
	this.imgId = "trackingImg"; // default tracking image id
	this.url = "";
	this.currentGUID = "";
	this.newGUID = "";
	this.stepId = "";
	this.casinoId = "";
	this.clientTypeId = "";
	this.browserLang = "";
	this.clientLang = "";
	this.btag = ""
	this.browser = "";
	this.os = "";
	this.ipAddress = "";
	this.flashPlayerVersion = null;
}

/**
* Create and return a tracking object
*/
Genie.prototype.getTrackingObj = function()
{
	var dataObj = new GenieTrackingObj(this);
	return dataObj;
}

/**
* Read the current tracking GUID from cookie
*/
Genie.prototype.getTrackingGUID = function(noCookie)
{
	if (!noCookie) {
		this.currentGUID = GetCookie("genieGUID");
	}

	if ((this.currentGUID == null) || (this.currentGUID == "" && this.newGUID != "")) {
		this.currentGUID = this.newGUID;
		SetCookie("genieGUID", this.currentGUID, months*60);
	}
	return this.currentGUID;
}

/**
* Constructor for tracking object
* This object will inherit the values set in the Genie object and will send a tracking event
*/
function GenieTrackingObj(data) 
{
	// optional values. will not be passed if value are null
	this.alert = null;
	this.playerLoginName = null;
	this.regType = null;
	this.userIdentifier = null;

	// set tracking object values from Genie object values
	for (x in data) {
		if (typeof data[x] == "string") {
			this[x] = data[x];
		}
	}
}
GenieTrackingObj.prototype = new Genie();

/**
* Send a tracking event using the img tag with given id
*/
GenieTrackingObj.prototype.send = function(doAJAX)
{
	var img = document.getElementById(this.imgId);
	//var params = this.url + "?";
	var params = "StepId=" + escape(this.stepId);
	params += "&CasinoId=" + escape(this.casinoId);
	params += "&ClientTypeId=" + escape(this.clientTypeId);
	params += "&PCMGUID=" + escape(this.currentGUID);
	if (this.newGUID != this.currentGUID && this.newGUID != "") {
		params += "&UnusedPCMGUID=" + escape(this.newGUID);
	}
	params += "&BrowserLang=" + escape(this.browserLang);
	params += "&ClientLang=" + escape(this.clientLang);
	params += "&BTag=" + escape(this.btag);
	params += "&Browser=" + escape(this.browser);
	params += "&OS=" + escape(this.os);
	params += "&IPAddress=" + escape(this.ipAddress);
	
	if (this.alert != null && this.alert != "") {
		params += "&Alert=" + escape(this.alert);
	}
	if (this.playerLoginName != null && this.playerLoginName != "") {
		params += "&PlayerLoginName=" + escape(this.playerLoginName);
	}
	if (this.regType != null && this.regType.toString() != "") {
		params += "&RegType=" + escape(this.regType);
	}
	if (this.userIdentifier != null && this.userIdentifier != "") {
		params += "&UserIdentifier=" + escape(this.userIdentifier);
	}
	if (this.flashPlayerVersion != null) {
		params += "&FlashPlayerVersion=" + escape(this.flashPlayerVersion);
	}
	
	if (!doAJAX) 
	{
		img.src = this.url + "?" + params;
	}
	else
	{
		xhReq = createXMLHttpRequest();
		xhReq.open("POST", "genie.asp?trackingUrl=" + this.url, true);
		xhReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhReq.onreadystatechange = onSumResponse;
		xhReq.send(params);
	}
}

var xhReq = new Object();

function createXMLHttpRequest() 
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
}

function onSumResponse() 
{
	if (xhReq.readyState != 4)  { return; }
	var serverResponse = xhReq.responseText;
}