// Amgraf, Inc. // OneForm Designer Plus // Iform Server Database Access JavaScript Include Functions // // Revision History: // 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. // 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 rtext = ""; var comboline = ""; var ctext = ""; var rtext = ""; var http; var Activex; if (window.XMLHttpRequest){ // If IE7, 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.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; alert ("_initSelection:" + rStr + "\r\n" + rtext); return; } } else { http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; // alert ("No Applet: _initSelection:" + rStr + "\r\n" + rtext); } else { rtext = http.statusText; alert ("_initSelection:" + rStr + "\r\n" + rtext); return; } } } else { // Use the applet code instead if (bsniff.mac && MacCompatAllowed == 1) { // Save all select lists _saveSelectLists (_msldata); var lastfocusObj = document.getElementById ('_MACH_lastfocus'); if (lastfocusObj != null) lastfocusObj.value = _FormLastFocus; var callbackObj = document.getElementById ('_MACH_callback'); if (callbackObj != null) callbackObj.value = callback; var scriptObj = document.getElementById ('_MACH_script'); if (scriptObj != null) scriptObj.value = qURL; var requestObj = document.getElementById ('_MACH_reqstr'); if (requestObj != null) requestObj.value = rStr; var blineObj = document.getElementById ('_MACH_bline'); if (blineObj != null) blineObj.value = bLine; var selectObj = document.getElementById ('_MACH_selectlist'); if (selectObj != null) selectObj.value = comboObj.id; var DiagsObj = document.getElementById ('_MACH_diags'); DiagsObj.value = "0"; SetSubmitDateTime (); document.forms[0].action = "save_req04-pl.cgi"; document.forms[0].target = "_self"; document.forms[0].submit(); } else { // Use the applet code var rURL = qURL; if (rStr.length) rURL += "?" + rStr; ctext = document.getURL.fetch (rURL, null); if (bsniff.mozilla && !bsniff.firefox) { var z = ctext.substr(4); ctext = z + "\n"; } else { ctext += "\n"; } } } _VList.length = _TList.length = cline; _VList[cline-1] = _TList[cline-1] = ""; while (ctext.length > 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]; } } } 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: initSelection ("../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 rtext = ""; var comboline = ""; var ctext = ""; var rtext = ""; var cCnt = 0; var http; var Activex; if (window.XMLHttpRequest){ // If IE7, 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.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; alert ("_initSelectionStep:" + rStr + "\r\n" + rtext); return; } } else { http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; // alert ("No Applet: _initSelectionStep:" + rStr + "\r\n" + rtext); } else { rtext = http.statusText; alert ("_initSelectionStep:" + rStr + "\r\n" + rtext); return; } } } _VList.length = _TList.length = cline; _VList[cline-1] = _TList[cline-1] = ""; while (ctext.length > 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]; } } } } 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; var ctext = ""; var rtext = ""; if (pfdata == void 0 || pfdata == null || pfdata.length == 0) { var http; var Activex; if (window.XMLHttpRequest){ // If IE7, 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; } //alert ("http: " + http); //alert ("activex: " + Activex); if (http != null || (bsniff.ie55 || bsniff.ie6 || bsniff.ie7) && !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; alert ("_InitDependentFields:" + rStr + "\r\n" + rtext); return; } } else { http.open ("POST", qURL, false); //alert ("http.open " + http.readyState); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); //alert ("http.setRequestHeader " + http.readyState); http.send (rStr); //alert ("http.send " + http.readyState); if (http.status == 200) { ctext = http.responseText; //alert ("No Applet: _InitDependentFields:\r\n" + qURL + "\r\n" + rStr + "\r\n" + ctext); } else { rtext = http.statusText; alert ("_InitDependentFields Error:\r\n" + qURL + "\r\n" + rStr + "\r\n" + rtext); return; } } } else { // Use the applet code instead if (bsniff.mac && MacCompatAllowed == 1) { // Save all select lists _saveSelectLists (_msldata); var lastfocusObj = document.getElementById ('_MACH_lastfocus'); if (lastfocusObj != null) lastfocusObj.value = _FormLastFocus; var scriptObj = document.getElementById ('_MACH_script'); if (scriptObj != null) scriptObj.value = qURL; var requestObj = document.getElementById ('_MACH_reqstr'); if (requestObj != null) requestObj.value = rStr; var OlistObj = document.getElementById ('_MACH_objlist'); OlistObj.value = ""; var KlistObj = document.getElementById ('_MACH_keylist'); KlistObj.value = ""; var DiagsObj = document.getElementById ('_MACH_diags'); DiagsObj.value = "0"; var callbackObj = document.getElementById ('_MACH_callback'); if (callbackObj != null) callbackObj.value = callback; for (var dindex = 0; dindex < len; dindex++) { KlistObj.value += KeyList[dindex] + "\n"; OlistObj.value += ObjList[dindex].name + "\n"; } SetSubmitDateTime (); document.forms[0].action = "save_req04-pl.cgi"; document.forms[0].target = "_self"; document.forms[0].submit(); } else { var rURL = qURL; if (rStr.length) rURL += "?" + rStr; ctext = document.getURL.fetch (rURL, null); if (bsniff.mozilla && !bsniff.firefox) { var z = ctext.substr(4); ctext = z + "\n"; } else { ctext += "\n"; } } } } else { ctext = pfdata; } if (ctext.length < 2) return; while (cindex < len) { if (ObjList[cindex] != null && (typeof ObjList[cindex]) == "object") { if (ObjList[cindex].tagName == "P") ObjList[cindex].innerText = ""; else ObjList[cindex].value = ""; } cindex++; } while (ctext.length > 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); } } } function _submitData (qURL, rStr) { // _submitData ("../scripts/CompanySaveData-pl.cgi", reqstr); var rtext = ""; var http; var Activex; if (window.XMLHttpRequest){ // If IE7, 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.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; alert ("_submitData:" + rStr + "\r\n" + rtext); return; } } else { http.open ("POST", qURL, false); http.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); http.send (rStr); if (http.status == 200) { ctext = http.responseText; // alert ("No Applet: _submitData:" + rStr + "\r\n" + rtext); } else { rtext = http.statusText; alert ("_submitData:" + rStr + "\r\n" + rtext); return; } } } else { // Use the applet code instead var rURL = qURL; if (rStr.length) rURL += "?" + rStr; ctext = document.getURL.fetch (rURL, null); if (bsniff.mozilla && !bsniff.firefox) { var z = ctext.substr(4); ctext = z + "\n"; } else { ctext += "\n"; } } if (ctext.substring (0, 1) == "0") retcode = false; else retcode = true; return (retcode); } function _setValue (Fld, Val) { if (PlainPagePrint == 0) { var _frm = document.forms[0]; } else { var _frm = index_sig; } 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 (_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); }