﻿/** @singleton */
Netxion                      = {__package:1};/** @singleton */
Netxion.Collections          = {__package:1};/** @singleton */
Netxion.Drawing              = {__package:1};/** @singleton */
Netxion.Data                 = {__package:1};/** @singleton */
Netxion.Data.Sql             = {__package:1};/** @singleton */
Netxion.Encryption           = {__package:1};/** @singleton */
Netxion.Net                  = {__package:1};/** @singleton */
Netxion.Ui                   = {__package:1};/** @singleton */
Netxion.Ui.Animation         = {__package:1};/** @singleton */
Netxion.Ui.Controls          = {__package:1};/** @singleton */
Netxion.Ui.Devices           = {__package:1};/** @singleton */
Netxion.Ui.Input             = {__package:1};/** @singleton */
Netxion.Web                  = {__package:1};/** @singleton */
Netxion.Xml                  = {__package:1};/** @singleton */
Netxion.Xml.Dbml             = {__package:1};/** @singleton */
Netxion.Xml.Soap             = {__package:1};/** @singleton */
Netxion.Xml.Rss              = {__package:1};


/** Netxion utillity class, supplies basic functionality @singleton */
Netxion.Util = 
{
	/** Debug indication, if set to true script's will with .src reference.
	* <div style="color:#FF0000;">This will throw an error in Internet Explorer browsers, debugging should be done with a Gecko browser.</div>
	* @type Boolean
	*/
	debug: false,

	/** Global object list, used for gobal identification eg. asynchronous operations @type Object[] */
	objects: [],

	/** Reference to a pre tag created on first use of debugWrite() @type HTMLElement */
	_debugWritePre: null,
	
	_scripts: [],
	_scriptBoot: "Netxion.js",
	_scriptRoot: "",
	_scriptSize: 0,

	/** Get a new XMLHttpRequest @type XMLHttpRequest */
	getXmlHttpRequest: function()
	{
		if(typeof XMLHttpRequest != "undefined"){return new XMLHttpRequest();} 
		if(typeof ActiveXObject != "undefined")
		{
			var progids = ["MsXml2.XmlHttp.6.0", "MsXml2.XmlHttp.4.0", "MsXml2.XmlHttp.3.0", "Microsoft.XmlHttp"];
			for(var i=0; i<progids.length; i++)
			{
				try{obj = new ActiveXObject(progids[i]); return obj;}
				catch(x){}
			}
		}
		return null;
	},

	/** Get a new XMLDocument @type XMLDocument */
	getXmlDocument: function()
	{
		if(navigator.appName.indexOf("Microsoft")==-1){return document.implementation.createDocument("", "", null);}
		if(typeof ActiveXObject != "undefined")
		{
			var progids = ["MsXml2.DomDocument.6.0", "MsXml2.DomDocument.4.0", "MsXml2.DomDocument.3.0", "Microsoft.XmlDom"];
			for(var i=0; i<progids.length; i++)
			{
				try{obj = new ActiveXObject(progids[i]); return obj;}
				catch(x){}
			}
		}
		return null;
	},

	/** Include scripts on the fly */
	include: function(sScript)
	{
		if(this._scripts.length == 0)
		{
			var str_find = "Netxion.js";
			this._scripts   = [];
			this._scriptRoot = "";
			this._scriptSize = 0;

			var arrScript = document.documentElement.getElementsByTagName("script");
			for(var i=0; i<arrScript.length; i++)
			{
				this._scripts.push(arrScript[i].src.split("/").pop());
				if(arrScript[i].src.split("/").pop() == this._scriptBoot)
					this._scriptRoot = arrScript[i].src.substr(0, arrScript[i].src.length - this._scriptBoot.length);
			}
		}

		for(var i=0; i<this._scripts.length; i++)
			if(this._scripts[i].split("/").pop().toLowerCase() == sScript.toLowerCase())
				return;


		this._scripts.push(sScript);
		var objHttp = this.getXmlHttpRequest();
		objHttp.open("GET", this._scriptRoot + sScript, false);
		objHttp.send(null);
		if(objHttp.status>400){throw new Error("Failed to load '" + this._scriptRoot + sScript + "' (HTTP" + objHttp.status + ")"); return;}
	
		var script   = document.createElement("script");
		script.type  = "text/javascript";

		try{script.appendChild(document.createTextNode(objHttp.responseText + ";"));}
		catch(x){script.text = objHttp.responseText + ";";}
		this._scriptSize += objHttp.responseText.length;

		if(this.debug){script.src = this._scriptRoot + sScript; script.defer = false;}

		document.getElementsByTagName("head")[0].appendChild(script);
	},
	
	/** writes a line of debugging information */
	debugWrite: function(sString)
	{
		if(this._debugWritePre == null){this._debugWritePre = document.body.appendChild(document.createElement("pre"));}
		this._debugWritePre.innerHTML += sString + "<br />";
	}
};

/** Netxion globalization class @singleton */
Netxion.Globalization = {
	file: "/classes/lang/1033.xml",
	xmlDocument: null,
	loaded: false,
	getText: function(sClassMember)
	{
		var strRet = null;
		var objNode = this.getNode(sClassMember);
		if(objNode!=null){strRet = objNode.getAttribute("text");}
		return strRet != null? strRet: "";
	},
	getTitle: function(sClassMember)
	{
		var strRet = null;
		var objNode = this.getNode(sClassMember)
		if(objNode!=null){strRet = objNode.getAttribute("title");}
		return strRet != null? strRet: "";
	},
	getNode: function(sClassMember)
	{
		if(!this.loaded){return null;}
		var arrPath = sClassMember.split(".");
		var objNode = this.xmlDocument;
		if(arrPath.length>0)
		{
			for(var i=0; i<arrPath.length; i++)
			{
				if(objNode == null){break;}
				objNode = objNode.getElementsByTagName(arrPath[i])[0];
			}
		}

		return objNode;
	},

	init: function()
	{
		if(this.file!="")
		{
			this.xmlDocument = Netxion.Util.getXmlDocument();
			this.xmlDocument.async = false;
			//this.loaded            = this.xmlDocument.load(this.file);
		}
	}
};
Netxion.Globalization.init();

