/* ===========================================================*/
/* Copyright (c) 2009 by SDN AG, CH-8912 Obfelden Switzerland */
/* -----------------------------------------------------------*/
/* Project : easyLEARN skills4u                               */
/* -----------------------------------------------------------*/
/* $Id: jslib.js,v 1.49 2009/11/16 11:00:55 MWE Exp $  */
/* ============================================================*/
/*
History
=======
$Log: jslib.js,v $
Revision 1.49  2009/11/16 11:00:55  MWE
Neue Funktion JSLibToggleElement()

Revision 1.48  2009/11/11 14:12:48  MWE
Neue Klasse elPopupBox(), neuen Funktionen  elAttentionBox(), elMessageBox()

Revision 1.47  2009/10/14 14:55:47  MWE
*** empty log message ***

Revision 1.46  2009/10/14 08:47:23  MWE
Neuen Funktionen elSessionKeepaliveXX um die Session aktiv zu behalten

Revision 1.45  2009/09/18 13:04:13  MWE
Neue Funktionen JSLibDoShowDocElement(elem) und  JSLibHideDocElement(elem)

Revision 1.44  2009/04/29 11:21:53  MWE
UTF8 Anpassungen, JSquote()

Revision 1.43  2008/06/04 05:50:21  MWE
*** empty log message ***

*/
function elPopupBox(id,itop,ileft)
{
  this.id = id;
  this.itop = itop;
  this.ileft = ileft;
  this.valid = false;
  this.mouse_y = 0;
  this.mouse_x = 0;
  this.isdrag = false;
  this.dragobj = null;
  this.createWindow();

}


elPopupBox.prototype.createWindow = function()
{
  var html;
  var xnodes = document.getElementsByTagName("body")[0];
  var achr = "'";
  html ='<table width="380" cellpadding="0" cellspacing="0" border="0" style="margin:0px;padding:0px">';
  html += '<tr>';
  html += '<td style="padding:0px;margin:0px"><img height="23" width="24" border="0"src="images/popup_topleft.jpg"></td>';
  html += '<td style="padding:0px;margin:0px"><img height="23" width="332" border="0" src="images/popup_top.jpg" repeat class="dragme"></td>';
  html += '<td style="padding:0px;margin:0px"><a href="javascript:'+this.id+'.close();"><img height="23" width="24" src="images/popup_close.gif" border="0"></a></td>';
  html += '</tr>';
  html += '<tr><td valign="top" colspan="3" style="background-color:white; width: 380px; height: 277px;margin:0px;padding:0px;border-style:outset;border-width:2px;border-color:#4972FB;margin:0px">';
  html += '<div id="elpopup_content'+this.id+'" align="left" style="padding:5px;width:365px; height:260px;overflow:auto">';
  html += '</div><tr>';
  html += '<td style="padding:0px;margin:0px"><img height="28" width="24" border="0" src="images/popup_bottomleft.jpg"></td>';
  html += '<td style="padding:0px;margin:0px;background-image:url('+achr + 'images/popup_bottom.jpg'+achr+')" width="332" height="28">';
  html += '<div style="text-align:center;vertical-align:top"><button type="button" onclick="'+this.id+'.close()">&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;</button></div></td>';
  html += '<td style="padding:0px;margin:0px"><img height="28" width="24" border="0" src="images/popup_bottomright.jpg"></td>';
  html += '</tr></td></tr></table></div>';
  
  //alert(html)
  
  var idiv = document.createElement("div");
  idiv.id = "elpopup" + this.id;
  idiv.style.position = "absolute";
  idiv.style.top = this.itop;
  idiv.style.width = '380px';
  idiv.style.height = '300px';
  idiv.style.left = this.ileft;
  idiv.style.zIndex = 10000;
  idiv.style.display  = "none";
  idiv.innerHTML = html;

  xnodes.appendChild(idiv);
  this.valid = true;

}

elPopupBox.prototype.show = function(content)
{
  if (!this.valid)
    this.createWindow();
  var idiv = document.getElementById("elpopup"+this.id);
  idiv.style.display = 'block';  
  var icontent = document.getElementById("elpopup_content"+this.id);
  icontent.innerHTML = content;
 
}

elPopupBox.prototype.close =  function()
{
  this.removeWindow();
}

elPopupBox.prototype.removeWindow = function()
{
  if (!this.valid)
    return;
  try
  {
    var xnodes = document.getElementsByTagName("body")[0];
    var idiv = document.getElementById("elpopup"+this.id);
    if (idiv)
      xnodes.removeChild(idiv);
  }
  catch(e)
  {

  }
  this.valid = false;
}

elPopupBox.prototype.closeclick = function()
{
  this.removeWindow();
}

elPopupBox.prototype.centerWindow = function()
{
  if (!this.valid)
	this.createWindow();	
  var w = wInnerWidth() / 2;
  var h = wInnerHeight() /2;
  if (w <= 0) w = 10 + 190;
  if (h <= 0) h = 10 + 150;
  var idiv = document.getElementById("elpopup"+this.id);
  idiv.style.top = h +wPageYOffset() - 150;
  idiv.style.left = w + wPageXOffset()- 190;
}

elPopupBox.prototype.mousemoveHandler = function(e)
{
  if( this.isdrag )
  {
	dobj.style.left = this.nn6 ? tx + e.clientX - mouse_x : tx + event.clientX - mouse_x;
	dobj.style.top  = this.nn6 ? ty + e.clientY - y : ty + event.clientY - mouse_y;
	return false;
  }	
}
function wGetScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
} 

function wGetScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}
/* =========================*/
var hlpwinhndl = null;
var _jslib_barWidth = -1;
var _jslib_barHeight = -1;
var winhndl2 = null;
var _jslib_msgboxobj = null;

function GetSkills4uSiteId()
{
    if (document.gSkills4uSiteID)
      return document.gSkills4uSiteID;

  if (parent.gSkills4uSiteID)
     return parent.gSkills4uSiteID;
   if (top.gSkills4uSiteID)
     return top.gSkills4uSiteID;
   return "default";
}

function elMessageBox(amsg)
{
  if (_jslib_msgboxobj == null)
	  _jslib_msgboxobj = new elPopupBox('_jslib_msgboxobj',10,10);
  _jslib_msgboxobj.centerWindow();
  _jslib_msgboxobj.show(amsg);

}

function elAttentionBox(amsg)
{
  elMessageBox(amsg);	
}
function easyAlert(amsg)
{
  s = '' + amsg + '';
  alert(s.replace(/&acute;/g,'\''));	
}
function showinfo(module,ident)
{
 var aUrl = 'showinfo.php?action=info&module=' + module + '&ident='+ident;
 winhndl = window.open(aUrl, 'epinfowin','width=500,height=300,scrollbars=yes,resizable=yes,status=yes');
 if (!winhndl)
   PopupBlocked();
 else
  winhndl.focus();
}

function showstat(module,ident,ident2)
{
 var aUrl = 'showinfo.php?action=status&module=' + module + '&ident='+ident +'&ident2=' + ident2;
  winhndl = window.open(aUrl, 'epinfowin','width=500,height=300,scrollbars=yes,resizable=yes,status=yes');
  winhndl.focus();
}
function showlsnstat(module,ident,ident2,ident3)
{
  var aUrl = 'showinfo.php?action=status&module=' + module + '&ident='+ident +'&ident2=' + ident2 + '&ident3=' +ident3 +'';
  winhndl = window.open(aUrl, 'epinfowin','width=500,height=300,scrollbars=yes,resizable=yes,status=yes');
  winhndl.focus();
}

function startChapter(aUrl,awin)
{
  var alpha = "abcdefghijklmnopqrstuvwxyz";
  var s = awin + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  if(screen.availHeight > 600)
    winhndl = window.open(aUrl, out,'left=10,top=10,width=800,height=600,scrollbars=yes,resizable=yes');
  else
  {
    winhndl = window.open(aUrl, out,'left=5,top=5,width=768,height=480,scrollbars=yes,resizable=yes');
  }
  winhndl.focus();
}

function startLearnWindow(crsid,courseid)
{
  var alpha = "abcdefghijklmnopqrstuvwxyz";
  var aUrl = "elwinstart.html?cid=" + crsid + "";
  var s = courseid + "";
  var s = GetSkills4uSiteId() + courseid + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  winhndl = window.open(aUrl, out,'left=10,top=10,width=640,height=480,scrollbars=yes,resizable=no');
  if (!winhndl)
    PopupBlocked();
  else
  {
    winhndl.focus();
  }
}
function startLearnWindowV4(enc_crsid,courseid)
{
  var alpha = "abcdefghijklmnopqrstuvwxyz";
  var aUrl = "lwplayer.php?courseid=" + enc_crsid + "";
  var s = GetSkills4uSiteId() + courseid + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  winhndl = window.open(aUrl, out,'left=10,top=10,width=640,height=480,scrollbars=no,resizable=yes');
  if (!winhndl)
    PopupBlocked();
  else
  {
    winhndl.focus();
  }
}
function startSCORMWindow(crsid,scoid,courseid,mode,currentorg,attempt)
{
  var alpha = "abcdefghijklmnopqrstuvwxyz";
  var sattempt ='';
  if (!(attempt == 'undefined' || attempt == null || !attempt))
    sattempt = attempt;
  var aUrl = 'scplayer.php?crsid=' + crsid + '&scoid='+scoid + '&mode='+mode+'&currentorg='+currentorg+'&attempt='+sattempt;
  var s = GetSkills4uSiteId() + courseid + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  winhndl = window.open(aUrl, out,'left=10,top=10,width=640,height=480,status=yes,scrollbars=no,resizable=yes');
  if (!winhndl)
    PopupBlocked();
  else
  {
    winhndl.focus();
  }
}

function Statustext(Text)
{
  parent.defaultStatus = Text;
  parent.status = Text;
  window.status = Text;
  return true;
}

function showusrlog(uid)
{
 var aUrl = 'showusrlog.php?cmd=list&uid=' + uid + '';
  winhndl = window.open(aUrl, 'epinfowin','width=600,height=400,scrollbars=yes,resizable=yes');
  winhndl.focus();
}

function OpenFilter(filtername,theurl)
{
  var aUrl = 'showfilter.php?filter=' + filtername + '&url='+escape(theurl) + "";
  winhndl2 = window.open(aUrl, 'epfilterwin','width=650,height=450,scrollbars=yes,resizable=yes');
  winhndl2.focus();
  window.setTimeout('chkClosed("'+theurl+'")',500);
}

function chkClosed(theurl) {
/*  alert(theurl); */
  if (winhndl2)
  {
    if(winhndl2.closed == true)
    { window.focus(); window.location = theurl; }
    else {window.setTimeout('chkClosed("'+theurl+'")',500); }
  }
}


var winhndl3 = null;


function chkClosedwin3() {
  if(winhndl3.closed) return;
  winhndl3.document.writeln("<A href='javascript:close()'>Close</A>\n");
  winhndl3.document.writeln("<SCRIPT language='javascript' src='closewin.js'>");
  winhndl3.document.writeln('</SCR'+'IPT>');

}


function OpenMessageWindow(rcpt,subject) {
  var aUrl = 'crmessage.php?mcmd=add&rcpt=' + rcpt + '&subject='+subject + "";
  winhndl4 = window.open(aUrl, 'epmsgwin','width=650,height=600,scrollbars=yes,resizable=yes');
  winhndl4.focus();

}

function CloseThis(win)
{
  win.Close();
}

function OpenHelpWindow(helpfile)
{
  var left = screen.availWidth - 640 - 10 ;
  var height = screen.availHeight - 130;
  var opt = "width=640,height="+height+",top=0,left="+left+",resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes";
  hlpwinhndl = window.open(helpfile,"eportalhelpwin", opt);
  hlpwinhndl.focus();
}

function OpenContextHelpWindow(aurl,id)
{
  var width;
  if (screen.availWidth > 800)
    width = 640;
  else
    width = screen.availWidth;

  var left = screen.availWidth - width - 10 ;
  if (left < 0)
    left = 0;

  var height = screen.availHeight - 130;
  var opt = "width="+width+",height="+height+",top=0,left="+left+",resizable=yes,scrollbars=yes,status=yes";
  var ctxwindow = window.open(aurl,id,opt);
  if (!ctxwindow)
    PopupBlocked();
  else
  {
    ctxwindow.focus();
  }
}


function PopupBlocked()
{
  alert("Error: Cannot create new window! Popup-Blocker maybe active!");
}

function OpenDefaultWindow(aurl,id)
{
  var alpha = "abcdefghijklmnopqrstuvwxyz";
  var s = GetSkills4uSiteId() + id + "";
  var s2 = s.toLowerCase();
  var i = 0;
  var out = "";
  for (i = 0; i < s2.length;i++)
  {
    if (alpha.indexOf(s2.charAt(i)) >= 0)
      out = out + s2.charAt(i);
  }
  var stdwindow = window.open(aurl,out,"location=yes,status=yes,resizable=yes,scrollbars=yes,menubar=yes,toolbar=yes");
  if (!stdwindow)
    PopupBlocked();
  else
  {
    stdwindow.focus();
  }
}

function SetReloadMeTimer(msec)
{
  window.setTimeout("LibReloadThisPage()",msec);
}

function LibReloadThisPage()
{
  document.location = document.location;
}

function LibFileBrowser(destfield, filemask,defaultdir)
{
  var aurl = "filebrowser.php?dir="+defaultdir+"&resultfield=" + destfield + "&t=" + filemask +"";
  var browsewindow = window.open(aurl,"FILEBROWSER","width=550,height=400,resizable=yes,scrollbars=yes");
  if (!browsewindow)
    PopupBlocked();
  else
  {
    browsewindow.focus();
  }
}

function OpenWindowEx(aurl,id,width,height)
{
  var windowex = window.open(aurl,id,"resizable=yes,scrollbars=yes,width=" + width+",height="+height+"");
  if (!windowex)
    PopupBlocked();
  else
  {
    windowex.focus();
  }
}

function OpenWindowExBlur(aurl,id,width,height)
{
  var windowex = window.open(aurl,id,"resizable=yes,scrollbars=yes,width=" + width+",height="+height+"");
  if (!windowex)
    PopupBlocked();
  else
  {
    windowex.blur();
  }
}


function OpenInfoWindowEx(aurl,id,width,height)
{

  var windowex = window.open(aurl,id,"resizable=yes,scrollbars=yes,width=" + width+",height="+height+"");
  if (!windowex)
  {
    PopupBlocked();
    windowex = window.open(aurl,id,"resizable=yes,scrollbars=yes,width=" + width+",height="+height+"");
  }
  else
  {
    windowex.focus();
  }
}

function OpenWindowWithParam(aurl,id,aparam)
{

  var windowex = window.open(aurl,id,aparam);
  if (!windowex)
  {
    PopupBlocked();
    windowex = window.open(aurl,id,aparam);
  }
  else
  {
    windowex.focus();
  }
}


function wInnerWidth()
{
  if (self.innerHeight) // all except Explorer
  {
	return self.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth)
	// Explorer 6 Strict Mode
  {
	return document.documentElement.clientWidth;

  }
  else if (document.body) // other Explorers
  {
	return document.body.clientWidth;
  }
}

function wInnerHeight()
{
   if (self.innerHeight) // all except Explorer
  {
	return self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
  {
	return document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
	return document.body.clientHeight;
  }
}

function wOuterHeight()
{
   if (self.outerHeight) // all except Explorer
  {
	return self.outerHeight;
  }
  if (_jslib_barHeight == -1)
  {
    _jslib_initializeOuterWidth();
  }

  if (document.documentElement && document.documentElement.offsetHeight)
	// Explorer 6 Strict Mode
  {
	return document.documentElement.offsetHeight + _jslib_barHeight;
  }
  else if (document.body) // other Explorers
  {
	return document.body.offsetHeight + _jslib_barHeight;
  }
}

function wOuterWidth()
{
  if (self.outerHeight) // all except Explorer
  {
    return self.outerWidth;
  }
  if (_jslib_barWidth == -1)
  {
    _jslib_initializeOuterWidth();
  }

  if (document.documentElement && document.documentElement.offsetWidth)
	// Explorer 6 Strict Mode
  {
    return document.documentElement.offsetWidth + _jslib_barWidth;
  }
  else if (document.body) // other Explorers
  {
	return document.body.offsetWidth + _jslib_barWidth;
  }
}

function wPageYOffset()
{
   if (typeof window.pageYOffset == "number")
     return window.pageYOffset;
   if (document.documentElement && document.documentElement.scrollTop)
     return document.documentElement.scrollTop;
   return document.body.scrollTop ;
}

function wPageXOffset()
{
   if (typeof window.pageXOffset == "number")
     return window.pageXOffset;
   if (document.documentElement && document.documentElement.scrollLeft)
     return document.documentElement.scrollLeft;
   return document.body.scrollLeft;
}
function _jslib_initializeOuterWidth()
{
	_jslib_barWidth = 8;
	_jslib_barHeight = 57;
	try
	{
    var cW=document.body.offsetWidth;
    var cH=document.body.offsetHeight;
    try
    {
      window.resizeTo(500,500);
      _jslib_barWidth=500-document.body.offsetWidth;
      _jslib_barHeight=500-document.body.offsetHeight;
      var wW=_jslib_barWidth+cW;
      var wH=_jslib_barHeight+cH;
      window.resizeTo(wW,wH);
    }
    catch(e)
    {

    }
	}
	catch(e)
	{

	}
}


function JSLibDoShowDocElement(elem)
{
  try {document.getElementById(elem).style.display = 'block';} catch(e)  {}
}

function JSLibHideDocElement(elem)
{
  try {document.getElementById(elem).style.display = 'none';} catch(e)  {} 
}

function JSLibToggleElement(elem)
{
 try {
   if (document.getElementById(elem).style.display == 'none')
	 document.getElementById(elem).style.display = 'block';
   else document.getElementById(elem).style.display = 'none';
  } catch(e)  {}	
}
function getXMLRequester( )
{
  var xmlHttp = false;

 // try to create a new instance of the xmlhttprequest object
 try
 {
  // Mozilla, Opera und Safari, IE 7+
   if( window.XMLHttpRequest )
   {
     xmlHttp = new XMLHttpRequest();
   }
   // Internet Explorer 5,6
   else if( window.ActiveXObject )
   {
     for( var i = 5; i; i-- )
     {
       try
       {
         // loading of a newer version of msxml dll (msxml3 - msxml5) failed
         // use fallback solution
         // old style msxml version independent, deprecated
         if( i == 2 )
         {
           xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
         }
         // try to use the latest msxml dll
         else
         {
           xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
         }
         break;
       }
       catch( excNotLoadable )
       {
         xmlHttp = false;
       }
     }
   }

 }
 // loading of xmlhttp object failed
 catch( excNotLoadable )
 {
   xmlHttp = false;
 }
 return xmlHttp ;
}
   //XMLHttpRequest-Objekt


function cEasyLogger(debugenabled, windebug, dbdebug, appname)
{
  this.mDebugEnabled = debugenabled;
  this.mDebugWinID = null;
  this.mWinDebugEnabled = windebug;
  this.mDBDebugEnabled = dbdebug;
  this.mAjax = null;
  this.mDebugAPP = appname;

}

cEasyLogger.prototype.IsDebugEnabled = function()
{
  return this.mDebugEnabled;
}

cEasyLogger.prototype.EnableDebug = function()
{
  this.mDebugEnabled = true;
}

cEasyLogger.prototype.Add = function (str)
{

  if (this.mDebugEnabled)
  {
  	if (this.mWinDebugEnabled)
  	{
  	  if (this.mDebugWinID == null || this.mDebugWinID == "undefined" || this.mDebugWinID.closed)
      {
  	    this.mDebugWinID = window.open('lwdbgwin.html','geasyloggergwin','width=800,height=400,scrollbars=yes,resizable=yes');
  	    if (this.mDebugWinID)
  	    {
           window.focus();
  	    }
  	    else
  	    {
  	      // Popupblocker aktiv, debug ausschalten.
  	      _jslib_initializeOuterWidth();
  	      this.mWinDebugEnabled = false;
  	      return;
  	    }
  	  }
  	  try
      {
        if (this.mDebugWinID.addLog)
          this.mDebugWinID.addLog(str);
      }
      catch(e)
      {
      }
    }
    if (this.mDBDebugEnabled)
    {
      if (this.mAjax == null)
      {
        this.mAjax = new cAjax();
        this.mAjax.AllowDebug(false); // Debug fuer Debugschreiber abschalten
      }
      var cmd = 'ajaxcmd=debug&str='+escape(str)+'&app='+escape(this.mDebugAPP);
      this.mAjax.PostWait(null,cmd);
    }
  }
}

cEasyLogger.prototype.Close = function()
{
  if (this.mDebugEnabled)
  {
    if (this.mWinDebugEnabled)
  	{
  	  if (this.mDebugWinID != null)
  	  {
  	    try
  	 	{
  	 	  this.mDebugWinID.close();
  	 	}
  	 	catch(e) {}
  	  }
  	  this.mDebugWinID = null;
  	}
  	if (this.mDBDebugEnabled)
  	{
  	  if (this.mAjax)
  	  {
  	  	this.mAjax = null;
  	  }
  	}
  	this.mDebugEnabled = false;
  }
}


function cAjax()
{
  this.mOnRequestNotifyStart = null;
  this.mOnRequestNotifyComplete = null;
  this.mRequester = getXMLRequester();
  this.mResponseText = '';
  this.mResponseXML = '';
  this.mOK = false;
  this.mResponseText = '';
  this.mResponseXML = null;
  this.mSelfParam = null;
  this.mOnComplete = null;
  this.mName = 'Ajax';
  this.mRequestID = '';
  this.mSysError  = '';
  this.mIsRunning = false;
  this.mAllowDebug = true;
}

cAjax.prototype.AllowDebug = function(flag)
{
  this.mAllowDebug = (flag == true);
}

cAjax.prototype.RequestPending = function()
{
  return this.mIsRunning == true;
}

cAjax.prototype.showdebuginfo = function(debugstr)
{
  if (this.mAllowDebug)
  {
  	if (gDebugger)
  	  gDebugger.Add(debugstr);
  }
}

cAjax.prototype.SetRequestID = function (id)
{
  this.showdebuginfo("cAjax::SetRequestID("+id+")");
  this.mRequestID = id;
}

cAjax.prototype.Success = function()
{
  return this.mOK;
}
cAjax.prototype.GetDefaultAction = function()
{
  var theurl = '';
  try
  {
    if (gJSbaseurl)
      theurl = gJSbaseurl;
    if (theurl == '')
    {
  	  if (window.location)
  	  {
  	    var url = location.pathname;
        var idx = url.lastIndexOf("/");
        if (idx != -1)
        {
          url = url.substr(idx+1);
        }
  	    theurl = location.protocol + location.host + url;
  	  }
    }
  }
  catch(e)
  {

  }
  theurl += 'ajaxintf.php';
  return theurl;
}

cAjax.prototype.GetRequestID = function ()
{
  this.showdebuginfo("cAjax::GetRequestID()");
  return this.mRequestID;
}

cAjax.prototype.OnStart = function (fnc)
{
  this.showdebuginfo("cAjax::OnStart()");
  this.mOnRequestNotifyStart = fnc;
}

cAjax.prototype.OnComplete = function (fnc)
{
  this.showdebuginfo("cAjax::OnComplete()");
  this.mOnRequestNotifyComplete = fnc;
}

cAjax.prototype.RequestDone = function (bstat)
{
  this.showdebuginfo("cAjax::RequestDone("+bstat+")");
  this.mIsRunning = false;
  this.mOK = bstat;
  if (this.mOnRequestNotifyComplete)
  {
  	this.showdebuginfo("cAjax::RequestDone(): call OnRequestNotifyComplete");
    this.mOnRequestNotifyComplete.call();
  }
}

cAjax.prototype.RequestStart = function ()
{
  this.showdebuginfo("cAjax::RequestStart()");
  this.mSysError = '';
  this.mIsRunning = true;
  this.mOK = false;
  if (this.mOnRequestNotifyStart)
  {
  	this.showdebuginfo("cAjax::RequestStart(): call OnRequestNotifyStart");
    this.mOnRequestNotifyStart.call();
  }
}


cAjax.prototype.Post = function (action, cmd, oncomplete,selfparam)
{
  if (action == null || action == '')
    action = this.GetDefaultAction();
  this.showdebuginfo("cAjax::Post("+action+","+cmd+")");
  try
  {
  	this.RequestStart();
    this.mOnComplete = oncomplete;
    this.mSelfParam = selfparam|| null;
    this.mRequester.open('POST', action, true);
    this.mRequester.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    var self = this;
    this.mRequester.onreadystatechange= function() { self.onreadystatechange.call(self); }
    this.mRequester.send(cmd);
  }
  catch(e)
  {
  	this.mSysError = "cAjax::Post: "+ e.message;
  	this.RequestDone(false);
  }
}

cAjax.prototype.PostWait = function (action, cmd)
{
  if (action == null || action == '')
    action = this.GetDefaultAction();
  this.showdebuginfo("cAjax::PostWait("+action+","+cmd+")");
  try
  {
  	this.RequestStart();
    this.mRequester.open('POST', action, false);
    this.mRequester.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    this.mRequester.send(cmd);
    this.mResponseText = this.mRequester.responseText;
    this.mResponseXML = this.mRequester.responseXML;
    this.RequestDone(true);
  }
  catch(e)
  {
  	this.mSysError = "cAjax::PostWait: "+ e.message;
  	this.RequestDone(false);
  }
}

cAjax.prototype.Get = function (action, cmd, oncomplete,selfparam)
{
  if (action == null || action == '')
    action = this.GetDefaultAction();
  this.showdebuginfo("cAjax::get("+action+","+cmd+")");
  this.mOnComplete = oncomplete;
  this.mSelfParam = selfparam|| null;
  try
  {
  	this.RequestStart();
    this.mRequester.open('GET', action + '?'+cmd, true);
    this.mRequester.setRequestHeader('Content-Type', 'text/xml');
    var self = this;
    this.mRequester.onreadystatechange= function() { self.onreadystatechange.call(self); }
    this.mRequester.send('');
  }
  catch(e)
  {
  	this.mSysError = "cAjax::Get: "+ e.message;
  	this.RequestDone(false);
  }
}

cAjax.prototype.GetWait = function (action, cmd)
{
  if (action == null || action == '')
    action = this.GetDefaultAction();
  this.showdebuginfo("cAjax::GetWait("+action+","+cmd+")");
  try
  {
    this.mRequester.open('GET', action + '?'+ cmd, false);
    this.mRequester.setRequestHeader('Content-Type', 'text/xml');
    this.RequestStart();
    this.mRequester.send('');
    this.mResponseText = this.mRequester.responseText;
    this.mResponseXML = this.mRequester.responseXML;
    this.RequestDone(true);
  }
  catch(e)
  {
  	this.mSysError = "cAjax::GetWait: "+ e.message;
  	this.RequestDone(false);
  }
}

cAjax.prototype.onreadystatechange = function()
{
	this.showdebuginfo("cAjax::onreadystatechange: readystate="+ this.mRequester.readyState)
    if ( this.mRequester.readyState == 4 )  // Request done
    {
      this.showdebuginfo("readystate=4,status ="+ this.mRequester.status)
      if (this.mRequester.status == 200 )
      {
      	this.mResponseText = this.mRequester.responseText;
      	this.mResponseXML = this.mRequester.responseXML;
      	this.mOK = true;
    	if (this.mOnComplete)
        {
          if (this.mSelfParam)
            this.mOnComplete(this.mSelfParam, this);
          else
            this.mOnComplete(this);
        }
        this.RequestDone(true);
      }
      else
      {
      	this.mSysError = 'Status: '+ this.mRequester.status;
        this.mResponseText = this.mRequester.responseText;
        this.RequestDone(false);
        if (this.mOnComplete)
        {
          if (this.mSelfParam)
            this.mOnComplete(this.mSelfParam, this);
          else
            this.mOnComplete(this);
        }
      }
    }
}


cAjax.prototype.responseXML = function()
{
	return this.mResponseXML;
}

cAjax.prototype.responseText = function()
{
  return this.mResponseText;
}

/* Session am Leben erhalten */

var gSessionKeepAliveTimerTimeSpan = 10;
var gSessionKeepAliveIntervalObj = null;
var gSessionKeepAliveAjaxObj = null;

function elSessionKeepaliveInitialize(minutes)
{
  try {
    gSessionKeepAliveTimerTimeSpan = minutes;
    if (minutes > 1)
      window.setTimeout('elSessionKeepaliveStartDelayed()', 60000);
  }
  catch(e) {}
}

function elSessionKeepaliveStartDelayed()
{
  var msec;
  try {	
    msec = gSessionKeepAliveTimerTimeSpan * 60 * 1000;
    gSessionKeepAliveIntervalObj = window.setInterval("elSessionKeepaliveTouchSession()",msec);
    if (gSessionKeepAliveTimerTimeSpan > 10)
      elSessionKeepaliveTouchSession();
  }
  catch(e)  {}
}

function elSessionKeepaliveStop()
{
  try {	
   if (gSessionKeepAliveIntervalObj)
   {
	window.clearInterval(gSessionKeepAliveIntervalObj);
	gSessionKeepAliveIntervalObj = null;
	window.setTimeout('elSessionKeepaliveRunnerDone()',1000)
   }
  }
  catch(e) {}
}

function elSessionKeepaliveRunnerDone()
{
  try {
  if (gSessionKeepAliveAjaxObj)
	gSessionKeepAliveAjaxObj = null;
  }
  catch(e) {}
}

function elSessionKeepaliveRunner(ajax)
{
  try {
	var xmldoc = ajax.responseXML().documentElement;
    var thevalue = xmldoc.getElementsByTagName('sessnkeepaliveresult')[0].firstChild.data;
    if (thevalue == 1)
    {
      window.setTimeout('elSessionKeepaliveRunnerDone()',1000);
      return;
    }
    else
    {
      elSessionKeepaliveStop();
    }
  }
  catch(e) { elSessionKeepaliveStop();	return;  }
}

function elSessionKeepaliveTouchSession()
{
  gSessionKeepAliveAjaxObj = new cAjax();
  gSessionKeepAliveAjaxObj.AllowDebug(false);
  gSessionKeepAliveAjaxObj.Post('elsessnkeepalive.php', 'jslib=1', elSessionKeepaliveRunner);
}