/* *---------------------------------------------------- * this file is linked in starteam across all web apps *----------------------------------------------------- * this file contains common javascript functions that are used across projects */ /** * given a url, determine the correct parameter delimiter ('?' or '&') and append the parameter and value * with the value encoded using encodeuricomponent(). * the new url is returned. */ function appendparametertourl(url, paramname, paramvalue) { var delimiter; if( url.indexof("?") == -1) { delimiter = "?"; } else { delimiter = "&"; } return url + delimiter + encodeuricomponent(paramname) + "=" + encodeuricomponent(paramvalue); } function getinputobjectbyname(name) { return eval("document.forms[0]." + name); } /* * check a checkbox input field, using a boolean value. * the checkbox object is located in document.forms[0] by its name. */ function setcheckboxbyname( checkboxname, booleanvalue ) { var cbx = getinputobjectbyname(checkboxname); setcheckbox(cbx, booleanvalue); } /* * check a checkbox input field, using a boolean value. * the checkbox object is located in document.forms[0] by its name. */ function setcheckbox( checkboxobject, booleanvalue ) { if(checkboxobject != null && checkboxobject != 'undefined') { if(booleanvalue) { checkboxobject.checked = 'checked'; checkboxobject.value = 'on'; } else { checkboxobject.checked = false; } } } /* * not yet tested, taken from config intelliquip.js */ function togglecheckbox(checkboxobject) { if(checkboxobject != null && checkboxobject != 'undefined') { if(checkboxobject.checked) checkboxobject.checked = false; else checkboxobject.checked = true; } } function setdisabledbyid(id, isdisabled) { var obj = window.document.getelementbyid(id); setdisabledbyobject(obj, isdisabled); } function setdisabledbyobject(obj, isdisabled) { if(obj != null) { obj.disabled = isdisabled; } } function restoredefaultforradio(radioobj) { var allradios = document.getelementsbyname(radioobj.name); for(var i=0; i object. * this method will determine the default value (selected option when the page was loaded), and select it. */ function restoredefaultforselect(selectobj) { for(var i=0; i object. * this method will determine the value of the currently selected option. */ function getselectvalue(selectobj) { return selectobj.options[selectobj.selectedindex].value } /** * converts a number using regional settings into a simple decimal format * consisting of no digit grouping symbols, and a period as the decimal symbol. * this conversion is necessary in order to compare numbers in javascript that * use regional settings. * * this function is currently duplicated in selector's commonfunctions.js using the name getsimpledecimalformat(). * in the future the selector should be migrated to use this function instead. it also defines getoriginaldecimalformat() which may be useful here. */ function getsimpledecimalfromdisplay(originalnum, digitgroupingsymbol, decimalsymbol) { var newstring = ""; var retval = ""; //alert('originalnum='+originalnum); //alert('digitgroupingsymbol='+digitgroupingsymbol); //alert('decimalsymbol='+decimalsymbol); // build new number string without digit grouping symbols for (var i = 0; i < originalnum.length; i++) { if (originalnum.charat(i) != digitgroupingsymbol) { newstring = newstring + originalnum.charat(i); } } // convert decimal symbol to period for (var i = 0; i < newstring.length; i++) { if (newstring.charat(i) == decimalsymbol) { // replace with period retval = retval + "."; } else { // otherwise just copy character retval = retval + newstring.charat(i); } } //alert('retval='+retval); return retval; } /* * locate the input object using its name, returns its value as a float */ function getinputasfloatbyname(inputname, groupingsymbol, decimalsymbol) { var inputobj = getinputobjectbyname(inputname); if(!isinputobjectdefined(inputobj)){ return undefined; } else { return getinputasfloat(inputobj, groupingsymbol, decimalsymbol); } } /* * returns the input object's value as a float */ function getinputasfloat(inputobj, groupingsymbol, decimalsymbol) { //alert('getinputasfloat() inputobj='+inputobj+' groupingsymbol='+groupingsymbol+' decimalsymbol='+decimalsymbol); var valstring = getsimpledecimalfromdisplay(inputobj.value, groupingsymbol, decimalsymbol); //alert('getinputasfloatbyname() valstring='+valstring); var val = parsefloat(valstring); //alert('getinputasfloatbyname() val='+val); return val; } /* * check if the value of an input field is empty * returns a boolean */ function isinputvalueempty(inputname) { var inputobj = getinputobjectbyname(inputname); return inputobj.value.length == 0; } /* * validate that input is greater than the specified value and is not 'nan' * returns a boolean */ function validateinput_greaterthanvalue(value, inputname, groupingsymbol, decimalsymbol) { var val = getinputasfloatbyname(inputname, groupingsymbol, decimalsymbol); if(val == undefined) { return true; } else { return !isnan(val) && val > value; } } /* * validate that input is equal to or greater than the specified value and is not 'nan' * returns a boolean */ function validateinput_equaltoorgreaterthanvalue(value, inputname, groupingsymbol, decimalsymbol) { var val = getinputasfloatbyname(inputname, groupingsymbol, decimalsymbol); if(val == undefined) { return true; } else { return !isnan(val) && val >= value; } } function validateinput_equaltoorgreaterthanotherinput(name1, name2, groupingsymbol, decimalsymbol) { var val1 = getinputasfloatbyname(name1, groupingsymbol, decimalsymbol); var val2 = getinputasfloatbyname(name2, groupingsymbol, decimalsymbol); if(val1 == undefined) { return true; } else { return !isnan(val1) && val1 >= val2; } } /* * validate that input is greater than zero and is not 'nan' * returns a boolean */ function validateinput_greaterthanzero(inputname, groupingsymbol, decimalsymbol) { return validateinput_greaterthanvalue(0.0, inputname, groupingsymbol, decimalsymbol); } /* * deprecated - use validateinput_greaterthanzero() because the name is clearer * validate that input is greater than zero and is not 'nan' * returns a boolean */ function validateinput_nonzero(inputname, groupingsymbol, decimalsymbol) { return validateinput_greaterthanzero(inputname, groupingsymbol, decimalsymbol); } /* * validate that input1 is greater than input2 * returns a boolean */ function validateinput_greaterthan(input1_name, input2_name, groupingsymbol, decimalsymbol) { var val1 = getinputasfloatbyname(input1_name, groupingsymbol, decimalsymbol); if(val1 == undefined) { return true; } var val2 = getinputasfloatbyname(input2_name, groupingsymbol, decimalsymbol); if(val2 == undefined) { return true; } //alert('validateinputs_greaterthan() val1='+val1+', val2='+val2); return val1 >= val2; } /* * validate that input1 is greater than input2, where empty input values are acceptable * returns a boolean */ function validaterangeinput_greaterthan(input1_name, input2_name, groupingsymbol, decimalsymbol) { var inputobj1 = getinputobjectbyname(input1_name); var inputobj2 = getinputobjectbyname(input2_name); if(!isinputobjectdefined(inputobj1)|| !isinputobjectdefined(inputobj2)) { return true; } if(inputobj1.value == '' || inputobj2.value == '') { return true; } var val1 = getinputasfloat(inputobj1, groupingsymbol, decimalsymbol); var val2 = getinputasfloat(inputobj2, groupingsymbol, decimalsymbol); //alert('validaterangeinput_greaterthan() val1='+val1+', val2='+val2); return val1 >= val2; } function validateinput_withinrange(input_name, minvalue, maxvalue, groupingsymbol, decimalsymbol) { var val = getinputasfloatbyname(input_name, groupingsymbol, decimalsymbol); if(val == undefined) { return true; } return minvalue <= val && val <= maxvalue; } /* * scroll to a positiony for the div specified by divid. * this is duplicated within config and qm intelliquip.js using the name "getpreviousfocus()" and should be migrated to use this function. */ function scrolltovertical(positiony, divid) { var divobj = document.getelementbyid(divid); if(divobj != null) { var y = parseint(positiony); if(!isnan(y) && y > 0) { divobj.scrolltop = y; } } } function setscrollpositionyvalueforbody(positiony){ var y = parseint(positiony); if(!isnan(y) && y > 0) { window.document.body.scrolltop = y; } } /* * sets the form's field value to the scrolltop of an object. */ function setscrollpositionyvalue(fieldobj, divobj){ var y = parseint(divobj.scrolltop); if(!isnan(y)){ fieldobj.value =y; } } /* * set the form input variable 'positiony' to the scrolltop value of the div object. * does not perform null checks so that it fails loudly. * this is duplicated within config and qm intelliquip.js using the name "setpositiony()" and should be migrated to use this function. */ function setscrollpositiony(divobj) { setscrollpositionyvalue(window.document.forms[0].positiony, divobj); } /* * set the inputname's value to the value of the selectobj's selected option value * selectobj - must be a to be updated */ function updateinputwithselectedoptionvalue(selectobj, inputname) { var selectvalue = getselectvalue(selectobj); getinputobjectbyname(inputname).value = selectvalue; } /** * builds a url from the 2 dimensional array(paramarray) with the parameter * values(not the names - name must always be ascii) encoded to support utf-8. * * var param = new array(["lookuptype", lookuptype], ["lookupid", lookupid] ); * var param = [["lookuptype", lookuptype], ["lookupid", lookupid]]; */ function buildparamurl(baseurl, paramarray){ var newurl = baseurl; if (paramarray && paramarray.length > 0){ for (var i=0; i< paramarray.length; i++){ //appendparametertourl will encode the parameter values to utf-8 newurl = appendparametertourl(newurl, paramarray[i][0], paramarray[i][1]); } } return newurl; } /* * returns a new array with the name and value appended as another element. * var param = [["lookuptype", lookuptype], ["lookupid", lookupid]]; * param = concatoneparam(param, "x","y"); * param becomes [["lookuptype", lookuptype], ["lookupid", lookupid], ["x", "y"]]; */ function concatoneparam(paramarray, name, value){ return paramarray.concat([[name,value]]); } function submittourl_newwindow(url) { submittourl(url, "_blank"); } /* * similar function exists in qm's intelliquip.js, called dosubmit(actionurl, targetframe) */ function submittourl(url, targetframe) { document.forms[0].method = 'post'; document.forms[0].target = targetframe; document.forms[0].action = url; document.forms[0].submit(); } /* * returns true if the variable has been declared. */ function isvariabledefined(variablename){ return (typeof(window[variablename]) == "undefined") ? false:true; } function trim(input){ return input.replace(/^\s+|\s+$/g, ''); } function isinputobjectdefined(inputobj) { return inputobj != null && inputobj != undefined; } function executeonclickorhref(linkelement){ if(linkelement!=null){ linkelement.click(); } } function addselectedfrompicklisttoresultlist(picklist, resultlist) { leftlist = $('#' + picklist + ' option:selected'); rightlist = $('#' + resultlist + ' option'); var intersection = new array(); test = false; for (i=0;i < leftlist.length;i++){ for (j=0;j < rightlist.length;j++){ if(leftlist[i].value == rightlist[j].value){ test=true; j = rightlist.length; } } if(!test){ intersection.push(leftlist[i]); } test=false; } $(intersection).clone(true).appendto('#' + resultlist); $('#' + resultlist).focus(); return false; } function removeselectedfromresultlist(list) { return $('#' + list +' option:selected').remove(); } /* * must call this method to select all entries in the list to be submitted. otherwise, only the entries * the user highlighted will be submitted. */ function selectresultlistforsubmit(list) { if($('#'+list).length >0) { $('#'+ list + ' option').each(function(k) { $(this).prop("selected", "selected"); }); } return false; } /* this must be called on the current frame, which can be achieved using: window.displayjavascriptloadingscreen(loadingimagepath) if the top frameset includes common-util-functions.js, and is set then this may be called from the frameset, and it will not work. */ function displayjavascriptloadingscreen(loadingimagepath) { displayjavascriptloadingscreenwithposition(loadingimagepath,"center") } function displayjavascriptloadingscreenwithposition(loadingimagepath, position){ var busydialogdiv = $('#busydialog'); if (busydialogdiv.length <= 0){ busydialogdiv = $(document.createelement('div')).attr('id', 'busydialog'); $('body').prepend(busydialogdiv); } busydialogdiv.css({"width":"100%", "height":"100%", 'background-image': 'url(' + loadingimagepath + ')', "background-position":position, "background-repeat":"no-repeat", "position":"fixed", "z-index":"9999", "display":"none", "cursor":"progress"}); busydialogdiv.show(); } function displaysimplemessagedialog(dialogid, width, height, title, divtext, btns){ var divobj = $("#"+dialogid); if (divobj.length <= 0){ divobj = $(document.createelement('div')).attr('id', dialogid); $('body').prepend(divobj); } divobj.text(divtext); divobj.dialog({modal: true, width:width, height:height, title: title, buttons: btns}); $(".ui-dialog-titlebar-close").hide(); } function displaysimplemessagedialogwithokbuttonthatclosesdialog(dialogid, width, height, title, divtext){ displaysimplemessagedialog(dialogid, width, height,title, divtext); $("#"+dialogid).dialog('option', 'buttons', { 'ok' : function() { $("#"+dialogid).dialog("close"); } }); } function displaydialog(dialogid, width, height, title, btns){ var divobj = $("#"+dialogid); if (divobj.length <= 0){ divobj = $(document.createelement('div')).attr('id', dialogid); $('body').prepend(divobj); } return divobj.dialog({modal: true, width:width, height:height, title: title, buttons: btns}); } function removejavascriptloadingscreen() { $("#busydialog").remove(); } function handleenterkeypress(evt, command) { if (getcharcode(evt) == 13) { command(); } return false; } function getcharcode(evt) { var charcode = (evt.which) ? evt.which : evt.keycode; return charcode; } /** * requires- jquery js files imported into the page. * this creates a simple jquery dialog which contains a single button, whose function will be to just close the popup. */ function showsimpleokalertdialog(divid, dialogwidth, btnlabel, alertmsg, title, buttonfuction) { var divelmt = document.getelementbyid(divid); /* create only 1 div per document and reuse it */ if(divelmt == null) { var divelmt = document.createelement('div'); divelmt.id = divid; document.forms[0].appendchild(divelmt); $(divelmt).hide(); } /* * idd#11293: check if the dialog is already visible. * the dialog('open') may re-fire the event that triggered this function, causing the dialog to display twice. */ var divobj = $(divelmt); if(!divobj.closest('.ui-dialog').is(':visible')) { divobj.text(alertmsg); var btns = {}; btns[btnlabel] = function() { $(this).dialog("destroy"); if(buttonfuction){ buttonfuction(); } }; divobj.dialog({ width: dialogwidth, center:1, title: title, draggable: false, resizable: false, autoopen: false, modal: true, buttons: btns}); /*add this to the above line if the dialog is not positioned in the center for ie - it is apparently a jquery bug for ie * position: { my: "center", at: "center", of: $("body"), within: $("body") }}*/ divobj.dialog("open"); divobj.focus(); $(".ui-dialog-titlebar-close").hide(); } } /** * this function duplicated in qm/config intelliquip.js with name 'replacecommawithperiod', * in the future we should delete them and migrate to use the below function. */ function replacecommasepwithperiod(objval) { if(typeof objval == 'number') { objval = objval.tostring(); } if(objval.indexof(',') >= 0) { objval = objval.replace(',', '.'); } return objval; } /** * this function duplicated in qm/config intelliquip.js with name 'replaceperiodwithcomma', * in the future we should delete them and migrate to use the below function. */ function replaceperiodsepwithcomma(objval) { if(typeof objval == 'number') { objval = objval.tostring(); } if(objval.indexof('.') >= 0) { objval = objval.replace('.', ','); } return objval; } /** * this function duplicated in qm/config intelliquip.js with name 'removedigitgroupingsymbol', * in the future we should delete them and migrate to use the below function. */ function removedigitgroupingsep(obj, digitgroupingsymbol) { if(obj != null && typeof obj.value != 'undefined') { for(i=0; i < obj.value.length; i++) { if(obj.value.charat(i)== digitgroupingsymbol) obj.value = obj.value.replace(digitgroupingsymbol, ''); } } } function makefocusfunction(objtofocus){ if (objtofocus != null && objtofocus != 'undefined') { return function() {objtofocus.focus()}; } } /** * this function duplicated in qm/config intelliquip.js with name 'checknumber', * in the future we should delete them and migrate to use the below function. */ function chknumber(obj, digitgroupingsymbol, decimalsymbol,label_enter_numeric_value) { objvalue = obj.value; if(decimalsymbol == ',') objvalue = replacecommasepwithperiod(objvalue); if(!$.isnumeric(objvalue)) { var buttonfunction = makefocusfunction(obj); showsimpleokalertdialog('okalertdiv', 400, 'ok', label_enter_numeric_value, '', buttonfunction); obj.value = obj.defaultvalue; removedigitgroupingsep(obj, digitgroupingsymbol); return false; } return true; } /** * this function duplicated in qm/config intelliquip.js with name 'checkdecimalsymbol', * in the future we should delete them and migrate to use the below function. */ function chkdecimalsep(inputobject, digitgroupingsymbol, decimalsymbol, label_thousand_sep_not_allowed) { var buttonfunction = makefocusfunction(inputobject); var commaseperatorcounter = 0; for(p=0; p < inputobject.value.length; p++) { if(inputobject.value.charat(p)== ',') commaseperatorcounter = commaseperatorcounter + 1; } var periodseperatorcounter = 0; for(q=0; q < inputobject.value.length; q++) { if(inputobject.value.charat(q)== '.') periodseperatorcounter = periodseperatorcounter + 1; } if(commaseperatorcounter > 1 || periodseperatorcounter > 1) { showsimpleokalertdialog('okalertdiv', 400, 'ok', label_thousand_sep_not_allowed, '', buttonfunction); inputobject.value = inputobject.defaultvalue; removedigitgroupingsep(inputobject, digitgroupingsymbol); return false; } return true; } function performnumchecks(inputobject, digitgroupingsymbol, decimalsymbol, label_thousand_sep_not_allowed, label_please_enter_numeric_number , label_enter_value_in_range) { removedigitgroupingsep(inputobject, digitgroupingsymbol); var retstatus = chkdecimalsep(inputobject, digitgroupingsymbol, decimalsymbol, label_thousand_sep_not_allowed); if(retstatus) { retstatus = chknumber(inputobject, digitgroupingsymbol, decimalsymbol, label_please_enter_numeric_number); } return retstatus; } /** * used in qm and configurator. this performs discount multiplier [minval, maxval] range related validations. */ function performdiscountlimitchecks(inputobject, digitgroupingsymbol, decimalsymbol, label_thousand_sep_not_allowed, label_please_enter_numeric_number, label_enter_value_in_range, multiplier_override_alert, ok_btn_label, pricingcalcfactorsprecision) { var retstatus = performnumchecks(inputobject, digitgroupingsymbol, decimalsymbol, label_thousand_sep_not_allowed, label_please_enter_numeric_number , label_enter_value_in_range); var buttonfunction = makefocusfunction(inputobject); minval = inputobject.getattribute('discountminlimit'); maxval = inputobject.getattribute('discountmaxlimit'); minfactor = inputobject.getattribute('discountfactormin'); maxfactor = inputobject.getattribute('discountfactormax'); if(minfactor != -1 && minval != -1) { minval = minval * minfactor; } if(maxfactor != -1 && maxval != -1) { maxval = maxval * maxfactor; } if (typeof minval != 'undefined' && typeof maxval != 'undefined' && minval != -1 && maxval != -1 && minval !== "" && maxval !== "") { var inputval = inputobject.value; if(decimalsymbol == ',') { inputval = replacecommasepwithperiod(inputval); } if(inputval.indexof('.') == 0) { inputval = '0' + inputval; } inputval = parsefloat(inputval); if (typeof pricingcalcfactorsprecision != 'undefined' && pricingcalcfactorsprecision !== "" && !isnan(pricingcalcfactorsprecision)){ minval = parsefloat(minval).tofixed(pricingcalcfactorsprecision); maxval = parsefloat(maxval).tofixed(pricingcalcfactorsprecision); } else { minval = parsefloat(minval).tofixed(2); maxval = parsefloat(maxval).tofixed(2); } retstatus = inputval >= minval && inputval <= maxval; //alert(inputval + ' : ' + minval + ' : ' + maxval + ' : ' + retstatus); if( !retstatus){ if(decimalsymbol == ','){ //for alerting convert . back to , minval = replaceperiodsepwithcomma(minval); maxval = replaceperiodsepwithcomma(maxval); } showsimpleokalertdialog('okalertdiv', 400, ok_btn_label, label_enter_value_in_range+ " " + minval +" and "+ maxval +".", multiplier_override_alert, buttonfunction); inputobject.value = inputobject.defaultvalue; } } return retstatus; } function checkidfornan(obj, label, oldfieldvalue, label_invalid_integer_entered, field) { var buttonfunction = makefocusfunction(obj); if(obj != null) { if(obj.value != "") { objvalue = obj.value; for(i = 0; i < objvalue.length; i++) { charec = objvalue.charat(i); if(isnan(parseint(charec))) { if(document.all.recalc != null) { document.all.recalc.style.display="none";} showsimpleokalertdialog('okalertdiv', 400, 'ok', label_invalid_integer_entered + label + field + "\n", '', buttonfunction); obj.value = ''; return false; } } } /* removed to allow "" else { // on customer id fields- in case when a previous value is completely removed and user wants to recalculate, dont allow if(oldfieldvalue != "") { showsimpleokalertdialog('okalertdiv', 400, 'ok', "please enter valid integer value in '"+ label +"' field.\n", '', buttonfunction); obj.value = oldfieldvalue; return false; } }*/ } return true; } function performnumcheckscustom(inputobject, digitgroupingsymbol, decimalsymbol, rfqlabel, field, label_enter_numeric_value_or, label_enter_numeric_value) { removedigitgroupingsep(inputobject, digitgroupingsymbol); var retstatus = chkdecimalsep(inputobject, digitgroupingsymbol, decimalsymbol, "thousand seperator is not allowed"); if(retstatus) { if(field == 'pricefield') { retstatus = chkspaceinpricefield(inputobject, digitgroupingsymbol, decimalsymbol, rfqlabel, label_enter_numeric_value_or); } else if(field == 'numericfield') { retstatus = chknumber(inputobject, digitgroupingsymbol, decimalsymbol, label_enter_numeric_value); } } return retstatus; } function chkspaceinpricefield(obj, digitgroupingsymbol, decimalsymbol, rfqlabel, label_enter_numeric_value_or) { var buttonfunction = makefocusfunction(obj); objvalue = obj.value; if (objvalue == rfqlabel) return true; if(decimalsymbol == ',') objvalue = replacecommawithperiod(objvalue); var s = new string(objvalue); if(isnan(s.valueof()) || s.indexof(' ') > -1) { showsimpleokalertdialog('okalertdiv', 400, 'ok', label_enter_numeric_value_or + rfqlabel + '.', '', buttonfunction); obj.value = obj.defaultvalue; removedigitgroupingsymbol(obj, digitgroupingsymbol); return false; } return true; } function detectsvgplugin() { var results = {support:null, plugin:null, builtin:null}; var obj = null; if (navigator && navigator.mimetypes && navigator.mimetypes.length) { for (var mime in {"image/svg+xml":null, "image/svg":null, "image/svg-xml":null}) { if (navigator.mimetypes[mime] && (obj=navigator.mimetypes[mime].enabledplugin) && obj) results = {plugin:(obj=obj.name.tolowercase()) && obj.indexof("adobe") >= 0 ? "adobe" : (obj.indexof("renesis") >= 0 ? "renesis" : "unknown")}; } } else if ((obj = document.createelement("object")) && obj && typeof obj.setattribute("type", "image/svg+xml")) { if (typeof obj.use_svgz == "string") results = {plugin:"adobe", iid:"adobe.svgctl", pluginversion:obj.window && obj.window._window_impl ? (obj.window.evalscript ? 6 : 3) : 2}; else if (typeof obj.readystate == "number" && obj.readystate == 0) results = {plugin:"renesis", iid:"renesisx.renesisctrl.1", pluginversion:">=1.0"}; else if (obj.window && obj.window.getsvgviewerversion().indexof("enesis") > 0) results = {plugin:"renesis", iid:"renesisx.renesisctrl.1", pluginversion:"<1.0"}; } results.iid = (results.plugin == "adobe" ? "adobe.svgctl" : (results.plugin == "renesis" ? "renesisx.renesisctrl.1" : null)); var claimed = !!window.devicepixelratio || (typeof svgangle == "object" || (document && document.implementation && document.implementation.hasfeature("org.w3c.dom.svg", "1.0"))); var nsi = window.components && window.components.interfaces && !!components.interfaces.nsidomgetsvgdocument; results.builtin = claimed ? (!!window.opera ? "opera" : (nsi ? "gecko" : "safari")) : (!!window.opera && window.opera.version ? "opera" : (nsi ? "gecko" : null)); results.builtinversion = results.builtin && !!window.opera ? parsefloat(window.opera.version()) : (nsi ? (typeof iterator == "function" ? (array.reduce ? 3.0 : 2.0) : 1.5) : null); if (!!window.opera && results.builtinversion >= 9 && (obj = document.createelement("object")) && obj && typeof obj.setattribute("type", "image/svg+xml") != "undefined" && document.appendchild(obj)) { results.support = obj.offsetwidth ? "plugin" : "builtin"; document.removechild(obj); } else { results.support = results.plugin && !claimed ? "plugin" : (results.builtin && claimed ? "builtin" : null); } if (!results.support && results.builtin) { return false; } else if (!results.support) { return false; } return true; } function detectsvgandalertuser(browsersupportsnativesvg) { if(browsersupportsnativesvg == 'false' && !detectsvgplugin()) { alert('please install the adobe svg viewer plugin to use this page'); window.open("http://www.adobe.com/svg/viewer/install/"); } } /** * this method will expand/collapse a twistie section and will set a form parameter for persistence if savetoform is true * it is important that the twistiesection is named exactly as the name defined in the qmtwistieconstants.java * */ function displaytwistiesection_shared(twistiesection, twistiegraphic, imagespath, savetoform, isdynamictwistie) { var displaystyle = ""; var twistiesuffix = "displaystyle"; if (twistiesection.style.display == "inline") { displaystyle = "none"; twistiesection.style.display = "none"; twistiegraphic.src = imagespath + 'twistieclosed.gif'; if (savetoform) { $('input[name="'+twistiesection.id + twistiesuffix + '"]').val("none"); } } else { displaystyle = "inline"; twistiesection.style.display = "inline"; twistiegraphic.src = imagespath + 'twistieopen.gif'; if (savetoform) { $('input[name="'+twistiesection.id + twistiesuffix + '"]').val("inline"); } } if(isdynamictwistie && savetoform) { appenddynamictwistietoform(twistiesection.id); } if(document.getelementbyid("currentpagenameforajax") != null){ //must come after appenddynamictwistietoform() savetwistiesettingajax(twistiesection, twistiesuffix, displaystyle, isdynamictwistie); } } function appenddynamictwistietoform(nametoappend) { var twistielist = document.forms[0].dynamictwistienamelist; if(twistielist != null) { if(twistielist.value == null || twistielist.value == "") { twistielist.value = nametoappend; } else { var separator = ';'; var twisties = twistielist.value.split(separator); var hastwistie = false; for(var i=0; i 0) && (parent.style.display != "inline")) { // a parent is hidden, this will break out of the loop isinline = false; } //iterate over all parents parent = parent.parentnode; } return isinline; } /* disable the link, call the functiontocall, and re-enable the link if functiontocall returns a falsy value. useful when submitting a page, and disabling the submit button to prevent multiple submits. */ function callfunctionanddisablelink(functiontocall, linkid) { var linkobj = $('#'+linkid); if(linkobj.prop('disabled') !== 'disabled') { //for chrome and safari, disabled does nothing for anchor links, need to check manually linkobj.prop('disabled','disabled'); var success = functiontocall(); if(!success) { linkobj.removeprop('disabled'); } } } function callfunctionandjqueryloadingscreen(functiontocall, loadingimagepath) { displayjavascriptloadingscreen(loadingimagepath); var success = functiontocall(); if(!success) { removejavascriptloadingscreen(); } } /* dynamichrefidarray is meant for anchors where id is dynamically set, eg- quote worksheet's discount class multipliers */ var dynamichrefidarray = []; /* disables all input fields, except of type=hidden, and also disables any other required images, anchors. */ function disablefieldsinarchivequotemode(objectstodisable, disableinputfields) { if(disableinputfields) { /*disable all input fields except of type=hidden */ $(':input:not(input[type=hidden])').attr('disabled', 'true'); } $.each(objectstodisable, function(arraytype, objarray) { if(arraytype == 'img') { disableimgfields(objarray); } else if(arraytype == 'anchor' || arraytype == 'dynamicanchor') { disableanchorfields(objarray); } else if (arraytype == 'btnanchor') { disablebtnfields(objarray); } else if(arraytype == 'jqueryanchor') { disablejqueryanchorfields(objarray); } }); } function disableimgfields(objarray) { $.each(objarray, function(index, imgid) { $('img[id^=' + imgid + ']').each(function() { if($(this).attr('grayoutendimg') != 'no') { $(this).css('opacity', 0.5); } }); }); } function disableanchorfields(objarray) { $.each(objarray, function(index, anchorid) { $('a[id^=' + anchorid + ']').each(function() { $(this).css('opacity', 0.5).prop('onclick', 'javascript:void(0)').prop('href', 'javascript:void(0)'); $(this).css('cursor', 'none'); }); }); } function disablejqueryanchorfields(objarray) { $.each(objarray, function(index, anchorid) { $('a[id^=' + anchorid + ']').each(function() { $(this).css('opacity', 0.5).unbind('click', ''); $(this).css('cursor', 'none'); }); }); } function disablebtnfields(objarray) { $.each(objarray, function(index, anchorid) { $('button[id^=' + anchorid + ']').each(function() { $(this).css('opacity', 0.5).attr('disabled', 'true'); $(this).css('cursor', 'none'); }); }); } /* this resets the textarea's text to maxlength if user tries to enter text exceeding the permissible maxlength setting value. */ function setmaxlengthtextlimitintextareafield() { $('textarea[maxlength]').keyup(function() { //get the limit from maxlength attribute var limit = parseint($(this).attr('maxlength')); //get the current text inside the textarea var text = $(this).val(); //count the number of characters in the text var chars = text.length; //check if there are more characters than allowed if(chars > limit) { //and if there are use substr to get the text before the limit var new_text = text.substr(0, limit); //and change the current text with the new text $(this).val(new_text); } }); } function blinkbutton(flashbuttonid, btnblinkcontrol) { if (btnblinkcontrol == 'true'){ var flashbutton = $('#' + flashbuttonid); if (flashbutton != null && flashbutton != 'undefined') { setinterval( function(){ changecolor(flashbutton, flashbutton.attr("flashtype"), flashbutton.attr("flashcolor")); }, 500); } } } function changecolor(flashbutton,type,color){ if (type==0){ if (flashbutton.prop('style').color == color)//get color by css() works in ie, but not in chrome and safari, so prop() is better. flashbutton.prop('style').color = ''; else flashbutton.prop('style').color = color; } else if (type==1){ if (flashbutton.prop('backgroundcolor').color == color) flashbutton.prop('backgroundcolor').color = ''; else flashbutton.prop('backgroundcolor').color = color; } } function autofocusonfield(fieldidorname){ if (fieldidorname != null && fieldidorname != 'undefined') { $('#' + fieldidorname).focus(); $('[name=' + fieldidorname + ']').focus(); } else {//if no fieldidorname param defined, default focus on first non-hidden input field on the page $('input[type!=hidden]:first').focus(); } } /* * called from every popup window's onunload handler. * this is necessary because a race condition occurs between the closing of the childwin, and the main window's focus check * that focus check is performed in main.jsp function checkchildwin(). */ function dochildwinunload() { //make sure the opener and achildwindow has been defined if (window.opener != null && window.opener.achildwindow != null) { //explicitly set the achildwindow variable to null, do not rely on the browser to do this when the window closes window.opener.achildwindow = null; } } /** * try to calculate the scrollbar width for your browser/os * @return {number} */ function scrollbarwidth() { var $div = $( //borrowed from anti-scroll '
' + '
' ); $('body').append($div); var w1 = $div.innerwidth(); var w2 = $('div', $div).innerwidth(); $div.remove(); return w1 - w2; } /** * this returns the correct viewport width taking into account browser compatibility. */ function getviewwidth(){ return window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth; } /** * this returns the correct viewport height taking into account browser compatibility. */ function getviewheight(){ return window.innerheight || document.documentelement.clientheight || document.body.clientheight; } function parsedate(datefieldstr){ if(datefieldstr.indexof(" ") > -1){ /* don't know which use case this is for */ var userdatesplit = datefieldstr.split(" "); var userday = userdatesplit[0]; var usermonth = userdatesplit[1]-1; var useryear = userdatesplit[2]; return new date(useryear, usermonth, userday); } if(datefieldstr.indexof("-") > -1){ var userdatesplit = datefieldstr.split("-"); var userday = userdatesplit[2]; var usermonth = userdatesplit[1]-1; var useryear = userdatesplit[0]; return new date(useryear, usermonth, userday); } return null; } function functionchain() { this.chainoffunctions = []; } functionchain.prototype = { /* add functions in the order you want them executed */ add: function(functiontoadd) { this.chainoffunctions = [functiontoadd].concat(this.chainoffunctions); return this; }, /* * remove and execute the next function, according to the order they were added. * the "this" object in the execution of that function will be set to thisarg. * returns the result of that function. */ executenextfunction: function(thisarg) { var func = this.chainoffunctions.pop(); if(func != null) { if(func instanceof function) { return func.call(thisarg, this); } else { alert('functionchain contains an invalid argument "'+func+'"'); } } }, /* * remove and return the next function object, according to the order they were added. */ nextfunction: function() { return this.chainoffunctions.pop(); } } function collectinputs(cssselector) { return $(cssselector + ' :input:enabled') .filter(':not(:checkbox), :checkbox:checked'); // avoid collecting unchecked checkboxes. } function upsertdirtyflagtodiv(divid, name){ upserthiddeninputtodiv(divid, name, true); } function upserthiddeninputtodiv(divid, name, value) { var input = $('#'+divid+' input[name="'+name+'"]'); if(input.length) { input.val(value); } else { $('#'+divid).append(''); } } function upsertdirtyflag(name){ upserthiddeninput(name, true); } function upserthiddeninput(name, value) { var input = $('[name="'+name+'"]'); if(input.length) { input.val(value); } else { $('form').append(''); } } function resizewidth(id){ var bodywidth = $('body').width(); if (bodywidth < 5000) { $('#'+id).css("width", bodywidth-2); } else { $('#'+id).css("width", "100%"); } } function downloadassinglefile(downloadtype, url) { url = appendparametertourl(url, 'downloadtype', downloadtype); $('input:checkbox:checked').each(function( index ) { url = appendparametertourl(url, 'savepdf', this.value); }); window.open(url); } function creategoogleanalyticsevent(category,action,label){ //the event tracking currently doesn't work with google tag manager - to be fixed: ife-820 var key = action+'-'+category; if(typeof datalayer == 'undefined'){ datalayer = []; } datalayer.push({key : label}); }