/* ------------------------------------------------------------ note: please do not remove this notice or modify this code. you may reuse/subclass this code into your projects and if you have suggestions/ideas/fixes for this code, please discuss with the original authors ------------------------------------------------------------ inception: 9/2003 ideas by: binh, lucy reference: http://phccwdd6ljp911.hew.us.ml.com/GenesisDemo ------------------------------------------------------------ */ function getParentElement (control, tagName) { if (tagName == null) return null; while (control != null) { if (control.tagName != null && control.tagName.toLowerCase () == tagName.toLowerCase ()) break; control = control.parentElement; } return control; } function dataGridSelectRows (control, cellIndex) { var table = dataGridGetTable (control); if (table != null) { for (var i = 0; i < table.rows.length; i++) { var row = table.rows [i]; dataGridSelectCell (row, cellIndex, control.checked); } } } function dataGridSelectCell (row, cellIndex, checked) { if (cellIndex >= row.cells.length) return; var cell = row.cells [cellIndex]; if (cell.childNodes.length == 1) { var inputs = cell.getElementsByTagName ("INPUT"); if (inputs == null || inputs.length == 0) return; var child = inputs [0]; if (child.tagName == null || child.tagName.toLowerCase () != "input") return; if (child.parentElement.disabled) return; var type = child.getAttribute ("type"); if (type == null) return; if (type.toLowerCase () == "checkbox") child.checked = checked; } } function dataGridGetTable (control) { var el = control; while (el != null) { if (el.tagName != null && el.tagName.toLowerCase () == "table") return el; el = el.parentElement; } return null; } function dataGridGetRow (control) { var el = control; while (el != null) { if (el.tagName != null && el.tagName.toLowerCase () == "tr") return el; el = el.parentElement; } return null; } function dataGridGetFieldIndex (control, name) { var table = dataGridGetTable (control); if (table == null || table.rows.length < 1) return -1; var header = table.rows [0]; for (var i = 0; i < header.cells.length; i++) { var cell = header.cells [i]; if (cell.getAttribute ("datafield") == name) return parseInt (cell.getAttribute ("index")) } return -1; } function dataGridGetCellText (control, name) { var index = dataGridGetFieldIndex (control, name); if (index == -1) return null; var row = dataGridGetRow (control); if (row == null) return null; var cell = row.cells [index]; var text = dataGridTrimText (dataGridGetCellValue (cell)); return text; } function dataGridGetCellValue (cell) { if (cell.children.length > 0) { for (var i = 0; i < cell.children.length; i++) { var editor = cell.children [i]; if (typeof (editor.value) == "string") return editor.value; } } return cell.innerText; } function dataGridTrimText (s) { return s.replace (/^\s*/, '').replace (/\s*$/, ''); } function dataGridHiliteRow (control, clearAll) { var table = null; var row = null; var el = control while (el != null) { if (el.tagName != null && el.tagName.toLowerCase () == "table") table = el; else if (el.tagName != null && el.tagName.toLowerCase () == "tr") row = el; if (row != null && table != null) break; el = el.parentElement; } //unhilite if ((typeof (clearAll) == "undefined" || clearAll) && (table != null)) { for (var i = 0; i < table.rows.length; i++) dataGridHiliteOneRow (table.rows [i], false); } //hilite if (row != null) dataGridHiliteOneRow (row, true); } function dataGridHiliteOneRow (row, hilite) { var saveClassAttribute = "_oldClass"; if (hilite) { if (row.getAttribute (saveClassAttribute) == null) row.setAttribute (saveClassAttribute, row.className); for (var i = 0; i < row.cells.length; i++) { var cell = row.cells [i]; if (cell.getAttribute (saveClassAttribute) == null) cell.setAttribute (saveClassAttribute, cell.className); cell.className = ""; } row.className = "datagridrowhover"; } else { if (row.getAttribute (saveClassAttribute) != null) { row.className = row.getAttribute (saveClassAttribute); row.removeAttribute (saveClassAttribute); } for (var i = 0; i < row.cells.length; i++) { var cell = row.cells [i]; if (cell.getAttribute (saveClassAttribute) != null) { cell.className = cell.getAttribute (saveClassAttribute); cell.removeAttribute (saveClassAttribute); } } } } function dataGridIsRowHilited (row) { return row.className.toLowerCase () == "datagridrowhover"; } function dataGridToggleHiliteRow (control) { var row = null; var saveClassAttribute = "_oldClass"; var el = control while (el != null) { if (el.tagName != null && el.tagName.toLowerCase () == "tr") row = el; if (row != null) break; el = el.parentElement; } //hilite if (row != null) dataGridHiliteOneRow (row, !dataGridIsRowHilited (row)); } function dataGridMouseDownForSelection (row, cellIndex) { var BUTTON_LEFT = 1; if (window.event.button != BUTTON_LEFT) return; if (window.event.srcElement != null && window.event.srcElement.tagName == "INPUT") return; dataGridSelectRow (row, cellIndex, window.event.ctrlKey, window.event.shiftKey); } function dataGridSelectRow (row, cellIndex, ctrlKey, shiftKey) { if (ctrlKey) { var selected = dataGridIsRowHilited (row); dataGridToggleHiliteRow (row); dataGridSelectCell (row, cellIndex, !selected); } else if (shiftKey) { var table = getParentElement (row, "TABLE"); if (table != null) { var end = -1; //forwards for (var i = row.rowIndex + 1; i < table.rows.length; i++) { var r = table.rows [i]; if (dataGridIsRowHilited (r)) { end = i; break; } } //backwards if (end == -1) { for (var i = row.rowIndex - 1; i >= 0; i--) { var r = table.rows [i]; if (dataGridIsRowHilited (r)) { end = i; break; } } } if (end != -1) { var start = 0; if (row.rowIndex > end) { start = end; end = row.rowIndex; } else start = row.rowIndex; for (var i = start; i <= end; i++) { var r = table.rows [i]; dataGridHiliteRow (r, false); dataGridSelectCell (r, cellIndex, true); } } } } else { dataGridHiliteRow (row); dataGridSelectCell (row, cellIndex, true); } } function dataGridMouseDownForContextMenu (control) { var BUTTON_RIGHT = 2; if (window.event.button == BUTTON_RIGHT) dataGridHiliteRow (control); } function commandControlHilite (control) { control.style.cursor = "hand"; } var popupWindowCurrent = null; function PopupWindow (x, y, width, height, className) { if (typeof (className) == "undefined") className = "PopupWindow"; this.x = x; this.y = y; this.width = typeof (width) == "undefined" ? -1 : width; this.height = typeof (height) == "undefined" ? -1 : height; this.className = className; //sender is the element/source that called this popup this.sender = null; //opener is the calling window that opened this popup this.opener = null; //trackMouse specifies of mouse movements outside the popup will automatically close it this.trackMouse = false; PopupWindow.doneMouseTracking (); } PopupWindow.close = function () { try { if (popupWindowCurrent != null) if (popupWindowCurrent.window != null) { if (typeof (popupWindowCurrent.window.close) != "undefined") popupWindowCurrent.window.close (); else if (typeof (popupWindowCurrent.window.hide) != "undefined") popupWindowCurrent.window.hide (); popupWindowCurrent.window = null; } } catch (e) { } } PopupWindow.isOpen = function () { try { if (popupWindowCurrent != null) if (popupWindowCurrent.window != null) return popupWindowCurrent.window.isOpen; } catch (e) { return false; } } PopupWindow.prototype.show = function (content, sender, opener) { PopupWindow.close (); if (typeof (opener) == "undefined") opener = window; if (typeof (sender) == "undefined") sender = window; var win = window.createPopup (); var doc = win.document; popupCopyCurrentStylesheets (doc); doc.body.innerHTML = content; for (var i = 0; i < doc.body.children.length; i++) { var child = doc.body.children [i]; child.style.display = "inline"; if (this.className != null && child.className == "") child.className = this.className; } doc.body.scroll = "no"; doc.opener = opener; doc.sender = sender; this.sender = sender; this.opener = opener; popupWindowCurrent = this; popupWindowCurrent.window = win; this.calculateDimensions (doc.body.innerHTML); if (this.width < screen.width && this.height < screen.height) { win.show (this.x, this.y, this.width, this.height, document.body); if (this.trackMouse) this.initializeMouseTracking (); } else { //content does not fit screen, so open it up in a new browser window var newWin = window.open ("about:blank", "Popup", "menubar=no,resizable=yes,scrollbars=yes"); var newDoc = newWin.document; newDoc.opener = opener; newDoc.sender = sender; newDoc.body.innerHTML = doc.body.innerHTML; popupCopyCurrentStylesheets (newDoc); newWin.focus (); popupWindowCurrent.window = newWin; } } PopupWindow.prototype.initializeMouseTracking = function () { document.onmouseover = PopupWindow.handleTrackMouse; } function PopupWindow.handleTrackMouse () { if (PopupWindow.isOpen ()) { if (!PopupWindow.isMenuElement (window.event.srcElement)) { PopupWindow.close (); PopupWindow.doneMouseTracking (); } } } function PopupWindow.doneMouseTracking () { if (popupWindowCurrent != null) try { if (popupWindowCurrent.sender.getAttribute ("closepopupscript") != null) { var script = new Function ("__closePopupScript = " + popupWindowCurrent.sender.getAttribute ("closepopupscript") + ";"); script (); __closePopupScript (popupWindowCurrent.sender); } } catch (e) { } document.onmouseover = null; } function PopupWindow.isMenuElement (field) { while (field != null) { if (field.getAttribute ("menu") == "true") return true; field = field.parentElement; } return false; } PopupWindow.prototype.calculateDimensions = function (content) { if (this.width > 0 && this.height > 0) return; var workAreaID = "__PopupWindowWorkArea"; workArea = document.all [workAreaID]; if (workArea == null) { workArea = document.createElement ("DIV"); workArea.id = workAreaID; var style = workArea.style; style.position = "absolute"; style.visibility = "hidden"; document.body.appendChild (workArea); } workArea.innerHTML = content; if (this.width <= 0) this.width = workArea.offsetWidth; if (this.height <= 0) this.height = workArea.offsetHeight; workArea.innerHTML = ""; } function popupCopyCurrentStylesheets (targetDoc) { for (i = 0; i < document.styleSheets.length; i++) targetDoc.createStyleSheet ((document.styleSheets [i].href) ? document.styleSheets [i].href : ""); } var contextMenuCustomArgument = ""; function ContextMenuParameters (name, argument) { this.name = name; this.argument = argument; } function contextMenuOnContextMenu () { contextMenuCustomArgument = ""; var e = window.event.srcElement; var srcIsReadOnly = e.tagName == "TD" || e.tagName == "DIV" || e.tagName == "SPAN" || e.tagName == "TABLE"; if (srcIsReadOnly) if (contextMenuPrepareAndShow (e)) return false; return true; } function contextMenuPrepareAndShow (sender) { var params = contextMenuPrepareParameters (sender); if (params.name != null) { contextMenuShow (sender, params.name, window.event.x - 2, window.event.y - 2, true); return true; } return false; } function contextMenuPrepareParameters (sender) { contextMenuCustomArgument = ""; //get contextmenu name + argument var name = null; var arg = null; var e = sender; while ((name == null) && (e != null)) { name = e.contextmenu; if (arg == null) arg = e.contextmenuargument; e = e.parentElement; } //set contextmenuargument if (arg != null) contextMenuCustomArgument = arg.toString (); return new ContextMenuParameters (name, arg); } //prototype: function contextMenuItemInitScript (sender, menuItem, commandName) //return true to show menu item; false to hide menu item function contextMenuShow (sender, name, x, y, trackMouse) { var menu = document.all [name]; if (menu != null) { var initScript = menu.getAttribute ("initscript"); if (initScript != null && initScript != "") { initScript = new Function ("__contextMenuItemInitScript = " + initScript + ";"); initScript (); //initialize if (__contextMenuItemInitScript != null) { var noneVisible = true; var items = menu.getElementsByTagName ("TR"); if (items != null) for (var i = 0; i < items.length; i++) { var item = items [i]; var showItem = __contextMenuItemInitScript (sender, item, item.getAttribute ("commandname")); if (item.getAttribute ("commandname") == "Header") showItem = item.innerText != ""; item.style.display = showItem ? "" : "none"; if (showItem) noneVisible = false; } if (noneVisible) return false; } } contextMenuCleanUpSeparators (menu); var popup = new PopupWindow (x, y); if (typeof (trackMouse) != "undefined") popup.trackMouse = trackMouse; popup.show (menu.outerHTML, sender); return true; } return false; } function contextMenuCleanUpSeparators (menu) { var items = menu.getElementsByTagName ("TR"); if (items != null) { //eliminate dups var lastIsSeparator = false; for (var i = 0; i < items.length; i++) { var item = items [i]; if (item.style.display == "none") continue; var isSeparator = item.getAttribute ("separator") == "true"; if (isSeparator) if (lastIsSeparator) item.style.display = "none"; lastIsSeparator = isSeparator; } //eliminate top for (var i = 0; i < items.length; i++) { var item = items [i]; if (item.style.display == "none") continue; var isSeparator = item.getAttribute ("separator") == "true"; if (isSeparator) item.style.display = "none"; else break; } //eliminate bottom for (var i = items.length - 1; i >= 0; i--) { var item = items [i]; if (item.style.display == "none") continue; var isSeparator = item.getAttribute ("separator") == "true"; if (isSeparator) item.style.display = "none"; else break; } } } function contextMenuClick (sender) { PopupWindow.close (); var isPostBack = sender.getAttribute ("onclick").toString ().indexOf ("PostBack") >= 0; if (isPostBack) document.body.style.cursor = "wait"; } function contextMenuSetItemText (item, headerText) { var cells = item.getElementsByTagName ("TD"); if (cells != null) cells [cells.length - 1].innerHTML = headerText; } function dataGridToggle (control) { var toggle = control; var table = null; while (control != null) { if (control.tagName != null && control.tagName.toLowerCase () == "table") { table = control; break; } control = control.parentElement; } if (table != null) { dataGridToggleControls (table); var collapsed = toggle.getAttribute ("collapsed"); collapsed = collapsed == "true" ? "false" : "true"; toggle.setAttribute ("collapsed", collapsed); toggle.src = collapsed == "true" ? toggle.getAttribute ("collapsedimage") : toggle.getAttribute ("expandedimage"); toggle.alt = collapsed == "true" ? toggle.getAttribute ("collapsedhint") : toggle.getAttribute ("expandedhint"); } dataGridUpdateData (toggle); } function dataGridToggleControls (table) { var cells = table.getElementsByTagName ("TD"); if (cells == null || cells.length == 0) return; for (var i = 0; i < cells.length; i++) { var cell = cells [i]; if (cell.getAttribute ("toggle") != "true") continue; cell.style.display = cell.style.display == "none" ? "" : "none"; } } function dataGridUpdateData (control) { var data = document.all [control.getAttribute ("data")]; if (data != null) { var collapsed = control.getAttribute ("collapsed"); data.value = collapsed; } } function listboxUpdateData (listbox, postback) { var data = document.all [listbox.getAttribute ("data")]; if (data != null) { data.value = htmlFormEncode (listbox.innerHTML); //postback if autopostback is set to true... var args = null; if ((listbox.getAttribute("autopostback") == "true") && postback) { //alert(listbox.getAttribute("name")); __doPostBack(listbox.getAttribute("clientid"), args); } } } function htmlFormEncode (s) { s = s.replace (/&/gi, "&"); s = s.replace (/"/gi, """); s = s.replace (//gi, ">"); return s; } function listboxSelectAll (listbox, select) { //note: reversed so that top-most selected item is always visible for (var i = listbox.options.length - 1; i >= 0; i--) { var option = listbox.options [i]; option.selected = select; } } function listboxClearAll (listbox) { listbox.options.length = 0; listboxUpdateData (listbox, false); } function listboxCanAddItem (listbox) { var capacity = listboxGetCapacity (listbox); if (capacity != -1) if (listbox.options.length >= capacity) return false; return true; } function listboxGetCapacity (listbox) { var capacity = listbox.getAttribute ("capacity"); if (capacity != null) return parseInt (capacity); return -1; } function listboxValidateCapacity (listbox) { if (!listboxCanAddItem (listbox)) { alert ("You can only add/select up to " + listboxGetCapacity (listbox) + " item(s)."); return false; } return true; } function listboxAddItem (listbox, item) { if (!listboxValidateCapacity (listbox)) return false; listbox.options.add (item); listboxUpdateData (listbox, false); return true; } function listboxIndexOfValue (listbox, value) { for (var i = 0; i < listbox.options.length; i++) { var item = listbox.options [i]; if (item.value == value) return i; } return -1; } function listboxRemoveItem (listbox, index) { listbox.options.remove (index); listboxUpdateData (listbox, false); } var lookupUserValue = "?"; function lookupGetAutoSelect (lookup) { return lookup.getAttribute ("autoselect") == "true"; } function lookupKeyDown (lookup) { //alert (window.event.keyCode); var KEY_DELETE = 46; var KEY_ENTER = 13; var persistSelectAll = lookup.getAttribute ("persistselectall"); switch (window.event.keyCode) { case KEY_DELETE: for (var i = lookup.options.length - 1; i >= 0; i--) { var option = lookup.options [i]; if (option.selected || (persistSelectAll == "true")) listboxRemoveItem (lookup, i); } if (lookup.options.length == 0) lookupBeginEdit (lookup); break; case KEY_ENTER: lookupBeginEdit (window.event.srcElement); break; } } function lookupHideEditor (control, saveContents) { var refid = control.getAttribute ("refid"); var ref = document.all [refid]; if (saveContents) { var text = control.value; if (ref != null) { listboxClearAll (ref); if (text != "") { var item = document.createElement ("OPTION"); item.value = lookupUserValue; item.text = text; if (lookupGetAutoSelect (ref)) item.selected = true; listboxAddItem (ref, item); } } //postback if autopostback is set to true... var args = null; if (ref.getAttribute("autopostback") == "true") { //alert(ref.getAttribute("name")); __doPostBack(ref.getAttribute("clientid"), args); } } control.parentElement.removeChild (control); ref.style.display = ""; if (document.activeElement == null || document.activeElement.tagName == null || document.activeElement.tagName == "BODY" || document.activeElement.tagName == "TD") //? { window.setTimeout ("lookupFocus ('" + refid + "')", 1); //focus hack } else { if (document.activeElement != null && document.activeElement.tagName == "SELECT") { var id = document.activeElement.id; if (id != null && id != "" && document.activeElement.multiple) window.setTimeout ("lookupFocus ('" + id + "')", 1); //focus hack } } } function lookupFocus (id) { try { var field = document.all [id]; if (field != null) field.focus (); } catch (e) { } } function lookupExit () { var control = window.event.srcElement; lookupHideEditor (control, true); } function lookupEditorKeyDown () { var KEY_ESC = 27; var KEY_ENTER = 13; var control = window.event.srcElement; switch (window.event.keyCode) { case KEY_ESC: lookupHideEditor (control, false); break; case KEY_ENTER: lookupHideEditor (control, true); break; } } function lookupIsEditable (control) { if (control.disabled) return false; return control.getAttribute ("editable") == "true" && control.size == 1; } function lookupShowEditor (control) { var text = document.createElement ("INPUT"); text.className = "textbox"; text.style.top = control.offsetTop; text.style.left = control.offsetLeft; text.style.width = control.offsetWidth; if (control.getAttribute ("maxlength") != null) text.maxLength = control.getAttribute ("maxlength"); text.setAttribute ("refid", control.id); if (control.options.length == 1 && control.options [0].value == lookupUserValue) text.value = control.options [0].text; text.onblur = lookupExit; text.onkeydown = lookupEditorKeyDown; control.parentElement.insertBefore (text, control); control.style.display = "none"; text.focus (); text.select (); } function lookupBeginEdit (control) { if (lookupIsEditable (control)) { lookupShowEditor (control); } } function lookupIsUserValue (value) { return value == lookupUserValue; } function lookupClick (control) { if (control.options.length == 0 || (control.options.length == 1 && control.options [0].value == lookupUserValue)) lookupBeginEdit (control); } function formToggle (control) { var toggle = control; var table = null; while (control != null) { if (control.tagName != null && control.tagName.toLowerCase () == "table") { table = control; break; } control = control.parentElement; } if (table != null) { formToggleControls (table); var collapsed = toggle.getAttribute ("collapsed"); collapsed = collapsed == "true" ? "false" : "true"; toggle.setAttribute ("collapsed", collapsed); toggle.src = collapsed == "true" ? toggle.getAttribute ("collapsedimage") : toggle.getAttribute ("expandedimage"); toggle.alt = collapsed == "true" ? toggle.getAttribute ("collapsedhint") : toggle.getAttribute ("expandedhint"); } formUpdateData (toggle); } function formToggleControls (table) { var cells = table.getElementsByTagName ("TD"); if (cells == null || cells.length == 0) return; for (var i = 0; i < cells.length; i++) { var cell = cells [i]; if (cell.getAttribute ("toggle") != "true") continue; cell.style.display = cell.style.display == "none" ? "" : "none"; } } function formUpdateData (control) { var data = document.all [control.getAttribute ("data")]; if (data != null) { var collapsed = control.getAttribute ("collapsed"); data.value = collapsed; } } function formEnableControl (id, enable) { var control = document.all [id]; if (control == null) return; var cell = getParentElement (control, "td"); if (cell != null) { formEnableCell (cell, enable); formEnableCell (cell.previousSibling, enable); } } function formEnableCell (cell, enable) { if (cell == null) return; for (var i = 0; i < cell.children.length; i++) cell.children [i].disabled = !enable; } function webTaskRun (id) { webTaskRun (id, null); } function webTaskIsArray (o) { if (typeof o == 'object') return o.constructor.toString ().match (/array/i) != null; return false; } function webTaskRun (id, parameters) { var task = document.all [id]; if (task == null) { alert ("Invalid task specified: " + id); return; } var url = task.getAttribute ("taskurl"); document.body.style.cursor = "wait"; if (webTaskIsArray (parameters)) { //post! warning: post will record in browser history //parameters format: [name, value, name, value, ...] if (parameters.length % 2 != 0) { alert ("Parameters must have even count."); return; } var doc = frames [id].document; doc.open (); doc.writeln ("
"); doc.close (); for (var i = 0; i < parameters.length; i += 2) doc.all [parameters [i]].value = parameters [i + 1]; task.setAttribute ("running", "true"); doc.forms [0].submit (); } else { //get! //parameters format: valid querystring if (parameters != "" && parameters != null) { if (url.indexOf ("?") < 0) url += "?"; url += parameters; } task.setAttribute ("running", "true"); frames [id].location.replace (url); } } function WebTaskResult (ok, output) { this.ok = ok; this.output = output; } function webTaskGetResult (id) { try { var dataField = frames [id].document.all ["webtaskresult"]; return dataField != null ? new WebTaskResult (true, dataField.value) : new WebTaskResult (false, frames [id].document.body.outerHTML); } catch (e) { return null; } } function webTaskDone (id, clientScript) { //alert("I am here"); //alert(id); if (document.all [id].getAttribute ("running") != "true") return; document.all [id].removeAttribute ("running"); document.body.style.cursor = ""; if (clientScript != null) { var result = webTaskGetResult (id); if (result != null) { if (result.ok) clientScript (result.output, id); else { alert ("Unable to complete processing task. Please report the following error (shown next) to your help desk."); showWebTaskError (result.output); } } else alert ("Unable to complete processing task. Please check if the application web server is running properly."); } } function showWebTaskError (output) { var log = window.open ("about:blank"); log.document.open (); log.document.writeln (""); log.document.writeln (output); log.document.close (); } function compareValidatorEvaluate (val) { var dataType = val.type; if (dataType == "Double" && document.all [val.controltocompare] != null) { var compareTo = ValidatorGetValue (val.controltocompare); if (ValidatorTrim (compareTo).length == 0) return true; } return CompareValidatorEvaluateIsValid (val); } function requiredValidatorEvaluateLookup (val) { var field = document.all [val.controltovalidate]; if (field != null && field.options.length > 0) return true; return RequiredFieldValidatorEvaluateIsValid (val); } function openReport (id) { var report = document.all [id]; if (report == null) { alert ("Invalid report specified: " + id); return; } var url = report.getAttribute ("reporturl") var inputID = report.getAttribute ("reportinput"); var inputField = document.all [inputID]; var input = inputField != null ? inputField.value : ""; var win = window.open ("", "Report"); if (win != null) win.close (); win = window.open ("about:blank", "Report", "menubar=no,toolbar=yes,status=yes,resizable=yes,scrollbars=yes"); var doc = win.document; doc.open (); doc.writeln (""); doc.writeln ("