//<!--
// WEBABACUS CLIENT INFO VERSION 2.04, (c)2007 Foviance Ltd ALL RIGHTS RESERVED. 
// Version to be used as a JS include
// See accompanying clientinfo-include-notes.txt for change history, or contact helpdesk@foviance.com

// User variables: Change these values to set global settings
var server = "http://s.homesmine.gmgrd.co.uk";            // Set to another server (e.g. http://192.168.1.250) to send tag request to that server (not local)
var secureserver = "";  // Enter the address of the server to which secure tag requests should be sent (include https:// part)
var site = "homesmine";                                                         //  - (Recommended) Enter the name of this site
var cookieLife = 730;                                                       // No. of days that the cookie is valid for (default is 730 - two years)
var cookieDomain = ".homesmine.gmgrd.co.uk";                                                      //  - (Optional) Domain for the cookie (must start with and include at least two full stops - e.g. .webabacus.com or .webabacus.co.uk)  
var perfinfo = 0;                                                               // Flag to indicate whether this script will be used to gather full performance data - set to 1 if it will be
var sourceparamname = "";                                               //  - (Optional) Name of the parameter in the query string which indicates a source value
// End of user variables

// set timer
var fromt = new Date();
var elapsedt = fromt.getTime();
var pet = "";
var SRT = "0";
var OET = "0";
var UET = "0";

var civersion="2.04";
var js = "-";
var sc = 0;
var sw = 0;
var sh = 0;
var ww = 0;
var wh = 0;
var je = "-";
var lg = "-";
var dn = "-";
var bt="";
var st="-";
var tz=0;
var vl="-";
var t=0;
var sr="-";
var res="-";
var ref="-";
var res2="-";
var pt="-";
var fs=0;
var is=0;
var id="-";
var idparm="";
var nu="-";
var wr="-";
var base="";
var reqsrc="";
var now="";
var tt=0;
keys = new Array();
values = new Array();
var source = "";
var src = "-";
var clifems = cookieLife * 86400000;
ccrt = new Date(fromt.getTime());
cexp = new Date(fromt.getTime() + clifems);
var srctime=0;
var customfields="";
var optout="";
var trioid="-";

var key1 = '';
var key2 = '';
var charArray = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');


var rn="";
for (i = 0; i < 4; i++){
        rn += charArray[Math.floor(Math.random() * charArray.length)];
    }
var tmp1=new Date();
var tmp2=tmp1.getTime();
var tmp3=Math.floor(tmp2/200000);
var tmp4=Math.floor(tmp3*200000);
var rn2 = rn + (Math.floor(tmp2-tmp4));

function logclientdata(n,r) {
    thispet = n;
        if(r)
        res2=r;
    // Calculate time differentials
    if (thispet=="01") {
      now = new Date();
      tt = now.getTime();
      SRT = (tt - elapsedt);
      trioid = rn2;
      }
    else if (thispet=="02") {
      now = new Date();
      tt = now.getTime();
      OET = (tt - elapsedt);
      trioid = rn2;
      }
    else if (thispet=="03") {
      now = new Date();
      tt = now.getTime();
      UET = (tt - elapsedt);
      trioid = rn2;
      }
    else if (thispet=="0") {
        var tmp5=new Date();
        var tmp6=tmp5.getTime();
        var tmp7=Math.floor(tmp6/200000);
        var tmp8=Math.floor(tmp7*200000);
        var rn3 = rn + (Math.floor(tmp6-tmp8));
      SRT = 0;
      OET = 0;
      UET = 0;
      trioid = rn3;
    }
    else  {
      SRT = 0;
      OET = 0;
      UET = 0;
      trioid = rn2;
      thispet = "-";
      }
    
    if (navigator.appName == 'Netscape') bt = "NS";
    else {
    if (navigator.appName == 'Microsoft Internet Explorer') bt = "IE";
    else bt="OT";
    }
    
    je = navigator.javaEnabled() ? "Y" : "N";
    dn = document.domain;
    lg = bt=="NS" ? navigator.language : navigator.browserLanguage;
    sc = Math.pow(2, screen.colorDepth);
    sp = screen.pixelDepth;
    sw = screen.width;
    sh = screen.height;
    now = new Date();
    
    st = escape(site);
    if (st==null || st=="") st = "-";
    tz = now.getTimezoneOffset();
    vl = history.length;
    t = now.getTime();
    sr = sw + "x" + sh;
    
    res = escape(document.URL);
    ref = escape(document.referrer);
    if (ref==null || ref=="") ref = "-";
    pt = escape(document.title);
    if (pt==null || pt=="") pt = "-";
    
    if((navigator.appName == 'Netscape')&&(parseInt(navigator.appVersion)<5)){
        fs = "-";
      is = "-";
      wr = "-";
      customfields = "-";
    }
    else {
        if (thispet != "01"){
        // Capture size of document and related graphics
        is = 0;
        try {
            fs = document.fileSize * 1;  
            var iMap = new Object();
            for (i = 0; i < document.images.length; i++) {
              if (!iMap[document.images[i].src]) {
                    is += parseInt(document.images[i].fileSize);
                  iMap[document.images[i].src] = true;
                }
            }
        } catch (e) {fs = 0; is = 0;}
      
        if (bt == 'IE') {
             if (document.documentElement && document.documentElement.clientWidth) {
              ww = document.documentElement.clientWidth;
                wh = document.documentElement.clientHeight;
            }
            else if (document.body){
              ww = document.body.clientWidth;
                wh = document.body.clientHeight;
            }
        }
        else {
            try {
            ww = window.outerWidth; wh = window.outerHeight;
            } catch (e) {ww = 0; wh = 0;}
        }
        var wr = ww + "x" + wh;
      
        }
        else {
        fs = "-";
        is = "-";
        wr = "-";
        }
    }
    
    // Capture the values of the custom fields
    if (typeof(wacustomvarnames) != "undefined") {
    customfields = "";
    for (i = 0; i < wacustomvarnames.length; i++) {
      customfields = customfields + wacustomvarnames[i] + "~" + wacustomvarvalues[i];
        if (i != wacustomvarnames.length-1) customfields = customfields + "~";
    }
    } else
        customfields = "-"; 
    
    parseQS();
    
    
    function gen_id(int2) {
        var key1="";
        var key2="";
        for (i = 0; i < int2; i++){
            key1 += charArray[Math.floor(Math.random() * charArray.length)];
        }
        for (i = 0; i < key1.length; i++){
            key2 += key1.charCodeAt(i).toString(16);
        }
        var id = key1 + key2 + "-1-" + ccrt.toUTCString();
        return(id);
    }
    
    // Check for and issue cookie - will use the value of a "webabacus_id" parameter by preference
    optout = getCookie("nocookie");
    
    if (optout != "1") {
      idparm = getQSParam("webabacus_id");
      if (idparm == null || idparm == "") {
        id = getCookie("webabacus_id");
      } else {
        id = idparm;
      }
      if (id == null || id == "-1") {
        //id = now.getTime()+"-1";
        id = gen_id(5);
        nu="1" // New user (they've not been issued a cookie before)
      } else {
        nu="0"
      }
      document.cookie = "webabacus_id="+escape(id)+"; expires=" + cexp.toUTCString() + "; path=/" + (cookieDomain == "" ? "" : "; domain=" + cookieDomain);
      // Check that cookie has been set. If not set the webabacus id value to null.
       if(document.cookie.indexOf(escape(id))<0){
        var id = null;
        var nu = null;
      }
        
    } else {
      id = "nocookie";
      nu = "-1";
    }
    // Get query string info & parse out required parameters
    source=getQSParam(sourceparamname);
    // If a particular parameter is non-null, set that value in the "click source" cookie
    if (source != null) {
      src = escape(source);
      srctime=fromt.getTime();
      if (optout != "1") {
        document.cookie = "wa_last_source="+escape(source)+"; expires=" + cexp.toUTCString() + "; path=/" + (cookieDomain == "" ? "" : "; domain=" + cookieDomain);
        document.cookie = "wa_last_source_date="+srctime+"; expires=" + cexp.toUTCString() + "; path=/" + (cookieDomain == "" ? "" : "; domain=" + cookieDomain);
      }
    } else {
      if (optout != "1") {
        src = getCookie("wa_last_source");
        srctime = getCookie("wa_last_source_date");
      }
      if (src == null) src = "-";
      if (srctime == null) srctime = 0;
    }
      
    // decide which tag request (secure vs non-secure) to use
    if (res.substring(0,5) == "https"){
      base = secureserver + "/clientinfo.gif?" + civersion + "&" + t + "&";
    }
    else{
      base = server + "/clientinfo.gif?" + civersion + "&" + t + "&";
    }
    
    // Checks if a custom event call has been made (res2)  
    if(res2!="-"){
        var res = escape('http://') + dn + '/' + escape(res2.replace('http://',''));
        var ref = escape(document.URL);
    }
    
    reqsrc = st + "&" + tz + "&" +id + "&" +nu + "&" + sc + "&" +sr + "&" + wr + "&" + js + "&" + je + "&" + lg + "&" + dn + "&" + res + "&" + ref + "&" + pt + "&" + fs + "&" + is + "&" + trioid + "&" + thispet + "&" + SRT + "&" + OET + "&" + UET + "&" + src + "&" + srctime + "&" + customfields;
    var maxlen = 4000;  // max request size
    var reqlen = reqsrc.length;
    if (reqlen>maxlen) reqsrc = reqsrc.substring(0,maxlen);
      
    var request = new Image();
    request.src = base + reqsrc + "&-";
    
    if((document.URL.indexOf('wa_debug=true')>-1)|(document.cookie.indexOf("webabacus_debug=true")>-1)){
        alert("WebAbacus Debug Infomation\n\nnote: to remove add 'wa_debug=false' to the URL\n\nSite name (st): " + st +"\nTime zone offset (tz): "+tz+"\nWebabacus ID (id): "+id+"\nNew user flag (nu): "+nu+"\nVisitor Screen Colour Depth (sc): "+sc+"\nVisitor Screen resolution (sr): "+sr+"\nVisitor Window resolution (wr): "+wr+"\nJavascript version (js): "+js+"\nJava Enablement (je): "+je+"\nBrowser Language (lg): "+lg+"\nServer name (dn): "+dn+"\nResource (res): "+res+"\nReferrer (ref): "+ref+"\nPage Title (pt): "+pt+"\nfs: "+fs+"\nis: "+is+"\ntrioid: "+trioid+"\nthispet: "+thispet+"\nSRT: "+SRT+"\nOET: "+OET+"\nUET: "+UET+"\nsrc: "+src+"\nsrctime: "+srctime+"\ncustomfields: "+customfields + "\n\nMain Tag: "+ base + reqsrc + "&-");
        document.cookie="webabacus_debug=true; expires="+cexp.toUTCString()+"; path=/"+(cookieDomain==""?"":"; domain="+cookieDomain);
    }
    
    if(document.URL.indexOf('wa_debug=false')>-1){
        document.cookie="webabacus_debug=false; expires="+cexp.toUTCString()+"; path=/"+(cookieDomain==""?"":"; domain="+cookieDomain);
    }
}

function getCookie (name) {
var dc = document.cookie;
var cname = name + "=";
var clen = dc.length;
var cbegin = 0;
while (cbegin < clen) { 
var vbegin = cbegin + cname.length;
  if (dc.substring(cbegin, vbegin) == cname) { 
    var vend = dc.indexOf (";", vbegin);
    if (vend == -1) vend = clen;
    return unescape(dc.substring(vbegin, vend));
    }
  cbegin = dc.indexOf(" ", cbegin) + 1;
  if (cbegin== 0) break;
  }
return null;
}

function getQSParam(key)
{
    var value = null;
    for (var i=0;i<keys.length;i++)
    {
        if (keys[i]==key)
        {
            value = values[i];
            break;
        }
    }
    return value;
}

function parseQS()
{
    var query = "";
    try {
      query = top.window.location.search.substring(1);
    } catch (e) {}
    var query1 = query.toLowerCase();
    var pairs = query1.split("&");
    
    for (var i=0;i<pairs.length;i++)
    {
        var pos = pairs[i].indexOf('=');
        if (pos >= 0)
        {
            keys[keys.length] = pairs[i].substring(0,pos);
            values[values.length] = pairs[i].substring(pos+1);      
        }
    }
}

// This code executes when the script is first parsed
if (perfinfo == 1) {
  logclientdata("01");
} else {
  logclientdata("");
}

//-->


