
var isOpera = (/opera/i.test(navigator.userAgent));
var isIE  = ((/msie/i.test(navigator.userAgent)
				 || /offline explorer/i.test(navigator.userAgent)
				 || /internet explorer/i.test(navigator.userAgent)) && !isOpera);
var isIE5 = (isIE && /msie 5\.0/i.test(navigator.userAgent));
var isGaleon = (/galeon/i.test(navigator.userAgent));
var isMozilla = ((/gecko/i.test(navigator.userAgent)
					  || /mozilla\/5/i.test(navigator.userAgent)) && !isGaleon && !isIE);
var isNetscape = (/mozilla\/4/i.test(navigator.userAgent) && !isGaleon && !isIE && !isNetscape);
var isSafari = (/safari/i.test(navigator.userAgent));
var isKonqueror = (/konqueror/i.test(navigator.userAgent));


//WINDOWS
function fullWindow(url_, title_)
{
	var w = screen.width - 10;
	var h = screen.height - 55;
	window.open(url_, title_, "top=0,left=0,width=" + w + ",height=" + h + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes,fullscreen=no,scrollbars=yes");
}

function centeredPop(url_, title_, w, h)
{
	var t = Math.round((screen.height-h)/2);
	var l = Math.round((screen.width-w)/2);
	window.open(url_, title_, "top=" + t + ",left=" + l + ",width=" + w + ",height=" + h + ",status=no,toolbar=no,menubar=no,location=no,resizable=no,fullscreen=no,scrollbars=no");
}

function centeredWindow(url_, title_, w, h, features)
{
	var t = Math.round((screen.height-h)/2);
	var l = Math.round((screen.width-w)/2);
	if(!features)
		features = "status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,fullscreen=no,scrollbars=yes";

	window.open(url_, title_, "top=" + t + ",left=" + l + ",width=" + w + ",height=" + h + "," + features);
}


//OBJECTS
function obj_nn(obj)
{
	return EQX.$(obj).nodeName.toLowerCase();
}

function obj_exists(obj_id)
{
	if(typeof(obj_id) != "string")
		return true;

	var obj = document.getElementById(obj_id);
	if(!obj)
	{
		if(document.all)
			obj = document.all[obj_id];
	}

	if(!obj)
		return false;

	return true;
}


function frame_get(name)
{
	if(window.frames[name])
		return window.frames[name];

	return EQX.$(name);
}

function obj_createEx(w, type, parent, n)
{
	var obj;

	if(w.document.createElement)
		obj = w.document.createElement(type);
	else if(w.document.createElementNS)
		obj = w.document.createElementNS('http://www.w3.org/1999/xhtml', type);

	if(parent)
		obj_setParent(obj, parent);

	if(typeof(n) == "string")
	{
		obj.id = n;
		if(typeof(obj.name) != "undefined")
			obj.name = n;
	}

	return obj;
}
function obj_create(type, parent, n)
{
	return obj_createEx(window, type, parent, n);
}

function obj_copyProperties(oSource, oDest, functions)
{
	for(var pn in oSource)
	{
		var pv = oSource[pn];
		switch(typeof(pv))
		{
			case "object":
			{
				if(!oDest[pn])
					oDest[pn] = {};
				obj_copyProperties(pv, oDest[pn], functions);
				break;
			}

			case "function":
			{
				if(functions)
					oDest[pn] = pv;
				break;
			}

			default:
			{
				oDest[pn] = pv;
				break;
			}
		}
	}
}

function obj_setParent(obj, parent)
{
	if(typeof(parent) == "string")
		parent = EQX.$(parent);

	if(!parent)
	{
		alert("Invalid parent: "  + parent);
		return;
	}

	parent.appendChild(obj);
}

function obj_getFirstParentOfType(obj, tagName)
{
	obj = EQX.$(obj);
	tagName = tagName.toLowerCase();

	var p = obj;
	while(p)
	{
		if(p.nodeName.toLowerCase() == tagName)
			return p;

		p = p.parentNode;
	}

	return null;
}

function obj_getParents(obj)
{
	obj = EQX.$(obj);

	var a = [], p = obj;
	while(p && (p.nodeName.toLowerCase() != "body"))
	{
		a[a.length] = p;
		p = p.parentNode;
	}

	return a;
}

function obj_isParentOf(obj1, obj2)
{
	while(obj2 && (obj2 != obj1))
		obj2 = obj2.parentNode;

	return (obj1 == obj2);
}


function obj_setContent(obj, c)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	obj.innerHTML = "";
	if(obj)
		obj.innerHTML = c;
}

function obj_setEnabled(obj, enabled)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	if(obj)
		obj.disabled = !enabled;
}
function obj_disable(obj)
{
	obj_setEnabled(obj, false);
}
function obj_enable(obj)
{
	obj_setEnabled(obj, true);
}

function obj_vis(obj, visible)
{
	obj = EQX.$(obj);

	if(obj)
		obj.style.visibility = (visible ? "visible" : "hidden");
}

function obj_dis(obj, display)
{
	obj = EQX.$(obj);

	if(obj)
		obj.style.display = display;
}

function objs_hide(a)
{
	for(var i = 0; i < a.length; i++)
		EQX.$h(a[i]);
}

function objs_show(a)
{
	for(var i = 0; i < a.length; i++)
		EQX.$s(a[i]);
}

function obj_isVisible(obj)
{
	obj = EQX.$(obj);

	if(obj)
		return (obj.style.display != "none");
	else
		return false;
}

function obj_isVisibleEx(obj)
{
	if(!obj || !obj.style)
		return true;

	else if(obj.style.display == "none")
		return false;

	return obj_isVisibleEx(obj.parentNode);
}

function obj_cycleDisplay(obj)
{
	if(obj_isVisible(obj))
	{
		EQX.$h(obj);
		return false;
	}

	EQX.$s(obj);
	return true;
}

function obj_tag(obj)
{
	obj = EQX.$(obj);
	return obj.nodeName.toLowerCase();
}

function obj_rename(obj, new_id)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	if(!obj) return;

	obj_setAttribute(obj, "id", new_id);
	if(obj.name)
		obj_setAttribute(obj, "name", new_id);
}

function obj_del(obj)
{
	obj = EQX.$(obj);
	if(obj)
	{
		if(obj.parentNode)
		{
			obj.parentNode.removeChild(obj);
		}
		else if(obj.removeNode)
		{
			obj.removeNode(true);
		}
		else
		{
			obj.innerHTML = "";
			obj.style.display = "none";
			obj.id = "";
			if(obj.name)
				obj.name = "";
		}
	}
}

function obj_inIFrame(obj)
{
	return false;
	if(obj.name && (obj.name == "cmbSalutation"))
	{
		var f = EQX.$("ifObject_1020_1200");
		alert(f);
//		alert(f.contains(obj));
	}
}

function obj_removeChildNodes(obj)
{
	obj = EQX.$(obj);
	if(!obj) return false;

	for(var i = obj.childNodes.length; i > 0 ; i--)
		obj.removeChild(obj.childNodes[0]);
}

function obj_getSize(obj)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	var p =	{x: obj.offsetWidth, y: obj.offsetHeight}

	return p;
}

function obj_adjustHeight(obj, max_height, margin, js_before, js_after)
{
	obj = EQX.$(obj);
	if(!obj || !max_height || !obj_isVisibleEx(obj)) return;

	if(undef(margin)) margin = 2;

	var ch = obj.clientHeight, sh = obj.scrollHeight;
	if((Math.abs(ch - sh) > 4) || (ch < sh))
	{
		sh += margin;
		if(sh > max_height)
			sh = max_height;

		if(js_before) eval(js_before);

		obj.style.height = sh + margin + "px";

		if(js_after) eval(js_after);

		return true;
	}

	return false;
}

function obj_hasPos(obj)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	return ((obj.style.left.length > 0) && (obj.style.top.length > 0));
}

function obj_initPos(obj)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	var p = obj_getAbsPos(obj);
	obj.style.position = 'absolute';
	obj_setPos(obj, p.x, p.y);
}

function obj_getAbsPos(obj)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	var scroll_x = 0, scroll_y = 0;
	var is_div = /^div$/i.test(obj.nodeName);
	if (is_div && obj.scrollLeft)
		scroll_x = obj.scrollLeft;
	if (is_div && obj.scrollTop)
		scroll_y = obj.scrollTop;
	var p =	{x: obj.offsetLeft - scroll_x, y: obj.offsetTop - scroll_y}
	if(obj.offsetParent)
	{
		var p_ = obj_getAbsPos(obj.offsetParent);
		p.x += p_.x;
		p.y += p_.y;
	}

	return p;
}

function obj_getPos(obj)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	var p = {x: 0, y: 0};
	if(obj)
	{
		p.x = parseInt(obj.style.left);
		p.y = parseInt(obj.style.top);
	}

	return p;
}

function obj_getRelPos(obj)
{
	var p = obj_getPos(obj);

	var so = body_getScrollOffset();
	p.x -= so.x;
	p.y -= so.y;

	return p;
}

function obj_setPos(obj, x, y)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	if(obj)
	{
		obj.style.left = x + "px";
		obj.style.top = y + "px";
	}
}

function obj_setRelPos(obj, x, y)
{
	obj = EQX.$(obj);

	var so = body_getScrollOffset();
	x = parseInt(x) + so.x;
	y = parseInt(y) + so.y;
	obj_setPos(obj, x, y);
}

function obj_foc(obj)
{
	var o, o_name, pre, a, j;
	for(var i = 0; i < arguments.length; i++)
	{
		o_name = (typeof(arguments[i]) == "object") ? arguments[i].name : arguments[i];
		pre = o_name.substring(0, 3);
		if((pre == "rad") || (pre == "chk"))
		{
			a = objs_get("INPUT", o_name);
			for(j = 0; j < a.length; j++)
			{
				if(a[j].checked && obj_isVisibleEx(a[j]))
				{
					a[j].focus();
					return;
				}
			}
		}
		else
		{
			o = EQX.$(arguments[i]);
			if(o && obj_isVisibleEx(o) && o.focus)
			{
				o.focus();
				return;
			}
		}
	}
}

function obj_getIndex(obj)
{
	obj = EQX.$(obj);
	if(!obj) return -1;

	for(var i = 0, idx = 0, pc = obj.parentNode.childNodes; i < pc.length; i++)
	{
		if(pc[i] == obj) return idx;
		if(pc[i].nodeName) idx++;
	}
}



function body_getSize()
{
	var body_;

	if(!document.compatMode || (document.compatMode == "BackCompat"))
		body_ = "body";
	else if((document.compatMode == "CSS1Compat") && document.documentElement && !undef(document.documentElement.scrollLeft))
		body_ = "documentElement";

	if(undef(document[body_]) || undef(document[body_].clientWidth))
	{
		if(undef(window.innerWidth))
			return {x: 0, y: 0};
		else
			return {x: window.innerWidth, y: window.innerHeight};
	}

	return {x: document[body_].clientWidth, y: document[body_].clientHeight};
}

function body_getScrollSize(win)
{
	if(!win) win = window;

	var body_;

	var mode = win.document.compatMode;
	if(!mode || (mode == "BackCompat"))
		body_ = "body";
	else if((mode == "CSS1Compat") && win.document.documentElement)
		body_ = "documentElement";

	try
	{
		var winX = ((win.innerWidth && win.scrollMaxX) ? (win.innerWidth + win.scrollMaxX) : 0);
		var winY = ((win.innerHeight && win.scrollMaxY) ? (win.innerHeight + win.scrollMaxY) : 0);
	//	alert(winX + ':' + winY);
		var scrollX = win.document[body_].scrollWidth;
		var scrollY = win.document[body_].scrollHeight;
	//	alert(scrollX + ':' + scrollY);
		var offsetX = win.document[body_].offsetWidth;
		var offsetY = win.document[body_].offsetHeight;
		var clientX = win.document[body_].clientWidth;
		var clientY = win.document[body_].clientHeight;

		var aX = [winX, scrollX, offsetX, clientX];
		var aY = [winY, scrollY, offsetY, clientY];
	}
	catch(e){}

//	alert(aX);
//	alert(aY);
	var x = aX.maxNum();
	var y = aY.maxNum();
//alert(x + ':' + y);
	return {x: x, y: y};
}

function body_getScrollOffset()
{
	if(!undef(window.scrollX))
		return {x: window.scrollX, y: window.scrollY};

	var body_;
	if(!document.compatMode || (document.compatMode == "BackCompat"))
		body_ = "body";
	else if((document.compatMode == "CSS1Compat") && document.documentElement && !undef(document.documentElement.scrollLeft))
		body_ = "documentElement";

	if(!document[body_] || undef(document[body_].scrollLeft))
		return {x: 0, y: 0};

	return {x: document[body_].scrollLeft, y: document[body_].scrollTop};
}

function body_getViewport()
{
	var bs = body_getSize(), so = body_getScrollOffset();
	bs.x += so.x; bs.y += so.y;

	return bs;
}



function div_create(id, parent)
{
	if(!parent)
		parent = document.body;

	var div = obj_create("div", parent, id);

	return div;
}

function div_align(d, align)
{
	if(typeof(d) == "string")
		d = EQX.$(d);

	if(!align.length)
		align = 'center';

	if(!d.offsetWidth || !d.offsetHeight)
		EQX.$s(d);

	lW = d.offsetWidth;
	lH = d.offsetHeight;

	var bs = body_getSize();

	switch(align)
	{
		case "center":
		{
			x = parseInt((bs.x-lW)/2);
			y = parseInt((bs.y-lH)/2);

			break;
		}
	}

	var so = body_getScrollOffset();
	x += so.x;
	y += so.y;

	if(!isMozilla)
	{
		d.style.position = 'absolute';
		obj_setPos(d, 0, 0);
		p = obj_getAbsPos(d);
		x -=  p.x;
		y -=  p.y;
	}

	if(x < 0) x = 10;
	if(y < 0) x = 10;

	obj_setPos(d, x, y);
}

function obj_registerEvent(obj, evt, ev_handler)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	if(!obj) return;

	var a = evt.split(","), e, h;
	for(var i = 0; i < a.length; i++)
	{
		e = a[i];

		if(typeof(ev_handler) == "string")
		{
			if(typeof(obj['anon_event_' + e]) == "string")
				obj['anon_event_' + e] += " " + ev_handler;
			else
				obj['anon_event_' + e] = ev_handler;

			h = obj_anonEvent;
		}
		else
		{
			h = ev_handler;
		}

		if(obj.addEventListener)
			obj.addEventListener(e, h, false);
		else if(obj.attachEvent)
			obj.attachEvent('on' + e, h);
		else
			obj['on' + e] = h;
	}
}

function obj_anonEvent(evt)
{
	var obj = EQX.F.Event.getSender(evt);

	if(obj && obj['anon_event_' + evt.type])
		return eval(obj['anon_event_' + evt.type]);
	else if(window['anon_event_' + evt.type])
		return eval(window['anon_event_' + evt.type]);
}

function obj_unregisterEvent(obj, evt, ev_handler)
{
	if(typeof(obj) == "string")
		obj = EQX.$(obj);

	if(!obj) return;

	if(typeof(ev_handler) == "string")
		ev_handler = obj_anonEvent;

	if(obj.removeEventListener)
		obj.removeEventListener(evt, ev_handler, false);
	else if(obj.detachEvent)
		obj.detachEvent('on' + evt, ev_handler);
	else
		obj['on' + evt] = null;
}


function obj_setAttribute(obj, a, v)
{
	obj = EQX.$(obj);

	//the standard setAttribute doesn't work properly in mozilla
	obj[a] = v;
	obj.setAttribute(a, v);
}


function obj_duplicate_style(src_obj, dst_obj)
{
	if(typeof(src_obj.style.cssText) == "string")
	{
		dst_obj.style.cssText = src_obj.style.cssText;
		return;
	}

	var t, x;
	try
	{
		for(var s in src_obj.style)
		{
			t = typeof(src_obj.style[s]);
			if((t == "object") || (t == "function") || (t == "undefined"))
				continue;

			dst_obj.style[s] = src_obj.style[s];
		}
	}
	catch(e){}
}

function objs_get(tagName, oName, oParent, partial_name)
{
	var aObjs = null;

	if(tagName) tagName = tagName.toUpperCase();

	oName = oName;

	//IE doesn't return the dynamically generated objects
	if(oName && !partial_name && document.getElementsByName && !isIE)
	{
		if(oParent)
		{
			oParent = EQX.$(oParent);
			aObjs = oParent.getElementsByTagName(tagName);
		}
		else
		{
			if(tagName)
				aObjs = document.getElementsByTagName(tagName);
			else
				aObjs = document.getElementsByName(oName);
		}
	}
	else if(tagName)
	{
		if(oParent)
		{
			oParent = EQX.$(oParent);
			aObjs = oParent.getElementsByTagName(tagName);
		}
		else
		{
			aObjs = document.getElementsByTagName(tagName);
		}
	}

	var aObjsF = new Array();
	for(var i = 0; i < aObjs.length; i++)
	{
		if((!oName || (aObjs[i].name == oName) || (aObjs[i].id == oName)
				|| (partial_name && ((aObjs[i].name.indexOf(oName) >= 0) || (aObjs[i].id.indexOf(oName) >= 0))))
		 	&& (!tagName || (aObjs[i].nodeName.toUpperCase() == tagName)))
		{
			aObjsF[aObjsF.length] = aObjs[i];
		}
	}

	return aObjsF;
}

function objs_setAttribute(tagName, oName, attribName, attribValue, oParent)
{
	if(!attribName)
		return null;

	if(!(aObjs = objs_get(tagName, oName, oParent)))
		return null;

	for(var i = 0; i < aObjs.length; i++)
	{
		if(!aObjs[i].disabled)
			obj_setAttribute(aObjs[i], attribName, attribValue)
	}
}


//object dragging
var obj_dragged;
function obj_dragStart(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	if(obj_dragged && obj_dragged.dragging)
		return;

	var obj = EQX.F.Event.getSender(evt);
	if(!obj) return;

	if(obj.className == "fbox_h")
		obj_dragged = obj.parentNode;
	else
		return;

	EQX.F.Obj.fixBeneath(obj_dragged);

	if(EQX.$(obj_dragged.id + '_c'))
		EQX.$(obj_dragged.id + '_c').style.display = 'none';

	if(!obj_hasPos(obj_dragged))
		obj_initPos(obj_dragged);

	var p = EQX.F.Event.getXY(evt);
	var op = obj_getPos(obj_dragged);
	obj_dragged.drag_ox = p.x - op.x;
	obj_dragged.drag_oy = p.y - op.y;

	obj_dragged.dragging = true;
	obj_registerEvent(document, "mousemove", obj_dragMove);
	obj_registerEvent(document, "mouseup", obj_dragEnd);

	return EQX.F.Event.stop(evt);
}

function obj_dragMove(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	if(!obj_dragged || !obj_dragged.dragging)
		return;

	var p = EQX.F.Event.getXY(evt);
	obj_setPos(obj_dragged, p.x - obj_dragged.drag_ox, p.y - obj_dragged.drag_oy);
	EQX.F.Obj.fixBeneath(obj_dragged);

	return EQX.F.Event.stop(evt);
}

function obj_dragEnd(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	if(!obj_dragged || !obj_dragged.dragging)
		return false;

	obj_unregisterEvent(document, "mousemove", obj_dragMove);
	obj_unregisterEvent(document, "mouseup", obj_dragEnd);

	if(EQX.$(obj_dragged.id + '_c'))
		EQX.$(obj_dragged.id + '_c').style.display = '';

	var p = obj_getRelPos(obj_dragged);
	setCookie(obj_dragged.id + "_pos", p.x + ":" + p.y);

	EQX.F.Obj.fixBeneath(obj_dragged);

  	obj_dragged = null;

	return EQX.F.Event.stop(evt);
}

function obj_clifoc(obj)
{
	obj = EQX.$(obj);
	if(obj)
	{
		obj.click();
		obj_foc(obj);
	}
}

function obj_addClass(obj, c)
{
	obj = EQX.$(obj);
	if(!obj) return;

	if(typeof(c) == 'string')
		c = [c];

	for(var i = 0; i < c.length; i++)
	{
		if(!l_contains(obj.className, c[i], " "))
			obj.className = l_append(obj.className, c[i], " ");
	}
}
function obj_rmClass(obj, c)
{
	obj = EQX.$(obj);
	if(!obj) return;

	if(typeof(c) == 'string')
		c = [c];

	if(c.length)
	{
		for(var i = 0; i < c.length; i++)
			obj.className = l_delete(obj.className, c[i], " ");
	}
}
function obj_hasClass(obj, c)
{
	obj = EQX.$(obj);
	if(!obj) return false;
	return l_contains(obj.className, c, " ");
}
function obj_decodeClass(obj, aClasses, aValues, def_val)
{
	obj = EQX.$(obj);
	if(!obj) return false;
	for(var i = 0; i < aClasses.length; i++)
	{
		if(l_contains(obj.className, aClasses[i], " "))
			return aValues[i];
	}

	return def_val;
}


function t_create(id, parent, cellPadding, cellSpacing)
{
	var t = obj_create("table", parent, id);
	t.cellPadding = def(cellPadding) ? cellPadding : 0;
	t.cellSpacing = def(cellSpacing) ? cellSpacing : 0;

	return t;
}

/******************************************************************************
   adds a tr to a table
******************************************************************************/
function t_addTR(t, tr_id, tr_idx)
{
	t = EQX.$(t);
	if(!t) return null;

	var tr;
	if(t.insertRow)
	{
		if(typeof(tr_idx) != "number")
			tr_idx = t.rows.length;

		tr = t.insertRow(tr_idx);
	}
	else
	{
		tr = obj_create("tr", t);
	}

	tr.id = tr_id;

	return tr;
}

function t_deleteAllRows(t)
{
	t = EQX.$(t);
	while(t.rows.length > 0)
		t.deleteRow(0);
}

function tr_addTD(tr, td_id, content, align, is_th)
{
	var td;
	if(is_th)
		td = obj_create("th", tr);
	else
		td = obj_create("td", tr);

	if(typeof(id) == "string")
		td.id = td_id;

	if(typeof(align) == "string")
		td.align = align;

	if(typeof(content) == "string")
		td.innerHTML = content;

	return td;
}

function tr_getCell(tr, cellIndex)
{
	return tr.cells[cellIndex];
}

function tr_getCellContent(tr, cellIndex)
{
	return tr.cells[cellIndex].innerHTML;
}

function hid_create(name, value, parent)
{
	var hid = obj_create("input");
	hid.setAttribute("type", "hidden");
	hid.name = name;
	hid.id = name;
	hid.value = value;

	if(typeof(parent) != "undefined")
		EQX.$(parent).appendChild(hid);

	return hid;
}

function chk_create(name, value, checked, parent, disabled)
{
	if(typeof(checked) == "undefined")
		checked = false;
	if(typeof(disabled) == "undefined")
		disabled = false;

	var chk = obj_create("input");
	chk.setAttribute("type", "checkbox");
	chk.name = name;
	chk.value = value;
	chk.checked = checked;
	chk.disabled = disabled;

	if(typeof(parent) != "undefined")
		EQX.$(parent).appendChild(chk);

	return chk;
}


function chk_getSelectedValues(p, chkName)
{
	var allI;
	if(p)
		allI = EQX.$(p).getElementsByTagName("input");
	else
		allI = document.getElementsByTagName("input");

	var aSelValues = new Array();

	for(var i = 0; i < allI.length; i++)
	{
		if((allI[i].name == chkName) && !allI[i].disabled && allI[i].checked)
			aSelValues[aSelValues.length] = allI[i].value;
	}

	return aSelValues;
}


function rad_getSelected(p, chkName)
{
	var allI = EQX.$(p).getElementsByTagName("input");
	var aSelValues = new Array();

	for(var i = 0; i < allI.length; i++)
	{
		if((allI[i].name == chkName) && !allI[i].disabled && allI[i].checked)
			return allI[i].value;
	}

	return null;
}


function chk_selectAll(frm, chkName, counter)
{
	if(typeof(frm) == "string")
		frm = frm_get(frm);

	if(!window[counter])
		window[counter] = 0;

	var c = window[counter];
	var set = (c <= 0);

	c = 0;
	for(var i = 0; i < frm.elements.length; i++)
	{
		if((frm.elements[i].name == chkName) && !frm.elements[i].disabled)
		{
			frm.elements[i].checked = set;
			if(set)
				c++;
		}
	}
	window[counter] = c;
}

function chk_check(evt, counter)
{
	if(!window[counter])
		window[counter] = 0;

	EQX.F.Event.getSender(evt).checked ? window[counter]++ : window[counter]--;
}

function t_alternateBg(t, class_dark, class_light)
{
	t_ = EQX.$(t);
	var allR = t_.getElementsByTagName("tr");
	var r_bg = false;
	for(var i = 0; i < allR.length; i++)
	{
		if((allR[i].style.display != 'none'))
			allR[i].className = ((r_bg = !r_bg) ? class_light : class_dark);
	}

	return r_bg;
}


/******************************************************************************
	COMBOBOX FUNCTIONS
******************************************************************************/
function cmb_create(name, parent)
{
	return obj_create("select", parent, name);
}

function cmb_stealOptions(cmb, cmbOpt)
{
	cmb = EQX.$(cmb);
	cmbOpt = EQX.$(cmbOpt);
	if(!cmb || !cmbOpt) return;

	for(var i = 0; i < cmbOpt.options.length; i++)
		cmb_addOpt(cmb, cmbOpt[i].text, cmbOpt[i].value);
	cmb.selectedIndex = cmbOpt.selectedIndex;
}

function cmb_addOpt(cmb, text, val, selected, unique)
{
	if(typeof(cmb) == "string")
		cmb = EQX.$(cmb);
	if(!cmb) return;

	if(unique)
		cmb_deleteOptByVal(cmb, val);

	if(typeof(selected) == "undefined")
		selected = false;

	cmb.options[cmb.options.length] = new Option(text, val, selected, selected);
}

function cmb_selectOptByVal(cmb, val, cond_sel)
{
	if(typeof(cmb) == "string")
		cmb = EQX.$(cmb);
	if(!cmb || ((typeof(cond_sel) != "undefined") && (cmb.selectedIndex != cond_sel))) return;

	for(var i = 0; i < cmb.options.length; i++)
	{
		if(cmb[i].value == val)
		{
			cmb.selectedIndex = i;
			return;
		}
	}
}

function cmb_loadFromArray(cmb, a)
{
	if(typeof(cmb) == "string")
		cmb = EQX.$(cmb);
	if(!cmb) return;

	cmb.options.length = 0;
	for(var i = 0; i < a.length; i++)
		cmb_addOpt(cmb, a[i], a[i]);
}

function cmb_deleteOptByVal(cmb, val)
{
	if(typeof(cmb) == "string")
		cmb = EQX.$(cmb);
	if(!cmb) return;

	for(var i = 0; i < cmb.options.length; i++)
	{
		if(cmb[i].value == val)
		{
			cmb[i] = null;
			return;
		}
	}
}

/******************************************************************************
	FORM FUNCTIONS
******************************************************************************/
var aFrmChecks = new Object();

function frm_get(frm)
{
	if(typeof(frm) == "string")
		return document[frm];
	else
		return frm;
}

// Adds an input object to a form
function frm_addInput(frm, i_type, i_name, i_value)
{
	if(typeof(frm) == "string")
		frm = frm_get(frm);

	var i = obj_create("input");
	i.setAttribute("type", i_type);
	i.id =  i_name;
	i.name = i_name;
	i.value = i_value;
	obj_setParent(i, frm);

	return i;
}

function frm_addCheck(frm, obj, check_t, js)
{
	obj = EQX.$(obj);
	if(!obj) return;

	if(typeof(frm) == "object")
		frm = frm.name;

	if(!aFrmChecks[frm])
		aFrmChecks[frm] = new Array();

	aFrmChecks[frm][aFrmChecks[frm].length] = {o: obj, t: check_t, js: js};
}

function frm_clearObjChecks(frm, obj)
{
	obj = EQX.$(obj);
	if(!obj) return;

	if(typeof(frm) == "object")
		frm = frm.name;

	if(!aFrmChecks[frm])
		return;

	var i = 0;
	while(i < aFrmChecks[frm].length)
	{
		if(aFrmChecks[frm][i].o == obj)
			aFrmChecks[frm].rm(i);
		else
			i++;
	}
}

//sets the action and submits a form
function frm_act(frm_act, frm, hid, execute_checks)
{
	if(!frm)
		frm = "frmCMSA";

	if(typeof(frm) == "string")
		frm = document[frm];

	var frm_name = frm.name, tagName;

	if(((frm_act == "ok") || (frm_act.substring(0, 6).toLowerCase() == "update") || execute_checks) && aFrmChecks[frm_name] && !((typeof(execute_checks) == "boolean") && (execute_checks == false)))
	{
		var aChk = aFrmChecks[frm_name], obj, trigger = false, tamp;

		for(var i = 0; i < aChk.length; i++)
		{
			if(!aChk[i].t || !aChk[i].o)
				continue;

			obj = aChk[i].o;
			tagName = obj.nodeName.toLowerCase();
			switch(aChk[i].t)
			{
				case "empty":
				{
					trigger = (((tagName == "input") || (tagName == "textarea")) && !obj.value.length) || ((tagName == "select") && (obj.selectedIndex < 0));

					break;
				}

				case "int":
				case "uint":
				case "pint":
				{
					if(tagName != "input")
						continue;

					tamp = parseInt(obj.value);
					trigger = (tamp + "" != obj.value) || ((aChk[i].t == "uint") && (tamp < 0)) || ((aChk[i].t == "pint") && (tamp < 1));

					break;
				}
			}

			if(trigger)
			{
				if(aChk[i].js.substring(0, 3).toLowerCase() == 'a::')
					aChk[i].js = 'alert("' + aChk[i].js.substring(3) + '");';
				tamp = aChk[i].js ? eval(aChk[i].js) : true;
				if(tamp != false)
				{
					obj_foc(obj);
					obj.className += " err";

					return;
				}
			}
		}
	}

	if(!hid || ((typeof(hid) != "string") && (typeof(hid) != "object")))
		hid = FRM_ACTION;

	if(!EQX.$(hid))
		frm_addInput(frm, "hidden", hid);

	obj_setVal(hid, frm_act);

	frm.submit();
}

function frm_foc(evt, name)
{
	evt = (evt ? evt : (window.event ? event : null));
	if(evt.keyCode == 13)
	{
		evt.keyCode = 0;
		var obj = EQX.F.Event.getSender(evt);
		var frm = obj.form;
		if(frm[name])
			obj_foc(frm[name]);

		return EQX.F.Event.stop(evt);
	}
}

function frm_kd13(evt, js)
{
	evt = (evt ? evt : (window.event ? event : null));
	if(evt.keyCode == 13)
	{
		try{evt.keyCode = 0;}catch(e){}
		eval(js);

		return EQX.F.Event.stop(evt);
	}
}


function obj_valLen(obj)
{
	obj = EQX.$(obj);
	if(!obj || !obj.value) return 0;

	return obj.value.length;
}

function obj_setVal(obj, value)
{
	obj = EQX.$(obj);
	if(!obj || (typeof(obj.value) == "undefined")) return;

	obj.value = value;
}


/******************************************************************************
	IFRAME FUNCTIONS
******************************************************************************/
function if_go(f, url)
{
	if(typeof(f) == "string")
		frames[f].location.href = url;
	else
		f.src = url;
}

function if_win(if_)
{
	var i = EQX.$(if_, 'iframe');
	if(!i) return null;
	return i.contentWindow || i.contentDocument;
}

function if_doc(if_)
{
	var ifw = if_win(if_);
	return ifw.document || null;
}

function if_foc(if_)
{
	var i = EQX.$(if_);
	if(i)
	{
		i = if_win(if_);
	}
	else
	{
		if(frames[if_])
			i = frames[if_];
		else
			return false;
	}

	i.focus();
	return true;
}



/******************************************************************************
	CALLBACK FUNCTIONS
******************************************************************************/
var cb_busy = false;
function cb_start(cb)
{
	if(cb_busy)
	{
		alert("Callback busy...");
		return false;
	}

	cb_busy = true;

	var cb_id = Math.random();
	eval("window.__cb__" + cb + " = " + cb_id);
	setTimeout("cb_raise('" + cb + "', " + cb_id + ")", 5000);

	return true;
}

function cb_stop(cb)
{
	eval("window.__cb__" + cb + " = null");
	cb_busy = false;
}

function cb_raise(cb, cb_id)
{
	if(eval("window.__cb__" + cb) == cb_id)
	{
		alert("Waiting too long for the callback...");
		cb_stop(cb);
	}
}


/******************************************************************************
	STRING LISTS
******************************************************************************/
function l_append(l, v, s)
{
	if(l == "") return v;
	if(!s) s = ",";

	var lh;
	if((lh = EQX.$(l)) && lh.type && (lh.type = "hidden"))
		lh.value = lh.value + (lh.value.length ? s : "") + v;
	else
		return l + (l.length ? s : "") + v;
}

function l_delete(l, v, s)
{
	if(l == "") return "";
	if(!s) s = ",";

	var lh, re, r_;
	re = eval("/" + s + v + s + "/g");
	if((lh = EQX.$(l)) && lh.type && (lh.type = "hidden"))
	{
		r_ = (s + lh.value + s).replace(re, s);
		lh.value = r_.substr(1, r_.length - 2);
	}
	else
	{
		r_ = (s + l + s).replace(re, s);
		return r_.substr(1, r_.length - 2);
	}
}

function l_contains(l, v, s)
{
	if(l == "") return false;
	if(!s) s = ",";

	var lh = EQX.$(l);
	v = s + v + s;
	if(lh && lh.type && (lh.type = "hidden"))
		return ((s + lh.value + s).indexOf(v) != -1);
	else
		return ((s + l + s).indexOf(v) != -1);
}



/******************************************************************************
	EVENTS
******************************************************************************/
function evt_cs(evt, aNames, aValues)
{
	var obj = EQX.F.Event.getSender(evt);
	if(!obj || !aNames.length || !aValues.length)
		return;

	for(var i = 0; i < aNames.length; i++)
		obj.style[aNames[i]] = aValues[i];
}


function evt_ul(evt, underline)
{
	var obj = EQX.F.Event.getSender(evt);
	if(!obj) return;
	while(obj.className != "simple")
	{
		obj = obj.parentNode;
		if(!obj) return;
	}

	obj.style.textDecoration = underline ? "underline" : "";
}


/******************************************************************************
	SMALL BUT USEFUL
******************************************************************************/

function var_def(var_, def_val)
{
	return (typeof(var_) == "undefined") ? def_val : var_;
}

function in_array(a, v)
{
	for(var i = 0; i < a.length; i++)
	{
		if(a[i] == v)
			return true;
	}

	return false;
}

function setCookie(name, value, ttl)
{
	var c = name + "=" + value + ";path=/" + (ttl ? ";expires=" + ttl.toGMTString() : "");//;domain= ;secure
	document.cookie = c;
}

function getCookie(name)
{
	var c = document.cookie;
	var p = c.indexOf(name + "=");
	if(p < 0)
		return null;

	var ep = c.indexOf(";", p);
	return c.substring(p + name.length + 1, ((ep == -1) ? c.length : ep));
}

function setWindowStatus(str)
{
	window.status = str;
}

function str_trimRight(str)
{
	return str.replace(/\s+$/, '');
}

function str_trim(str)
{
	return str.replace(/(^\s+|\s+$)/g, '');
}

function def(v)
{
	return (typeof(v) != "undefined");
}

function undef(v)
{
	return (typeof(v) == "undefined");
}

function clip_copy(str)
{
	if(window.clipboardData)
	{
		window.clipboardData.setData("Text", str);
		return true;
	}

	return false;
}


//XMLHttpRequest component
var XReq;
function XReqHandler()
{
	this.JS_REQ = 1;

	this.XObj = null;
	this.busy = false;
	this.msg_div = null;

	this.cbFunction = null;

	this.showBusy = function(show)
	{
		if(!this.msg_div)
		{
			this.msg_div = div_create('div_xreq', document.body);
			EQX.$h(this.msg_div);
			this.msg_div.className = 'xreq_busy m';
			this.msg_div.innerHTML = 'Loading...';
		}

		if(show && this.busy)
		{
			this.msg_div.style.top = body_getScrollOffset().y + 5 + "px";
			EQX.$s(this.msg_div);
		}
		else
			EQX.$h(this.msg_div);
	}


	this.setBusy = function(busy)
	{
		this.busy = busy;

		if(busy)
			setTimeout("XReq.showBusy(true);", 200);
		else
			this.showBusy(false);
	}


	this.request = function(cbFunction, url)
	{
		if(this.busy || !doc_loaded)
			return false;

		if(window.XMLHttpRequest)
			this.XObj = new XMLHttpRequest();
		else if(window.ActiveXObject)
			this.XObj = new ActiveXObject("Microsoft.XMLHTTP");

		if(!this.XObj)
			return false;

//alert(url);
		this.setBusy(true);
		this.cbFunction = cbFunction;
		this.XObj.onreadystatechange = function(){XReq.response();};
		this.XObj.open('GET', url, true);
		this.XObj.send(null);

		return true;
	}


	this.post = function()
	{

	}


	this.requestChain = function(aChain)
	{
	}


	this.response = function(url)
	{
		if(this.XObj.readyState != 4)
			return;

		this.setBusy(false);

		try
		{
		if(this.XObj.status != 200)
			return;
		}
		catch(e)
		{
//			alert(this);
			alert('in');
			alert(this.XObj);
			alert(this.XObj.status);
			alert('out');
		}

		var text = this.XObj.responseText;
if(parent.obj_setVal)
	parent.obj_setVal("edt111", text);
else
	obj_setVal("edt111", text);
//alert(text);

		var ct = this.XObj.getResponseHeader('Content-Type');
		if(ct) ct = ct.toLowerCase();

		var cbFunction = this.cbFunction;

		if(cbFunction == this.JS_REQ && (ct == "text/javascript" || ct == "application/x-javascript"))
		{
			if(text.length)
			{
				eval(text);
			}
		}
		else if(cbFunction != this.JS_REQ)
		{
			if(cbFunction)
			{
				if(typeof(cbFunction) == "string")
					eval(cbFunction);
				else if(typeof(cbFunction) == "function")
					cbFunction(ct, text);
			}
		}
	}
}
XReq = new XReqHandler();


function lookup_box()
{
	this.timer = null;
	this.obj = null;
	this.div = null;
	this.on_screen = false;
	this.limit = 15;
	this.val_sep = null;

	this.register = function(obj, val_sep, xreq)
	{
		if(!window["LookupStatic"])
			window["LookupStatic"] = this;

		obj = EQX.$(obj);
		if(!obj) return false;

		this.obj = obj;
		this.div = null;
		if(val_sep)
			this.val_sep = val_sep;
		this.xreq = xreq || false;
		if(this.xreq)
		{
			//
			this.delay = 300;
		}
		else
		{
			this.list = null;
			this.delay = 150;
		}
		this.searched_val = null;
		this.lb_id = "lookupBox_" + obj.id;
		window[this.lb_id] = this;

		obj_setAttribute(obj, "autocomplete", "off");

		if(document.all && !isOpera)
		{
			obj_registerEvent(obj, "keydown", LookupStatic.kd);
		}
		else
		{
			this.old_kp = obj.onkeypress;
			obj.onkeypress = null;
			obj_registerEvent(obj, "keypress", LookupStatic.kd);
		}

		obj_registerEvent(obj, "blur", LookupStatic.b);

		return true;
	}


	this.kd = function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));

		var obj = EQX.F.Event.getSender(evt);
		var lb_id = "lookupBox_" + obj.id;
		var lb = window[lb_id];

		if(!this.xreq && !lb.list.length)
			return true;

		if(this.timer)
			clearTimeout(this.timer);

		var key = (evt.keyCode ? evt.keyCode : evt.which);

		switch(key)
		{
			//vertical arrows(up, down)
			case 38:
			case 40:
			{
				if(EQX.F.Event.isShiftDown(evt) || !lb.on_screen)
					break;

				lb.select(lb.selectedIndex + (key == 38 ? -1 : 1));
				return EQX.F.Event.stop(evt);
			}

			//enter
			case 13:
			{
				if(!lb.on_screen)
				{
					if(typeof(lb.old_kp) == "function")
						lb.old_kp(evt);

					return true;
				}

				lb.pick();
				return EQX.F.Event.stop(evt);
			}

			//esc
			case 27:
			{
				lb.hide();
				return EQX.F.Event.stop(evt);
			}

			//backspace
			case 8:
			{
				if(lb.obj_getVal().length == 1)
				{
					lb.hide();
					return true;
				}

				break;
			}
		}

		if(((key > 31) || (key == 8)) && (key != 45) &&(EQX.F.Event.isShiftDown(evt) || ((key != 35) && (key != 36) && (key != 37) && (key != 38) && (key != 39))))
		{
			this.timer = setTimeout("LookupStatic.display_results(" + lb_id + ");", this.delay);
		}

		if(typeof(lb.old_kp) == "function")
			lb.old_kp(evt);

		return true;
	}


	this.b = function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));

		if(this.timer)
			clearTimeout(this.timer);

		var obj = EQX.F.Event.getSender(evt);
		var lb_id = "lookupBox_" + obj.id;
		var lb = window[lb_id];

		lb.hide();
	}


	this.display_results = function(lb)
	{
		var obj = lb.obj, val = lb.obj_getVal();
		if(!val || !val.length) // || (lb.searched_val == val)
		{
			if(lb.searched_val == val)
				lb.hide();

			return;
		}

		lb.searched_val = val;

		if(lb.xreq)
		{
			//
		}
		else
		{
			var c = 0, a = new Array();
			for(var i = 0; i < lb.list.length; i++)
			{
				if(lb.list[i] && (lb.list[i].toLowerCase().indexOf(val) >= 0))
				{
					a[c++] = lb.list[i];
					if(c == lb.limit)
						break;
				}
			}

			lb.render_results(lb, val, a);
		}
	}


	this.render_results = function(lb, val, aResults)
	{
		if(!aResults.length || ((aResults.length == 1) && (aResults[0].toLowerCase() == lb.searched_val)))
		{
			lb.hide();
			return;
		}

		if(!lb.div)
		{
			lb.div = div_create("divLookupBox");
			EQX.$h(lb.div);
			EQX.F.Obj.fixBeneath(lb.div);
			lb.div.lb_id = lb.lb_id;
			lb.div.list = obj_create("ul", lb.div, "ulLookupBox");
			lb.div.className = "lookup";
		}
		var p = obj_getAbsPos(lb.obj), s = obj_getSize(lb.obj);
		lb.div.style.top = p.y + s.y + 1 + "px";
		lb.div.style.left = p.x + "px";
		lb.div.style.width = s.x + "px";

		obj_removeChildNodes(lb.div.list);
		var rval, li, re;
		rval = val.replace("<", "&lt;").replace(">", "&gt;").replace("(", "\\(").replace(")", "\\)").replace("[", "\\[").replace("]", "\\]");
		re = new RegExp('(' + rval + ')', 'i');
		for(var i = 0; i < aResults.length; i++)
		{
			li = obj_create("li", lb.div.list);
			li.innerHTML = aResults[i].replace("<", "&lt;").replace(">", "&gt;").replace(re, "<b>$1</b>");
			li._lookup_id = i;
			li._lookup_v = aResults[i];
			obj_registerEvent(li, "mouseover", 'LookupStatic.li_event(evt, "over");');
			obj_registerEvent(li, "mousedown", 'LookupStatic.li_event(evt, "mdown");');
		}

		lb.select(0);
		lb.show();
	}


	this.show = function()
	{
		EQX.$s(this.div);
		EQX.F.Obj.fixBeneath(this.div);
		this.on_screen = true;
	}


	this.hide = function()
	{
		EQX.$h(this.div);
		EQX.F.Obj.fixBeneath(this.div);
		this.on_screen = false;
		this.searched_val = null;
	}


	this.select = function(idx)
	{
		if(!this.div)
			return false;

		if(idx < 0)
			idx = this.div.list.childNodes.length - 1;
		else if(idx >= this.div.list.childNodes.length)
			idx = 0;

		if((typeof(this.selectedIndex) != "undefined") && this.div.list.childNodes[this.selectedIndex])
			this.div.list.childNodes[this.selectedIndex].className = "";

		this.div.list.childNodes[idx].className = "sel";
		this.selectedIndex = idx;

		return true;
	}


	this.pick = function()
	{
		var val = this.curVal();
		if(this.val_sep)
		{
			var old_val = EQX.$value(this.obj);
			if(old_val.lastIndexOf(this.val_sep) >= 0)
			{
				val = old_val.substring(0, old_val.lastIndexOf(this.val_sep)) + this.val_sep + " " + val;
			}
			val +=  this.val_sep + " ";
		}

		obj_setVal(this.obj, val);
		F.Sel.select(this.obj, val.length, val.length);

		this.hide();
	}


	this.obj_getVal = function()
	{
		var val = EQX.$value(this.obj), rval;

		if(this.val_sep && (val.lastIndexOf(this.val_sep) >= 0))
			rval = val.substring(val.lastIndexOf(this.val_sep) + this.val_sep.length);
		else
			rval = val;

		return str_trim(rval.toLowerCase());
	}


	this.curVal = function()
	{
		return this.div.list.childNodes[this.selectedIndex]._lookup_v;
	}


	this.li_event = function(evt, et)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		var lb_id = obj.parentNode.parentNode.lb_id;
		if(!window[lb_id]) return true;

		var lb = window[lb_id];

		switch(et)
		{
			case "over":
			{
				lb.select(obj._lookup_id);
				break;
			}

			case "mdown":
			{
				lb.pick();
				break;
			}
		}

		EQX.F.Event.stop(evt);

		return false;
	}

}

var H = {
	spLink : function(click, text)
	{
		return '<span onclick="' + click + '" class="simple" style="margin-left: 0px;" onblur="evt_ul(event);" onmouseover="evt_ul(event,1);" onmouseout="evt_ul(event);">' + text + '</span>';
	}
}

var F =
{
	allPopups : {},

	isNumericKey : function(keyCode)
	{
		return keyCode >= 48 && keyCode <= 57;
	},

	daysInMonth : function(year, month)
	{
		var a = [31, ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		if(a[--month])
			return a[month];
		return -1;
	},

	logDiv : null,
	logBG : false,

	logCreate : function()
	{
		if(F.logDiv)
			return;

		F.logDiv = obj_create("div", document.body);
		with(F.logDiv)
		{
			className = "f_logDiv";
		}
	},

	logResize : function(x, y)
	{
		F.logCreate();
		F.logDiv.style.width = x + 'px';
		F.logDiv.style.height = y + 'px';
	},

	log : function(s)
	{
		F.logCreate();

		var d = obj_create("div", F.logDiv);
		d.innerHTML = s;
		F.logBG = !F.logBG;
		d.className = F.logBG ? 'gray_row' : 'light_row';
	},

	logObject : function(obj, show_objects, show_functions, show_events, hide_scalars)
	{
		var s = EQX.F.Obj._dump(obj, show_objects, show_functions, show_events, hide_scalars);
		s = s.replace(/^\[(\S+)\]/, "<b>$1</b>");
		s = s.replace(/\n\[(\S+)\]/g, "<br /><b>$1</b>");
		F.log(s);
	},

	logSep : function(s)
	{
		F.logCreate();

		var d = obj_create("hr", F.logDiv);
	}

};


//selection
F.Sel =
{
		select : function(obj, start, end)
	{
		obj = EQX.$(obj);
		if(obj.setSelectionRange)
		{
			try
			{
				obj.focus();
				obj.setSelectionRange(start, end);
			}
			catch(e){}
		}
		else if(obj.createTextRange)
		{
			var r = obj.createTextRange();
			r.collapse(true);
			r.moveEnd('character', end);
			r.moveStart('character', start);
			r.select();
		}
	},

		get : function(w)
	{
		if(!w) w = window;

		if(w.getSelection)
			return w.getSelection();
		else if(w.document && w.document.selection)
			return w.document.selection;

		return null;
	},

	getRange : function(w)
	{
		var sel = F.Sel.get(w);
		if(!sel) return null;

		if(sel.rangeCount && (sel.rangeCount > 0))
			return sel.getRangeAt(0);
		else if(sel.createRange)
			return sel.createRange();

		return null;
	},

	/*
	getSelectedText : function(w)
	{
		var r = F.Sel.getRange();
		if(!r) return '';

		if(r.htmlText)
			return r.htmlText;
		else if(r.endContainer)
		{
			var ss = r.cloneContents();
//			alert(r.toString());
		}
		return '';
	},
	*/

	getCaretPos : function(obj, w)
	{
		if(def(obj.selectionEnd))
			return obj.selectionEnd;

		var r = F.Sel.getRange(w);
		if(!r) return null;

		if(r.parentElement() == obj)
		{
			r.moveStart('textedit', -1);
			return r.text.length;
		}

		return null;
	},

	setCaretPos : function(obj, pos, w)
	{
		F.Sel.select(obj, pos, pos);
	},

		getContainer : function(w)
	{
		var r = F.Sel.getRange(w);
		if(!r) return null;

		if(r.parentElement)
		{
			return r.parentElement();
		}
		else if(r.commonAncestorContainer)
		{
			var obj = r.commonAncestorContainer;
			if(obj.nodeType == 3)
				obj = obj.parentNode;
			return obj;
		}

		return null;
	},

		getParents : function(w)
	{
		if(!F.Sel.get(w))
			return null;

		var r = F.Sel.getRange(w);
		if(r.parentElement)
		{
			var rt = r.text.length - str_trimRight(r.text).length;
			if(rt > 0)
			{
				r.moveEnd("character", -rt);
				return obj_getParents(r.parentElement());
			}
		}
		else
		{
			var sc = r.startContainer;
			var ec = r.endContainer;

			if(sc == ec)
			{
				if((sc.nodeType == 1) && (sc.tagName == "BODY"))
				{
					for(var i = 0; i < sc.childNodes.length; i++)
					{
						if((sc.childNodes[i].nodeType == 1) && (sc.childNodes[i].tagName != "BR"))
							return [sc.childNodes[i]];
					}
				}

				if(sc.nodeType == 3)
					sc = sc.parentNode;

				return obj_getParents(sc);
			}

			if(sc.nodeType == 3)
			{
				if((ec.nodeType == 1) && (ec.tagName == "BODY"))
				{
					if(sc.nodeType == 3)
						sc = sc.parentNode;
					return obj_getParents(sc);
				}

				if(r.startOffset == sc.nodeValue.length)
				{
					if(obj_isParentOf(sc.nextSibling, ec))
					{
						if(ec.nodeType == 3)
							ec = ec.parentNode;
						return obj_getParents(ec);
					}
				}
			}

			if((sc.nodeType == 1) && (sc.tagName == "BODY"))
			{
				if(ec.nodeType == 3)
					ec = ec.parentNode;
				return obj_getParents(ec);
			}

		}

		return obj_getParents(F.Sel.getContainer(w));
	},


	getSubtreeBounds : function(w)
	{
		if(!w) w = window;

		var r = F.Sel.getRange(w), root, start, end;

		// Gecko, Opera
		if(r.startContainer)
		{
			start = r.startContainer;
			end = r.endContainer;
			root = r.commonAncestorContainer;

			if(start == end)
				root = start;

			if(start.nodeName.toLowerCase() == "body")
				return null;

//			if(start.nodeType == 3)
//				start = start.parentNode;
//
//			if(end.nodeType == 3)
//				end = end.parentNode;

			return {root: root, start: start, end: end};
		}
		else if(r.duplicate) // MSIE
		{
			var r1 = r.duplicate();
			var r2 = r.duplicate();

			r1.collapse(true);

			r2.moveToElementText(r1.parentElement());
			r2.setEndPoint("EndToStart", r1);
			start = r1.parentElement();
//			start = r1.parentElement();

			r1 = r.duplicate();
			r2 = r.duplicate();
			r2.collapse(false);
			r1.moveToElementText(r2.parentElement());
			r1.setEndPoint("StartToEnd", r2);
			end = r2.parentElement();

			root = r.parentElement();
			if(start == end)
				root = start;

			return {root: root, start: start, end: end};
		}

		return null;
	},

	getElementsInSubtree : function(bounds, tagName, recursive)
	{
		var root = bounds.root, start = bounds.start, end = bounds.end;

		// stage: 0 - before start; 1 - between start and end; 2 - past end
		if(undef(F.Sel.stage))
			F.Sel.stage = 0;

		if(start == end)
			return [start];

		if(!root.firstChild)
			return [];

		if(tagName)
			tagName = tagName.toLowerCase();

		if(F.Sel.stage == 2)
			return [];

		var a = [];
		var child = root.firstChild;
		do{
			if((child == start) && (F.Sel.stage == 0))
				F.Sel.stage = 1;

			if((child.nodeName.toLowerCase() == tagName) && (child.nodeType != 3) || !tagName)
			{
				if(F.Sel.stage == 1)
					a.push(child);
			}

			if((child == end) && (F.Sel.stage == 1))
				F.Sel.stage = 2;

			a = a.concat(F.Sel.getElementsInSubtree({root:child, start:start, end:end}, tagName, true));
		}while(child = child.nextSibling)

		return a;
	},

	getObjects : function(w, tagName)
	{
		var bounds = F.Sel.getSubtreeBounds(w)
		if(!bounds)
			return null;

		if(tagName)
		{
			tagName = tagName.toLowerCase();
			bounds.start = obj_getFirstParentOfType(bounds.start, tagName);
			bounds.end = obj_getFirstParentOfType(bounds.end, tagName);
		}
		else
		{
//			bounds.start = bounds.start.parentNode;
//			bounds.end = bounds.end.parentNode;
		}

//		F.Sel.getElementsInSubtree(bounds, tagName).dumpO();

		return F.Sel.getElementsInSubtree(bounds, tagName);
	}
}



//popup menu
F.popup = function(id)
{
	this.id = id;
	this.div = null;
	this.count = 0;
	this.items = [];
	this.oIdMap = {};
	this.on_screen = false;
	this.width = 0;
	this.width = 100;
	F.allPopups[id] = this;
}

F.popup.prototype.add = function(l, a, img)
{
	this.items[this.count++] = {label: l, action: a, img: img};
	return this.count - 1;
}

F.popup.prototype.addEx = function(id, l, a, img)
{
	if(this.oIdMap[id])
	{
		alert("An entry with the specified id already exists.\nPopup id: " + this.id + "\nEntry id: " + id);
		return -1;
	}
	this.oIdMap[id] = this.add(l, a, img);

	return this.oIdMap[id];
}

F.popup.prototype.addSep = function()
{
	this.items[this.count++] = {sep: 1};
	return this.count - 1;
}

F.popup.prototype.rm = function(idx)
{
	this.items.splice(idx, 1);
	this.count--;
}

F.popup.prototype.clear = function()
{
	this.items.splice(0, this.items.length);
	this.count = 0;
}

F.popup.prototype.update = function(idx, l, a)
{
	idx = undef(this.oIdMap[idx]) ? idx : this.oIdMap[idx];

	if(l != null)
		this.items[idx].label = l;

	if(a != null)
		this.items[idx].action = a;
}

F.popup.prototype.beginRadioGroup = function()
{
	if(!this.aRadioGroups)
		this.aRadioGroups = new Array();

	if(this.beganRadioGroup)
		this.endRadioGroup();

	this.aRadioGroups.push({b: this.count, e: 0, checked: -1});
	this.beganRadioGroup = true;

	return this.aRadioGroups.length - 1;
}

F.popup.prototype.endRadioGroup = function()
{
	if(!this.beganRadioGroup)
		return;

	this.aRadioGroups[this.aRadioGroups.length - 1].e = this.count - 1;
	if(this.aRadioGroups[this.aRadioGroups.length - 1].checked > this.count - 1)
		this.aRadioGroups[this.aRadioGroups.length - 1].checked = 0;

	this.beganRadioGroup = false;
}

F.popup.prototype.setChecked = function(rg_id, rg_pos)
{
	var item_id = this.aRadioGroups[rg_id].b + rg_pos;
	if(this.aRadioGroups && this.aRadioGroups[rg_id] && (item_id >= this.aRadioGroups[rg_id].b) && ((item_id <= this.aRadioGroups[rg_id].e) || !this.aRadioGroups[rg_id].b))
		this.aRadioGroups[rg_id].checked = item_id;
}

F.popup.prototype.getChecked = function(rg_id)
{
	if(this.aRadioGroups && this.aRadioGroups[rg_id])
		return this.aRadioGroups[rg_id].checked - this.aRadioGroups[rg_id].b;

	return null;
}

F.popup.prototype.uncheck = function(rg_id)
{
	if(this.aRadioGroups && this.aRadioGroups[rg_id])
		return this.aRadioGroups[rg_id].checked = -1;
}

F.popup.prototype.e_pop = function(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	var obj = EQX.F.Event.getSender(evt);
	if(!obj) return;

	if(evt.type == "click")
		this.pop(obj);
}

F.popup.prototype.pop = function(obj)
{
	if(this.beganRadioGroup)
		this.endRadioGroup();

	if(!this.div)
	{
		this.div = div_create(this.id);
		EQX.$h(this.div);
		EQX.F.Obj.fixBeneath(this.div);
		this.div.className = "popup";
		this.div.style.width = this.width + "px";
		this.div.ul = obj_create("ul", this.div);
	}

	if(this.aRadioGroups)
		obj_addClass(this.div.ul, "chk");
	else
		obj_rmClass(this.div.ul, "chk");

	obj_removeChildNodes(this.div.ul);
	for(var i = 0; i < this.count; i++)
	{
		if(this.items[i].visible == false)
			continue;

		if(this.items[i].sep)
		{
			obj_create("div", this.div.ul).className = "sep";
		}
		else
		{
			li = obj_create("li", this.div.ul, 'popentry_' + this.id + '_' + i);
			li.innerHTML = (this.items[i].img ? '<img src="' + this.items[i].img + '" alt="" />' : '') + this.items[i].label;
			li._popup_id = i;
			if(isIE) li.style.width = (this.width - ((document.compatMode == "CSS1Compat") ? (this.aRadioGroups ? 10 : 8) : 2) + (this.items[i].img ? 2 : 0)) + "px";
			if(this.aRadioGroups)
			{
				for(var rad_i = 0; rad_i < this.aRadioGroups.length; rad_i++)
				{
					if(this.aRadioGroups[rad_i].checked == i)
					{
						obj_addClass(li, "checked");
						break;
					}
				}
			}
			obj_registerEvent(li, "mouseover", this.li_event);
			obj_registerEvent(li, "mousedown", this.li_event);
		}
	}

	var p = obj_getAbsPos(obj), s = obj_getSize(obj), vp = body_getViewport();
	var y = p.y + s.y + 1;
	this.div.style.top = y + "px";
	var rmargin = (isIE ? 5 : 2);
	if(p.x > vp.x - this.width - rmargin)
		p.x = vp.x - this.width - rmargin;
	this.div.style.left = p.x + "px";

	this.show();

	var os = obj_getSize(this.div);
	if(vp.y < y + os.y + 3)
		this.div.style.top = (vp.y -os.y - 3) + "px";
}

F.popup.prototype.show = function()
{
	EQX.$s(this.div);
	EQX.F.Obj.fixBeneath(this.div);
	this.on_screen = true;
}

F.popup.prototype.hide = function()
{
	EQX.$h(this.div);
	EQX.F.Obj.fixBeneath(this.div);
	this.on_screen = false;
}

F.popup.prototype.li_event = function(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	var obj = EQX.F.Event.getSender(evt);
	if(undef(obj) || !obj) return;

	var li = ((obj.nodeName.toLowerCase() == "li") ? obj : obj.parentNode);
	if(undef(li._popup_id)) return true;

	var pop = F.allPopups[li.parentNode.parentNode.id], cancel = false;
	switch(evt.type)
	{
		case "mouseover":
		{
			pop.select(li._popup_id);
			cancel = true;
			break;
		}

		case "mousedown":
		{
			pop.act(li._popup_id);
			pop.hide();
			cancel = true;
			break;
		}
	}

	if(cancel) return EQX.F.Event.stop(evt);

	return true;
}

F.popup.prototype.act = function(idx)
{
	if((idx < 0) || (idx >= this.count))
		return;

	var js = this.items[idx].action;
	if(typeof(js) == "string")
		eval(js);
}

F.popup.prototype.select = function(idx)
{
	if(!this.div)
		return false;

	if(idx < 0)
		idx = this.count - 1;
	else if(idx >= this.count)
		idx = 0;

	if(!undef(this.selectedIndex))
		obj_rmClass(EQX.$('popentry_' + this.id + '_' + this.selectedIndex), "sel");
	obj_addClass(EQX.$('popentry_' + this.id + '_' + idx), "sel");
	this.selectedIndex = idx;

	return true;
}

F.popup.prototype.shEntries = function(aEntriesId, visible)
{
	if(undef(aEntriesId.length))
		aEntriesId = [aEntriesId];

	var idx;
	for(var i = 0; i < aEntriesId.length; i++)
	{
		idx = undef(this.oIdMap[aEntriesId[i]]) ? aEntriesId[i] : this.oIdMap[aEntriesId[i]];
		if(!undef(this.items[idx]))
			this.items[idx].visible = visible;
	}
}

F.popup.prototype.hideEntries = function(aEntriesId)
{
	this.shEntries(aEntriesId, false);
}

F.popup.prototype.showEntries = function(aEntriesId)
{
	this.shEntries(aEntriesId, true);
}


F.InputDM =
{
	aSep : ['.', ':', '/', ' ', '-'],
	oPatterns :{
						dd		: {mask: '99'	, min: 1, max: 31},
						mm		: {mask: '99'	, min: 1, max: 12},
						yyyy	: {mask: '9999', min: 1900, max: 2035},
						hh		: {mask: '99'	, min: 1, max: 12},
						HH		: {mask: '99'	, min: 0, max: 23},
						mi		: {mask: '99'	, min: 0, max: 59},
						ss		: {mask: '99'	, min: 0, max: 59},
						am		: {mask: 'aa'	, values: ['am', 'pm']},
						AM		: {mask: 'AA'	, values: ['AM', 'PM']}
					},

	applyMask : function(obj, mask)
	{
		obj = EQX.$(obj);

		obj.s_mask = mask;
		obj.aMask = [''];
		var c, i;
		for(i = 0; i < mask.length; i++)
		{
			c = mask.charAt(i);
			if(F.InputDM.aSep.contains(c))
			{
				obj.aMask[obj.aMask.length] = '';
				continue;
			}
			obj.aMask[obj.aMask.length - 1] += c;
		}

		obj_registerEvent(obj, 'focus'	, F.InputDM.onFocus);
		obj_registerEvent(obj, 'click'	, F.InputDM.onClick);
		obj_registerEvent(obj, 'keydown'	, F.InputDM.onKeyDown);
		obj_registerEvent(obj, 'keyup'	, F.InputDM.onKeyUp);
		obj_registerEvent(obj, 'keypress', F.InputDM.onKeyPress);
		obj_registerEvent(obj, 'blur'		, F.InputDM.onBlur);

		if(obj.value.length)
			F.InputDM.validateAllBlocks(obj);

		if(!obj.value.length || F.InputDM.getBlockCount(obj) < obj.aMask.length)
			obj.value = mask;

		F.InputM.applyMask(obj);
	},

	onFocus : function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		if(!F.InputM.isMasked(obj))
			return;

		if(obj.value.length < obj.s_mask.length)
			obj.value = obj.s_mask;

		setTimeout(function(){F.InputDM.selectBlock(obj, -2);}, 10);
	},

	onBlur : function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		if(!F.InputM.isMasked(obj))
			return;

		if(obj.value.length < obj.s_mask.length)
			obj.value = obj.s_mask;

		F.InputDM.validateAllBlocks(obj);
	},

	onClick : function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		if(!F.InputM.isMasked(obj))
			return;

		F.InputDM.selectBlock(obj);
	},

	onKeyDown : function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		if(!F.InputM.isMasked(obj))
			return;

		var k = EQX.F.Event.getKeyCode(evt);
//		setWindowStatus(k);

		var p = F.Sel.getCaretPos(obj);
		var selected = F.InputDM.isBlockSelected(obj);

		if(k == 46 && !selected && F.InputDM.isSep(obj.value.charAt(p)))
			return EQX.F.Event.stop(evt);

		if(k == 8 && F.InputDM.isSep(obj.value.charAt(p-1)))
			return EQX.F.Event.stop(evt);

		if(k == 35 || k == 36)// end/home
		{
			F.Sel.setCaretPos(obj, (k == 35 ? obj.value.length : 0));
			F.InputDM.selectBlock(obj);
			return EQX.F.Event.stop(evt);
		}

		if(k == 37 || k == 39 || k == 9)// left/right
		{
			var block_idx = F.InputDM.getBlockIdx(obj, p);
			F.InputDM.validateBlock(obj, block_idx);
			//(obj, p);
			if(selected || k == 9)
				F.InputDM.selectBlock(obj, k == 37 ? -1 : 1);
			else
				F.InputDM.selectBlock(obj);

			return EQX.F.Event.stop(evt);
		}

		if(k == 38 || k == 40)// up/down
		{
			var block_idx = F.InputDM.getBlockIdx(obj, p);
			F.InputDM.incBlockValue(obj, block_idx, k == 40);
//				F.InputDM.selectBlock(obj);
			return EQX.F.Event.stop(evt);
		}

	},


	onKeyUp : function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		if(!F.InputM.isMasked(obj))
			return;

		var k = EQX.F.Event.getKeyCode(evt);

		if(F.isNumericKey(k))
		{
			var p = F.Sel.getCaretPos(obj);
			if(!F.InputDM.isBlockSelected(obj) && F.InputDM.isSep(obj.s_mask.charAt(p)))
			{
				F.InputDM.validateBlock(obj, F.InputDM.getBlockIdx(obj, p));
				F.InputDM.selectBlock(obj, 1);
			}
		}
	},

	onKeyPress : function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		if(!F.InputM.isMasked(obj))
			return;

		var k = EQX.F.Event.getKeyCode(evt);
		var c = EQX.F.Event.getKeyAsChar(evt);
		var p = F.Sel.getCaretPos(obj);
		var selected = F.InputDM.isBlockSelected(obj);

//			setWindowStatus('.'.charCodeAt(0) + ' - [' + c + '] - ' + k);
		if(k != 38 && k != 40 && F.InputDM.isSep(c))
		{
			F.InputDM.validateBlock(obj, F.InputDM.getBlockIdx(obj, p));
			F.InputDM.selectBlock(obj, 1);
			return EQX.F.Event.stop(evt);
		}

		if(k == 8 || k == 46)
			return;

		if(F.isNumericKey(k))
		{
			if(!selected && (p >= obj.s_mask.length || F.InputDM.isSep(obj.s_mask.charAt(p))))
				return EQX.F.Event.stop(evt);

			return;
		}

		return EQX.F.Event.stop(evt);
	},


	selectBlock : function(obj, dir)
	{
		obj = EQX.$(obj);

		if(dir == -2)
			F.Sel.setCaretPos(obj, 1);

		var p = F.Sel.getCaretPos(obj);
		if(dir == -1)
			p = F.InputDM.prevSep(obj, p) - 1;
		else if(dir == 1)
			p = F.InputDM.nextSep(obj, p) + 1;

		var p1 = F.InputDM.prevSep(obj, p);
		var p2 = F.InputDM.nextSep(obj, p);
//			setWindowStatus(p + '::' + p1 + ':' + p2);
		F.Sel.select(obj, p1, p2);
	},

	isBlockSelected : function(obj)
	{
		if(obj.selectionEnd)
			return obj.selectionEnd - obj.selectionStart > 0;

		var r = F.Sel.getRange();
		if(r.htmlText)
			return r.htmlText.length > 0;

		return false;
	},

	isSep : function(ch)
	{
		return F.InputDM.aSep.contains(ch);
	},

	nextSep : function(obj, start)
	{
		var s = obj.value;
		for(var i = start; i < s.length; i++)
		{
			if(F.InputDM.isSep(s.charAt(i)))
				return i;
		}
		return s.length;
	},

	prevSep : function(obj, stop)
	{
		var s = obj.value;
		for(var i = stop-1; i > 0; i--)
		{
			if(F.InputDM.isSep(s.charAt(i)))
				return i + 1;
		}
		return 0;
	},

	getBlockIdx : function(obj, pos)
	{
		var idx = 0, s = obj.value;
		for(i = 0; i < pos; i++)
		{
			if(F.InputDM.isSep(s.charAt(i)))
				idx++;
		}

		return idx;
	},

	getBlockPattern : function(obj, block_idx)
	{
		return obj.aMask[block_idx];
	},

	getBlockCount : function(obj)
	{
		var i, c, s = obj.value, count = 0;
		for(i = 0; i < s.length; i++)
		{
			c = s.charAt(i);
			if(F.InputDM.aSep.contains(c))
				count++;
		}

		return count + 1;
	},

	getBlockContent : function(obj, block_idx)
	{
		var block = '', i, c, curBlockIdx = 0, s = obj.value;
		for(i = 0; i < s.length; i++)
		{
			c = s.charAt(i);
			if(F.InputDM.isSep(c))
			{
				if(curBlockIdx++ > block_idx)
					break;
				continue;
			}

			if(curBlockIdx == block_idx)
				block += c;
		}

		return block;
	},

	setBlockContent : function(obj, block_idx, content)
	{
		var p1 = 0, p2 = obj.value.length, i, curBlockIdx = 0, s = obj.value;
		for(i = 0; i < s.length; i++)
		{
			c = s.charAt(i);
			if(F.InputDM.aSep.contains(c))
			{
				if(++curBlockIdx > block_idx)
				{
					p2 = i;
					break;
				}

				if(curBlockIdx == block_idx)
					p1 = i + 1;
			}
		}

		obj.value = s.substring(0, p1) + content + s.substring(p2);
		F.InputDM.selectBlock2(obj, block_idx);
	},

	validateAllBlocks : function(obj)
	{
		if(obj.value == obj.s_mask)
			return;

		var i, c = F.InputDM.getBlockCount(obj);
		for(i = 0; i < c; i++)
			F.InputDM.validateBlock(obj, i);
	},

	validateBlock : function(obj, block_idx)
	{
		var block_pattern = F.InputDM.getBlockPattern(obj, block_idx);
		var block_content = F.InputDM.getBlockContent(obj, block_idx);
		var oPattern = F.InputDM.oPatterns[block_pattern];

		var s = F.InputM.validateBlock(block_content, oPattern);
		if(s !== null)
			F.InputDM.setBlockContent(obj, block_idx, s);

		if(['dd', 'mm', 'yyyy'].contains(block_pattern))
			F.InputDM.validateDay(obj);
	},

	validateDay : function(obj)
	{
		var year_idx = obj.aMask.indexOf('yyyy');
		var month_idx = obj.aMask.indexOf('mm');
		var day_idx = obj.aMask.indexOf('dd');
		if(year_idx > -1 && month_idx > -1 && day_idx > -1)
		{
			var year = parseInt(F.InputDM.getBlockContent(obj, year_idx), 10);
			var month = parseInt(F.InputDM.getBlockContent(obj, month_idx), 10);
			var day = parseInt(F.InputDM.getBlockContent(obj, day_idx), 10);
			if(!isNaN(year) && !isNaN(month) && !isNaN(day))
			{
				var dim = F.daysInMonth(year, month);
				if(dim > -1 && dim < day)
				{
					var cp = F.Sel.getCaretPos(obj);
					F.InputDM.setBlockContent(obj, day_idx, dim);
					F.Sel.setCaretPos(obj, cp);
				}
			}
		}
	},

	incBlockValue : function(obj, block_idx, decrement)
	{
		var block_pattern = F.InputDM.getBlockPattern(obj, block_idx);
		var block_content = F.InputDM.getBlockContent(obj, block_idx);
		var oPattern = F.InputDM.oPatterns[block_pattern];

		var s = F.InputM.incBlockValue(block_content, oPattern, decrement);
		if(s !== null)
			F.InputDM.setBlockContent(obj, block_idx, s);
	},

	selectBlock2 : function(obj, block_idx)
	{
		var i, curBlockIdx = 0, s = obj.value, p1 = 0, p2 = s.length;
		for(i = 0; i < s.length; i++)
		{
			c = s.charAt(i);
			if(F.InputDM.isSep(c))
			{
				if(++curBlockIdx > block_idx)
				{
					p2 = i;
					break;
				}

				if(curBlockIdx == block_idx)
					p1 = i + 1;
			}
		}
//		setWindowStatus('select2 ' + p1 + ':' + p2);
		F.Sel.select(obj, p1, p2);
	}

};


F.InputM =
{
	applyMask : function(obj)
	{
		EQX.$(obj).is_masked = true;
	},

	isMasked : function(obj)
	{
		return EQX.$(obj).is_masked === true;
	},

	removeMask : function(obj)
	{
		EQX.$(obj).is_masked = false;
	},

	validateBlock : function(block_content, oPattern)
	{
		var ptype = oPattern.mask.charAt(0);
		var plen = oPattern.mask.length;
		switch(ptype)
		{
			case '9':
			{
				var i = parseInt(block_content, 10);
				if(isNaN(i))
					i = oPattern.min;

				if(i > oPattern.max || i < oPattern.min)
					i = (i > oPattern.max) ? oPattern.max : oPattern.min;

				var s = i + '';
				if(s.length < plen)
					s = s.pad(plen, 0, true);

				if(s !== block_content)
					return s

				return null;
			}
		}
	},

	incBlockValue : function(block_content, oPattern, decrement)
	{
		var ptype = oPattern.mask.charAt(0);
		var plen = oPattern.mask.length;

		var validated = F.InputM.validateBlock(block_content, oPattern);
		if(validated !== null)
			return validated;

		switch(ptype)
		{
			case '9':
			{
				var i = parseInt(block_content, 10);
				if(decrement && i == oPattern.min)
					i = oPattern.max;
				else if(!decrement && i == oPattern.max)
					i = oPattern.min;
				else
					i += decrement ? -1 : 1;

				var s = i + '';
				if(s.length < plen)
					s = s.pad(plen, 0, true);

				return s;
			}
		}
	}

};


F.LU =
{

	aOnLoad : [],
	aOnUnload : [],

	attachedEvents : false,

	attachEvents : function()
	{
		if(F.LU.attachedEvents) return;
		obj_registerEvent(window, 'load', F.LU.doOnLoad);
		obj_registerEvent(window, 'unload', F.LU.doOnUnload);
		F.LU.attachedEvents = true;
	},

	_add : function(a, f)
	{
		F.LU.attachEvents();
		if(typeof(f) != "function" && typeof(f) != "string")
			return;

		a[a.length] = f;
	},

	_addM : function(a, obj, method, aParams)
	{
		if(typeof(obj) != "object" || typeof(method) != "string" || !obj[method])
			return;

		var f = function(){
									if(aParams)
										obj[method].apply(obj, aParams);
									else
										obj[method]();
								};

		F.LU._add(a, f);
	},

	addOnLoad : function(f)
	{
		F.LU._add(F.LU.aOnLoad, f);
	},

	addOnLoadM : function(obj, method, aParams)
	{
		F.LU._addM(F.LU.aOnLoad, obj, method, aParams);
	},

	focusOnLoad : function(obj)
	{
		F.LU.addOnLoad(function(){obj_foc(obj);})
	},

	addOnUnload : function(f)
	{
		F.LU._add(F.LU.aOnUnload, f);
	},

	addOnUnloadM : function(obj, method, aParams)
	{
		F.LU._addM(F.LU.aOnUnload, obj, method, aParams);
	},

	_do : function(a)
	{
		for(var i = 0; i < a.length; i++)
		{
			if(typeof(a[i]) == 'function')
				a[i]();
			else
				eval(a[i]);
		}
	},

	doOnLoad : function()
	{
		F.LU._do(F.LU.aOnLoad);
	},

	doOnUnload : function()
	{
		F.LU._do(F.LU.aOnUnload);
	}

}

