﻿// Version-2.2.0.3

function AXProxy()
{
	this._control = null;
	this._registryName = "_no_regName_";
	this._oldRegistryName = "";
	this._migrationCompleted = false;
}

AXProxy.prototype.setControl = function(control)
{
	if (control != null)
	{
		this._control = control;
		// set the control to point to the correct registry name
		this._control.szCasino = this._registryName;
	}
	else
	{
		//alert("No valid fraud control found");
	}
}

AXProxy.prototype.setRegistryName = function(name)
{
	if (name != null)
	{
		this._registryName = name;
		
		// set the control to point to the correct registry name
		if (this._control != null)
		{
			this._control.szCasino = name;
		}
	}
}

AXProxy.prototype.getRegistryName = function()
{
	return this._registryName;
}

AXProxy.prototype.setGamingGroupName = function(name)
{
	if (name != null)
	{
		this._control.GamingGroup = name;
	}
}

AXProxy.prototype.setOldRegistryName = function(name)
{
	this._oldRegistryName = (name != null)? name : this._oldRegistryName;
}

AXProxy.prototype.getOldRegistryName = function()
{
	return this._oldRegistryName;
}

AXProxy.prototype.setValue = function(key, value, registryName)
{
	registryName = (registryName != null)? registryName : this._registryName;
	if (this._control != null)
	{
		// set the control to point to the correct registry name
		this._control.szCasino = registryName;
		// write value
		//alert(key + ' : ' + value);
		this._control[key] = value;
	}
	// reset control to point to the original registry name
	this.revertToDefaultRegistryName();
}

AXProxy.prototype.getValue = function(key, registryName)
{
	registryName = (registryName != null)? registryName : this._registryName;
	var value = "";
	if (this._control != null)
	{
		// set the control to point to the correct registry name
		this._control.szCasino = registryName;
		// read value
		value = this._control[key];
	}
	// reset control to point to the original registry name
	this.revertToDefaultRegistryName();
	// return value
	return value;
}

AXProxy.prototype.createShortcut = function(type)
{
	var registryName = (this._oldRegistryName != "")? this._oldRegistryName : this._registryName;
	this._control.szCasino = registryName;
	type = (type == null)? 0 : type;
	this._control.AddLink(type);
	this.revertToDefaultRegistryName();
}

AXProxy.prototype.doMigrationIfRequired = function()
{
	if (this.canWeDoMigration())
	{
		this.doMigration();
	}
	this._migrationCompleted = true;
}

AXProxy.prototype.canWeDoMigration = function()
{
	var migrate = false;
	
	if (this._oldRegistryName != "" && !this._migrationCompleted)
	{
		if (this.isOldLevelGuestOrReal())
		{
			if (this.isOnlyOldSSO())
			{
				migrate = true;
			}
			else if (this.isNewUpeLessThanOldUpe())
			{
				migrate = true;
			}
			else if (this.getValue("ID4") == "2")
			{
				migrate = true;
			}
		}
	}
	return migrate;
}

AXProxy.prototype.isOldLevelGuestOrReal = function()
{
	var oldLevel = this.getValue("ID4", this._oldRegistryName);
	
	return (oldLevel < 2);
}

AXProxy.prototype.isOnlyOldSSO = function()
{
	var oldSSO = this.getValue("SingleSignOn", this._oldRegistryName);
	var newSSO = this.getValue("SingleSignOn");
	
	return (oldSSO == 1 && newSSO == 0);
}

AXProxy.prototype.isNewUpeLessThanOldUpe = function()
{
	var oldUPE = this.getValue("UPE", this._oldRegistryName);
	var newUPE = this.getValue("UPE");
	
	return (newUPE < oldUPE);
}

AXProxy.prototype.doMigration = function()
{
	if (!this._migrationCompleted)
	{
		var keys = {};
		keys.LogUName = {key:"LogUName", defaultValue:""};
		keys.ReCall = {key:"ReCall", defaultValue:0};
		keys.ID1 = {key:"ID1", defaultValue:""};
		keys.ID3 = {key:"ID3", defaultValue:""};
		keys.ID4 = {key:"ID4", defaultValue:2};
		keys.ShowSignInDialog = {key:"ShowSignInDialog", defaultValue:0};
		keys.PPUserName = {key:"PPUserName", defaultValue:""};
		keys.PPKey = {key:"PPKey", defaultValue:""};
		keys.UPE = {key:"UPE", defaultValue:0};
		keys.SingleSignOn = {key:"SingleSignOn", defaultValue:0};
		
		for (var s in keys)
		{
			var value = this.getValue(keys[s]['key'], this._oldRegistryName);
			this.setValue(keys[s]['key'], value)
			this.setValue(keys[s]['key'], keys[s]['defaultValue'], this._oldRegistryName)
		}
	}
	
	this.revertToDefaultRegistryName();
	this._migrationCompleted = true;
}

AXProxy.prototype.revertToDefaultRegistryName = function()
{
	if (this._control != null)
	{
		this._control.szCasino = this._registryName;
	}
}
