﻿//document.onclick = exitURL; // route all click events
var varExitURL = "";
var Pagesviewed = history.length;
var startime = (new Date()).getTime();
var varUrl = "";

window.onunload = function () {
    //exit url
    varExitURL = document.location.toString();
    varUrl = "http://www.aryans.biz/page_tracker.aspx?we=unload&time=" + (((new Date()).getTime() - startime) / 1000) + "&exiturl='" + varExitURL + "'";
    //alert(varUrl);
    var x = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
    x.open("GET", varUrl, true);
    x.send(null)
    return true;
}

window.onload = function () {
    var varScreenResolution = "";
    var varTitle = "";
    var varUrl = "";
    var varReferral = "";
    //screen resolution

    try {
        varScreenResolution = screen.width + 'x' + screen.height;

        //title
        varTitle = document.title.toString();

        varUrl = document.location.toString();
        //current url
        //  varUrl = document.url.toString();
        //document.location.toString()
        //referrer
        //document.referrer.toString()
        // varReferral = Get_Cookie("ref_url");
        //if (document.referrer) {
        varReferral = document.referrer;
        //Set_Cookie(('ref_url',varReferral,1,'/','.health-total.com','')
        //}
        varUrlOpen = "http://www.aryans.biz/page_tracker.aspx?we=load&url=" + escape(varUrl) + "&referral=" + escape(varReferral) + "&screen=" + varScreenResolution + "&Title=" + varTitle + "&sessionpages=" + Pagesviewed;
       // alert(varUrlOpen);
        //document.write("<font color:white>" + varUrlOpen + "</font>")
        var x = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        x.open("GET", varUrlOpen, true);
        x.send(null)
        return true;
    }
    catch (err) {
        //alert(varUrl);
        alert(err.description);
        return true;
    }

}

function Get_Cookie(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_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}

//alert(document.location.toString());
//alert(((new Date()).getTime() - startime)/1000);

//function exitURL(e) {
//   
//    if (!document.getElementById) return true; // DOM only
//    var eTag = document.getElementById('tracker');
//    var uLog = '/capture_exit.aspx?url=';
//    var isLink = false;
//    alert(uLog);
//    if (!e) {
//        var e = window.event; // IE
//        var elmClick = e.srcElement;
//    } else {
//        var elmClick = e.target; // FF
//    }
//    while (String(elmClick.nodeName) != "A") {
//        elmClick = elmClick.parentNode; // up the tree 
//        if (String(elmClick.nodeName) == "HTML") return true;
//    }
//    url = String(elmClick);
//    if (url.indexOf("http") != -1 && url.indexOf(location.hostname) == -1) {
//        eTag.onerror = function() { document.location.href = url; }
//        eTag.src = uLog + url;
//        alert(uLog + ur);
//        return false; // wait for log, then leave page
//    }
//    return true; // pass back to originating object
//}

/* browser details */
//var navName = navigator.appName;

//var brVer = navigator.userAgent; var brNum; var reg = new RegExp('/');

//function verNumIE() {
//    var brVerId = brVer.indexOf('MSIE');
//    brNum = brVer.substr(brVerId, 8);
//}
//function verNumOt() {
//    var brVerId = brVer.search(reg);
//    brNum = brVer.substring(brVerId + 1);
//}
/* browser details end*/



//alert(history.);
//document.write('You\'ve been to ' + times + ' site(s) in this browser session.');


// This part gets the IP
//var ip = '<!--#echo var="REMOTE_ADDR"-->';

// This part is for an alert box
//alert("Your IP address is " + ip);

//var language
//if (navigator.appName == 'Netscape')
//     language = navigator.language;
//else
//     language = navigator.browserLanguage;

//alert(language);


//alert(window.history.go(0));


//alert(screen.width + 'x' + screen.height);
//alert()
//alert(new Date().getUTCMonth() + "/" + new Date().getUTCDay() + "/" + new Date().getUTCFullYear() + " " + new Date().getUTCHours() + ":" + new Date().getUTCMinutes() + ":" + new Date().getUTCSeconds());
//alert(new Date().toUTCString());
//alert(new Date().constructor());

//current url
//document.url.toString()
//document.location.toString()
//referrer
//document.referrer.toString()

//    if (document.referrer) {
//        document.write("<B>Thanks for visiting us from ");
//        document.write(document.referrer + "</B>");
//    }

//domain
//document.domain.toString()

//cookie
//document.cookie.toString()

