///////////////////
//
// Observe
// Web2.0 AJAX sitetracking functions
//
// 2006 Marc Brauel , Onwerk GmbH, Mannheim
// V 1.0
///////////////////
 
 

  ////
  // create Ajax Object
  //
  var REQOBJ =
  { 
     /////
     // Properties
    bStatus: false,
    objAJAX: null,
	SOAPAnswer: '',
	SOAPRequest: '',
	SOAPAction: 'onwerk_OBSERVE/bSnapshot',
	URL_WS: '',
	
	/////
    // Init the object
    init: function()
	{ 
	  try  /* w3c */
	  {
	    REQOBJ.objAJAX = new XMLHttpRequest();
	    REQOBJ.bStatus = true;
	    DEBUG('init w3c object');
	  }
	  catch(e_w3c) /* MSIE */
	  {
           try
		   {
              REQOBJ.objAJAX = new ActiveXObject("Msxml2.XMLHTTP");
			  REQOBJ.bStatus = true;
	  	      DEBUG('init new msie object');

		   }
		   catch(e_msie)
		   {
	           try
			   {
		          REQOBJ.objAJAX = new ActiveXObject("Microsoft.XMLHTTP");
			      REQOBJ.bStatus = true;
	  	          DEBUG('init old msie object');
			   }
			   catch(e_msie_old)
			   {
			     REQOBJ.bStatus = false;
  	            DEBUG('init failt:'+e_msie_old);
			     
			   }	/* MSIE alt */     
		   }	/* MSIE neu */     
	  } /* w3c */
    },// init

    /////
    // Send SOAP request
    //
	doSend: function(sSessionid,sUserid,sWebsite,sEvent,sActionarea)
	{
      if((REQOBJ.URL_WS == "") || (REQOBJ.SOAPAction=="")){DEBUG('URL_WS or SOAPAction empty');return false;}
      if(!REQOBJ.bStatus){DEBUG('bStatus is false');return false;}
      
      try
      {
		REQOBJ.objAJAX.open('POST',REQOBJ.URL_WS,true);
		REQOBJ.objAJAX.setRequestHeader("Man", "POST "+REQOBJ.URL_WS+" HTTP/1.1");
		REQOBJ.objAJAX.setRequestHeader("MessageType", "CALL");
		REQOBJ.objAJAX.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
		REQOBJ.objAJAX.setRequestHeader("SOAPAction", REQOBJ.SOAPAction);
        DEBUG('set header succeeded :'+REQOBJ.URL_WS) ;

		REQOBJ.objAJAX.onreadystatechange = function(){
			if(REQOBJ.objAJAX.readyState == 4){
				if(REQOBJ.objAJAX.bStatus != 200 && REQOBJ.objAJAX.bStatus != 0) {
					//
                    // alert('Error sending:'+REQOBJ.objAJAX.statusText);
					//
			        return false;
				}
				REQOBJ.SOAPAnswer = REQOBJ.objAJAX.responseText;
			}//REQOBJ.objAJAX.readyState == 4
			} //REQOBJ.objAJAX.onreadystatechange
        DEBUG('set response delegate succeeded') ;


		REQOBJ.SOAPRequest = '<?xml version="1.0" encoding="utf-8"?>\n'+
					'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\n'+
					'<soap:Body>\n'+
					'<bSnapshot xmlns="onwerk_OBSERVE">\n'+
					'  <sSessionid>'+sSessionid+'</sSessionid>\n'+
					'  <sUserid>'+sUserid+'</sUserid>\n'+
					'  <sWebsite>'+sWebsite+'</sWebsite>\n'+
					'  <sEvent>'+sEvent+'</sEvent>\n'+
					'  <sActionarea>'+sActionarea+'</sActionarea>\n'+
					'</bSnapshot>\n'+
					'</soap:Body>\n'+
					'</soap:Envelope>\n';
        DEBUG('set request succeeded\n'+REQOBJ.SOAPRequest) ;
	      
		REQOBJ.SOAPAnswer='';
		REQOBJ.objAJAX.send(REQOBJ.SOAPRequest);
        DEBUG('sending successfull') ;
		return true;
       }
       catch(eSendError)
       {
         DEBUG('doSend failt:'+eSendError) ;
         return false;
       }
	}//doSend
  }//REQOBJ
     
  REQOBJ.init();


  function DEBUG(sText)
  {
    return;
    alert(sText);
  }
  
////-----------------------------------------------------------------

 //////////
 ///doTrackSite
 //
 //
 // [string] sSessionid - ID of teh current session
 // [string] sUserid    - SUN PRO Id of this user
 // [string] sWebsite   - Name of the Webseite
 // [string] sEvent     - type of Event (click, mouseover etc.)
 // [string] sActionarea- object who activate the event (button xyz,)
  //
 function /*void*/ doTrackSite(sSessionid,sUserid,sWebsite,sEvent,sActionarea)
 {
    var bResp;
    try
    {
      if(REQOBJ.bStatus)
      {
        if(bResp = REQOBJ.doSend(sSessionid,sUserid,sWebsite,sEvent,sActionarea))
	    {
	     // handle the response  / not used 
		  return "doSend: Resp="+bResp;
	    }
	  }//if(REQOBJ.bStatus)
	  return "ERROR: bStatus="+REQOBJ.bStatus;
	}catch(eError)
	{
	   return "ERROR:"+eError;
	}
 }//doTrackSite
 
 // REQOBJ.URL_WS = "http://localhost/Observer/Observe.asmx";
 REQOBJ.URL_WS = "http://login.sunpromotions.com/wDEU/Observe.php";



////
////////////////////////////////

/*
<!---  SiteTrack ---->
<?$ROOTURL = "http://login.sunpromotions.com/wDEU"?>
<script language="JavaScript" src="<?echo $ROOTURL;?>/observe.js"></script>

<?if( isset( $_SESSION[ "sun_login"]) && isset($_SESSION[ "sun_userarr"])) {?>
<script language="JavaScript">
  //doTrackSite(sSessionid,sUserid,sWebsite,sEvent,sActionarea)
  doTrackSite('<?echo md5(date("YmDHis").$_SESSION[ "sun_userarr"][ "userid"]);?>','<?echo $_SESSION[ "sun_userarr"][ "userid"];?>','left.php','open','site');
</script>
<?}?>
<!---  SiteTrack ---->

*/  