/*
 * Returns an new XMLHttpRequest object, or false if the browser
 * doesn't support it
 */
function newXMLHttpRequest() {
	var xmlhttp = null;
	if (window.XMLHttpRequest) {
  		xmlhttp = new XMLHttpRequest();
  			if ( typeof xmlhttp.overrideMimeType != 'undefined') {
    			xmlhttp.overrideMimeType('text/xml');
  			}
	} else if (window.ActiveXObject) {
  		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
  		alert('Error getting information, perhaps your browser does not support xmlhttprequests?');
  	}
  		
  	return xmlhttp;
}

function getReadyStateHandler(req, responseXmlHandler) {

   // Return an anonymous function that listens to the XMLHttpRequest instance
   return function () {

     // If the request's status is "complete"
     if (req.readyState == 4) {
       
       // Check that we received a successful response from the server
       if (req.status == 200) {
		 
         // Pass the XML payload of the response to the handler function.
         responseXmlHandler(req.responseXML);

       } else {

         // An HTTP problem has occurred
         alert("HTTP error "+req.status+": "+req.statusText);
       }
     }
   }
 }

//Global XMLHttpRequest variable
var request = null;

// This function loads the specified URL and inserts the result of it (or an error message)
// into the "content" div.  It uses a synchronous XMLHTTPRequest to do so and returns false
// if an error occurs loading the URL.
function loadURL(url){
	// Variable for response content
	var content = '';
	
	// Return value
	var value = false;
	
	// Create an XMLHttpRequest object or ActiveX control
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// If XMLHTTPRequest is supported
	if (request){
		// Set up synchronous request
		request.open("GET", url, false);
		
		// Send synchronous request
		request.send(null);
		
		// Check the status
		if (request.status == 200){
			// Success
			content = request.responseText;
			value = true;
		}
		else{
			// Error
			content = 'Error: ' + request.status + ' ' + request.statusText;
			alert("error:"+content);
		}
	}
	
	// Set the contents of the div
	//document.getElementById("content").innerHTML = content;

	return content;
	
}


