/*
* This module is the vitabytes ajax communication module.
* written by Kaveh Raji - Vitabytes - 2007 - info@vitabytes.de
* ver. 1.3.0
* In this version there also exists the opportunity to
* send an command with the responseTXT which will be evaluated.
* if you want to send an alert command then you should
* integrate the following txt into your txt sent by your server:
* ###!alert('hallo');!###
* The ###! & !### are acting as seperators.
*/


var LoadingPic="<img src='Images/loading.gif'>";
var resObject=null;

function getRequestObject()
{
var resObject=null;

try
{
 resObject = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(Error)
{
  try
   {
    resObject = new ActiveXObject("MSXML2.XMLHTTP"); 
   }
  catch(Error)
   {
    try
     {
      resObject = new XMLHttpRequest();
     }
    catch(Error)
     {
      alert("Konnte Requestobjekt nicht erstellen");
     }
   }
}

return resObject;

}



//This is the function which has to be called whenever
//a request shall be proceeded.
function sndReq(ActionID,Param,Url,Obj)
{

var DocObj;

this.DocObj=Obj;

 document.getElementById(this.DocObj).innerHTML=LoadingPic;
if(resObject.readyState==4 || resObject.readyState==0)
{
querystring="";

querystring="ActionID="+ActionID+"&Param="+Param;


 resObject.open("POST",Url,true);

resObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
resObject.setRequestHeader("POST", Url+" HTTP/1.1");

  this.handleReqObject=handleReqObject;
  resObject.onreadystatechange=this.handleReqObject;
  resObject.send(querystring);

}
}



function sndReq2(ActionID,Param,Url,Obj)
{

var DocObj;

this.DocObj=Obj;

 document.getElementById(this.DocObj).innerHTML=LoadingPic;

//if(resObject.readyState==4)
{
querystring="";

querystring="ActionID="+ActionID+"&Param="+Param;


 resObject.open("POST",Url,true);

//resObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
resObject.setRequestHeader("Content-Type", "multipart/form-data");
resObject.setRequestHeader("POST", Url+" HTTP/1.1");

  this.handleReqObject=handleReqObject;
  resObject.onreadystatechange=this.handleReqObject;
  resObject.send(querystring);

}
}




function handleReqObject()
 {
  if(resObject.readyState==4)
    {
         var resTxt=resObject.responseText;
         var FirstPos=resTxt.indexOf("###!");
         if(FirstPos > -1)
          {
           var SecondPos=resTxt.indexOf("!###");
           var Command=resTxt.substring(FirstPos+4,SecondPos);
           resTxt=resTxt.substring(SecondPos+4,resTxt.length);
          }
         document.getElementById(DocObj).innerHTML=resTxt;
         eval(Command);
    }
 }


/*
* This function will show a given Div - x Object determined by its name PopupName
* at the determined position
*/
function show_popup(PopupName,PosX,PosY)
 {
  

  dobj = document.getElementById(PopupName);
  dobj.style.left=PosX +"px";
  dobj.style.top=PosY +"px";
  dobj.style.display="block";
 }


/*
* This function hides a popup determined by its name
*/
function close_popup(PopupName)
 {

  dobj = document.getElementById(PopupName);
  dobj.style.display="none";
 }


resObject=getRequestObject();
