///
/// Depends on TAG system
///
var $__getADT = function() {
	var loggerMessages = [];
	var log = function(message, level) {
		loggerMessages.pop(message);
	};

	String.isNullOrEmpty = function(str) {
		return str == undefined || str == null || /^\s*$/.test(str); ;
	}

	var ADT = function() {
	};

	ADT.inited = false;

	ADT.BEUrl = "http://adt.capatest.net/execute.ashx";
	ADT.stack = [];

	ADT.UserId = null;

	var track = function(campaignId) {
		var BE = new Protocol(ADT.BEUrl);
		var params = [];
		if (ADT.UserId != null) {
			log('Send LogVisit() request');
			params = [document.location, campaignId, ADT.UserId];
		} else {
			log('User information absent');
			params = [campaignId];
		}
		BE.execute('LogVisit', params,
				function(data) {
					log('Requested completed: ' + data.Message);
				},
				function(code, response) {
					log('Failed with code ' + code);
				});

	};


	ADT.track = function(campaignId) {
		if (ADT.inited == false) {
			ADT.stack.push(campaignId);
			return;
		}

		track(campaignId);
	};
	if (typeof ($___TAG) == 'undefined') {
		$__TAG.GetUser(function(userId) {
			ADT.inited = true;
			ADT.UserId = userId;
			for (var i = 0; i < ADT.stack.length; i++) {
				track(ADT.stack[i]);
			}
			ADT.stack = [];
		});
	} else {
		log('Tag system is not present');
	}

	return ADT;
};

window.$__ADT = $__getADT();




