// JavaScript Document
// Load the given JavaScript file. This function is good for on-demand loading and when
// loading files based on the AJAX response

function ImportJavaScript(sourceUrl)
{
	// The basic script is simple, create the SCRIPT object and add it to HTML DOM
	var scriptElem = document.createElement("script");
	scriptElem.src = sourceUrl;
	scriptElem.type = "text/javascript";
	
	// Append this to header object
	document.getElementsByTagName("head")[0].appendChild(scriptElem);
}

// Load the given CSS file. This function is good for on-demand CSS loading
var loadedCssFiles = new Array();
var loadedColorCss= null;
function ImportCss(sourceUrl)
{
	//UnloadCss(sourceUrl);
	UnloadPrevouisCssElem();

	//// First check if we browser can directly load the CSS file
	//if(document.createStyleSheet)
	//	document.createStyleSheet(sourceUrl);
	//else
	//{
		// Load the CSS using the DHTML (create Link tag and add it to header)
		var linkElem = document.createElement("link");
		linkElem.rel="stylesheet";
		linkElem.type = "text/css";
		linkElem.href = sourceUrl;
		
		// Append this to header object
		document.getElementsByTagName("head")[0].appendChild(linkElem);
		//loadedCssFiles.push(linkElem);
		
		loadedColorCss = linkElem;
	//}
}

function UnloadCss(sourceUrl) {
	for(var temp in loadedCssFiles) {
		if(loadedCssFiles[temp].href == sourceUrl) {
			document.getElementsByTagName("head")[0].removeChild(loadedCssFiles[temp]);
			alert("css entfernt");
			loadedCssFiles.splice(loadedCssFiles.length-1, 1);
		}
	}
}

function UnloadPrevouisCssElem() {
	if(loadedColorCss != null) {
		document.getElementsByTagName("head")[0].removeChild(loadedColorCss);
	}
}

//So whererver you need to load a JavaScript or CSS file in your code, you can do something like this:
//ImportJavaScript(“/Library/XYZ/MyJavaScript.js”);
//ImportJavaScript(“/CSS/AddPanel.css”);