/* 
 -- CallTask(): Calls server end returns result as a string 
 -- tested across broweser platforms and in keeping with current specs
 -- Written by Ed Sanford of ODI Consulting (c) 1996-2008 all rights reserved
 -- modifications: (c) 1998,2000,2004,2007,2008,2009  all rights reserved
 -- usage example: var serverTime=CallTask('/utiltiy/time.cfm');
 ... notes: 
 		created 1998 using document.write('script src=...')
 		replace document.write with innerHTML+= ...  (es 2000)
 		innerHTML+="&lt;script src=...&gt;&lt;/script&gt;" with XMLHttpRequest() (es 2004)
 		remove unneeded eval() option on result of XMLHttpRequest() (es 2007)
 		update comments (es 2008)
 		getHTTPObject added for better backward compatibility (es 2009)
*/

function getHTTPObject() { 

  var xmlhttp;


    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/
      }



  return xmlhttp;

}

/* Simple Trim function for convenience */
function Trim(pcString){return pcString.replace(/(^\s*)|(\s*$)/g,'')}

/* 
 -- CallTask(): Calls server end returns result as a string 
 -- tested across broweser platforms and in keeping with current specs
 -- Written by Ed Sanford of ODI Consulting (c) 1996-2008 all rights reserved
 -- modifications: (c) 1998,2000,2004,2007,2008  all rights reserved
 -- note: most recent modification was to increase simplification by removing the exec/noexec option
 --		 not only returns litteral string from server
 --      those wishing to execute returned code may do so by passing result to exec()
 
 -- usage example: var serverTime=CallTask('/utiltiy/time.cfm');
*/
function CallTask(pcTask){var loClient = getHTTPObject();loClient.open("GET", pcTask,false);loClient.send(null);return loClient.responseText}

/* New as of 09/03/10 - ejs - added simple ability to populate a div in background, some tweaking/testing may yet be needed */
/* New as of 05/20/11 - ejs - added post support to callTaskDiv, added custom callback support passes request and div to callback function */
CalledTasks=new Object();CallTaskOnChange="req.onreadystatechange=function(){CallTaskStateChange";
CallBacks=new Object();CallTaskPost="application/x-www-form-urlencoded";
function CallTaskStateChange(d){var req=CalledTasks[d];if(req.readyState == 4){var o=document.getElementById(d);if(o)o.innerHTML=req.responseText;var f=CallBacks[d];if(f)f(req,d)}}
function CallTaskDiv(pcTask,pcDiv,pcParms,pfCallBack)
{	var req=CalledTasks[pcDiv]=getHTTPObject();
	eval(CallTaskOnChange+"('"+pcDiv+"')}");
	req.open((pcParms?"POST":"GET"), pcTask,true);
	if(pcParms) req.setRequestHeader("Content-type", CallTaskPost);
	req.send(pcParms?pcParms:"")
}

