// Amgraf, Inc. // OneForm Designer Plus // Iform Server Database Access JavaScript Include Functions // // Revision History: // 10/29/2009 Code compare & update with OFDP gcode // // 07/30/2007 Changed over code to check for type of XMLHttpRequest // is supported and use that on all browsers. We assume the // applet code is no longer available. // var ctext = ""; var rtext = ""; function _initSelection (qURL, rStr, bLine, comboObj, callback) { // usage: var reqstr = "CompID=" + document.forms[0].CompanyName0.value; // usage: _initSelection ("../query/CompanyLocList-pl.cgi", reqstr, 1, document.forms[0].LocationID0); // usage: NOTE: callback is only used in MacCompat Mode var _TList = new Array; var _VList = new Array; var cline = 1; var cindex = 0; var eindex = 0; var comboline = ""; ctext = ""; rtext = ""; var http; var Activex; // Do not try if we did not come from server if (window.location.protocol.indexOf ("http") < 0) { return (0); } if (window.XMLHttpRequest && !window.ActiveXObject){ // If IE7, IE8, Mozilla, Safari, etc: Use native object http = new XMLHttpRequest(); Activex = false; } else if (window.ActiveXObject){ // ...otherwise, use the ActiveX control for IE5.x and IE6 http = new ActiveXObject("Microsoft.XMLHTTP"); Activex = true; } if (http != null || (bsniff.ie55 || bsniff.ie6 || bsniff.ie7 || bsniff.ie8) && !bsniff.mac) { if (Activex) { // var http = new ActiveXObject("Microsoft.XMLHTTP"); http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; } else { rtext = http.statusText; ctext = http.responseText; if (ctext.indexOf (" 0) { cindex = ctext.indexOf ("\n"); if (cindex > 0) { ++cline; _VList.length = _TList.length = cline; comboline = ctext.substring (0, cindex); eindex = comboline.indexOf ("="); if (eindex > 0) { _VList[cline-1] = comboline.substring (0, eindex); _TList[cline-1] = comboline.substring (eindex+1); } ctext = ctext.substring (cindex+1); } else { ++cline; _VList.length = _TList.length = cline; _VList[cline-1] = _TList[cline-1] = ctext; ctext = ""; } } if (bLine == 0) { // ignore 1st blank line entry var tlen = comboObj.options.length = _TList.length-1; for (i = 0; i < tlen; i++) { comboObj.options[i].text = _TList[i+1]; comboObj.options[i].value = _VList[i+1]; } } else { var boffset = 0; // all entries w/blank line var tlen = comboObj.options.length = _TList.length; if (bLine == -1) { if (tlen == 2) { boffset = 1; --tlen; } } for (i = 0; i < tlen; i++) { comboObj.options[i].text = _TList[i+boffset]; comboObj.options[i].value = _VList[i+boffset]; } } return (tlen); } function _saveSelectLists (ListArray) { var _slDiags = 0; for (fld in ListArray) { if (_slDiags) { alert (fld); } var slObj = document.getElementById (ListArray[fld]); if (slObj != null) { hidObj = document.getElementById (fld); if (hidObj != null) { hidObj.value = ""; if (_slDiags) { alert ("SelectList: " + fld + ", length= " + slObj.options.length + " Sel=" + slObj.options.selectedIndex); } // First line of returned select list is the "count, curIndex" hidObj.value = slObj.options.length + "," + slObj.options.selectedIndex + "\n"; for (var sndx = 0; sndx < slObj.options.length; sndx++) { if (_slDiags) { alert (slObj.options[sndx].value + " -- " + slObj.options[sndx].text); } hidObj.value += escape(slObj.options[sndx].value) + "=" + escape(slObj.options[sndx].text) + "\n"; } } } } } function _initSelectionStep (qURL, rStr, bLine, comboObj, comboCnt) { // usage: var reqstr = "CompID=" + document.forms[0].CompanyName0.value; // usage: _initSelectionStep ("../query/CompanyLocList-pl.cgi", reqstr, 1, document.forms[0].LocationID0); var _TList = new Array; var _VList = new Array; var cline = 1; var cindex = 0; var eindex = 0; var comboline = ""; var cCnt = 0; ctext = ""; rtext = ""; var http; var Activex; // Do not try if we did not come from server if (window.location.protocol.indexOf ("http") < 0) { return (0); } if (window.XMLHttpRequest && !window.ActiveXObject){ // If IE7, IE8, Mozilla, Safari, etc: Use native object http = new XMLHttpRequest(); Activex = false; } else if (window.ActiveXObject){ // ...otherwise, use the ActiveX control for IE5.x and IE6 http = new ActiveXObject("Microsoft.XMLHTTP"); Activex = true; } if (http != null || (bsniff.ie55 || bsniff.ie6 || bsniff.ie7 || bsniff.ie8) && !bsniff.mac) { if (Activex) { // var http = new ActiveXObject("Microsoft.XMLHTTP"); http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; } else { rtext = http.statusText; ctext = http.responseText; if (ctext.indexOf (" 0) { cindex = ctext.indexOf ("\n"); if (cindex > 0) { ++cline; _VList.length = _TList.length = cline; comboline = ctext.substring (0, cindex); eindex = comboline.indexOf ("="); if (eindex > 0) { _VList[cline-1] = comboline.substring (0, eindex); _TList[cline-1] = comboline.substring (eindex+1); } ctext = ctext.substring (cindex+1); } else { ++cline; _VList.length = _TList.length = cline; _VList[cline-1] = _TList[cline-1] = ctext; ctext = ""; } } if (bLine == 0) { // ignore 1st blank line entry for (cCnt = 0; cCnt < comboCnt; cCnt++) { var tlen = comboObj[cCnt].options.length = _TList.length-1; for (i = 0; i < tlen; i++) { comboObj[cCnt].options[i].text = _TList[i+1]; comboObj[cCnt].options[i].value = _VList[i+1]; } } } else { for (cCnt = 0; cCnt < comboCnt; cCnt++) { var boffset = 0; // all entries w/blank line var tlen = comboObj[cCnt].options.length = _TList.length; if (bLine == -1) { if (tlen == 2) { boffset = 1; --tlen; } } for (i = 0; i < tlen; i++) { comboObj[cCnt].options[i].text = _TList[i+boffset]; comboObj[cCnt].options[i].value = _VList[i+boffset]; } } } return (comboCnt); } function _InitDependentFields (qURL, rStr, ObjList, KeyList, len, pfdata, callback) { // usage: var reqstr = "CompID=" + form.CompanyName0.value; // usage: NOTE: callback is only used in MacCompat Mode // var OList = new Array (); // OList[0] = form.Field0; // Repeat for all dependent fields // var KList = new Array (); // KList[0] = "KeyName"; // Repeat for all dependent fields // pfdata ; // Pre-filled in data (server is not contacted, just parse string passed) // _InitDependentFields ("../query/CompanyLocData-pl.cgi", reqstr, OList, KList, KList.length); var cindex = 0; var eindex = 0; ctext = ""; rtext = ""; if (pfdata == void 0 || pfdata == null || pfdata.length == 0) { var http; var Activex; // Do not try if we did not come from server if (window.location.protocol.indexOf ("http") < 0) { return (0); } if (window.XMLHttpRequest && !window.ActiveXObject){ // If IE7, IE8, Mozilla, Safari, etc: Use native object http = new XMLHttpRequest(); Activex = false; } else if (window.ActiveXObject){ // ...otherwise, use the ActiveX control for IE5.x and IE6 http = new ActiveXObject("Microsoft.XMLHTTP"); Activex = true; } if (http != null || (bsniff.ie55 || bsniff.ie6 || bsniff.ie7 || bsniff.ie8) && !bsniff.mac) { if (Activex) { // var http = new ActiveXObject("Microsoft.XMLHTTP"); http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; } else { rtext = http.statusText; ctext = http.responseText; if (ctext.indexOf (" 0) { cindex = ctext.indexOf ("\n"); if (cindex > 0) { var comboline = ctext.substring (0, cindex); eindex = comboline.indexOf ("="); if (eindex > 0) { key = comboline.substring (0, eindex); val = comboline.substring (eindex+1); for (J = 0; J < len; J++) { if (KeyList[J].toLowerCase() == key.toLowerCase()) { if (ObjList[J] != null && (typeof ObjList[J]) == "object") { if (ObjList[J].type == "checkbox") { if (val == "1" || val.toLowerCase() == "true" || val.toLowerCase() == "y") { ObjList[J].value = "1"; ObjList[J].checked = true; } else { ObjList[J].value = "0"; ObjList[J].checked = false; } } else { val = val.replace (/\\r/g, "\r"); val = val.replace (/\\n/g, "\n"); if (ObjList[J].tagName == "P") ObjList[J].innerText = val; ObjList[J].value = val; } } break; } } } ctext = ctext.substring (cindex+1); } } return (1); } function _submitData (qURL, rStr) { // _submitData ("../scripts/CompanySaveData-pl.cgi", reqstr); ctext = ""; rtext = ""; var http; var Activex; // Do not try if we did not come from server if (window.location.protocol.indexOf ("http") < 0) { return (false); } if (window.XMLHttpRequest && !window.ActiveXObject){ // If IE7, IE8, Mozilla, Safari, etc: Use native object http = new XMLHttpRequest(); Activex = false; } else if (window.ActiveXObject){ // ...otherwise, use the ActiveX control for IE5.x and IE6 http = new ActiveXObject("Microsoft.XMLHTTP"); Activex = true; } if (http != null || (bsniff.ie55 || bsniff.ie6 || bsniff.ie7 || bsniff.ie8) && !bsniff.mac) { if (Activex) { // var http = new ActiveXObject("Microsoft.XMLHTTP"); http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; } else { rtext = http.statusText; ctext = http.responseText; if (ctext.indexOf ("") { if (_SelectQuery[FieldName] == null) { _SelectQuery[FieldName] = new Object; } _SelectQuery[FieldName][TestColumn] = "> \'" + CriteriaSrc.substr(1) + "\'"; } else if (srch.substr(0,1) == "<") { if (_SelectQuery[FieldName] == null) { _SelectQuery[FieldName] = new Object; } _SelectQuery[FieldName][TestColumn] = "< \'" + CriteriaSrc.substr(1) + "\'"; } else if (srch.substr(0,1) == "!") { if (srch.indexOf("=") == 1) { if (UCsrch.indexOf("NULL") == 2) { if (_SelectQuery[FieldName] == null) { _SelectQuery[FieldName] = new Object; } _SelectQuery[FieldName][TestColumn] = "IS NOT NULL"; } } else if (UCsrch.indexOf("LIKE ") == 1) { if (_SelectQuery[FieldName] == null) { _SelectQuery[FieldName] = new Object; } _SelectQuery[FieldName][TestColumn] = "NOT LIKE \'" + CriteriaSrc.substr(6) + "\'"; } else _SelectQuery[FieldName][TestColumn] = "!= \'" + CriteriaSrc.substr(1) + "\'"; } eval ("InitSele_" + FieldName + "(0)"); } function RemoveSelectCriteria (FieldName, TestColumn) { // This function will parse the input Criteria and build the // where clause for selecting the subset of input requested. // Arguments: // 1. FieldName -- Name of the select list field // 2. TestColumn -- Column name in datatable that is tested // // Test if criteria exists already if (_SelectQuery[FieldName] != null) { if (_SelectQuery[FieldName][TestColumn] != null) _SelectQuery[FieldName][TestColumn] = ""; } eval ("InitSele_" + FieldName + "(0)"); } function _setValue (Fld, Val) { if (PlainPagePrint == 0) { var _frm = document.forms[0]; } else { var _frm = document.forms[0].name; } if (_frm[Fld] != null && (typeof _frm[Fld]) == "object") { if (_frm[Fld].type == "checkbox") { if (Val == "1" || Val.toLowerCase() == "on" || Val.toLowerCase() == "true" || Val.toLowerCase() == "y" || Val.toLowerCase() == "yes") { _frm[Fld].value = "1"; _frm[Fld].checked = true; } else { _frm[Fld].value = "0"; _frm[Fld].checked = false; } } else { if (_frm[Fld].tagName == "P") _frm[Fld].innerText = Val; _frm[Fld].value = Val; } } } function _buildSendAll () { var reqstr = ""; for (fld in _ThisForm) { if (document.getElementById (fld) != null) { if (_ThisForm[fld].type != "button") { if (reqstr.length) { reqstr += "&"; } if (_ThisForm[fld].type == "checkbox") { var C = _ThisForm[fld].name; if (_ThisForm[fld].checked) { reqstr += C + "=on&"; } else { reqstr += C + "=off&"; } reqstr += C.substring (0, C.length - 3); // remove "(0)" if (_ThisForm[fld].checked) { reqstr += "=1"; } else { reqstr += "=0"; } } else { reqstr += _ThisForm[fld].name + "=" + escape(_ThisForm[fld].value); } } } } return (reqstr); }