
if("undefined" == typeof(ASP_X_UTILS) || ASP_X_UTILS == "")
{
ASP_X_UTILS = "defined";

Array.prototype.IndexOf = function(item) { return GetItemIndex(this, item); }
Array.prototype.Add = function(item) { this[this.length] = item; }
Array.prototype.First = function() { return (this.length > 0) ? this[0] : null; }
Array.prototype.Last = function() { return (this.length > 0) ? this[this.length - 1] : null; }

var debug = false;
function Trace(s) {
	if(window.defaultStatus.length > 150)
		window.defaultStatus = "";
	if(debug) window.defaultStatus += " |" + s;
}
function insp(obj) {
	var s = GetObjInfo(obj);
	alert(s);
}
function GetObjInfo(obj) {
	var ar = [];
	for(i in obj) {
	        if(true || i.indexOf("on") != 0 && i.indexOf("outer") != 0 && i.indexOf("inner") != 0) {
				var val = " = " + eval("obj." + i);
				if(val.indexOf("function") < 0) {
					ar.push("" + i + val);
//					s += i + val + "\t\t";
				}
			}
	}
	ar.sort();
	return ar.join("\t\t");
//	return s;
}
function SetProperties(obj, s) {
	var a = s.split( ";" );
	for(var i = 0; i < a.length; i++) {
		if(a[i].length > 0) eval("obj." + a[i]);
		//var b = a[i].split( ":" );
		//if(b.length == 2) eval("obj." + b[0] + "=" + b[1]);
	}
}
function Exists(obj) {
	return null != obj && (typeof(obj) == "string" && obj == "") == false && "undefined" != typeof(obj);
}
function DoEventArgs(args) {
	var s = "";
	for(var i = 0; i < args.length; i++) {
		s += DoEventArg(args[i][0], args[i][1]);
	}
	return s;
}
function DoEventArg(name, val) { 
	return name + "=" + val + ";";
}
function GetItemIndex(items, item) { 
	if( Exists(items) ) {
		for(var i = 0; i < items.length; i++) 
			if(items[i] == item) return i; 
	}
	return -1; 
}
function GetItemByName(items, name) { 
	return Exists(items) ? items[name] : null;
}
function GetArgValue(args, index, val) {
	return (index < args.length) ? args[index] : val;
}

// class ****
function dx_Utils()
{
	this.NavigateUrl = function(url, target) {
		if(Exists(url) == false)
			return;
		if(url.indexOf("javascript") != -1) eval(url);
		else {
			if( Exists(target) ) {
				if( this.IsSpecial(target) ) {
					this.NavigateSpecialTarget(url, target);
					return;
				} else {
					var frame = this.GetFrame(top.frames, target);
					if( Exists(frame) ) {
						frame.location.href = url; 
						return;
					}
				}
			} 
			location.href = url;
		}
	}
	this.IsSpecial = function(target) {
		var t = target.toLowerCase();
		var targets = ['_top','_self','_search','_parent','_blank'];
		for(var i = 0; i < targets.length; i++)
			if(targets[i] == t) return true;
		return false;
	}
	this.NavigateSpecialTarget = function(url, target) {
		var t = target.toLowerCase();
		if("_top" == t) {
			top.location.href = url;
		} else if("_self" == t) {
			location.href = url;
		} else if("_search" == t) {
			window.open(url, 'blank');
		} else if("_parent" == t) {
			if( Exists(window.parent) ) window.parent.location.href = url;
		} else if("_blank" == t) {
			window.open(url, 'blank');
		}
	}
	this.GetFrame = function(frames, name) {
		if( Exists(frames) ) {
			for(var i = 0; i < frames.length; i++) {
				var frame = frames[i];
				if(frame.name == name) return frame;	

				frame = this.GetFrame(frame.frames, name);
				if( Exists(frame) ) return frame;	
			}
		}
		return null;
	}
	this.CreatePosHelper = function() {
		var info = new dx_Info();
		var pos = info.ie ? new dx_PosIE() : 
			info.ns4 ? new dx_PosNS4() : 
			(info.ns6 || info.moz) ? new dx_PosNS6() : 
			info.op7 ? new dx_PosOP7() : 
			info.op ? new dx_PosOP() : 
			new dx_PosHelper();
		return pos;
	}
	this.CreateObjHelper = function() {
		var info = new dx_Info();
		var obj = info.ie4 || info.ie5 ? new dx_ObjIE4() : 
			info.ns4 ? new dx_ObjNS4() :
//			info.op ? new dx_ObjIE4() :
			info.op ? new dx_ObjDOM() :
			info.dom ? new dx_ObjDOM() :
			new dx_ObjHelper();
		return obj;
	}
}
/// class ***
function dx_Info()
{
	this.ver = navigator.appVersion;
	this.agent = navigator.userAgent.toLowerCase();
	this.op5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera;
	this.op6 = (this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera; 
	this.op7 = (this.agent.indexOf("opera 7")>-1 || this.agent.indexOf("opera/7")>-1) && window.opera;
	this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6);
	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1);
	this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6);
	this.ie4 = (this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6);
//	this.ie = (this.ie4 || this.ie5 || this.ie6);
	this.mac = (this.agent.indexOf("mac")>-1);
//	this.ns6 = (this.agent.indexOf("gecko")>-1 || window.sidebar);
	this.ns6 = (this.agent.indexOf("gecko")>-1 && this.agent.indexOf("netscape6")>-1);
	this.moz = (this.agent.indexOf("gecko")>-1 && this.agent.indexOf("netscape6")<0);
	this.dom = document.getElementById && !this.ie5 ? 1 : 0;
	this.ns4 = (!this.dom && document.layers)?1:0;
	this.bw = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6);
	this.px = this.dom&&!this.op5?"px":"";
	this.ie = (this.ie6 || this.ie5 || this.ie4);
	this.op = (this.op6 || this.op5 || this.op7);
	
	
	return this;
}
// class *****
function dx_EventInfo()
{
	this.info = new dx_Info();
	this.leftButton = this.info.moz || this.info.ns6 ? 0 : 1;
	this.GetEvent = function(e) { return this.info.ie ? event : e; }
	
	this.GetSrcElement = function(e) { 
		return this.info.ie ? event.srcElement : e.target; 
	}
	
	this.IsLeftButton = function(e) {
		var ev = this.GetEvent(e);
		return ev.button == this.leftButton;
	}
	return this;
}
// class ******
function dx_Rect(left, top, width, height) 
{
	this.left = left;
	this.top = top;
	this.right = left + width;
	this.bottom = top + height;
	
	this.IsEmpty = function() {
		return (this.left == 0 && this.top == 0 && this.right == 0 && this.bottom == 0);
	}
	this.Contains = function(pt) {
		return (pt.x > this.left && pt.x < this.right && pt.y > this.top && pt.y < this.bottom) ?
			true : false;
	}
	this.Inflate = function(dx, dy) {
		this.left -= dx;
		this.top -= dy;
		this.right += dx;
		this.bottom += dy;
	}
	return this;
}
///// class *****
function dx_Point(x,y) 
{
	this.x = x;
	this.y = y;
	this.FromString = function(s) {
		var arr = s.split( ";" );
		if(arr.length > 1) {
			this.x = parseInt(arr[0], 10);
			this.y = parseInt(arr[1], 10);
		}
	}
	this.IsEmpty = function() {
		return (this.x == 0 && this.y == 0);
	}
	this.Offset = function(dx, dy) { this.x += dx; this.y += dy; }
	this.Clone = function() { return new dx_Point(this.x, this.y); }
	return this;
}
//// class ****
function dx_PosHelper()
{
	this.ElementContainsPoint = function(el, pt) {
		var r = this.GetElementRect(el);
		return Exists(r) ? r.Contains(pt) : false;
	}
	this.GetElementRect = function(el) {
		if( Exists(el) ) {
			var s = this.GetElementSize(el);
			var p = this.GetAbsolutePos(el);
			return new dx_Rect(p.x, p.y, s.x, s.y);
		}
		return null;
	}
	this.EventPoint = function(e, wind) {
		return new dx_Point(this.GetEventX(e,wind), this.GetEventY(e,wind));
	}
	this.GetElementSize = function(el) { 
		return Exists(el) ? new dx_Point(el.offsetWidth, el.offsetHeight) : null;
	}
	this.SetElementWidth = function(el, width) { 
		if( Exists(el) ) {
			el.style.width = width;
		}
	}
	this.ZIndex = function(el, val) {
		if(arguments.length > 1) el.style.zIndex = val;
		else return parseInt(el.style.zIndex);
	}
	this.GetAbsolutePos = function(el) {
		var pt = new dx_Point(0, 0);
		if( Exists(el) ) { 
			if( Exists(el.offsetParent) ) {
				pt = this.GetAbsolutePos(el.offsetParent);
//				if(el.clientWidth != 0 || el.clientHeight != 0 || "absolute" == el.style.position)
					pt.Offset(el.offsetLeft, el.offsetTop);
			} else {
				pt = new dx_Point(el.offsetLeft, el.offsetTop);
			}
		}
		return pt;
	}
	this.SetAbsolutePos = function(elem, x, y) {
		if( Exists(elem) ) {
			elem.style.left = x;
			elem.style.top = y;
		}
	}
	return this;
}
// class ********
function dx_PosIE()
{
	this.inherit = dx_PosHelper;
	this.inherit();

	this.GetEventX = function(e, wind) { return event.clientX + wind.document.body.scrollLeft; }
	this.GetEventY = function(e, wind) { return event.clientY + wind.document.body.scrollTop; }
	this.GetWindowRect = function() {
		with(document.body) {
			return new dx_Rect(scrollLeft, scrollTop, clientWidth, clientHeight);
		}
	}
	this.SetAbsolutePos = function(elem, x, y) {
		if( Exists(elem) ) {
			var offset = this.GetParentOffset(elem);
			elem.style.left = x - offset.x;
			elem.style.top = y - offset.y;
		}
	}
	this.GetParentOffset = function(elem) {
		var pt = new dx_Point(0,0);
		var parent = elem.offsetParent;
		while( Exists(parent) ) {
			if("absolute" == parent.style.position) {
				pt.Offset(parent.offsetLeft, parent.offsetTop);
			}
			parent = parent.offsetParent;
		}
		return pt;
	}
	return this;
}
/// class ****
function dx_PosOP()
{
	this.inherit = dx_PosIE;
	this.inherit();
	this.GetElementSize = function(el) { 
//		alert(el.id + "|" + el.offsetWidth)
//		return Exists(el) ? new dx_Point(el.offsetWidth, el.offsetHeight) : null;
		return Exists(el) ? new dx_Point(el.style.width, el.style.height) : null;
	}
	this.GetWindowRect = function() {
		var db = document.body;
		return new dx_Rect(db.scrollLeft, db.scrollTop, db.clientWidth, db.clientHeight)
	}
	this.GetAbsolutePos = function(el) {
		var pt = new dx_Point(el.offsetLeft, el.offsetTop);
		var parent = el.offsetParent;
		while( Exists(parent) ) {
			pt.Offset(parent.offsetLeft, parent.offsetTop);
			parent = parent.offsetParent;
		}
		return pt;
	}
	this.SetElementWidth = function(el, width) { 
		if( Exists(el) ) {
			el.style.width = width;
		}
	}
	
	return this;
}
/// class ****
function dx_PosOP7()
{
	this.inherit = dx_PosHelper;
	this.inherit();
	this.GetWindowRect = function() {
		var db = document.body;
		return new dx_Rect(db.scrollLeft, db.scrollTop, db.clientWidth, db.clientHeight)
	}
	return this;
}
/// class *****
function dx_PosNS()
{
	this.inherit = dx_PosHelper;
	this.inherit();

	this.GetEventX = function(e, wind) { return (null != e) ? e.pageX : 0; }
	this.GetEventY = function(e, wind) { return (null != e) ? e.pageY : 0; }
	this.GetWindowRect = function() {
		with(window) {
			return new dx_Rect(pageXOffset, pageYOffset, innerWidth, innerHeight);
		}
	}
	return this;
}
///// class ***
function dx_PosNS4()
{
	this.inherit = dx_PosNS;
	this.inherit();

	this.GetElementSize = function(el) {
//			insp(el)
		return Exists(el) && Exists(el.clip) ? new dx_Point(el.clip.width, el.clip.height) : null; 
	}
	this.ZIndex = function(el, val) {
		if(arguments.length > 1) el.zIndex = val;
		else return el.zIndex
	}
	this.GetAbsolutePos = function(el) {
		var pt = new dx_Point(el.x, el.y); 
		var parent = this.GetParentOf(el);
		if( Exists(parent) && Exists(parent.pageX) && Exists(parent.pageY) )
			pt.Offset(parent.pageX, parent.pageY);
		return pt; 
	}
	this.SetAbsolutePos = function(el, x, y) {
		var pt = new dx_Point(x, y); 
		var parent = this.GetParentOf(el);
		if( Exists(parent) && Exists(parent.pageX) && Exists(parent.pageY) ) 
			pt.Offset(-parent.pageX, -parent.pageY);
		el.x = pt.x; el.y = pt.y;
	}
	this.GetParentOf = function(el) {
		if(Exists(el.parentElement) == false) {
			el.parentElement = this.SearchParentOf(el);
		}
		return el.parentElement;
	}
	this.SearchParentOf = function(el) {
		var searcher = new dx_Searcher();
		searcher.GetNodes = function(node) { return node.document.layers; }
		searcher.GetElement = function(node, val) {
			if(Exists(val.name) == false) return null;
			var el = GetItemByName(node.document.layers, val.name);
			if( Exists(el) ) return node;
			var el = GetItemByName(node.document.images, val.name);
			if( Exists(el) ) return node;
			var el = GetItemByName(node.document.anchors, val.name);
			if( Exists(el) ) return node;
			return null;
		}
		return searcher.GetElementByVal(window, el);
	}
	return this;
}
// class ****
function dx_PosNS6()
{
	this.inherit = dx_PosNS;
	this.inherit();
	return this;
}
/// class *****
function dx_StringComparer()
{
	this.Equals = function(a, b) { return (Exists(a) && a.indexOf(b) != -1); }
	return this;
}
/// class *****
function dx_DefaultComparer()
{
	this.Equals = function(a, b) { return a == b; }
	return this;
}
// class ******
function dx_NodeCollector(comp)
{
	this.comp = comp;
	this.nodes = [];
	this.SelectNodes = function(src, property, value) {
		if(Exists(this.comp) == false) this.comp = new dx_DefaultComparer();
		for(var i = 0; i < src.length; i++) {
			var node = src[i];
			var propValue = eval("node." + property);
			if( this.comp.Equals(propValue,value) )
				this.nodes.Add(node);
		}
	}
}
// class ****
function dx_ObjHelper()
{
	this.IsElementVisible = function(el) { return false; }
	this.SetElementVisibility = function(el, visible) {}
	this.GetElementById = function(name) { return null; }
	this.ParentOf = function(elem) { return null; }
	this.ChildrenOf = function(elem) { return null; }
	this.GetTags = function(elem, name) {
		return this.GetChildren(elem, "tagName", name.toUpperCase(), null);
	}
	
	this.GetNodes = function(src, property, value, comp) {
		var coll = new dx_NodeCollector(comp);
		coll.SelectNodes(src, property, value);
		return coll.nodes;
	}
	this.GetChildren = function(elem, property, value, comp) {
		var coll = new dx_NodeCollector(comp);
		this.SelectChildren(elem, coll, property, value);
		return coll.nodes;
	}
	this.SelectChildren = function(elem, coll, property, value) {
		var src = this.ChildrenOf(elem);
		if( Exists(src) ) {
			coll.SelectNodes(src, property, value);
			for(var i = 0; i < src.length; i++) {
				this.SelectChildren(src[i], coll, property, value);
			}
		}
	}
	this.GetParentByClass = function(elem, className) {
		while( Exists(elem) && elem.className != className ) {
			elem = this.ParentOf(elem);
		}
		return elem;
	}
	this.GetParentById = function(elem, id) {
		while( Exists(elem) ) {
			if(Exists(elem.id) && elem.id.indexOf(id) != -1)
				break;
			elem = this.ParentOf(elem);
		}
		return elem;
	}
	this.GetChildById = function(elem, id) {
		var searcher = new dx_Searcher();
		searcher.GetNodes = this.ChildrenOf;
		searcher.GetElement = function(node, val) { return (val == node.id) ? node : null; }
		return searcher.GetElementByVal(elem, id);
	}
	return this;
}
/// class ****
function dx_ObjIE4()
{
	this.inherit = dx_ObjHelper;
	this.inherit();

	this.IsElementVisible = function(el) { return "hidden" != el.style.visibility; }
	this.SetElementVisibility = function(el, visible) { el.style.visibility = visible ? "visible" : "hidden"; }
	this.GetElementById = function(name) { return document.all[name]; }
	this.ParentOf = function(elem) { return elem.parentElement; }
	this.ChildrenOf = function(elem) { return elem.children; }
	this.GetTags = function(elem, name) { return elem.all.tags(name); }
	return this;
}
// class *****
function dx_ObjNS4()
{
	this.inherit = dx_ObjHelper;
	this.inherit();

	this.IsElementVisible = function(el) { return "hide" != el.visibility; }
	this.SetElementVisibility = function(el, visible) { 
//		alert(el);
		el.visibility = visible ? "visible" : "hidden"; 
	}
	this.CreateLayer = function(width, parent, s) {
		var el = new Layer(width, parent);
		this.WriteLayer(el, s);
		return el;
	}
	this.WriteLayer = function(el, s) {
		if( Exists(el) && Exists(s) ) {
			el.document.open();
			el.document.write(s);
			el.document.close();
		}
	}
	this.GetElementById = function(name) {
		var searcher = new dx_Searcher();
		searcher.GetNodes = function(node) { return node.document.layers; }
		searcher.GetElement = function(node, val) { 
			var el = node.document.layers[val];
			if(Exists(el) == false) el = node.document.anchors[val];
			if(Exists(el) == false) el = node.document.images[val];
			if( Exists(el) ) el.parentElement = node;
			return el;
		}
		return searcher.GetElementByVal(window, name);
	}
	return this;
}
/// class *****
function dx_ObjDOM()
{
	this.inherit = dx_ObjHelper;
	this.inherit();

	this.IsElementVisible = function(el) { return "hidden" != el.style.visibility; }
	this.SetElementVisibility = function(el, visible) { el.style.visibility = visible ? "visible" : "hidden"; }
	this.GetElementById = function(name) { 
		return document.getElementById(name); 
	}
	this.ParentOf = function(elem) { return elem.parentNode; }
	this.ChildrenOf = function(elem) { return elem.childNodes; }
	return this;
}
/// class ****
function dx_Searcher()
{
	this.GetElement = function(node, val) { return null; }
	this.GetNodes = function(node) { return null; }
	
	this.GetElementByVal = function(src, val) {
		var el = this.GetElement(src, val);
		if( Exists(el) ) return el;
		
		var nodes = this.GetNodes(src);
		if(Exists(nodes) == false) return null;
		
		for(var i = 0; i < nodes.length; i++) {
			el = this.GetElement(nodes[i], val);
			if( Exists(el) ) return el;
			el = this.GetElementByVal(nodes[i], val);
			if( Exists(el) ) return el;
		}
		return null;
	}
	return this;
}
/// class ****
function dx_Event()
{
	this.func = null;
	this.prev = null;
	this.capture = false;
	
	this.Exec = function(e) {
		if(this.capture == false && Exists(this.prev) ) this.prev(e);
		if( Exists(this.func) ) this.func(e);
	}
	this.Attach = function(name, func) {
		if(Exists(this.prev) == false) {
			this.prev = eval(name);
			this.func = func;
		}
	}
	this.Capture = function(name, func) {
		this.Attach(name, func);
		this.capture = true;
	}
	this.Detach = function(name) {
		eval(name + " = this.prev");
		this.func = null;
		this.prev = null;
		this.capture = false;
	}
	return this;
}
// class ****
function dx_EventManager()
{
	this.events = [];
	this.Exec = function(name,e) {
		var ev = this.events[name];
		if( Exists(ev) ) ev.Exec(e);
	}
	this.AddEvent = function(name) {
		var ev = new dx_Event();
		this.events[name] = ev;
		return ev;
	}
	this.Capture = function(name, func) {
		if(Exists(this.events[name]) == false) {
			var ev = this.AddEvent(name);
			ev.Capture(name, func);
		}
	}
	this.Attach = function(name, func) {
		if(Exists(this.events[name]) == false) {
			var ev = this.AddEvent(name);
			ev.Attach(name, func);
		}
	}
	this.Detach = function(name) {
		if(Exists(this.events[name]) == true) {
			this.events[name].Detach(name);
			this.events[name] = null;
		}		
	}
}

}


