// associative array of included js files
var js_files = new Array();
// associative array of included css files
var css_files = new Array();

// include js or css file only once into the head tag of the html page
function include_once(type, fullFilePath, isFile)
{
	// include the file only if it's not already included
	if (type == 'js')
	{
		if (isFile == 'file')
		{
			// it's a file, include it
			if (js_files[fullFilePath] == undefined)
			{
				var scriptElement = document.createElement("script");
				scriptElement.setAttribute('type', 'text/javascript');
				scriptElement.setAttribute('src', fullFilePath);
				document.getElementsByTagName("head")[0].appendChild(scriptElement);

				// add file to global associateve array of included files
				js_files[fullFilePath] = 1;
			}
		}
		else
		{
			// need to execute the script
			var scriptElement = document.createElement("script");
			scriptElement.setAttribute('type', 'text/javascript');
			// script can not have children, use text instead (appendChild to text)
			scriptElement.text = fullFilePath;
			document.getElementsByTagName("head")[0].appendChild(scriptElement);
		}
	}
	else if (type == 'css')
	{
		if (css_files[fullFilePath] == undefined)
		{
			var linkElement = document.createElement("link");
			linkElement.setAttribute('rel', 'stylesheet');
			linkElement.setAttribute('type', 'text/css');
			linkElement.setAttribute('media', 'screen');
			linkElement.setAttribute('href', fullFilePath);
			document.getElementsByTagName("head")[0].appendChild(linkElement);

			// add file to global associateve array of included files
			css_files[fullFilePath] = 1;
		}
	}
}
