/*
*     lib_error.js
*     
*     Catcher d'erreur javascript
*     Permet de recevoir par mail les erreurs javascript
*
*     Nicolas CRESPEAU Le Phare 2010
*
*/


var catcherJs = function(){
   // abstract :) 
}
catcherJs.prototype = {
      // definition des variables
      line : 0,
      file : null,
      error: null,
      xhr_object : null,
      
      initialize : function(debug) {      
         if(debug)// en mode debug
            window.onerror = this.catchErrorAlert;
         else            
            window.onerror = this.catchError;
      },
      
      catchErrorAlert : function(error,file,line){
         this.line  = line + "\n";
         this.file  = file + "\n";
         this.error = error + "\n";
         alert (this.line + " " +this.file + " " + this.error);
      },
      // chope les parametres de l'erreur
      catchError : function(error,file,line){
         this.line  = line;
         this.file  = file;
         this.error = error; 
     
         if(window.XMLHttpRequest) // Firefox 
   	      this.xhr_object = new XMLHttpRequest(); 
   	   else if(window.ActiveXObject) // Internet Explorer 
   	      this.xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
   	   else { 
            // XMLHttpRequest non supporté par le navigateur 
   	      return; 
   	   } 
	      // on defini l'envoie
         this.xhr_object.open("POST", "/fr/s99_error/jsError.php", true);
         //set le header
         this.xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
         // les parametres
         var data = "data[error]="+this.error+"&data[line]="+this.line+"&data[file]="+this.file; 
         // on envoie !
         this.xhr_object.send(data);        
      }      
}
   
var trigger = new catcherJs();
trigger.initialize(false);
 
