// written by Francesco Abbattista
// 

var msh_ajax_http_request_objects = new Array();

function msh_ajax()
{
	this.init();
}

msh_ajax.prototype.init = function ()
{
	this.xml_http_request 		 = null;
	this.xml_elements_tagname  = "";
	this.xml_request_datakey	 = ""
	this.xml_request_method		 = "POST";		
	this.xml_request_handler	 = "";
	this.xml_callback_function = null;
	this.xml_request_data      = new Array();
	this.data									 = new Array();
	
	if (window.XMLHttpRequest) {
	  this.xml_http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	  try {
	    this.xml_http_request = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch (ex) {
	    try {
	      this.xml_http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (ex) {
	    }
	  }
	  
	  if ( this.xml_http_request == null ) {
	  	alert("Kein AJAX m?glich! \nBitte verwenden Sie einen aktuellen Browser bzw. vergewissern Sie sich dass Sie Javascript aktiviert haben.");
	  }
	}	
}

msh_ajax.prototype.read = function ()
{
	
	var params = "";
		
	msh_ajax_http_request_objects.push(this.xml_http_request);
  
  if ( this.xml_request_data && this.xml_request_data.length > 0 ) {
  	for ( var i = 0; i < this.xml_request_data.length; i++ ) {

  		params += this.xml_request_data[i];
  	}
  	params = params.substring(1);
  }
	
  if ( this.xml_request_method.toLowerCase() == "post" ) {
		// reads the XML containing all the MARKEN by sending the request via post to the servlet
	  this.xml_http_request.open(this.xml_request_method, this.xml_request_handler, true);
	  
	  if ( this.xml_callback_function != null ) {
		  this.xml_http_request.onreadystatechange = eval(this.xml_callback_function);
		}
		else {
		  this.xml_http_request.onreadystatechange = this.callback;
		}

	  this.xml_http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	this.xml_http_request.send(params);		
	}
	else {
		// reads the XML containing all the MARKEN by sending the request via post to the servlet
	  this.xml_http_request.open(this.xml_request_method, this.xml_request_handler+"?"+params, true);
	  
	  if ( this.xml_callback_function != null ) {
		  this.xml_http_request.onreadystatechange = eval(this.xml_callback_function);
		}
		else {
		  this.xml_http_request.onreadystatechange = this.callback;
		}


  	this.xml_http_request.send(null);		
	}
}

msh_ajax.prototype.clear_params = function ()
{
	this.xml_request_data = new Array();
}

msh_ajax.prototype.add_param = function (key, value)
{
	this.xml_request_data.push( "&" + key + "=" + value );
}

msh_ajax.prototype.add_data = function (something) 
{
	this.data.push( something );
}

msh_ajax.prototype.clear_data = function ()
{
	this.data = new Array();
}

msh_ajax.prototype.callback = function ()
{
		alert("Standard-Callback\nEs wurde noch kein Callback Handler gesetzt, verwenden Sie hierfuer xml_callback_function.");
}