function Ajax()
{
  this.req = null;
  this.url = null;
  this.method = 'GET';
  this.async = true;
  this.status = null;
  this.statusText = null;
  this.postData = null;
  this.readyState = null;
  this.responseText = null;
  this.responseXML = null;
  this.handleResp = null;
  this.responseFormat = 'text'; // text xml or object
  this.mimeType = null;
  this.isInit = false;
  this.handler = null;
  this.handlerParam = null;
  this.moz = false;
  this.safari = false;

this.init = function()
{
  if(!this.isInit) {
    try {
      // try to create object for Firefox, Safari, IE7, etc
	    this.req = new XMLHttpRequest();
//alert('XMLHttpRequest created');
	}
    catch (e) {
      try {
        // try to create object for later versions of IE
        this.req = new ActiveXObject('MSXML2.XMLHTTP');
//alert('MSXML2.XMLHTTP created');
      }
      catch (e) {
        try {
          // Try to create object for early versions of IE
          this.req = new ActiveXObject('Microsoft.XMLHTTP');
//alert('Microsoft.XMLHTTP created');
        }
        catch (e) {
          // Could not create XMLHTTPRequest object.
//alert("req could not be created");
          return false;
        }
      }
    }
  }
  this.isInit = true;
//alert("req has been created");
  return true;
};

this.doReq = function()
{
//alert("isInit: " + this.isInit);
  if(!(this.isInit || this.init())) {
    this.responseText = 'Unable to initialize ajax doReq.';
    this.handleErr();
    return false;
  }
  if(!this.moz) {
	if(this.url.indexOf('?') > -1) {
	    this.url = this.url + this.ieCache();
    } else {
	  this.url = this.url + '?' + this.ieCache();
    }
  }
//alert('here: ' + this.req);
  this.req.open(this.method, this.url, this.async);
  if(this.method == 'POST') {
    this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencode');
  } else {
  // haven't been able to determine what to set it too here.
//    this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencode');
  }
  if(this.mimeType) {
    try {
      req.overrideMimeType(this.mimeType);
    }
    catch (e) {
      // error overriding mimeType IE6 or Opera???
    }
  }
  var self = this; // Fix loss of scope in inner function
  this.req.onreadystatechange = function() {
    var resp = null; // initialize
	if(self.debug)
		alert("ajax doReq 1; onreadystatechange; readyState: " + self.req.readyState);
    if(self.req.readyState == 4) {
      switch(self.responseFormat) {
        case 'text':
          resp = self.req.responseText;
          break;
        case 'xml':
          resp = self.req.responseXML;
          break;
        case 'object':
          resp = self.req;
          break;
      }
      if(self.req.status >= 200 && self.req.status <300) {
        self.handleResp(resp, self.handler, self.handlerParam);
      } else {
        self.handleErr(resp);
      }
    }
  }; // end anonymous readyStateChange handler function

	this.req.send(this.postData);
	if(!this.async)  {
	  if(this.req.onreadystatechange == null){
	    var resp = null; // initialize
        switch(self.responseFormat) {
          case 'text':
            resp = self.req.responseText;
            break;
          case 'xml':
            resp = self.req.responseXML;
            break;
          case 'object':
            resp = self.req;
            break;
        }
		this.handleResp(resp, this.handler, this.handlerParam);
	  }
	}
};
this.setMimeType = function(mimeType)
{
  this.mimeType = mimeType;
};

this.handleErr = function()
{
  //should we report the error back to the server for logging and analysis?
  var errorWin;
  try {
//    errorWin = window.open('', 'errorWin');
//    errorWin.document.body.innerHTML = this.responseText;
  }
  catch (e) {
/*    alert('An error has occurred, but the error message cannot be displayed.  '
    + 'This is probably because of your browser\'s pop-up blocker.\n'
    + 'Please allow pop-ups from this web site if you want to see the full '
    + 'error messages.\n\n  Status Code: ' + this.req.status + '\n  Status '
    + 'Description: ' + this.req.StatusText);
*/
  }
};

this.abort = function()
{
  if(this.req) {
    this.req.onreadystatechange = function() {};
    this.req.abort();
    this.req = null;
  }
};

this.doGet = function(url, handlerMethod, handler, format, param)
{
  if(!this.init()){
//alert('this.init returned false');
    this.responseText = 'Unable to initialize ajax GET.';
    this.handleErr();
  }
//alert('this.init has run');
  this.method = 'GET';
  this.postData = null; // in case of re-use
  this.url = url;
  this.setHandleResp(handlerMethod);
  this.handlerParam = param;
  this.handler = handler;
  this.responseFormat = format || 'text';
  this.doReq();
};

this.setHandleResp =  function(handlerMethod)
{
	if(handlerMethod == null) {
		// create do-nothing method
		this.handleResp = function(a, b, c) { return true; };
	} else {
		this.handleResp = handlerMethod;
	}
}

this.doPost = function(url, postData, handlerMethod, handler, format, param)
{
  if(!this.init()){
    this.responseText = 'Unable to initialize ajax POST.';
    this.handleErr();
  }
  this.method = 'POST';
  this.postData = postData;
  this.url = url;
  this.setHandleResp(handlerMethod);
  this.handlerParam = param;
  this.handler = handler;
  this.responseFormat = format || 'text';
  this.doReq();
};

this.ieCache = function()
{
  result = "&ie=" + Math.random();
//  result = "&ie=1";//for testing expires header
  return result;
};

function sendFeedbackRequest()
{
  new Ajax.Request("feedback_process.php", {
    method: 'post',
    postBody: "email="+$F("email")+"&feedback="+$F("feedback"),
    onComplete: showFeedbackResponse
  });
}

function showFeedbackResponse(req)
{
	var response = req.responseText;
	$('errors').innerHTML=  response;
	if(response.charAt(13) == 't') {
		document.getElementById('test').style.display = 'none';
	}
};
}

