function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {onClick="updateText('test.html');"
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/  
  
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function NRequest(url, verb, func, formdata, asXML, id, four04) {
	var x= getHTTPObject();
	this.request = x;
	this.request.open(verb, url, true); 
	
    this.request.onreadystatechange = function () {
	        //*  0 (uninitialized)
    		//* 1 (loading)
    		//* 2 (loaded)
    		//* 3 (interactive)
    		//* 4 (complete) 
    	
	    if (x.readyState == 4) {
            if (x.status == 200) {
		if ( func !== null) {
			if (asXML) {
				func(x.responseXML, id);
			} else {
				func(x.responseText, id);
			}
		} else {
			alert("200 OK");	
		}
            } 
            else if (x.status == 404) {
	            if ( four04 !== null ) {
		         	four04(x.responseText);   
	            } else {
	            	alert( url + ' not found (404)');
            	    }
            }
            else {
                alert('There was a problem with the request.');
            }
        }
    } 

    	if ( verb == "POST") {
		// formdata takes the form key=val&key2=val2, etc
		this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.request.setRequestHeader("Content-length", formdata.length);
		this.request.setRequestHeader("Connection", "close");
		this.request.send(formdata);
	} else {	
    	this.request.send(null);
	}
		
}

function addEventHandler(node, type, f) {
	node["on" + type] = f;
}
