/*
Start Configuration
*/
if(typeof(xLibPath)=='undefined'){
	var xLibPath = '/JSlibrary/';
}
// End Configuration

var w    = window;
w.d      = document;
w.w      = window;
w._      = null;
d.w      = d.write;
var moz  = document.implementation.hasFeature("XPath", "3.0");
var IE   = !moz;

var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
//if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

w.missingArgs = 'Error in {f}: required arguments not provided.';

__=function stringNamespace(){
	String.prototype.suplant=function(o){var s=this;for(i in o)s=s.replace(new RegExp('{'+i+'}','gi'),o[i]);return s;}
}();

/*
Namespace: necessary functions
------------------------------
functions that need to be defined before -anything- else
------------------------------
*/
__=function necessaryNamespace(){
	/*
	Function: undefined [w.uD]
	--------------------------
	returns true if object is undefined
	--------------------------
	*/
	function uD(e) {return typeof(e)=='undefined';}

	/*
	Function: undefined or null [w.uDN]
	-----------------------------------
	returns true if object is undefined or null
	-----------------------------------
	*/
	function uDN(e){return uD(e)||e==_;}

	w.uD     = uD;
	w.uDN    = uDN;
}();

/*
Namespace: event cache
----------------------
caches events so that more than one event per action can be added, and events can be removed
----------------------
*/
__=function eventCacheNamespace(){
	/*
	Function: add event [w.addEvent]
	--------------------------------
	add an event to an object
	--------------------------------
	0 o : 
	1 e : 
	2 f : 
	3 c : 
	*/
	function aE(o,e,f,c){if(uDN(o))return; if(c)eventCache.flush(o, e); if(o.attachEvent){o.attachEvent("on"+e,f);} else if(o.addEventListener){o.addEventListener(e, f, true);} else if(typeof o[e] == "function"){var d = o[e];o[e] = function(e){ d(e); f(e); };} else {o[e] = f;};eventCache.add(o, e, f, true);};

	/*
	Function: remove event [w.removeEvent]
	--------------------------------------
	remove an event from an object
	--------------------------------------
	0 o : 
	1 e : 
	2 f : 
	*/
	function rE(o,e,f){if(o.detachEvent){o.detachEvent("on"+e,f);} else if(o.removeEventListener){o.removeEventListener(e, f, true);} else if(typeof o[e]=="function"){o[e]=null;}}

	/*
	Function: get to parent [w.getToParent]
	---------------------------------------
	returns a reference to the first parent node of a specified type
	if no node is found, returns a reference to document
	---------------------------------------
	0 o  : 
	1 nN : 
	*/
	function gTP(o, nN){
		while(!uDN(o) && o.nodeName!=nN && o!=d) o=o.parentNode;
		return o;
	}

	/*
	Function: get first sibling [w.getFirstSib]
	-------------------------------------------
	returns a reference to the first sibling of a specified type.
	-------------------------------------------
	0 o  : 
	1 nN : 
	*/
	function gFS(o, nN){
		while(!uDN(o) && o.nodeName!=nN) o=o.nextSibling;
		return o;
	}

	/*
	Object: event cache
	-------------------
	-------------------
	*/
	var eventCache = function(){
		var listEvents = [];

		return {
			listEvents:listEvents,

			/*
			Function: add event [not exposed]
			---------------------------------
			0 node
			1 sEventName
			2 fHandler
			3 bCapture
			*/
			add:function(){listEvents.push(arguments);},

			/*
			Function: fire events [w.fireEvents]
			------------------------------------
			executes any events attached to an object->event.
			------------------------------------
			0 o : object
			1 e : event
			*/
			fE:function(o,e){
				for(var i=0; i<listEvents.length; i++){
					var item = listEvents[i];
					if(!uD(o)&&!uD(e)&&item[0]!=o||item[1]!=e) continue;

					item[2]();
				}
			},

			/*
			Function: clone events [w.cloneEvents]
			--------------------------------------
			copies events from one object to another
			--------------------------------------
			0 s : source
			1 t : target
			*/
			clE:function(s,t){
				for(var i=0; i<listEvents.length; i++){
					var item = listEvents[i];
					if(uD(s)||uD(t)||item[0]!=s) continue;
					aE(t, item[1], item[2]);
				}
			},

			/*
			Function: flush events [w.flushEvents]
			--------------------------------------
			removes events from an object
			--------------------------------------
			 0 o  : source object
			[1 e] : event name
			*/
			flush:function(o,e){
				var i, item;
				for(i = listEvents.length - 1; i >= 0; i = i - 1){
					item = listEvents[i];
					if(!uD(o)&&!uD(e)&&item[0]!=o||item[1]!=e) continue;

					if(item[0].removeEventListener){item[0].removeEventListener(item[1], item[2], item[3]);};
					if(item[1].substring(0, 2) != "on") item[1] = "on" + item[1];
					if(item[0].detachEvent) item[0].detachEvent(item[1], item[2]);

					item[0][item[1]] = null;
				};
			}
		};
	}();

	// Event Cleanup - helps to prevents memory leaks
	var clearElementProps = ['data', 'onload', 'onmousemove', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'ondblclick', 'onclick', 'onselectstart', 'oncontextmenu'];

	aE(w, "unload", function(){
		var el;
		for(var i = d.all.length;i--;){
			el = d.all[i];
			for(var c = clearElementProps.length;c--;) el[clearElementProps[c]] = null;
		}
	});

	aE(w, "unload", function(){ eventCache.flush(); });

	w.fireEvents  = eventCache.fE;
	w.cloneEvents = eventCache.clE;
	w.addEvent    = aE;
	w.removeEvent = rE;
	w.flushEvents = eventCache.flush;
	w.getToParent = gTP;
	w.getFirstSib = gFS;
}();

/*
Namespace: general
------------------------------
general functions that are widely used by other modules
------------------------------
*/
__=function GeneralNamespace(){

	var l  = {};
	var dl = {};
	var m  = {
		animation    : _,
		array        : _,
		cookies      : _,
		datatable    : _,
		drag         : _,
		eventcache   : _,
		filesystem   : _,
		firefox      : _,
		firefoxxml   : _,
		formdefaults : _,
		formvalidate : _,
		geocode      : _,
		googlemaps   :
			{
			gbound              : _,
			googlemaps          : _,
			googlemapsapi1      : _,
			googlemapsapi2      : _,
			gpoint              : _,
			gpolylinewrapper    : _,
			xarrowcontroller    : _,
			xarrow              : _,
			xarrowshape         : _,
			xdebug              : _,
			xdistanceangle      : _,
			xicon               : _,
			xiconshape          : _,
			ximagefactory       : _,
			xmaps               : _,
			xmarker             : _,
			xmodel              : _,
			xpatterncontroller  : _,
			xpngimagefactory    : _,
			xpolygon            : _,
			xpolyline           : _,
			xpolylinecontroller : _,
			xsegmentedpolylinecontroller : _,
			xtextcontroller     : _,
			xuseragent          : _
			},
		hex             : _,
		imagerollovers  : _,
		keyboard        : _,
		mask            : _,
		mouse           : _,
		multiselectbox  : _,
		number          : _,
		positioning     : _,
		querystring     : _,
		resize          : _,
		screenposition  : _,
		scrollbars      : _,
		starlight       : _,
		string          : _,
		styles          : _,
		tooltip         : _,
		xml             : _,
		xmlformvalidate : _,
		xmlhttp         : _
	};
	var ext = {
		datatable: {
			mssql:['mssqlnode'],
			mysql:['mysqlnode']
		}
	};

	/*
	Function: done loading [w.doneLoading]
	--------------------------------------
	internal function that declares a javascript file is finished loading
	--------------------------------------
	*/
	function dL(s){
		dl[s.toLowerCase()] = 1;
		for(n in l) if(uD(dl[n])) return;

		fireEvents (w, 'scriptload');
		flushEvents(w, 'scriptload');
	}
	addEvent(w, 'load', function(){
		fireEvents (w, 'scriptload');
	});

	/*
	Function: load [w.load]
	-----------------------
	loads a specified module
	-----------------------
	*/
	var ldd = 0;
	function L(s, e, r, p){
		if(uD(p)) p='';
		if(uDN(r)) r = m;
		if(s.indexOf('/')>=0){
			p+=s.substr(0, s.lastIndexOf('/')+1);
			s=s.substr(s.lastIndexOf('/')+1);
			var x=p.split('/');
			for(var i=0; i<x.length; i++){
				if(x[i]=='') continue;
				if(uD(r[x[i]])) return;
				r=r[x[i]];
			}
		}
		s=s.toLowerCase();
		if(!uD(l[s])||uD(r[s])){
			for(var x in r)
				if(!uDN(r[x])&&typeof(r[x])!='string')
					L(s, e, r[x], x+'/');
			return;
		}
		if(r[s]!=_&&typeof(r[s])!='string'){
			L(s, e, r[s], s+'/');
			return;
		}

		if(!uDN(d.body)&&(d.readyState==4)){
			if(ldd++>0) return;
			var S = cE('SCRIPT');

			d.body.appendChild(S);
			S.language = "Javascript"
			S.src = xLibPath+p+(r[s]==_?s+'.js':r[s]);
		} else {
			d.write('<script language="Javascript" src="'+xLibPath+p+(r[s]==_?s+'.js':r[s])+'"></scr'+'ipt>');
		}

		l[s]=(r[s]==_?s+'.js':r[s]);
		if(!uDN(e)&&!uDN(ext[s])){
			for(var i=0; i<ext[s][e].length; i++)
				L(ext[s][e][i]);
		}
	}

	/*
	Function: write loaded [w.writeLoaded]
	--------------------------------------
	opens a dialog that shows all loaded modules
	--------------------------------------
	*/
	function wL(){
		throwError('general.js');
		for(n in l) throwError(l[n]);
	}

	/*
	Function: check loaded [w.loaded]
	---------------------------------
	checks if a specific module has been loaded
	---------------------------------
	*/
	function cL(s){
		return !uD(dl[s.toLowerCase()]);
	}

	/*
	Function: prepare arguments [w.prepArgs]
	----------------------------------------
	internal function that prepares function arguments
	----------------------------------------
	*/
	function pA(){
		var r = {};

		var a = arguments[0];
		var m = arguments[1];

		if(a[0] && a[0].callee) a=a[0];
		if(isGenObject(a[0])){
			for(n in a[0]) r[n] = a[0][n];
		} else if(isArray(m)) {
			for(var i=0; i<m.length; i++) r[m[i]] = a[i];
		}

		return r;
	}
	/*
	Object: err
	-----------
	error handling object
	-----------
	*/
	var err = function(){
		var aDiv, bDiv, tNode, btn;
		/*
		Function: throw error [w.throwError]
		------------------------------------
		throw an error message
		------------------------------------
		0 t : 
		1 e : 
		2 s : 
		*/
		function e(t, e, s){
			if(!uDN(s)&&s){
				if(!uDN(e)){
					var eD=e.getAttribute('errortext');
					if(eD!=_)e=gid(eD);
					if(e.nodeName=='DIV'||e.nodeName=='SPAN'){
						e.innerText=t;
						return;
					}
				}
				return;
			}
			var s=d.getElementsByTagName('SELECT');
			if(uD(aDiv)){
				aDiv = d.body.appendChild(cE('DIV'));
				bDiv = d.body.appendChild(cE('DIV'));
				btn  = cE('button');
				addEvent(btn, 'click', function(){
					aDiv.style.display = bDiv.style.display = 'none';
					for(var i=aDiv.childNodes.length-1; i>=0; i--) if(aDiv.childNodes[i].nodeName=='DIV') aDiv.removeChild(aDiv.childNodes[i]);
					for(var i=0; i<s.length; i++){ s[i].style.visibility=s[i].gA('visibility'); s[i].sA('visibility', _); }

					fireEvents(w, 'reload');
				});
				aDiv.aC(btn);
				btn.aC(document.createTextNode('Continue'));
				btn.style.cssText  = 'border:1px solid #000;float:right;';
				bDiv.style.cssText = 'position:absolute;top:0px;left:0px;background-color:#000;opacity:0.5;moz-opacity:0.5;filter:alpha(opacity=50);';
				aDiv.style.cssText = 'height:auto;overflow:auto;width:50%;font-family:verdana,tahoma,sans-serif;color:#C00;font-size:11px;padding:5px;z-index:10;position:absolute;border:2px solid #444;background-color:#fff;';
			}
			var vS = getViewSize();

			for(var i=0; i<s.length; i++){ aP(s[i]); if(s[i].gA('visibility')!=_) continue; s[i].sA('visibility', s[i].style.visibility); s[i].style.visibility='hidden'; }
			var cTxt = cE('DIV');
			var txt  = document.createTextNode(t);
			cTxt.style.cssText = 'float:left;width:100%;padding-bottom:5px;';
			aDiv.style.display = bDiv.style.display = 'block';
			cTxt.aC(txt)
			aDiv.aC(cTxt);
			aDiv.aC(btn);

			aDiv.style.top =d.body.scrollTop +(vS.h-aDiv.scrollHeight)/2;
			aDiv.style.left=d.body.scrollLeft+(vS.w-aDiv.scrollWidth) /2;
			bDiv.style.height=d.body.scrollHeight<vS.h?vS.h:d.body.scrollHeight;
			bDiv.style.width =d.body.scrollWidth<vS.h?vS.h:d.body.scrollWidth;

			btn.focus();
		}
		/*
		Function: clear error [w.clearError]
		------------------------------------
		clears the errors for an object
		------------------------------------
		*/
		function c(f){
			aP(f)
			if(!uD(aDiv)) for(var i=aDiv.childNodes.length-1; i>=0; i--) if(aDiv.childNodes[i].nodeName=='DIV') aDiv.removeChild(aDiv.childNodes[i]);
			if(!uD(f.gA('errorText'))) gid(f.gA('errorText')).innerText='';
		}

		return {tE:e, cE:c};
	}();
	/*
	Function: get element by id [w.gid]
	-----------------------------------
	returns a reference to an item by it's id name
	-----------------------------------
	*/
	var gid = function(){var cache={};function e(e){if(typeof(e)!='string') return e;if(!uD(cache[e]))return cache[e];if(d.getElementById){ret = d.getElementById(e);}else if(d.all){ret=d.all[e];}else if(d.layers){ret=d.layers[e];}else{ret=null}if(ret!=null){ret=aP(ret);cache[e]=ret;}return ret;}return e;}();
	
	/*
	Function: create element [w.cE]
	-------------------------------
	a mapping to document.createElement

	returns a new element of specified type
	-------------------------------
	*/
	function cE(e) {return aP(d.createElement(e));}
	/*
	Function: create text node [w.cTN]
	----------------------------------
	a mapping to document.createTextNode

	returns a new text node with specified text
	----------------------------------
	*/
	function cTN(e){return d.createTextNode(e);}

	/*
	Function: add prototypes [w.addPrototypes]
	------------------------------------------
	adds prototypes to an object:

	aC = appendChild
	rAC, removeAllChildren (removes all child nodes)
	gA = getAttribute
	sA = setAttribute
	------------------------------------------
	*/
	function aP(e) {if(!uD(e.sA)) return;e.aC=function(e){this.appendChild(e);};e.rAC=e.removeAllChildren=function(){rAC(this);};e.sA=function(e,f){this.setAttribute(e,f);};e.gA=function(e){return this.getAttribute(e);};return e;}

	/*
	Function: remove all children [not exposed]
	-------------------------------------------
	removes all children from an object
	-------------------------------------------
	*/
	function rAC(e){for(var i=e.childNodes.length-1; i>=0; i--) e.removeChild(e.childNodes[i]);};

	w.load   = L;
	w.loaded = cL;
	w.gid    = gid;
	w.cE     = cE;
	w.cTN    = cTN;
	w.doneLoading   = dL;
	w.writeLoaded   = wL;
	w.throwError    = err.tE;
	w.clearError    = err.cE;
	w.addPrototypes = aP;
	w.prepArgs      = pA;
	w.isArray       = function(a){return isObject(a)&&a.constructor==Array;}
}();

/*
Namespace: auto load
--------------------
removes the requirement of loading a module before calling it's functions
does not do this for all modules
--------------------
*/
__=function autoLoadNamespace(){
	var functions = {
		formvalidate:{
			loadFromQueryString : _,
			addDefault          : _,
			addRequired         : _,
			addValidation       : _,
			addSelectAll        : _,
			addStartVal         : _
		},
		mask:{
			addMask             : _
		}
	}

	for(ns in functions){
		for(f in functions[ns]){
			if(uD(w[f])){
				w[f] = new Function('', 'var f="'+f+'";var ns="'+ns+'";var arg=arguments;addEvent(w, "scriptload", function(){if(loaded(ns) && !uDN(w[f])) w[f](arg);}); load("'+ns+'");');
			}
		}
	}
}();

/*
Namespace: types
------------------------------
adds isType functions:

w.isAlien
w.isArray
w.isBool
w.isEmpty
w.isFunction
w.isNull
w.isNumber
w.isObject
w.isGenObject (is object defined as {})
w.isString
w.isUndefined
------------------------------
*/
__=function typesNamespace(){
	w.isAlien    =function(a){return isObject(a)&&typeof a.constructor!='function';}
	w.isArray    =function(a){return isObject(a)&&a.constructor==Array;}
	w.isBool     =function(a){return typeof a=='boolean';}
	w.isEmpty    =function(o){if(isObject(o)){for(var i in o){var v=o[i];if(isUndefined(v)&&isFunction(v)){return false;}}}return true;}
	w.isFunction =function(a){return typeof a=='function';}
	w.isNull     =function(a){return typeof a=='object' && !a;}
	w.isNumber   =function(a){return typeof a=='number'&&isFinite(a);}
	w.isObject   =function(a){return (a&&typeof a=='object')||isFunction(a);}
	w.isGenObject=function(a){return isObject(a)&&!isArray(a)&&!isFunction(a)&&uD(a.nodeName);}
	w.isString   =function(a){return typeof a=='string';}
	w.isUndefined=function(a){return typeof a=='undefined';} 
}();

load('array');
load('positioning');
if(moz) load('firefox');
