support zip5 tax lookups, correct errors with fixed format cch import, inital import...
[freeside.git] / httemplate / elements / ajaxcontentmws.js
diff --git a/httemplate/elements/ajaxcontentmws.js b/httemplate/elements/ajaxcontentmws.js
new file mode 100644 (file)
index 0000000..9177049
--- /dev/null
@@ -0,0 +1,185 @@
+/*\r
+ ajaxcontentmws.js - Foteos Macrides (author and Copyright holder)\r
+    Initial: June 22, 2006 - Last Revised: March 24, 2008\r
+ Wrapper function set for getting and using the responseText and / or\r
+ responseXML from a GET or POST XMLHttpRequest, which can be used to\r
+ generate dynamic content for overlib or overlib2 calls, or to modify\r
+ the content of a displayed STICKY popup dynamically.\r
+\r
+ For GET Use:\r
+       onmouseover="return OLgetAJAX(url, command, delay, css);"\r
+       onmouseout="OLclearAJAX();"  (if delay > 0)\r
+ or:\r
+       onclick="OLgetAJAX(url, command, 0, css); return false;"\r
+ or:\r
+       onload="OLgetAJAX(url, command, 0, css);\r
\r
+ Where:\r
+       url (required)\r
+ is a quoted string, or unquoted string variable name or array entry, with\r
+ the full, relative, or partial URL for a file or a server-side script (php,\r
+ asp, or cgi, e.g. perl), and may have a query string appended (e.g.,\r
+ 'http://my.domain.com/scripts/myScript.php?foo=bar&life=grand').\r
+ And:\r
+       command (required)\r
+ is the function reference (unquoted name without parens) of a function to\r
+ be called when the server's response has been received (it could instead be\r
+ an inline function, i.e., defined within the 2nd argument, or a quoted string\r
+ for a function with parens and any args)\r
+ And:\r
+       delay (may be omitted unless css is included)\r
+ is an unquoted number indicating the number of millisecs to wait before\r
+ initiating an XMLHttpRequest GET request. It should be 0 when using onclick\r
+ or onload, but may be a modest value such as 300 for onmouseover to avoid\r
+ any chatter of requests. When used with onmouseover, include:\r
+       onmouseout="OLclearAJAX();"\r
+ to clear the request if the user does not hover for at least that long.  If\r
+ the popup is not STICKY, include an nd or nd2 call, e.g.,\r
+       onmouseout="OLclearAJAX(); nd();"\r
+ And:\r
+       css (may be omitted)\r
+ is a quoted string with the CSS class (e.g. 'ovfl510' for\r
+ .ovfl510 {width:510px; height:145px; overflow:auto; ...} ) for a div to\r
+ encase the responseText and set the width, height and scrollbars in the\r
+ main text area of the popup, or the unquoted number 0 if no encasing div\r
+ is to be used.\r
+\r
+ For POST substitute OLpostAJAX(url, qry, command, delay, css);\r
+ Where\r
+       qry (required)\r
+ is the string to be posted, typically a query string (without a lead ?)\r
+ and the other arguments are as above.\r
+\r
+ See http://www.macridesweb.com/oltest/AJAX.html for more information.\r
+*/\r
+\r
+// Initialize our global variables for this function set.\r
+var OLhttp=false,OLcommandAJAX=null,OLdelayidAJAX=0,OLclassAJAX='',\r
+OLresponseAJAX='',OLabortAJAX=0,OLdebugAJAX=0;\r
+\r
+// Create a series of wrapper functions (e.g. OLcmdT#() for  ones which\r
+// use OLhttp.responseText via the OLresponseAJAX global, and OLcmdX#()\r
+// for ones which use OLhttp.responseXML) whose reference (unquoted name\r
+// without parens) is the 2nd argument in OLgetAJAX(url,command,delay,css)\r
+// calls.  This one is for the first example in the AJAX.html support\r
+// document, to use the OLresponseAJAX global as the lead argument for an\r
+// overlib popup. Put your functions in the head, or in another imported\r
+// .js file, so that they will not be affected by updates of this .js file.\r
+//\r
+function OLcmdExT1() {\r
+ return overlib(OLresponseAJAX, TEXTPADDING,0, CAPTIONPADDING,4,\r
+  CAPTION,'Example with AJAX content via <span '\r
+  +'class="yellow">responseText</span>.&nbsp; Popup scrolls with the window.',\r
+  WRAP, BORDER,2, STICKY, CLOSECLICK, SCROLL,\r
+  MIDX,0, RELY,100,\r
+  STATUS,'Example with AJAX content via responseText of XMLHttpResponse');\r
+}\r
+\r
+// Alert for old browsers which lack XMLHttpRequest support. \r
+function OLsorryAJAX() {\r
+ alert('Sorry, AJAX is not supported by your browser.');\r
+ return false;\r
+}\r
+\r
+// Check 2nd arg for function\r
+function OLchkFuncAJAX(ar){\r
+ var t=typeof ar;return (((t=='function'))||((t=='string')&&(/.+\(.*\)/.test(ar))));\r
+}\r
+\r
+// Alert for bad 2nd argument\r
+function OLnotFuncAJAX(m) {\r
+  if(over)cClick();\r
+  alert('The 2nd arg of OL'+m+'AJAX is not a function reference, nor an inline function, '\r
+  +'nor a quoted string with a function indicated.');\r
+  return OLclearAJAX();\r
+}\r
+\r
+// Alert for indicating an XMLHttpRequest network error.\r
+function OLerrorAJAX() {\r
+ if(OLhttp.status&&OLhttp.status!=2147746065)alert('Network error '+OLhttp.status+'. Try again later.');\r
+ return false;\r
+}\r
+\r
+// Returns a new XMLHttpRequest object, or false for older browsers\r
+// which did not yet support it.  Called as OLhttp=OLnewXMLHttp() via\r
+// the OLgetAJAX(url,command,delay,css) wrapper function.\r
+//\r
+function OLnewXMLHttp() {\r
+ var f=false,req=f;\r
+ if(window.XMLHttpRequest)eval(new Array('try{',\r
+ 'req=new XMLHttpRequest();','}catch(e){','req=f;','}').join('\n'));\r
+ /*@cc_on @if(@_jscript_version>=5)if(!req)\r
+ eval(new Array('try{','req=new ActiveXObject("Msxml2.XMLHTTP");',\r
+ '}catch(e){','try{','req=new ActiveXObject("Microsoft.XMLHTTP");',\r
+ '}catch(e){','req=f;','}}').join('\n')); @end @*/\r
+ return req;\r
+}\r
+\r
+// Handle the OLhttp.responseText string from the XMLHttpRequest object.\r
+function OLdoAJAX() {\r
+ if(OLhttp.readyState==4){\r
+  if(OLdebugAJAX)alert(\r
+    'OLhttp.status = '+OLhttp.status+'\n'\r
+   +'OLhttp.statusText = '+OLhttp.statusText+'\n'\r
+   +'OLhttp.getAllResponseHeaders() = \n'\r
+   +OLhttp.getAllResponseHeaders()+'\n'\r
+   +'OLhttp.getResponseHeader("Content-Type") = '\r
+   +OLhttp.getResponseHeader("Content-Type")+'\n');\r
+  if(OLhttp.status==200||(OLhttp.status==0&&!OLabortAJAX&&!OLie55)){\r
+   OLresponseAJAX=OLclassAJAX?'<div class="'+OLclassAJAX+'">':'';\r
+   OLresponseAJAX += OLhttp.responseText;\r
+   OLresponseAJAX += OLclassAJAX?'</div>':'';\r
+   if(OLdebugAJAX)alert('OLresponseAJAX = \n'+OLresponseAJAX);\r
+   OLclassAJAX=0;\r
+   return (typeof OLcommandAJAX=='string')?eval(OLcommandAJAX):OLcommandAJAX();\r
+  }else{\r
+   OLclassAJAX=0;\r
+   OLabortAJAX=0;\r
+   return OLerrorAJAX();\r
+  }\r
+ }\r
+}\r
+\r
+// Actually make the request initiated via OLgetAJAX or OLpostAJAX, or\r
+// invoke a "permission denied" alert if a cross-domain URL was used.\r
+function OLsetAJAX(url,qry) {\r
+ if(window.location.protocol.indexOf('http')==0&&\r
+ (url.indexOf('file:')==0||url.indexOf('ftp:')==0)){\r
+ alert('[object Error]\n(Cross-domain access not permitted)');return false;}\r
+ qry=(qry||null);var s='',m=(qry)?'POST':'GET';OLabortAJAX=0;\r
+ OLdelayidAJAX=0;eval(new Array('try{','OLhttp.open(m,url,true);',\r
+ '}catch(e){','s=e','OLhttp=false;','}').join('\n'));if(!OLhttp){\r
+ alert(s+'\n(Cross-domain access not permitted)');return false;}if(qry)\r
+ OLhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');\r
+ OLhttp.onreadystatechange=OLdoAJAX;\r
+ OLhttp.send(qry);\r
+}\r
+\r
+// Clear or abort any delayed OLsetAJAX call or pending request. \r
+function OLclearAJAX() {\r
+ if(OLdelayidAJAX){clearTimeout(OLdelayidAJAX);OLdelayidAJAX=0;}\r
+ if(OLhttp&&!OLdebugAJAX){OLabortAJAX=1;OLhttp.abort();}\r
+ return false;\r
+}\r
+\r
+// Load a new XMLHttpRequest object into the OLhttp global, load the\r
+// OLcommandAJAX and OLclassAJAX globals, and initiate a GET request\r
+// via OLsetAJAX(url) to populate OLhttp.\r
+function OLgetAJAX(url,command,delay,css) {\r
+ if(!OLchkFuncAJAX(command))return OLnotFuncAJAX('get');\r
+ OLclearAJAX();OLhttp=OLnewXMLHttp();if(!OLhttp)return OLsorryAJAX();\r
+ OLcommandAJAX=command;delay=(delay||0);css=(css||0);OLclassAJAX=css;\r
+ if(delay)OLdelayidAJAX=setTimeout("OLsetAJAX('"+url+"')",delay);\r
+ else OLsetAJAX(url);\r
+}\r
+\r
+// Load a new XMLHttpRequest object into the OLhttp global, load the\r
+// OLcommandAJAX and OLclassAJAX globals, and initiate a POST request\r
+// via OLsetAJAX(url,qry) to populate OLhttp.\r
+function OLpostAJAX(url,qry,command,delay,css) {\r
+ if(!OLchkFuncAJAX(command))return OLnotFuncAJAX('post');\r
+ OLclearAJAX();OLhttp=OLnewXMLHttp();if(!OLhttp)return OLsorryAJAX();\r
+ qry=(qry||0);OLcommandAJAX=command;delay=(delay||0);css=(css||0);OLclassAJAX=css;\r
+ if(delay)OLdelayidAJAX=setTimeout("OLsetAJAX('"+url+"','"+qry+"')",delay);\r
+ else OLsetAJAX(url,qry);\r
+}\r