var jsUtils = { addEvent: function(el, evname, func)
{ if(el.attachEvent)
el.attachEvent("on" + evname, func); else if(el.addEventListener)
el.addEventListener(evname, func, false); else
el["on" + evname] = func;}, removeEvent: function(el, evname, func)
{ if(el.detachEvent)
el.detachEvent("on" + evname, func); else if(el.removeEventListener)
el.removeEventListener(evname, func, false); else
el["on" + evname] = null;}, GetRealPos: function(el)
{ if(!el || !el.offsetParent)
return false; var res=Array(); res["left"] = el.offsetLeft; res["top"] = el.offsetTop; var objParent = el.offsetParent; while(objParent.tagName != "BODY")
{ res["left"] += objParent.offsetLeft; res["top"] += objParent.offsetTop; objParent = objParent.offsetParent;}
res["right"]=res["left"] + el.offsetWidth; res["bottom"]=res["top"] + el.offsetHeight; return res;}, FindChildObject: function(obj, tag_name, class_name)
{ if(!obj)
return null; var tag = tag_name.toUpperCase(); var cl = (class_name? class_name.toLowerCase() : null); var n = obj.childNodes.length; for(var j=0; j<n; j++)
{ var child = obj.childNodes[j]; if(child.tagName && child.tagName.toUpperCase() == tag)
if(!class_name || child.className.toLowerCase() == cl)
return child;}
return null;}, FindNextSibling: function(obj, tag_name)
{ var o = obj; var tag = tag_name.toUpperCase(); while(o.nextSibling)
{ var sibling = o.nextSibling; if(sibling.tagName && sibling.tagName.toUpperCase() == tag)
return sibling; o = sibling;}
return null;}, FindPreviousSibling: function(obj, tag_name)
{ var o = obj; var tag = tag_name.toUpperCase(); while(o.previousSibling)
{ var sibling = o.previousSibling; if(sibling.tagName && sibling.tagName.toUpperCase() == tag)
return sibling; o = sibling;}
return null;}, FindParentObject: function(obj, tag_name)
{ var o = obj; var tag = tag_name.toUpperCase(); while(o.parentNode)
{ var parent = o.parentNode; if(parent.tagName && parent.tagName.toUpperCase() == tag)
return parent; o = parent;}
return null;}, IsIE: function()
{ return (document.attachEvent && !this.IsOpera());}, IsOpera: function()
{ return (navigator.userAgent.toLowerCase().indexOf('opera') != -1);}, ToggleDiv: function(div)
{ var style = document.getElementById(div).style; if(style.display!="none")
style.display = "none"; else
style.display = "block"; return (style.display != "none");}, urlencode: function(s)
{ return escape(s).replace(new RegExp('\\+','g'), '%2B');}, OpenWindow: function(url, width, height)
{ var w = screen.width, h = screen.height; if(this.IsOpera())
{ w = document.body.offsetWidth; h = document.body.offsetHeight;}
window.open(url, '', 'status=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',top='+Math.floor((h - height)/2-14)+',left='+Math.floor((w - width)/2-5));}, SetPageTitle: function(s)
{ document.title = phpVars.titlePrefix+s; var h1 = document.getElementsByTagName("H1"); if(h1)
h1[0].innerHTML = s;}, LoadPageToDiv: function(url, div_id)
{ var div = document.getElementById(div_id); if(!div)
return; CHttpRequest.Action = function(result)
{ CloseWaitWindow(); div.innerHTML = result;}
ShowWaitWindow(); CHttpRequest.Send(url);}, trim: function(s)
{ var r, re; re = /^[ \r\n]+/g; r = s.replace(re, ""); re = /[ \r\n]+$/g; r = r.replace(re, ""); return r;}
}
function JCAdminList(table_id)
{ var _this = this; this.table_id = table_id; this.InitTable = function()
{ var tbl = document.getElementById(this.table_id); if(!tbl || tbl.rows.length<1 || tbl.rows[0].cells.length<1)
return; var i; var nCols = tbl.rows[0].cells.length; var sortedIndex = -1; for(i=0; i<nCols; i++)
{ var j; var cell_sort = tbl.rows[1].cells[i]; var sort_table = jsUtils.FindChildObject(cell_sort, "table", "sorting"); for(j=0; j<2; j++)
{ var cell = tbl.rows[j].cells[i]; cell.onmouseover = function(){_this.HighlightGutter(this, true)}; cell.onmouseout = function(){_this.HighlightGutter(this, false)}; if(sort_table)
{ cell.onclick = sort_table.onclick; cell.title = sort_table.title; cell.style.cursor = "pointer"; if(j == 0)
{ var cl = sort_table.rows[0].cells[1].className.toLowerCase(); if(cl == "sign up" || cl == "sign down")
{ cell.className += ' sorted'; sortedIndex = i;}
}
}
}
if(sort_table)
sort_table.onclick = null;}
var n = tbl.rows.length; for(i=0; i<n; i++)
{ var row = tbl.rows[i]; row.cells[0].className += ' left'; row.cells[row.cells.length-1].className += ' right'; if(row.className && row.className == 'footer')
continue; if(sortedIndex != -1 && sortedIndex < row.cells.length)
row.cells[sortedIndex].className += ' sorted'; if(i>=2)
{ var checkbox = row.cells[0].childNodes[0]; if(checkbox && checkbox.tagName && checkbox.tagName.toUpperCase() == "INPUT" && checkbox.type.toUpperCase() == "CHECKBOX")
{ checkbox.onclick = function(){_this.SelectRow(this); _this.EnableActions()}; jsUtils.addEvent(row, "click", _this.OnClickRow);}
row.onmouseover = function(){_this.HighlightRow(this, true)}; row.onmouseout = function(){_this.HighlightRow(this, false)}; if(i%2 == 0)
row.className += ' odd'; else
row.className += ' even'; if(row.oncontextmenu)
{ jsUtils.addEvent(row, "contextmenu", function(e)
{ if(!e) e = window.event; if(e.ctrlKey) return; var targetElement; if(e.target) targetElement = e.target; else if(e.srcElement) targetElement = e.srcElement; while(targetElement && !targetElement.oncontextmenu)
targetElement = jsUtils.FindParentObject(targetElement, "tr"); var x = e.clientX + document.body.scrollLeft; var y = e.clientY + document.body.scrollTop; var pos = []; pos['left'] = pos['right'] = x; pos['top'] = pos['bottom'] = y; var menu = window[_this.table_id+"_menu"]; menu.PopupHide(); menu.BuildItems(targetElement.oncontextmenu()); setTimeout(function(){menu.PopupShow(pos)}, 10); e.returnValue = false; if(e.stopPropagation) e.stopPropagation();} );}
}
}
if(tbl.rows.length > 2)
{ tbl.rows[2].className += ' top'; tbl.rows[tbl.rows.length-1].className += ' bottom';}
}
this.HighlightGutter = function(cell, on)
{ var table = cell.parentNode.parentNode.parentNode; var gutter = table.rows[0].cells[cell.cellIndex]; if(on)
gutter.className += ' over'; else
gutter.className = gutter.className.replace(/\s*over/i, '');}
this.HighlightRow = function(row, on)
{ if(on)
row.className += ' over'; else
row.className = row.className.replace(/\s*over/i, '');}
this.SelectRow = function(checkbox)
{ var row = checkbox.parentNode.parentNode; var tbl = row.parentNode.parentNode; var span = document.getElementById(tbl.id+'_selected_span'); var selCount = parseInt(span.innerHTML); if(checkbox.checked)
{ row.className += ' selected'; selCount++;}
else
{ row.className = row.className.replace(/\s*selected/ig, ''); selCount--;}
span.innerHTML = selCount; var checkAll = document.getElementById(tbl.id+'_check_all'); if(selCount == tbl.rows.length-2)
checkAll.checked = true; else
checkAll.checked = false;}
this.OnClickRow = function(e)
{ if(!e)
var e = window.event; if(!e.ctrlKey)
return; var obj = (e.target? e.target : (e.srcElement? e.srcElement : null)); if(!obj)
return; if(!obj.parentNode.cells)
return; var checkbox = obj.parentNode.cells[0].childNodes[0]; if(checkbox && checkbox.tagName && checkbox.tagName.toUpperCase() == "INPUT" && checkbox.type.toUpperCase() == "CHECKBOX" && !checkbox.disabled)
{ checkbox.checked = !checkbox.checked; _this.SelectRow(checkbox);}
_this.EnableActions();}
this.SelectAllRows = function(checkbox)
{ var tbl = checkbox.parentNode.parentNode.parentNode.parentNode; var bChecked = checkbox.checked; var i; var n = tbl.rows.length; for(i=2; i<n; i++)
{ var box = tbl.rows[i].cells[0].childNodes[0]; if(box && box.tagName.toUpperCase() == 'INPUT' && box.type.toUpperCase() == "CHECKBOX")
{ if(box.checked != bChecked && !box.disabled)
{ box.checked = bChecked; this.SelectRow(box);}
}
}
this.EnableActions();}
this.EnableActions = function()
{ var form = document.forms['form_'+this.table_id]; if(!form) return; var bEnabled = this.IsActionEnabled(); var bEnabledEdit = this.IsActionEnabled('edit'); if(form.apply) form.apply.disabled = !bEnabled; var b = document.getElementById('action_edit_button'); if(b) b.className = 'context-button icon action-edit-button'+(bEnabledEdit? '':'-dis'); b = document.getElementById('action_delete_button'); if(b) b.className = 'context-button icon action-delete-button'+(bEnabled? '':'-dis');}
this.IsActionEnabled = function(action)
{ var form = document.forms['form_'+this.table_id]; if(!form) return; var bChecked = false; var span = document.getElementById(this.table_id+'_selected_span'); if(span && parseInt(span.innerHTML)>0)
bChecked = true; if(action == 'edit')
return !(form.action_target && form.action_target.checked) && bChecked; else
return (form.action_target && form.action_target.checked) || bChecked;}
this.SetActiveResult = function()
{ CHttpRequest.Action = function(result)
{ CloseWaitWindow(); document.getElementById(_this.table_id+"_result_div").innerHTML = result; _this.InitTable(); jsAdminChain.AddItems(_this.table_id+"_navchain_div");}
}
this.GetAdminList = function(url)
{ ShowWaitWindow(); if(url.indexOf('?')>=0)
url += '&mode=list&table_id='+escape(this.table_id); else
url += '?mode=list&table_id='+escape(this.table_id); this.SetActiveResult(); CHttpRequest.Send(url);}
this.PostAdminList = function(url)
{ if(url.indexOf('?')>=0)
url += '&mode=frame&table_id='+escape(this.table_id); else
url += '?mode=frame&table_id='+escape(this.table_id); var frm = document.getElementById('form_'+this.table_id); try{frm.action.act.parentNode.removeChild(frm.action);}catch(e){}
frm.action = url; frm.onsubmit(); frm.submit();}
}
 