// Report Kit main file
// Known supported browsers: Internet Explorer 6 and 7, Mozilla Firefox 2 and 3, Konqueror and Opera

// Create a script tag
function javascript_tag(path) {
	return '<sc' + 'ript type="text/javascript" src="' + path + '" charset="utf-8"></sc' + 'ript>\n';
}

// Create a CSS tag
function css_tag(path) {
	return '<link href="' + path + '.css" media="screen" rel="stylesheet" type="text/css" />\n';
}

// Validate that the id attribute of the script tag is present
if (!document.getElementById('report_kit_script') ||
     document.getElementById('report_kit_script').tagName != 'SCRIPT')
	alert('Error! Do not remove the unique id attribute of the ReportKit script tag.');

// Get the directory where this file is located
var base_dir = document.getElementById('report_kit_script').getAttribute('src').replace('report_kit.js','');

// Load configuration by requesting the file using Sjax
var xmlhttp;
try {
	xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest():
	new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { /* do nothing */ }

xmlhttp.open('GET', base_dir + 'config.txt', false);
xmlhttp.setRequestHeader('Accept','text/plain');
xmlhttp.send(null);
var json = xmlhttp.responseText;
// Security test suggested in the JSON RFC
var config = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
		json.replace(/"(\\.|[^"\\])*"/g, ''))) &&
		eval('(' + json + ')');

// Attach dependencies
document.write( javascript_tag(config.url) );

document.write( css_tag(base_dir + 'themes/' + config.theme + '/style') );

for (var i=0; i < config.js.length; i++) {
	document.write( javascript_tag(base_dir + config.js[i] + '.js') );
}
