
function dump_click(obj)
{
	if(!obj) return;
	obj.style.fontStyle = obj_cycleDisplay(obj.parentNode.cells[1]) ? "normal" : "italic";
}


function invoke(ot_id, o_id, method, language)
{
	url_ = CMSP_URL_CMS + "object.php?ot_id=" + ot_id + "&id=" + o_id + "&method=" + method;
	if(language)
		url_ += "&l=" + language;
	fullWindow(url_, "invoke_" + ot_id + "_" + o_id);
}

function invokeEx(ot_id, o_id, method, language, urlExtra)
{
	url_ = CMSP_URL_CMS + "object.php?ot_id=" + ot_id + "&id=" + o_id + "&method=" + method + "&l=" + language;
	url_ += urlExtra;
	fullWindow(url_, "invoke_" + ot_id + "_" + o_id);
}

function invokeWithSize(ot_id, o_id, method, language, x, y, w, h)
{
	window.open(CMSP_URL_CMS + "object.php?ot_id=" + ot_id + "&id=" + o_id + "&method=" + method + "&l=" + language,
					"invoke_" + ot_id + "_" + o_id,
					"top=" + y + ",left=" + x + ",width=" + w + ",height=" + h + ",status=no,toolbar=no,menubar=no,location=no,resizable=yes,fullscreen=no,scrollbars=yes");
}

function container_content(c_id, language)
{
	window.open(CMSP_URL_CMS + "container_content.php?&id=" + c_id + "&l=" + language,
					"container_content_" + c_id + '_' + language,
					"status=no,toolbar=no,menubar=no,location=no,directories=no,personalbar=no,resizable=yes,fullscreen=no,scrollbars=yes,width=995,height=680,top=10,left=10");
}


/******************************************************************************
	UI
******************************************************************************/
function cms_img(i, id)
{
	if(id)
		id = " id='" + id + "'";
	document.write("<img src='" + CMS_URL_IMAGES + i + "' border='0' alt=''" + id + ">");
}


var fbox_count = 0;
var FBOX_FIXED = 1;
var FBOX_FLOATABLE = 2;

function fbox_open(mode, t, params)
{
	if(!params) params = {};

	fbox_count++;
	if(!params.id || !params.id.length)
		params.id = "fbox_" + fbox_count;

	if(!mode)
		mode = FBOX_FIXED;

	if(!params.style)
		params.style = "";

	if(!params.c_style)
		params.c_style = "";

	var cls = "fbox", c_cls = "fbox_c";
	if(params.cls)
		cls += " " + params.cls;
	if(params.c_cls)
		c_cls += " " + params.c_cls;

	if(mode == FBOX_FIXED)
	{
		var h =	"<div class='" + cls + "' id='" + params.id + "' style='" + params.style + "'>"+
						"<div class='fbox_h' id='" + params.id + "_t'>" + t + "</div>" +
					"<div id='" + params.id + "_c' class='" + c_cls + "' style='" + params.c_style + "'>";
		document.write(h);
	}
	else
	{
		var h =	"<div class='" + cls + "' id='" + params.id + "' style='" + params.style + "; position: absolute;'>" +
						"<div class='fbox_h' id='" + params.id + "_t' style='cursor: move;'>" +
						"<a href='javascript: void EQX.$h(\"" + params.id + "\");' style='float: right;'><img src='" + CMS_URL_IMAGES + "ico_close.jpg' alt=''></a>" + t + "</div>" +
					"<div id='" + params.id + "_c' class='" + c_cls + "' style='overflow: auto;" + params.c_style + "'>";
		document.write(h);
		obj_registerEvent(params.id + '_t', 'mousedown', obj_dragStart);
	}
}

function fbox_open_dyn(mode, t, params)
{
	if(!params) params = {};

	fbox_count++;
	if(!params.id || !params.id.length)
		params.id = "fbox_" + fbox_count;

	if(!mode) mode = FBOX_FIXED;

	this.f = div_create(params.id, document.body);
	this.f.className = "fbox";
	if(mode == FBOX_FIXED)
	{
		var h =	"<div class='fbox_h' id='" + params.id + "_t'>" + t + "</div>" +
					"<div id='" + params.id + "_c' class='fbox_c' style='overflow: auto;'></div>";
		this.f.innerHTML = h;
	}
	else
	{
		this.f.style.position = 'absolute';
		var h =	"<div class='fbox_h' id='" + params.id + "_t' style='cursor: move;'>" +
					"<a href='javascript: void EQX.$h(\"" + params.id + "\");' style='float: right;'><img src='" + CMS_URL_IMAGES + "ico_close.jpg' alt=''></a>" + t + "</div>" +
					"<div id='" + params.id + "_c' class='fbox_c' style='overflow: auto;'></div>";
		this.f.innerHTML = h;

		obj_registerEvent(params.id + '_t', 'mousedown', obj_dragStart);
	}
	this.fc = EQX.$(params.id + '_c');

	return this;
}

function ffbox_open(t, id)
{
	fbox_open(t, id, FBOX_FLOATABLE);
}

function ffbox_open_dyn(t, id)
{
	return fbox_open_dyn(FBOX_FLOATABLE, t, {id: id});
}

function fbox_bottomBar()
{
	document.write("</div><div class='fbox_b'>");
}

function fbox_close()
{
	document.write("</div></div>");
}

function fbox_show(fbox)
{
	if(typeof(fbox) == "string")
		fbox = EQX.$(fbox);

	if(!getCookie(fbox.id + "_pos"))
		div_align(fbox, "center");

	EQX.$s(fbox, true);
}

function fbox_methodOverflow(fb_id)
{
	var fb = EQX.$(fb_id + "_c");
	var s = body_getSize();
	fb.style.display = "block";
	fb.style.position = "absolute";
	fb.style.width = (s.x - 3) + "px";
	fb.style.height = (s.y - 23 - 30 - 1) + "px";
	fb.style.overflowY = "auto";
}



/******************************************************************************
	tab
******************************************************************************/
var tab_count = 0;
var aAllTabs = new Array();
aAllTabs['a'] = 1;
tab = function(id, dynamic, parent)
{
	aAllTabs[id] = this;
	this.id = id;
	this.dynamic = dynamic || false;
	this.count = 0;
	this.deleted = 0;
	
	// store active tab's id
	this.selectedIndex;

	this.on_switch = "";
	this.on_switched = "";

	this.aTabs = new Array();

	// store active's tab id 
	this.activeTabId;

	if(this.dynamic)
	{
		this.parent = parent || document.body;

		this.t = t_create(this.id, this.parent);
		this.t.className = "tab";
		var c =	"<table class='tab_h' cellpadding='0' cellspacing='0'>" +
					"<tr id='tabh_" + this.id + "'><td></td></tr></table>";
		var td = tr_addTD(t_addTR(this.t, null), null, c);
	}
	else
	{
		document.write("<table cellpadding='0' cellspacing='0' class='tab' id='" + this.id + "'><tr><td>" +
							"<table class='tab_h' cellpadding='0' cellspacing='0'>" +
							"<tr id='tabh_" + this.id + "'><td></td></tr></table>" +
							"</td></tr>");
		this.t = EQX.$(this.id);
	}
	this.h = EQX.$("tabh_" + this.id);


	this.initSelIdx = function(no_cookie)
	{
		if(!this.aTabs[this.selectedIndex])
		{
			if(!no_cookie)
				this.selectedIndex = getCookie(id + "_sel");

			if(!this.aTabs[this.selectedIndex])
			{
				for(var i = 1; i <= this.aTabs.length; i++)
				{
					if(this.aTabs[i])
					{
						this.selectedIndex = i;
						break;
					}
				}
			}
		}
	};


	this.close = function()
	{
		if(!this.dynamic)
		{
			if(this.count > 0)
				document.write("</td></tr>");

			document.write("</table>");
		}

		this.initSelIdx();

		if(this.selectedIndex > 0)
			F.LU.addOnLoad("tab_switchTo('" + this.id + "', " + this.selectedIndex + ", false, true);");
	};


	//returns the index of the newly created tab
	this.add = function(label, content, selected, focus_obj)
	{
		var idx = ++this.count;
		this.aTabs[idx] = [];
		this.aTabs[idx].focus_obj = focus_obj;

		if(selected)
			this.selectedIndex = idx;

		var tr_id = this.id + "_" + idx;
		if(this.dynamic)
		{
			var tr = t_addTR(this.t, tr_id);
			var td = tr_addTD(tr, tr_id + "_", content);
			td.className = "tab_c";
			if(!selected)
				tr.style.display = "none";
			this.aTabs[idx].tr_c = tr;
		}
		else
		{
			if(idx > 1)
				document.write("</td></tr>");
			document.write("<tr id='" + tr_id + "'" + (selected ? "" : " style='display: none;'") + "><td class='tab_c' id='" + tr_id + "_" + "'>");
			this.aTabs[idx].tr_c = EQX.$(tr_id);
		}

		var co = '<a href="" onclick="tab_switchTo(\'' + this.id + "', " + idx + '); return false;">' + label + "</a>";
		var td = tr_addTD(this.h, null, co);
		this.aTabs[idx].a_h = td.childNodes[0];

		return idx;
	};


	this.getContent = function(index)
	{
		if(this.aTabs[index])
			return this.aTabs[index].tr_c;
		else
			return null;
	};


	this.getLabel = function(index)
	{
		if(this.aTabs[index])
			return this.aTabs[index].a_h;
		else
			return null;
	};


	this.setLabel = function(index, label)
	{
		if(this.aTabs[index])
			this.aTabs[index].a_h.innerHTML = label;
	};


	this.remove = function(index)
	{
		if(!this.aTabs[index])
			return;

		obj_del(this.aTabs[index].tr_c);
		obj_del(this.aTabs[index].a_h.parentNode);
		this.aTabs[index] = null;
		this.deleted++;

		if(this.deleted < this.count)
		{
			var i = index + 1, j = index - 1;
			while((i <= this.count) || (j > 0))
			{
				if(this.aTabs[i])
				{
					this.switchTo(i, false, true);
					break;
				}
				else if(this.aTabs[j])
				{
					this.switchTo(j, false, true);
					break;
				}

				i++; j--;
			}
		}
	};


	this.switchTo = function(index, no_cookie, force)
	{
		if(!this.aTabs[this.selectedIndex])
		{
			if(this.selectedIndex)
				this.initSelIdx();
			else
				this.initSelIdx(true);

			force = true;
		}

		if((index == this.selectedIndex)  && !force)
			return;

		if(this.on_switch && this.on_switch.length)
		{
			var tab = this;
			var cancel = eval(this.on_switch);
			if((typeof(cancel) == "boolean") && !cancel)
				return;
		}

		if(!this.aTabs[this.selectedIndex])
			return;

		this.aTabs[this.selectedIndex].a_h.className = '';
		this.aTabs[index].a_h.className = 'selected';
		EQX.$h(this.aTabs[this.selectedIndex].tr_c);
		EQX.$s(this.aTabs[index].tr_c);
		this.selectedIndex = index;
		if(!no_cookie)
			setCookie(this.id + "_sel", index);

		// move focus on the desired tab
		if(this.aTabs[index].focus_obj)
		{
			var focus_obj = EQX.$(this.aTabs[index].focus_obj);
			if(focus_obj && obj_isVisibleEx(focus_obj))
				obj_foc(focus_obj);
		}

		if(this.on_switched && this.on_switched.length)
		{
			var tab = this;
			eval(this.on_switched);
		}
	};
}

function tab_(tab_id)
{
	return aAllTabs[tab_id];
}

function tab_switchTo(tab_id, index, no_cookie, force)
{
	var tab = aAllTabs[tab_id];
	if(!tab)
		return;
	tab.switchTo(index, no_cookie, force);
}




//iframe objects
var ifo_tabs = new Object();
var ifo_tab;
var ifo_count = 0;
var ifo_new_count = 0;
var ifo_added_on = false;
function ifo_invoke(ot_id, o_id, label, method, url, param, tab_id)
{
	if(typeof(tab_id) == "undefined")
	{
		if(method.toLowerCase() == "create")
			o_id = ifo_new_count++;

		tab_id = ot_id + "_" + method + "_" + o_id;
	}

	if(label.indexOf("||") >= 0)
	{
		var p = label.indexOf("||"), s = str_trim(label.substring(0, p));
		label = (s.length ? s : label.substring(p + 2));
	}

	if(!label || !label.length)
		label = "Unknown" + (ifo_count + 1);

	var ifo_fb = EQX.$("fb_ifo");
	if(!ifo_fb)
	{
		var f = ffbox_open_dyn("Objects", "fb_ifo");

		f.f.style.display = "none";
		var bs = body_getSize();
		f.f.style.width = Math.max(Math.round((70 * bs.x / 100)), 830) + "px";
		f.fc.style.height = Math.max(Math.round((60 * bs.y / 100)), 500) + "px";
		f.f.style.borderColor = "#000000";
		ifo_tab = new tab("ifo_tab", true, f.fc);
		ifo_tab.t.style.height = "100%";

		ifo_fb = f.f;
	}

	if(!ifo_tabs[tab_id])
	{
		ifo_tabs[tab_id] = ifo_tab.add(label);
		var tab_c = tr_getCell(ifo_tab.getContent(ifo_tabs[tab_id]), 0);

		tab_c.style.height = '100%';
		tab_c.style.position = "relative";
		tab_c.innerHTML = "<iframe class='ifo' width='100%' height='100%' scrolling='no' frameborder='0' id='ifObject_" + tab_id + "' src='" + CMSP_URL_CMS + "empty.htm'></iframe>";
		var if_ = EQX.$("ifObject_" + tab_id);
		if(url)
		{
			if_go(if_, url);
		}
		else
		{
			var url = CMSP_URL_CMS + "object.php?ifo=1&ot_id=" + ot_id + "&id=" + o_id + "&method=" + method + "&rand=" + Math.random();
			if(param)
			{
				if(typeof(param) == "object")
					url += "&p=" + C.encodeMethodParams(param);
				else
					url += "&p=" + param;
			}
			if_go(if_, url);
		}
		ifo_count++;
	}
	tab_switchTo(ifo_tab.id, ifo_tabs[tab_id]);

	if(!obj_isVisible(ifo_fb))
		fbox_show(ifo_fb);

	if(!ifo_added_on)
	{
		ifo_added_on = true;
		window.onbeforeunload = function(evt){if(ifo_count > 0)return "There are still objects opened.\nAre you sure you want to continue?"};
	}
}

function ifo_invoker(ot_id, o_id, label, method, param, id)
{
	var url = "/cms/invoker.php?ifo=1&ot_id=" + ot_id + "&id=" + o_id + "&method=" + method + "&rand=" + Math.random();
	if(param)
		url += "&p=" + param;

	ifo_invoke(ot_id, o_id, label, method, url, null, id);
}

function ifo_close(ot_id, o_id, method)
{
	var id = ot_id + "_" + method + "_" + o_id;
	ifo_tab.remove(ifo_tabs[id]);
	ifo_tabs[id] = null;
	ifo_count--;
	if(!ifo_count)
		EQX.$h("fb_ifo");
}

function ifo_smartClose(ot_id, o_id, method)
{
	if(C.AjaxInvokerTab && C.AjaxInvokerTab.isIFrame())
		C.AjaxInvokerTab.getAjaxTab().rm();
	else if(parent.ifo_close && parent.ifo_tab)
		parent.ifo_close(ot_id, o_id, method);
	else
		window.close();
}

function ifo_close_custom(id)
{
	ifo_tab.remove(ifo_tabs[id]);
	ifo_tabs[id] = null;
	ifo_count--;
	if(!ifo_count)
		EQX.$h("fb_ifo");
}

function ifo_cb_new(ot_id, new_id, o_id, method)
{
	if(!method)
		method = "edit";

	var id = ot_id + "_" + method + "_" + o_id;
	var new_id = ot_id + "_create_" + new_id;
	ifo_tabs[id] = ifo_tabs[new_id];

	var f = EQX.$("ifObject_" + new_id);
	if(f)
		f.setAttribute("id", "ifObject_" + id);
}

function ifo_cb_change_method(ot_id, o_id, old_method, new_method)
{
	var old_id = ot_id + "_" + old_method + "_" + o_id;
	var new_id = ot_id + "_" + new_method + "_" + o_id;

	ifo_tabs[new_id] = ifo_tabs[old_id];
	ifo_tabs[old_id] = null;

	var f = EQX.$("ifObject_" + old_id);
	if(f)
		f.setAttribute("id", "ifObject_" + new_id);
}


function ifo_cb_change_object(ot_id, old_o_id, new_o_id, old_method, new_method, new_tab_label)
{
	if(!new_method)
		new_method = old_method;

	var old_id = ot_id + "_" + old_method + "_" + old_o_id;
	var new_id = ot_id + "_" + new_method + "_" + new_o_id;

	ifo_tabs[new_id] = ifo_tabs[old_id];
	ifo_tabs[old_id] = null;

	if(new_tab_label)
		ifo_tab.setLabel(ifo_tabs[new_id], new_tab_label);

	var f = EQX.$("ifObject_" + old_id);
	if(f)
		f.setAttribute("id", "ifObject_" + new_id);
}

function ifo_cb_setLabel(ot_id, o_id, method, new_tab_label)
{
	var tab_id = ot_id + "_" + method + "_" + o_id;
	if(new_tab_label)
		ifo_tab.setLabel(ifo_tabs[tab_id], new_tab_label);
}

function ifo_eval(ot_id, o_id, method, js, tab_id)
{
	if(!tab_id)
		tab_id = ot_id + "_" + method + "_" + o_id;

	var ifw = if_win("ifObject_" + tab_id);
	if(!ifw || !ifw.eval) return;
	try{ifw.eval(js);}catch(e){}
//	alert(js);ifw.eval(js);
}




//paged query
function pq_changeRPP(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	var obj = EQX.F.Event.getSender(evt);
	var frm = obj.form;
	frm.page.value = 1;
	frm.submit();
}

function pq_orderBy(pq, order_by, order_asc)
{
	var frm = EQX.$("pq_fr_" + pq).form;
	frm.order_by.value = order_by;
	frm.order_asc.value = order_asc;
	frm.submit();
}

function pq_goto(frm_name, page)
{
	var frm = document[frm_name];
	frm.page.value = page;
	frm.submit();
}

function pq_changeFB(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	var obj = EQX.F.Event.getSender(evt);
	var frm = obj.form;
}

function pq_filter(frm_name)
{
	var frm = document[frm_name];
	frm.page.value = 1;
	frm.submit();
}

function pq_filterDown(evt)
{
	evt = (evt ? evt : (window.event ? event : null));
	if(evt.keyCode == 13)
	{
		var obj = EQX.F.Event.getSender(evt);
		var frm = obj.form;
		pq_filter(frm.name);
	}
}

function pq_check(evt, pq)
{
	evt = (evt ? evt : (window.event ? event : null));
	var chk = EQX.F.Event.getSender(evt);
	if(!chk) return;

	var chkAll = EQX.$("chkPqSel" + pq);
	if(chk.checked)
	{
		if(!pq_checkedCount(pq, true))
			chkAll.checked = true;
	}
	else
	{
		if(chkAll && chkAll.checked)
			chkAll.checked = false;
	}
}

function pq_checkAll(evt, pq)
{
	evt = (evt ? evt : (window.event ? event : null));
	var chk = EQX.F.Event.getSender(evt);
	if(!chk) return;

	var chk_name = EQX.$value("pq_chk_" + pq);

	var a = objs_get("INPUT", chk_name);
	for(var i = 0; i < a.length; i++)
	{
		if((a[i].name == chk_name) && !a[i].disabled)
		{
			a[i].checked = chk.checked;
		}
	}
}


function pq_checkedCount(pq, count_unchecked)
{
	var chk_name = EQX.$value("pq_chk_" + pq);
	var a = objs_get("INPUT", chk_name), c = 0;
	for(var i = 0; i < a.length; i++)
	{
		if((a[i].name == chk_name) && !a[i].disabled && ((count_unchecked && !a[i].checked) || (!count_unchecked && a[i].checked)))
			c++;
	}

	return c;
}



//dynamic page query

var oAllPQD = new Array();
cms_pqd = function(pq_name, row_count, row_from, row_to, rpp, page_no, pages_count, hide_rownum)
{
	if(oAllPQD[pq_name])
		return oAllPQD[pq_name];

	this.id = pq_name;
	this.row_count = row_count;
	this.row_from = row_from;
	this.row_to = row_to;
	this.rpp = rpp;
	this.page_no = page_no;
	this.pages_count = pages_count;
	this.loaded = true;
	this.hide_rownum = hide_rownum;

	oAllPQD[pq_name] = this;
	if(!window["CmsPQDStatic"])
		window["CmsPQDStatic"] = this;

	this.changeRPP = function(evt)
	{
		evt = (evt ? evt : (window.event ? event : null));
		var obj = EQX.F.Event.getSender(evt);
		this.rpp = obj[obj.selectedIndex].text;

		this.act("rpp", {rpp: obj.value});
	};

	this.act = function(act, oParams)
	{
		var p = "a=pqd&id=" + this.id + "&pqd_a=" + act;
		if(typeof(oParams) == "object")
		{
			oParams.$foreach(function(pName, pVal)
				{
					p += "&" + pName + "=" + pVal;
				});
		}

		this.loaded = false;
//		XReq.request(XReq.JS_REQ, CMSP_URL_CMS + "xhandler.php?" + p);
		EQX.F.AjaxRequest.request(EQX.F.AjaxRequest.fcbJS, CMSP_URL_CMS + "xhandler.php?" + p);
	};

	this.first = function()
	{
		this.act("first");
	};

	this.prev = function()
	{
		this.act("prev");
	};

	this.next = function()
	{
		this.act("next");
	};

	this.last = function()
	{
		this.act("last");
	};

	this.refresh = function()
	{
		this.act("refresh");
	};

	this.go_to = function(page_no)
	{
		this.act("goto", {page: page_no});
	};

	this.go_to_row = function(row_num)
	{
		var page = Math.ceil(row_num / this.rpp);
		this.go_to(page);
	};

	this.order_by = function(by, asc)
	{
		this.act("ord", {by: by, asc: asc});
	};

	this.filter = function()
	{
		var c = EQX.$("cmbFB" + this.id), e = EQX.$("edtFV" + this.id), m;
		if(c.value < 0) return;

		var fc = window['pqfc_' + this.id], fcc = 1;
		var p = {by0: c.value, val0: e.value};
		if(fc)
		{
			for(var i = 1; i <= fc; i++)
			{
				c = EQX.$("cmbFB" + i + this.id); e = EQX.$("edtFV" + i + this.id); m = EQX.$("cmbFM" + i + this.id);
				if((c.value > -1) && e.value.length)
				{
					p["by" + fcc] = c.value;
					p["val" + fcc] = e.value;
					p["m" + fcc] = m.value;
					fcc++;
				}
			}
		}

		p["c"] = fcc;
		this.act("filter", p);
	};

	this.addCriteria = function()
	{
		if(!window['pqfc_' + this.id])
			window['pqfc_' + this.id] = 1;
		else
			window['pqfc_' + this.id]++;
		var fc = window['pqfc_' + this.id];

		var t = EQX.$("tPQF" + this.id);
		if(!t) return;

		var cmb = EQX.$("cmbFB" + this.id);
		var c = '<select name="cmbFB' + fc + this.id + '" id="cmbFB' + fc + this.id + '">';
		for(var i = 0; i < cmb.options.length; i++)
			c += '<option value="' + cmb.options[i].value + '">' + cmb.options[i].text;
		c += '</select>';
		var e = '<input type="text" class="w_100" id="edtFV' + fc + this.id + '" name="edtFV' + fc + this.id + '" value="">';
		var tr = t_addTR(t, "tPQF" + this.id + t.rows.length);
		var cm = '<select class="w_50" name="cmbFM' + fc + this.id + '" id="cmbFM' + fc + this.id + '"><option value="0">AND<option value="1">OR<option value="2">NOT</select>';
		tr_addTD(tr, null, cm).align = 'right';
		tr_addTD(tr, null, c + e);
	};


	this.removeCriteria = function()
	{
		var t = EQX.$("tPQF" + this.id);
		if(!t || !window['pqfc_' + this.id]) return;
		t.deleteRow(t.rows.length-1);
		window['pqfc_' + this.id]--;
	};


	this.xCallback = function(page, num_pages, p_from, p_to, r_count, r_from, r_to)
	{
		this.row_count = r_count;
		this.row_from = r_from;
		this.row_to = r_to;
		this.page_no = page;
		this.pages_count = num_pages;

		if(num_pages < 2)
		{
			EQX.$h("pq_pos_" + this.id);
			EQX.$h("pq_ctrl_" + this.id);
		}
		else
		{
			EQX.$s("pq_pos_" + this.id);
			EQX.$s("pq_ctrl_" + this.id);

			obj_setContent("pq_r_from_" + this.id, r_from);
			obj_setContent("pq_r_to_" + this.id, r_to);
			obj_setContent("pq_r_count_" + this.id, r_count);

			obj_setEnabled("pq_next_" + this.id, (page < num_pages));
			obj_setEnabled("pq_prev_" + this.id, (page > 1));
			obj_setEnabled("pq_first_" + this.id, (page > 1));
			obj_setEnabled("pq_last_" + this.id, (page < num_pages));

			var pager_count = p_to - p_from + 1;
			var t_pager = EQX.$("pqd_p_t_" + this.id), page_no;

			var p_btn_;
			for(var i = t_pager.rows[0].cells.length; i <= pager_count; i++)
			{
				p_btn_ = "<button id='" + "pqd_p_btn_" + this.id + i + "' class='minibtn' onclick='PQD_" + this.id + ".go_to(this.innerHTML);'>" + (p_from + i) + "</button>";
				tr_addTD(t_pager.rows[0], null, p_btn_).style.display = "none";
			}

			for(var i = 1; i < t_pager.rows[0].cells.length; i++)
			{
				if(i > pager_count)
				{
					EQX.$h(t_pager.rows[0].cells[i]);
					continue;
				}

				EQX.$s(t_pager.rows[0].cells[i]);
				page_no = p_from + i - 1;
				with(t_pager.rows[0].cells[i].childNodes[0])
				{
					innerHTML = page_no;
					title = "Go to page " + page_no;
					if(page_no == page)
					{
						className = "minibtn minibtns";
						focus();
					}
					else
					{
						className = "minibtn";
					}
				}
			}
		}

		this.loaded = true;
	};


	this.getChkByTR = function(tr)
	{
		return tr.cells[(this.hide_rownum ? 0 : 1)].childNodes[0];
	};


	this.getChkValue = function(row)
	{
		if(((row > this.row_to) && (this.page_no < this.pages_count)) || ((row < this.row_from) && (row > 0)))
		{
			this.go_to_row(row);
			return "xreq";
		}

		var t = EQX.$("tPQ" + this.id);
		var trow = row - this.row_from + 1;
		if(!t.rows[trow])
			return null;

		return this.getChkByTR(t.rows[trow]).value;
	};


	this.getTableRowByRowNum = function(row)
	{
		var t = EQX.$("tPQ" + this.id);

		var trow = row - this.row_from + 1;
		if(!t.rows[trow])
			return null;

		return t.rows[trow];
	};


	this.getRowNumByChkValue = function(chk_value)
	{
		var t = EQX.$("tPQ" + this.id);
		for(var i = t.rows.length - 1; i > 0; i--)
		{
			if(this.getChkByTR(t.rows[i]).value == chk_value)
				return this.row_from + i - 1;
		}

		return 0;
	};


	this.getTableRowByChkValue = function(chk_value)
	{
		var t = EQX.$("tPQ" + this.id);
		for(var i = t.rows.length - 1; i > 0; i--)
		{
			if(this.getChkByTR(t.rows[i]).value == chk_value)
				return t.rows[i];
		}

		return null;
	};


	this.getTable = function()
	{
		return EQX.$("tPQ" + this.id);
	};


	this.getTableRowCount = function()
	{
		var t = EQX.$("tPQ" + this.id);
		return t.rows.length;
	};
}




//TREE
var oAllTrees = new Array();
cms_tree = function(id, dynamic, parent)
{
	if(oAllTrees[id])
		return oAllTrees[id];

	this.id = id;
	this.dynamic = dynamic || false;
	this.col_count = 0;
	this.n_count = 0;
	this.aNodes = [];
	this.indent = 19;
	this.aColumns = [];

	this.on_expand = "";
	this.on_collapse = "";

	this.ico_d = CMS_URL_IMAGES + "tree/org.gif";
	this.ico_do= CMS_URL_IMAGES + "tree/org_open.gif";
	this.ico_n = CMS_URL_IMAGES + "tree/person.gif";

	oAllTrees[id] = this;

	if(this.dynamic)
	{
		this.parent = parent || document.body;

		this.t = t_create(this.id, this.parent);
		this.t.className = "tree";
		this.h = t_addTR(this.t);
		var td = tr_addTD(this.h, null, "Name");
		td.style.width = "99%";
		td.noWrap = true;
	}
	else
	{
		document.write("<table cellpadding='0' cellspacing='0' class='tree' id='" + this.id + "'><tbody>" +
							"<tr class='tree_h'><td nowrap='nowrap'>Name</td></tr></tbody></table>");
		this.t = EQX.$(this.id);
		this.h = this.t.rows[0];
	}


	//returns the index of the newly added column
	this.addColumn = function(label, width, align, content_align)
	{
		this.col_count++;
		this.aColumns[this.col_count] = [width, content_align];

		var td = tr_addTD(this.h, 'treec_' + this.id + '_' + this.col_count, label);
		td.className = "col";
		if(align) td.align = align;
		if(width) td.width = width;

		return this.col_count;
	};


	this.node_ico = function(node, ico)
	{
		node.cells[0].childNodes[0].childNodes[0].src = ico;
	};


	this.add = function(id, name, aCol, parent_id, is_dir, force_visible, exp_dyn)
	{
		if(this.aNodes["n_" + id])
			return;

		if(parent_id && !this.aNodes["n_" + parent_id])
			parent_id = null;

		this.n_count++;
		this.aNodes["n_" + id] = this.n_count;

		var tr_idx, parent_n;
		if(parent_id)
		{
			parent_n = this.aNodes[this.aNodes["n_" + parent_id]];
			if(!parent_n.c_count)
			{
				this.node_ico(parent_n, this.ico_d);
				parent_n.is_dir = true;
			}

			parent_n.c_count++;
			if(parent_n.last_c)
			{
				var last_c = parent_n.last_c;
				while(last_c.last_c)
					last_c = last_c.last_c;

				tr_idx = last_c.rowIndex + 1;
			}
			else
				tr_idx = parent_n.rowIndex + 1;
		}

		var node = t_addTR(this.t, "treen_" + this.id + "_" + id, tr_idx);
		if(parent_n)
		{
			if(!force_visible)
				EQX.$h(node);
			parent_n.last_c = node;
			parent_n.aChildren[parent_n.c_count-1] = node;
			node.level = parent_n.level + 1;
		}
		else
			node.level = 1;

		var n_ico = is_dir ? this.ico_d : this.ico_n;

		var td = tr_addTD(node, null, '<a class="simple" href="javascript: void cms_tree_nc(\'' + this.id + '\', \'' + id + '\');">' +
												'<img src="' + n_ico + '" alt="">' + name  + '</a>');

		td.style.paddingLeft = ((node.level - 1) * this.indent) + "px";
		node.aChildren = new Array();
		node.c_count = 0;
		node.expanded = false;
		node.is_dir = is_dir;
		node.n_id = id;
		node.parent_n = parent_n;
		node.exp_dyn = exp_dyn;
		this.aNodes[this.n_count] = node;

		if(this.col_count > 0)
		{
			var i = 1, td;
			if(aCol && aCol.length)
			{
				for(var j = 0; j < Math.min(this.col_count, aCol.length); j++)
				{
					td = tr_addTD(node, null, aCol[j]);
					td.className = "col";
					if(this.aColumns[j+1][0]) td.width = this.aColumns[j+1][0];
					if(this.aColumns[j+1][1]) td.align = this.aColumns[j+1][1];
				}
				i += j;
			}

			for(; i <= this.col_count; i++)
				tr_addTD(node, null, "&nbsp;");
		}

		return node;
	};

	this.dyn_loaded = function(n_id)
	{
		var n = this.get(n_id);
		n.exp_dyn = false;
		n.expanded = true;
		this.node_ico(n, this.ico_do);
	};

	this.get = function(id)
	{
		if(this.aNodes["n_" + id])
			return this.aNodes[this.aNodes["n_" + id]];
		else if(this.aNodes[id])
			return this.aNodes[id];

		return null;
	};

	this.getById = function(id)
	{
		if(this.aNodes["n_" + id])
			return this.aNodes[this.aNodes["n_" + id]];

		return null;
	};

	this.node_click = function(n_id)
	{
		var node = this.aNodes[this.aNodes["n_" + n_id]];

		var f = node.expanded ? "on_collapse" : "on_expand";
		if(this[f] && this[f].length)
		{
			var tree = this;
			var cancel = eval(this[f]);
			if((typeof(cancel) == "boolean") && !cancel)
				return;
		}

		if(node.expanded)
			this.collapse(node, true);
		else
			this.expand(node);
	};

	this.expand = function(node, deep)
	{
		if(!node.is_dir) return;

		if(!node.exp_dyn)
			this.node_ico(node, this.ico_do);

		for(var i = 0; i < node.c_count; i++)
		{
			EQX.$s(node.aChildren[i]);
			if(deep)
				this.expand(node.aChildren[i], true);
		}

		node.expanded = true;
	};

	this.collapse = function(node, deep)
	{
		if(!node.is_dir) return;

		this.node_ico(node, this.ico_d);

		if(node.c_count)
		{
			for(var i = 0; i < node.c_count; i++)
			{
				if(deep)
					this.collapse(node.aChildren[i], true);
				EQX.$h(node.aChildren[i]);
			}
		}

		node.expanded = false;
	};

	this.expand_all = function()
	{
		for(i = 1; i <= this.n_count; i++)
			this.expand(this.aNodes[i], true);
	};
}

function cms_tree_(tree_id)
{
	return oAllTrees[tree_id];
}

function cms_tree_nc(t_id, n_id)
{
	var tree = oAllTrees[t_id];
	if(!tree || !tree.aNodes["n_" + n_id])
		return false;

	tree.node_click(n_id);
}

var input_img_;
function input_img(evt, icond, ictrl)
{
	var obj = EQX.F.Event.getSender(evt);

	if(!obj || !obj_isVisibleEx(obj)) return;

	if(!input_img_)
	{
		input_img_ = obj_create("DIV", document.body);
		input_img_.innerHTML = '<img alt="" title="This indicates that you may press enter in order to jump to the next field" src="' + CMS_URL_IMAGES + 'return.gif" border="0" />';
		input_img_.style.position = "absolute";
		input_img_.style.zIndex = 1000;
		EQX.$h(input_img_);
	}

	switch(evt.type)
	{
		case "focus":
		{
			if(icond)
			{
				var co = EQX.$(icond);
				if(co && obj_isVisibleEx(co))
					return;
			}

			var p, d, p2;
			if(ictrl)
			{
				ictrl = EQX.$(ictrl);
				if(!ictrl)
					return;

				p = obj_getAbsPos(ictrl);
				d = obj_getSize(ictrl);
				p2 = obj_getAbsPos(obj);
				p.y = p2.y;
			}
			else
			{
				p = obj_getAbsPos(obj);
				d = obj_getSize(obj);
			}

			input_img_.style.left = (p.x + d.x + 7) + "px";
			input_img_.style.top = (p.y + 4) + "px";
			input_img_.style.display = "block";

			break;
		}

		case "blur":
		{
			input_img_.style.display = "none";

			break;
		}
	}
}


//XReq
if(typeof(XReqHandler) != "undefined")
{
	XReqHandler.prototype.registerSetContainerPosContent = function(_div, js)
	{
		this.actions[_div] = "obj_setContent('" + _div + "', text); " + js;
	}

	XReqHandler.prototype.requestCPosContent = function(_div, ot_id, o_id, method, lang, params)
	{
		if(params && params.charAt(0) != "&")
			params = "&" + params;

		qp = '_r=' + Math.random() + '&a=render&ot_id=' + ot_id + '&o_id=' + o_id + '&method=' + method + '&_div=' + _div + '&_url=' + PAGE_URL + '&_pid=' + PAGE_ID + params;
		if(lang)
			qp += '&l=' + lang;

		XReq.request(_div, '/cms/xhandler.php?' + qp);
	}
}


var C =
{
	encodeMethodParams : function(oP)
	{
		if(typeof(oP) != "object")
			return "";

		var p_ = "";
		for(var p in oP)
		{
			if(['object', 'function', 'undefined'].contains(typeof(oP[p])))
				continue;

			p_ += p + "::" + oP[p] + "||";
		}

		return p_;
	},

	invokeAJAXMethod : function(ot_id, id, method, language, oParams, oOptions)
	{
		C.invokeAJAXMethodEx(EQX.F.AjaxRequest.fcbJS, ot_id, id, method, language, oParams, oOptions);
	},

	invokeAJAXUrl : function(ot_id, id, method, language)
	{
		var url = "/cms/invoker_ajax.php?ot_id=" + ot_id + "&id=" + id + "&method=" + method;
		if(language)
			url += "&language=" + language;
		return url;
	},

	invokeAJAXMethodEx : function(cbFunction, ot_id, id, method, language, oParams, oOptions)
	{
		var o = {
			url: C.invokeAJAXUrl(ot_id, id, method, language),
			success:cbFunction,
			failure: oOptions.failure || function(response) {
				alert('Error code: ' + response.status + '\r\nError message: ' + response.statusMsg);
			},
			method: 'post'
		};
		if(typeof(oOptions) == 'object')
		{
			for(var p in oOptions)
				o[p] = oOptions[p];
		}
		if(typeof(oParams) === 'object')
			o.params = {p: C.encodeMethodParams(oParams)};
		return Ext.Ajax.request(o);
	}

}


var O2O =
{
	oInit : {},

	generateName : function(otid_parent, oid_parent, otid_child, assigned, reversedAssignments)
	{
		return "o2o" + (assigned ? "asgn" : "add") + "_" + (reversedAssignments ? "t"+otid_child+"_t"+otid_parent+"_"+oid_parent : "t"+otid_parent+"_"+oid_parent+"_t"+otid_child);
	},

	act : function(act, oParams)
	{
		var p = "a=o2o&o2o_a=" + act;
		if(typeof(oParams) == "object")
		{
			for(var param in oParams)
				p += "&" + param + "=" + oParams[param];
		}

//		XReq.request(XReq.JS_REQ, CMSP_URL_CMS + "xhandler.php?" + p);
		EQX.F.AjaxRequest.request(EQX.F.AjaxRequest.fcbJS, CMSP_URL_CMS + "xhandler.php?" + p);
	},

	add : function(otid_parent, oid_parent, otid_child, reversedAssignments)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, false, reversedAssignments);
		if(!O2O.oInit[name])
		{
			eval("PQD_" + name).filter();
			O2O.oInit[name] = true;
		}

		fbox_show("fb" + name);
		obj_foc("edtFV" + name);
	},

	addDo : function(otid_parent, oid_parent, otid_child, reversedAssignments)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, false, reversedAssignments);
		if(pq_checkedCount(name) > 0)
		{
			var a = chk_getSelectedValues(null, "chk_" + name + "[]");
			var oParams = {otid_parent: otid_parent, oid_parent: oid_parent, otid_child: otid_child, reversedAssignments: (reversedAssignments ? 1 : 0), oid_child: a.toString()};
			O2O.oInit[name] = false;
			O2O.act("add", oParams);
		}
	},

	hideAdd : function(otid_parent, oid_parent, otid_child, reversedAssignments)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, false, reversedAssignments);
		EQX.$h('fb' + name);
	},

	refreshAssigned : function(otid_parent, oid_parent, otid_child, reversedAssignments)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, true, reversedAssignments);
		eval("PQD_" + name).refresh();
	},

	refreshAvailable : function(otid_parent, oid_parent, otid_child, reversedAssignments)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, false, reversedAssignments);
		eval("PQD_" + name).refresh();
	},

	rmSel : function(otid_parent, oid_parent, otid_child, reversedAssignments)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, true, reversedAssignments);
		if(pq_checkedCount(name) > 0)
		{
			var a = chk_getSelectedValues(null, "chk_" + name + "[]");
			var oParams = {otid_parent: otid_parent, oid_parent: oid_parent, otid_child: otid_child, reversedAssignments: (reversedAssignments ? 1 : 0), oid_child: a.toString()};
			O2O.oInit[O2O.generateName(otid_parent, oid_parent, otid_child, false, reversedAssignments)] = false;
			O2O.act("remove", oParams);
		}
	},

	rm : function(otid_parent, oid_parent, otid_child, reversedAssignments, child_id)
	{
		var name = O2O.generateName(otid_parent, oid_parent, otid_child, true, reversedAssignments);
		var oParams = {otid_parent: otid_parent, oid_parent: oid_parent, otid_child: otid_child, reversedAssignments: (reversedAssignments ? 1 : 0), oid_child: child_id};
		O2O.oInit[O2O.generateName(otid_parent, oid_parent, otid_child, false, reversedAssignments)] = false;
		O2O.act("remove", oParams);
	},


	addCreate : function(otid_parent, oid_parent, otid_child, reversedAssignments, parent_method, title)
	{
		var p = C.encodeMethodParams({act2: 'o2oadd', otid_parent: otid_parent, oid_parent: oid_parent, parent_method: parent_method, reversedAssignments: reversedAssignments});
		parent.intra_ifo_invoke(otid_child, 0, title, 'create', p);
	}

}

if(typeof(EQX) != "undefined")
{
	EQX.registerNamespace('C');

	EQX.C.$extend(
	{
		help : function(hid, h_otid, tab_label)
		{
			var atc;
			if(C.AjaxInvokerTab.isIFrame() && (atc = C.AjaxInvokerTab.getAjaxTabControl()))
			{
				atc.invoke(tab_label, h_otid, 1, null, 'help', {hid: hid});
			}
			else
			{
				var w = parent.ifo_invoker ? parent : window;
				w.ifo_invoker(h_otid, 1, tab_label, 'help', C.encodeMethodParams({hid: hid}));
			}
		},

		invokerUrlParams : function(ot_id, o_id, language, method, oParams)
		{
			var url = "ot_id=" + ot_id + "&id=" + o_id + "&method=" + method + "&rand=" + Math.random();

			if(language)
				url += "&l=" + language;

			if(typeof(oParams) == 'object')
				url += "&p=" + C.encodeMethodParams(oParams);

			return url;
		},

		goMethodEx : function(phpInvokerPath, ot_id, o_id, language, method, oParams)
		{
			var url = phpInvokerPath + "?" + EQX.C.invokerUrlParams(ot_id, o_id, language, method, oParams);
			EQX.F.go(url);
		},

		goMethod : function(ot_id, o_id, language, method, oParams)
		{
			EQX.C.goMethodEx('/cms/object.php', ot_id, o_id, language, method, oParams);
		},

		setAjaxTabLabel : function(win, label)
		{
			if(!C || !C.AjaxInvokerTab) return;

			var tab = C.AjaxInvokerTab.getAjaxTab(win);
			if(tab)
				tab.setLabel(label);
		}

	});
}