/* 
	Tecknosfera DBNET S.L.
	Element: LIB DHTML
	Programed by: francisco_javier_martinez@hotmail.com
	To : Tecknosfera DBNET S.L.
*/

// Class to create Dynamic elements

function LIB_DHTML_object ()
{
	// Constructor
	this.LIB_DHTML_object = function ()
	{
	
	}
	
	// Function to create a LINK element
	this.createDynamicLink = function(container, href, linkText, className)
	{
		// Set on the Navigator TD the section to Load
		var tdNavigator = document.getElementById(container);
		var navigatorLink = document.createElement('a');
		navigatorLink.setAttribute('href',href)
		// The CLASS STYLE Atributhe is diferent to MIE and FIREFOX
		if (LIB_navigator.getName() == "Microsoft Internet Explorer")
		{
			navigatorLink.setAttribute('className',className);
		}
		else
		{
			navigatorLink.setAttribute('class',className);
		}
		
		navigatorLink.appendChild(document.createTextNode(linkText));
		return(navigatorLink);
	}
	
	/* ********************************************************************************************************************************************************* */
	// ******************* Include Functions
	/* ********************************************************************************************************************************************************* */
	
	// Function to create a Script include on current HTML page
	this.include = function (includeURL)
	{
		var theInclude = getInclude(includeURL)
		var head = document.getElementsByTagName("head").item(0);
		head.appendChild(theInclude);
	}
	
	// Function to create a Script include on current HTML page. Verify if exists or not exist the script
	this.include_once = function (scriptURL)
	{
		var head = document.getElementsByTagName("head").item(0);
		var contHeadNodes;
		for(contHeadNodes=0; contHeadNodes<head.childNodes.length; contHeadNodes++)
		{
			var headNode = head.childNodes[contHeadNodes];
			// If the actual node is an script node and the name is the same of my Script to include.. SKIP -> return(false)
			if(headNode.nodeName.toLowerCase() == "script" && headNode.getAttribute("src") == scriptURL)
			{
				return (false);
			}
		}
		// If not skeeped, include the file
		LIB_DHTML.include(scriptURL);
	}
	
	// Function to create the correspondent include
	function getInclude (theIncludeURL)
	{
		var theInclude = null;
		var typeOfInclude = theIncludeURL.split(".")[theIncludeURL.split(".").length - 1];
		switch (typeOfInclude)
		{
			case "js":
				theInclude = document.createElement("script");
				theInclude.setAttribute("language","javascript");
				theInclude.setAttribute("type","text/javascript");
				theInclude.setAttribute("src",theIncludeURL);
			break;
			
			case "css":
				theInclude = document.createElement("link");
				theInclude.setAttribute("rel","stylesheet");
				theInclude.setAttribute("type","text/css");
				theInclude.setAttribute("href",theIncludeURL);
			break;
		}
		return (theInclude);
	}
}

var LIB_DHTML = new LIB_DHTML_object();

