/*-----------------------------------------------------------------------------
 file:log.js

 description: JavaScript function to log dprGuru client side user events.

 author: amit barak, 2008
 -----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
 CHANGE LOG
 ------------------------------------------------------------------------------
 2008-10-13 | Amit Barak
 -----------------------
 removing alert on xmlhttp.status!=200 after i saw this popping in firefox.
 ------------------------------------------------------------------------------
 2008-08-31 | Amit Barak
 -----------------------
 Added "etext=escape(text)", and now sending the escaped string rather than the
 plain string. this is done to avoid Http requests screw-ups which can be caused
 by special characters in the text string.
 The bug was found during updates to the dprGuru project when all of the sudden
 some of the Http requests did not yield the expected result in the server side.
 -----------------------------------------------------------------------------*/

var xmlhttp;

function logDprGuruEvent(text){
  xmlhttp=null;
  var etext = escape(text);
  var ajaxScript='http://www.dprguru.com/log.php';
//var ajaxScript='http://localhost/ab/dprm/log.php';
  if (window.XMLHttpRequest) {// code for Firefox, Opera, IE7, etc.
    xmlhttp=new XMLHttpRequest();
  }

  else if (window.ActiveXObject) {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  if (xmlhttp!=null) {
    xmlhttp.onreadystatechange=state_Change;
    xmlhttp.open("POST",ajaxScript+'?event='+etext,true);
    xmlhttp.send(null);
  }
  else {
    alert("Your browser does not support XMLHTTP.");
  }
}//end function logDprGuruEvent(...)

function state_Change(){
  var tmp;
  if (xmlhttp.readyState==4){// 4 = "loaded"
    if (xmlhttp.status==200){// 200 = "OK"
    //document.getElementById('T1').innerHTML=xmlhttp.responseText;
      tmp = xmlhttp.responseText;
    }
    else{
    //alert("Problem retrieving data:" + xmlhttp.statusText);
      tmp = xmlhttp.statusText;
    }
  }
}//end function state_Change()

