	/**
	 * Purpose: Called when you need to make AJAX call for getting tool content
     * This method creates XMLHttpRequest object to communicate with the
     * servlet
     */
    function getTool(url, divID)
    {
    	try
    	{
			var httpRequest;
			//alert("getTool(): EPIC_adSection=" + EPIC_adSection+'----');
			if (window.ActiveXObject)
	        {
	            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        else if (window.XMLHttpRequest)
	        {
	            httpRequest = new XMLHttpRequest();
	        }
	        
	        re = '\\?';	
	        myArray = url.match(re);
	        
	        if (typeof(window[ 'EPIC_adSection' ] ) != "undefined" )
	        {
		        if(EPIC_adSection!=''){
					if(myArray!=null && myArray.length>0)        	
						url=url+'&adsec='+EPIC_adSection;
		        	else
		        		url=url+'?adsec='+EPIC_adSection;
		        }
	        }
	        
		// BEGIN: HANDLE POLL TOOL AS THE REQUESTED URL
	        if(url.indexOf("/poll/user.do") > 0)
	        {
	                //COMMENT IN THE FOLLOWING LINE TO DISABLE LIVE POLLS
	                //return false;

               		// HANDLE SITUATION WHEN URL FOR POLL IS EMBEDDED IN CONTENT INCLUDED PAGE
                	url = url.replace('destURL','embedURL');
                	url = url + "&destURL=" + escape(document.location.href);
	        }
	        //END: HANDLE POLL TOOL AS THE REQUESTED URL
	        
	        httpRequest.open("GET", url, true);
	        httpRequest.onreadystatechange = function() {processRequest(divID, httpRequest); } ;
	        httpRequest.send(null);
		}
		catch (err)
		{
			// THERE WAS A GET TOOL ERROR (POSSIBLE 404) IGNORE IT
		}
	}

	/**
     * This is the call back method
     * If the call is completed when the readyState is 4
     * and if the HTTP is successfull when the status is 200
     * update the toolSection DIV
     */
	function processRequest(divID, httpRequest)
	{
    	if (httpRequest.readyState == 4)
        {
        	//alert(httpRequest.status);
            if(httpRequest.status == 200)
            {
                //get the text sent by the url
                var toolText = httpRequest.responseText;
                //alert(toolText);

                //Update the HTML
                updateHTML(toolText, divID);
                
                //allow for callback hook for executing code after getTool completes
                if (typeof getToolHook == 'function') {
                    getToolHook(divID);
                } 
            }
            else
            {
                //alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
            }
        }
	}

	/**
     * This function parses the XML and updates the
     * HTML DOM by creating a new text node is not present
     * or replacing the existing text node.
     */
    function updateHTML(toolText, divID)
    {
        // Get the reference of the DIV in the HTML DOM by passing the ID
        var toolSection = document.getElementById(divID);
        //alert("divID=" + divID); // + ", toolText=" + toolText);
		toolSection.innerHTML = toolText;
		
		var x = toolSection.getElementsByTagName("script");
        for(var i=0;i<x.length;i++)
        {
                var code = x[i].text;
                var dj_global = this; // global scope reference
                if (window.execScript)
                {
                        window.execScript(code); // eval in global scope for IE
                }
                else
                {
                        dj_global.eval(code);
                }
        }
    }
