/********************************
 * Funktionen für AJAX Zugriffe *
 ********************************/ 
function createXMLHttp() {
   if (typeof XMLHttpRequest != 'undefined') {
      return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
      var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp","MSXML2.XmlHttp.3.0", "MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.5.0"];
      for (var i = avers.length -1; i >= 0; i--) {
         try {
            httpObj = new ActiveXObject(avers[i]);
            return httpObj;
         } catch(e) {
         }
      }
   }
   return false;
}

function doAsyncAjaxCall (url, obj, type) {
   var separator = "?";
   var ind = url.indexOf ("?");
   if (ind >= 0) {
      separator = "&";
   }
   url += separator + "ContentType=text/html";
   callAjax (url, true, obj, type);
}

function doSyncAjaxCall (url) {	
   //return callAjax (url + "?ContentType=text/plain", false);   
   return callAjax (url , false);
}

function callAjax (url, doAsynchronous, obj, type) {
//alert ("doing " + ((doAsynchronous)?"a":"") + "synchronous AJAX call '" + url + "', type='" + type + "'");
   if (!type) {
      type = "innerHTML";
   }
   try {
      var xmlHttp = createXMLHttp();
      if (xmlHttp) {
         xmlHttp.open('GET', url, doAsynchronous);
         xmlHttp.setRequestHeader("enctype", "application/x-www-form-urlencoded");
         if (doAsynchronous) {
            xmlHttp.setRequestHeader("Content-Type", "text/html");
            xmlHttp.setRequestHeader("Pragma", "no-cache"); 
            xmlHttp.setRequestHeader("Cache-Control", "no-cache, must-revalidate"); 
            xmlHttp.onreadystatechange = function () {
               if (xmlHttp.readyState == 4) {
//alert ("retrieved answer for async AJAX call '" + url + "': " + xmlHttp.responseText);
                  if (type == 'innerHTML') {
                     obj.innerHTML = xmlHttp.responseText.replace(/ +/g, ' ').replace(/^\s+/g, '').replace(/\s+$/g, '');  // = "trim()", replaced it since the Praxisvermittlung had a problem to call "trim()"
                  } else if (type == 'doNothing') {
                     // do nothing, just hope that this call did what it should have done
                  }
               }
            };
         } else {
            xmlHttp.setRequestHeader("Content-Type", "text/plain");
         }
         
         xmlHttp.send(null);         
      }
      if (!doAsynchronous) {
      
         var retStr = xmlHttp.responseText;
         retStr = retStr.replace(/^\s*(.*)\s*$/,"$1"); // trim() schmeisst Exception, deshalb ueber regex...         
            
		//alert ("xml=" + xmlHttp.responseXML.xml)
		//alert ("retrieved answer for sync AJAX call '" + url + "': '" + retStr + "'");
         return retStr;
      }
   } catch(except) {
      alert ("Error callAjax(): " + except.toString());
      return false;
   }
}
function openPopup(url, title, params, id){
	doSyncAjaxCall("/servlet/PB/menu/"+id+"_pwebco/index.html?param5="+escape(url)+"&param6="+escape(id));
	window.open(url, title, params);
}
function openWindow(url, title, params, id){
	doSyncAjaxCall("/servlet/PB/menu/"+id+"_pwebco/index.html?param5="+escape(url)+"&param6="+escape(id));
	window.location = url;
}
function popup (url, title, width, height) {
   window.open (url, title, 'location=yes,menubar=no,scrollbars=yes,toolbar=yes,status=no,resizable=yes,width='+width+',height='+height);
}

