/**
  ********************************************
  *                                          *
  *  JStats                                  *
  *                                          *
  *  An AJAX / javascript statistics snippet *
  *  This will push the stats in your DB     *
  *  using an ajah request :)                *
  *  this means fun fun fun!                 *
  *                                          *
  *  @Author:    joggink                     *
  *  @Date  :    2006/12/18                  *
  *  @Version:   0.1 beta                    *
  *  @contact:   info@joggink.be             *
  *  @homepage:  www.joggink.be              *
  ********************************************
 **/


  var ref = "";
  var dom = "";
  var nav = "";
  var res = "";
  var http = getHTTPObject();
  var isWorking = false;

  store();

  function store(){
	  if (document.referrer){
        ref = document.referrer;
	  }
	  
     if (window.location){
        dom = window.location;
	  }
	  
	  if (navigator.userAgent){
		  nav = navigator.userAgent;
	  }
	  	
	  res = screen.width + " x " + screen.height;
		
	  storeStats();
  }

  function getHTTPObject() {
     var xmlhttp;
     /*@cc_on
     @if (@_jscript_version >= 5)
       try {
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
         try {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (E) {
           xmlhttp = false;
         }
       }
     @else
     xmlhttp = false;
     @end @*/
     if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
         xmlhttp = new XMLHttpRequest();
       } catch (e) {
         xmlhttp = false;
       }
     }
     return xmlhttp;
  }

  function storeStats(){
     if (!isWorking && http) {
        http.open("GET", 'jstats/stats.php?dom=' + dom + '&ref=' + ref + '&nav=' + nav + '&res=' + res, true);
        http.onreadystatechange = handleStats;
        isWorking = true;
        http.send(null);
     }
  }
  
  function handleStats(){
     if (http.readyState == 4) {
        if (http.responseText.indexOf('invalid') == -1) {
			  results = http.responseText;
			  if (results){
				  //window.alert(results);
			  }
           isWorking = false;
		  }
	  }
  }