// Fuel Web Sight
// Analysis Engine - Passive Analysis Interface V2.0
// 
// (c) 2008 - 2009 FUEL Data Strategies Limited
// Developed by Mustafa Ozkececigil
//
// Revisions:
// MO - 30 Jul 2008 V1.0
// MO - 12 Jan 2009 V2.0
// MO - 12 Oct 2009 V3.0 - Changed function names so that they can no
//                         longer be guessed in non Web Sight java code 

/*
* Configurable variables.
*/
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
* String arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }
function b64_md5(s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }
function str_md5(s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); }
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/** Main variables */
var wsshash = "";
var wdWidth = 0;
var wdHeight = 0;
var wsmseX = 0;
var wsmseY = 0;
var wsBrowser = '';
var wsclickTime = 0;
var wsclickEvent = "";
var wsDocument = '';


function submitCallbackWS() {
    var oref = document.referrer;

    var loc = "http://analytics.fueldata.co.uk/webtrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&fcty=" + encodeURI(ws_cpg) + "&pcty=" + encodeURI(ws_ucd) + "&pg=" + encodeURIComponent(document.URL) + "&lk=&cks=" + ws_cks + "&ref=" + encodeURIComponent(oref) + "&ty=true&rev=" + ws_revisiting + "&cls=false";

    var image = new Image();
    image.src = loc;

    return true;
}

function submitClsWS() {
    var oref = document.referrer;

    var loc = "http://analytics.fueldata.co.uk/webtrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&fcty=" + encodeURI(ws_cpg) + "&pcty=" + encodeURI(ws_ucd) + "&pg=" + encodeURIComponent(document.URL) + "&lk=&cks=" + ws_cks + "&ref=" + encodeURIComponent(oref) + "&ty=true&rev=" + ws_revisiting + "&cls=true";

    var image = new Image();
    image.src = loc;

    return true;
}

//function submitEventWS(Event, lnk) {
//    lnk = Event + ";" + lnk;
//    var loc = "http://analytics.fueldata.co.uk/webtrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&fcty=" + encodeURI(ws_cpg) + "&pcty=" + encodeURI(ws_ucd) + "&pg=" + encodeURIComponent(document.URL) + "&lk=" + encodeURIComponent(lnk) + "&ref=&cks=" + ws_cks + "&ty=true" + "&cls=false";

//    var image = new Image();
//    image.src = loc;

//    return true;
//}

function submitedFormWS() {
    var lnk = "FORM_SUBMITTED"; // + document.forms[0].name;
    var loc = "http://analytics.fueldata.co.uk/webtrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&fcty=" + encodeURI(ws_cpg) + "&pcty=" + encodeURI(ws_ucd) + "&pg=" + encodeURIComponent(document.URL) + "&lk=" + encodeURI(lnk) + "&ref=&cks=" + ws_cks + "&ty=true" + "&cls=false";

    var image = new Image();
    image.src = loc;

    return true;
}

function submitMouseOverWS(lnk, evt, mX, mY, plink) {
    var loc = "http://analytics.fueldata.co.uk/MouseTrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&lk=" + encodeURI(lnk) + "&ev=" + evt + "&px=" + mX + "&py=" + mY + "&sw=" + wdWidth + "&sh=" + wdHeight + "&bw=" + wsBrowser + "&plk=" + plink;

    var image = new Image();
    image.src = loc;

    return true;
}

function submitClickedWS(lnk, evt, mX, mY, plink) {
    var loc = "http://analytics.fueldata.co.uk/MouseTrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&lk=" + encodeURI(lnk) + "&ev=" + evt + "&px=" + mX + "&py=" + mY + "&sw=" + wdWidth + "&sh=" + wdHeight + "&bw=" + wsBrowser + "&plk=" + plink;
    var loc1 = "http://analytics.fueldata.co.uk/webtrack.aspx?shh=" + wsshash + "&cid=" + encodeURI(ws_ccd) + "&fcty=" + encodeURI(ws_cpg) + "&pcty=" + encodeURI(ws_ucd) + "&pg=" + encodeURIComponent(document.URL) + "&lk=" + encodeURIComponent(plink) + "&ref=&cks=" + ws_cks + "&ty=true&rev=" + ws_revisiting + "&cls=false";

    var i = 0;

    // create object
    imageObj = new Image();


    // set image list
    images = new Array();
    images[0] = loc;
    images[1] = loc1;

    for (i = 0; i <= 1; i++) {
        imageObj.src = images[i];
    }

    return true;
}

function GetCoords_WS(e) {
    if (!e) var e = window.event;

    if (wsBrowser == "msie") {
        wsmseX = e.clientX;
        wsmseY = e.clientY;

        wsmseX = wsmseX + document.body.scrollLeft + document.documentElement.scrollLeft;
        wsmseY = wsmseY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    else {
        // browser is NS or other
        wsmseX = e.pageX;
        wsmseY = e.pageY;
    }

    GetWindowSizwWS();
}

function getmousecoordshoverWS(e, lnk) {
    ws_lclicked = "t";

    var sPath = window.location.pathname;
    ////var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

    if (!e) var e = window.event;

    var nTime = new Date();
    if ((nTime.getTime() - wsclickTime) < 1000) {
        return;
    }

    wsclickTime = nTime.getTime();

    GetCoords_WS(e);
    submitMouseOverWS(sPath, "HOVER", wsmseX, wsmseY, lnk);

    return;
}

function getmousecoordsclickWS(e, lnk) {
    ws_lclicked = "t";

    var sPath = window.location.pathname;

    GetCoords_WS(e);
    submitClickedWS(sPath, "CLICK", wsmseX, wsmseY, lnk);

    return;
}

function GetWindowSizwWS() {
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        wdWidth = window.innerWidth;
        wdHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        wdWidth = document.documentElement.clientWidth;
        wdHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        wdWidth = document.body.clientWidth;
        wdHeight = document.body.clientHeight;
    }

    return;
}

function ResetMseWS(e) {
    ws_lclicked = null;
}

function getparameterWS(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);

    if (results == null)
        return "";
    else
        return results[1];
}

function LeftWS(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}


//function addEventWS(el, ev, fn) {
//    if (el.addEventListener) {
//        el.addEventListener(ev, fn, false);
//    }
//    else if (el.attachEvent) {
//        el.attachEvent("on" + ev, fn);
//    }
//    else {
//        el["on" + ev] = fn;
//    }
//
//    return;
//}

// written by Dean Edwards, 2005
// with input from Tino Zijdel, Matthias Miller, Diego Perini

// http://dean.edwards.name/weblog/2005/10/add-event/

function addEventWS(element, type, handler) {
    if (element.addEventListener) {
        element.addEventListener(type, handler, false);
    } else {
        // assign each event handler a unique ID
        if (!handler.$$guid) handler.$$guid = addEventWS.guid++;
        // create a hash table of event types for the element
        if (!element.events) element.events = {};
        // create a hash table of event handlers for each element/event pair
        var handlers = element.events[type];
        if (!handlers) {
            handlers = element.events[type] = {};
            // store the existing event handler (if there is one)
            if (element["on" + type]) {
                handlers[0] = element["on" + type];
            }
        }
        // store the event handler in the hash table
        handlers[handler.$$guid] = handler;
        // assign a global event handler to do all the work
        element["on" + type] = handleEventWS;
    }
};

// a counter used to create unique IDs
addEventWS.guid = 1;

function removeEventWS(element, type, handler) {
    if (element.removeEventListener) {
        element.removeEventListener(type, handler, false);
    } else {
        // delete the event handler from the hash table
        if (element.events && element.events[type]) {
            delete element.events[type][handler.$$guid];
        }
    }
};

function handleEventWS(event) {
    var returnValue = true;
    // grab the event object (IE uses a global event object)
    event = event || fixEventWS(((this.ownerDocument || this.document || this).parentWindow || window).event);
    // get a reference to the hash table of event handlers
    var handlers = this.events[event.type];
    // execute each event handler
    for (var i in handlers) {
        this.$$handleEventWS = handlers[i];
        if (this.$$handleEventWS(event) === false) {
            //returnValue = false;
            break;
        }
    }

    //return returnValue;
};



function fixEventWS(event) {
    // add W3C standard event methods
    event.preventDefault = fixEventWS.preventDefault;
    event.stopPropagation = fixEventWS.stopPropagation;
    return event;
};
fixEventWS.preventDefault = function() {
    this.returnValue = false;
};
fixEventWS.stopPropagation = function() {
    this.cancelBubble = true;
};

function setLinksWS() {
    var Links = document.getElementsByTagName("a");

    for (var i = 0; i < Links.length; i++) {
        addEventWS(Links[i], "mouseover", function(e) { getmousecoordshoverWS(e, this.href) });
        addEventWS(Links[i], "mouseout", function(e) { ResetMseWS(e) });
        addEventWS(Links[i], "click", function(e) { getmousecoordsclickWS(e, this.href) });
    }

    var fs = document.forms;

    for (var i = 0; i < fs.length; i++) {
        addEventWS(fs[i], "submit", submitedFormWS);
    }

    return;
}

var ws_lclicked = null;

function BClsWS() {
    if (ws_lclicked == null) {
        if (document.referrer != document.URL) {
            submitClsWS();
        }
    }

    return true;
}

// **********************************************************
// MD5 stuff starts here
//
//***********************************************************

/*
* Calculate the MD5 of an array of little-endian words, and a bit length
*/
function core_md5(x, len) {
    /* append padding */
    x[len >> 5] |= 0x80 << ((len) % 32);
    x[(((len + 64) >>> 9) << 4) + 14] = len;

    var a = 1732584193;
    var b = -271733879;
    var c = -1732584194;
    var d = 271733878;

    for (var i = 0; i < x.length; i += 16) {
        var olda = a;
        var oldb = b;
        var oldc = c;
        var oldd = d;

        a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
        d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
        c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
        b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
        a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
        d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
        c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
        b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
        a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
        d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
        c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
        b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
        a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
        d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
        c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
        b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);

        a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
        d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
        c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
        b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
        a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
        d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
        c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
        b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
        a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
        d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
        c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
        b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
        a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
        d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
        c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
        b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);

        a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
        d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
        c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
        b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
        a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
        d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
        c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
        b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
        a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
        d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
        c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
        b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
        a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
        d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
        c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
        b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);

        a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
        d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
        c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
        b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
        a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
        d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
        c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
        b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
        a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
        d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
        c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
        b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
        a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
        d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
        c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
        b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);

        a = safe_add(a, olda);
        b = safe_add(b, oldb);
        c = safe_add(c, oldc);
        d = safe_add(d, oldd);
    }

    return Array(a, b, c, d);

}

/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t) {
    return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
}
function md5_ff(a, b, c, d, x, s, t) {
    return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t) {
    return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t) {
    return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t) {
    return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
* Calculate the HMAC-MD5, of a key and some data
*/
function core_hmac_md5(key, data) {
    var bkey = str2binl(key);

    if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

    var ipad = Array(16), opad = Array(16);

    for (var i = 0; i < 16; i++) {
        ipad[i] = bkey[i] ^ 0x36363636;
        opad[i] = bkey[i] ^ 0x5C5C5C5C;
    }

    var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);

    return core_md5(opad.concat(hash), 512 + 128);
}

/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y) {
    var lsw = (x & 0xFFFF) + (y & 0xFFFF);
    var msw = (x >> 16) + (y >> 16) + (lsw >> 16);

    return (msw << 16) | (lsw & 0xFFFF);
}

/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt) {
    return (num << cnt) | (num >>> (32 - cnt));
}

/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
*/
function str2binl(str) {
    var bin = Array();
    var mask = (1 << chrsz) - 1;

    for (var i = 0; i < str.length * chrsz; i += chrsz)
        bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
    return bin;
}

/*
* Convert an array of little-endian words to a string
*/
function binl2str(bin) {
    var str = "";
    var mask = (1 << chrsz) - 1;

    for (var i = 0; i < bin.length * 32; i += chrsz)
        str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
    return str;
}

/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex(binarray) {
    var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
    var str = "";

    for (var i = 0; i < binarray.length * 4; i++) {
        str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
           hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
    }

    return str;
}

/*
* Convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray) {
    var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var str = "";

    for (var i = 0; i < binarray.length * 4; i += 3) {
        var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16)
                | (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8)
                | ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
        for (var j = 0; j < 4; j++) {
            if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
            else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
        }
    }

    return str;
}

// End MD5 stuff


// Cookie stuff start
//
//
function Get_CookieWS(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }

        a_temp_cookie = null;
        cookie_name = '';
    }

    if (!b_cookie_found) {
        return null;
    }
}

function Set_CookieWS(name, value, expires, path, domain, secure) {
    var cookieString = name + "=" + escape(value) +
       ((expires) ? ";expires=" + expires.toGMTString() : "") +
       ((path) ? ";path=" + path : "") +
       ((domain) ? ";domain=" + domain : "") +
       ((secure) ? ";secure" : "");
    document.cookie = cookieString;

    return;
}

function Delete_CookieWS(name, path, domain) {
    if (Get_CookieWS(name)) document.cookie = name + "=" +
      ((path) ? ";path=" + path : "") +
      ((domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";

    return;
}

var ws_today = new Date();
var ws_zero_date = new Date(0, 0, 0);
ws_today.setTime(ws_today.getTime() - ws_zero_date.getTime());
var ws_cookie_expire_date = new Date(ws_today.getTime() + (8 * 7 * 86400000));

function setWSVisitorID() {
    var ws_VisitorID;

    ws_VisitorID = Get_CookieWS('ACEVisitor');
    ws_revisiting = "true";
    ws_cks = "true";

    if (ws_VisitorID == null) {
        ws_revisiting = "false";
        Delete_CookieWS('ACEVisitor', '/', '');
        ws_VisitorID = setparWS();
        Set_CookieWS('ACEVisitor', ws_VisitorID, ws_cookie_expire_date, '/', '', '');

        if (document.cookie == "" || document.cookie == undefined || document.cookie == null) {
            ws_cks = "false";
        }
    }

    return ws_VisitorID;
}

function setparWS() {
    var results = sessvars_WS.username;

    if (results == null) {
        sessvars_WS.username = "WS1-" + hex_md5(escape(Math.random() * 9));
        return sessvars_WS.username;
    }
    else {
        return results;
    }
}

// End cookie stuff


// **********************************************************
// MAIN Proc
//
//***********************************************************


var ws_cpg;   // = getparameter("fcty"); // campaign no
var ws_ucd;   // = getparameter("pcty"); // user code
var ws_ccd; // client code
var ws_revisiting = "false";
var ws_cks = "true";

var ws_BrowserDetect = {
    init: function() {
        this.browser = this.searchString(this.dataBrowser) || "unknown";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "unknown version";
        this.OS = this.searchString(this.dataOS) || "unknown OS";
    },
    searchString: function(data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function(dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{
		    string: navigator.userAgent,
		    subString: "Chrome",
		    identity: "chrome"
		},
		{ string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "omniweb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "safari",
		    versionSearch: "Version"
		},
		{
		    prop: window.opera,
		    identity: "opera"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "icab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape6p",
		    identity: "netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "msie",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "netscape4m",
		    versionSearch: "Mozilla"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.userAgent,
		    subString: "iPhone",
		    identity: "iPhone/iPod"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};

ws_BrowserDetect.init();

wsBrowser = ws_BrowserDetect.browser;
wsDocument = (document.documentElement != undefined && document.documentElement.clientHeight != 0) ? document.documentElement : document.body;

// Check if cookies are enabled
var ws_cookieEnabled = (navigator.cookieEnabled) ? true : false

//if (typeof navigator.cookieEnabled == "undefined" && !ws_cookieEnabled) {
//    document.cookie = "ACEVisitor"
//    ws_cookieEnabled = (document.cookie.indexOf("ACEVisitor") != -1) ? true : false
//}

if (ws_cookieEnabled) //if cookies are enabled on client's browser
{
    //cookies are supported
    wsshash = setWSVisitorID(); // set the cookie

    if (ws_cks == "false") {
        wsshash = setparWS();
    }
}
else {
    // cookies are not supported
    ws_cks = "false";
    wsshash = setparWS();
}

addEventWS(window, "load", setLinksWS);
addEventWS(window, "beforeunload", BClsWS);