// loadtype, page, id, id2, ....idx, [no_asynch]
function ajaxManager()	{
	var args = ajaxManager.arguments;	
	var go_asynch = true; //used to determine if we're running this asynch
	//here we check our last argument, if it's 'no_asynch' then remove the argument and set
	//go_asynch = false
	if (args[args.length-1] == "no_asynch") {
	    go_asynch = false;
	    args.length = args.length - 1;
	    }
	//see if we have a status field with the element ID of 'ajax_status'
	var hasStatus;
	var ajax_status = document.getElementById("ajax_status");
	if(ajax_status) {
	    hasStatus = true;
	    }
	else { 
	    hasStatus = false; 
	    }
	if (document.getElementById) {
    	var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
	
	if (x) {
	    
	    x.onreadystatechange = function() 
	        {
	        if (x.readyState == 0 && hasStatus) {  
	            ajax_status.innerHTML = "Initializing";
	            }  
	        else if (x.readyState == 1 && hasStatus) {  
	            ajax_status.innerHTML = "Processing Request";
	            }      
	        else if (x.readyState == 2 && hasStatus) {  
	            ajax_status.innerHTML = "Request Acknowledged";
	            }   
	        else if (x.readyState == 3 && hasStatus) {  
	            ajax_status.innerHTML = "Loading Data";
	            }
		    else if (x.readyState == 4 && x.status == 200) {
		        switch (args[0]) {
		            case "load_page":
		                //use this to load any page
						el = document.getElementById(args[2]);
						el.innerHTML = x.responseText;
						break;
				    case "load_page_append":
				        //use this to append any page to the innerHTML
				        el = document.getElementById(args[2]);
				        el.innerHTML += x.responseText;
				        break;
                    case "load_xml_by_element": //given the element itself
                        myXml = x.responseXML;
						for(i=2;i<args.length;i++){
						    args[i].innerHTML = myXml.getElementsByTagName('out'+(i-1))[0].firstChild.data;
						    }
						break;
				    case "load_xml": //given the element ID
				        //use this one to load up an xml file with fields named out1, out2, out3, etc...
				        myXml = x.responseXML;
						for(i=2;i<args.length;i++){
						    document.getElementById(args[i]).innerHTML = myXml.getElementsByTagName('out'+(i-1))[0].firstChild.data;
						    }
						break;
                    case "load_value": //returns a simple value, only one at a time
                        //eval(args[2]+"='"+x.responseText+"';");
                        break;
                    case "load_alert": //returns a simple value to an alert window
                        alert(x.responseTexT);
                        break;
		            }
		        if (hasStatus) { //finish the status then clear it after 1.5 seconds
		            ajax_status.innerHTML = "Process Completed"; 
		            var t=setTimeout("document.getElementById('ajax_status').innerHTML=''",1500)
		            }
		        }
		    } //end function
		x.open("GET", args[1], go_asynch);
		x.send(null);
		}			
	}
