	function ajaxProcessor() {
		this.NUMBER_LIVE_REQS = 0;
		this.process = function(xmldoc) {
			this.searchRoot = xmldoc.getElementsByTagName('feed')[0];
			if(!(this.searchRoot)) {
				return(1);
			}
			this.feedId = getValue(this.searchRoot, 'id');
			this.feedHtml = getValue(this.searchRoot, 'content');
			this.id = "rss"+this.feedId;
			this.element = document.getElementById(this.id);
			if(this.element && this.feedHtml) {
				this.element.innerHTML = this.feedHtml;
			}
			this.NUMBER_LIVE_REQS = this.NUMBER_LIVE_REQS - 1;
			
			try {
				if(queueRequests.length < 1 && this.NUMBER_LIVE_REQS < 1) {
					timer();
				}
			}
			catch(e) {
				
			}
			return(0);
			
		}
	}
	
	var  generic_http_request = false;
	var  generic_http_request2 = false;
	var lastRequest = "";
	var responseCounter = 0;
	var responseObjects = new Array();
	var requestObjects = new Array();
	var globalTimeoutID;
	var isSearching = false;
	var queueRequests = new Array();
	
	
	
	
	var ajaxProcessObj = new ajaxProcessor;
	
	// getValue:
  // This reads the value that's required from the XML.
  function getValue(theElement, isSearchingFor) {
   	 if(!(theElement)) {
   	 	return("");	
   	 }
     var myElement = theElement.getElementsByTagName(isSearchingFor);
     var retVal;
     if(myElement) {
     	if(myElement[0]) {
     		if(myElement[0].firstChild) {
     			retVal = myElement[0].firstChild.nodeValue;
     		}
     	}
     }
     return(retVal);
   }
	
	function _debugMessage() {
		
	}
	
	function updateInfoMessage() {
		
	}
	
	function stopSearching() {
  	loadingDivStop();
  	isSearching = 0;
  	keepSearching = 0;
	}
  
  function startSearching() {
  	loadingDivStart();
  	isSearching = 1;
  	keepSearching = 1;
  }
  
  function loadingDivStart() {
   	var loadingDiv = document.getElementById("loadingDiv");
   	if(globalTimeoutID) {
   		clearTimeout(globalTimeoutID);
   		globalTimeoutID = "";
   	}
   	if(loadingDiv) {
   		//loadingDiv.innerHTML = "Loading...";
   		if(BrowserDetect.browser == "Firefox") {
   			loadingDiv.style.left = "505px";
   			loadingDiv.style.top = "150px";
   		}
   		else {
   			loadingDiv.style.left = "500px";
   			loadingDiv.style.top = "145px";	
   		}
   		//loadingDiv.style.display = "block";
   		//loadingDiv.scrollIntoView();
   		globalTimeoutID = setTimeout("stopSearching()", 5500);
   	}
   	else {
   		updateInfoMessage("ERROR: NO LOADING DIV");
   	}
   	
  }
  
  function loadingDivStop() {
   	var loadingDiv = document.getElementById("loadingDiv");
   	globalTimeoutID = "";
   	if(loadingDiv) {
			loadingDiv.style.display = "none";
   		loadingDiv.innerHTML = "";
   		loadingDiv.style.top = "100px";
   		loadingDiv.style.left = "200px";
   		
   	}
  }
	
	var _requestNumber = 0;
	function genericRequest(theMethod,theURL, parameters) {
    /*_debugMessage("genericRequest: "+theURL+parameters);*/

    var ajax = new Ajax.Request(
        theURL+parameters,
        {
            method: theMethod,
            parameters: "",
            onFailure: genericAjaxError,
            onSuccess: processGenericResponse
        }
    );
	}

	function genericAjaxError(response) {
    alert("There was an error performing this request - " + response.status + " : " + response.statusText);

    _debugMessage(response.responseText);
	}
 
   
   
  function generic_processResponse() {
 	 // alert contents processes the named file
   //
   		var serializer = new XMLSerializer();
   		
   		try {
   			if(generic_http_request) {
   			
   			}
   		}
   		catch(e) {
   			//alert("argh");
   			generic_http_request = makeGenericXMLHttp();
   		}
   		//alert("in process Response");
      //if(generic_http_request) {
      	if (generic_http_request.readyState == 4) {
      		//alert("1.response ready");
         if (generic_http_request.status == 200) {
         		//Alert("response 100% ready");
	    			stopSearching();
	    			
	    			responseCounter++;
	    			
	    			var generic_xmldoc;
	    			var oDomDoc;
	    				isProcessingUDR = 0;
            	responseObjects[responseCounter] = generic_http_request.responseText;
            	var theText = generic_http_request.responseText;
            	
            	
            	
            	responseObjects[responseCounter] = theText;
            	if(document.location.href.match("lecdbg")) {
            		alert(theText);
            	}
            	//generic_xmldoc = generic_xmldoc.replace("Content-type: application/xml", "");
            	//generic_xmldoc = generic_xmldoc.replace(/Content\-length\: \d+/, "");
            
            	// Generally, on more standard browsers, we'd just use the XML object
            	// that's in the generic_http_request.responseXML
            	// HOWEVER: MS IE has a bug in it, which means that it is unable
            	// to parse it!
            	// - See http://www.quirksmode.org/blog/archives/2005/09/xmlhttp_notes_r_1.html
            	// for more information! Bah!
            	var oDomDoc = Sarissa.getDomDocument();
            	//alert("after oDomDoc");
            	try {
            		var theString = responseObjects[responseCounter];
            		
            		oDomDoc = (new DOMParser()).parseFromString(theString, "text/xml");
            		
            		
            	}
            	catch(e) {
            		// return to pharmsHomePage
            		try {
            			alert("(2) The system was unable to process your request at this time, as your session appears to have timed out. You are now being redirected to the home page.");
            			document.location.href = homeURL;
            		}
            		catch(e) {
            			alert("(2) The system was unable to process your request at this time, as your session appears to have timed out. Please select any link above in order to continue.");
            		}
            		return(0);
            	}
            	
            	if(Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
									// The document was parsed/loaded just fine, go on
									//alert("NOW ITS:"+Sarissa.serialize(oDomDoc));
									//alert(" GET BACK:"+serializer.serializeToString(oDomDoc));
									if(oDomDoc) {
										//oDomDoc = generic_http_request.responseXML;
            				responseObjects[responseCounter] = oDomDoc;
            				
            				
            				processGenericResponse(oDomDoc, responseObjects[responseCounter], responseCounter);
            				
            			}
            			else {
            				alert("(3)The system was unable to process your request");
            				return(0);
            			}
           				
							} 
							else{
								// The document was not loaded correctly! Inform the user:
								//alert("There was an error parsing: "+Sarissa.getParseErrorText(oDomDoc));
								responseObjects[responseCounter] = generic_http_request.responseXML;
								oDomDoc =  generic_http_request.responseXML;
								processGenericResponse(oDomDoc, responseObjects[responseCounter], responseCounter);
								
							};
           		generic_http_request = false;
            
            
            
         } else {
         		loadingDivStop();
         		generic_http_request = false;
            //alert('There was a problem with the request.Status='+generic_http_request.status);
            alert("The system was unable to process your request. (GENERIC)Please try again in a few moments:"+generic_http_request.status);
         }
      //}
    }
      
   	}
   	
   	function processGenericResponse(response) {
   		/* get response text */
   	 var htmlText = response.responseText;

    	/* place holder for DOM object */
    	var generic_xmldoc;

    	/* use Sarissa to parse this object due to IE bugs with XML parseing */
   	 	var oDomDoc = Sarissa.getDomDocument();
    	oDomDoc = (new DOMParser()).parseFromString(htmlText, "text/xml");

    	/* check the document parsed OK and set generic_xmldoc.  if there is a problem throw and error */
	    if(Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
	        if(oDomDoc) {
	             generic_xmldoc = oDomDoc;
	        }
	        else {
	        			generic_xmldoc = response.responseXml;
		            //alert("There was an error parsing the response:");
		            //alert(Sarissa.getParseErrorText(oDomDoc));
		            _debugMessage(htmlText);
		          
	        }
	    }
	    else {
	        
		           //alert("There was an error parsing the response:"+htmlText);
		           //alert(Sarissa.getParseErrorText(oDomDoc));
		           generic_xmldoc = response.responseXml;
		           _debugMessage(htmlText);
		      
	    };

    	var rootNodeName = generic_xmldoc.documentElement.nodeName;
    
   		// new udr responds <new_udr>
   		//
   		var newUdr;
   		
   		
   		
   		if(rootNodeName == "feed") {
   			//alert("filtered_items:"+htmlText);
   			// re-init the num of results for this one.
   			ajaxProcessObj.process(generic_xmldoc);
   		}
   		
   		
   		else {
   			updateInfoMessage("The system encountered a problem (EPARSEGENERIC)"+generic_http_request.responseText);
   		}
   		// clean up the response and request counters.
   		responseObjects[theCounter] = false;
   		
   		
   		
   	}
   	
   	function showRssFeed(id) {
   		
   		if(feedLink.match(/max/)) {
   			feedLinkSend = feedLink + "&feedId="+id;
   		}
   		else {
   			feedLinkSend = feedLink + "?feedId="+id;
   		}
   		
   		queueRequests.push(feedLinkSend);
   			
   		return(false);	
   	}
   	
   	function ajaxOnLoad() {
   		processRequests();
   	}
   	
   	var timeOutID;
   	function processRequests() {
   		var theRequest = queueRequests.pop();
   		if(theRequest) {
   			ajaxProcessObj.NUMBER_LIVE_REQS = ajaxProcessObj.NUMBER_LIVE_REQS+1;
   			//alert("SENT: "+ajaxProcessObj.NUMBER_LIVE_REQS);
   			//alert("SEND: "+theRequest);
   			genericRequest("GET", theRequest, "");
   			timeOutID = setTimeout('processRequests()', 100);
   		}
   		else {
   			if(timeOutID) {
   				clearTimeout(timeOutID);
   				timeoutID = "";
   			}
   		}
   		
   	}
   	
   	
   	
   	

