// --------------- AJAX-Initialisierung
var ajax = false;
if(window.XMLHttpRequest)  // Mozilla, Safari,...
   ajax = new XMLHttpRequest();
else if(window.ActiveXObject) { // IE
   try {
      ajax = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e) {
      try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {}
   }
}
// Ende AJAX-Initialisierung
 
// ------------------------------------- 
function do_http_get_request(type, url, output_id) {   
   if(!ajax)
          return false;
   ajax.onreadystatechange = function() {
      if(ajax.readyState == 4) {
         if(ajax.status == 200) {
                        if(type == "text")
               handle_text_response(ajax.responseText, output_id);
                         else if(type == "xml")
               handle_xml_response(ajax.responseXML, output_id);
                 }
             else
                return false;
      }
          else
             return false;
   } 
   ajax.open('GET', url, true);
   ajax.send(null);
}
 
// ------------------------------------- 
function do_http_post_request(type, url, post_field_ids, output_id) {   
   if(!ajax)
          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);
   ajax.onreadystatechange = function() {
      if(ajax.readyState == 4) {
         if(ajax.status == 200) {
                        if(type == "text")
               handle_text_response(ajax.responseText, output_id);
                        else if(type == "xml")
               handle_xml_response(ajax.responseXML, output_id);
                 }
             else
                return false;
      }
          else
             return false;
   } 
   ajax.open('POST', url, true);
   ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   ajax.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(content, output_id) {
   if(!document.getElementById)
      return false;
   if(!document.getElementById(output_id))
          return false;
   if(xml_response_handler)
          xml_response_handler(ajax.responseXML, output_id);
}
