﻿var apiTimeoutMsecs = 200;

function GetAgentId(callback, data) {
    if (!dev) {
        callback(null);
        return;
    }

	var apiUrl = 'https://agentid.radionomy.com/get/website';
	if (dev) {
		apiUrl = 'http://agentid.radionomy.local/get/website';
	}

	if (data) {
		apiUrl += '?d=' + btoa(data);
	}

	// Force callback if api doesn't respond in time
	var timeouted = false;
	var timeout = setTimeout(function () {
		timeouted = true;
		callback(null);
	}, apiTimeoutMsecs);

	$.get(apiUrl, function (result) {
		if (timeouted) return;

		callback(result);

		clearTimeout(timeout);
	})
	.fail(function () {
		clearTimeout(timeout);
		callback(null);
	});
}

function GetAgentToken() {
	return 'xxxxxxxxxxxxxxxxxxxx'.replace(/x/g, function (c) { return ((Math.random() * 16) | 0).toString(16) });
}