function openPopup(url) {
window.open(
url,
"",
"width=900, height=550, scrollbars=yes, resizable=yes, location=no"
);
return false;
}
function ajax_POSTRequest(form, url, element) {
var parameters = "sys_Source=ajax";
for (var i = form.elements.length - 1; i >= 0; i--) {
parameters =
parameters +
"&" +
form.elements[i].name +
"=" +
encodeURIComponent(form.elements[i].value);
}
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
if (request.overrideMimeType) request.overrideMimeType("text/html");
} else if (window.ActiveXObject) {
request = new ActiveXObject("MSXML2.XMLHTTP");
}
request.onreadystatechange = function () {
ajax_onResponse(element);
};
request.open("POST", url, true);
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//request.setRequestHeader("Content-length", parameters.length);
//request.setRequestHeader("Connection", "close");
request.send(parameters);
}
// Same as old POSTRequest but calls different callback
// function that greys out content when loading rather
// than replacing content with loading gif
function ajax_new_POSTRequest(form, url, element) {
var parameters = "sys_Source=ajax";
for (var i = form.elements.length - 1; i >= 0; i--) {
parameters =
parameters +
"&" +
form.elements[i].name +
"=" +
encodeURIComponent(form.elements[i].value);
}
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
if (request.overrideMimeType) request.overrideMimeType("text/html");
} else if (window.ActiveXObject) {
request = new ActiveXObject("MSXML2.XMLHTTP");
}
request.onreadystatechange = function () {
ajax_new_onResponse(element);
};
request.open("POST", url, true);
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(parameters);
}
function ajax_new_onResponse(element) {
var lsError;
if (request.readyState == 1) {
setToLoading(element);
}
if (request.readyState == 4) {
if (request.status == 200) {
setContent(request.responseText, element);
} else if (request.status == 404) {
// Add a custom message or redirect the user to another page
setContent("File not found", element);
} else if (request.status == 403) {
// Add a custom message for the error
setContent("Access Denied", element);
} else if (request.status == 401) {
// Add a custom message for the error
setContent(
"
Unauthorised
You must log in to view this content.",
element
);
} else if (request.status == 400) {
// Add a custom message for the error
lsError = "" + request.getResponseHeader("X-Error-Message");
// Make sure there is an error message - not sure if this correct, see next case -TB
if (!lsError.length > 0)
lsError = "There was a problem retrieving the content.";
// Display the error as the content
setContent("
Unable to Continue:
" + lsError, element);
} else {
// Add a custom message for the error
lsErrorID = "" + request.getResponseHeader("X-Error-ID");
// Make sure there is an error message
if (!(lsErrorID.length == 36)) {
setContent(
"System Error - There was a problem retrieving the content.",
element
);
} else {
// Display the error as the content
ajax_makeRequest(
"/matrix/D468F7A0-BA05-43EB-85AD-EB5A0FA392F8?" + lsErrorID,
element
);
}
}
}
}
function setToLoading(element) {
if (document.getElementById(element)) {
var lElem = document.getElementById(element);
// Always show content from response
lElem.overrideHTML = "";
// Do not append loading mask if already done so
// if(!hasChildWithClass(lElem,"matrix_ajax_refreshmask_holder")) {
if (!hasChildWithClass(lElem, "matrix_ajax_refreshmask")) {
if (lElem.tagName == "TR") {
// Cannot use .innerHTML for table rows
lElem.firstChild.innerHTML +=
"";
} else {
// This was in here 22-6-2018 but don't know why, assume it is because of another bug but no idea what. CP
// lElem.className = "matrix_ajax_refreshmask_holder";
// Don't apply relative to the right-click menu!
// Don't apply relative css to queries - problems with BA - RB 18/12/13
if (
lElem.getAttribute("id") != "lContextMenu" &&
lElem.getAttribute("id") != "query"
) {
lElem.style.position = "relative";
}
lnodeHolder = document.createElement("div");
lnodeHolder.className = "matrix_ajax_refreshmask";
lnodeHolder.minHeight = "50px";
lnodeHolder.innerHTML =
";";
lElem.appendChild(lnodeHolder);
}
}
}
}
function hasChildWithClass(element, classname) {
// look for a child with specified class name
for (var i = 0; i < element.childNodes.length; i++) {
if (element.childNodes[i].className == classname) {
return true;
}
}
// Class not found
return false;
}
function ajax_updateElement(url, element) {
// Create Request
if (window.XMLHttpRequest) request = new XMLHttpRequest();
else if (window.ActiveXObject) request = new ActiveXObject("MSXML2.XMLHTTP");
request.onreadystatechange = function () {
ajax_updateElementonResponse(element);
};
request.open("GET", url, true);
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.send(null);
}
function ajax_updateElementonResponse(element) {
if (request.readyState == 4) {
if (request.status == 200) {
setContent(request.responseText, element);
} else if (request.status == 404) {
// Add a custom message or redirect the user to another page
setContent("File not found", element);
} else if (request.status == 400) {
// Add a custom message for the error
lsError = "" + request.getResponseHeader("X-Error-Message");
// Make sure there is an error message - not sure if this correct, see next case -TB
if (!lsError.length > 0)
lsError = "There was a problem retrieving the content.";
// Display the error as the content
setContent("
Unable to Continue:
" + lsError, element);
} else {
// Add a custom message for the error
lsErrorID = "" + request.getResponseHeader("X-Error-ID");
// Make sure there is an error message
if (!(lsErrorID.length == 36)) {
setContent(
"System Error - There was a problem retrieving the content.",
element
);
} else {
// Display the error as the content
ajax_makeRequest(
"/matrix/D468F7A0-BA05-43EB-85AD-EB5A0FA392F8?" + lsErrorID,
element
);
}
}
}
}
function ajax_makeRequest(url, element) {
if (window.XMLHttpRequest) request = new XMLHttpRequest();
else if (window.ActiveXObject) request = new ActiveXObject("MSXML2.XMLHTTP");
request.onreadystatechange = function () {
ajax_onResponse(element);
};
request.open("GET", url, true);
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.send(null);
}
function ajax_onResponse(element) {
// if(request.readyState == 0) { setContent("Sending ...", element); }
if (request.readyState == 1) {
setToLoading(element);
}
// if(request.readyState == 1) { setContent("", element); }
// if(request.readyState == 2) { setContent("Loaded ...", element); }
if (request.readyState == 3) {
setContent("Processing ...", element);
}
if (request.readyState == 4) {
if (request.status == 200) {
setContent(request.responseText, element);
} else if (request.status == 404) {
// Add a custom message or redirect the user to another page
setContent("File not found", element);
} else if (request.status == 403) {
// Add a custom message for the error
setContent("Access Denied", element);
} else if (request.status == 401) {
// Add a custom message for the error
setContent(
"
Unauthorised
You must log in to view this content.",
element
);
} else if (request.status == 400) {
// Add a custom message for the error
lsError = "" + request.getResponseHeader("X-Error-Message");
// Make sure there is an error message - not sure if this correct, see next case -TB
if (!lsError.length > 0) {
lsError = "There was a problem retrieving the content.";
}
// Display the error as the content
setContent("
Unable to Continue:
" + lsError, element);
} else {
// Add a custom message for the error
lsErrorID = "" + request.getResponseHeader("X-Error-ID");
// Make sure there is an error message
if (!(lsErrorID.length == 36)) {
setContent(
"System Error - There was a problem retrieving the content.",
element
);
} else {
// Display the error as the content
ajax_makeRequest(
"/matrix/D468F7A0-BA05-43EB-85AD-EB5A0FA392F8?" + lsErrorID,
element
);
}
}
}
}
function setContent(newContent, element) {
if (document.getElementById(element)) {
var lElem = document.getElementById(element);
if (lElem) {
if (lElem.overrideHTML != newContent) {
lElem.overrideHTML = newContent;
if (lElem.tagName != "TR") {
lElem.innerHTML = newContent;
} else {
// Need to remove the existing cell
lElem.removeChild(lElem.firstChild);
//lElem = newContent
var newCell = lElem.insertCell(0);
newCell.innerHTML = newContent;
newCell.style.position = "relative";
newCell.colSpan = 3;
}
}
// Execute javascript in the new code
execJS(lElem);
}
}
}
var bSaf = navigator.userAgent.indexOf("Safari") != -1;
var bOpera = navigator.userAgent.indexOf("Opera") != -1;
var bMoz = navigator.appName == "Netscape";
function execJS(node) {
var st = node.getElementsByTagName("SCRIPT");
var strExec;
for (var i = 0; i < st.length; i++) {
if (bSaf) strExec = st[i].innerHTML;
else if (bOpera) strExec = st[i].text;
else if (bMoz) strExec = st[i].textContent;
else strExec = st[i].text;
try {
eval(strExec.split("").join(""));
} catch (e) {
alert(e);
}
}
}
function startDrag(ev, sourceObjectID) {
// post the data for Windows:
var dragData = ev.dataTransfer;
// set the type of data for the clipboard:
dragData.setData("Text", sourceObjectID);
// allow only dragging that involves moving the object:
dragData.effectAllowed = "all";
// use the special 'move' cursor when dragging:
dragData.dropEffect = "move";
}
function enterDrag(ev) {
// allow target object to read clipboard:
// window.event.dataTransfer.getData('Text');
ev.returnValue = false;
}
function endDrag(ev) {
// when done remove clipboard data
ev.dataTransfer.clearData();
}
function overDrag(ev) {
//window.event.srcElement.scrollIntoView();
ev.preventDefault ? ev.preventDefault() : (ev.returnValue = false);
//ev.srcElement.focus();
//ev.returnValue=false;
//window.event.srcElement.scrollIntoView();
// tell onOverDrag handler not to do anything
//window.event.returnValue = false;
}
function drop(ev, targetObjectID, ParameterName) {
ev.preventDefault ? ev.preventDefault() : (ev.returnValue = false);
// eliminate default action of ondrop so we can customize:
parent.mainFrame.location =
"/matrix/bxe-3B5F3014-CF29-4694-815A-FA834B77F506?" +
ev.dataTransfer.getData("Text") +
"&" +
targetObjectID +
"&" +
ParameterName;
ev.returnValue = false;
}
function droptv(ev, targetObjectID) {
ev.preventDefault ? ev.preventDefault() : (ev.returnValue = false);
// eliminate default action of ondrop so we can customize:
//parent.mainFrame.location = '/matrix/bxe-DE5F1C15-09AC-4F2C-BBEF-985FB6092538?' + ev.dataTransfer.getData('Text') + '&' + targetObjectID;
if (ev.ctrlKey) {
// Ctrl key is held down - try and run the admin 'move/copy' override
parent.mainFrame.location =
"/matrix/bxe-DE5F1C15-09AC-4F2C-BBEF-985FB6092538?" +
ev.dataTransfer.getData("Text") +
"&" +
targetObjectID;
} else {
// Run the standard code
top.tbox_show(
"/matrix/4AEDC633-A081-4D3F-8F10-A10A80C9647E?" +
ev.dataTransfer.getData("Text") +
"&" +
targetObjectID,
"Drag Item",
{ height: 340, width: 640 }
);
}
ev.returnValue = false;
}
function fnCancelEffect(ev) {
//alert(window.event.srcElement.innerHTML);
ev.preventDefault ? ev.preventDefault() : (ev.returnValue = false);
//ev.returnValue=false;
}
function clearSelection(targetField) {
if (targetField.createTextRange) {
var range = targetField.createTextRange();
range.moveStart("character", targetField.value.length);
range.select();
}
}
function controlCursor_Tab(formControl, e) {
if (
(e.keyCode == 13 && e.shiftKey == false) ||
(e.keyCode == 9 && e.shiftKey == false)
) {
moveFocus(formControl, 1);
return false;
}
if (
(e.keyCode == 13 && e.shiftKey == true) ||
(e.keyCode == 9 && e.shiftKey == true)
) {
moveFocus(formControl, -1);
return false;
}
}
function controlCursor_Cursor(formControl, e) {
if (e.keyCode == 40) {
moveFocus(formControl, 1);
return false;
}
if (e.keyCode == 38) {
moveFocus(formControl, -1);
return false;
}
}
function controlCursor_Date(formControl, e) {
// Check for any character that could seperate a date and use it to tab to the next control
if (
e.keyCode == 111 ||
e.keyCode == 189 ||
e.keyCode == 191 ||
e.keyCode == 109 ||
e.keyCode == 32
) {
moveFocus(formControl, 1);
return false;
}
}
function checkInteger(formControl, e) {
if (!isHorzCursor(e.keyCode) && !isNumeric(e.keyCode)) return false;
}
function checkNumeric(formControl, e) {
if (
!isHorzCursor(e.keyCode) &&
!(isNumeric(e.keyCode) && e.shiftKey == false) &&
!(e.keyCode == 109) &&
!(e.keyCode == 110) &&
!(e.keyCode == 189 && e.shiftKey == false) &&
!(e.keyCode == 190 && e.shiftKey == false)
)
return false;
}
function checkAlpha(formControl, e) {
if (!isHorzCursor(e.keyCode) && !isAlphabetical(e.keyCode)) return false;
}
function checkAlphaNumeric(formControl, e) {
if (!isHorzCursor(e.keyCode) && !isAlphaNumeric(e.keyCode)) return false;
}
function checkEmail(formControl, e) {
if (!isHorzCursor(e.keyCode) && !isEmail(e.keyCode, e.shiftKey)) return false;
}
function checkURL(formControl, e) {
if (!isHorzCursor(e.keyCode) && !isURL(e.keyCode, e.shiftKey)) return false;
}
function checkCursor(formControl, e) {
if (!isHorzCursor(e.keyCode) && !isVertCursor(e.keyCode)) return false;
}
function isCursor(key) {
var flag = false;
// Cursors
// left right
if (key == 37 && key == 39) flag = true;
// up down
if (key == 38 && key == 40) flag = true;
return flag;
}
function isVertCursor(key) {
var flag;
// up down
if (key == 38 || key == 40) flag = true;
return flag;
}
function isHorzCursor(key) {
var flag;
// left right
if (key == 37 || key == 39) flag = true;
return flag;
}
function isNumeric(key) {
flag = false;
// Numbers along the top
if (key >= 48 && key <= 57) {
flag = true;
}
// Numeric keypad
if (key >= 96 && key <= 105) {
flag = true;
}
// Backspace and something else
if (key == 8 || key == 46) {
flag = true;
}
// Return
return flag;
}
function isURL(key, shift) {
//alert(key);
var flag = false;
// Numbers along the top
if (key >= 48 && key <= 57 && shift == false) {
flag = true;
}
// Numeric keypad
if (key >= 96 && key <= 105) {
flag = true;
}
// Hyphen and underscore
if (key == 189 || key == 109) {
flag = true;
}
// Backspace, Home, End, and delete
if (key == 8 || key == 36 || key == 35 || key == 46) {
flag = true;
}
// standard letters
if (key >= 65 && key <= 90) {
flag = true;
}
// Others such as Period Key and ???
if ((key == 190 && shift == false) || key == 110) {
flag = true;
}
// @ symbol - uk keyboard
if (key == 192 && shift == true) {
flag = true;
}
// @ symbol - us keyboard
if (key == 50 && shift == true) {
flag = true;
}
// url characters []!$&'()
if (
(key == 219 && shift == false) ||
(key == 221 && shift == false) ||
(key == 49 && shift == true) ||
(key == 192 && shift == false) ||
(key == 57 && shift == true) ||
(key == 48 && shift == true)
) {
flag = true;
}
// url characters *+,;=~
if (
(key == 56 && shift == true) ||
(key == 187 && shift == true) ||
(key == 188 && shift == false) ||
(key == 187 && shift == false) ||
(key == 186 && shift == false) ||
(key == 222 && shift == true) ||
(key == 192 && shift == true)
) {
flag = true;
}
// url characters :/?%
if (
(key == 186 && shift == true) ||
(key == 191 && shift == false) ||
(key == 191 && shift == true) ||
(key == 53 && shift == true)
) {
flag = true;
}
// Return
return flag;
}
function isEmail(key, shift) {
//alert(key);
var flag = false;
// Numbers along the top
if (key >= 48 && key <= 57 && shift == false) {
flag = true;
}
// Numeric keypad
if (key >= 96 && key <= 105) {
flag = true;
}
// Hyphen and underscore
if (key == 189 || key == 109) {
flag = true;
}
// Backspace, Home, End, and delete
if (key == 8 || key == 36 || key == 35 || key == 46) {
flag = true;
}
// standard letters
if (key >= 65 && key <= 90) {
flag = true;
}
// Others such as Period Key and ???
if ((key == 190 && shift == false) || key == 110) {
flag = true;
}
// @ symbol - uk keyboard
if (key == 192 && shift == true) {
flag = true;
}
// @ symbol - firefox
if (key == 222 && shift == true) {
flag = true;
}
// @ symbol - us keyboard
if (key == 50 && shift == true) {
flag = true;
}
// Return
return flag;
}
function isAlphabetical(key) {
var flag = false;
// standard letters
if (key >= 65 && key <= 90) {
flag = true;
}
// Other characters that are allowed ('_.del')
if (
key == 8 ||
key == 46 ||
key == 222 ||
key == 192 ||
key == 190 ||
key == 110
) {
flag = true;
}
// Space
if (key == 32) {
flag = true;
}
// Hyphen and underscore
if (key == 109 || key == 189) {
flag = true;
}
// Return
return flag;
}
function isAlphaNumeric(key) {
flag = isNumeric(key) || isAlphabetical(key);
return flag;
}
function guessYear(fldYear) {
// If the user enters '03' for the year, it will be seen as '0003'
// We could easily convert this to '2003' so lets give it a bash
// Declares
var now;
var date = "";
var lsNewYear = "";
var currentYear = 0;
var lYear = "";
// Extract the year in numeric form
lYear = Number(fldYear);
// If length of year value is 2 digits or less
if (lYear < 100 && lYear > 0) {
// Try to guess to relevant leading 2 digits
// Make a note of the current date and time
now = new Date();
// Get the current year, i.e. 2003 = 03
currentYear = Number(String(now.getFullYear()).substr(2, 2));
// Get the right hand two characters from the entered year and prefix it with zeros, i.e. 3 = 03
lsNewYear = "00" + fldYear;
lsNewYear = lsNewYear.substring(lsNewYear.length - 2);
// Select the prefix 19 or 20 and return it
if (lYear > currentYear + 10) {
return "19" + lsNewYear;
} else {
return "20" + lsNewYear;
}
} else {
return fldYear;
}
}
function updateDateFieldKeyUp(fld) {
// Declares
var lsYear, lsMonth, lsDay, lsHour, lsMinute, lsSecond;
var lsMasterFieldName;
// Get the field values
lsMasterFieldName = fld.name;
lsYear = "0000" + fld.form.elements[lsMasterFieldName + "_YYYY"].value;
lsMonth = "00" + fld.form.elements[lsMasterFieldName + "_MM"].value;
lsDay = "00" + fld.form.elements[lsMasterFieldName + "_DD"].value;
lsHour = "00" + fld.form.elements[lsMasterFieldName + "_HH"].value;
lsMinute = "00" + fld.form.elements[lsMasterFieldName + "_MI"].value;
lsSecond = "00" + fld.form.elements[lsMasterFieldName + "_SS"].value;
lsYear = lsYear.substring(lsYear.length - 4);
lsMonth = lsMonth.substring(lsMonth.length - 2);
lsDay = lsDay.substring(lsDay.length - 2);
lsHour = lsHour.substring(lsHour.length - 2);
lsMinute = lsMinute.substring(lsMinute.length - 2);
lsSecond = lsSecond.substring(lsSecond.length - 2);
// Set the new date
if (
parseInt(lsYear) == 0 &&
parseInt(lsMonth) == 0 &&
(parseInt(lsDay) == 0 || parseInt(lsDay) == 1) &&
parseInt(lsHour) == 0 &&
parseInt(lsMinute) == 0 &&
parseInt(lsSecond) == 0
) {
// If there is no date return it as a blank
fld.form.elements[lsMasterFieldName].value = "";
} else {
fld.form.elements[lsMasterFieldName].value =
lsYear + lsMonth + lsDay + lsHour + lsMinute + lsSecond;
}
return lsYear + lsMonth + lsDay;
}
function updateDateField(fld, endDateFld) {
// Declares
var lsYear, lsMonth, lsDay, lsHour, lsMinute, lsSecond;
var lsMasterFieldName;
// Get the field values
lsMasterFieldName = fld.name;
// Get the field values
// lsYear = "0000" + fld.form.elements[lsMasterFieldName + '_YYYY'].value;
lsYear = guessYear(
"0000" + fld.form.elements[lsMasterFieldName + "_YYYY"].value
);
lsMonth = "00" + fld.form.elements[lsMasterFieldName + "_MM"].value;
lsDay = "00" + fld.form.elements[lsMasterFieldName + "_DD"].value;
lsHour = "00" + fld.form.elements[lsMasterFieldName + "_HH"].value;
lsMinute = "00" + fld.form.elements[lsMasterFieldName + "_MI"].value;
lsSecond = "00" + fld.form.elements[lsMasterFieldName + "_SS"].value;
lsYear = lsYear.substring(lsYear.length - 4);
lsMonth = lsMonth.substring(lsMonth.length - 2);
lsDay = lsDay.substring(lsDay.length - 2);
lsHour = lsHour.substring(lsHour.length - 2);
lsMinute = lsMinute.substring(lsMinute.length - 2);
lsSecond = lsSecond.substring(lsSecond.length - 2);
// Set the new date
if (
parseInt(lsYear) == 0 &&
parseInt(lsMonth) == 0 &&
parseInt(lsDay) == 0 &&
parseInt(lsHour) == 0 &&
parseInt(lsMinute) == 0 &&
parseInt(lsSecond) == 0
) {
// If there is no date return it as a blank
fld.form.elements[lsMasterFieldName].value = "";
} else if (
parseInt(lsYear) == 0 &&
parseInt(lsMonth) == 0 &&
parseInt(lsDay) == 1 &&
parseInt(lsHour) == 0 &&
parseInt(lsMinute) == 0 &&
parseInt(lsSecond) == 0
) {
// If there is no date other than 01 in the day then return it as a blank
fld.form.elements[lsMasterFieldName].value = "";
} else {
fld.form.elements[lsMasterFieldName].value =
lsYear + lsMonth + lsDay + lsHour + lsMinute + lsSecond;
}
// Time range
if (endDateFld) {
lsEndHour = "00" + fld.form.elements[lsMasterFieldName + "_END_HH"].value;
lsEndMinute = "00" + fld.form.elements[lsMasterFieldName + "_END_MI"].value;
lsEndHour = lsEndHour.slice(-2);
lsEndMinute = lsEndMinute.slice(-2);
lsEndDate = lsYear + lsMonth + lsDay + lsEndHour + lsEndMinute + "00";
if (lsEndDate.length == 14) endDateFld.value = lsEndDate;
}
return lsYear + lsMonth + lsDay;
}
//SW 30/09/2022 - Added ability to uncheck buttons in buttonset
function updateRadioField(fld) {
var lFields = fld.form.elements;
var textField = fld.form.elements.namedItem(fld.name.substr(3));
for (var i = 0; i < lFields.length; i++) {
lField = lFields[i];
if (lField.name == fld.name) {
if (lField.checked) {
if(textField.value === lField.value) {
textField.value = "";
lField.checked = false;
$(fld.parentElement).buttonset('refresh');
}
else {
textField.value = lField.value;
}
try {
var event = new Event("change");
textField.dispatchEvent(event);
} catch (e) {}
}
}
}
}
function updateCheckField(fld) {
var checkField = fld;
var textField = eval("checkField.form." + fld.name.substr(3));
if (checkField.checked) textField.value = 1;
else textField.value = 0;
try {
var event = new Event("change");
textField.dispatchEvent(event);
} catch (e) {}
}
// added by JH 18.12 to update our new lookup type
function updateGrid(pSelection) {
// get all of the children associated with this container
var parentWrapperChildren = pSelection.parentElement.children;
// unset the display class and radio significance
for (var i = 0; parentWrapperChildren.length > i; i++) {
if (parentWrapperChildren[i].nodeName == "LABEL")
parentWrapperChildren[i].classList.remove("selected");
if (parentWrapperChildren[i].nodeName == "INPUT")
parentWrapperChildren[i].setAttribute("significant", "false");
}
// reset the selection to be this value
pSelection.setAttribute("significant", "true");
document.getElementById(pSelection.id + "_label").classList.add("selected");
}
// added by JH 18.12 to update our new lookup type
function updateButtonSet(pSelection) {
// get all of the children associated with this container
var parentWrapperChildren = pSelection.parentElement.children;
// unset the display class and radio significance
for (var i = 0; parentWrapperChildren.length > i; i++) {
if (parentWrapperChildren[i].nodeName == "LABEL")
parentWrapperChildren[i].classList.remove("ui-state-active");
if (parentWrapperChildren[i].nodeName == "INPUT")
parentWrapperChildren[i].setAttribute("significant", "false");
}
// reset the selection to be this value
pSelection.setAttribute("significant", "true");
document
.getElementById(pSelection.id + "_label")
.classList.add("ui-state-active");
}
function onBeforePrint() {
// Show the new page
for (var i = 1; i < lastPage; i++) {
if (checkIfPageIsAllowed(i)) {
document.getElementById("Page" + i).style.display = "block";
}
}
// Hide the buttons
document.getElementById("button_submit").style.visibility = "hidden";
document.getElementById("button_next").style.visibility = "hidden";
document.getElementById("button_back").style.visibility = "hidden";
}
function onAfterPrint() {
// Hide all the pages except the current one
for (var i = 1; i < lastPage; i++) {
if (i == currentPage) {
} else {
document.getElementById("Page" + i).style.display = "none";
}
}
// Show the right buttons
hideShowButtons(currentPage);
}
function validateValidCurrency(targetField) {
var regXp = /^[-]?([1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|\.[0-9]{1,2})$/;
if (targetField.value.match(regXp)) return true;
else return false;
}
/**
function validateAjax(targetField){
var strReturn = "";
var lbValid = 0;
var parameters = "sys_Source=ajax"
for (var i=targetField.form.elements.length - 1; i>=0; i--){
parameters = parameters + "&" + targetField.form.elements[i].name + "=" + encodeURI(targetField.form.elements[i].value)
}
jQuery.ajax({
type: 'POST',
data: parameters,
url: '/matrix/' + targetField.eventobjectid + '?' + queryObjectID,
success:function(html){strReturn = html;lbValid=1},
error:function(x, e){strReturn = x.responseText;},
async:false
});
if (lbValid==1) return true;
else return false;
}
**/
// targetField is a validation rule object
function validateAjax(targetField) {
var strReturn = "";
var lbValid = 0;
var parameters = "sys_Source=ajax";
var lform = targetField.field.form;
for (var i = lform.elements.length - 1; i >= 0; i--) {
parameters =
parameters +
"&" +
lform.elements[i].name +
"=" +
encodeURI(lform.elements[i].value);
}
jQuery.ajax({
type: "POST",
data: parameters,
url: "/matrix/" + targetField.eventobjectid + "?" + queryObjectID,
success: function (html) {
// eval('validate' + targetField.Name + '()');
strReturn = html;
lbValid = 1;
if (targetField.async)
targetField.displayRow.className = "Form_Row_Valid";
},
error: function (x, e) {
strReturn = x.responseText;
},
async: targetField.async,
});
if (targetField.async) {
return false;
} else {
if (lbValid == 1) {
return true;
} else {
// As the validation is being done async return false until set in callback
return false;
}
}
}
function validateValidDate(targetField) {
var inyear = "";
var inmonth = "";
var inday = "";
var inmydate = targetField.value; // The input date should be in the format '19001231000000'
var ch = ""; // A var used to store a character from a string
inyear = inmydate.substr(0, 4);
inmonth = inmydate.substr(4, 2);
inday = inmydate.substr(6, 2);
inhour = inmydate.substr(8, 2);
inminute = inmydate.substr(10, 2);
insecond = inmydate.substr(12, 2);
// If no date specified assume it is OK
if (inmydate.length == 0) return true;
// Make sure the user has entered all of the date
if (inmydate.length != 14) return false;
// Check to make sure the user has only entered numbers
for (var i = 0; i < inmydate.length; i++) {
// Get this particular character from the date string
ch = inmydate.substring(i, i + 1);
// See if it is outside the valid range
if (ch < "0" || ch > "9") {
// tsch, no good.
return false;
}
}
// Check to make sure the user hasn't entered a day outside the number of days in the month
if (
parseInt(inday, 10) >
daysInMonth(parseInt(inmonth, 10), parseInt(inyear, 10)) ||
parseInt(inday, 10) < 1
)
return false;
if (parseInt(inmonth, 10) > 12 || parseInt(inmonth, 10) < 1) return false;
if (parseInt(inhour, 10) > 23 || parseInt(inhour, 10) < 0) return false;
if (parseInt(inminute, 10) > 59 || parseInt(inminute, 10) < 0) return false;
if (parseInt(insecond, 10) > 59 || parseInt(insecond, 10) < 0) return false;
// Check to make sure the user has entered a year
if (parseInt(inyear, 10) == 0) return false;
// Check bounds from datepicker
if (targetField.upperbounds && targetField.upperbounds.length > 0) {
arrayUpperBounds = targetField.upperbounds.split(",");
for (var i = 0; i < arrayUpperBounds.length; i++) {
upperBoundValue = document.getElementById("fld" + arrayUpperBounds[i])
.value;
if (upperBoundValue.length > 0 && targetField.value > upperBoundValue)
return false;
}
}
if (targetField.lowerbounds && targetField.lowerbounds.length > 0) {
arrayLowerBounds = targetField.lowerbounds.split(",");
for (var i = 0; i < arrayLowerBounds.length; i++) {
lowerBoundValue = document.getElementById("fld" + arrayLowerBounds[i])
.value;
if (lowerBoundValue.length > 0 && targetField.value < lowerBoundValue)
return false;
}
}
// Still Here?? - must be correct
return true;
}
function validateLength2(targetField) {
if (
targetField.value.length < parseInt(targetField.min) ||
targetField.value.length > parseInt(targetField.max)
) {
return false;
} else {
return true;
}
}
function validateRequired(targetField) {
if (targetField.value.length == 0) {
return false;
} else {
return true;
}
}
function validateSum(targetField) {
var fieldsArray = targetField.fields.split(",");
var runningTotal = parseInt(targetField.value);
for (var i = 0; i < fieldsArray.length; i++) {
runningTotal =
runningTotal +
parseInt(targetField.field.form.elements["fld" + fieldsArray[i]].value);
}
if (targetField.max) {
if (parseInt(runningTotal) > parseInt(targetField.max)) {
return false;
}
}
if (targetField.min) {
if (parseInt(runningTotal) < parseInt(targetField.min)) {
return false;
}
}
if (targetField.targetvalue) {
if (runningTotal == targetField.targetvalue) {
return false;
}
}
return true;
}
function validateRegExpr(targetField) {
var regXp = new RegExp(targetField.regxp);
if (regXp.test(targetField.value)) {
return true;
} else {
return false;
}
}
function validateJavaExpr(targetField) {
// Create some links to expose the field to the validation expression
this.field = targetField.field;
document.frmMain = targetField.field.form;
// Run the expression and see if it return true (i.e. valid)
if (eval(targetField.expr)) {
return true;
} else {
return false;
}
}
function validateValue(targetField) {
// If a field has been specified to test the date against use that instead of the system date
if (targetField.inrelationto) {
var sourceField =
targetField.field.form.elements["fld" + targetField.inrelationto].value;
// Check the value of this field as a percentage of the related value
var percIndex;
var thisValue = targetField.value;
if (targetField.min) {
var minVal = targetField.min;
minVal = parseFloat(minVal.substring(0, minVal.indexOf("%")));
if (thisValue < (minVal / 100) * parseFloat(sourceField)) {
return false;
}
}
if (targetField.max) {
var maxVal = targetField.max;
maxVal = parseInt(maxVal.substring(0, maxVal.indexOf("%")));
if (thisValue > (maxVal / 100) * parseFloat(sourceField)) {
return false;
}
}
} else {
if (targetField.max) {
if (parseInt(targetField.value) > parseInt(targetField.max)) {
return false;
}
}
if (targetField.min) {
if (parseInt(targetField.value) < parseInt(targetField.min)) {
return false;
}
}
if (targetField.targetvalue) {
if (targetField.value == targetField.targetvalue) {
return false;
}
}
}
return true;
}
function validateLength(targetField) {
if (targetField.max) {
if (parseInt(targetField.value.length) > parseInt(targetField.max)) {
return false;
}
}
if (targetField.min) {
if (
parseInt(targetField.value.length) < parseInt(targetField.min) &&
parseInt(targetField.value.length) > 0
) {
return false;
}
}
return true;
}
function validateValidURL(targetField) {
// If no data assume it is OK
if (targetField.value.length == 0) {
return true;
}
var regXp = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/;
var patt = new RegExp(regXp);
if (patt.test(targetField.value)) {
return true;
} else {
return false;
}
}
function validateValidEmailAddress(targetField) {
// If no data assume it is OK
if (targetField.value.length == 0) {
return true;
}
var regXp = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
if (targetField.value.match(regXp)) {
return true;
} else {
return false;
}
}
function validateValidPostCode(targetField) {
// If no data assume it is OK
if (targetField.value.length == 0) {
return true;
}
// Convert to upper case
targetField.value = targetField.value.toUpperCase();
// Removed as postcodes with 4 characters at start don't work e.g. "RH15" puts "R H15" RB - Dec 2015
// Check for no space
// if (targetField.value.indexOf(' ') < 0) {
// size = targetField.value.length
// if (size > 3) {
// targetField.value = targetField.value.substr(0,size-3) + " " + targetField.value.substr(size-3,size);
// }
// }
targetField.field.value = targetField.value;
var regXp = /^(((^[BEGLMNS][1-9]\d?)|(^W[2-9])|(^(A[BL]|B[ABDHLNRST]|C[ABFHMORTVW]|D[ADEGHLNTY]|E[HNX]|F[KY]|G[LUY]|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]|M[EKL]|N[EGNPRW]|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKL-PRSTWY]|T[ADFNQRSW]|UB|W[ADFNRSV]|YO|ZE)\d\d?)|(^W1[A-HJKSTUW0-9])|(^E1[W])|(((^WC[1-2])|(^EC[1-4])|(^SW1))[ABEHMNPRVWXY]))(\s){1}([0-9][ABD-HJLNP-UW-Z]{2}))$|(^GIR\s?0AA$)$/;
return targetField.value.match(regXp);
}
function validatePasswordComplexity(targetField) {
var regXp = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{4,8}$/;
if (targetField.value.match(regXp)) {
return true;
} else {
return false;
}
}
function getTodayAsMatrixDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
if (dd < 10) {
dd = "0" + dd;
}
if (mm < 10) {
mm = "0" + mm;
}
today = "" + yyyy + mm + dd + "000000";
return today;
}
function validateDateAge(targetField) {
// Declares
var minDate;
var maxDate;
var sourceDate;
// If a field has been specified to test the date against use that instead of the system date
if (targetField.inrelationto) {
if (
//targetField.form.elements["fld" + targetField.inrelationto].value
//.length == 0
targetField.field.form.elements["fld" + targetField.inrelationto].value
.length == 0
)
return true;
sourceDate =
//targetField.form.elements["fld" + targetField.inrelationto].value;
targetField.field.form.elements["fld" + targetField.inrelationto].value;
} else {
sourceDate = getTodayAsMatrixDate();
}
minDate = dateSubtract(sourceDate, targetField.min);
maxDate = dateSubtract(sourceDate, targetField.max);
minDate = "" + minDate;
maxDate = "" + maxDate;
minDate = minDate.substr(0, 8) + "000000";
maxDate = maxDate.substr(0, 8) + "000000";
if (
((targetField.value >= maxDate || targetField.max.length != 14) &&
(targetField.value <= minDate || targetField.min.length != 14)) ||
targetField.value.length == 0
) {
return true;
} else {
return false;
}
}
function validateFutureDate(targetField) {
var minDate;
var maxDate;
var sourceDate;
// If a field has been specified to test the date against use that instead of the system date
if (targetField.inrelationto) {
if (
targetField.field.form.elements["fld" + targetField.inrelationto].value
.length == 0
)
return true;
sourceDate =
targetField.field.form.elements["fld" + targetField.inrelationto].value;
} else {
sourceDate = getTodayAsMatrixDate();
}
minDate = dateAdd(sourceDate, targetField.min);
maxDate = dateAdd(sourceDate, targetField.max);
minDate = "" + minDate;
maxDate = "" + maxDate;
minDate = minDate.substr(0, 8) + "000000";
maxDate = maxDate.substr(0, 8) + "000000";
if (
((targetField.value <= maxDate || targetField.max.length != 14) &&
(targetField.value >= minDate || targetField.min.length != 14)) ||
targetField.value.length == 0
) {
return true;
} else {
return false;
}
}
function dateAdd(psDate1, psDate2) {
// Declares
var lsDate1 = psDate1,
lsDate2 = psDate2;
var liSecondsCarry = 0;
var liMinutesCarry = 0;
var liHoursCarry = 0;
var liDaysCarry = 0;
var liMonthsCarry = 0;
var liOverflow = 0;
var ldResult = "";
var ldPreResult;
var ldSec1, ldSec2, liTempSec;
var ldMin1, ldMin2, liTempMin;
var ldHour1, ldHour2, liTempHour;
var ldDay1, ldDay2, liTempDay;
var liDaysThisMonth;
var ldMonth1, ldMonth2, liTempMonth;
var ldYear1, ldYear2, liTempYear;
var liRemainingDays = 0;
// Check dates are of correct length
if (lsDate1.length != 14 || lsDate2.length != 14) return false;
// Add seconds
ldSec1 = parseInt(lsDate1.substr(12, 2), 10);
ldSec2 = parseInt(lsDate2.substr(12, 2), 10);
liTempSec = ldSec1 + ldSec2;
if (liTempSec > 59) {
liSecondsCarry = parseInt(liTempSec / 60);
liTempSec = liTempSec % 60;
}
liTempSec = "00" + liTempSec;
liTempSec = liTempSec.substr(liTempSec.length - 2, 2);
// Add minutes
ldMin1 = parseInt(lsDate1.substr(10, 2), 10);
ldMin2 = parseInt(lsDate2.substr(10, 2), 10);
liTempMin = ldMin1 + ldMin2 + liSecondsCarry;
if (liTempMin > 59) {
liMinutesCarry = parseInt(liTempMin / 60);
liTempMin = liTempMin % 60;
}
liTempMin = "00" + liTempMin;
liTempMin = liTempMin.substr(liTempMin.length - 2, 2);
// Add hours
ldHour1 = parseInt(lsDate1.substr(8, 2), 10);
ldHour2 = parseInt(lsDate2.substr(8, 2), 10);
liTempHour = ldHour1 + ldHour2 + liMinutesCarry;
if (liTempHour > 23) {
liHoursCarry = parseInt(liTempHour / 24);
liTempHour = liTempHour % 24;
}
liTempHour = "00" + liTempHour;
liTempHour = liTempHour.substr(liTempHour.length - 2, 2);
// Add days
liDaysThisMonth = daysInMonth(lsDate1.substr(4, 2), lsDate1.substr(0, 4));
ldDay1 = parseInt(lsDate1.substr(6, 2), 10);
ldDay2 = parseInt(lsDate2.substr(6, 2), 10);
liTempDay = ldDay1 + ldDay2 + liHoursCarry;
if (liTempDay > liDaysThisMonth) {
liDaysCarry = 1;
liRemainingDays = liTempDay - liDaysThisMonth - 1;
liTempDay = 1;
}
liTempDay = "00" + liTempDay;
liTempDay = liTempDay.substr(liTempDay.length - 2, 2);
// Add months
ldMonth1 = parseInt(lsDate1.substr(4, 2), 10);
ldMonth2 = parseInt(lsDate2.substr(4, 2), 10);
liTempMonth = ldMonth1 + ldMonth2 + liDaysCarry;
if (liTempMonth > 12) {
liMonthsCarry = parseInt(liTempMonth / 12);
liTempMonth = liTempMonth % 12;
}
liTempMonth = "00" + liTempMonth;
liTempMonth = liTempMonth.substr(liTempMonth.length - 2, 2);
// Add years
ldYear1 = parseInt(lsDate1.substr(0, 4), 10);
ldYear2 = parseInt(lsDate2.substr(0, 4), 10);
liTempYear = ldYear1 + ldYear2 + liMonthsCarry;
if (liTempYear > 9999) {
liOverflow = parseInt(liTempMonth / 9999);
liTempYear = liTempYear - liOverflow * 9999;
}
liTempYear = "0000" + liTempYear;
liTempYear = liTempYear.substr(liTempYear.length - 4, 4);
// Form results
ldResult = liTempYear + liTempMonth + liTempDay;
ldPreResult = liTempHour + liTempMin + liTempSec;
ldResult = ldResult + ldPreResult;
if (liRemainingDays > 0) {
liRemainingDays = "00" + liRemainingDays;
liRemainingDays = liRemainingDays.substr(liRemainingDays.length - 2, 2);
return dateAdd(ldResult, "000000" + liRemainingDays + "000000");
} else {
return ldResult;
}
}
function dateSubtract(psDate1, psDate2) {
// Declares
var lsDate1 = psDate1,
lsDate2 = psDate2;
var liSecondsCarry = 0;
var liMinutesCarry = 0;
var liHoursCarry = 0;
var liDaysCarry = 0;
var liMonthsCarry = 0;
var liOverflow = 0;
var ldResult = "";
var ldPreResult;
var ldSec1, ldSec2, liTempSec;
var ldMin1, ldMin2, liTempMin;
var ldHour1, ldHour2, liTempHour;
var ldDay1, ldDay2, liTempDay;
var liDaysThisMonth;
var ldMonth1, ldMonth2, liTempMonth;
var ldYear1, ldYear2, liTempYear;
var liRemainingDays = 0;
// Check dates are of the correct length
if (lsDate1.length != 14) return false;
if (lsDate2.length != 14) return false;
// Subtract seconds
ldSec1 = parseInt(lsDate1.substr(12, 2), 10);
ldSec2 = parseInt(lsDate2.substr(12, 2), 10);
liTempSec = ldSec1 - ldSec2;
if (liTempSec < 0) {
liSecondsCarry = 1;
liTempSec = 60 + liTempSec;
}
liTempSec = "00" + liTempSec;
liTempSec = liTempSec.substr(liTempSec.length - 2, 2);
// Subtract minutes
ldMin1 = parseInt(lsDate1.substr(10, 2), 10);
ldMin2 = parseInt(lsDate2.substr(10, 2), 10);
liTempMin = ldMin1 - ldMin2 - liSecondsCarry;
if (liTempMin < 0) {
liMinutesCarry = 1;
liTempMin = liTempMin + 60;
}
liTempMin = "00" + liTempMin;
liTempMin = liTempMin.substr(liTempMin.length - 2, 2);
// Subtract hours
ldHour1 = parseInt(lsDate1.substr(8, 2), 10);
ldHour2 = parseInt(lsDate2.substr(8, 2), 10);
liTempHour = ldHour1 - ldHour2 - liMinutesCarry;
if (liTempHour < 0) {
liHoursCarry = 1;
liTempHour = liTempHour + 24;
}
liTempHour = "00" + liTempHour;
liTempHour = liTempHour.substr(liTempHour.length - 2, 2);
// Subtract days
liDaysThisMonth = daysInMonth(lsDate1.substr(4, 2), lsDate1.substr(0, 4));
ldDay1 = parseInt(lsDate1.substr(6, 2), 10);
ldDay2 = parseInt(lsDate2.substr(6, 2), 10);
liTempDay = ldDay1 - ldDay2 - liHoursCarry;
if (liTempDay < 0) {
liDaysCarry = 1;
liTempDay = liTempDay + liDaysThisMonth;
}
liTempDay = "00" + liTempDay;
liTempDay = liTempDay.substr(liTempDay.length - 2, 2);
// Subtract months
ldMonth1 = parseInt(lsDate1.substr(4, 2), 10);
ldMonth2 = parseInt(lsDate2.substr(4, 2), 10);
liTempMonth = ldMonth1 - ldMonth2 - liDaysCarry;
if (liTempMonth < 0) {
liMonthsCarry = 1;
liTempMonth = liTempMonth + 12;
}
liTempMonth = "00" + liTempMonth;
liTempMonth = liTempMonth.substr(liTempMonth.length - 2, 2);
// Subtract years
ldYear1 = parseInt(lsDate1.substr(0, 4), 10);
ldYear2 = parseInt(lsDate2.substr(0, 4), 10);
liTempYear = ldYear1 - ldYear2 - liMonthsCarry;
if (liTempYear < 0) {
liOverflow = liTempYear;
liTempYear = 9999;
}
liTempYear = "0000" + liTempYear;
liTempYear = liTempYear.substr(liTempYear.length - 4, 4);
// Form the result
ldResult = liTempYear + liTempMonth + liTempDay;
ldPreResult = liTempHour + liTempMin + liTempSec;
ldResult = ldResult + ldPreResult;
// Return the result
return ldResult;
}
function daysInMonth(psMonth, psYear) {
var liMonth = parseInt(psMonth, 10);
var liYear = parseInt(psYear, 10);
// set liResult to the corresponding number of days
var months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Adjust for leap years
if (liYear % 4 != 0) months[1] = 28;
else months[1] = 29;
// Return result as integer
return parseInt(months[liMonth - 1], 10);
}
function validateField(field) {
field.blur;
var vReturn;
eval("vReturn = validate" + field + "();");
if (vReturn.length == 0) {
// Valid
eval(
'document.getElementById("frmParameter' +
field +
'").className="Form_Row_Valid";'
);
} else {
// Not Valid
eval(
'document.getElementById("frmParameter' +
field +
'").className="Form_Row_NotValid";'
);
}
}
function showFirstPagez(frm) {
// Declares
var targetPage = 1;
if (frm.fldSystemCurrentPage) {
// Get the target page
targetPage = parseInt(frm.fldSystemCurrentPage.value);
// If the value is bad set it to 1
if (isNaN(targetPage)) {
for (var i = 1; i <= lastPage; i++) {
if (checkIfPageIsAllowed(i) == true) {
targetPage = i;
break;
}
}
}
}
// Show the target page
showPage(targetPage);
}
var currentPage = 1;
function checkLastPagez() {
// Stop to next page operation if the form data is incomplete
if (isPageComplete(lastPage) == false) {
return false;
} else {
return true;
}
}
function hideShowButtonsz(newPage) {
//Show buttons in the default state
// Declares
var pagesAfter = false;
var pagesBefore = false;
// Loop through the pages before until the beginning
for (var i = newPage - 1; i >= 1; i--) {
if (checkIfPageIsAllowed(i) == true) {
pagesBefore = true;
break;
}
}
// Loop through the pages after until the end
for (var i = newPage + 1; i <= lastPage; i++) {
if (checkIfPageIsAllowed(i) == true) {
pagesAfter = true;
//break;
}
}
if (document.frmMain.elements["fldFinishButtonCaption"]) {
if (document.frmMain.elements["fldFinishButtonCaption"].value.length >= 0) {
document.getElementById("button_submit").value =
document.frmMain.elements["fldFinishButtonCaption"].value;
}
}
if (document.frmMain.elements["fldCancelButtonCaption"]) {
if (document.frmMain.elements["fldCancelButtonCaption"].value.length >= 0) {
document.getElementById("button_cancel").value =
document.frmMain.elements["fldCancelButtonCaption"].value;
document.getElementById("button_cancel").style.visibility = "visible";
} else {
document.getElementById("button_cancel").style.visibility = "hidden";
}
}
if (pagesBefore) {
// Somewhere inthe middle so show the back button
document.getElementById("button_back").style.visibility = "visible";
} else {
// At the first page so hide the back button
document.getElementById("button_back").style.visibility = "hidden";
}
if (pagesAfter) {
// More visible pages after this one
document.getElementById("button_submit").style.visibility = "hidden";
document.getElementById("button_next").style.visibility = "visible";
} else {
// At the last page so replace the next button with the finish button
document.getElementById("button_submit").style.visibility = "visible";
document.getElementById("button_next").style.visibility = "hidden";
}
}
function forceFocus(formControl) {
if (formControl.getAttribute("significant") == "true") {
try {
formControl.focus();
if (formControl.select) formControl.select();
return true;
} catch (e) {
return false;
}
} else return false;
}
function moveFocus(formControl, shiftAmount) {
// Declares
var lbFoundControl = false;
for (var i = 0; i < formControl.form.elements.length; i++) {
if (formControl.form.elements[i] == formControl) {
if (shiftAmount < 0) {
// Start with the previous control on this page and work backwards until we can set the focus
for (var j = i - 1; j >= 0; j--) {
if (
formControl.form.elements[j].getAttribute("wizardPage") ==
formControl.getAttribute("wizardPage")
) {
if (forceFocus(formControl.form.elements[j])) {
// Julian Mummery - 25th November 2011 - Fixes problem when trying to tab past a hidden element
if (
formControl.form.elements[j].offsetWidth == 0 &&
formControl.form.elements[j].offsetHeight == 0
) {
// Continue to next element as this one must be hidden!!!
} else {
lbFoundControl = true;
break;
}
}
}
}
// What to do if could not find a control to set focus to
if (!lbFoundControl && formControl.form.matrix_pagesBefore())
document.getElementById("button_back").onclick();
} else {
// Start with the next control on this page and work forwards until we can set the focus
for (var j = i + 1; j < formControl.form.elements.length; j++) {
if (
formControl.form.elements[j].getAttribute("wizardPage") ==
formControl.getAttribute("wizardPage")
) {
if (forceFocus(formControl.form.elements[j])) {
// Julian Mummery - 25th November 2011 - Fixes problem when trying to tab past a hidden element
if (
formControl.form.elements[j].offsetWidth == 0 &&
formControl.form.elements[j].offsetHeight == 0
) {
// Continue to next element as this one must be hidden!!!
} else {
lbFoundControl = true;
break;
}
}
}
}
// What to do if could not find a control to set focus to
if (!lbFoundControl) {
if (formControl.form.matrix_pagesAfter()) {
formControl.form.button_next.onclick();
} else {
formControl.form.button_submit.onclick();
}
}
}
}
}
}
// Make an ID to store how many dialog boxes we are up to
var tbox_id = 1;
// Hide and show the session timeout box
function tbox_show(AJAX_URL, tbox_name, options) {
//React Native
if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage("tbox_show");
}
// wg 11-12-2020 hide context menu if showing , was causing issues with new mobile context menu
$('#lContextMenu').hide()
// Create the first one
lobjDialogHolder = document.createElement("div");
lobjDialog = document.createElement("div");
lobjDialogContent = document.createElement("div");
if (document.top_tbdialog) {
// Already one open
lobjDialogHolder.top_tbdialog = document.top_tbdialog;
show_tbox_overlay(options.modal); // move infront of current tbox
} else {
// Add overlay to document
show_tbox_overlay(options.modal);
}
// Setup the dialog holder - this is the fullscreen wrapper that centers the dialog and handles the onClick event
//lobjDialogHolder.setAttribute("id","box_"+ tbox_id);
//lobjDialogHolder.setAttribute("name", tbox_name );
lobjDialogHolder.className = "tbox_holder";
lobjDialogHolder.style.zIndex = 260 + 2 * tbox_id;
// Setup the dialog div
lobjDialog.setAttribute("id", "box_" + tbox_id);
lobjDialog.setAttribute("name", tbox_name);
//lobjDialog.setAttribute("class", "tbox_window"); broken in ie7???
lobjDialog.className = "tbox_window";
// Setup the dialog content div
lobjDialogContent.setAttribute("class", "tbox_content");
// Setup the header
lobjDialogHeader = document.createElement("div");
lobjDialogHeader.setAttribute("class", "tbox_header");
// Setup the holder that loads the AJAX content
lobjAjaxHolder = document.createElement("div");
lobjAjaxHolder.setAttribute("class", "tbox_ajax_content");
lobjAjaxHolder.setAttribute("id", "box_" + tbox_id + "_content");
// Apply Any Display Options
if (options.width) {
// lobjDialog.style.width = options.width + "px";
// marginLeft = (options.width / 2) * (-1);
// lobjDialog.style.marginLeft = marginLeft + "px";
lobjDialog.style.minWidth = options.width + "px";
}
if (options.height) {
lobjDialogContent.style.Height = options.height + "px";
if (options.height > 500) lobjDialog.style.top = "10%"; // reduce top spacing (default = 20%)
}
if (options.modal !== true) {
// Non-modal popup (show close button etc.)
lobjDialogHeader.innerHTML =
"×
" +
tbox_name +
"
";
} else {
lobjDialogHeader.innerHTML =
"
" + tbox_name + "
";
}
// Prevent the window in the background from scrolling
$(window).scroll(function () {
return false;
});
// Show
lobjDialog.appendChild(lobjDialogHeader);
lobjDialog.appendChild(lobjDialogContent);
lobjDialogContent.appendChild(lobjAjaxHolder);
lobjDialogHolder.appendChild(lobjDialog);
document.body.appendChild(lobjDialogHolder);
if (options.modal !== true) {
//SW 27/05/2022: Changed onclick to onmousedown
//lobjDialogHolder.setAttribute("onclick", "tbox_close()");
lobjDialogHolder.setAttribute("onmousedown", "if(event.matrixBubbleFromDialog!=true) {tbox_close()}");
// lobjDialog.setAttribute(
// "onclick",
// "if(event.stopPropagation){event.stopPropagation();}event.cancelBubble=true;"
// );
lobjDialog.setAttribute(
"onmousedown",
// "if(event.stopPropagation){event.stopPropagation();}event.cancelBubble=true;"
"event.matrixBubbleFromDialog=true;"
);
}
// Get the overlay node
//lobjOverlay = document.getElementById("tbox_overlay")
//lobjOverlay.appendChild(lobjDialog);
// Get content for Dialog
ajax_makeRequest(AJAX_URL, "box_" + tbox_id + "_content");
// Increment identifier
tbox_id++;
// Set the new foremost Dialog
document.top_tbdialog = lobjDialogHolder;
}
function tbox_close(callback) {
var unloadMessage = "";
//React Native
if (window.ReactNativeWebView) {
window.ReactNativeWebView.postMessage("tbox_close");
}
//close any select 2s that are open
// SW 23/05/2023: Added to fix issue where select2 dropdown didn't close when closing tbox
if($('.select2-hidden-accessible')) {
$('.select2-hidden-accessible').select2('close');
}
// Show warning message - don't continue if cancelled
if (top.document.unloadMessage) {
unloadMessage = top.document.unloadMessage;
if (unloadMessage.length > 0) {
if (document.frmMain) {
if (document.frmMain.matrix_hasChanged()) {
if (!confirm(unloadMessage + "\n\nAre you sure?")) return;
}
}
}
}
// Clear message
top.document.unloadMessage = "";
// Try to remove any old thickbox
try {
tb_remove();
} catch (err) {
}
if (top.document.top_tbdialog) {
lobjMostHighdialog = top.document.top_tbdialog;
top.document.top_tbdialog = lobjMostHighdialog.top_tbdialog;
lobjParentNode = lobjMostHighdialog.parentNode;
lobjParentNode.removeChild(lobjMostHighdialog);
}
if (top.document.top_tbdialog) {
// still got at least one left after removal
// Make sure the overlay is behind the thickbox
document.getElementById("tbox_overlay").style.zIndex =
top.document.top_tbdialog.style.zIndex - 1;
// Restore unload message
top.document.unloadMessage = unloadMessage;
// Decrement the ID
tbox_id--;
} else {
// None left - remove overlay
$(window).unbind("scroll");
hide_tbox_overlay();
// Reset the ID
tbox_id = 1;
}
// Check for callback function
if (typeof callback == "function") callback();
}
// Show tbox overlay
// This function shows the translucent grey mask behind the tbox
function show_tbox_overlay(lbmodal) {
if (document.getElementById("tbox_overlay") == null) {
// Doesn't currently exist in DOM
lobjOverlay = document.createElement("div");
lobjOverlay.setAttribute("id", "tbox_overlay");
// Click to close
//if (lbmodal !== true) lobjOverlay.setAttribute("onclick", "tbox_close()");
//SW 27/05/2022: Changed onclick to onmousedown
if (lbmodal !== true) lobjOverlay.setAttribute("onmousedown", "tbox_close()");
// Add to DOM
document.body.appendChild(lobjOverlay);
// Add class to say we have an overlay - this allows us to do blur etc.
// document.body.classList.add("hasPopup"); // Changed to HTML element so we have more control over scrolling when popup is visible
document.documentElement.classList.add("hasPopup");
} else {
// Secondary box opened - move overlay forwards in Z index
document.getElementById("tbox_overlay").style.zIndex =
260 + 2 * tbox_id - 1;
}
}
// Hide tbox overlay
// Removes the translucent grey mask from DOM
function hide_tbox_overlay() {
var lobjOverlay = document.getElementById("tbox_overlay");
if (lobjOverlay != null) {
lobjParentNode = lobjOverlay.parentNode;
lobjParentNode.removeChild(lobjOverlay);
// Remove class to say we have an overlay - this allows us to do blur etc.
//document.body.classList.remove("hasPopup");
document.documentElement.classList.remove("hasPopup");
}
}
// Calls Get Messages event
function checkConnection() {
// Check if the user is still logged in
// ajax_makeRequest("/data/E32674AF-1080-47DC-9D82-D9FD50C8517C?E32674AF-1080-47DC-9D82-D9FD50C8517C&" + sys_sessionID, "ajax_messaging");
// Using this version as ajax_makeRequest seems to have problems with concurrent requests
jQuery.ajax({
type: "GET",
url:
"/data/E32674AF-1080-47DC-9D82-D9FD50C8517C?E32674AF-1080-47DC-9D82-D9FD50C8517C&" +
sys_sessionID +
"&" +
matrix.generateViewportToken() +
"&" +
matrix.generateSessionToken(),
success: function (data) {
$("#ajax_messaging").html(data).show();
},
});
}
$(document).ready(function () {
if (sys_sessionID) {
var ajax_messaging_timeout;
var ajax_messaging_interval;
// Run get messages now and every 30 seconds thereafter
if (top == self) {
lobjAjaxMessage = document.createElement("div");
lobjAjaxMessage.setAttribute("id", "ajax_messaging");
lobjAjaxMessage.setAttribute("style", "display:none;");
document.body.appendChild(lobjAjaxMessage);
ajax_messaging_timeout = setTimeout("checkConnection()", 750);
ajax_messaging_interval = setInterval("checkConnection()", 30000);
}
}
$.ajaxSetup({
error: function (x, e) {
if (x.status == 0) {
//alert('Unable to Connect!\n Please Check Your Internet Conenction.');
} else if (x.status == 400) {
//alert(x.responseText.replace(" ","\n"));
} else if (x.status == 404) {
//alert('Requested URL not found.');
} else if (x.status == 500) {
//alert('Internel Server Error.');
} else if (e == "parsererror") {
//alert('Error.nParsing JSON Request failed.');
} else if (e == "timeout") {
//alert('Request Time out.');
} else {
//alert('Unknown Error');
}
},
});
});
$.fn.m_load = function (pURL) {
return $(this).each(function () {
$(this).attr("data-url", pURL);
$(this).css("cursor", "wait");
$(this).css("position", "relative");
$("#message", this).remove();
$("#overlay", this).remove();
$(this).append('');
$(this).append(
"
"
);
$(this).load(pURL, function (response, status, xhr) {
$(this).css("cursor", "auto");
if (status == "error") {
if (xhr.getResponseHeader("X-Error-Message")) {
var msg =
"
Request has failed
" +
xhr.getResponseHeader("X-Error-Message") +
"
";
} else {
var msg = "
Request has failed - " + xhr.statusText + "
";
}
msg =
msg +
"Retry ...";
$(this).find("#message").html(msg);
} else {
$(this).find("#overlay").remove();
$(this).find("#message").remove();
}
});
});
};
// Set a cookie on the browser
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
// Read a cookie on the browser
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == " ") c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
/**************** Graph Module (See PW Bookings) ******************/
function draw_AssetScheduleGraph01(date, reportstore, element, mapelement) {
var url =
"/matrix/C292D14F-3454-4908-909F-DC2144C92573?" +
reportstore +
"&" +
date +
"&" +
element +
"&" +
mapelement;
$.get(url, function (data) {
$("#" + element).html(data);
});
}
// Generating the image map
function processMapData(json) {
var obj = JSON.parse(json);
var objLength = obj.chartshape.length;
var res = "";
return res;
}
/*****************************************************************/
function addSource(ev, targetObjectID, ParameterName, inputID) {
/* needs to update the sources in the query and redraw the page/refresh the query so that new filter and sort xml can be generated*/
/* get the sources element*/
var elSources = document.getElementById(inputID);
/* get the current sources value*/
var lsCurrentSources = elSources.value;
/* get the dragged data*/
var draggedData = ev.dataTransfer.getData("Text");
/* check we have some data*/
if (draggedData != undefined) {
/* check the data is the right length to be an objectID*/
if (draggedData.length == 73 || draggedData.length == 36) {
/* get the object id from the data*/
if (draggedData.indexOf("&") != -1) {
draggedData = draggedData.split("&")[0];
}
/* check to see if we already have the item*/
if (lsCurrentSources.indexOf(draggedData) != -1) {
/* we already have the item so alert the user*/
alert("You have already added this item to the list of sources");
} else {
/*add the new source to the current sources*/
elSources.value = lsCurrentSources + draggedData + ",";
}
} else {
/* alert the user that the current item cannot be added to the sources*/
alert("Sorry this item cannot be added as a source");
}
} else {
/* alert the user that the current item cannot be added to the sources*/
alert("Sorry this item cannot be added as a source");
}
elSources.form.matrix_refreshPage();
ev.returnValue = false;
}
function removeSource(psObjectId, inputID) {
/* get the sources element*/
var elSources = document.getElementById(inputID);
/* get the current sources*/
var lsCurrentSources = elSources.value;
/* find the position of the id to be removed*/
var liIdPos = lsCurrentSources.indexOf(psObjectId);
/* check we have the id and remove it from the sources*/
if (lsCurrentSources.indexOf(psObjectId) != -1) {
lsObjectId = psObjectId + ",";
elSources.value = lsCurrentSources.replace(lsObjectId, "");
}
/* save and redraw the current page*/
elSources.form.matrix_refreshPage();
return false;
}
function updateTextValue(pelObjectRoot, psInputID, psTextID, psValueLocation) {
switch ($(pelObjectRoot).val()) {
case "all":
document.getElementById(psInputID).value = "";
break;
default:
document.getElementById(psInputID).value =
psValueLocation +
$(pelObjectRoot).val() +
"_" +
$("#" + psTextID).val();
break;
}
}
function updateObjectValues(pelMasterSwitchObject, pelRootObject, psInputID) {
var lbAllChildrenChecked = true;
var lsValues = "";
var liChildrenUnchecked = 0;
childCheckboxes = pelRootObject.getElementsByTagName("input");
for (var j = 0; j < childCheckboxes.length; j++) {
if (childCheckboxes[j].checked) {
lsValues = lsValues + $(childCheckboxes[j]).val() + ",";
} else {
lbAllChildrenChecked = false;
liChildrenUnchecked++;
}
}
if (lbAllChildrenChecked || liChildrenUnchecked == childCheckboxes.length) {
document.getElementById(psInputID).value = "";
} else {
document.getElementById(psInputID).value = lsValues;
}
}
/* Bind this to the on change of a master object filter switch on change */
function updateChildObjectValues(pelMasterSwitch, pelRootObject, psInputID) {
/* Get the child check boxes */
childCheckboxes = pelRootObject.getElementsByTagName("input");
/* Loop through all the child check boxes and (un)check them */
for (var j = 0; j < childCheckboxes.length; j++) {
/* Check if we need to check the boxes or unchecked them */
if (pelMasterSwitch.checked) {
/* Check the current child */
childCheckboxes[j].checked = true;
} else {
/* Uncheck the current child */
childCheckboxes[j].checked = false;
}
}
/* Update the stored values to blank as either way we are not filtering by anything yet */
document.getElementById(psInputID).value = "";
}
function checkThis(pElem) {
pElem.checked = true;
}
function updateNumberValue(psName, psValueLocation) {
var liMin = document.getElementById("min_" + psName).value;
var liMax = document.getElementById("max_" + psName).value;
document.getElementById("fld" + psName).value =
psValueLocation + "min_" + liMin + ",max_" + liMax;
}
function updateRangeType(pelemSelect, psName, psValueLocation) {
switch ($(pelemSelect).val()) {
case "any":
document.getElementById("min_" + psName).value = "";
document.getElementById("max_" + psName).value = "";
$("#min_" + psName).hide();
$("#max_" + psName).hide();
$("#dash_" + psName).hide();
break;
case "morethan":
document.getElementById("min_" + psName).value = "";
$("#min_" + psName).show();
$("#max_" + psName).hide();
$("#dash_" + psName).hide();
break;
case "lessthan":
document.getElementById("max_" + psName).value = "";
$("#min_" + psName).hide();
$("#max_" + psName).show();
$("#dash_" + psName).hide();
break;
case "range":
$("#min_" + psName).show();
$("#max_" + psName).show();
$("#dash_" + psName).attr("style", "display:inline");
break;
default:
// do nothing
break;
}
updateNumberValue(psName, psValueLocation);
}
function updateDateValue(pelObjectRoot, psInputID, psName, psValueLocation) {
switch ($(pelObjectRoot).val()) {
case "all":
document.getElementById(psInputID).value = "";
break;
case "custom":
var lsMin = "";
var lsMax = "";
var lsNewValue = "";
lsMin = document.getElementById("fldMin_" + psName).value;
lsMax = document.getElementById("fldMax_" + psName).value;
if (lsMax.length > 0) {
lsNewValue = lsNewValue + "max_" + lsMax + ",";
}
if (lsMin.length > 0) {
lsNewValue = lsNewValue + "min_" + lsMin + ",";
}
document.getElementById(psInputID).value = psValueLocation + lsNewValue;
break;
default:
document.getElementById(psInputID).value =
psValueLocation + $(pelObjectRoot).val();
break;
}
}
function updateCheckFilterValue(pInput, psElementValueID) {
var lsValue = pInput.value;
if (pInput.checked) {
document.getElementById(psElementValueID).value = lsValue;
}
}
// Check if the user device is touch
// the double exclamation forces a boolean rather than 'undefined'
function isTouch() {
return "ontouchstart" in window || !!navigator.msMaxTouchPoints;
}
/***************************************************************************/
/*! jQuery UI - Core - v1.10.4
* http://jqueryui.com
* Copyright jQuery Foundation and other contributors; Licensed MIT */
(function ($, undefined) {
var uuid = 0,
runiqueId = /^ui-id-\d+$/;
// $.ui might exist from components with no dependencies, e.g., $.ui.position
$.ui = $.ui || {};
$.extend($.ui, {
version: "1.10.4",
keyCode: {
BACKSPACE: 8,
COMMA: 188,
DELETE: 46,
DOWN: 40,
END: 35,
ENTER: 13,
ESCAPE: 27,
HOME: 36,
LEFT: 37,
NUMPAD_ADD: 107,
NUMPAD_DECIMAL: 110,
NUMPAD_DIVIDE: 111,
NUMPAD_ENTER: 108,
NUMPAD_MULTIPLY: 106,
NUMPAD_SUBTRACT: 109,
PAGE_DOWN: 34,
PAGE_UP: 33,
PERIOD: 190,
RIGHT: 39,
SPACE: 32,
TAB: 9,
UP: 38,
},
});
// plugins
$.fn.extend({
focus: (function (orig) {
return function (delay, fn) {
return typeof delay === "number"
? this.each(function () {
var elem = this;
setTimeout(function () {
$(elem).focus();
if (fn) {
fn.call(elem);
}
}, delay);
})
: orig.apply(this, arguments);
};
})($.fn.focus),
scrollParent: function () {
var scrollParent;
if (
($.ui.ie && /(static|relative)/.test(this.css("position"))) ||
/absolute/.test(this.css("position"))
) {
scrollParent = this.parents()
.filter(function () {
return (
/(relative|absolute|fixed)/.test($.css(this, "position")) &&
/(auto|scroll)/.test(
$.css(this, "overflow") +
$.css(this, "overflow-y") +
$.css(this, "overflow-x")
)
);
})
.eq(0);
} else {
scrollParent = this.parents()
.filter(function () {
return /(auto|scroll)/.test(
$.css(this, "overflow") +
$.css(this, "overflow-y") +
$.css(this, "overflow-x")
);
})
.eq(0);
}
return /fixed/.test(this.css("position")) || !scrollParent.length
? $(document)
: scrollParent;
},
zIndex: function (zIndex) {
if (zIndex !== undefined) {
return this.css("zIndex", zIndex);
}
if (this.length) {
var elem = $(this[0]),
position,
value;
while (elem.length && elem[0] !== document) {
// Ignore z-index if position is set to a value where z-index is ignored by the browser
// This makes behavior of this function consistent across browsers
// WebKit always returns auto if the element is positioned
position = elem.css("position");
if (
position === "absolute" ||
position === "relative" ||
position === "fixed"
) {
// IE returns 0 when zIndex is not specified
// other browsers return a string
// we ignore the case of nested elements with an explicit value of 0
//