function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();


var var_ajax_action;
var var_ajax_container;
var var_ajax_in_use = 0;


arr_ajax_action = new Array();
arr_ajax_poststr = new Array();
arr_sheriff_container = new Array();
arr_sheriff_open_container = new Array();

function ajaxObject() {
	this.var_ajax_in_use = 0;
	this.var_ajax_action;
	this.var_ajax_poststr;
	this.var_ajax_container_id;
	this.var_ajax_handle_responde_function;
	this.var_response_text;
	this.arr_ajax = new Array();
	
	this.var_ajax_send_time;
	this.var_ajax_receive_time;
	this.var_ajax_end_time;
	
	var thisO = this;
	
	this.getHTTPObject = function() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
	    try {
	      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	      try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (E) {
	        xmlhttp = false;
	      }
	    }
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	    try {
	      xmlhttp = new XMLHttpRequest();
		  xmlhttp.overrideMimeType("text/xml");
	    } catch (e) {
	      xmlhttp = false;
	    }
	  }
	  return xmlhttp;
	}
	this.http = this.getHTTPObject();
	
	this.action = function() {
		return this.var_ajax_action;
	}
	
	this.containerId = function() {
		return this.var_ajax_container_id;
	}
	
	this.getResponseText = function() {
		return this.var_response_text;
	}
	
	this.responseText = function() {
		return this.var_response_text;
	}
	
	this.ajax = function(action, poststr, container_id, handle_responde_function) {
		this.var_ajax_send_time;
		if ( !poststr || !handle_responde_function ) {
			alert('The post string (poststr) which contains the POST data and \nthe function name which has to be called on succeeded responde (handle_responde_function) \nhave to be set!\n\nfunction(action, poststr, container_id, handle_responde_function)');
		} else {
			arr_temp = new Array();
			arr_temp['action'] 						= action;
			arr_temp['poststr'] 					= poststr;
			arr_temp['container_id'] 				= container_id;
			arr_temp['handle_responde_function'] 	= handle_responde_function;
			this.arr_ajax.push(arr_temp);
			this.send();
		}
	}
	
	this.send = function() {
		this.var_ajax_send_time = new Date();
		this.var_ajax_send_time = this.var_ajax_send_time.getTime();
		if ( !this.var_ajax_in_use ) {
			this.var_ajax_in_use = 1;
			this.var_ajax_action = this.arr_ajax[0]['action'];
			this.var_ajax_poststr = this.arr_ajax[0]['poststr'];
			this.var_ajax_container_id = this.arr_ajax[0]['container_id'];
			this.var_ajax_handle_responde_function = this.arr_ajax[0]['handle_responde_function'];
			this.var_ajax_receive_time = new Date();
			this.var_ajax_receive_time = this.var_ajax_receive_time.getTime();
			this.var_ajax_poststr = this.var_ajax_poststr + '&send_time=' + Math.floor(this.var_ajax_send_time);
			//alert(this.arr_ajax[0]['action'] + ' - ' + this.var_ajax_action + '\n' + this.arr_ajax[0]['poststr'] + ' - ' + this.var_ajax_poststr + '\n' + this.arr_ajax[0]['container_id'] + ' - ' + this.var_ajax_container_id + '\n' + this.arr_ajax[0]['handle_responde_function'] + ' - ' + this.var_ajax_handle_responde_function)
			this.arr_ajax.shift();
			this.http.open('POST', 'ajax_receive.php', true);
			this.http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//this.http.setRequestHeader("Content-length", this.var_ajax_poststr.length);
			//this.http.setRequestHeader("Connection", "close");
			this.http.send(this.var_ajax_poststr);
			this.http.onreadystatechange = 	function(){
												if ( thisO.http.readyState == 4 ) {
													thisO.var_ajax_receive_time = new Date();
													thisO.var_ajax_receive_time = thisO.var_ajax_receive_time.getTime();
													thisO.handleResponse();
												}
											};
		}
	}
	
	this.handleResponse = function() {
		//alert('handleResponse_1 '  + '\n' + this + '\n' + this.var_ajax_in_use + '\n' + this.var_ajax_action + '\n' + this.var_ajax_poststr + '\n' + this.var_ajax_container_id + '\n' + this.var_ajax_handle_responde_function)
		//alert('alert vor eval!' + this.var_ajax_handle_responde_function);
		//alert(this.var_ajax_action + '\n' + this.var_ajax_poststr + '\n' + this.var_ajax_container_id + '\n' + this.var_ajax_handle_responde_function)
		this.var_response_text = this.http.responseText;
		//alert(this.var_ajax_handle_responde_function);
		eval(this.var_ajax_handle_responde_function);
		//this.var_ajax_handle_responde_function;
		this.var_ajax_in_use = 0;
		this.var_ajax_end_time = new Date();
		this.var_ajax_end_time = this.var_ajax_end_time.getTime();
		var span_send = this.var_ajax_receive_time - this.var_ajax_send_time;
		var span_calc = this.var_ajax_end_time - this.var_ajax_receive_time;
		//alert("span_send: " + span_send + "\nspan_calc: " + span_calc + "\n" + this.var_ajax_handle_responde_function);
		if ( this.arr_ajax.length > 0 ) {
			this.send();
		}
	}
}

var ajaxRequest = new ajaxObject();