// AJAX-Initialisierung
function init_ajax(ah) { 
   ah = false;
   if(window.XMLHttpRequest)  // Mozilla, Safari,...
      ah = new XMLHttpRequest();
   else if(window.ActiveXObject) { // IE
      try {
         ah = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         try {
            ah = new ActiveXObject("Microsoft.XMLHTTP");
         }
         catch (e) {}
      }
   }
   return(ah);
}


// Ende AJAX-Initialisierung

function do_http_get_request(ah, type, url, output_id) { 
   if(!ah)
      return false;
   ah.onreadystatechange = function() {
      if(ah.readyState == 4) {
         if(ah.status == 200) {
            if(type == "text") 
               handle_text_response(ah.responseText, output_id); 
            else if(type == "xml")
               handle_xml_response(ah, ah.responseXML, output_id);
            else if(type == "value")
               handle_value_response(ah.responseText, output_id);
         }
         else
            return false;
      }
      else
         return false;
   } 
   ah.open('GET', url, true);
   ah.send(null);
}
 
function do_http_post_request(ah, type, url, post_field_ids, output_id) {   
   if(!ah)
      return false;
   var post_field_array = post_field_ids.split("+");
   post_field_str = "";
   for(i = 0; i < post_field_array.length; i++) {
      post_field_id = post_field_array[i];
      post_field_value = document.getElementById(post_field_id).value;
      post_field_str += post_field_id + "=" + encodeURIComponent(post_field_value) + "&";
   }
   if(post_field_str.length > 1)
      post_field_str = post_field_str.substr(0, post_field_str.length - 1);
   ah.onreadystatechange = function() {
      if(ah.readyState == 4) {
         if(ah.status == 200) {
            if(type == "text")
               handle_text_response(ah.responseText, output_id);
            else if(type == "xml")
               handle_xml_response(ah, ah.responseXML, output_id);
            else if(type == "value")
               handle_value_response(ah.responseText, output_id);
         }
         else
            return false;
      }
      else
         return false;
   } 
   ah.open('POST', url, true);
   ah.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   ah.send(post_field_str);
}
 
function do_http_get_request_plus(ah, type, url, output_id, js_code) { 
   if(!ah)
      return false;
   ah.onreadystatechange = function() {
      if(ah.readyState == 4) {
         if(ah.status == 200) {
            if(type == "text") 
               handle_text_response(ah.responseText, output_id); 
            else if(type == "xml")
               handle_xml_response(ah, ah.responseXML, output_id);
            else if(type == "value")
               handle_value_response(ah.responseText, output_id);
            eval(js_code);
	     }
         else
            return false;
      }
      else
         return false;
   } 
   ah.open('GET', url, true);
   ah.send(null);
}
 
function do_http_post_request_plus(ah, type, url, post_field_ids, output_id, js_code) {   
   if(!ah)
          return false;
   var post_field_array = post_field_ids.split("+");
   post_field_str = "";
   for(i = 0; i < post_field_array.length; i++) {
          post_field_id = post_field_array[i];
          post_field_value = document.getElementById(post_field_id).value;
      post_field_str += post_field_id + "=" + encodeURIComponent(post_field_value) + "&";
   }
   if(post_field_str.length > 1)
      post_field_str = post_field_str.substr(0, post_field_str.length - 1);
   ah.onreadystatechange = function() {
      if(ah.readyState == 4) {
         if(ah.status == 200) {
            if(type == "text")
               handle_text_response(ah.responseText, output_id);
            else if(type == "xml")
               handle_xml_response(ah, ah.responseXML, output_id);
            else if(type == "value")
               handle_value_response(ah.responseText, output_id);
            eval(js_code);
		 }
         else
            return false;
      }
      else
         return false;
   } 
   ah.open('POST', url, true);
   ah.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   ah.send(post_field_str);
}
 
function handle_text_response(content, output_id) {
   if(!document.getElementById)
      return false;
   if(!document.getElementById(output_id))
      return false;
   document.getElementById(output_id).innerHTML = content;
} 
 
function handle_xml_response(ah, content, output_id) {
   if(!document.getElementById)
      return false;
   if(!document.getElementById(output_id))
      return false;
   if(xml_response_handler)
      xml_response_handler(ah.responseXML, output_id);
}

function handle_value_response(content, output_id) {
   if(!document.getElementById)
      return false;
   if(!document.getElementById(output_id))
      return false;
   document.getElementById(output_id).value = content;
}


