/*----------------------------------------------------------------------------- | | | shared.js | | | | Think Computer Corporation | | Shared JavaScript Library | | | | Copyright © 2001-2012 Think Computer Corporation. All Rights Reserved. | | | -----------------------------------------------------------------------------*/ if (! ('console' in window)) window.console = { log: function(){}, dir: function(){} }; // Rollovers function flip(image, vertical) { image.style.backgroundPosition='0px ' + vertical + 'px'; } // DIV Visibility function ID(id) { return document.getElementById(id) } function showID(id) { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById(id).style.display = 'block'; } else { if (document.layers) { // Netscape 4 document.id.display = 'block'; } else { // IE 4 document.all.id.style.display = 'block'; } } } function hideID(id) { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById(id).style.display = 'none'; } else { if (document.layers) { // Netscape 4 document.id.display = 'none'; } else { // IE 4 document.all.id.style.display = 'none'; } } } function hideIDs(prefix, count, start) { for (var i = start; i < start + count; i++) { hideID(prefix + i); } } function showTR(id) { if (document.getElementById) { // DOM3 = IE5, NS6; IE7 doesn't know what a table row is. document.getElementById(id).style.display = (navigator.appName == "Microsoft Internet Explorer" ? 'block' : 'table-row'); } else { if (document.layers) { // Netscape 4 document.id.display = 'table-row'; } else { // IE 4 document.all.id.style.display = 'table-row'; } } } function hideTR(id) { if (document.getElementById) { // DOM3 = IE5, NS6 if (document.getElementById(id)) document.getElementById(id).style.display = 'none'; } else { if (document.layers) { // Netscape 4 if (document.id) document.id.display = 'none'; } else { // IE 4 if (document.all.id) document.all.id.style.display = 'none'; } } } // People function switchProfile(index) { $.get(handler, { "method": "switchProfile", "profileid": index }, function(reply) { if (reply.error) { alert(reply.error) } else { document.location.reload(); } }); } function amendShareList(data, lineid) { if (!data) return false; $.post(handler + '?method=amendShareList', data, function(reply) { if (reply && reply.id && parseInt(reply.id)) { $('#shareList').append(reply.html); } else { alert(data.display + ' is already in the list.'); } }); } function redactShareList(rel) { var arr = rel.split(';'); $.post(handler + '?method=redactShareList', { type: arr[0], id: arr[1] }, function(reply) { if (parseInt(reply + 1)) { $('#shareItem' + parseInt(reply)).remove(); } }); } function selectPerson(li, field, path) { var index = document.forms[1].elements[field + 'Index'].value; document.getElementById(field + 'Results').innerHTML += '
'; document.getElementById(field).value = ''; document.forms[1].elements[field + 'Count'].value++; document.forms[1].elements[field + 'Index'].value++; } function digestPerson(box, event, field) { if (event.keyCode == 13 && box.value != '') { var url = shared + 'javascript/handler.js?method=digestPerson'; var data = {'q': box.value}; $.get(url, data, function(reply) { if (! reply.id) { alert('Please type in a phrase for your tag that is at least three characters long.'); } else { var li = {'selectValue': box.value, 'extra': new Array(1)} li.extra[0] = reply.id; selectPerson(li, field, 'contacts') } }); } } function deletePendingPerson(index, field) { document.getElementById(field + index).innerHTML = ''; } function deleteExistingPerson(index, linkTable) { var url = shared + 'javascript/handler.js?method=deleteTag'; var data = {'id': id, 'l': linkTable, 'index': index}; $.post(url, data, function(reply) { if (! reply) { alert('There was no response from the server.'); } else if (reply.error) { alert(reply.error); } else { deletePendingTag(index); } }); } function makeConnections(id, myid) { initDialog(); $('#connect').show(); } // Products // versionElement: ID of the TR element and also name of the element that contains the dropdown for the versions of the product // onchange: onchange content of the dropdown function updateProduct(formName, productid, versionid, description, versionElement, onchange) { if (document.forms[formName].product) { document.forms[formName].product.value = description; } var params = { 'productid': productid, 'versionid': versionid, 'versionElement': versionElement, 'onchange': onchange }; $.get(handler + '?method=productVersions', params, function(reply) { // note: versionElement is used as an ID here, whereas at the same time, it's used as the name for the dropdown in productVersions document.getElementById(versionElement).cells[1].innerHTML = reply; showTR(versionElement); }); } // Confirmation Dialogs function deleteRecord(phpself, id) { if (confirm("Are you sure you want to delete this record?")) { window.location = phpself + '?delete=1&' + id; } } function actOnRecords(action, tableName, formName) { if (confirm('Are you sure you want to ' + action + ' the selected records?')) { document.forms[formName].elements['table'].value = tableName; document.forms[formName].elements['button'].value = action; document.forms[formName].submit(); } } function invertRecords(formName, hiddenField) { var count = 0, undefined; if (hiddenField != undefined){ $('input[name^="' + hiddenField + '"]').each(function(){ if (parseInt($(this).val()) > 0) count++ }); } if (count == 0 && hiddenField != undefined){ alert('You must select items to invert first.'); } else if (confirm("Are you sure you want to invert the selected records?")) { document.forms[formName].button.value = 'invert'; document.forms[formName].submit(); } } function copyRecords(formName, hiddenField) { var count = 0, undefined; if (hiddenField != undefined) { $('input[name^="' + hiddenField + '"]').each(function() { if (parseInt($(this).val()) > 0) count++ }); } if (count == 0 && hiddenField != undefined){ alert('You must select items to copy first.'); } else if (confirm("Are you sure you want to copy the selected records?")) { document.forms[formName].button.value = 'copy'; document.forms[formName].submit(); } } function updateRecords(formName) { document.forms[formName].button.value = 'update'; document.forms[formName].submit(); } function doneRecords(formName) { if (confirm("Are you sure you want to mark the selected records as done?")) { document.forms[formName].button.value = 'done'; document.forms[formName].submit(); } } function checkEntityBox(box, field, e) { if (box.value.length > 1) { if (e.explicitOriginalTarget != undefined) { // Firefox has a convenient event attribute that tells you what set of the blur event var clickedOnList = e == 1 ? true : e.explicitOriginalTarget.parentElement.className == 'auto-complete-list' || e.explicitOriginalTarget.parentElement.parentElement.className == 'auto-complete-list'; } else { // IE, Chrome and Safari get to use this ungodly hack instead. var clickedOnList = document.activeElement.innerHTML.indexOf('auto-complete-list-rollover') != -1; } // No Entity ID in the hidden field, not coming from a direct click, and not triggered from an onBlur event just before that same click if (ID(field).value == '' && e != 1 && ! clickedOnList) { box.style.cssText = "border: #FFD0D0 solid 1px; background: url('" + static + "images/loading2.gif') right no-repeat; background-color: #FFF0F0; padding-right: 2px;"; $.get(handler, { 'method': 'checkEntityBox', 'field': field, 'value': box.value }, function(reply) { if (reply.error) { alert(reply.error); } else if (reply) { ID(field + 'dialog').innerHTML = reply; $('#' + field + 'dialog').dialog('destroy'); box.style.cssText = "border: #FFD0D0 solid 1px; background-color: #FFF0F0;"; $('#' + field + 'dialog').dialog({ 'title': 'Entity Search', 'modal': true, 'width': 540, 'height': 360, buttons: { Cancel: function() { $(this).dialog('close'); } }, close: function(event, ui) { // Reset the dialog's DIV ID(field + 'dialog').innerHTML = ''; // Do what would have happened if the proper entity were selected fixEntityBox('', '', field); if (ID(field).value == '') { // Still nothing selected ID(field + 'Display').value = ''; box.style.cssText = ''; } } }); } }); } else { box.style.cssText = 'border: #A0D0A0 solid 1px; background-color: #F0FFF0;'; } } } function entityEnter(box, field, e) { if (e.keyCode == 13) { checkEntityBox(box, field, e); $('.auto-complete-list').hide(); return false; } } function fixEntityBox(entityid, value, field) { $('.auto-complete-list').hide(); if (entityid) { ID(field + 'Display').value = value ID(field).value = entityid; } eval(field + 'Select();'); if (entityid) $('#' + field + 'dialog').dialog('close'); } function checkTagBox(box, field, e) { if (box.value.length > 1) { if (e.explicitOriginalTarget != undefined) { // Firefox has a convenient event attribute that tells you what set of the blur event var clickedOnList = e == 1 ? true : e.explicitOriginalTarget.parentElement.className == 'auto-complete-list' || e.explicitOriginalTarget.parentElement.parentElement.className == 'auto-complete-list'; } else { // IE, Chrome and Safari get to use this ungodly hack instead. var clickedOnList = document.activeElement.innerHTML.indexOf('auto-complete-list-rollover') != -1; } // No Entity ID in the hidden field, not coming from a direct click, and not triggered from an onBlur event just before that same click if (ID(field).value == '' && e != 1 && ! clickedOnList) { box.style.cssText = "border: #FFD0D0 solid 1px; background: url('" + static + "images/loading2.gif') right no-repeat; background-color: #FFF0F0; padding-right: 2px;"; $.get(handler, { 'method': 'checkTagBox', 'field': field, 'value': box.value }, function(reply) { if (reply.error) { alert(reply.error); } else if (reply) { ID(field + 'dialog').innerHTML = reply; $('#' + field + 'dialog').dialog('destroy'); box.style.cssText = "border: #FFD0D0 solid 1px; background-color: #FFF0F0;"; $('#' + field + 'dialog').dialog({ 'title': 'Tag Search', 'modal': true, 'width': 540, 'height': 360, buttons: { Cancel: function() { $(this).dialog('close'); } }, close: function(event, ui) { // Reset the dialog's DIV ID(field + 'dialog').innerHTML = ''; // Do what would have happened if the proper entity were selected fixEntityBox('', '', field); if (ID(field).value == '') { // Still nothing selected ID(field + 'Display').value = ''; box.style.cssText = ''; } } }); } }); } else { box.style.cssText = 'border: #A0D0A0 solid 1px; background-color: #F0FFF0;'; } } } function fixTagBox(tagid, value, field) { $('.auto-complete-list').hide(); if (tagid) { ID(field + 'Display').value = value ID(field).value = entityid; } eval(field + 'Select();'); if (tagid) $('#' + field + 'dialog').dialog('close'); } function tagEnter(box, field, e) { if (e.keyCode == 13) { checkTagBox(box, field, e); $('.auto-complete-list').hide(); return false; } } // Pop-Up Windows function openWindow(path, name, width, height, format) { window.open(path, name, "width=" + width + ",height=" + height + "," + format); } // List Boxes function changeSequence(list, to) { var index = list.selectedIndex; var total = list.options.length - 1; if (index == -1) return false; if (to == +1 && index == total) return false; if (to == -1 && index == 0) return false; var items = new Array; var values = new Array; for (i = 0; i <= total; i++) { items[i] = list.options[i].text; values[i] = list.options[i].value; } for (i = 0; i <= total; i++) { list.options[i] = new Option(items[i], values[i]); } list.options[index + to] = new Option(items[index], values[index], 0, 1); list.options[index] = new Option(items[index + to], values[index + to]); list.focus(); } function selectAll(list, value) { for (i = 0; i <= list.options.length - 1; i++) { list.options[i].selected = value; } } // Tabs function showTab(tabGroup, tabName) { var location = 0; var src = ''; if (! tabs) tabs = [[], []]; // Locate ourself in the row - used to test if we need to change right/left ends for (i = 0; i < tabs[0].length; i++) { // Reset all tabs to unselected tabs[1][i] = 2; if (tabs[0][i] == tabName) { tabs[1][i] = 1; location = i; } document.getElementById(tabGroup + 'panel' + i).style.backgroundColor = tabs[1][i] == 3 ? '#FF0000' : '#606060'; document.getElementById(tabGroup + tabs[0][i]).style.display = 'none'; } // Left End if (tabs[1][0] == 3) { document.getElementById(tabGroup + 'leftend').style.backgroundColor = '#FF0000'; } else if (location != 0) { document.getElementById(tabGroup + 'leftend').style.backgroundColor = '#606060'; } else { document.getElementById(tabGroup + 'leftend').style.backgroundColor = '#404040'; } // Right End if (tabs[1][tabs[0].length - 1] == 3) { document.getElementById(tabGroup + 'rightend').src = static + "tabs/rightend3.gif"; } else if (location != (tabs[0].length - 1)) { document.getElementById(tabGroup + 'rightend').src = static + "tabs/rightend2.gif"; } else { document.getElementById(tabGroup + 'rightend').src = static + "tabs/rightend1.gif"; } // Intersections. 2 sides per word - 2 outside ends / 2 var intersections = ((tabs[0].length * 2) - 2) / 2; // Just choose selected ones for (i = 0; i < intersections; i++) { var tab1Color = tabs[1][i] != 3 ? 2 : 3; var tab2Color = i + 1 < tabs[0].length ? tabs[1][i + 1] : false; // Basically, because red is the color for selected AND deselected tabs, we run into this weird naming issue. if (tab1Color == 2 && tab2Color == 3) tab2Color = '3a'; document.getElementById(tabGroup + 'intersection' + i).src = static + "tabs/intersection" + tab1Color + "-" + tab2Color + ".gif"; } // Swap var previousColor = tabs[1][location - 1] == 3 ? 3 : 2; var activeColor = tabs[1][location] == 3 ? 3 : 1; var nextColor = tabs[1][location + 1] == 3 ? 3 : 2; if (location > 0) { document.getElementById(tabGroup + 'intersection' + (location - 1)).src = static + "tabs/intersection" + previousColor + "-" + (activeColor == 3 && previousColor != 3 ? '3b' : activeColor) + ".gif"; if (location < intersections) document.getElementById(tabGroup + 'intersection' + location).src = static + "tabs/intersection" + activeColor + "-" + nextColor + ".gif"; } else { document.getElementById(tabGroup + 'intersection0').src = static + "tabs/intersection" + activeColor + "-" + nextColor + ".gif"; } document.getElementById(tabGroup + 'panel' + location).style.backgroundColor = tabs[1][location] == 3 ? '#FF0000' : '#404040'; document.getElementById(tabGroup + tabName).style.display = 'block'; } // Flash / IE Legal Workaround // Copyright 2006 Adobe Systems, Inc. All rights reserved. Modified by Think Computer Corporation. function AC_Generateobj(objAttrs, params, embedAttrs) { var str = ''; document.write(str); } function AC_FL_RunContent() { var ret = AC_GetArgs(arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash"); AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs); } function AC_SW_RunContent() { var ret = AC_GetArgs(arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000", null); AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs); } function AC_GetArgs(args, ext, srcParamName, classid, mimeType) { var ret = new Object(); ret.embedAttrs = new Object(); ret.params = new Object(); ret.objAttrs = new Object(); for (var i = 0; i < args.length; i = i+2) { var currArg = args[i].toLowerCase(); switch (currArg) { case "classid": break; case "pluginspage": ret.embedAttrs[args[i]] = args[i+1]; break; case "src": case "movie": ret.embedAttrs["src"] = args[i+1]; ret.params[srcParamName] = args[i+1]; break; case "type": case "codebase": ret.objAttrs[args[i]] = args[i+1]; break; case "width": case "height": case "tabindex": ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1]; break; default: ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1]; } } ret.objAttrs["classid"] = classid; if (mimeType) ret.embedAttrs["type"] = mimeType; return ret; } // E-Mail function copyAddressBook() { var append = document.messages.quickchoose[document.messages.quickchoose.selectedIndex].value + '\n'; document.messages.to.value += append; } // Calendar function getAddresses(entityid) { $.get(handler, { 'method': getAddresses, 'id': entityid }, function(reply) { if (! reply) { alert('There was no response from the server. Please check your network connection.'); } else { if (reply.error) { alert('There was a problem with the server request. Please make sure your link is valid.'); } else { document.getElementById('addresses').innerHTML = reply; } showTR('addressrow'); } }); } function changeRecord(formName, imageName, hiddenName, numberArrows, arrowid, recordid) { document.forms[formName].elements[hiddenName].value = recordid; turnOnePurple(formName, imageName, hiddenName, numberArrows, arrowid); } // Money function formatNumber(number, preSign, postSign, round) { var newValue = ''; var sign = ''; var exponent = Math.pow(10, round); number = forceNumber(number); if (isFinite(number)) { if (number < 0) { number = Math.abs(number); sign = '-'; } return sign + preSign + (Math.round(number * exponent) / exponent).toFixed(round).toString() + postSign; } return 0; } // parse text (twice?) and return a number, eliminating dollar signs and commas? no. If theres a leading dollar sign, itll parse as NaN and return a zero. try this: var n = parseFloat(number.replace(/[$, ]/g, '')); if (isNaN(n)) return 0; else return n; function forceNumber(number) { if (isNaN(parseFloat(number))) number = 0; number = number.toString().replace(/[$, ]/g, ''); return parseFloat(number); } function justifyRight(string, size) { var originalLength = string.length; if (string.length) { for (i = 0; i < size - originalLength; i++) { string = ' ' + string; } } return string; } function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } // Top Search function selectHomeSearch(data) { if (! data || ! data.type || ! data.id) return false; switch (data.type) { case 'entities': window.location = '/profiles/index.html?id=' + data.id; break; case 'tag': window.location = '/tags/index.html?id=' + data.id; break; } } function selectTopSearchControl(data) { selectTopSearch(data, 1) } function selectTopSearch(data, control) { if (! data || ! data.type || ! data.id) return false; switch (data.type) { case 'entities': window.location = '/profiles/index.html?id=' + data.id; break; case 'contacts': if (parseInt(control) == 1) { window.location = '/control/contacts.html?id=' + data.id; } else { window.location = '/contacts/index.html?id=' + data.id; } break; case 'ap': window.location = '/money/accounting/ap.html?id=' + data.id; break; case 'ar': window.location = '/money/accounting/ar.html?id=' + data.id; break; case 'po': window.location = '/money/purchaseorders/index.html?id=' + data.id; break; case 'assets': window.location = '/money/accounting/assets.html?id=' + data.id; break; case 'employees': window.location = '/money/accounting/payroll/employees.html?id=' + data.id; break; case 'tags': window.location = '/tags/index.html?id=' + data.id; break; default: window.location = '/money/' + data.type + '/index.html?id=' + data.id; break; } } // Lampshade function preload(img) { var a = new Image(); a.src = img; return a; } function rollover(image, value) { eval('document[\'' + image + '\'].src = ' + value + '.src;'); } function turnPurple(formName, imageName, hiddenName, id) { if (document.forms[formName].elements[hiddenName + '[' + id + ']'].value == id) { document[imageName + id].src = arrowgray.src; document.forms[formName].elements[hiddenName + '[' + id + ']'].value = ''; } else { document[imageName + id].src = arrowon.src; document.forms[formName].elements[hiddenName + '[' + id + ']'].value = id; } } function turnOnePurple(formName, imageName, hiddenName, numberArrows, id) { for (var i = 0; i < numberArrows; i++) { document[imageName + i].src = arrowgray.src; } document[imageName + id].src = arrowon.src; } function turnColor(formName, imageName, hiddenName, color) { stringLength = hiddenName.length; elementArray = document.forms[formName].elements; for (i = 0; i < elementArray.length; i++) { if (elementArray[i].name.substr(0, stringLength) == hiddenName) { openBracket = elementArray[i].name.search('\\['); closeBracket = elementArray[i].name.search('\\]'); arrayIndex = elementArray[i].name.substring(openBracket + 1, closeBracket); if (elementArray[i].value == arrayIndex) { eval('document[imageName + arrayIndex].src = arrow' + color + '.src'); } } } } function actionPurple(formName, imageName, hiddenName, id, action) { if (document.forms[formName].elements[hiddenName + '[' + id + ']'].value == id) { document[imageName + id].src = arrowgray.src; document.forms[formName].elements[hiddenName + '[' + id + ']'].value = ''; } else { document[imageName + id].src = arrowon.src; document.forms[formName].elements[hiddenName + '[' + id + ']'].value = id; } eval(action); } function selectAllArrows(formName, imageName, hiddenName) { if (typeof selectAllArrows.status == 'undefined') selectAllArrows.status = false; stringLength = hiddenName.length; elementArray = document.forms[formName].elements; for (i = 0; i < elementArray.length; i++) { if (elementArray[i].name.substr(0, stringLength) == hiddenName) { openBracket = elementArray[i].name.search('\\['); closeBracket = elementArray[i].name.search('\\]'); arrayIndex = elementArray[i].name.substring(openBracket + 1, closeBracket); if (! selectAllArrows.status) { document[imageName + arrayIndex].src = arrowon.src; document.forms[formName].elements[hiddenName + '[' + arrayIndex + ']'].value = arrayIndex; } else { document[imageName + arrayIndex].src = arrowgray.src; document.forms[formName].elements[hiddenName + '[' + arrayIndex + ']'].value = ''; } } } selectAllArrows.status = ! selectAllArrows.status; } function showNextDrop(obj, k) { var $span = $(obj).next('span').eq(0), disp = $span.css('display'); if (disp == 'none') { $span.show(); $('#filtertriangle' + k).hide(); } else { $span.hide(); $('#filtertriangle' + k).show(); } } function startTopSearch(text) { if (! text.length) { ID('topSearch').style.cssText = ID('topSearch').style.cssText.replace(' background: url(\'' + static + 'images/loading2.gif\'); background-position: 99% 50%; background-repeat: no-repeat; padding-right: 2px;', ''); } else if (text.length >= 2) { if (text.match(/(.+)@(.+)\.(.+)/)) { ID('topSearch').style.cssText = "homeField"; ID('topSearch').name = "signinemail"; showID('topSignIn'); } else { ID('topSearch').style.cssText += " background: url('" + static + "images/loading2.gif'); background-position: 99% 50%; background-repeat: no-repeat; padding-right: 2px;"; } } return text; } function thinkPrompt(box) { var query = box.value; if (window.thinklink == undefined) window.thinklink = { 'state': false, 'step': false }; box.value = ''; if (window.thinklink.state == 'signin' && window.thinklink.step == 'password') { ID('above').innerHTML += "